How can computer replace PLC in industrial machines?
A PLC (programmable logic controller) IS a computer, albeit a special purpose one.  The main differences between it and a PC or laptop are a PLC is ruggedized to operate in a harsh environment on a factory floor, such as extended temperature range, dust, high humidity, and vibration; and it has dozens of inputs and outputs designed to work in a noisy (EMI) environment.

Inputs are tied to sensors (temperature, liquid levels, RPM) or cameras for machine vision, or a network like CAN (Controller Area Network.  Outputs may control relays which are connected to motors, valves,  and other devices, or drive analog or PWM or 4-20 ma circuits; or are connected to a network like CAN.  Some of the inputs and outputs may be tied together to form a PID control system.



The computer will be running a real-time OS.  Early PLC's had a user interface built-in, but now a laptop is plugged in for this purpose.  It is disconnected after programming since the laptop is not designed for the harsh industrial environment.  (The laptop is not used for running the PLC software, just for programming it.)

PLC's were originally constructed using hundreds of relays, and the programming was done using ladder diagrams.  Since engineers working with PLC's were used to this, when PLC's switched over to computer control, the ladder diagram interface was retained.  It substitutes a graphic programming interface for the conventional programming language.



So you could build your own PLC, for example take a BeagleBone Black, replace the Linux OS with QNX (a real-time OS), and add capes for input and output (relays).  Then add a ladder diagram user interface and you're all set.

Don't put it to work in a factory though, since the BeagleBone and its capes will not be rated for the industrial environment.  It would work fine for a home automation system though.