When designing a freeport communication program, the core of the program design is to use the transmit command (XMT) and receive command (RCV) to send and receive data. The difficulty in applying the receive command (RCV) lies in how to set the "start and end conditions for judging the received message," while the transmit command is relatively simple; you only need to prepare the data and then send it using the transmit command.
But is this really how it works in practice? In a communication program, there might be a lot of data to send. For example, in communication with a Mitsubishi inverter, which uses the inverter's proprietary communication protocol, the data to be sent might include run commands, frequency modifications, and parameter reads. Moreover, these data are all different. Therefore, it would be necessary to define different data in different memories beforehand, and then send the data for the command being sent. Is this really the right approach? I personally disagree with this method. I prefer to create a function block containing the data to be sent, then fill the required data into the pins of this function block, and place the send command within this function block. Each time the function block is activated, the corresponding data is sent.
Let's take the Mitsubishi proprietary communication protocol as an example to illustrate its functions of sending operation commands, modifying frequencies, and reading some parameters.
You can find details about Mitsubishi's proprietary communication protocol online; we won't go into detail here. Instead, we'll focus on the format of the data that the PLC needs to send to the inverter.
The format that a PLC needs to send when writing data to a frequency converter is as follows, depending on the data length: There are three formats:
The data format that needs to be sent when a PLC reads data from a frequency converter.
The following table shows the inverter's operating code, frequency modification code, and inverter parameter reading code.
Combining the above data transmission format and code table, we can find that the formats of the run command, the transmission frequency, and the read inverter parameter values are different, but there are also some common contents in the preceding parts. Therefore, when designing the function block, we need to make a judgment to determine whether it is a "read command" or a "write command". If it is a write command, we need to further determine whether it is a "write run command" or a "write frequency command". Based on this principle, we can start designing the function block.
(1) Compile a variable table
(2) Procedure
After writing the function blocks, you only need to call these function blocks in the main program and assign actual parameters to different function blocks, as shown below: