In the previous article, we introduced some basic knowledge about freeport communication, explaining what a communication protocol is, what an information frame or message message is, and the relationship between start/end symbols and start/stop bits. Today, we'll discuss the freeport communication functions and program design of the Siemens S7-200 series.
Freeport Mode is a distinctive feature of the S7-200 series PLC . With Freeport Mode, users can operate the port themselves using (XMT and RCV). This allows the S7-200 series PLC to communicate with any intelligent device or controller with a known communication protocol and a serial port, such as printers, frequency converters, and smart meters.
The communication port on the S7-200 CPU is electrically a standard RS-485 half-duplex serial communication (half-duplex communication means that sending and receiving cannot occur simultaneously; therefore, in program design, sending must be completed before receiving, and receiving must be completed before sending). The format of this serial character communication can include:
(1) A start bit
(2) 7 or 8 characters (data bytes)
(3) One parity bit, or no parity bit
(4) A stop bit
(5) Baud rate: 1200, 2400, 4800, 9600, 19200, 38400, 57600 or 112500 bps
Any communication format that meets the above conditions can use freeport communication to exchange information.
If you need to use a PLC to send data out via a free port, you must complete the following steps:
(1) Communication format settings, used to specify the communication format between the two communicating parties.
(2) The data that the PLC needs to send via the XMT instruction can be prepared according to the information frame format provided by the communication protocol.
(3) Determining whether information has been sent: Only when the information has been sent can the user design the information receiving program or decide on the next sending.
Taking the communication protocol of the instrument mentioned in the previous article as an example:
(1) Set the communication format word in the PLC.
The communication format words are stored in a special system memory for PLCs. In the 200 series PLCs, this is done through SMB30 (port 0) and SMB130 (port 1). Setting the communication format words must be done in conjunction with the slave device. The following is the parameter setting provided by the instrument.
Here, if you select a baud rate of 9600, one stop bit, 8 data bits, and no parity (Note: it cannot be set to two stop bits, as PLC free port communication does not support two stop bits), then the communication format word in the PLC can be set to 16#09 . The communication format word is set as shown in the following figure:
(2) Prepare the data to be sent out via XMT command according to the communication protocol:
Suppose we need to read process values from an instrument, we need to prepare the corresponding data according to the communication protocol format:
XMT command format:
Note: T represents the address of TBL in the instruction. As shown in the figure, T represents VB0, so T+0 represents VB0, T+1 represents VB1 and so on. port represents the port number of the PLC.
You can define the data you need to send in the data block:
(3) Determining when information transmission is complete
There are two ways to determine whether a message has been successfully sent.
One method is to use a send completion interrupt to determine...
Ports 0 and 1 have corresponding send completion interrupt events, which can be used to determine whether the message has been sent successfully. Two interrupt events are allocated to each port (PORT0 and PORT1) to indicate message transmission completion. Interrupt event 9 is allocated to PORT0, and interrupt event 26 is allocated to PORT1.
Alternatively, it can be determined by checking system storage locations .
The completion flag is used to determine whether data transmission is complete. This can be done by monitoring the SM4.5 (port0) or SM4.6 (port1) flags. SM4.5 =1 indicates that port 0 is idle, and SM4.5 =0 indicates that port 0 is in transmission mode.