You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Instruction & API information is on following section
1.1. About NModbus4
NModbus is a C# implementation of the Modbus protocol.
Provides connectivity to Modbus slave compatible devices and applications.
Supports serial ASCII, serial RTU, TCP, and UDP protocols.
NModbus4 it's a fork of NModbus(https://code.google.com/p/nmodbus).
NModbus4 differs from original NModbus in following:
1. removed USB support(FtdAdapter.dll)
2. removed log4net dependency
3. removed Unme.Common.dll dependency
4. assembly renamed to NModbus4.dll
5. target framework changed to .NET 4
1.1.1. NModbus4 License
The MIT License (MIT)
Copyright (c) 2006 Scott Alexander, 2015 Dmitry Turin
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
1.2. About NModbus4.Wrapper
NModbus4.Wrapper is driven from NModbus4 for integrated usage.
Difference of NModbus4.Wrapper from NModbus4 is:
1. integrate class (RTU, TCP, UDP...) into ModbusService
2. support C# data types (bool, int, float)
3. support threading when using Client
1.2.1. NModbus4.Wrapper License
The MIT License (MIT)
Copyright (c) 2023 Peponi
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
1.2.2. NModbus4.Wrapper install
1.2.2.1. Package Manager
NuGet\Install-Package NModbus4.Wrapper
1.3. Code Example
1.3.1. From constructor to connect
stringinterfaceName="Test";ModbusTypemodbusType=ModbusType.TCP_Slave;intslaveNo=1;EthernetInformationethernetInformation=newEthernetInformation{Address="127.0.0.1",Port=50001};Endianendian=Endian.Big;ModbusInterfaceinterfaceData=newModbusInterface(interfaceName,modbusType,slaveNo,ethernetInformation,endian);ModbusServicemodbus=newModbusService(interfaceData,CheckConnectionStatus);modbus.ModbusLog+=Modbus_LogWrite;modbus.ModbusDataReceived+=Modbus_ModbusDataReceived;modbus.ModbusCommunicationException+=Modbus_ModbusCommunicationException;modbus.ModbusGeneralException+=Modbus_ModbusGeneralException;modbus.Connect();voidCheckConnectionStatus(ModbusInterfacemodbusInterface,boolconnectStatus){if(connectStatus){// Do something...}else{// Reconnect, or other things to do..}}
// 1. Single casevarcommData=newCommunicationData(DataStorage.HoldingRegister,0,default(double),modbus.Interface.EndianOption);if(modbus.ReadData(refcommData)){// Data process...}else{// Do something for error handling...}// 2. List caseList<CommunicationData>commDatas=newList<CommunicationData>();commDatas.Add(newCommunicationData(DataStorage.HoldingRegister,0,default(float),modbus.Interface.EndianOption));commDatas.Add(newCommunicationData(DataStorage.HoldingRegister,2,default(bool),modbus.Interface.EndianOption));commDatas.Add(newCommunicationData(DataStorage.HoldingRegister,3,default(int),modbus.Interface.EndianOption));if(modbus.ReadData(refcommDatas)){// Data process...}else{// Do something for error handling...}
1.3.5. Write data asynchronous
// 1. Single casevarcommData=newCommunicationData(DataStorage.HoldingRegister,0,10.12,modbus.Interface.EndianOption);if(!awaitmodbus.WriteDataAsync(commData)){// Do something for error handling...}// 2. List caseList<CommunicationData>commDatas=newList<CommunicationData>();commDatas.Add(newCommunicationData(DataStorage.HoldingRegister,0,3.465F,modbus.Interface.EndianOption));commDatas.Add(newCommunicationData(DataStorage.Coil,0,true,modbus.Interface.EndianOption));commDatas.Add(newCommunicationData(DataStorage.HoldingRegister,2,534,modbus.Interface.EndianOption));if(!awaitmodbus.WriteDataAsync(commDatas)){// Do something for error handling...}
2. API Information
2.1. namespace NModbus4.Wrapper.Define
2.1.1. enum LogLevel
Name
Value
Communication
1
Exception
2
2.1.2. enum CommunicationException
Name
Value
Description
SlaveFunctionCodeException
1
SlaveUnimplementedException
2
MasterTransportNullException
3
Remote connection lost
2.1.3. enum DataType
Support data type
Name
Value
Bool
1
Int
2
Float
4
2.1.4. enum ModbusType
Set Network type, Master / Slave mode
Name
Value
RTU_Master
1
TCP_Master
2
UDP_Master
3
RTU_Slave
11
TCP_Slave
12
UDP_Slave
13
2.1.5. enum DataStorage
Name
Value
Coil
0
DiscreteInput
1
InputRegister
2
HoldingRegister
3
2.1.6. enum Endian
Remote's endian matching enum
Name
Value
Big
1
Little
2
2.1.7. struct SerialPortInformation
Type
Name
string
Port
int
Baudrate
System.IO.Ports.Parity
Parity
int
Databits
System.IO.Ports.StopBits
Stopbits
System.IO.Ports.Handshake
Handshake
2.1.8. struct EthernetInformation
Type
Name
string
Address
int
Port
2.1.9. class CommunicationData
Built in type for communication of NModbus4.Wrapper