1. Introduction
In the field of industrial control, frequency converters are often used to control the speed and direction of AC motors. Although frequency converters have their own control interface and are simple and effective, they have drawbacks such as inconvenient on-site operation, poor intuitiveness, and the ability to only achieve single-machine control. To address these shortcomings, modern frequency converters are equipped with RS485 communication interfaces, allowing users to conveniently and flexibly select the powerful functions of the frequency converter. Developing industrial control software under Windows can take advantage of the rich resources of Windows to easily generate various data entry forms and beautiful graphical interfaces.
The MOBus protocol is a general-purpose language used in electronic controllers, enabling communication between controllers. The MSComm communication control, an ActiveX control in Visual C++ 6.0, provides the low-level resources needed for microcomputer development in a Windows environment. This article describes a solution using the MOBus protocol's ASC II transmission mode, implemented through Visual C++ 6.0 programming, to create a computer control system for a Delta VFD-S frequency converter under a Windows environment.
2. System Hardware Design
Most PCs nowadays have RS232 serial ports, but few have RS485 ports. To achieve long-distance and noise-resistant communication with the frequency converter, an RS232/RS485 converter is generally used. The overall system block diagram is shown in Figure 1.
Currently, RS232/485 converters are available in both passive and active types. If the communication distance is short, a passive converter is sufficient. You can either purchase one or design your own.
3. Communication process in ASCII mode under the MOBus protocol and communication requirements of Delta VFD-S inverter.
3.1 Communication process specified by the Mobus protocol
The MOBus protocol is a reliable and efficient communication protocol for industrial control systems, supported by numerous hardware manufacturers and widely used. MOBus data communication is achieved through a query/response mechanism between the master and slave devices. The function code in the query message informs the slave device of the function to be performed, and the data segment contains additional information about the function to be performed. The slave device generates a response message, in which the function code is a response to the function code in the query message. Both the query and response messages contain error detection fields to determine if the transmission is correct.
3.2 Communication data format in ASCII mode II
The Mobus protocol system has two valid transmission modes: ASCII (American Standard Code for Information Interchange) mode and RTU (Remote Terminal Unit) mode. In ASCII mode communication, each 8-bit data in a message consists of two ASCII characters. For example, a 1-byte data 64h (hexadecimal representation), represented as ASCII "64", contains '6' (36h) and '4' (34h).
ASC II mode:
The ASCII mode uses LRC (longitudinal redundancy check) error detection. The LRC error detection value is obtained by summing the data from ADR1 to the last data, with the result in units of 256, and removing any excess (for example, if the result is 1f2h, only f2h is taken). The result after the second complement is the LRC error detection value.
3.3 Communication Requirements for Delta VFD-S Inverters
The VFD-S series AC motor driver has a built-in RS485 serial communication interface. The communication port (RJ-11) is located in the control circuit terminals, and the terminal definitions are as follows: 2: GND 3: SG- 4: SG+ 5: +5V. Pins 2 and 5 are the power supply for the parameter setting panel. Do not use them when performing RS485 communication!
When using the RS485 serial communication interface, each VFD-S model must be pre-assigned a communication address in (9-00), and the computer will then implement control based on its individual address.
4. Introduction to the MSComm control
The MSComm control is a control developed by Microsoft specifically for serial communication. It serves as a bridge between serial communication programs written in high-level languages and the PC's serial port. The MSComm control is provided in VC++ 6.0, allowing users to embed it into their applications for convenient management of computer serial port communication.
One of the challenges when using the MSComm control is processing the data in the input or output buffers. This is because the data written to the output buffer and read from the input buffer are of variant type, while the communication data commonly used in the program may be either text strings or binary numbers. Therefore, it is necessary to handle the conversion between strings and variant type data, as well as the conversion between binary data and variant type data.
The following code briefly demonstrates how to receive and send string or binary values using the MSComm control:
i. Collect strings
variant input1; // Define a variable of type variant input1; // Define a variable of type variant input1;
char *str;
int counts;
counts = mycomm.getinbuffercount(); // Get the number of characters in the receive buffer.
if (counts>0)
{
input1 = myco mm.getinput(); // Read the contents of the receive buffer into input1.
str = (char *)(unsigned char *)input1.parray->pvdata; // Assign the data pointer of the input1 variable to the character pointer.
}
...
ii. Sending a string
cstring senddata1;
senddata1=”atz”;
mycomm.setoutput(colevariant(senddata1));
iii. Receiving binary data
variant input1; // Define a variant type variable
byte rxdata[2048], aa1; // Define an array to store binary data
long len1,k;
colesafearray safearray1; // Define an instance of the colesafearray class
input1 = mycomm.getinput();
safearray1 = input1; // Assign the variant variable to an instance of the colesafearray class.
len1 = safearray1.getonedimsize(); // Use the member function of the safearray class to get the data length.
for (k = 0; k = k ...
iv. Sending binary data
cbytearray array1;
array1.removeall();
array1.setsize();
array1.setat(0, 12);
array1.setat(1, 79);
array1.setat(2, 0xe2);
mycomm.setoutput(colevariant(array1));
5. Communication program writing
The following is a serial communication control program for a Delta VFD-S type frequency inverter using a PC:
(1) Port setting interface (as shown in Figure 3) By setting the port parameters, the control program is made consistent with the inverter's (9-00 9-01 9-04) parameter settings, thereby ensuring normal communication. At the same time, the inverter's (2-00 2-01) parameter is set so that the inverter's control is output through the RS485 communication interface.
(2) Main interface (as shown in Figure 4) The main interface is used to send control information to the frequency converter to control the motor's start, stop, reverse, inching and frequency, etc.
(3) Operation control programming
Send control signals:
Main code (taking forward rotation as an example)
if (nid == idc_radio1)
{
str0=":010620000012" ;
b="0x01"+0x06+0x20+0x00+0x00+0x12;
if (b>0xff)
b="b"&0x0ff;
b="b"︿c; // Calculate the validation b="b"+1;
str1.format("%02x", b);
}
str3 = str0 + str1 + "\r\n";
mycomm.setoutput(colevariant(str3));
Received return information:
The status of the frequency converter is monitored by receiving returned information, including output frequency, output current, operation commands, frequency converter status, and error codes.
To improve program efficiency, data receiving operations are usually performed in the oncomm event. The main code is as follows:
... variant input1; // Define a variable of type variant
char rxdata[2048]; // Define an array to store binary data
long len1,k;
colesafearray safearray1; // Define an instance of the colesafearray class
cstring strdis;
switch(mycomm.getcommevent())
{
case 2: input1 = mycomm.getinput(); // Received rthreshold characters
safearray1 = input1; // Assign the variable to an instance of the colesafearray class.
len1 = safearray1.getonedimsize(); // Use the member function of the safearray class to get the data length.
for(k=0;k safearray1.getelement(&k,rxdata+k);
for(k=0;k {strdis+=rxdata[k];
}
... //Process the received information
6. Summary
This article describes how to implement computer-controlled frequency converter parameter transfer, operation, frequency control, and real-time monitoring in a Windows environment using the MSComm control in VC++ 6.0, following the ASC II mode of the MOBus protocol. Through the hardware and software design of the entire control system, the author achieved computer control of the frequency converter. Experiments show that the system's frequency control is more accurate than using external AVI input, and the system has the advantages of simplicity, reliability, and practicality.