Data transmission using MODBUS Protocol Driver. Serial Communications and via TCP/IP. MODBUS RTU ASCII Modus. Modbus Library with Master, Client and Slave support.
Serial Communications and via TCP/IP. MODBUS RTU ASCII Modus. Data transmission using MODBUS Protocol. Modbus Library.
SuperCom - MODBUS Protocol Library
MODBUS Protocol Library
MODBUS is a industrial data communication protocol to be used over serial lines (serial communications protocol) and over TCP/IP connections.
The SuperCom MODBUS Protocol Library provides a rock solid foundation to develop fast and easy MODBUS capable applications. It hides the complex protocol details and enables data communication with ease thus saving valuable time, reducing costs and ensuring quality results.
The SuperCom MODBUS Protocol Library supports data communication between devices connected to a serial port, on a bus system or network. The protocol module supports ASCII and RTU (Remote Terminal Unit) operation mode (ASCI mode transfers ASCII codes and RTU binary data bytes in binary mode).
There is only one API to learn! The same functions and parameters with serial, TCP/IP or ISDN type of connections and operation mode (MODBUS/ASCII, MODBUS/RTU).
The SuperCom MODBUS Protocol Library also supports custom function codes and data packets by implementing functions that communicate transparently. Controling machine specific extensions is realy easy using these functions.
Accomplish with ease
In most cases only a handful functions are needed to talk to the PLC. Your project is updated real fast. A lot of functions is backing you up to accomplish different tasks or configurations.
- Run multiple Modbus masters.
- Connect one or more Modbus RTU or ASCII masters to one or more Modbus slaves.
- Receive Modbus data packets and simulate one or more Modbus slaves or Protocol Gateway.
- The Modbus protocol module can control, based on the used SuperCom software, serial and/or TCP connections.
- The MODBUS protocol module can run concurrently connections thus polling more than one plc the same time is possible.
The SuperCom MODBUS Protocol Library uses the SuperCom Communication Layer which provides a rock solid foundation to develop data communication software fast and without headache. Thus it makes no difference to the programmer if the MODBUS protocol used over TCP/IP or serial lines (RS-232, RS-422, RS-485, Modem, TAPI).
Samples - MODBUS Protocol API:
1. Read a single coil
C/C++
#define SLAVE_ID 1
BYTE Com = COM_2; // Use serial port COM2
ComInit (Com);
ComSetState (Com, 9600, ...);
:
RS_MBSetConfig(Com,,SuperCom.MODBUS.MODBUS_MODE_RTU,,);
if (RS_MBReadCoil (Com,
SLAVE_ID,
wCoil,
&Buffer))
{
printf("Coil[%d] = %s ", wCoil, Buffer?"TRUE":"FALSE");
}
else
{
int ErrorCode = RS_MBGetLastError(Com);
if (ErrorCode == MB_ERR_EXCEPTION)
printf("Exception %02X reported from slave ", RS_MBGetException(Com));
else
printf("Error %d", ErrorCode);
}
ComReset (Com);
Delphi
Const SLAVE_ID = 1;
Com = COM_2; // Use serial port COM2
Var ErrorCode:Integer;
ComInit (Com);
ComSetState (Com, 9600, ...);
:
RS_MBSetConfig(Com,,SuperCom.MODBUS.MODBUS_MODE_RTU,,);
If (RS_MBReadCoil (Com,
SLAVE_ID,
wCoil,
Buffer)) Then
Write('Coil[', wCoil, '] =', Buffer)
Else
Begin
ErrorCode = RS_MBGetLastError(Com);
If (ErrorCode = MB_ERR_EXCEPTION) Then
Write('Exception ', RS_MBGetException(Com), ' reported from slave ')
Else
Write('Error %d', ErrorCode);
End;
ComReset (Com);
C# using the TSCom class (ActiveX API)
SCom = new MYSCOM(Com, frm1);
SCom.Settings = "9600,N,8,1";
SCom.PortOpen = true;
:
SuperCom.MODBUS.RS_MBSetConfig(Com,,SuperCom.MODBUS.MODBUS_MODE_RTU,,);
if (SuperCom.MODBUS.RS_MBReadCoil (Com,
SLAVE_ID,
wCoil,
Buffer))
WriteLine("Coil[{0}] = {0}", wCoil, Buffer);
else
{
int ErrorCode = SuperCom.MODBUS.RS_MBGetLastError(Com);
if (ErrorCode = MB_ERR_EXCEPTION) Then
{
WriteLine("Exception {0} reported from slave", SuperCom.MODBUS.RS_MBGetException(Com));
}
else
{
WriteLine("Error {0}", ErrorCode);
}
}
SCom.PortOpen = false;
Visual Basic
Const SLAVE_ID = 1
Const Com = COM_2 ' Use serial port COM2
Dim ErrorCode As Integer
Call ComInit (Com)
Call ComSetState (Com, 9600, ...)
:
Call RS_MBSetConfig(Com,,SuperCom.MODBUS.MODBUS_MODE_RTU,,)
If (RS_MBReadCoils(Com, _
SLAVE_ID, _
wFromCoil, _
wCount, _
cBuffer(0))) Then
WriteLine ("Response (" & Format(wCount) & " bits), Coil:" & Format(wFromCoil) & vbCrLf)
Else
ErrorCode = RS_MBGetLastError(Com)
If (ErrorCode = MB_ERR_EXCEPTION) Then
WriteLine ("Exception " & Format(RS_MBGetException(Com)) & " reported from slave " & vbCrLf)
End If
End If
Call ComReset (Com);
|
2. Read/Write Registers
C/C++
#define SLAVE_ID 1
BYTE Com = COM_2; // Using serial port COM2
WORD Buffer [10];
WORD wStart=0x0000;
WORD wCount=1;
WORD wValue=0x0020;
:
ComInit (Com);
ComSetState (Com, 9600, ...);
:
RS_MBSetConfig(Com,,SuperCom.MODBUS.MODBUS_MODE_RTU,,);
if (RS_MBWriteRegister(Com, SLAVE_ID, wStart, wValue))
printf ("Read Success.\n");
else
printf ("Error: %d\n", RS_MBGetLastError(Com));
if (RS_MBReadHoldingRegisters(Com,
SLAVE_ID,
wStart,
&wCount,
Buffer))
{
printf("Read %d Register:", wCount);
for (int i=0; i<wCount; i++) printf ("%4X",Buffer[i]);
}
else
printf ("Error: %d\n", RS_MBGetLastError(Com));
ComReset (Com);
Delphi
Const SLAVE_ID = 1;
Com = COM_2; // Use serial port COM2
Var ErrorCode:Integer;
Buffer:Array [0..9] Of Word;
wStart:WORD=$0000;
wCount:WORD=1;
wValue:WORD=0x0020;
:
ComInit (Com);
ComSetState (Com, 9600, ...);
:
RS_MBSetConfig(Com,,SuperCom.MODBUS.MODBUS_MODE_RTU,,);
If (RS_MBWriteRegister(Com, SLAVE_ID, wStart, wValue)) Then
WriteLn('Read Success.')
Else
WriteLn('Error: ', RS_MBGetLastError(Com));
If (RS_MBReadHoldingRegisters(Com,
SLAVE_ID,
wStart,
&wCount,
Buffer)) Then
Begin
Write('Read ', wCount, ' Register:');
For I:=0 To wCount-1 Do Write(Hex(Buffer[i]));
End
Else
WriteLn('Error: ', RS_MBGetLastError(Com));
ComReset (Com);
C# using TSCom class (ActiveX API)
int ErrorCode
int Buffer=new int[10];
int wStart ,wCount, wValue;
wStart = 0x0000; wCount = 1; wValue = 0x0020;
:
SCom = new MYSCOM(Com, frm1);
SCom.Settings = "9600,N,8,1";
SCom.PortOpen = true;
:
SuperCom.MODBUS.RS_MBSetConfig(Com,,SuperCom.MODBUS.MODBUS_MODE_RTU,,);
if (SuperCom.MODBUS.RS_MBWriteRegister(Com, SLAVE_ID, wStart, wValue))
WriteLine ("Read Success.\n");
else
WriteLine("Error: {0}", RS_MBGetLastError(Com));
if (RS_MBReadHoldingRegisters(Com,
SLAVE_ID,
wStart,
ref wCount,
ref Buffer))
{
WriteLine("Read {0} Register:", wCount);
for (int i=0; i<wCount; i++)
WriteLine("{0:x4}",Buffer[i]);
}
else
printf ("Error: {0}\n", RS_MBGetLastError(Com));
SCom.PortOpen = false;
Visual Basic
Const SLAVE_ID = 1
Const Com = COM_2 ' Use serial port COM2
Dim ErrorCode As Integer
Dim Buffer(10) As Integer
Dim wStart ,wCount, wValue As Integer
wStart = &H0000 : wCount = 1 : wValue = &H0020
:
Call ComInit (Com)
Call ComSetState (Com, 9600, ...)
:
Call RS_MBSetConfig(Com,,SuperCom.MODBUS.MODBUS_MODE_RTU,,)
If (RS_MBWriteRegister(Com, SLAVE_ID, wStart, wValue)) Then
WriteLine("Read Success.")
Else
WriteLine("Error: " & Format(RS_MBGetLastError(Com)));
If (RS_MBReadHoldingRegisters(Com,
SLAVE_ID,
wStart,
&wCount,
Buffer(0))) Then
WriteLine("Read " & Format(wCount) & " Register:" &vbCrLf);
For I=0 To wCount-1 Do WriteLine(Hex(Buffer[i]));
Else
WriteLine("Error: " & Format(RS_MBGetLastError(Com)));
EndIf
Call ComReset (Com);
|
Capture, Store, Forward - MODBUS Slave or Gateway functions
Communication at lower data packet level is possible thus allowing to capture, store and forward of MODBUS data packets or transmit replies. Monitoring MODBUS data packets, simulating a MODBUS Slave or building a protocol converter / gateway is possible. Simulating a MODBUS Slave can be very handy while testing the software.
License Information
Executables developed using SuperCom MODBUS Protocol Module can be distributed royalty free.
Supported compilers
C++, C#, Delphi, Visual C++, Visual Basic, Visual Basic NET, C++ Builder, Borland C/C++, Microsoft C/C++, Borland Pascal, VBA, LabView, PowerBuilder and other Windows programming tools (MS .NET ?).
Samples
for C/C++, C#, Visual C++, C++ Builder, Pascal/Delphi, Visual Basic, Visual Basic NET (VB .NET), LabVIEW.
How to use?
The SuperCom MODBUS Protocol library can be used over any communication link supported by SuperCom (currently Serial, TCP/IP, ISDN). For a list of available SuperCom packages incl. support for MODBUS see the following chart.
The use of one common API for Serial, TCP/IP and ISDN applies here too.