NetworkDoubleBaseReadFromCoreServer 方法 (Socket, Byte, Boolean, 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.Core.Net
程序集:
HslCommunication (在 HslCommunication.dll 中) 版本:12.1.1.0 (12.1.1.0)
语法 public virtual OperateResult<byte[]> ReadFromCoreServer(
Socket socket,
byte[] send,
bool hasResponseData = true,
bool usePackAndUnpack = true
)
Public Overridable Function ReadFromCoreServer (
socket As Socket,
send As Byte(),
Optional hasResponseData As Boolean = true,
Optional usePackAndUnpack As Boolean = true
) As OperateResult(Of Byte())
public:
virtual OperateResult<array<unsigned char>^>^ ReadFromCoreServer(
Socket^ socket,
array<unsigned char>^ send,
bool hasResponseData = true,
bool usePackAndUnpack = true
)
abstract ReadFromCoreServer :
socket : Socket *
send : byte[] *
?hasResponseData : bool *
?usePackAndUnpack : bool
(* Defaults:
let _hasResponseData = defaultArg hasResponseData true
let _usePackAndUnpack = defaultArg usePackAndUnpack true
*)
-> OperateResult<byte[]>
override ReadFromCoreServer :
socket : Socket *
send : byte[] *
?hasResponseData : bool *
?usePackAndUnpack : bool
(* Defaults:
let _hasResponseData = defaultArg hasResponseData true
let _usePackAndUnpack = defaultArg usePackAndUnpack true
*)
-> OperateResult<byte[]>
参数
- socket
- 类型:System.Net.SocketsSocket
指定的套接字 - send
- 类型:SystemByte
发送的完整的报文信息 - hasResponseData (Optional)
- 类型:SystemBoolean
是否有等待的数据返回,默认为 true - usePackAndUnpack (Optional)
- 类型:SystemBoolean
是否需要对命令重新打包,在重写PackCommandWithHeader(Byte)方法后才会有影响
返回值
类型:
OperateResultByte接收的完整的报文信息
备注
无锁的基于套接字直接进行叠加协议的操作。
示例
假设你有一个自己的socket连接了设备,本组件可以直接基于该socket实现modbus读取,三菱读取,西门子读取等等操作,前提是该服务器支持多协议,虽然这个需求听上去比较变态,但本组件支持这样的操作。
ModbusTcpNet modbus = new ModbusTcpNet( );
MelsecMcNet melsec = new MelsecMcNet( );
SiemensS7Net siemens = new SiemensS7Net( SiemensPLCS.S1200 );
PipeTcpNet pipe = new PipeTcpNet( "192.168.0.100", 1000 );
pipe.OpenCommunication( );
OperateResult<byte[]> read_modbus = modbus.ReadFromCoreServer( pipe, SoftBasic.HexStringToBytes( "00 00 00 00 00 06 00 03 00 00 00 03" ), hasResponseData: true, usePackAndUnpack: true );
OperateResult<byte[]> read_melsec = melsec.ReadFromCoreServer( pipe, SoftBasic.HexStringToBytes( "50 00 00 FF FF 03 00 0D 00 0A 00 01 14 01 00 64 00 00 90 01 00 10" ), hasResponseData: true, usePackAndUnpack: true );
OperateResult<byte[]> read_siemens = siemens.ReadFromCoreServer( pipe, 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" ), hasResponseData: true, usePackAndUnpack: true );
pipe.CloseCommunication( );
参见