public override void ClientEncode( ModbusCommand command, ByteArrayWriter body) { body.WriteUInt16BE((ushort)command.Offset); body.WriteUInt16BE(command.Data[0]); }
public override void ClientEncode( ModbusCommand command, ByteArrayWriter body) { body.WriteUInt16BE((ushort)command.Offset); body.WriteUInt16BE(command.Data[0]); }
public override bool ServerEncode( ModbusCommand command, ByteArrayWriter body) { //ModbusCodecBase.PushRequestHeader( // command, // body); body.WriteUInt16BE((ushort)command.Offset); body.WriteUInt16BE(command.Data[0]); return(true); }
void IProtocolCodec.ServerEncode(CommDataBase data) { ModbusServer ownerProtocol = (ModbusServer)data.OwnerProtocol; ModbusCommand userData = (ModbusCommand)data.UserData; byte functionCode = userData.FunctionCode; ByteArrayWriter byteArrayWriter1 = new ByteArrayWriter(); ModbusCodecBase.CommandCodecs[(int)functionCode]?.ServerEncode(userData, byteArrayWriter1); int num = userData.ExceptionCode == (byte)0 ? 2 + byteArrayWriter1.Length : 3; ByteArrayWriter byteArrayWriter2 = new ByteArrayWriter(); byteArrayWriter2.WriteUInt16BE((ushort)userData.TransId); byteArrayWriter2.WriteInt16BE((short)0); byteArrayWriter2.WriteInt16BE((short)num); byteArrayWriter2.WriteByte(ownerProtocol.Address); if (userData.ExceptionCode == (byte)0) { byteArrayWriter2.WriteByte(userData.FunctionCode); byteArrayWriter2.WriteBytes(byteArrayWriter1); } else { byteArrayWriter2.WriteByte((byte)((uint)userData.FunctionCode | 128U)); byteArrayWriter2.WriteByte(userData.ExceptionCode); } data.OutgoingData = byteArrayWriter2.ToReader(); }
//public static readonly ModbusCommandCodec[] CommandCodecs = new ModbusCommandCodec[36]; /// <summary> /// Append the typical header for a request command (master-side) /// </summary> /// <param name="command"></param> /// <param name="body"></param> internal static void PushRequestHeader( ModbusCommand command, ByteArrayWriter body) { body.WriteUInt16BE((ushort)command.Offset); body.WriteInt16BE((short)command.Count); }
//public static readonly ModbusCommandCodec[] CommandCodecs = new ModbusCommandCodec[36]; /// <summary> /// Append the typical header for a request command (master-side) /// </summary> /// <param name="command"></param> /// <param name="body"></param> internal static void PushRequestHeader( ModbusCommand command, ByteArrayWriter body) { body.WriteUInt16BE((ushort)command.Offset); body.WriteInt16BE((short)command.Count); }
public override void ClientEncode(ModbusCommand command, ByteArrayWriter body) { body.WriteUInt16BE((ushort)command.Offset); int num = command.Data[0] != (ushort)0 ? 65280 : 0; body.WriteInt16BE((short)num); }
public override void ServerEncode( ModbusCommand command, ByteArrayWriter body) { var count = command.Count; body.WriteByte((byte)(count * 2)); for (int i = 0; i < count; i++) body.WriteUInt16BE(command.Data[i]); }
public override void ServerEncode(ModbusCommand command, ByteArrayWriter body) { int count = command.Count; body.WriteByte((byte)(count * 2)); for (int index = 0; index < count; ++index) { body.WriteUInt16BE(command.Data[index]); } }
public override void ClientEncode(ModbusCommand command, ByteArrayWriter body) { ModbusCodecBase.PushRequestHeader(command, body); int count = command.Count; body.WriteByte((byte)(count * 2)); for (int index = 0; index < count; ++index) { body.WriteUInt16BE(command.Data[index]); } }
void IProtocolCodec.ServerEncode(CommDataBase data) { var server = (ModbusServer)data.OwnerProtocol; var command = (ModbusCommand)data.UserData; var fncode = command.FunctionCode; //encode the command body, if applies var body = new ByteArrayWriter(); var codec = CommandCodecs[fncode]; if (codec != null) { codec.ServerEncode(command, body); } //calculate length field var length = (command.ExceptionCode == 0) ? 2 + body.Length : 3; //create a writer for the outgoing data var writer = new ByteArrayWriter(); //transaction-id writer.WriteUInt16BE((ushort)command.TransId); //protocol-identifier writer.WriteInt16BE(0); //message length writer.WriteInt16BE((short)length); //unit identifier (address) writer.WriteByte(data.Address); if (command.ExceptionCode == 0) { //function code writer.WriteByte(command.FunctionCode); //body data writer.WriteBytes(body); } else { //function code writer.WriteByte((byte)(command.FunctionCode | 0x80)); //exception code writer.WriteByte(command.ExceptionCode); } data.OutgoingData = writer.ToReader(); }
public override void ClientEncode( ModbusCommand command, ByteArrayWriter body) { body.WriteUInt16BE((ushort)command.Offset); var value = command.Data[0] != 0 ? 0xFF : 0; body.WriteInt16BE((short)value); }
public override void ServerEncode( ModbusCommand command, ByteArrayWriter body) { var count = command.Count; body.WriteByte((byte)(count * 2)); for (int i = 0; i < count; i++) { body.WriteUInt16BE(command.Data[i]); } }
public override void ClientEncode( ModbusCommand command, ByteArrayWriter body) { body.WriteUInt16BE((ushort)command.Offset); var value = command.Data[0] != 0 ? 0xFF00 : 0; body.WriteInt16BE((short)value); }
public override void ServerEncode( ModbusCommand command, ByteArrayWriter body) { body.WriteByte(_device); var count = command.Count; body.WriteByte((byte)(count)); body.WriteByte(0xFF); body.WriteByte(0xFF); body.WriteInt32BE(_address); if (_category == 0) { for (int i = 0; i < count/2; i++) { UInt16 v = (UInt16) GetRandomNumber(0, 25); byte h = (byte)(v >> 8); byte l = (byte)(v &0x00FF); UInt16 t = (UInt16)((l << 8) + h); body.WriteUInt16BE(t); } } else if (_category == 2) { for (int i = 0; i < count / 2; i++) { body.WriteUInt16BE((UInt16)GetRandomNumber(0, 5)); } } else { for (int i = 0; i < count / 2; i++) { body.WriteUInt16BE((UInt16)GetRandomNumber(0, 50)); } } }
public override void ClientEncode( ModbusCommand command, ByteArrayWriter body) { ModbusCodecBase.PushRequestHeader( command, body); var count = command.Count; body.WriteByte((byte)(count * 2)); for (int i = 0; i < count; i++) body.WriteUInt16BE(command.Data[i]); }
public override void ServerEncode( ModbusCommand command, ByteArrayWriter body) { body.WriteByte(_device); var count = command.Count; body.WriteByte((byte)(count)); body.WriteByte(0xFF); body.WriteByte(0xFF); body.WriteInt32BE(_address); if (_category == 0) { for (int i = 0; i < count / 2; i++) { UInt16 v = (UInt16)GetRandomNumber(0, 25); byte h = (byte)(v >> 8); byte l = (byte)(v & 0x00FF); UInt16 t = (UInt16)((l << 8) + h); body.WriteUInt16BE(t); } } else if (_category == 2) { for (int i = 0; i < count / 2; i++) { body.WriteUInt16BE((UInt16)GetRandomNumber(0, 5)); } } else { for (int i = 0; i < count / 2; i++) { body.WriteUInt16BE((UInt16)GetRandomNumber(0, 50)); } } }
//public static readonly ModbusCommandCodec[] CommandCodecs = new ModbusCommandCodec[36]; /// <summary> /// Append the typical header for a request command (master-side) /// </summary> /// <param name="command"></param> /// <param name="body"></param> internal static void PushRequestHeader( ModbusCommand command, ByteArrayWriter body) { body.WriteUInt16BE((ushort)command.Offset); if (command.FunctionCode == 05 || command.FunctionCode == 06) { body.WriteInt16BE((short)command.Data[0]); } else { body.WriteInt16BE((short)command.Count); } }
public override void ClientEncode( ModbusCommand command, ByteArrayWriter body) { ModbusTcpCodec.PushRequestHeader( command, body); var count = command.Count; body.WriteByte((byte)(count * 2)); for (int i = 0; i < count; i++) { body.WriteUInt16BE(command.Data[i]); } }
void IProtocolCodec.ClientEncode(CommDataBase data) { ModbusClient ownerProtocol = (ModbusClient)data.OwnerProtocol; ModbusCommand userData = (ModbusCommand)data.UserData; byte functionCode = userData.FunctionCode; ByteArrayWriter byteArrayWriter1 = new ByteArrayWriter(); ModbusCodecBase.CommandCodecs[(int)functionCode]?.ClientEncode(userData, byteArrayWriter1); int num = 2 + byteArrayWriter1.Length; ByteArrayWriter byteArrayWriter2 = new ByteArrayWriter(); byteArrayWriter2.WriteUInt16BE((ushort)userData.TransId); byteArrayWriter2.WriteInt16BE((short)0); byteArrayWriter2.WriteInt16BE((short)num); byteArrayWriter2.WriteByte(ownerProtocol.Address); byteArrayWriter2.WriteByte(functionCode); byteArrayWriter2.WriteBytes(byteArrayWriter1); data.OutgoingData = byteArrayWriter2.ToReader(); }
void IProtocolCodec.ClientEncode(CommDataBase data) { var client = (ModbusClient)data.OwnerProtocol; var command = (ModbusCommand)data.UserData; var fncode = command.FunctionCode; //encode the command body, if applies var body = new ByteArrayWriter(); var codec = CommandCodecs[fncode]; if (codec != null) { codec.ClientEncode(command, body); } //calculate length field var length = 2 + body.Length; //create a writer for the outgoing data var writer = new ByteArrayWriter(); //transaction-id writer.WriteUInt16BE((ushort)command.TransId); //protocol-identifier (always zero) writer.WriteInt16BE(0); //message length writer.WriteInt16BE((short)length); //unit identifier (address) writer.WriteByte(client.Address); //function code writer.WriteByte(fncode); //body data writer.WriteBytes(body); data.OutgoingData = writer.ToReader(); }
void IProtocolCodec.ClientEncode(CommDataBase data) { var client = (ModbusClient)data.OwnerProtocol; var command = (ModbusCommand)data.UserData; var fncode = command.FunctionCode; //encode the command body, if applies var body = new ByteArrayWriter(); var codec = CommandCodecs[fncode]; if (codec != null) codec.ClientEncode(command, body); //calculate length field var length = 2 + body.Length; //create a writer for the outgoing data var writer = new ByteArrayWriter(); //transaction-id writer.WriteUInt16BE((ushort)command.TransId); //protocol-identifier (always zero) writer.WriteInt16BE(0); //message length writer.WriteInt16BE((short)length); //unit identifier (address) writer.WriteByte(client.Address); //function code writer.WriteByte(fncode); //body data writer.WriteBytes(body); data.OutgoingData = writer.ToReader(); }
void IProtocolCodec.ServerEncode(CommDataBase data) { var server = (ModbusServer)data.OwnerProtocol; var command = (ModbusCommand)data.UserData; var fncode = command.FunctionCode; //encode the command body, if applies var body = new ByteArrayWriter(); var codec = CommandCodecs[fncode]; if (codec != null) codec.ServerEncode(command, body); //calculate length field var length = (command.ExceptionCode == 0) ? 2 + body.Length : 3; //create a writer for the outgoing data var writer = new ByteArrayWriter(); //transaction-id writer.WriteUInt16BE((ushort)command.TransId); //protocol-identifier writer.WriteInt16BE(0); //message length writer.WriteInt16BE((short)length); //unit identifier (address) writer.WriteByte(server.Address); if (command.ExceptionCode == 0) { //function code writer.WriteByte(command.FunctionCode); //body data writer.WriteBytes(body); } else { //function code writer.WriteByte((byte)(command.FunctionCode | 0x80)); //exception code writer.WriteByte(command.ExceptionCode); } data.OutgoingData = writer.ToReader(); }