Modbus 2.0.0

Install-Package Modbus -Version 2.0.0
dotnet add package Modbus --version 2.0.0
<PackageReference Include="Modbus" Version="2.0.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Modbus --version 2.0.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: Modbus, 2.0.0"
#r directive can be used in F# Interactive, C# scripting and .NET Interactive. Copy this into the interactive tool or source code of the script to reference the package.
// Install Modbus as a Cake Addin
#addin nuget:?package=Modbus&version=2.0.0

// Install Modbus as a Cake Tool
#tool nuget:?package=Modbus&version=2.0.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

Modbus library

To communicate with slaves, you must create an ICommStream (currently, this library supports for SerialStream via serial port). After that, call the request function corresponds witch each function code. The request function will send a request to slave and waiting for the response, at that time, other requests will be pending until the current one is completed.

var serialPort = new SerialPort("COM1");
var stream = new SerialStream(serialPort);  
var responseBytes = stream.RequestFunc3(slaveId, dataAddress, registerCount);  

Supported function codes (example and code)

Read Holding Registers (FC=03)

// send request and waiting for response
// the request needs: slaveId, dataAddress, registerCount
var responseBytes = stream.RequestFunc3(0x11, 0x006B, 0x0003);
// extract the content part (the most important in the response)
var data= responseBytes.ToResponseFunc3().Data;

Read Input Registers (FC=04)

// send request and waiting for response
// the request needs: slaveId, dataAddress, registerCount
var responseBytes = stream.RequestFunc4(0x11, 0x0008, 0x0001);
// extract the content part (the most important in the response)
var data= responseBytes.ToResponseFunc4().Data;

Preset Single Register (FC=06)

// send request and waiting for response
// the request needs: slaveId, dataAddress, writeValue
var responseBytes = stream.RequestFunc6(0x11, 0x0001, 0x0003);
// the reponse bytes should be an echo of the request.

Diagnosis (FC=08)

// send request and waiting for response
// the request needs: slaveId, subFunction, data
var responseBytes = stream.RequestFunc8(0x0B, 0x0000, 0x0203);

Preset Multiple Registers (FC=16)

// send request and waiting for response
// the request needs: slaveId, dataAddress, writeValue
var responseBytes = stream.RequestFunc16(0x11, 0x0001, new byte[] {0x00, 0x0A, 0x01, 0x02});

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
2.0.0 5,700 10/19/2018
1.0.0 2,433 6/4/2017

Supports function codes: 3, 4, 6, 8, 16