2 Design of Simulation module
In the actual project, data acquisition module and control module generally adopt RS-485 interface, because this kind of interface only need two connection wiring, construction is convenient, at the same time, transmission distance can reach 1200 meters. General computers are equipped with RS-232 interface, can be converted through the rs-232/rs-485 converter, so that the computer and RS-485 interface module communication. Therefore, the simulation module adopts RS-232 interface. The main interface of the simulation module is shown in Figure 1.
Fig. 1 The main interface of AI/DO-M simulation module
Fig. 1 The left part is the abstraction of hardware kind, the working status indicator red light indicates the idle, the green light indicates that is working. The power LED is green to indicate that the module has been installed and the Tx LED is green to indicate that the module is sending data and the RX LED is green to indicate that the module is receiving data. The lower part is two temperature sensors, the data range is 00-0xff, respectively corresponding to the temperature 0-100 ℃. The upper two output switches are controlled by the main control program through the serial interface, if the OUT0 switch is closed, then form a loop, light, the corresponding temperature sensor S1 heating up, red arrow upward, data increment; otherwise, the corresponding sensor temperature drops. The right part of Figure 1 is the description of communication protocol, and communication protocol is the agreement of Operation module. There are three kinds of communication protocols, namely read Protocol, Response (Reply) protocol and write Protocol. The read protocol is used to read data in a module, EOT is a leading character, the ID is the address of the module, RD is the read flag, the BCC is the checksum, and EM is the end code. The Reply protocol is a response to the Read protocol, STX is a leading character, DT1 and DT2 are two temperature bytes of the sensor, do is the state of the output switch, OUT0 and OUT1 use a byte of the lowest two bits, 1 means the switch is closed, and 0 means the switch is open. WT of the Write protocol is a write sign. The lower part of the three protocol is a description of the characters in the protocol, such as EOT for bytes, 04,wt in 0x57, and so on.
The Receive text box displays the Read protocol or Write agreement sent by the host computer. The Send text box is the Reply protocol that the emulation module sends to the master controller.
The Setup button displays the module parameter setup form, as shown in Figure 2. The Port Setup tab is used to set the parameters associated with the serial port, protocols the Setup tab to set the protocol parameters, including the Protocol's checksum code and the end code. ID text box to set the address of the module, the Interval text box sets the time interval in seconds, and step represents the stride length, as shown in Figure 2, which indicates that the simulation module will increase the value of the sensor (if the corresponding output switch is closed) or drop (if the corresponding output switch is turned on) 5 per 6 seconds. The parameters you set are saved by the My.Settings method, and the data is restored the next time you open the program.
When using the Emulation module, you must first click the Setup button to set the parameters, and then click the power indicator to turn it green, at which point the Emulation module works. After receiving the data through the 1.4-section method, if the Read protocol is sent by the main controller, the current data of the module is assembled into the Reply protocol, and the SendData function in section 1.3 is sent out. If it is the write protocol, then call the Setbytebit and Resetbytebit functions in section 1.1 to place or reset, then call the Checkbytebit function to display the state of the output switch, if the corresponding bit is 1, show the red line, indicating that the switch is closed If the corresponding bit is 0, the red line is hidden, indicating that the switch is turned on.
The main form with the Timer_comm timer with the data received, with the timer_signal timer to control the Tx and Rx led flashing, with the Timer_step timer (Interval property by Figure 2 set) to adjust the sensor byte data.