Implementation of RS-485 Communication between PLC and PC of Distributed Control System Based on VB

.This paper focuses on achieving RS-485 communication between programmable logical controller (PLC) and PC based on visual basic 6.0 (VB6.0) on an experimental automatic production line. Mitsubishi FX 2N PLCs and a PC are chosen as slave stations and main station, respectively. Monitoring software is developed using VB6.0 for data input/output, flow control and online parameters setting. As a result, all functions are fulfilled with robust performance. It is concluded from results that one PC can monitor several PLCs using RS-485 communication.

software will be developed with VB 6.0, which has advantages about interface programing. After finishing those two parts, some experiments will be done on an experimental automatic production line only with one PLC. As a result, the monitoring software shows good performance on controlling the automatic produce line. Therefore, it is can control more PLCs and can be applied in practical automatic production line.
The system hardware are described in Section II. Section III gives an overview about implementation of communication between PC and PLC. The structure of program of PLC and VB6.0 is presented in Section IV. The results, presented in Section V, is a clear illustration of all functions such as monitoring all devices, controlling the automatic line and jogging and so on.

System hardware design
To fulfill these functions of system, the platform should be suitably integrated with hardware and software. When the requests are produced, the computer sends signals to the PLCs through the converter called USB to RS-485. Each PLC is connected with a 485ADP adapter, which transform signals in RS-485 to PLCs' format signal [8]. All PLCs are connected with each other in a parallel way. Each PLC can achieve different controlling functions according to system requirements. Figure  1 shows basic structure of the system.

Initialization communication format
The communication format decides communication setting (data length, parity, and baud rate, etc.) between computer and PLCs. The communication format can be set using the special data register D8120 in PLCs. Setting D8120 value makes it in accordance with external equipment, which refers to VB's MSCOMM Control in this system. Figure 2 shows parameters that chose and set in the PLCs. Figure 3 shows communication parameters set with VB6.0 [8,9]. After setting same communication format, the system can send and receive data according to communication protocol.

Introduction to communication protocol
FX series PLC provides two basic two formats for dedicated protocol, which can be selected by setting special data register D8120. This system chose format 1. Figure 4 shows specific communication protocol about reading and writing data. According to communication protocol, it can use different operation command to get a complete command string, which is corresponding string sent from VB6.0. For example, the monitoring software needs state of device X1 on, then it get the string "0500FFBRAX00101" according to communication protocol. For more details, please refer to Mitsubishi PLC communion Manual [8].

Software program design
This section can be divide into two parts: PLC's program structure and VB6.0's program structure, which use USB to RS485 converter to connect to each other and has same communication parameters.

PLC's program structure
There are five PLC programming languages: Ladder diagram (LD), Sequential Function Charts (SFC), Function Block Diagram (FBD), Structured Text (ST), and Instruction List (IL). This allows program developers to select the language best suited to each particular task depending on their advantages and disadvantages. This paper adopted SFC method because of multiple branches requirements. PLC's program structure is selection branch structure and the selection command is given from main station (PC) by users. One FX2N

VB6.0's program structure
Depending on automatic production line requirements and programmer developer's experiences, the monitoring software was designed to have 6 windows, which are main window, communication parameters setting and test window, run window, jog window, online devices' parameters setting and monitoring window, and help window. Every window has different functions and program structure.
Main window provides access to other 5 windows, which needs account and password and can prevent monitoring software operating by other people. Communication parameters, such as communication ports, can be changed with communication parameters setting and test window, which also can check if communication between PLC and PC works. In terms of online devices' parameters setting and monitoring window and run window, the main program's structure is a loop to scan state of PLCs' devices and there is a program interrupt to be used for devices' parameters setting. Besides, online devices' parameters window gives users access to read and write any PLC devices and workers can control and get real-time state information of automatic production line with run window. Jog window makes it easy for technics to tune production line after it was installed, while help window just shows some basic hints to solve some common errors.

RESULTS
In order to evaluate the performance of monitoring software and RS-485 communication, kinds of experiments are done on this system, such as online parameters setting and tuning. This part chooses three windows to show main functions of monitoring software. As figure 6 shows, the online devices' parameters setting and monitoring window has two main parts, the left part is used to set and monitor all devices while the right part only can show value or state of some common devices such as input devices X0~X7 and timer devices T0~T7. The left part has four small parts: communication test section, output devices Y0~Y7 setting and resetting section, state devices operation section and numerical devices operation section. This window demonstrates the ability of monitoring software to achieve online parameters setting and monitoring. For example, workers want to set timer T0's value as 100s. Firstly, operator needs to choose 'T' at numerical devices operation section and inputs timer device's address value '0000' to address textbox of numerical devices operation section. After that T0's value also should be input to the corresponding textbox of same section. Finally, click 'write' button. Referring to FX2N PLC communication user manual, timer devices' value has four bits, which explains that device T0's address value is '0000' instead of '0'.

Jog control
Performance of jog control is an important evaluation, which is very useful for production system tuning and maintaining. Figure 7 shows that this window has three main sections. And it was utilized to control three different kind motors: step motors, AC motors and servo motors. Each section has same structure, which has three buttons from up to down to achieve motors' clockwise rotation, counter clockwise rotation and stop function. The interlock of motors motion control was considered by PLC program instead of this window's program since PLC has better reliability.

Controlling and monitoring automatic production line
Run window is a custom design window depending on practical control subject's requirements and it can show real-time state of automatic production line such as state of sensors and position of motors. The function of this production line is to select different color balls and put them into different places. With monitoring all PLC devices used by this production line and some VB6.0's functions, this window can show operating state of production line in a animation way. For example, servo motor's image of this window can move depending on production line sensor's state and setting velocity. Though there is a delay, it is acceptable for most automatic production line. With this function, one worker can control many machines in offices. As figure 8 shows, the main content of this window is an animation picture of production line and four buttons can be found in the bottom of window, which shows different functions: reset, start, stop and quit. Those small blue rectangles indicate all sensors' position in production line and their color can become to red when sensors' state is on. The biggest rectangle stands for conveyor belt while step motor is shown using a big blue circle.

Conclusion
In conclusion, the monitoring software shows good performance on controlling the experimental automatic production line. Besides that, Experimental results also shows that monitoring software interface is friendly, that has good maneuverability, and that shows reliable performance. Comparing to other works, the innovation of this paper is the original combination of VB6.0, PLC, and RS-485, which other works maybe use different brand PLCs and kinds of software.