Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

This is an IoT device communication protocol implementation client, which will include common industrial communication protocols such as mainstream PLC communication reading, ModBus protocol, and Bacnet protocol. This component is open source and free for life, using the most relaxed MIT open source agreement, you can modify and commercial use a…

License

NotificationsYou must be signed in to change notification settings

zhaopeiym/IoTClient

Repository files navigation

English |中文文档

imageimageimage

  • This is an IoT device communication protocol realization client, which will include mainstream PLC communication reading, ModBus protocol, Bacnet protocol and other common industrial communication protocols.
  • This component is based on .NET Standard 2.0 and can be used for cross-platform development of .Net, such as Windows, Linux and even run on Raspberry Pi.
  • This component is open source and free for life, and adopts the most relaxed MIT protocol. You can also modify and use it for commercial use (commercial use please evaluate and test).
  • Development tools:Visual Studio 2019
  • QQ exchange group:700324594

Document directory

Instructions for use

Reference component

Nuget installationInstall-Package IoTClient
Or graphical installation
image

ModBusTcp read and write operations

//1、Instantiate the client-enter the correct IP and portModBusTcpClient client = new ModBusTcpClient("127.0.0.1", 502);//2、Write operation-parameters are: address, value, station number, function codeclient.Write("4", (short)33, 2, 16);//2.1、[Note] When writing data, you need to clarify the data typeclient.Write("0", (short)33, 2, 16);    //Write short type valueclient.Write("4", (ushort)33, 2, 16);   //Write ushort type valueclient.Write("8", (int)33, 2, 16);      //Write int type valueclient.Write("12", (uint)33, 2, 16);    //Write uint type valueclient.Write("16", (long)33, 2, 16);    //Write long type valueclient.Write("20", (ulong)33, 2, 16);   //Write ulong type valueclient.Write("24", (float)33, 2, 16);   //Write float type valueclient.Write("28", (double)33, 2, 16);  //Write double type valueclient.Write("32", true, 2, 5);         //Write Coil type valueclient.Write("100", "orderCode", stationNumber);  //Write string//3、Read operation-the parameters are: address, station number, function codevar value = client.ReadInt16("4", 2, 3).Value;//3.1、Other types of data readingclient.ReadInt16("0", stationNumber, 3);    //short type data readclient.ReadUInt16("4", stationNumber, 3);   //ushort type data readclient.ReadInt32("8", stationNumber, 3);    //int type data readclient.ReadUInt32("12", stationNumber, 3);  //uint type data readclient.ReadInt64("16", stationNumber, 3);   //long type data readclient.ReadUInt64("20", stationNumber, 3);  //ulong type data readclient.ReadFloat("24", stationNumber, 3);   //float type data readclient.ReadDouble("28", stationNumber, 3);  //double type data readclient.ReadCoil("32", stationNumber, 1);    //Coil type data readclient.ReadDiscrete("32", stationNumber, 2);//Discrete type data readclient.ReadString("100", stationNumber,readLength:10); //Read string//4、If there is no active Open, it will automatically open and close the connection every time you read and write operations, which will greatly reduce the efficiency of reading and writing. So it is recommended to open and close manually.client.Open();//5、Read and write operations will return the operation result object Resultvar result = client.ReadInt16("4", 2, 3);//5.1 Whether the reading is successful (true or false)var isSucceed = result.IsSucceed;//5.2 Exception information for failed readingvar errMsg = result.Err;//5.3 Read the request message actually sent by the operationvar requst  = result.Requst;//5.4 Read the response message from the servervar response = result.Response;//5.5 Read valuevar value3 = result.Value;//6、Batch readvar list = new List<ModBusInput>();list.Add(new ModBusInput(){    Address = "2",    DataType = DataTypeEnum.Int16,    FunctionCode = 3,    StationNumber = 1});list.Add(new ModBusInput(){    Address = "2",    DataType = DataTypeEnum.Int16,    FunctionCode = 4,    StationNumber = 1});list.Add(new ModBusInput(){    Address = "199",    DataType = DataTypeEnum.Int16,    FunctionCode = 3,    StationNumber = 1});var result = client.BatchRead(list);//7、Other parameters of the constructor//IP, port, timeout time, big and small end settingsModBusTcpClient client = new ModBusTcpClient("127.0.0.1", 502, 1500, EndianFormat.ABCD);

For more usage of ModBusTcp, please refer toUnit Test

ModBusRtu read and write operations

//Instantiate the client-[COM port name, baud rate, data bits, stop bits, parity]ModBusRtuClient client = new ModBusRtuClient("COM3", 9600, 8, StopBits.One, Parity.None);//Other read and write operations are the same as ModBusTcpClient's read and write operations

ModBusAscii read and write operations

//Instantiate the client-[COM port name, baud rate, data bits, stop bits, parity]ModbusAsciiClient client = new ModbusAsciiClient("COM3", 9600, 8, StopBits.One, Parity.None);//Other read and write operations are the same as ModBusTcpClient's read and write operations

ModbusRtuOverTcp read and write operations

//Serial port transparent transmission i.e.: send Rtu format messages in Tcp mode//Instantiate the client-IP, port, timeout, big and small end settingsModbusRtuOverTcpClient client = new ModbusRtuOverTcpClient("127.0.0.1", 502, 1500, EndianFormat.ABCD);//Other read and write operations are the same as ModBusTcpClient's read and write operations

SiemensClient (Siemens) read and write operations

//1、Instantiate the client-enter the model, IP and port//Other models:SiemensVersion.S7_200、SiemensVersion.S7_300、SiemensVersion.S7_400、SiemensVersion.S7_1200、SiemensVersion.S7_1500SiemensClient client = new SiemensClient(SiemensVersion.S7_200Smart, "127.0.0.1",102);//2、Write operationclient.Write("Q1.3", true);client.Write("V2205", (short)11);client.Write("V2209", 33);//3、Read operationvar value1 = client.ReadBoolean("Q1.3").Value;var value2 = client.ReadInt16("V2205").Value;var value3 = client.ReadInt32("V2209").Value;//4、If there is no active Open, it will automatically open and close the connection every time you read and write operations, which will greatly reduce the efficiency of reading and writing. So it is recommended to open and close manually.client.Open();//5、Read and write operations will return the operation result object Resultvar result = client.ReadInt16("V2205");//5.1 Whether the reading is successful (true or false)var isSucceed = result.IsSucceed;//5.2 Exception information for failed readingvar errMsg = result.Err;//5.3 Read the request message actually sent by the operationvar requst  = result.Requst;//5.4 Read the response message from the servervar response = result.Response;//5.5 Read valuevar value4 = result.Value;

Note: About Siemens PLC address

VB263、VW263、VD263中的B、W、D分别表示:byte型(8位)、word型(16位)、doubleword型(32位)。When this component passes in the address, there is no need to carry the data type, just use the corresponding method to read the corresponding type, such as:VB263       - client.ReadByte("V263")VD263       - client.ReadFloat("V263")VD263       - client.ReadInt32("V263")DB108.DBW4  - client.ReadUInt16("DB108.4")DB1.DBX0.0  - client.ReadBoolean("DB1.0.0")DB1.DBD0    - client.ReadFloat("DB1.0")
C# data typesmart2001200/1500/300
bitV1.0DB1.DBX1.0
byteVB1DB1.DBB1
shor
ushort
VW2DB1.DBW2
int
uint
float
VD4DB1.DBD4

SiemensClient best practices

1、When not to take the initiative to openSiemens plc generally allows up to 8 long connections. So when the number of connections is not enough or when doing testing, do not take the initiative to open, so that the component will automatically open and close immediately.2、When to take the initiative to openWhen the number of long connections is enough, and you want to improve the read and write performance.3、In addition to active Open connections, batch read and write can also greatly improve read and write performance.//Batch readDictionary<string, DataTypeEnum> addresses = new Dictionary<string, DataTypeEnum>();addresses.Add("DB4.24", DataTypeEnum.Float);addresses.Add("DB1.434.0", DataTypeEnum.Bool);addresses.Add("V4109", DataTypeEnum.Byte);...var result = client.BatchRead(addresses);//Batch writeDictionary<string, object> addresses = new Dictionary<string, object>();addresses.Add("DB4.24", (float)1);addresses.Add("DB4.0", (float)2);addresses.Add("DB1.434.0", true);...var result = client.BatchWrite(addresses);4、[Note] When writing data, you need to clarify the data typeclient.Write("DB4.12", 9);          //What is written is of type intclient.Write("DB4.12", (float)9);   //What is written is a float type5、SiemensClient is a thread safe classDue to limited long PLC connections, SiemensClient is designed as a thread-safe class. You can set SiemensClient as a singleton, and use the instance of SiemensClient to read and write PLC between multiple threads.

MitsubishiClient (Mitsubishi) read and write operations

//1、Instantiate the client-enter the correct IP and portMitsubishiClient client = new MitsubishiClient(MitsubishiVersion.Qna_3E, "127.0.0.1",6000);//2、Write operationclient.Write("M100", true);client.Write("D200", (short)11);client.Write("D210", 33);//3、Read operationvar value1 = client.ReadBoolean("M100").Value;var value2 = client.ReadInt16("D200").Value;var value3 = client.ReadInt32("D210").Value;//4、If there is no active Open, it will automatically open and close the connection every time you read and write operations, which will greatly reduce the efficiency of reading and writing. So it is recommended to open and close manually.client.Open();//5、Read and write operations will return the operation result object Resultvar result = client.ReadInt16("D210");//5.1 Whether the reading is successful (true or false)var isSucceed = result.IsSucceed;//5.2 Exception information for failed readingvar errMsg = result.Err;//5.3 Read the request message actually sent by the operationvar requst  = result.Requst;//5.4 Read the response message from the servervar response = result.Response;//5.5 Read valuevar value4 = result.Value;

OmronFinsClient (Omron) read and write operations

//1、Instantiate the client-enter the correct IP and portOmronFinsClient client = new OmronFinsClient("127.0.0.1",6000);//2、Write operationclient.Write("M100", true);client.Write("D200", (short)11);client.Write("D210", 33);//3、Read operationvar value1 = client.ReadBoolean("M100").Value;var value2 = client.ReadInt16("D200").Value;var value3 = client.ReadInt32("D210").Value;//4、If there is no active Open, it will automatically open and close the connection every time you read and write operations, which will greatly reduce the efficiency of reading and writing. So it is recommended to open and close manually.client.Open();//5、Read and write operations will return the operation result object Resultvar result = client.ReadInt16("D210");//5.1 Whether the reading is successful (true or false)var isSucceed = result.IsSucceed;//5.2 Exception information for failed readingvar errMsg = result.Err;//5.3 Read the request message actually sent by the operationvar requst  = result.Requst;//5.4 Read the response message from the servervar response = result.Response;//5.5 Read valuevar value4 = result.Value;

AllenBradleyClient read and write operations

//1、Instantiate the client-enter the correct IP and portAllenBradleyClient client = new AllenBradleyClient("127.0.0.1",44818);//2、Write operation client.Write("A1", (short)11); //3、Read operationvar value = client.ReadInt16("A1").Value;//4、If there is no active Open, it will automatically open and close the connection every time you read and write operations, which will greatly reduce the efficiency of reading and writing. So it is recommended to open and close manually.client.Open();//5、Read and write operations will return the operation result object Resultvar result = client.ReadInt16("A1");//5.1 Whether the reading is successful (true or false)var isSucceed = result.IsSucceed;//5.2 Exception information for failed readingvar errMsg = result.Err;//5.3 Read the request message actually sent by the operationvar requst  = result.Requst;//5.4 Read the response message from the servervar response = result.Response;//5.5 Read valuevar value4 = result.Value;

Some projects based on IoTClient library

IoTClient Tool Desktop program tool (open source)

IoTClient Tool 桌面程序工具,开源地址

  • 1、可用来测试PLC和相关协议的通信
  • 2、可作为IoTClient库使用例子。

image

image

image

image

image

image

image

image

image

image

Energy Management System (Commercial)

能源管理-现场-单项目

image
image

能源管理-云端-多项目

image
image
image
image
image
image
image

能源管理-移动端

imageimageimageimageimageimageimage

Haidilao terminal control (commercial)

海底捞末端控制-web

image
image
image
image

海底捞末端控制-移动端

imageimageimageimage

About

This is an IoT device communication protocol implementation client, which will include common industrial communication protocols such as mainstream PLC communication reading, ModBus protocol, and Bacnet protocol. This component is open source and free for life, using the most relaxed MIT open source agreement, you can modify and commercial use a…

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages


[8]ページ先頭

©2009-2025 Movatter.jp