Share this

Design of serial port device communication implementation method in configuration software

2026-04-06 08:50:22 · · #1
Abstract: This paper analyzes the principle and development method of serial port device communication in configuration software, and proposes a specific implementation method for developing a serial port device communication module for configuration software using VC++6.0. Keywords: Configuration software, serial port device communication, VC++6.0 1. Introduction: The development and use of industrial control configuration software has a history of several decades. Many companies engaged in industrial control are now using or even developing their own configuration software. In the process of developing configuration software, communication is a very important module. After designing the display screen using configuration software, it is necessary to receive data collected from the field, form dynamic images, reflect various states of the industrial field, and control the field equipment. All of these depend on the communication module of the configuration software. Most field measurement and control equipment uses standard communication interfaces, and the serial interface is the most common communication interface used by measurement and control equipment. This paper first analyzes the method of developing serial port device communication in configuration software, and then proposes a specific implementation method for developing a serial port device communication module for configuration software using VC++6.0. 2. Communication Principle between Configuration Software and Measurement & Control Equipment The configuration software obtains real-time data from the field measurement and control equipment through I/O drivers. After processing the data, it displays it graphically on the computer screen to reflect the operating status of the field equipment. Simultaneously, according to configuration requirements and operator instructions, it sends control data to the I/O devices to control the actuators or adjust control parameters. Generally, I/O drivers are device-specific; that is, a driver for one type of device can only drive that type of device. Equipment manufacturers provide the interface protocol and physical interface standard for digital communication between the PC and the device. The physical interface standard specifies the communication medium and link layer interface standard used, such as RS232, RS485, Ethernet, etc.; the interface protocol specifies the command and data response formats agreed upon by both communicating parties, data verification methods, etc. The I/O driver mainly sends data request commands to the device according to the interface protocol, unpacks the returned data, and extracts the required data (i.e., configuration data connection items and device status data). Most devices' communication interface protocols have several read and write commands, used to read and write different types of data on the device. Each command can read or write multiple data entries of the same type; the specific number is defined by the interface protocol. Engineers using configuration software for I/O data connections do not need to understand these details; they only need to configure the mapping between database variables and device data items according to the I/O driver's manual. I/O drivers primarily process data in packets, which greatly improves communication efficiency. The communication process is shown in Figure 1: [align=center] Figure 1. Block diagram of communication principle in configuration software[/align] 3. Design of serial port device communication method in configuration software In the field of industrial control, field measurement and control equipment is often divided into three types: one is equipment that can work independently and complete specific data input and output functions, such as various boards for analog input and output and digital input and output; another type of equipment does not directly process data input and output, but plays a role in managing the work of other equipment, such as serial port equipment; the third type of equipment has the function of processing data input and output, but only together with the first type of equipment can it form a complete working system: such as PLC equipment, intelligent instruments and meters, etc. Different types of equipment have different working methods, and their corresponding communication methods are also different. The third type of equipment is the most commonly used type of equipment. Their communication method mainly involves operating the serial port, so they are called serial port devices here. The following example shows the method of designing serial port device communication in configuration software using VC++6.0. VC++ was chosen for development because software developed with VC++ has high running efficiency, shorter code, and faster execution speed, fully utilizing the advantages of multitasking and multithreading in 32-bit operating systems. There are generally two methods for developing serial communication using VC++ 6.0: one is to directly use Windows API functions for programming, and the other is to use the MSCOMM control for serial port programming. The latter method is relatively simpler in terms of program implementation because the MSCOMM control encapsulates a large number of Windows API functions. When programming with the MSCOMM control, users only need to consider how to use the properties and events provided by the MSCOMM control to drive the API function interface to complete the work. Implementing serial device communication in configuration software essentially involves developing drivers for different serial devices. This generally consists of two parts: first, setting up, initializing, and performing read/write operations on the serial port; and second, processing the data frames read and written from the serial port according to the communication protocols of different devices to extract the useful data. 3.1 Serial Port Property Setting Dialog Box Design Create a new project, insert an MSCOMM control into the project, create a dialog box (set_com), and add the following controls: This dialog box is used to set the properties of the serial port. However, this does not actually set the serial port; it only saves some parameters to variables. In actual applications, many other properties may be used, but the above are the most commonly used. For simplicity, this design only sets one of these properties; the other properties use their default settings. The MSCOMM control has two communication methods—event-driven and polling. For simplicity, this design also uses only one of these communication methods—event-driven. 3.2 Opening the serial port and data processing design This step should include the following functions: (1) The user can select the serial device to be used (2) Set the serial port according to the parameters set in 3.1 (3) Open the serial port, process the data and save it to the buffer For the sake of simplicity, the design of function (1) is omitted here. Assume that the configuration software we designed only communicates with one device (we use OMRON PLC, taking C200HE PLC as an example, and the communication protocol adopts the upper computer link communication) 3.2.1 Serial port attribute setting and opening the serial port Create a dialog box that supports ActiveX control (test_com), drag the MSCOMM control from the control toolbar to the dialog box, and add a control variable for the control: m_ctrlComm. In the test_com::OnInitDialog() function, the serial port properties are set as follows: // Assign the serial port properties set in the set_com dialog box to para para=btl+”,”+jojy+”,”+sjw+”,”+tzw+”,”; // Open the serial port if(m_ctrlComm.GetPortOpen()) m_ctrlComm.SetPortOpen(FALSE); m_ctrlComm.SetCommPort(selcom); // Select the serial port if(!m_ctrlComm.GetPortOpen()) m_ctrlComm.SetPortOpen(TRUE); // Open the serial port else AfxMessageBox("cannot open serial port"); // Set the serial port properties m_ctrlComm.SetSettings(para); // Baud rate, parity, data bits, stop bits m_ctrlComm.SetInputMode(1); //1: indicates that data is retrieved in binary mode m_ctrlComm.SetRThreshold(1); //Parameter 1 indicates that an OnComm event for receiving data will be triggered whenever there are more than or equal to 1 character in the serial port receive buffer m_ctrlComm.SetInputLen(0); //Set the current receive buffer data length to 0 m_ctrlComm.GetInput(); //Read the buffer first to clear residual data return TRUE; 3.2.2 Respond to serial port events and process data The process of the host computer sending data to the PLC is actually sending the command string to the serial port according to the PLC's communication protocol. The process of the host computer receiving PLC data is actually extracting the useful data according to the frame format specified in the PLC communication protocol. (1) Communication protocol of OMRON PLC (C200HX) The communication protocol used in this paper is host computer link communication. Host computer link communication is achieved by exchanging commands and responses between the host computer and the PLC. The command and response data transmitted in one exchange is called a frame, and a frame can contain a maximum of 131 data characters. The command frame format is as follows: The identification code and the body depend on the transmitted host computer link command. When a combined command is transmitted, there will also be a second identification code (sub-identification code). The FCS (Frame Check Sequence) code is calculated by the host computer and set in the command frame. The command frame can be up to 131 characters long. A command equal to or greater than 132 characters must be divided into several frames. The command is segmented using a carriage return delimiter (CHR$(13)) instead of a terminator. The terminator must be used at the end of the last frame. The response frame format identification code and the body depend on the received host computer link command. The end code indicates the status of the command completion (i.e., whether an error has occurred). When the response exceeds 132 characters, it must be divided into several frames. A delimiter (CHR$(13)) will be automatically set at the end of each frame instead of a terminator. The terminator must be set at the end of the last frame. (2) Respond to the OnComm event and process the data // Send event void test_com::OnSend() { // Write the command code string to be sent according to the command frame format in (1) CString m_send // Send this string to the serial port m_ctrlComm.SetOutput(COleVariant(m_send)); } // Receive event void test_com::OnComm() { if (m_ctrlComm.GetCommEvent() = 2) // An event value of 2 indicates that there are characters in the receive buffer { COleVariant m_input = m_ctrlComm.GetInput(); // The data in m_input is the received data. Extract the valid data according to the response frame format UpdateData(FALSE); } } 4. Conclusion Through specific applications in actual development, a specific implementation method for the serial port device communication module in configuration software is proposed, which has important application value in practical applications. References [1] Ma Guohua, Monitoring Configuration Software and Its Application, Tsinghua University Press, 2001.8 [2] Wang Yamin, Chen Qing, Liu Changsheng, Wang Shuiping, Configuration Software Design and Development, 2003.4 [3] Li Xianyong, Visual C++ Serial Communication Technology and Engineering Practice, People's Posts and Telecommunications Press, 2002.5
Read next

CATDOLL Katya Hybrid Silicone Head

The hybrid silicone head is crafted using a soft silicone base combined with a reinforced scalp section, allowing durab...

Articles 2026-02-22