PLCcom Class Library for Modbus
First steps with PLCcom for Modbus .NET
A practical starting point for building Modbus master and slave applications with PLCcom. This page gives you the orientation:
what the SDK provides, which transports are available, and where the first lines of code belong.
Use it as a map before you dive into the API reference.
Move to SecureTCP when certificates, TLS, and controlled trust are required.
The public API keeps both paths close to each other, so applications can grow from a small test tool into a secured production integration.
What is Modbus?
Modbus is a compact industrial communication protocol for exchanging coils, discrete inputs, input registers, and holding registers between automation devices.
It is widely used because the protocol is simple, well understood, and supported by many controllers, meters, drives, gateways, and SCADA systems.
The protocol itself is intentionally small. Real applications still need connection handling, correctly built requests, conversion between .NET values and register bytes, diagnostics, error handling, and often a slave implementation for simulation or integration testing.
What does PLCcom for Modbus provide?
PLCcom for Modbus equips .NET developers to build Modbus master and slave applications without manually assembling telegrams.
The SDK exposes typed request and result objects, master connectors, slave listeners, value conversion, diagnostic logging, and ready-to-use validation applications.
TCP, SecureTCP, UDP, RTU over TCP, RTU, and ASCII with typed request and result objects.
Multiple listeners can run side by side, for example TCP on port 502 and SecureTCP on port 802.
Telegram logging, connection state changes, read collections, and clear operation results for application logs.
16-bit, 32-bit, and 64-bit register modes with byte-order conversion for device-specific layouts.
Read, write, read/write, diagnostics, mask-write, report-server-ID, and CANopen-style access.
Modbus Security over TLS 1.3 or TLS 1.2 with PKI store, certificate validation, and authorization hooks.
System requirements
The .NET package targets the current PLCcom generation and can be used from .NET Framework, .NET Standard, and modern .NET applications.
The build includes targets from .NET Framework 4.7.2 and 4.8 through modern .NET targets up to .NET 10 where the consuming platform provides the required runtime.
For development, use a Visual Studio version that supports the target framework selected by your application.
Serial communication requires access to the configured COM port.
SecureTCP requires certificate material or a writable PKI folder so PLCcom can create the local endpoint certificate on first use.
Communication options at a glance
| Communication type | Typical use | PLCcom entry point |
|---|---|---|
| TCP | Classic Modbus TCP on port 502. |
SetConnector_TCP and AddOrReplaceListener_TCP. |
| SecureTCP | Modbus Security over TLS, usually on port 802. |
SetConnector_SecureTCP and AddOrReplaceListener_SecureTCP. |
| UDP | Connectionless Modbus datagrams where supported by the device. |
SetConnector_UDP and AddOrReplaceListener_UDP. |
| RTU, RTU over TCP, ASCII | Serial and serial-style Modbus communication. | The corresponding RTU, RTU over TCP, and ASCII connector and listener methods. |
Licensing
Before using the library, licence data - user name and serial number - is passed to the device instance:
to the ModbusMaster or ModbusSlave constructor, or through SetUser and SetSerial before the first access.
Evaluation mode: if both fields are left blank, the library runs for 15 minutes with the full functional scope
during a debug session - enough to bring up a connection and read values.
This lets you try the library out before you register. For uninterrupted work, generate yourself a free trial licence (14 days).
Free trial licence: https://www.indi-an.com/en/plccom/modbus/modbus-download/
First steps: Modbus master
A master application is the active side of the communication.
It connects to a Modbus device, sends a request, and evaluates the returned values.
In PLCcom this usually follows the same small sequence.
Create and initialize the master
ModbusMaster master = new ModbusMaster("user", "serial");
master.SetConnector_TCP("192.168.1.21", 502);
Dim master As New ModbusMaster("user", "serial")
master.SetConnector_TCP("192.168.1.21", 502)
Build and execute a read request
ReadRequest request = RequestBuilder.ReadRequestBuilder.Create(
1,
eReadFunction.F03_Read_Holding_Registers,
100,
eDataType.SHORT,
10);
ReadResult result = master.Read(request);
if (result.Quality == OperationResult.eQuality.GOOD)
{
foreach (ReadValue value in result.FetchValues())
Console.WriteLine(value.ToString());
}
Dim request As ReadRequest = RequestBuilder.ReadRequestBuilder.Create(
1,
eReadFunction.F03_Read_Holding_Registers,
100,
eDataType.[SHORT],
10)
Dim result As ReadResult = master.Read(request)
If result.Quality = OperationResult.eQuality.GOOD Then
For Each value As ReadValue In result.FetchValues()
Console.WriteLine(value.ToString())
Next
End If
First steps: Modbus slave
A slave application is the passive side.
It listens for incoming Modbus requests and provides values from its internal data store.
This is useful for real server implementations, device simulation, integration tests, and manual validation tools.
Create the slave and add listeners
ModbusSlave slave = new ModbusSlave("user", "serial", 1);
slave.AddOrReplaceListener_TCP("tcp_502", 502);
slave.SetValue(100, eModbusRegion.HoldingRegister, (ushort)1234);
Dim slave As New ModbusSlave("user", "serial", 1)
slave.AddOrReplaceListener_TCP("tcp_502", 502)
slave.SetValue(100, eModbusRegion.HoldingRegister, CUShort(1234))
Secure Modbus TCP in V9
SecureTCP adds Modbus Security over TLS to the existing TCP model. It is selected through eTypeOfCommunication.SecureTCP and uses
the same request, result, logging, and data-store model as normal TCP.
TLS 1.3 is preferred where both endpoints support it. TLS 1.2 remains available for devices that require it.
The TLS implementation uses BouncyCastle.
The important difference is not how requests are built, but how trust is established before telegrams are exchanged.
PKI store and certificate handling
SecureTCP options are configured through SecureModbusTcpOptions. For applications that should manage their own endpoint identity,
use SecureModbusPkiStore together with SecureModbusOwnCertificate.
The local endpoint certificate and its private key.
Remote certificates that are accepted by the application.
CA certificates for chain validation and certificates that require manual inspection.
PLCcom creates the complete PKI folder structure on first access.
Certificate formats such as DER, CER, PFX, P12, PEM, and key files are handled by the SecureTCP certificate utilities.
If the files are deleted while the process is running, the next TLS credential preparation reloads or recreates the own identity from the PKI store.
Default certificate validation
The default validator accepts a remote certificate when it is trusted and still valid. If the issuing CA certificate is available in
issuers/certs and the certificate chain and validity period are correct, PLCcom copies the leaf certificate to
trusted/certs and accepts it.
If no issuer certificate is available, or the certificate is malformed, unknown, or outside its
validity period, PLCcom stores it in rejected/certs. The integrator can then inspect the certificate and move it to a trusted
store deliberately.
A custom ISecureModbusCertificateValidator can replace the built-in certificate-level validation completely. In that case PLCcom
passes the remote certificate chain and PKI context to the validator and accepts the peer only when the validator returns true.
Minimal SecureTCP master setup
SecureModbusPkiStore pkiStore = new SecureModbusPkiStore(@"C:\ModbusPki");
SecureModbusTcpOptions options = new SecureModbusTcpOptions
{
PkiStore = pkiStore,
OwnCertificate = new SecureModbusOwnCertificate(pkiStore, "ModbusMaster", "changeit", 730),
TargetHostName = "modbus-device.example.local"
};
ModbusMaster master = new ModbusMaster("user", "serial");
master.SetConnector_SecureTCP("modbus-device.example.local", 802, options);
Role-based authorization
SecureTCP certificates can contain a role name. PLCcom exposes this role to an optional ISecureModbusAuthorizationValidator on the
slave side together with the Modbus function, subfunction, ADU, PDU, listener name, connection id, and client certificate chain.
If no validator is configured, requests are allowed after TLS and certificate validation. If the validator returns false, the slave rejects the
request with Modbus exception code 01, illegal function.
Keep authorization validators fast, because they may run for every SecureTCP request.
Register modes and byte order
PLCcom supports 16-bit, 32-bit, and 64-bit register modes.
Wider register modes are not generic modes for all datatypes. They are valid only for
datatypes that actually require the configured width, following the established 32-bit register behavior.
The V9 64-bit mode is intended for
values such as LONG, ULONG, and DOUBLE.
Byte order remains configurable because Modbus devices differ in how they arrange bytes and words for multi-register values.
Use the byte-order setting
that matches the target device documentation, then keep the request and response code independent from the device-specific wire layout.
Where to go next
- Use the PLCcomModbus.Master namespace for master applications and request collections.
- Use the PLCcomModbus.Slave namespace for slave applications, listeners, and data-store events.
- Use the PLCcomModbus.Core.Security namespace for SecureTCP options, PKI store handling, certificate validation, and authorization.
- Use the workshop and full application projects as runnable examples while the API reference provides the exact member-level details.
Namespaces
| PLCcomModbus.Core | Namespace of PLCcom for Modbus core functionality. |
| PLCcomModbus.Core.Security | |
| PLCcomModbus.DataAdapter | Namespace of PLCcom for Modbus connectivity and data access functionality. |
| PLCcomModbus.Master | Namespace of PLCcom for Modbus master functionality. |
| PLCcomModbus.Slave | Namespace of PLCcom for Modbus slave functionality. |