Share this

Research on serial communication between PC and frequency converter

2026-04-06 05:36:13 · · #1

introduction

Computer serial communication is a communication method for data transmission between a computer and control equipment (such as a frequency converter), and it is also a commonly used communication mode for industrial automatic control. Each communication method has a strictly defined corresponding communication protocol. To ensure normal communication between the computer and the frequency converter, the communication program must be written according to the frequency converter's communication protocol. This paper takes the Ripu frequency converter with an RS-485 communication interface as the research object, designs a network monitoring scheme for the frequency converter, and realizes online monitoring and control of various parameters of the frequency converter. The following section describes how to write a serial communication program between the computer and the Ripu frequency converter (RP3200) using API functions in the C++Builder programming environment.

Serial communication

Serial communication has always held an extremely important position in the field of industrial system control. Serial ports (RS-232) are a standard configuration on computers and are often used to connect modems to transmit data. They can be seen in the computer's hardware device manager and are defined as COM1, COM2, etc. There are two commonly used serial communication methods: RS-232 and RS-485. This article will use RS-485 as an example for introduction.

Write a communication program using C++Builder API functions.

C++ Builder itself does not provide a standalone serial communication component. This doesn't mean it can't use this functionality, but rather that it must use certain Windows API functions to achieve this. Windows APIs are functions provided by the operating system, offering programmers a considerable amount of execution capabilities. Even the operating system itself is composed of these API functions. Since Win32 APIs are already declared, they can be used directly. However, they must be used according to their definitions to obtain correct results, especially the parameter definitions. Care must be taken to ensure they match the definitions; otherwise, errors will occur. The following explains these essential functions.

API functions related to serial communication in C++ Builder

C++Builder itself does not provide a separate serial communication component; instead, it uses functions from the Windows API to achieve this. These functions are provided by the operating system and offer programmers a considerable amount of execution capabilities. There are approximately 20 functions related to serial communication in the API; the following discussion focuses on some of the frequently used ones.

Open the serial port

hcomm=createfile(comno,generic_read|generic_write,

0, null, open_existing, 1, 0)

The function parameters are defined as follows:

hcomm: The return value of the createfile() function. The program uses this return value to perform related serial port operations.

comno: Defines the serial port number, such as com1, com2, etc.

generic_read|generic_write: Read/write operations on the serial port.

0: Whether to share the serial port. Usually, the serial port is not shared with other programs, so set it to 0; otherwise, set it to 1.

null: Whether the function's return value hcomm can be inherited by subroutines; here it is set to not be inheritable.

open_existing: The way to open a port. A serial port is a device and must be specified as open_existing.

1: Use synchronous or asynchronous mode to transmit data. The frequency converter is asynchronous, so it is set to 1.

0: Set to 0 because serial port programming is used.

Get serial port status

getcommstate(hcomm,&dcb)

The function parameters are defined as follows:

hcomm: The return value of the createfile() function.

DCB: Serial port control block address, responsible for setting serial port parameters. Specific parameters are as follows:

dcb.baudrate: Sets the baud rate of the serial port. There are several options, such as 19200kb/s, 9600kb/s, and 4800kb/s. The most common setting is 9600kb/s.

dcb.bytesize: Sets the number of bits for the serial port data. There are 5, 6, 7, and 8 bits. The inverter's data bit width is 8 bits.

dcb.parity: Sets the parity check for the serial port. It has several options: none, even, and odd. Set it to none.

dcb.stopbits: Sets the number of stop bits for the serial port. It can be 1, 1.5, or 2. The stop bit of the frequency converter is 1.

Set serial port status

setcommstate(hcomm,&dcb)

The function parameter definition is the same as that of the getcommstate() function.

Write data to serial port

writefile(hcomm, senddata, bs, &lrc, null)

The function parameters are defined as follows:

hcomm: The return value of the createfile() function.

senddata: The address to write data to.

bs: Number of bytes of data written.

lrc: The address of the data to be written.

null: Synchronization check for written data. It can be set to null when the serial port uses synchronous communication.

Clear serial port errors or send the current data status of the serial port to the input buffer.

clearcommerror(hcomm,&dwerror,&cs)

The function parameters are defined as follows:

hcomm: The return value of the createfile() function.

dwerror: Returns an error message code.

cs: A structure variable pointing to the serial port status.

Read data from the input buffer of the serial port.

The function `readfile(hcomm, inbuff, cs.cbinque, &nbytesread, null)` has the following parameter definitions:

hcomm: The return value of the createfile() function.

inbuff: Points to the address used to store data.

cs.cbinque: The number of bytes of data read.

nbytesread: Total number of bytes read.

null: If no background work is performed, the serial port is set to null.

Close the serial port

closehandle (hcomm)

The function parameters are defined as follows:

hcomm: The return value of the createfile() function.

Design of a monitoring system for frequency converters

Hardware connection diagram

The monitoring system designed in this paper uses balanced transmission and differential reception for communication. Because the transmission line typically uses twisted-pair cable and differential transmission, it has strong immunity to common-mode interference. The maximum communication distance of RS-485 is 1219m, and the maximum transmission rate is 10mb/s. RS-485 operates in half-duplex mode and supports multi-point data communication. The bus network topology generally adopts a terminal-matched bus structure.

The RS-485 bus typically supports a maximum of 32 nodes.

This design uses a Ripu RP3200 frequency converter with an RS-485 interface to control the motor operation. A host computer communicates with the frequency converter, and the computer monitors the frequency converter's operating status by reading and writing its parameters. The host computer is the master control computer, and the slave computers are the controlled frequency converters (up to 31). The serial control signal between the master and slave is always initiated by the master control, with the slave responding accordingly. At any given time, the master control and a slave are transmitting signals, so each slave must be pre-assigned an address number, and the master control specifies the address to execute the transmission. After receiving the signal from the master control, the slave executes its function and returns a response to the master control. Since the computer itself supports RS-232 serial communication, an RS-232 to RS-485 converter is needed to connect the computer and the frequency converter. The network structure of the host computer and frequency converter control is shown in Figure 1.

Inverter communication function settings

This frequency converter offers three control commands and methods: digital panel control, terminal control, and RS-485 communication control. The default factory setting is control via the frequency converter control panel, which does not align with our PC-based control system.

To enable communication between the frequency converter and the PC, we configure the frequency converter as follows:

Operation method selection

In the digital panel, select parameter settings and set the operating mode to rs-485 operating mode according to Table 1.

Communication parameter settings

Communication address settings: Define device addresses 1–31. Two devices are not allowed to share the same address while online.

Transmission interruption detection time: Set range: 0-60 seconds

Communication specification settings:

Interface: RS-485 Synchronization Method: Asynchronous

Transmission parameters:

Baud rate: Selectable from 1200, 2400, 4800, 9600, 19200, etc.

Stop bit: fixed at 1 bit

Inverter Communication Command Introduction

Communication digital format

The digital format is shown in Figure 2.

1 start bit, 8 data bits, odd parity, 1 stop bit.

Error correction method

Add a checksum to the end of the information. The checksum is equal to the last byte of the sum of all bytes (hex), and then convert it to ASCII code.

Data packet format

Similar to the modbusascii format, the format is as follows.

headerakp1p0d3d2d1d0sdelimiter

Format parsing:

[header]: 3ah

【delimiter】:0dh,0ah

a, k, p1p0, d3d2, d1d0, and s are single-byte hexadecimal numbers, which are converted to ASCII codes.

【a】: Slave (inverter) address. The inverter address range is (1-31), and 'a' must exist.

Note: When address a=00h, it is valid for all slave devices, and none of the slave devices will send back a response. Therefore, a=00h can only send run commands.

【k】: Data packet function code.

【p1p0】: Parameter number. Parameter label, a two-byte hexadecimal number.

【d3d2d1d0】: Parameter value: The parameter value with the decimal point removed, a total of four bytes of hexadecimal number, with the high-order byte sent first and the low-order byte sent later.

【s】: Checksum. s is the sum of the hexadecimal values ​​of all the bytes above (a+k+p1p0+d3+d2+d1+d0), taking the last byte (bit7-bit0), and converting it to ASCII code.

The definitions of parameters k, p, d3d2d1d0 are shown in Table 3.

Implementation of serial communication program between computer and frequency converter

Design architecture of the main communication program

The main function of the communication program is to enable the computer to control the operation and monitor the status of the frequency converter, thus forming a closed-loop monitoring system. The program architecture is shown in Figure 3.

Example 1: Setting Variable Frequency Start-up Parameters

Inverter #1 changes its "set frequency" to 35.00 Hz while in operation.

The method is as follows:

35.00 minus the decimal is 3500d=0dach

a=1=01h (Inverter address is "01h")

k=04h (Running parameter set to "04h")

p1p0=0001h (Runtime frequency is set to "0001h")

d3=00h (the high byte of the data is "00h")

d2=00h (the second highest byte of the data is "00h")

d1=0dh (the second byte of the data is "0dh")

d0 = ach (the low byte of the data is "ach")

s=c9h (and the checksum is "c9h")

(s=0bh+04h+00h+01h+00h+00h+00h+0dh+ach=c9h)

The host sends the following data packets in ASCII format sequentially:

3ah, 30h, 42h, 30h, 34h, 30h, 30h, 30h, 31h, 30h, 30h, 30h, 30h, 30h, 44h, 41h, 43h, 43h, 39h, 0dh, 0ah

The frequency converter replies with the same data as the host.

The following is a partial communication code:

Code to open communication port

char*comno;

dcbdcb;

stringtemp;

temp="com"+inttostr(rdcom-》itemindex+1);

comno = temp.c_str();

hcomm=createfile(comno,generic_

read|generic_write, 0, null, open_existing, 0, 0);

if (hcomm==invalid_handle_value)

{

statusbar1->simpletext="Error opening communication port!";

return;

}

else

statusbar1->simpletext="Port is open!";

sleep(100);

getcommstate(hcomm,&dcb);

dcb.baudrate=cbr_9600;

dcb.bytesize=8;

dcb.parity=noparity;

dcb.stopbits = onestopbit;

setcommstate(hcomm,&dcb);

if(!setcommstate(hcomm,&dcb))

{

statusbar1->simpletext="Communication port setting error!";

closehandle(hcomm);

return;

}

Send data code

inti=0;

unsignedcharsends[21];

unsignedlonglrc, bs;

sends[0]=3ah;//header

sends[1]=30h;//a

sends[2]=31h;

sends[3]=30h;//k

sends[4]=34h;

sends[5]=30h;//p1

sends[6]=30h;

sends[7]=30h;//p0

sends[8]=31h;

sends[9]=30h;//d3

sends[10]=30h;

sends[11]=30h;//d2

sends[12]=30h;

sends[13]=30h;//d1

sends[14]=44h;

sends[15]=41h;//d0

sends[16]=43h;

sends[17]=43h;//s

sends[18]=39h;

sends[19]=0dh;//delimiter

sends[20]=0ah;

for (i=0;i++;i<21)

{

if (hcomm == 0)

return;

writefile(hcomm,sends,1,&lrc,null);

}

Receive data code

intln;

unsignedlonglrc, bs;

charinbuff[1024];

dwordnbytesread,dwevent,dwerror;

comstatcs;

if (hcomm == 0)

{

mreceive->text="There was a problem with the reading process, it has exited!";

return;

}

if (hcomm==invalid_handle_value)

{

mreceive->text="There was a problem with the reading process, it has exited!";

return;

}

clearcommerror(hcomm,&dwerror,&cs);

if (cs.cbinque)

{

readfile(hcomm, inbuff, cs.cbinque, &nbytesread, null);

inbuff[cs.cbinque]=`\0`;

mreceive->text=inbuff;

interceptrece(mreceive-》text);

}

else

mreceive->text="No data read!";

The above code was successfully debugged and compiled on the Windows XP SP2 operating system and in the C++ Builder 6 programming environment.

Conclusion

Based on the research of the Ripu series frequency converters with RS-485 communication interfaces, a feasible frequency converter network monitoring system scheme was designed. Using API functions in the C++Builder programming environment, online monitoring and control of various frequency converter parameters were achieved, improving the automation level of frequency converter control.

Read next

CATDOLL 146CM A-CUP/B-CUP Miho (TPE Body with Hard Silicone Head)

Height: 146cm A-cup Weight: 26kg Shoulder Width: 32cm Bust/Waist/Hip: 64/54/74cm Oral Depth: 3-5cm Vaginal Depth: 3-15c...

Articles 2026-02-22