mirror of
https://github.com/zhaopeiym/IoTClient
synced 2025-10-12 21:20:37 +08:00
西门子插槽和机架号的配置
This commit is contained in:
parent
6bf49e48bb
commit
52f51bfeaf
|
@ -49,14 +49,28 @@ namespace IoTClient.Clients.PLC
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public LoggerDelegate WarningLog { get; set; }
|
public LoggerDelegate WarningLog { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 插槽号
|
||||||
|
/// </summary>
|
||||||
|
public byte Slot { get; private set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 机架号
|
||||||
|
/// </summary>
|
||||||
|
public byte Rack { get; private set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 构造函数
|
/// 构造函数
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="version">CPU版本</param>
|
/// <param name="version">CPU版本</param>
|
||||||
/// <param name="ipAndPoint">IP地址和端口号</param>
|
/// <param name="ipAndPoint">IP地址和端口号</param>
|
||||||
/// <param name="timeout">超时时间</param>
|
/// <param name="timeout">超时时间</param>
|
||||||
public SiemensClient(SiemensVersion version, IPEndPoint ipAndPoint, int timeout = 1500)
|
/// <param name="slot">PLC的插槽号</param>
|
||||||
|
/// <param name="rack">PLC的机架号</param>
|
||||||
|
public SiemensClient(SiemensVersion version, IPEndPoint ipAndPoint, byte slot = 0x00, byte rack = 0x00, int timeout = 1500)
|
||||||
{
|
{
|
||||||
|
Slot = slot;
|
||||||
|
Rack = rack;
|
||||||
this.version = version;
|
this.version = version;
|
||||||
IpAndPoint = ipAndPoint;
|
IpAndPoint = ipAndPoint;
|
||||||
this.timeout = timeout;
|
this.timeout = timeout;
|
||||||
|
@ -68,9 +82,13 @@ namespace IoTClient.Clients.PLC
|
||||||
/// <param name="version">CPU版本</param>
|
/// <param name="version">CPU版本</param>
|
||||||
/// <param name="ip">IP地址</param>
|
/// <param name="ip">IP地址</param>
|
||||||
/// <param name="port">端口号</param>
|
/// <param name="port">端口号</param>
|
||||||
|
/// <param name="slot">PLC的槽号</param>
|
||||||
|
/// <param name="rack">PLC的机架号</param>
|
||||||
/// <param name="timeout">超时时间</param>
|
/// <param name="timeout">超时时间</param>
|
||||||
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;
|
this.version = version;
|
||||||
IpAndPoint = new IPEndPoint(IPAddress.Parse(ip), port); ;
|
IpAndPoint = new IPEndPoint(IPAddress.Parse(ip), port); ;
|
||||||
this.timeout = timeout;
|
this.timeout = timeout;
|
||||||
|
@ -111,17 +129,17 @@ namespace IoTClient.Clients.PLC
|
||||||
Command2 = SiemensConstant.Command2_200Smart;
|
Command2 = SiemensConstant.Command2_200Smart;
|
||||||
break;
|
break;
|
||||||
case SiemensVersion.S7_300:
|
case SiemensVersion.S7_300:
|
||||||
Command1[21] = 0x02;
|
Command1[21] = (byte)((Rack * 0x20) + Slot); //0x02;
|
||||||
break;
|
break;
|
||||||
case SiemensVersion.S7_400:
|
case SiemensVersion.S7_400:
|
||||||
Command1[21] = 0x03;
|
Command1[21] = (byte)((Rack * 0x20) + Slot); //0x03;
|
||||||
Command1[17] = 0x00;
|
Command1[17] = 0x00;
|
||||||
break;
|
break;
|
||||||
case SiemensVersion.S7_1200:
|
case SiemensVersion.S7_1200:
|
||||||
Command1[21] = 0x00;
|
Command1[21] = (byte)((Rack * 0x20) + Slot); //0x00;
|
||||||
break;
|
break;
|
||||||
case SiemensVersion.S7_1500:
|
case SiemensVersion.S7_1500:
|
||||||
Command1[21] = 0x00;
|
Command1[21] = (byte)((Rack * 0x20) + Slot); //0x00;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
Command1[18] = 0x00;
|
Command1[18] = 0x00;
|
||||||
|
|
|
@ -2540,21 +2540,35 @@
|
||||||
为了可用性,会对异常网络进行重试。此类日志通过委托接口给出去。
|
为了可用性,会对异常网络进行重试。此类日志通过委托接口给出去。
|
||||||
</summary>
|
</summary>
|
||||||
</member>
|
</member>
|
||||||
<member name="M:IoTClient.Clients.PLC.SiemensClient.#ctor(IoTClient.Common.Enums.SiemensVersion,System.Net.IPEndPoint,System.Int32)">
|
<member name="P:IoTClient.Clients.PLC.SiemensClient.Slot">
|
||||||
|
<summary>
|
||||||
|
PLC的槽号
|
||||||
|
</summary>
|
||||||
|
</member>
|
||||||
|
<member name="P:IoTClient.Clients.PLC.SiemensClient.Rack">
|
||||||
|
<summary>
|
||||||
|
PLC的机架号
|
||||||
|
</summary>
|
||||||
|
</member>
|
||||||
|
<member name="M:IoTClient.Clients.PLC.SiemensClient.#ctor(IoTClient.Common.Enums.SiemensVersion,System.Net.IPEndPoint,System.Byte,System.Byte,System.Int32)">
|
||||||
<summary>
|
<summary>
|
||||||
构造函数
|
构造函数
|
||||||
</summary>
|
</summary>
|
||||||
<param name="version">CPU版本</param>
|
<param name="version">CPU版本</param>
|
||||||
<param name="ipAndPoint">IP地址和端口号</param>
|
<param name="ipAndPoint">IP地址和端口号</param>
|
||||||
<param name="timeout">超时时间</param>
|
<param name="timeout">超时时间</param>
|
||||||
|
<param name="slot">PLC的槽号</param>
|
||||||
|
<param name="rack">PLC的机架号</param>
|
||||||
</member>
|
</member>
|
||||||
<member name="M:IoTClient.Clients.PLC.SiemensClient.#ctor(IoTClient.Common.Enums.SiemensVersion,System.String,System.Int32,System.Int32)">
|
<member name="M:IoTClient.Clients.PLC.SiemensClient.#ctor(IoTClient.Common.Enums.SiemensVersion,System.String,System.Int32,System.Byte,System.Byte,System.Int32)">
|
||||||
<summary>
|
<summary>
|
||||||
构造函数
|
构造函数
|
||||||
</summary>
|
</summary>
|
||||||
<param name="version">CPU版本</param>
|
<param name="version">CPU版本</param>
|
||||||
<param name="ip">IP地址</param>
|
<param name="ip">IP地址</param>
|
||||||
<param name="port">端口号</param>
|
<param name="port">端口号</param>
|
||||||
|
<param name="slot">PLC的槽号</param>
|
||||||
|
<param name="rack">PLC的机架号</param>
|
||||||
<param name="timeout">超时时间</param>
|
<param name="timeout">超时时间</param>
|
||||||
</member>
|
</member>
|
||||||
<member name="M:IoTClient.Clients.PLC.SiemensClient.Connect">
|
<member name="M:IoTClient.Clients.PLC.SiemensClient.Connect">
|
||||||
|
|
|
@ -2,9 +2,9 @@
|
||||||
IoTClient
|
IoTClient
|
||||||
</h1>
|
</h1>
|
||||||
|
|
||||||
[](https://www.nuget.org/packages/IoTClient/) [](https://www.nuget.org/packages/IoTClient/) 
|
## [English](README.md) | 简体中文
|
||||||
|
|
||||||
[English](README.md) | 简体中文
|
[](https://www.nuget.org/packages/IoTClient/) [](https://www.nuget.org/packages/IoTClient/) 
|
||||||
|
|
||||||
- 这是一个物联网设备通讯协议实现客户端,将包括主流PLC通信读取、ModBus协议、Bacnet协议等常用工业通讯协议。
|
- 这是一个物联网设备通讯协议实现客户端,将包括主流PLC通信读取、ModBus协议、Bacnet协议等常用工业通讯协议。
|
||||||
- 本组件基于.NET Standard 2.0,可用于.Net的跨平台开发,如Windows、Linux甚至可运行于树莓派上。
|
- 本组件基于.NET Standard 2.0,可用于.Net的跨平台开发,如Windows、Linux甚至可运行于树莓派上。
|
||||||
|
|
128
README.md
128
README.md
|
@ -2,9 +2,9 @@
|
||||||
IoTClient
|
IoTClient
|
||||||
</h1>
|
</h1>
|
||||||
|
|
||||||
[](https://www.nuget.org/packages/IoTClient/) [](https://www.nuget.org/packages/IoTClient/) 
|
## English | [中文文档](README-zh_CN.md)
|
||||||
|
|
||||||
English | [简体中文](README-zh_CN.md)
|
[](https://www.nuget.org/packages/IoTClient/) [](https://www.nuget.org/packages/IoTClient/) 
|
||||||
|
|
||||||
- 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 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 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
|
## 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);
|
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
|
||||||
```
|
```
|
||||||
</details>
|
</details>
|
||||||
|
|
||||||
|
@ -123,10 +123,10 @@ ModBusRtuClient client = new ModBusRtuClient("COM3", 9600, 8, StopBits.One, Pari
|
||||||
|
|
||||||
## ModBusAscii read and write operations
|
## 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);
|
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
|
||||||
```
|
```
|
||||||
</details>
|
</details>
|
||||||
|
|
||||||
|
@ -135,12 +135,12 @@ ModbusAsciiClient client = new ModbusAsciiClient("COM3", 9600, 8, StopBits.One,
|
||||||
|
|
||||||
## ModbusRtuOverTcp read and write operations
|
## 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);
|
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
|
||||||
```
|
```
|
||||||
</details>
|
</details>
|
||||||
|
|
||||||
|
@ -149,34 +149,34 @@ ModbusRtuOverTcpClient client = new ModbusRtuOverTcpClient("127.0.0.1", 502, 150
|
||||||
|
|
||||||
## SiemensClient (Siemens) read and write operations
|
## SiemensClient (Siemens) read and write operations
|
||||||
```
|
```
|
||||||
//1、实例化客户端 - 输入型号、IP和端口
|
//1、Instantiate the client-enter the model, IP and port
|
||||||
//其他型号:SiemensVersion.S7_200、SiemensVersion.S7_300、SiemensVersion.S7_400、SiemensVersion.S7_1200、SiemensVersion.S7_1500
|
//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);
|
SiemensClient client = new SiemensClient(SiemensVersion.S7_200Smart, "127.0.0.1",102);
|
||||||
|
|
||||||
//2、写操作
|
//2、Write operation
|
||||||
client.Write("Q1.3", true);
|
client.Write("Q1.3", true);
|
||||||
client.Write("V2205", (short)11);
|
client.Write("V2205", (short)11);
|
||||||
client.Write("V2209", 33);
|
client.Write("V2209", 33);
|
||||||
|
|
||||||
//3、读操作
|
//3、Read operation
|
||||||
var value1 = client.ReadBoolean("Q1.3").Value;
|
var value1 = client.ReadBoolean("Q1.3").Value;
|
||||||
var value2 = client.ReadInt16("V2205").Value;
|
var value2 = client.ReadInt16("V2205").Value;
|
||||||
var value3 = client.ReadInt32("V2209").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();
|
client.Open();
|
||||||
|
|
||||||
//5、读写操作都会返回操作结果对象Result
|
//5、Read and write operations will return the operation result object Result
|
||||||
var result = client.ReadInt16("V2205");
|
var result = client.ReadInt16("V2205");
|
||||||
//5.1 读取是否成功(true或false)
|
//5.1 Whether the reading is successful (true or false)
|
||||||
var isSucceed = result.IsSucceed;
|
var isSucceed = result.IsSucceed;
|
||||||
//5.2 读取失败的异常信息
|
//5.2 Exception information for failed reading
|
||||||
var errMsg = result.Err;
|
var errMsg = result.Err;
|
||||||
//5.3 读取操作实际发送的请求报文
|
//5.3 Read the request message actually sent by the operation
|
||||||
var requst = result.Requst;
|
var requst = result.Requst;
|
||||||
//5.4 读取操作服务端响应的报文
|
//5.4 Read the response message from the server
|
||||||
var response = result.Response;
|
var response = result.Response;
|
||||||
//5.5 读取到的值
|
//5.5 Read value
|
||||||
var value4 = result.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位)。
|
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")
|
VB263 - client.ReadByte("V263")
|
||||||
VD263 - client.ReadFloat("V263")
|
VD263 - client.ReadFloat("V263")
|
||||||
VD263 - client.ReadInt32("V263")
|
VD263 - client.ReadInt32("V263")
|
||||||
|
@ -197,7 +197,7 @@ DB108.DBW4 - client.ReadUInt16("DB108.4")
|
||||||
DB1.DBX0.0 - client.ReadBoolean("DB1.0.0")
|
DB1.DBX0.0 - client.ReadBoolean("DB1.0.0")
|
||||||
DB1.DBD0 - client.ReadFloat("DB1.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
|
|bit | V1.0 | DB1.DBX1.0
|
||||||
|byte | VB1 | DB1.DBB1
|
|byte | VB1 | DB1.DBB1
|
||||||
|
@ -210,14 +210,14 @@ DB1.DBD0 - client.ReadFloat("DB1.0")
|
||||||
|
|
||||||
## SiemensClient best practices
|
## SiemensClient best practices
|
||||||
```
|
```
|
||||||
1、什么时候不要主动Open
|
1、When not to take the initiative to open
|
||||||
西门子plc一般最多允许8个长连接。所以当连接数不够用的时候或者做测试的时候就不要主动Open,这样组件会自动Open并即时Close。
|
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<string, DataTypeEnum> addresses = new Dictionary<string, DataTypeEnum>();
|
Dictionary<string, DataTypeEnum> addresses = new Dictionary<string, DataTypeEnum>();
|
||||||
addresses.Add("DB4.24", DataTypeEnum.Float);
|
addresses.Add("DB4.24", DataTypeEnum.Float);
|
||||||
addresses.Add("DB1.434.0", DataTypeEnum.Bool);
|
addresses.Add("DB1.434.0", DataTypeEnum.Bool);
|
||||||
|
@ -225,7 +225,7 @@ addresses.Add("V4109", DataTypeEnum.Byte);
|
||||||
...
|
...
|
||||||
var result = client.BatchRead(addresses);
|
var result = client.BatchRead(addresses);
|
||||||
|
|
||||||
//批量写入
|
//Batch write
|
||||||
Dictionary<string, object> addresses = new Dictionary<string, object>();
|
Dictionary<string, object> addresses = new Dictionary<string, object>();
|
||||||
addresses.Add("DB4.24", (float)1);
|
addresses.Add("DB4.24", (float)1);
|
||||||
addresses.Add("DB4.0", (float)2);
|
addresses.Add("DB4.0", (float)2);
|
||||||
|
@ -233,12 +233,12 @@ addresses.Add("DB1.434.0", true);
|
||||||
...
|
...
|
||||||
var result = client.BatchWrite(addresses);
|
var result = client.BatchWrite(addresses);
|
||||||
|
|
||||||
4、【注意】写入数据的时候需要明确数据类型
|
4、[Note] When writing data, you need to clarify the data type
|
||||||
client.Write("DB4.12", 9); //写入的是int类型
|
client.Write("DB4.12", 9); //What is written is of type int
|
||||||
client.Write("DB4.12", (float)9); //写入的是float类型
|
client.Write("DB4.12", (float)9); //What is written is a float type
|
||||||
|
|
||||||
5、SiemensClient是线程安全类
|
5、SiemensClient is a thread safe class
|
||||||
由于plc长连接有限,SiemensClient被设计成线程安全类。可以把SiemensClient设置成单例,在多个线程之间使用SiemensClient的实例读写操作plc。
|
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.
|
||||||
```
|
```
|
||||||
</details>
|
</details>
|
||||||
|
|
||||||
|
@ -247,33 +247,33 @@ client.Write("DB4.12", (float)9); //写入的是float类型
|
||||||
|
|
||||||
## MitsubishiClient (Mitsubishi) read and write operations
|
## 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);
|
MitsubishiClient client = new MitsubishiClient(MitsubishiVersion.Qna_3E, "127.0.0.1",6000);
|
||||||
|
|
||||||
//2、写操作
|
//2、Write operation
|
||||||
client.Write("M100", true);
|
client.Write("M100", true);
|
||||||
client.Write("D200", (short)11);
|
client.Write("D200", (short)11);
|
||||||
client.Write("D210", 33);
|
client.Write("D210", 33);
|
||||||
|
|
||||||
//3、读操作
|
//3、Read operation
|
||||||
var value1 = client.ReadBoolean("M100").Value;
|
var value1 = client.ReadBoolean("M100").Value;
|
||||||
var value2 = client.ReadInt16("D200").Value;
|
var value2 = client.ReadInt16("D200").Value;
|
||||||
var value3 = client.ReadInt32("D210").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();
|
client.Open();
|
||||||
|
|
||||||
//5、读写操作都会返回操作结果对象Result
|
//5、Read and write operations will return the operation result object Result
|
||||||
var result = client.ReadInt16("D210");
|
var result = client.ReadInt16("D210");
|
||||||
//5.1 读取是否成功(true或false)
|
//5.1 Whether the reading is successful (true or false)
|
||||||
var isSucceed = result.IsSucceed;
|
var isSucceed = result.IsSucceed;
|
||||||
//5.2 读取失败的异常信息
|
//5.2 Exception information for failed reading
|
||||||
var errMsg = result.Err;
|
var errMsg = result.Err;
|
||||||
//5.3 读取操作实际发送的请求报文
|
//5.3 Read the request message actually sent by the operation
|
||||||
var requst = result.Requst;
|
var requst = result.Requst;
|
||||||
//5.4 读取操作服务端响应的报文
|
//5.4 Read the response message from the server
|
||||||
var response = result.Response;
|
var response = result.Response;
|
||||||
//5.5 读取到的值
|
//5.5 Read value
|
||||||
var value4 = result.Value;
|
var value4 = result.Value;
|
||||||
```
|
```
|
||||||
</details>
|
</details>
|
||||||
|
@ -283,33 +283,33 @@ var value4 = result.Value;
|
||||||
|
|
||||||
## OmronFinsClient (Omron) read and write operations
|
## 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);
|
OmronFinsClient client = new OmronFinsClient("127.0.0.1",6000);
|
||||||
|
|
||||||
//2、写操作
|
//2、Write operation
|
||||||
client.Write("M100", true);
|
client.Write("M100", true);
|
||||||
client.Write("D200", (short)11);
|
client.Write("D200", (short)11);
|
||||||
client.Write("D210", 33);
|
client.Write("D210", 33);
|
||||||
|
|
||||||
//3、读操作
|
//3、Read operation
|
||||||
var value1 = client.ReadBoolean("M100").Value;
|
var value1 = client.ReadBoolean("M100").Value;
|
||||||
var value2 = client.ReadInt16("D200").Value;
|
var value2 = client.ReadInt16("D200").Value;
|
||||||
var value3 = client.ReadInt32("D210").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();
|
client.Open();
|
||||||
|
|
||||||
//5、读写操作都会返回操作结果对象Result
|
//5、Read and write operations will return the operation result object Result
|
||||||
var result = client.ReadInt16("D210");
|
var result = client.ReadInt16("D210");
|
||||||
//5.1 读取是否成功(true或false)
|
//5.1 Whether the reading is successful (true or false)
|
||||||
var isSucceed = result.IsSucceed;
|
var isSucceed = result.IsSucceed;
|
||||||
//5.2 读取失败的异常信息
|
//5.2 Exception information for failed reading
|
||||||
var errMsg = result.Err;
|
var errMsg = result.Err;
|
||||||
//5.3 读取操作实际发送的请求报文
|
//5.3 Read the request message actually sent by the operation
|
||||||
var requst = result.Requst;
|
var requst = result.Requst;
|
||||||
//5.4 读取操作服务端响应的报文
|
//5.4 Read the response message from the server
|
||||||
var response = result.Response;
|
var response = result.Response;
|
||||||
//5.5 读取到的值
|
//5.5 Read value
|
||||||
var value4 = result.Value;
|
var value4 = result.Value;
|
||||||
```
|
```
|
||||||
</details>
|
</details>
|
||||||
|
@ -319,29 +319,29 @@ var value4 = result.Value;
|
||||||
|
|
||||||
## AllenBradleyClient read and write operations
|
## 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);
|
AllenBradleyClient client = new AllenBradleyClient("127.0.0.1",44818);
|
||||||
|
|
||||||
//2、写操作
|
//2、Write operation
|
||||||
client.Write("A1", (short)11);
|
client.Write("A1", (short)11);
|
||||||
|
|
||||||
//3、读操作
|
//3、Read operation
|
||||||
var value = client.ReadInt16("A1").Value;
|
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();
|
client.Open();
|
||||||
|
|
||||||
//5、读写操作都会返回操作结果对象Result
|
//5、Read and write operations will return the operation result object Result
|
||||||
var result = client.ReadInt16("A1");
|
var result = client.ReadInt16("A1");
|
||||||
//5.1 读取是否成功(true或false)
|
//5.1 Whether the reading is successful (true or false)
|
||||||
var isSucceed = result.IsSucceed;
|
var isSucceed = result.IsSucceed;
|
||||||
//5.2 读取失败的异常信息
|
//5.2 Exception information for failed reading
|
||||||
var errMsg = result.Err;
|
var errMsg = result.Err;
|
||||||
//5.3 读取操作实际发送的请求报文
|
//5.3 Read the request message actually sent by the operation
|
||||||
var requst = result.Requst;
|
var requst = result.Requst;
|
||||||
//5.4 读取操作服务端响应的报文
|
//5.4 Read the response message from the server
|
||||||
var response = result.Response;
|
var response = result.Response;
|
||||||
//5.5 读取到的值
|
//5.5 Read value
|
||||||
var value4 = result.Value;
|
var value4 = result.Value;
|
||||||
```
|
```
|
||||||
</details>
|
</details>
|
||||||
|
|
Loading…
Reference in New Issue
Block a user