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 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)); } } }