Implementation of serial communication between RS-485 frequency converter and PC
2026-04-06 06:47:07··#1
Abstract: RS-485 serial communication can ensure fast, stable and long-distance data transmission, and has been increasingly used in industrial control. This paper introduces the hardware characteristics, communication protocol and software implementation of serial communication between SANKEN inverter and PC based on RS-485. Experiment shows that the communication software has stable performance and good practical effect. Keywords: serial communication; RS-485; inverter 1 IntroductionCurrently , RS-485 is the most widely used field control bus in China. The common-mode output voltage of the RS-485 bus is between -7V and +12V, possessing the ability to suppress common-mode interference. The maximum data transmission rate is 10Mbit/s, and theoretically, the maximum transmission distance can reach 15 kilometers at a baud rate of 1200bps. RS-485 networks are widely adopted by frequency converter manufacturers due to their advantages such as simple equipment, ease of implementation, long transmission distance, and convenient maintenance. This article analyzes the reasons for choosing RS-485 for serial communication in industrial environments, discusses the hardware characteristics, communication protocol, and software implementation of RS-485-based serial communication between a Sanken frequency converter and a PC. Experiments show that the communication software is stable and reliable, allows for intuitive viewing of the actual operating status of the frequency converter, and facilitates the setting and modification of multiple sets of parameters. This software greatly facilitates the operation and control of the frequency converter by engineers and customers. 2. Comparison of RS-232 and RS-485 There are two commonly used serial communication methods: RS-232 serial communication and RS-485 serial communication. Because of its ease of use, serial communication is widely used in industrial control for data exchange. However, industrial equipment often operates in harsh environments, potentially subject to noise or power harmonic interference. RS-232's interference resistance in such environments is far inferior to RS-485. Furthermore, RS-232 only supports one-to-one control, while RS-485 can achieve one-to-many control; RS-232 typically uses a 9-pin male connector, while RS-485 requires only two wires. Therefore, RS-485 serial communication is the most common method used in industrial environments. 3. Serial Communication between Sanken Inverters and PCs 3.1 Hardware and Software Environment Hardware Configuration: One PC (equipped with a standard RS-232), one RS-232/RS-485 conversion card, one ISI communication card, and three Inverters (Sanken inverters ES-0.4KW, SPF-11KW, and IPF-90KW). The software includes: Windows XP operating system, Microsoft Visual Basic 6.0 Chinese version, Sanken inverter communication protocol guide, etc. 3.2 Communication Protocol The communication protocol formats provided by various series of Sanken inverters are as follows: 1. Instruction Format: The instruction format is shown in Figure 1, and the meaning of each field is shown in Table 1. 2. Detailed Explanation of Instructions Figure 1 shows the instruction format, with a total of 25 instructions, determined by the opcode (OP), consisting of AQ and R, S, x, y, z, a, b, c respectively. The detailed structure of the instructions is explained using instructions C and N, as shown in Table 2. Table 1 Meaning of Each Field in the Instruction 3. Communication Error Handling Performed by the Inverter If the inverter detects an error in the instructions received from the host computer, it will perform the following processing: ① In case of parity error, checksum error, or undefined instruction code: The returned error instruction is the instruction code "?". Simultaneously, the DT item returns a one-byte communication error code. ② When the data in the DT item is too long or insufficient and cannot be interpreted: If the data defined by each instruction of the received command is too long or insufficient, or the received command cannot be interpreted, the error handling is the same as ①. ③ Timeout handling: After receiving the start code, if all instructions cannot be received within 150ms, timeout handling will be performed, forcing the completion of the receiving state. At this time, the inverter will return the communication error code "d". ④ Communication error codes are: "p" represents parity error; "s" represents checksum error; "u" represents undefined operation code; "d" represents data too long, data insufficient, or data cannot be interpreted. ⑤ Other errors: Errors related to receiving computer instructions, except in the above situations, will be timed out, which is "no response" for the computer. 4. Inverter and computer instruction sending and receiving method: The basic procedure of serial communication is that a computer sends instructions to an inverter, and then the inverter sends back an acknowledgment to the computer. Therefore, the inverter must send back an acknowledgment after receiving the instructions sent by the computer. If the computer continues to send multiple instructions without receiving an acknowledgment, normal operation cannot be guaranteed. Due to inverter malfunction or communication line failure, the computer may be unable to receive the inverter's response. To avoid communication program lockout caused by waiting for the inverter's response, the computer will perform a receive timeout process for a set period of 2 seconds or longer. Table 2 provides detailed examples of the instructions. 3.3 Serial Communication Program Implementation Due to space limitations, only the implementation code of the communication part is introduced here, mainly including: the definition of the communication port, the setting of the communication rate, communication sending, communication receiving, communication error handling, and exit. The main code is as follows: … MSComm1.CommPort=1 'Select communication port 1 MSComm1.Settings="4800,o,8,1" 'Set to 4800bps, odd, 8 data bits, 1 stop bit MSComm1.RThreshold=1 'Comm Evert occurs when a character is received MSComm1.InputLen=0 'Clear input buffer data? MSComm1.PortOpen=True 'Open communication port? Timer1.Interval=1000 'Receive timeout (ms) 1 second Tx="*01C"? 'Set the data to be transmitted to the inverter TxLen=Len(Tx) 'Get the length of the transmitted data (excluding checksum and stop bits) Sum=0 For i=1 To TxLen Sum=Sum+Asc(Mid(Tx, i, 1)) Next i Sum=((0-Sum)And 127) Or 64 Tx=Tx+Chr(Sum)+vbCrLf 'Add checksum and stop bit (CR+LF) to the transmission code Timer1.Enabled=True 'Start the receive timeout detection counter MSComm1.Output=Tx 'Transmit data to the inverter End Sub Private Sub MSComm1_OnComm() '[Receive data through Comm event] Dim Rx As String, RxLen As Integer,Sum As Integer Dim Msg As String If MSComm1.CommEvent<>comEvReceive Then Exit Sub 'Confirm that the received data is a Comm event Do Rx=Rx+MSComm1.Input 'Receive data from the inverter DoEvents Loop Until Right(Rx,2)=(Chr(13)& Chr(10)) 'Find the stop bit Timer1.Enabled=False 'Cancel the timeout timer RxLen=Len(Rx)-2 'Received data word length (excluding stop bits) Sum=0 'Calculation of received checksum For i=1 To RxLen-1 Sum=Sum+Asc(Mid(Rx, i,1)) Next i Sum=((0-Sum)And 127)Or 64 If Mid(Rx, RxLen, 1)=Chr(Sum) Then 'Check the checksum Msg=Left(Rx, RxLen) ' Receive data (including checksum, excluding stop bits) Else Msg="Check Sum NG"? 'Display checksum error End If MsgBox "Received Data=" & Msg 'Display received data MSComm1.PortOpen=False '[Close communication port] End Sub ' When the inverter's output frequency is 20 Hz, running this program will display "*01C02000@" in the information box . Conclusion This article first compares RS-232 and RS-485, then introduces the implementation of serial communication between a Sanken frequency converter and a host computer based on RS-485. Experiments show that the human-machine interface developed using VB is easy to operate and achieves good practical results. Using the RS-485 protocol for serial communication can ensure fast, stable, and long-distance data transmission. It will undoubtedly see increasing applications in current and future industrial control and other fields. References [1]. Fan Yizhi, Chen Liyuan. Visual basic and RS-232 serial communication control [M]. Tsinghua University Press, 2004-6. [2]. Mitsubishi Electric Corporation. Inverter principle and reference tutorial [M]. National Defense Industry Press, 1998-9. [3]. Yang Xianhui et al. Fieldbus technology and its application [M]. Tsinghua University Press, 2001-2. [4]. Wang Mingyan, Zhao Yi. A communication method based on RS-485 interface [J]. Microcomputer Information. 2006-2 (1). P220-222. The paper's innovations: The design of serial communication between Sanken inverter and PC was completed. The communication software is stable and reliable, can intuitively view the actual operating status of the inverter, and can conveniently set and rewrite multiple sets of parameters. Through this software, it greatly facilitates the operation and mastery of the inverter by engineers and customers. Author Biography: He Ankun, male, born in June 1972, Han nationality, lecturer, Master's degree, research interests: microcontroller and embedded system development, computer applications. Email: [email protected]