From 52f51bfeaf87a44f1147499c493c27f636e4492c Mon Sep 17 00:00:00 2001 From: BennyZhao Date: Sun, 23 May 2021 13:57:25 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A5=BF=E9=97=A8=E5=AD=90=E6=8F=92=E6=A7=BD?= =?UTF-8?q?=E5=92=8C=E6=9C=BA=E6=9E=B6=E5=8F=B7=E7=9A=84=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- IoTClient/Clients/PLC/SiemensClient.cs | 30 ++++-- IoTClient/IoTClient/IoTClient.xml | 18 +++- README-zh_CN.md | 4 +- README.md | 128 ++++++++++++------------- 4 files changed, 106 insertions(+), 74 deletions(-) diff --git a/IoTClient/Clients/PLC/SiemensClient.cs b/IoTClient/Clients/PLC/SiemensClient.cs index 2a74d77..23f30f2 100644 --- a/IoTClient/Clients/PLC/SiemensClient.cs +++ b/IoTClient/Clients/PLC/SiemensClient.cs @@ -49,14 +49,28 @@ namespace IoTClient.Clients.PLC /// public LoggerDelegate WarningLog { get; set; } + /// + /// 插槽号 + /// + public byte Slot { get; private set; } + + /// + /// 机架号 + /// + public byte Rack { get; private set; } + /// /// 构造函数 /// /// CPU版本 /// IP地址和端口号 /// 超时时间 - public SiemensClient(SiemensVersion version, IPEndPoint ipAndPoint, int timeout = 1500) + /// PLC的插槽号 + /// PLC的机架号 + public SiemensClient(SiemensVersion version, IPEndPoint ipAndPoint, byte slot = 0x00, byte rack = 0x00, int timeout = 1500) { + Slot = slot; + Rack = rack; this.version = version; IpAndPoint = ipAndPoint; this.timeout = timeout; @@ -68,9 +82,13 @@ namespace IoTClient.Clients.PLC /// CPU版本 /// IP地址 /// 端口号 + /// PLC的槽号 + /// PLC的机架号 /// 超时时间 - public SiemensClient(SiemensVersion version, string ip, int port, int timeout = 1500) + public SiemensClient(SiemensVersion version, string ip, int port, byte slot = 0x00, byte rack = 0x00, int timeout = 1500) { + Slot = slot; + Rack = rack; this.version = version; IpAndPoint = new IPEndPoint(IPAddress.Parse(ip), port); ; this.timeout = timeout; @@ -111,17 +129,17 @@ namespace IoTClient.Clients.PLC Command2 = SiemensConstant.Command2_200Smart; break; case SiemensVersion.S7_300: - Command1[21] = 0x02; + Command1[21] = (byte)((Rack * 0x20) + Slot); //0x02; break; case SiemensVersion.S7_400: - Command1[21] = 0x03; + Command1[21] = (byte)((Rack * 0x20) + Slot); //0x03; Command1[17] = 0x00; break; case SiemensVersion.S7_1200: - Command1[21] = 0x00; + Command1[21] = (byte)((Rack * 0x20) + Slot); //0x00; break; case SiemensVersion.S7_1500: - Command1[21] = 0x00; + Command1[21] = (byte)((Rack * 0x20) + Slot); //0x00; break; default: Command1[18] = 0x00; diff --git a/IoTClient/IoTClient/IoTClient.xml b/IoTClient/IoTClient/IoTClient.xml index d4eea47..aafffae 100644 --- a/IoTClient/IoTClient/IoTClient.xml +++ b/IoTClient/IoTClient/IoTClient.xml @@ -2540,21 +2540,35 @@ 为了可用性,会对异常网络进行重试。此类日志通过委托接口给出去。 - + + + PLC的槽号 + + + + + PLC的机架号 + + + 构造函数 CPU版本 IP地址和端口号 超时时间 + PLC的槽号 + PLC的机架号 - + 构造函数 CPU版本 IP地址 端口号 + PLC的槽号 + PLC的机架号 超时时间 diff --git a/README-zh_CN.md b/README-zh_CN.md index 4843a45..be2c4d4 100644 --- a/README-zh_CN.md +++ b/README-zh_CN.md @@ -2,9 +2,9 @@ IoTClient -[![image](https://img.shields.io/nuget/v/IoTClient.svg)](https://www.nuget.org/packages/IoTClient/) [![image](https://img.shields.io/nuget/dt/IoTClient.svg)](https://www.nuget.org/packages/IoTClient/) ![image](https://img.shields.io/github/license/alienwow/SnowLeopard.svg) +## [English](README.md) | 简体中文 -[English](README.md) | 简体中文 +[![image](https://img.shields.io/nuget/v/IoTClient.svg)](https://www.nuget.org/packages/IoTClient/) [![image](https://img.shields.io/nuget/dt/IoTClient.svg)](https://www.nuget.org/packages/IoTClient/) ![image](https://img.shields.io/github/license/alienwow/SnowLeopard.svg) - 这是一个物联网设备通讯协议实现客户端,将包括主流PLC通信读取、ModBus协议、Bacnet协议等常用工业通讯协议。 - 本组件基于.NET Standard 2.0,可用于.Net的跨平台开发,如Windows、Linux甚至可运行于树莓派上。 diff --git a/README.md b/README.md index 9535f72..c0d6672 100644 --- a/README.md +++ b/README.md @@ -2,9 +2,9 @@ IoTClient -[![image](https://img.shields.io/nuget/v/IoTClient.svg)](https://www.nuget.org/packages/IoTClient/) [![image](https://img.shields.io/nuget/dt/IoTClient.svg)](https://www.nuget.org/packages/IoTClient/) ![image](https://img.shields.io/github/license/alienwow/SnowLeopard.svg) +## English | [中文文档](README-zh_CN.md) -English | [简体中文](README-zh_CN.md) +[![image](https://img.shields.io/nuget/v/IoTClient.svg)](https://www.nuget.org/packages/IoTClient/) [![image](https://img.shields.io/nuget/dt/IoTClient.svg)](https://www.nuget.org/packages/IoTClient/) ![image](https://img.shields.io/github/license/alienwow/SnowLeopard.svg) - 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. @@ -111,10 +111,10 @@ For more usage of ModBusTcp, please refer to [Unit Test](https://github.com/zhao ## ModBusRtu read and write operations ``` -//实例化客户端 - [COM端口名称,波特率,数据位,停止位,奇偶校验] +//Instantiate the client-[COM port name, baud rate, data bits, stop bits, parity] ModBusRtuClient client = new ModBusRtuClient("COM3", 9600, 8, StopBits.One, Parity.None); -//其他读写操作和ModBusTcpClient的读写操作一致 +//Other read and write operations are the same as ModBusTcpClient's read and write operations ``` @@ -123,10 +123,10 @@ ModBusRtuClient client = new ModBusRtuClient("COM3", 9600, 8, StopBits.One, Pari ## ModBusAscii read and write operations ``` -//实例化客户端 - [COM端口名称,波特率,数据位,停止位,奇偶校验] +//Instantiate the client-[COM port name, baud rate, data bits, stop bits, parity] ModbusAsciiClient client = new ModbusAsciiClient("COM3", 9600, 8, StopBits.One, Parity.None); -//其他读写操作和ModBusTcpClient的读写操作一致 +//Other read and write operations are the same as ModBusTcpClient's read and write operations ``` @@ -135,12 +135,12 @@ ModbusAsciiClient client = new ModbusAsciiClient("COM3", 9600, 8, StopBits.One, ## ModbusRtuOverTcp read and write operations ``` -//串口透传 即:用Tcp的方式发送Rtu格式报文 +//Serial port transparent transmission i.e.: send Rtu format messages in Tcp mode -//实例化客户端 - IP、端口、超时时间、大小端设置 +//Instantiate the client-IP, port, timeout, big and small end settings ModbusRtuOverTcpClient client = new ModbusRtuOverTcpClient("127.0.0.1", 502, 1500, EndianFormat.ABCD); -//其他读写操作和ModBusTcpClient的读写操作一致 +//Other read and write operations are the same as ModBusTcpClient's read and write operations ``` @@ -149,34 +149,34 @@ ModbusRtuOverTcpClient client = new ModbusRtuOverTcpClient("127.0.0.1", 502, 150 ## SiemensClient (Siemens) read and write operations ``` -//1、实例化客户端 - 输入型号、IP和端口 -//其他型号:SiemensVersion.S7_200、SiemensVersion.S7_300、SiemensVersion.S7_400、SiemensVersion.S7_1200、SiemensVersion.S7_1500 +//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_1500 SiemensClient client = new SiemensClient(SiemensVersion.S7_200Smart, "127.0.0.1",102); -//2、写操作 +//2、Write operation client.Write("Q1.3", true); client.Write("V2205", (short)11); client.Write("V2209", 33); -//3、读操作 +//3、Read operation var value1 = client.ReadBoolean("Q1.3").Value; var value2 = client.ReadInt16("V2205").Value; var value3 = client.ReadInt32("V2209").Value; -//4、如果没有主动Open,则会每次读写操作的时候自动打开自动和关闭连接,这样会使读写效率大大减低。所以建议手动Open和Close。 +//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、读写操作都会返回操作结果对象Result +//5、Read and write operations will return the operation result object Result var result = client.ReadInt16("V2205"); -//5.1 读取是否成功(true或false) +//5.1 Whether the reading is successful (true or false) var isSucceed = result.IsSucceed; -//5.2 读取失败的异常信息 +//5.2 Exception information for failed reading var errMsg = result.Err; -//5.3 读取操作实际发送的请求报文 +//5.3 Read the request message actually sent by the operation var requst = result.Requst; -//5.4 读取操作服务端响应的报文 +//5.4 Read the response message from the server var response = result.Response; -//5.5 读取到的值 +//5.5 Read value var value4 = result.Value; ``` @@ -189,7 +189,7 @@ var value4 = result.Value; ``` 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") @@ -197,7 +197,7 @@ DB108.DBW4 - client.ReadUInt16("DB108.4") DB1.DBX0.0 - client.ReadBoolean("DB1.0.0") DB1.DBD0 - client.ReadFloat("DB1.0") ``` -|C#数据类型 | smart200 | 1200/1500/300 +|C# data type | smart200 | 1200/1500/300 |---|---|--- |bit | V1.0 | DB1.DBX1.0 |byte | VB1 | DB1.DBB1 @@ -210,14 +210,14 @@ DB1.DBD0 - client.ReadFloat("DB1.0") ## SiemensClient best practices ``` -1、什么时候不要主动Open -西门子plc一般最多允许8个长连接。所以当连接数不够用的时候或者做测试的时候就不要主动Open,这样组件会自动Open并即时Close。 +1、When not to take the initiative to open +Siemens 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、什么时候主动Open -当长连接数量还够用,且想要提升读写性能。 +2、When to take the initiative to open +When the number of long connections is enough, and you want to improve the read and write performance. -3、除了主动Open连接,还可以通过批量读写,大幅提升读写性能。 -//批量读取 +3、In addition to active Open connections, batch read and write can also greatly improve read and write performance. +//Batch read Dictionary addresses = new Dictionary(); addresses.Add("DB4.24", DataTypeEnum.Float); addresses.Add("DB1.434.0", DataTypeEnum.Bool); @@ -225,7 +225,7 @@ addresses.Add("V4109", DataTypeEnum.Byte); ... var result = client.BatchRead(addresses); -//批量写入 +//Batch write Dictionary addresses = new Dictionary(); addresses.Add("DB4.24", (float)1); addresses.Add("DB4.0", (float)2); @@ -233,12 +233,12 @@ addresses.Add("DB1.434.0", true); ... var result = client.BatchWrite(addresses); -4、【注意】写入数据的时候需要明确数据类型 -client.Write("DB4.12", 9); //写入的是int类型 -client.Write("DB4.12", (float)9); //写入的是float类型 +4、[Note] When writing data, you need to clarify the data type +client.Write("DB4.12", 9); //What is written is of type int +client.Write("DB4.12", (float)9); //What is written is a float type -5、SiemensClient是线程安全类 -由于plc长连接有限,SiemensClient被设计成线程安全类。可以把SiemensClient设置成单例,在多个线程之间使用SiemensClient的实例读写操作plc。 +5、SiemensClient is a thread safe class +Due 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. ``` @@ -247,33 +247,33 @@ client.Write("DB4.12", (float)9); //写入的是float类型 ## MitsubishiClient (Mitsubishi) read and write operations ``` -//1、实例化客户端 - 输入正确的IP和端口 +//1、Instantiate the client-enter the correct IP and port MitsubishiClient client = new MitsubishiClient(MitsubishiVersion.Qna_3E, "127.0.0.1",6000); -//2、写操作 +//2、Write operation client.Write("M100", true); client.Write("D200", (short)11); client.Write("D210", 33); -//3、读操作 +//3、Read operation var value1 = client.ReadBoolean("M100").Value; var value2 = client.ReadInt16("D200").Value; var value3 = client.ReadInt32("D210").Value; -//4、如果没有主动Open,则会每次读写操作的时候自动打开自动和关闭连接,这样会使读写效率大大减低。所以建议手动Open和Close。 +//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、读写操作都会返回操作结果对象Result +//5、Read and write operations will return the operation result object Result var result = client.ReadInt16("D210"); -//5.1 读取是否成功(true或false) +//5.1 Whether the reading is successful (true or false) var isSucceed = result.IsSucceed; -//5.2 读取失败的异常信息 +//5.2 Exception information for failed reading var errMsg = result.Err; -//5.3 读取操作实际发送的请求报文 +//5.3 Read the request message actually sent by the operation var requst = result.Requst; -//5.4 读取操作服务端响应的报文 +//5.4 Read the response message from the server var response = result.Response; -//5.5 读取到的值 +//5.5 Read value var value4 = result.Value; ``` @@ -283,33 +283,33 @@ var value4 = result.Value; ## OmronFinsClient (Omron) read and write operations ``` -//1、实例化客户端 - 输入正确的IP和端口 +//1、Instantiate the client-enter the correct IP and port OmronFinsClient client = new OmronFinsClient("127.0.0.1",6000); -//2、写操作 +//2、Write operation client.Write("M100", true); client.Write("D200", (short)11); client.Write("D210", 33); -//3、读操作 +//3、Read operation var value1 = client.ReadBoolean("M100").Value; var value2 = client.ReadInt16("D200").Value; var value3 = client.ReadInt32("D210").Value; -//4、如果没有主动Open,则会每次读写操作的时候自动打开自动和关闭连接,这样会使读写效率大大减低。所以建议手动Open和Close。 +//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、读写操作都会返回操作结果对象Result +//5、Read and write operations will return the operation result object Result var result = client.ReadInt16("D210"); -//5.1 读取是否成功(true或false) +//5.1 Whether the reading is successful (true or false) var isSucceed = result.IsSucceed; -//5.2 读取失败的异常信息 +//5.2 Exception information for failed reading var errMsg = result.Err; -//5.3 读取操作实际发送的请求报文 +//5.3 Read the request message actually sent by the operation var requst = result.Requst; -//5.4 读取操作服务端响应的报文 +//5.4 Read the response message from the server var response = result.Response; -//5.5 读取到的值 +//5.5 Read value var value4 = result.Value; ``` @@ -319,29 +319,29 @@ var value4 = result.Value; ## AllenBradleyClient read and write operations ``` -//1、实例化客户端 - 输入正确的IP和端口 +//1、Instantiate the client-enter the correct IP and port AllenBradleyClient client = new AllenBradleyClient("127.0.0.1",44818); -//2、写操作 +//2、Write operation client.Write("A1", (short)11); -//3、读操作 +//3、Read operation var value = client.ReadInt16("A1").Value; -//4、如果没有主动Open,则会每次读写操作的时候自动打开自动和关闭连接,这样会使读写效率大大减低。所以建议手动Open和Close。 +//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、读写操作都会返回操作结果对象Result +//5、Read and write operations will return the operation result object Result var result = client.ReadInt16("A1"); -//5.1 读取是否成功(true或false) +//5.1 Whether the reading is successful (true or false) var isSucceed = result.IsSucceed; -//5.2 读取失败的异常信息 +//5.2 Exception information for failed reading var errMsg = result.Err; -//5.3 读取操作实际发送的请求报文 +//5.3 Read the request message actually sent by the operation var requst = result.Requst; -//5.4 读取操作服务端响应的报文 +//5.4 Read the response message from the server var response = result.Response; -//5.5 读取到的值 +//5.5 Read value var value4 = result.Value; ```