Hardware and software methods by listening, analyzing internal PLC inherent PPI protocol, then the host computer using VB programming, follow the PPI protocol, data reading and writing PLC, man-machine operation tasks. This communication method, compared with the general freedom of communication protocols, omitted through the PLC programming, just the preparation of the PC communication program resources S7-226 programming port physical layer is RS-485 configuration, SIEMENS offers MicroWin software, It uses a PPI (Point to Point) protocol can be used to transmit debug PLC programs. In the field, when required PLC and PC communication, the more use custom protocol to communicate with the host computer. In this communication, the need for programmers to define their own form of free communication, writing code in the PLC, the use of interrupt control communication port to send and receive data. In this way, PLC programming and debugging is more cumbersome, takes PLC software interrupt and code resources, and when the PLC communication port is defined as the free communication port, PLC programming software PLC can not monitor the PLC program debugging inconvenience .
SIEMENS S7-200PLC programming communication interface, internal curing communication protocol PPI protocol, if the host computer to read and write PLC follow the PPI protocol, you can omit the write PLC communication code. How to get PPI protocol? In the PLC programming software PLC to read and write data, the use of communications data third listens PLC’s serial port, or using software methods, has been opened and the interception of data communications port is then summarized, parses the data PPI protocol read and write messages. Thus, the PC follow the PPI protocol, you can conveniently read and write data within the PLC, man-machine operating functions of the host computer.
software design
System monitoring and control tasks are performed by SIEMENS S7-226PLC complete, PLC cyclic scan mode, when the regular time to time, perform data acquisition or PID control tasks, the completion of the field signal. Computer monitoring software using VB preparation, use MSComm control the completion of serial data communication, the communication protocol to follow for the PPI protocol.
PPI protocol
Siemens PPI (Point to Point) protocol uses a master-slave communication mode, a read or write operation steps include: First, read and write commands issued by host computer, PLC to receive the correct response, the PC receives this response is a confirmation application command, PLC is done correctly read and write response, response data to the host computer. Send and receive data twice, once to complete the reading and writing of data [5].
Its communication data packet formats generally have the following categories:
1, an application to read and write data format is as follows:
SD LE LER SD DA SA FC DASP SSAP DU FCS EDSD: (Start Delimiter) start delimiter (68H)LE: (Length) data packet lengthLER: (Repeated Length) duplicate data lengthSD: (Start Delimiter) start delimiter (68H)SA: (Source Address) source address pointer to the address, the address value multiplied by 8DA: (Destination Address) destination address, pointer to the address, the address value multiplied by 8FC: (Function Code) function codeDSAP: (Destination Service Access Point) destination service access pointSSAP: (Source Service Access Point) Source Service Access PointDU: (Data Unit) data unitFCS: (Frame Check Sequence) check codeED: (End Delimiter) End delimiter (16H)Packet data length and duplicate data length from DA to DU data length for the DA to DU checksum data and parity, just take one of the last byte value.In the read and write PLC variable data, the data read function code is 6CH, write data function code is 7CH.
2, PLC received read and write commands, after the check, they returned data format E5H
3, read and write commands to confirm the data format is:
SD SA DA FC FCS EDWherein SD as a starting character for 10HSA data source addressDA for the destination addressFC function code, take 5CHFCS for the SA + DA + FC and the last byteED is the end of the character, take 16HPPI protocol software preparation
When using the PC to communicate with the PLC, PC using VB programming, or general computer use PPI cable 485 serial card to connect to PLC programming mouth communication system uses a master-slave configuration, PC follow PPI protocol format, read and write the application issue , PLC returns the corresponding data. Program to achieve the following:
1, serial port initialization procedure:
MSComm1.CommPort = 1
MSComm1.Settings = “9600, e, 8,1”
MSComm1.InputLen = 0
MSComm1.RThreshold = 1MSComm1.InputMode = comInputModeBinaryPPI protocol defines the serial port to send and receive data in binary form, so that the efficiency of communication packets than ASCII code.
2, serial data read program to read VB100 data unit as an example:
Data Dim Str_Read (0 To 32) ‘is defined as the transmission byte array elements.Str_ Read (32) = & H16 ‘corresponding array element assignment in the following format:Str_ Read (29) = (100 * 8) \ 256 ‘address pointer value, first take the high address pointerStr_ Read (30) = (100 * 8) Mod 256 ‘to take the lower address pointerStr_ Read (24) = 1 ‘the read data length (Byte number)For I = 4 to 30
Temp_FCS = Temp_FCS + Str_Read (i)Next IStr_Read (31) = Temp_FCS Mod 256 ‘calculated FCS checksum, other array elements assigned omitted.68 1B 1B 68 2 0 6C 32 1 0 0 0 0 0 E 0 0 4 1 12 A 10 2 0 1 0 1 84 0 3 20 8B 16PLC after returning data E5, confirm read command, sends the following data:10 2 0 5C 5E 16
PC VB program then receives the following data:
68 16 16 68 0 2 8 32 3 0 0 0 0 0 2 0 5 0 0 4 1 FF 4 0 8 22 78 16First, identify the source address and destination address, confirm that the application returns the data, and then after a validation check, correct parse out the data No. 26 (& H22) is VB100 bytes of data.
3, serial data write process to write data VB100 unit as an example:
Data Dim Str_Write (0 To 37) ‘is defined as the transmission byte array elements.
Str_Write (37) = & H16 ‘corresponding array element assignment in the following formatStr_Write (35) = & H10 data values to be written ‘68 20 20 68 2 0 7C 32 1 0 0 0 0 0 E 0 5 5 1 12 A 10 2 0 1 0 1 84 0 3 20 0 4 0 8 C B9 16PLC after returning data E5, confirm the write command sends the following data:
10 2 0 5C 5E 16PC VB program then receives the following data:68 12 12 68 0 2 8 32 3 0 0 0 0 0 2 0 1 0 0 5 1 FF 47 16This PLC is correctly received and written information data is returned.4, receiver program:In the data receiving program, using VB in MSComm control, buffer once all the data received, stored in an array of temporary storage unit, and then analyze the value of each element to obtain read and write data.Dim RCV_Array () As ByteDim Dis_Array As StringDim RCV_Len As LongRCV_Array = MSComm1.Input ‘remove serial port to receive data buffer.RCV_Len = UBound (RCV_Array)ReDim Temp (0 To UBound (RCV_Array))For i = 0 To RCV_LenDis_Array = Dis_Array & Hex (RCV_Array (i)) & “”Next iText1.Text = Dis_Array ‘to send the received data show.
In the process of reading and writing program, one can read and write 222 byte maximum, given the current data reading and writing an integer format.Data type Str_ Read (27)S 04HSM 05HI 81HQ 82HM 83HV 84H
The above procedure is based on the reading and writing PLC V variable area as an example, the use of PPI protocol can also read and write S7-200PLC the various types of data, including I, Q, SM, M, V, T, C, S and other data type, can be read directly over variable bit, byte, word, double word, etc., in which the read bit variable, is to read the bit where the byte value, then the PC automatically recognizes the value of the bit. Read and write data according to type, wherein the value Str_ Read (27) each of different:
In the control system, PLC and host computer, using the PPI protocol, the host computer to read and write cycle once every 0.5 seconds PLC. PLC programming when the detected value, the output value and other data to be read, stored in a continuous variable area in the PLC, the PLC when the host computer to read data, it may be read out of this group of contiguous data, reduce data graded frequently read. When modifying the set value data, write the data communication operation.