Home > Net >  Written in c # application, read MODBUS_RTU
Written in c # application, read MODBUS_RTU

Time:10-05

Industrial control oneself do, to understand the c # is very weak, now begin to study, for project is urgent, so yourself to study may be in a hurry, to turn to god, is like this:
A batch of equipment of the RS485, now need to make wireless communications, and centralized monitoring, due to large industrial environment interference, no account of WiFi, adopt the ZigBee mode, to convert each device 485 ZigBee wireless signal, through the ZigBee module after receiving through Ethernet cable to connect to PC, the module configuration for the virtual serial port, through the modbus poll software data monitoring to all equipment, now need to make an application reads part of data in each device communications data formats and RTU device address should read as follows, serial form, the best alternative, 9600, 8, N, 1, needs to read from the optional, read address read keep register for equipment (4 x), address data for 0, before have considered using kingview to write, but powerful reason using c #, c #, every brother please have faced similar projects, still hope to give directions

CodePudding user response:

Going to made Winform VS2015 program

CodePudding user response:

C # realize serial communication is the basic function, nothing difficult, can be used directly,
Should consider the original poster is a communication protocol, namely data parsing,

CodePudding user response:

Baidu NModbus4

CodePudding user response:

Read MODBUS_RTU essence is multi-byte receives, using the array processing
2. Send data

Private void SerialPortSend ()
{
if (! SerialPort. IsOpen)
{
MessageBox. Show (" serial port is not open, can't send data!" );
return;
}
Try
{
GB2312 Encoding Encoding=Encoding. GetEncoding (" ");
Byte [] bytes=encoding. GetBytes (data);
SendCount +=(long) bytes. The Length;
SerialPort. Write (0 bytes, bytes. The Length). }
Catch
{
MessageBox. Show (" send failed!" );
}
}



3. Collect data

Private void SerialPort_DataReceived (object sender, SerialDataReceivedEventArgs e)
{
If (this. SerialPortIsReceiving)
{
return;
}
Try
{
SerialPortIsReceiving=true;
A string of text=string. The Empty;
int num;
Text=serialPort. ReadExisting ();
Num=serialPort. Encoding. GetBytes (text) Length;

}
The finally
{
SerialPortIsReceiving=false;
}
}

CodePudding user response:

Read back the data be decimal or hexadecimal
  •  Tags:  
  • C #
  • Related