nanoFramework.Iot.Device.Modbus 1.0.193

The ID prefix of this package has been reserved for one of the owners of this package by NuGet.org. Prefix Reserved
dotnet add package nanoFramework.Iot.Device.Modbus --version 1.0.193
NuGet\Install-Package nanoFramework.Iot.Device.Modbus -Version 1.0.193
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="nanoFramework.Iot.Device.Modbus" Version="1.0.193" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add nanoFramework.Iot.Device.Modbus --version 1.0.193
#r "nuget: nanoFramework.Iot.Device.Modbus, 1.0.193"
#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 nanoFramework.Iot.Device.Modbus as a Cake Addin
#addin nuget:?package=nanoFramework.Iot.Device.Modbus&version=1.0.193

// Install nanoFramework.Iot.Device.Modbus as a Cake Tool
#tool nuget:?package=nanoFramework.Iot.Device.Modbus&version=1.0.193

Modbus - Machine to machine communication protocol

Modbus communication protocol addresses architectures for distributed automation systems across multiple market segments. It can be serial port based or network based. This implementation is serial port based but can be adjusted to support networking easily.

Documentation

Modbus specifications can be found on the Modbus organization website.

Usage

If you are using an ESP32, you must initialize the pins to use serial port like this:

// SerialPort COM2
Configuration.SetPinFunction(16, DeviceFunction.COM2_RX);
Configuration.SetPinFunction(17, DeviceFunction.COM2_TX);
Configuration.SetPinFunction(18, DeviceFunction.COM2_RTS);

With an ESP32, you can almost use any pin for any function. When using an STM32 or other MCU, the pins are usually fixed. Refer to the documentation of your MCU to understand which pin to use.

Modbus client

To initialize and use a Modbus client, you can do the following:

// Modbus Client
var client = new ModbusClient("COM3");
client.ReadTimeout = client.WriteTimeout = 2000;

client.WriteMultipleRegisters(2, 0x5, new ushort[] { 3, 5, 2, 3 });
client.Raw(2, FunctionCode.Diagnostics, new byte[] { 0x01, 0x01, 0x01, 0x01 });

var data1 = client.ReadHoldingRegisters(2, 0x7, 4);
var data2 = client.ReadCoils(2, 0x23, 2);

As shown in the sample, you have the possibility to write multiple registers, use raw function and also ready multiple registers.

Modbus server

A server implementation is also available:

// Modbus Server
var server = new ModbusServer(new Device(1), "COM2");
server.ReadTimeout = server.WriteTimeout = 2000;
server.StartListening();

This server implementation will allow you to act as a server. It can be extended.

Hardware implementation

When using Modbus with an RS485, you can for example use a MAX485 to make the interface between the traditional serial port and RS485:

MAX485

RS232 support

You can change the mode parameter in constructor to 0 (SerialMode.Normal) if you're using Modbus over RS232

// Modbus Client
var client = new ModbusClient("COM3",SerialMode.Normal); 
// Modbus Server
var server = new ModbusServer(new Device(1), "COM2",mode:SerialMode.Normal);

Limitations

NOTE: nanoFramework only (currently) supports the "Modbus-RTU" protocol.

Product Compatible and additional computed target framework versions.
.NET Framework net is compatible. 
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
1.0.193 45 4/25/2024
1.0.189 90 4/15/2024
1.0.181 75 4/10/2024
1.0.89 259 11/10/2023
1.0.44 135 9/15/2023
1.0.43 114 9/15/2023
1.0.1 133 7/6/2023