点击或拖拽改变大小

RedisClientReadFromCoreServer 方法 (Socket, Byte, Boolean)

将数据报文发送指定的网络通道上,根据当前指定的INetMessage类型,返回一条完整的数据指令
Sends a data message to the specified network channel, and returns a complete data command according to the currently specified INetMessage type

命名空间:  HslCommunication.Enthernet.Redis
程序集:  HslCommunication (在 HslCommunication.dll 中) 版本:9.6.0.0 (9.6.0.0)
语法
public override OperateResult<byte[]> ReadFromCoreServer(
	Socket socket,
	byte[] send,
	bool hasResponseData = true
)

参数

socket
类型:System.Net.SocketsSocket
指定的套接字
send
类型:SystemByte
发送的完整的报文信息
hasResponseData (Optional)
类型:SystemBoolean
是否有等待的数据返回,默认为 true

返回值

类型:OperateResultByte
接收的完整的报文信息
备注
无锁的基于套接字直接进行叠加协议的操作。
示例
假设你有一个自己的socket连接了设备,本组件可以直接基于该socket实现modbus读取,三菱读取,西门子读取等等操作,前提是该服务器支持多协议,虽然这个需求听上去比较变态,但本组件支持这样的操作。
ReadFromCoreServer示例
ModbusTcpNet modbus = new ModbusTcpNet( );
MelsecMcNet melsec = new MelsecMcNet( );
SiemensS7Net siemens = new SiemensS7Net( SiemensPLCS.S1200 );

// 创建并连接一个socket
Socket socket = new Socket( AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp );
socket.Connect( System.Net.IPAddress.Parse( "192.168.0.100" ), 1000 );

// 叠加读写操作
OperateResult<byte[]> read_modbus = modbus.ReadFromCoreServer( socket, SoftBasic.HexStringToBytes( "00 00 00 00 00 06 00 03 00 00 00 03" ) );
OperateResult<byte[]> read_melsec = melsec.ReadFromCoreServer( socket, SoftBasic.HexStringToBytes( "50 00 00 FF FF 03 00 0D 00 0A 00 01 14 01 00 64 00 00 90 01 00 10" ) );
OperateResult<byte[]> read_siemens = siemens.ReadFromCoreServer( socket, SoftBasic.HexStringToBytes( "03 00 00 24 02 F0 80 32 01 00 00 00 01 00 0E 00 05 05 01 12 0A 10 02 00 01 00 00 83 00 03 20 00 04 00 08 3B" ) );


socket.Close( );
参见