Click or drag to resize

PLCCom Class Library for Modbus

Indi.An PLCCom for Modbus Class Library Reference






First steps PLCCom Modbus API for .NET

What is Modbus, anyway?

Modbus is a serial communications protocol originally published by Modicon (now Schneider Electric) in 1979 for use with its programmable logic controllers (PLCs). Simple and robust, it has since become a de facto standard communication protocol, and it is now a commonly available means of connecting industrial electronic devices.[1] The main reasons for the use of Modbus in the industrial environment are:

  • developed with industrial applications in mind
  • openly published and royalty-free
  • easy to deploy and maintain
  • moves raw bits or words without placing many restrictions on vendors


Modbus enables communication among many (approximately 240) devices connected to the same network, for example a system that measures temperature and humidity and communicates the results to a computer. Modbus is often used to connect a supervisory computer with a remote terminal unit (RTU) in supervisory control and data acquisition (SCADA) systems. Many of the data types are named from its use in driving relays: a single-bit physical output is called a coil, and a single-bit physical input is called a discrete input or a contact. (Source Wikipedia, Permalink: http://en.wikipedia.org/w/index.php?title=Modbus&oldid=639641882)

What provides PLCCom for Modbus?

The PLCCom for Modbus-API equips .NET or JAVA developer to realize optimized Modbus-Accesses from self created applications. It provides Master- Slave- components. The libraries are (depends on Verion) 100% JAVA or 100% .NET files. The driver can be used as a direct reference. No need for API- invocations. You can use the driver at 32-or 64 Bit-Environments and across platforms trouble-free. Further PLCCom Modbus features:
  • Access via TCP, UDP, RTU, RTU over TCP or ASCII
  • integrated ModBus-Master components
  • integrated ModBus-Slave components
  • The internal routines are optimized for High-Performance-accesses Various recurring read accesses can be combined into a collection; thereby Modbus requests are combined to an absolute minimum.
  • Optional 32-Bit Register-Modus to plotting 32-Bit-Numbers in a Register (Usually other tool only provide 16Bit-Register)
  • Read and write all logiclly primitives .Net/Java-data types. Including converting with an adjustable method (e.g. Big-Endian, Little-Endian, etc.)
  • Slave-component whit multiple listeners; that means it is possible to make any numbers of accesses to a Modbus Slave available at the same time e.g. TCP Port502, TCP Port503, UDP Port 502, etc.
  • Extensive Logs incl. Record of all sent data
  • Extensive example projects
  • Master- und Slave-simulation to support your development and also helps for putting your programs into operation
  • You receive a large collection of code examples to help and illustrate the connection of your program to a PLC. Usable on your own code.

Which system components require the PLCcom?

Here is an overview of recommended system components:
  • Microsoft .NET Framework 4.7.2 or newer (.Net version) or
  • Microsoft .NET Standard 2.1 or newer (.Net version) or
  • Microsoft .NET Core 3.1 or newer (.Net version) or
  • Microsoft .NET 5 or newer (.Net version) or
  • Microsoft .NET 6 or newer (.Net version) or
  • Microsoft .NET 7 or newer (.Net version) or
  • Microsoft .NET 8 or newer (.Net version) or
To run the attached program examples you need the following programming tools:
  • Visual Studio 2017 or newer (.Net version)

First steps PLCCom-ModBus-Master

Easy integration of the PLCCom-Library with just a few code lines. You need the following integration steps.

table1



Syntax: Create and initialize a Modbus-Master-Object

ModbusMaster Device = new ModbusMaster("user","serial");

Syntax: Creating a Data-connector and bind to the Modbus-Master

Device.SetConnector_TCP("192.168.1.21);

Syntax: Creat a Modbus-Request e.g. read / write data

//read 10 holding register from adress 100
ReadRequest myReadRequest = RequestBuilder.ReadRequestBuilder.Create(1,  //Slave ID
        eReadFunction.F03_Read_Holding_Registers, // function
        100,          //Read start address
        eDataType.SHORT,       //Target Datatype
        10);          //quantity of objects to be read

Syntax: Transfer the Request to Modbus-Master and receive the Result

ReadResult res = Device.Read(myReadRequest);

//evaluate results
Console.WriteLine(DateTime.Now.ToString() + ": " + res.Message);

if (res.Quality == OperationResult.eQuality.GOOD)
{
    StringBuilder sb = new StringBuilder();
    foreach (ReadValue item in res.FetchValues())
     {
  sb.Append("Address " + item.Address.ToString() + " / Pos" + item.AddressPosition.ToString());
  sb.Append(" >> ");
  sb.Append(item.ToString());
  sb.Append(Environment.NewLine);
      }
     Console.WriteLine(sb.ToString());
  }

First steps PLCCom- ModBus-Slave

Providing a PLCCom-Modbus-Slave with just a few code lines. You need the following integration steps.

table2

Syntax: Create and initialize a Modbus-Slave-Object

ModbusSlave Device = new ModbusSlave("user","serial",1); //SlaveID 1

Syntax: Adding at least one Listener

//add TCP listener
slave.AddOrReplaceListener_TCP("listener_tcp1", 502);

//add UDP listener
slave.AddOrReplaceListener_UDP("listener_udp1", 502);

//or add RTU listener
slave.AddOrReplaceListener_RTU("listener_rtu1",
        "COM1",
        eBaudrate.b9600,
        eDataBits.DataBits8,
        Parity.None,
        StopBits.One,
        Handshake.None);

//or add ASCII listener
slave.AddOrReplaceListener_ASCII("listener_ascii1",
        "COM2",
        eBaudrate.b9600,
        eDataBits.DataBits8,
        Parity.None,
        StopBits.One,
        Handshake.None);

Namespaces
Namespace Description
PLCcomModbus.Core Namespace of PLCCom for Modbus Core Functionality
PLCcomModbus.DataAdapter Namespace of PLCCom for Modbus Connectivity and Data Functionality
PLCcomModbus.Master Namespace of PLCCom for Modbus Master Functionality
PLCcomModbus.Slave Namespace of PLCCom for Modbus Slave Functionality