SecsHsmsServer 类 |
命名空间: HslCommunication.Secs
SecsHsmsServer 类型公开以下成员。
名称 | 说明 | |
---|---|---|
SecsHsmsServer |
实例化一个默认的对象
|
名称 | 说明 | |
---|---|---|
CheckSerialDataComplete |
检查串口接收到的数据是否完整
(继承自 CommunicationServer。) | |
CreateNewMessage |
获取一个新的消息对象的方法,需要在继承类里面进行重写 (继承自 CommunicationServer。)The method to get a new message object needs to be overridden in the inheritance class | |
CreatePipeSession |
创建会话状态的委托对象,也就可以自己指定创建自定义的会话
(继承自 CommunicationServer。) | |
DeviceId |
获取或设置当前服务器的默认的ID信息,在发布消息时将使用当前的值 Gets or sets the default ID information for the current server, and the current value will be used when publishing messages | |
EnableIPv6 |
获取或设置服务器是否支持IPv6的地址协议信息 (继承自 CommunicationTcpServer。)Get or set whether the server supports IPv6 address protocol information | |
ForceSerialReceiveOnce |
获取或设置当前的服务器接收串口数据时候,是否强制只接收一次数据,默认为false,适合点对点通信,如果你总线形式的连接,则需要设置 True (继承自 CommunicationServer。)Get or set whether to force the data to be received only once when the current server receives serial port data. The default value is false, which is suitable for point-to-point communication. If you have a bus connection, you need to set True | |
IsStarted |
服务器引擎是否启动 (继承自 CommunicationTcpServer。)Whether the server engine is started | |
LogDebugMessage |
记录一些调试日志的委托,将会进行输出调试文本。 (继承自 CommunicationTcpServer。)The delegate that records some debug logs will output debug text. | |
LogNet |
组件的日志工具,支持日志记录,只要实例化后,当前网络的基本信息,就以DEBUG等级进行输出 (继承自 CommunicationTcpServer。)The component's logging tool supports logging. As long as the instantiation of the basic network information, the output will be output at DEBUG | |
Port |
获取或设置服务器的端口号,如果是设置,需要在服务器启动前设置完成,才能生效。 (继承自 CommunicationTcpServer。)Gets or sets the port number of the server. If it is set, it needs to be set before the server starts to take effect. | |
SerialReceiveAtleastTime |
获取或设置串口模式下,接收一条数据最短的时间要求,当设备发送的数据非常慢的时候,或是分割发送数据的时候,就需要将本值设置的大一点,默认为20ms (继承自 CommunicationServer。)Get or set the shortest time required to receive a piece of data in serial port mode. When the data sent by the device is very slow, or when the data is divided and sent, you need to set this value to a larger value, the default is 20ms | |
SessionsMax |
获取或设置当前允许登录的最大客户端数量,默认为 uint.MaxValue = 4294967295 (继承自 CommunicationServer。)Gets or sets the maximum number of clients that are currently allowed to log in, which defaults to uint.MaxValue = 4294967295 | |
SocketKeepAliveTime |
获取或设置客户端的Socket的心跳时间信息,这个是Socket底层自动实现的心跳包,不基于协议层实现。默认小于0,不开启心跳检测,如果需要开启,设置 60_000 比较合适,单位毫秒 (继承自 CommunicationTcpServer。)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. | |
StringEncoding |
获取或设置用于字符串解析的编码信息 Obtain or set encoding information for string parsing | |
ThreadPoolLoginAfterClientCheck |
当线程检查后,进行登录之前的检查,通常用于自定义的握手包校验操作。仅对TCP通信的时候有效。
(继承自 CommunicationServer。) | |
UdpBufferSize |
获取或设置一次接收时的数据长度,默认2KB数据长度,特殊情况的时候需要调整 (继承自 CommunicationServer。)Gets or sets the length of data received at a time. The default length is 2KB |
名称 | 说明 | |
---|---|---|
AddSession |
新增加一个管道会话信息 (继承自 CommunicationServer。)A new pipeline session information has been added | |
CheckSerialReceiveDataComplete |
检查串口接收的数据是否完成的方法,如果接收完成,则返回True (继承自 CommunicationServer。) | |
CloseSerialSlave |
关闭提供从机服务的串口对象 (继承自 CommunicationServer。)Close the serial port object that provides slave services | |
ConnectHslAlientClient |
创建一个指定的异形客户端连接,使用Hsl协议来发送注册包 (继承自 CommunicationServer。)Create a specified profiled client connection and use the Hsl protocol to send registration packets | |
ConnectRemoteServer |
新增一个主动连接的请求,将不会收到是否连接成功的信息,当网络中断及奔溃之后,会自动重新连接。 (继承自 CommunicationServer。)A new active connection request will not receive a message whether the connection is successful. When the network is interrupted and crashed, it will automatically reconnect. | |
Equals | Determines whether the specified object is equal to the current object. (继承自 Object。) | |
ExtraOnClose |
关闭的时候额外执行的功能代码
(继承自 CommunicationServer。) | |
ExtraOnStart |
服务器启动的时候额外执行的功能代码
(继承自 CommunicationTcpServer。) | |
Finalize | Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (继承自 Object。) | |
GetHashCode | Serves as the default hash function. (继承自 Object。) | |
GetNewNetMessage |
获取一个新的消息对象的方法,需要在继承类里面进行重写 (重写 CommunicationServerGetNewNetMessage.)The method to get a new message object needs to be overridden in the inheritance class | |
GetPipeSessions |
获取管道会话的列表 (继承自 CommunicationServer。)Get a list of pipeline sessions | |
GetTrustedClients |
获取受信任的客户端列表 (继承自 CommunicationTcpServer。)Get a list of trusted clients | |
GetType | Gets the Type of the current instance. (继承自 Object。) | |
LogDebugMsg |
记录当前的日志信息
(继承自 CommunicationTcpServer。) | |
MemberwiseClone | Creates a shallow copy of the current Object. (继承自 Object。) | |
PublishSecsMessage(Byte, Byte, SecsValue) |
发布数据到所有的在线客户端信息
| |
PublishSecsMessage(Byte, Byte, SecsValue, Boolean) |
发布数据到所有的在线客户端信息
| |
RemoveSession(TimeSpan) |
指定超时时间移除当前的会话列表,只有是TCP的管道(PipeTcpNet)才需要被移除。 (继承自 CommunicationServer。)Specify a timeout to remove the current session list. Only TCP pipe (PipeTcpNet) need to be removed. | |
RemoveSession(PipeSession, String) |
移除一个管道会话 (继承自 CommunicationServer。)Remove a pipeline session | |
SendByCommand(PipeSession, SecsMessage, Byte, Byte, SecsValue) |
向指定的会话信息发送SECS格式的原始字节数据信息,session 为当前的会话对象,receiveMessage为接收到数据,后续的参数才是真实的返回数据
| |
SendByCommand(PipeSession, SecsMessage, Byte, Byte, Byte) |
向指定的会话信息发送SECS格式的原始字节数据信息,session 为当前的会话对象,receiveMessage为接收到数据,后续的参数才是真实的返回数据
| |
SendByCommand(PipeSession, SecsMessage, Byte, Byte, SecsValue, Boolean) |
向指定的会话信息发送SECS格式的原始字节数据信息,session 为当前的会话对象,receiveMessage为接收到数据,后续的参数才是真实的返回数据
| |
SendByCommand(PipeSession, SecsMessage, Byte, Byte, Byte, Boolean) |
向指定的会话信息发送SECS格式的原始字节数据信息,session 为当前的会话对象,receiveMessage为接收到数据,后续的参数才是真实的返回数据
| |
ServerClose |
关闭服务器的引擎 (继承自 CommunicationTcpServer。)Shut down the server's engine | |
ServerStart |
指定端口号来启动服务器的引擎 (继承自 CommunicationTcpServer。)Specify the port number to start the server's engine | |
ServerStart(Int32) |
指定端口号来启动服务器的引擎 (继承自 CommunicationTcpServer。)Specify the port number to start the server's engine | |
ServerStart(Int32, Boolean) |
指定端口号来启动服务器的引擎 (继承自 CommunicationServer。)Specify the port number to start the server's engine | |
ServerStart(Int32, Int32) |
指定一个TCP端口及UDP端口,同时启动两种模式的服务器 (继承自 CommunicationServer。)Specify a TCP port and a UDP port to start the server in both modes at the same time | |
SetNetMessage |
设置当前的服务器接收的消息信息
(继承自 CommunicationServer。) | |
SetTrustedIpAddress |
设置并启动受信任的客户端登录并读写,如果为null,将关闭对客户端的ip验证 (继承自 CommunicationTcpServer。)Set and start the trusted client login and read and write, if it is null, the client's IP verification will be turned off | |
SocketAcceptExtraCheck |
当客户端的socket登录的时候额外检查的操作,并返回操作的结果信息。 (继承自 CommunicationTcpServer。)The operation is additionally checked when the client's socket logs in, and the result information of the operation is returned. | |
StartSerialSlave(ActionSerialPort) |
启动串口的从机服务,使用自定义的初始化方法初始化串口的参数 (继承自 CommunicationServer。)Start the slave service of serial and initialize the parameters of the serial port using a custom initialization method | |
StartSerialSlave(String) |
启动串口的从机服务,使用默认的参数进行初始化串口,9600波特率,8位数据位,无奇偶校验,1位停止位 (继承自 CommunicationServer。)Start the slave service of serial, initialize the serial port with default parameters, 9600 baud rate, 8 data bits, no parity, 1 stop bit | |
StartSerialSlave(String, Int32) |
启动串口的从机服务,使用默认的参数进行初始化串口,8位数据位,无奇偶校验,1位停止位 (继承自 CommunicationServer。)Start the slave service of serial, initialize the serial port with default parameters, 8 data bits, no parity, 1 stop bit | |
StartSerialSlave(String, Int32, Int32, Parity, StopBits) |
启动串口的从机服务,使用指定的参数进行初始化串口,指定数据位,指定奇偶校验,指定停止位 (继承自 CommunicationServer。) | |
ThreadPoolLogin |
当客户端连接到服务器,并听过额外的检查后,进行回调的方法 (继承自 CommunicationServer。)Callback method when the client connects to the server and has heard additional checks | |
ToString | Returns a string that represents the current object. (重写 CommunicationServerToString.) | |
UseSSL(X509Certificate) |
使用SSL通信,传递一个证书的对象
(继承自 CommunicationTcpServer。) | |
UseSSL(String, String) |
使用SSL通信,传递一个证书的路径,以及证书的密码
(继承自 CommunicationTcpServer。) |
名称 | 说明 | |
---|---|---|
OnClientOffline |
当客户端下线时候的触发的事件 (继承自 CommunicationServer。)Event triggered when the client goes offline | |
OnClientOnline |
当客户端上线时候的触发的事件 (继承自 CommunicationServer。)Event triggered when the client goes online | |
OnPipeMessageReceived |
当管道接收到消息时触发
(继承自 CommunicationServer。) | |
OnSecsMessageReceived |
接收到数据的时候就触发的事件,示例详细参考API文档信息 An event that is triggered when data is received |
名称 | 说明 | |
---|---|---|
socketServer |
核心的socket服务器
(继承自 CommunicationTcpServer。) |
名称 | 说明 | |
---|---|---|
ToJsonString |
获取当前对象的JSON格式表示的字符串。 (由 HslExtension 定义。)Gets the string represented by the JSON format of the current object. |
private SecsHsmsServer server; public void ServerStart( ) { server = new SecsHsmsServer( ); // 实例化 server.OnSecsMessageReceived += Server_OnSecsMessageReceived; // 如果有客户端发来数据,触发事件 server.ServerStart( 5000 ); // 启动服务器 } private void Server_OnSecsMessageReceived( object sender, HslCommunication.Core.Net.PipeSession session, SecsMessage message ) { // 举例,处理 S1F1 的功能码 if (message.StreamNo == 1 && message.FunctionNo == 1) { // 返回两个数据的列表,是否真的返回,取决于代码 server.SendByCommand( session, message, 1, 2, new SecsValue( new string[] { "MDLN", "SOFTREV" } ) ); } else if (message.StreamNo == 2 && message.FunctionNo == 17) { // 返回时间数据对象信息 server.SendByCommand( session, message, 2, 18, new SecsValue( DateTime.Now.ToString( "yy MM dd HH mm ss" ).Replace( " ", "" ) ) ); } }
public void Sample2( ) { // 按照事例逐级提供演示 // 1. 最简单的 SVID "U4:1 810" SecsValue secsValue = new SecsValue( (uint)810 ); // 2. 字符串信息 SPNAME Example: "A:10 {BatchLocID}" secsValue = new SecsValue( "BatchLocID" ); // 3. 如果是 SVID的列表 {L:n SVID } secsValue = new SecsValue( new object[] { (uint)810 } ); // 多几个数据,就塞几个SVID // 4. 多个数据的 S1F13R // {L2 // MDLN // SOFTREV // } secsValue = new SecsValue( new object[] { "gemsim", "1.0" } ); // 5. 每种数据类型不一样,还支持嵌套行为,例如 S1F19R Get Attribute // {L:3 // OBJTYPE // {L:m // OBJID // } // {L:n // ATTRID // } //} // 我们假设有两个ID及两个特性ID需要读取,假设这些ID都是以字符串的形式的 secsValue = new SecsValue( new object[] { "A Carrier", new object[] { "Job0001", "Job0002" }, new object[] { "SourceURL", "SourceURL2" } } ); // 我们看到层级关系是一致的,而且object[]即表示列表,所有的数据可以层级嵌套。 // 下面简单的举例各种类型的实例化 secsValue = new SecsValue( true ); // Bool型 secsValue = new SecsValue( (sbyte)1 ); // I1 secsValue = new SecsValue( (byte)1 ); // U1 secsValue = new SecsValue( (short)1 ); // I2 secsValue = new SecsValue( (ushort)1 ); // U2 secsValue = new SecsValue( 1 ); // I4 secsValue = new SecsValue( (uint)1 ); // U4 secsValue = new SecsValue( (long)1 ); // I8 secsValue = new SecsValue( (ulong)1 ); // U8 secsValue = new SecsValue( (float)1 ); // F4 secsValue = new SecsValue( (double)1 ); // F8 secsValue = new SecsValue( "ABCD" ); // ASCII secsValue = new SecsValue( new string[] { "ABCD", "DEEG" } ); // 一个list,多个string元素 secsValue = new SecsValue( new byte[] { 0x01, 0x02, 0x03 } ); // Binary // 特别说明 secsValue = new SecsValue( ); // 默认的构造方法为空的secsvalue,没有任何的数据 // XML序列化和反序列化 secsValue = new SecsValue( new object[] { "gemsim", "1.0" } ); System.Xml.Linq.XElement element = secsValue.ToXElement( ); // 生成XML,可用于显示,存储,数据发送 SecsValue secsValueAgain = new SecsValue( element ); // 从XML进行实例化,数据是一模一样的 // 二进制的序列化和反序列化也是支持 secsValue = new SecsValue( new object[] { "gemsim", "1.0" } ); byte[] source = secsValue.ToSourceBytes( ); // 二进制的容量更小,可以直接当为data,发送到设备 secsValueAgain = SecsValue.ParseFromSource( source, Encoding.ASCII ); // 反序列化回来 }