Modbus 2.0.0

dotnet add package Modbus --version 2.0.0                
NuGet\Install-Package Modbus -Version 2.0.0                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<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                
#r "nuget: Modbus, 2.0.0"                
#r directive can be used in F# Interactive and Polyglot Notebooks. 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                

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});
Product Compatible and additional computed target framework versions.
.NET Framework net45 is compatible.  net451 was computed.  net452 was computed.  net46 was computed.  net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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 21,457 10/19/2018
1.0.0 3,178 6/4/2017

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