Share this

Communication and monitoring design between host computer and PLC

2026-04-06 05:28:03 · · #1
1 Introduction PLCs are dedicated computers designed specifically for industrial control. They are small in size, highly reliable, and have strong anti-interference capabilities, thus finding widespread use in industrial control. With the increasing automation of industry, higher demands are placed on PLC applications: faster processing speeds, higher reliability, and integrated control and management functions. Integrated control and management means applying computer information processing technology and network communication technology to PLCs, enabling PLCs to be used for distributed lower-level control, with a computer providing a graphical display interface while simultaneously monitoring the lower-level machines. This paper discusses the communication and monitoring design between the host computer and the Omron CPM2A PLC. 2 Communication Protocol 2.1 Communication Link Methods of CPM2A The CPM2A has three communication link methods: host link system, peer link system, and ComPoBus communication system. In factory automation systems, these three systems are often combined to achieve the multi-level functions required by the factory automation system. In a composite PLC network, the host link system is at the highest level, responsible for monitoring and optimizing the entire system. There are two communication methods between the host computer and the CMP2A: host computer commands and PLC communication commands. In the host computer command method, the host computer is active, and commands are sent from the host computer to the PLC. Using the host computer command method allows for convenient monitoring of the PLC by the host computer. The host computer and CMP2A communicate via an RS-232 port, and the serial port wiring is shown in Figure 1. [align=center] Figure 1 Connection between CMP2A and host computer[/align] 2.2 CMP2A Host Communication Protocol CMP2A data is sent in frame format. When the communication command is less than one frame, the sending format is shown in Figure 2. The text can be up to 122 characters. When the command block content is greater than one frame, it consists of a start frame, intermediate frames, and a result frame. The start frame can be up to 131 characters, and the intermediate and end frames can be up to 128 characters. The start frame consists of the device number, command code, text, FCS, and delimiter. The intermediate frame consists of text, FCS, and delimiter. The end frame consists of the text FCS and an end symbol. After the host computer sends each frame, it sends the next frame only after receiving the delimiter from the PLC. [align=center]Figure 2: Format of the command block during CPM2A communication[/align] The checksum FCS in the command block is an 8-bit binary number converted into a 2-bit ASCII character. This 8-bit data is the result of XORing the ASCII code bits of all characters before the checksum in a frame of data. When converting to a character, it is converted into the corresponding numeric character according to a 2-bit hexadecimal number. After receiving the command frame sent by the host computer, the PLC automatically generates a response block. The format of the response block is similar to that in Figure 2, except that a two-bit response code is added after the command code. The response code indicates the error information of the host computer command. A response code of 00 indicates that the PLC has successfully completed the host computer command. 3. Writing PLC Commands In the CPM2A host computer link system, the PLC receives instructions and passively returns a response block to the host computer. Therefore, the PLC, as the slave computer, does not need to write a communication program. Communication between the host computer and the PLC cannot change the PLC's input state. To change the PLC's output via the host computer, the slave computer's program must utilize the PLC's working positions. The host computer changes the state of these working positions to alter the PLC's output, thus achieving host computer control over the PLC's output. As shown in Figure 3, working positions 3.00 and 4.00 are added to the ladder diagram. During normal system operation, 3.00 and 4.00 are OFF. When host computer control is required, 3.00 is turned ON, disabling the PLC's input 0.00. The system output is controlled by switching working position 4.00 on and off. [align=center]Figure 3 PLC Programming for Host Computer Monitoring[/align] 4. Writing the Host Computer Communication Program In a host computer linkage system, communication is generally initiated by the host computer, using standard PLC communication. The host computer sends operation commands to the PLC, the PLC executes the corresponding operations according to the commands, and simultaneously returns data to the host computer. The serial communication flow is shown in the following figure. [align=center]Figure 4 Communication Flowchart[/align] 4.1 Writing the Host Communication Program The communication program can be written in a high-level language or assembly language. The example below is a communication program between a host computer and a CPM2A PLC written in Delphi. The communication adopts the standard communication mode. The communication interface is shown in Figure 5. [align=center]Figure 5 Communication Interface[/align] //Program Initialization: procedure TForm1.Init_PLC(nPort:integer); begin if MSComm.PortOpen then MSComm.PortOpen:=False; MSComm.Commport:=nPort; //Communication Port Selection MSComm.Settings:='9600,e,7,1'; //1 start bit, 7 data bits, even parity, 2 stop bits, 9600bps MSComm.PortOpen:=True;//Open serial port end; //FCS Check function FCS(s:string):variant; vari,len,tmpVar:integer; DataCheck:byte; f1,f2:byte; begin f1:=0; f2:=0; DataCheck:=0; len:=length(s); tmpVar:=0; for i:=1 to len do begin DataCheck:=ord(DataCheck) xor ord(s[i]); end; f1:=DataCheck and $0f; f2:=DataCheck and $f0; f2:=f2 shr 4; result:=inttostr(f2)+inttostr(f1); end; // Call the MSComm control to implement PLC communication procedure TForm1.HandShake_PLC; var tmpByte1,tmpByte2:char; tmpVar:string; s:string; begin Init_PLC(1); &nbs p; s:=Edit1.text; tmpVar:=s+inttostr(FCS(s))+'*'+chr(13); MSComm.RThreshold:=0; MSComm.Output:=tmpVar; // Output data to the serial port sleep(1000);// Delay tmpVar:=MSComm.Input; // Read data from serial port tmpByte1:=tmpVar[5]; tmpByte2:=tmpVar[6]; if tmpByte1=chr(48)& tmpByte2:=chr(48); // Check code equals 00, PLC completes operation normally then begin Showmessage('The data sent is correct'); else Showmessage('The data sent has a problem'); //end; end; 4.2 Implement monitoring of PLC by host computer Write communication program to establish connection between host computer and PLC. In any working mode of PLC, the status of PLC can be read by the "read" instruction. Thus, PLC can be monitored. Only when the working mode of PLC is monitoring can PLC be controlled by host computer. Therefore, in systems that require host computer control, PLC must be set to monitoring working mode. The host computer only needs to set the corresponding working position of PLC to realize the control of PLC. The following figure shows the PLC host computer control process. Figure a shows that when the PLC is working normally, the output is controlled by input 0.00. When it is necessary to transfer the control of the PLC to the host computer, simply input @00RR00030001 to the PLC, set 3.00 to ON, and cut off the path of 0.00. In this way, the output 10.00 will be controlled by 4.00. When input @00WR00040001, 4.00 is ON, and the output bit 10.00 will be generated. (a) PLC working normally (b) Host computer control [align=center] Figure 6 Host computer control of PLC[/align] 5 Conclusion This article discusses the method of realizing the communication between the PLC and the host computer system, and the PLC programming to realize the control of the lower PLC by the host computer. Through the monitoring and control of the PLC by the host computer, the automated monitoring of the factory production process can be conveniently realized. References [1] Mi Hongtao, Bi Guozhong, et al. PLC Application Technology. Beijing: China Electric Power Press, 2004 [2] Song Bosheng. PLC Programming Theory, Algorithm and Techniques. Beijing: Machinery Industry Press, 2006
Read next

CATDOLL 115CM Alice TPE (Customer Photos)

Height: 115cm Weight: 19.5kg Shoulder Width: 29cm Bust/Waist/Hip: 57/53/64cm Oral Depth: 3-5cm Vaginal Depth: 3-15cm An...

Articles 2026-02-22