Please Contact Us if Necessary , Email :
【Technical Class】S7 200 SMART Serial Free Port Quick Application

【Technical Class】S7 200 SMART Serial Free Port Quick Application

1. Hardware connection

For third-party equipment, such as code scanners, printers, meters, etc., it is a non-standard bus protocol and a custom protocol, which is called a free port protocol. Before starting the programming, the serial port type of the third-party device must be identified first.

1. Communication interface

A. The serial port of the SMART CPU body of the third-party device whose serial port is 232 is RS-485. To communicate with the 232 device, a 232to485 converter needs to be added in the middle. Common connections are shown in Figure 1.

B. The serial port of the third-party device is 485

When both SMART CPU and third-party device serial ports are 485, they can be directly connected. Common connections are shown in Figure 2.

C. If the serial port of the
third-party device is 422, the serial port of the third-party device is 422, and the connection method of 422 should be 485. Common connections are shown in Figure 3.

2. Communication connector

In the case of complex industrial sites or long-distance communication, it is recommended to choose high-quality bus connectors and cables. The bus connector of UniMAT Automation has its own terminal resistance and bias resistance. In this case, it can improve the stability and anti-interference ability of communication.
Bus connectors and cables, order numbers are shown in Table 4.

3. Why choose bus connectors and bus cables

As we all know, the network cable is divided into Category 5 and Category 6. The transmission bandwidth of Category 5 can be as high as 1000Mb/s, but it is generally only used in 100Mb/s networks; Category 6 is mainly used in Gigabit networks. The performance is much higher than the super five network cable standard. The intuitive difference between Category 5 and Category 6 cables is that the diameter of the copper core of the cable is different, and the copper core of Category 6 is obviously thicker than Category 5.

In the same way, it is speculated that the bus cable of UniMAT Automation, the loop impedance: <150R/KM, is better than the general communication cable. The line resistance is small, the communication distance is long, and the anti-interference ability is strong.

The bus connector of UniMAT Automation has its own terminal resistance and bias resistance, which can also improve the quality of communication.

The recommended networking method is shown in Figure 5:

The termination and bias resistors are shown in Figure 6:

2. Communication Mechanism


To understand the communication mechanism clearly, to clarify the program ideas, in order to program smoothly. Common communication mechanisms are as follows:

A. The CPU only accepts but does not send, that is, the third-party device only sends and does not receive. Common such as scanning code gun.

B. The CPU only sends and does not receive, that is, the third-party device only receives but does not send. Common such as printers.

C. The CPU sends first, then receives, then sends, and then receives. The CPU communication mechanism is similar to the master mechanism, such as Modbus RTU Master.

D. The CPU receives first, then sends, then receives, and then sends. The CPU communication mechanism is similar to the slave mechanism, such as Modbus RTU Slave.

E. Communication logic customization.


3. Communication message

Communication message, that is, the format of data sent and received. Such as Modbus communication, the communication format is clearly defined. Both parties of the communication should send and receive the response data according to the agreed format and length.

The CPU acts as the master station. Taking the Modbus RTU master station message as an example, the data format sent by the CPU is as follows:

The third-party device, after receiving the CPU message, needs to respond to the data format as follows:

The main purpose of the above example is to understand the meaning represented by each byte of communication data agreed upon by both parties. Data can be read or packaged only when the meaning of the data is clearly understood.


4. PLC control word


Before writing the program, there is a preparatory work to understand the control word that defines the serial port/communication method.

A. Serial control word

The SMB30 and SMB130 configure communication ports 0 and 1, respectively, for Freeport operation and provide a choice of baud rate, parity, and number of data bits. The figure below shows the Freeport Control Byte. For all configurations, a stop bit is generated.

SMB30\SMB130 data bit format:

SMB30\SMB130 data definition:

B. Communication control word & status word

5. PLC only receives but does not send

A. The main program is powered on and the serial port is initialized

2#00 0 010 01 SMB30 8-N-1 9600 Free port

2#01110000 SMB87

The header bit of the received data is A5, and the end of the table is 5A

Receive length 10 bytes SMB94

B. Turn on the receive completion interrupt

C. Trigger the receive command, and the received data is placed in the register area starting from VB200.

D. In the reception completion interrupt program, open the reception.

In the control word, the length of the received data is set to 10, the received data is stored in the 10 bytes starting from VB201, and VB200 is the received byte counter.


6. PLC only sends and does not receive

A. Serial port initialization

B. Organizing the data to be sent

C. Trigger sending instructions

The starting byte is VB100 is the byte length sent

D. Packet monitoring

Sending messages with different lengths

The logic is similar to the Modbus master, and the free port mode can also be used to edit the Modbus communication.

A. Serial port initialization, generally to define the length of the received character, or the end character to judge the end of the reception.

During initialization, the connection is interrupted when sending and receiving are completed.

B. Organization to send data

In this example, the transmission length is 10 bytes, VB100=10, and VB100-VB110 is the transmitted data

C. Program logic

D. Send & timeout judgment

If it times out, close the reception, that is, reset SM87.7

On the falling edge of the timeout flag, the reception is reopened, that is, SM87.7 is set, and the transmission is triggered again.

E. Send complete, open receive

F. The reception is completed, and the transmission is triggered again

G. Packet Analysis

After the transmission is completed, the PLC does not receive the data, and continues to send after the timeout. Such as the first five lines of the message.

After the transmission is completed, the PLC receives the data and immediately triggers the next transmission. Such as the sixth and seventh lines of the message.

Eight, PLC first receive and then send

The logic is similar to the previous chapter, and the logic is similar to a Modbus slave.


Nine, receive character interrupt

Serial port initialization, can ignore the received character length, end character, etc., the programming is more flexible.

A. Serial port initialization

Connection receive character break

B. Organize the sending of messages and trigger sending instructions

The received character is interrupted, and the received data is stored in the target register

X. Troubleshooting

When the communication is abnormal, it is recommended to check from the following aspects:

A. Make sure the communication cable is connected correctly, refer to Chapter 1, and focus on Chapter 1.1.

B. Make sure the communication parameters are consistent.

C. Use the computer serial port assistant software to monitor the communication messages and locate whether the PLC has not sent data or the device has not responded to the data. Refer to Chapter 3.

Monitor communication messages: connect A and B of the computer 485 in parallel on the communication link, the software recommends serial port assistant.

Leave a comment

Please note: comments must be approved before they are published.

If You Would Like to Contact Support or Make a Purchase Please Fill out the Form

If you have urgent needs, please call our customer service number

Please fill in your information in detail so that our support staff can clearly understand your needs.

Value is required
Value is required
Please input the correct email address
Value is required
Thank you!