OpenProtocolNet 类 |
命名空间: HslCommunication.Profinet.OpenProtocol
OpenProtocolNet 类型公开以下成员。
名称 | 说明 | |
---|---|---|
OpenProtocolNet |
实例化一个默认的对象 Instantiate a default object | |
OpenProtocolNet(String, Int32) |
使用指定的IP地址及端口来初始化对象 Use the specified IP address and port to initialize the object |
名称 | 说明 | |
---|---|---|
AutoAckControllerMessage |
针对控制器的主动发送的消息,是否无视Ack标记,全部进行返回信号操作,默认为 False,将根据报文里的Ack信号来决定是否返回数据 If the default value is False, the controller will decide whether to return data based on the Ack signal in the packet | |
CommunicationPipe | (继承自 BinaryCommunication。) | |
ConnectionId |
当前连接的唯一ID号,默认为长度20的guid码加随机数组成,方便列表管理,也可以自己指定 (继承自 BinaryCommunication。)The unique ID number of the current connection. The default is a 20-digit guid code plus a random number. | |
ConnectTimeOut |
获取或设置接收服务器反馈的时间,如果为负数,则不接收反馈 (继承自 TcpNetCommunication。)Gets or sets the time to receive server feedback, and if it is a negative number, does not receive feedback | |
IpAddress |
获取或是设置远程服务器的IP地址,如果是本机测试,那么需要设置为127.0.0.1 (继承自 TcpNetCommunication。)Get or set the IP address of the remote server. If it is a local test, then it needs to be set to 127.0.0.1 | |
JobMessage |
任务消息的相关属性,可以用来获取任务的数据,订阅任务,取消订阅任务,选择任务,启动任务。 The relevant properties of task messages can be used to obtain task data, subscribe to tasks, unsubscribe tasks, select tasks, and start tasks. | |
LocalBinding |
获取或设置绑定的本地的IP地址和端口号信息,如果端口设置为0,代表任何可用的端口 (继承自 TcpNetCommunication。)Get or set the bound local IP address and port number information, if the port is set to 0, it means any available port | |
LogNet |
组件的日志工具,支持日志记录,只要实例化后,当前网络的基本信息,就以DEBUG等级进行输出 (继承自 BinaryCommunication。)The component's logging tool supports logging. As long as the instantiation of the basic network information, the output will be output at DEBUG | |
ParameterSetMessages |
参数集合操作的相关属性,可以用来获取参数ID列表,设置数据等操作。 The properties related to parameter collection operations can be used to obtain parameter ID lists, set data, and other operations. | |
Port |
获取或设置服务器的端口号,具体的值需要取决于对方的配置 (继承自 TcpNetCommunication。)Gets or sets the port number of the server. The specific value depends on the configuration of the other party. | |
ReceiveTimeOut |
获取或设置接收服务器反馈的时间,如果为负数,则不接收反馈 (继承自 BinaryCommunication。)Gets or sets the time to receive server feedback, and if it is a negative number, does not receive feedback | |
RevisonOnConnected |
获取或设置初始化连接时 MID0001 命令的版本号,默认为 1,如果设置小于 0,则表示不发送 MID0001 命令。 Get or set the version of the MID0001 command when initializing the connection, the default is 1, if the setting is less than 0, it means that the MID0001 command is not sent. | |
SendBeforeHex |
获取或设置在发送通信报文前追加发送的字节信息,HEX格式,通常用于lora组网时,需要携带 00 00 00 02 四个字节的站地址功能。 (继承自 BinaryCommunication。)Obtain or set the byte information sent before sending communication packets, HEX format, usually used for LORA networking, you need to carry 00 00 00 02 four-byte station address function. | |
SleepTime |
获取或设置在正式接收对方返回数据前的时候,需要休息的时间,当设置为0的时候,不需要休息。 (继承自 BinaryCommunication。)Get or set the time required to rest before officially receiving the data from the other party. When it is set to 0, no rest is required. | |
SocketKeepAliveTime |
获取或设置客户端的Socket的心跳时间信息,这个是Socket底层自动实现的心跳包,不基于协议层实现。默认小于0,不开启心跳检测,如果需要开启,设置 60_000 比较合适,单位毫秒 (继承自 TcpNetCommunication。)Get or set the heartbeat time information of the Socket of the client. This is the heartbeat packet automatically implemented by the bottom layer of the Socket, not based on the protocol layer. The default value is less than 0, and heartbeat detection is not enabled. If you need to enable it, it is more appropriate to set 60_000, in milliseconds. | |
TighteningResultMessages |
拧紧结果消息的操作属性
| |
TimeMessages |
时间消息的属性
| |
ToolMessages |
工具消息的操作属性
|
名称 | 说明 | |
---|---|---|
BuildOpenProtocolMessage |
构建一个读取的初始报文
| |
BuildReadCommand |
构建一个读取的初始报文
| |
CheckRequestReplyMessages |
检查请求返回的消息是否合法的
| |
ConnectClose |
手动断开与远程服务器的连接,如果当前是长连接模式,那么就会切换到短连接模式 (继承自 TcpNetCommunication。)Manually disconnect from the remote server, if it is currently in long connection mode, it will switch to short connection mode | |
ConnectCloseAsync |
手动断开与远程服务器的连接,如果当前是长连接模式,那么就会切换到短连接模式 (继承自 TcpNetCommunication。)Manually disconnect from the remote server, if it is currently in long connection mode, it will switch to short connection mode | |
ConnectServer |
尝试连接远程的服务器,如果连接成功,就切换短连接模式到长连接模式,后面的每次请求都共享一个通道,使得通讯速度更快速 (继承自 TcpNetCommunication。)Try to connect to a remote server. If the connection is successful, switch the short connection mode to the long connection mode. Each subsequent request will share a channel, making the communication speed faster. | |
ConnectServerAsync |
尝试连接远程的服务器,如果连接成功,就切换短连接模式到长连接模式,后面的每次请求都共享一个通道,使得通讯速度更快速 (继承自 TcpNetCommunication。)Try to connect to a remote server. If the connection is successful, switch the short connection mode to the long connection mode. Each subsequent request will share a channel, making the communication speed faster. | |
DecideWhetherQAMessage |
决定当前的消息是否是用于问答机制返回的消息,默认直接返回 true, 实际的情况需要根据协议进行重写方法 (重写 BinaryCommunicationDecideWhetherQAMessage(CommunicationPipe, OperateResultByte).)To determine whether the current message is the message returned by the question answering mechanism, the default is true. In actual cases, the rewriting method needs to be performed according to the protocol | |
Equals | Determines whether the specified object is equal to the current object. (继承自 Object。) | |
ExtraAfterReadFromCoreServer |
和服务器交互完成的时候调用的方法,可以根据读写结果进行一些额外的操作,具体的操作需要根据实际的需求来重写实现 (继承自 BinaryCommunication。)The method called when the interaction with the server is completed can perform some additional operations based on the read and write results. The specific operations need to be rewritten according to actual needs. | |
ExtraOnDisconnect |
根据实际的协议选择是否重写本方法,有些协议在断开连接之前,需要发送一些报文来关闭当前的网络通道 (重写 BinaryCommunicationExtraOnDisconnect.)Select whether to rewrite this method according to the actual protocol. Some protocols need to send some packets to close the current network channel before disconnecting. | |
ExtraOnDisconnectAsync |
根据实际的协议选择是否重写本方法,有些协议在断开连接之前,需要发送一些报文来关闭当前的网络通道 (继承自 BinaryCommunication。)Select whether to rewrite this method according to the actual protocol. Some protocols need to send some packets to close the current network channel before disconnecting. | |
Finalize | Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (继承自 Object。) | |
GetErrorText |
根据错误代码来获取到错误文本信息
| |
GetHashCode | Serves as the default hash function. (继承自 Object。) | |
GetLogTextFromBinary |
获取当前的报文进行日志记录的时候,是否使用二进制的格式记录,默认返回 LogMsgFormatBinary,重写可以根据session对象分别返回不同记录模式 (继承自 BinaryCommunication。)Whether to log the current packet in binary format, the default return is LogMsgFormatBinary. If you want to override it, different recording modes can be returned according to session | |
GetNewNetMessage |
获取一个新的消息对象的方法,需要在继承类里面进行重写 (重写 BinaryCommunicationGetNewNetMessage.)The method to get a new message object needs to be overridden in the inheritance class | |
GetType | Gets the Type of the current instance. (继承自 Object。) | |
InitializationOnConnect |
根据实际的协议选择是否重写本方法,有些协议在创建连接之后,需要进行一些初始化的信号握手,才能最终建立网络通道。 (重写 BinaryCommunicationInitializationOnConnect.)Whether to rewrite this method is based on the actual protocol. Some protocols require some initial signal handshake to establish a network channel after the connection is created. | |
InitializationOnConnectAsync |
根据实际的协议选择是否重写本方法,有些协议在创建连接之后,需要进行一些初始化的信号握手,才能最终建立网络通道。 (重写 BinaryCommunicationInitializationOnConnectAsync.)Whether to rewrite this method is based on the actual protocol. Some protocols require some initial signal handshake to establish a network channel after the connection is created. | |
IpAddressPing |
对当前设备的IP地址进行PING的操作,返回PING的结果,正常来说,返回Success (继承自 TcpNetCommunication。)PING the IP address of the current device and return the PING result. Normally, it returns Success | |
LogRevcMessage(Byte) |
使用日志记录一个接收的报文信息 (继承自 BinaryCommunication。)` Logs are used to record information about a received packet | |
LogRevcMessage(Byte, PipeSession) |
使用日志记录一个接收的报文信息 (继承自 BinaryCommunication。)` Logs are used to record information about a received packet | |
LogSendMessage(Byte) |
使用日志记录一个发送的报文信息 (继承自 BinaryCommunication。)Logs are used to record information about a send packet | |
LogSendMessage(Byte, PipeSession) |
使用日志记录一个发送的报文信息 (继承自 BinaryCommunication。)Logs are used to record information about a send packet | |
MemberwiseClone | Creates a shallow copy of the current Object. (继承自 Object。) | |
PackCommandWithHeader |
对当前的命令进行打包处理,通常是携带命令头内容,标记当前的命令的长度信息,需要进行重写,否则默认不打包 (继承自 BinaryCommunication。)The current command is packaged, usually carrying the content of the command header, marking the length of the current command, and it needs to be rewritten, otherwise it is not packaged by default | |
ReadCustomer |
使用自定义的命令读取数据,需要指定每个参数信息,然后返回字符串数据内容,根据实际的功能码,解析出实际的数据信息 To use a custom command to read data, you need to specify each parameter information, then return the string data content, and parse the actual data information according to the actual function code | |
ReadCustomerAsync |
使用自定义的命令读取数据,需要指定每个参数信息,然后返回字符串数据内容,根据实际的功能码,解析出实际的数据信息 To use a custom command to read data, you need to specify each parameter information, then return the string data content, and parse the actual data information according to the actual function code | |
ReadFromCoreServer(Byte) |
将二进制的数据发送到管道中去,然后从管道里接收二进制的数据回来,并返回是否成功的结果对象。 (继承自 BinaryCommunication。)Send binary data to the pipeline, and then receive binary data back from the pipeline, and return whether the success of the result object | |
ReadFromCoreServer(IEnumerableByte) |
将多个数据报文按顺序发到设备,并从设备接收返回的数据内容,然后拼接成一个Byte[]信息,需要重写UnpackResponseContent(Byte, Byte)方法才能返回正确的结果。 (继承自 BinaryCommunication。)Send multiple data packets to the device in sequence, and receive the returned data content from the device, and then splicing them into a Byte[] message, you need to rewrite UnpackResponseContent(Byte, Byte) method to return the correct result. | |
ReadFromCoreServer(Byte, Boolean, Boolean) |
将二进制的数据发送到管道中去,然后从管道里接收二进制的数据回来,并返回是否成功的结果对象。 (继承自 BinaryCommunication。)Send binary data to the pipeline, and then receive binary data back from the pipeline, and return whether the success of the result object | |
ReadFromCoreServer(CommunicationPipe, Byte, Boolean, Boolean) |
使用指定的管道来进行数据通信,发送原始数据到管道,然后从管道接收相关的数据返回,本方法无锁
(继承自 BinaryCommunication。) | |
ReadFromCoreServerAsync(Byte) |
将二进制的数据发送到管道中去,然后从管道里接收二进制的数据回来,并返回是否成功的结果对象。 (继承自 BinaryCommunication。)Send binary data to the pipeline, and then receive binary data back from the pipeline, and return whether the success of the result object | |
ReadFromCoreServerAsync(IEnumerableByte) |
将多个数据报文按顺序发到设备,并从设备接收返回的数据内容,然后拼接成一个Byte[]信息,需要重写UnpackResponseContent(Byte, Byte)方法才能返回正确的结果。 (继承自 BinaryCommunication。)Send multiple data packets to the device in sequence, and receive the returned data content from the device, and then splicing them into a Byte[] message, you need to rewrite UnpackResponseContent(Byte, Byte) method to return the correct result. | |
ReadFromCoreServerAsync(Byte, Boolean, Boolean) |
将二进制的数据发送到管道中去,然后从管道里接收二进制的数据回来,并返回是否成功的结果对象。 (继承自 BinaryCommunication。)Send binary data to the pipeline, and then receive binary data back from the pipeline, and return whether the success of the result object | |
ReadFromCoreServerAsync(CommunicationPipe, Byte, Boolean, Boolean) |
使用指定的管道来进行数据通信,发送原始数据到管道,然后从管道接收相关的数据返回,本方法无锁
(继承自 BinaryCommunication。) | |
SetDtuPipe |
将当前的通信对象设置DTU模式,允许传入现成的管道,并返回初始化结果,如果该设备重写了握手报文,就是返回握手结果 (继承自 BinaryCommunication。)Set the current communication object to DTU mode, allow the existing pipe to be passed in, and return the initialization result, if the device rewrites the handshake packet, the handshake result is returned | |
SetDtuPipeAsync |
将当前的通信对象设置DTU模式,允许传入现成的管道,并返回初始化结果,如果该设备重写了握手报文,就是返回握手结果 (继承自 BinaryCommunication。)Set the current communication object to DTU mode, allow the existing pipe to be passed in, and return the initialization result, if the device rewrites the handshake packet, the handshake result is returned | |
ToString | Returns a string that represents the current object. (重写 TcpNetCommunicationToString.) | |
UnpackResponseContent |
根据对方返回的报文命令,对命令进行基本的拆包,例如各种Modbus协议拆包为统一的核心报文,还支持对报文的验证 (继承自 BinaryCommunication。)According to the message command returned by the other party, the command is basically unpacked, for example, various Modbus protocols are unpacked into a unified core message, and the verification of the message is also supported |
名称 | 说明 | |
---|---|---|
OnReceivedOpenMessage |
当接收到OpenProtocol协议消息触发的事件
|
名称 | 说明 | |
---|---|---|
LogMsgFormatBinary |
设置日志记录报文是否二进制,如果为False,那就使用ASCII码 (继承自 BinaryCommunication。)Set whether the log message is binary, if it is False, then use ASCII code |
名称 | 说明 | |
---|---|---|
ToJsonString |
获取当前对象的JSON格式表示的字符串。 (由 HslExtension 定义。)Gets the string represented by the JSON format of the current object. |
// 实例化对象,指定open协议的ip地址 OpenProtocolNet openProtocol = new OpenProtocolNet( "192.168.1.110", 4545 ); // 连接 OperateResult connect = openProtocol.ConnectServer( ); if (connect.IsSuccess) { // connect success! } else { // connect failed 连接失败,应该提醒或是返回 Console.WriteLine( "connect failed: " + connect.Message ); return; } // 举例自定义读取数据 // 以下例子使用 MID0010 例子读取参数ID的集合,具体参见手册 // Send: 00200010 NUL // Rece: 00290011 002001002NUL OperateResult<string> read = openProtocol.ReadCustomer( 10, 1, -1, -1, null ); if (read.IsSuccess) { List<int> list = new List<int>(); int count = Convert.ToInt32( read.Content.Substring( 20, 3 ) ); for (int i = 0; i < count; i++) { list.Add( Convert.ToInt32( read.Content.Substring( 23 + i * 3, 3 ) ) ); } // list 就是所有参数ID的集合,其他命令也是类似的解析 } else { Console.WriteLine( "read failed: " + read.Message ); } // 系统退出的时候关闭连接 openProtocol.ConnectClose( );
// 当然hslcommunication里也提供了几个更加便捷的数据交互的方法 // 以下例子使用 MID0010 例子读取参数ID的集合 OperateResult<int[]> read = openProtocol.ParameterSetMessages.ParameterSetIDUpload( ); if (read.IsSuccess) { // read.Content 就是读取的结果; } else { Console.WriteLine( "read failed: " + read.Message ); } // 比如订阅,取消订阅操作 OperateResult sub = openProtocol.ParameterSetMessages.ParameterSetSelectedSubscribe( ); if (sub.IsSuccess) { Console.WriteLine( "sub success" ); } else { Console.WriteLine( "sub faield: " + sub.Message ); } OperateResult unsub = openProtocol.ParameterSetMessages.ParameterSetSelectedUnsubscribe( ); if (unsub.IsSuccess) { Console.WriteLine( "unsub success" ); } else { Console.WriteLine( "unsub faield: " + unsub.Message ); }
// 实例化对象,指定open协议的ip地址 OpenProtocolNet openProtocol = new OpenProtocolNet( "192.168.1.110", 4545 ); // 绑定事件即可支持订阅操作 openProtocol.OnReceivedOpenMessage += ( object sender, OpenEventArgs e ) => { string mid = e.Content.Substring( 4, 4 ); if (mid == "0015") { // 如果订阅了 0014 的功能码 } else if (mid == "0035") { // 如果订阅了 Job Message的0034 功能码 } // 等等 }; // 连接 OperateResult connect = openProtocol.ConnectServer( ); if (connect.IsSuccess) { // connect success! } else { // connect failed 连接失败,应该提醒或是返回 Console.WriteLine( "connect failed: " + connect.Message ); return; } // 订阅 0014 OperateResult sub = openProtocol.ParameterSetMessages.ParameterSetSelectedSubscribe( ); if (sub.IsSuccess) { Console.WriteLine( "sub success" ); } else { Console.WriteLine( "sub faield: " + sub.Message ); }