public override byte[] ConvertToTcp(byte unitId, ushort transactionId, ushort protocolId = 0) { List <byte> frames = new List <byte>(); frames.Add(FunctionCode); frames.Add((byte)((StartingAddress >> 8) & 0x00FF)); frames.Add((byte)(StartingAddress & 0x00FF)); frames.Add((byte)((QuantityOfRegisters >> 8) & 0x00FF)); frames.Add((byte)(QuantityOfRegisters & 0x00FF)); frames.Add(ByteCount); for (int i = 0; i < Data.Length; i++) { frames.Add((byte)((Data[i] >> 8) & 0x00FF)); frames.Add((byte)(Data[i] & 0x00FF)); } MbapHeader header = new MbapHeader() { UnitId = unitId, TransactionId = transactionId, ProtocolId = protocolId, Length = (ushort)(frames.Count + 1) }; byte[] headerBytes = header.Encode(); byte[] message = new byte[headerBytes.Length + frames.Count]; Buffer.BlockCopy(headerBytes, 0, message, 0, headerBytes.Length); Buffer.BlockCopy(frames.ToArray(), 0, message, headerBytes.Length, frames.Count); return(message); }
public override byte[] ConvertToTcp(byte unitId, ushort transactionId, ushort protocolId = 0) { List <byte> frames = new List <byte>(); frames.Add(FunctionCode); frames.Add((byte)((StartingAddress >> 8) & 0x00FF)); frames.Add((byte)(StartingAddress & 0x00FF)); frames.Add((byte)((QuantityOfCoils >> 8) & 0x00FF)); frames.Add((byte)(QuantityOfCoils & 0x00FF)); frames.Add(ByteCount); byte[] data = new byte[ByteCount]; Data.CopyTo(data, 0); foreach (var item in data) { frames.Add(item); } MbapHeader header = new MbapHeader() { UnitId = unitId, TransactionId = transactionId, ProtocolId = protocolId, Length = (ushort)(frames.Count + 1) }; byte[] headerBytes = header.Encode(); byte[] message = new byte[headerBytes.Length + frames.Count]; Buffer.BlockCopy(headerBytes, 0, message, 0, headerBytes.Length); Buffer.BlockCopy(frames.ToArray(), 0, message, headerBytes.Length, frames.Count); return(message); }
public override byte[] ConvertToTcp(byte unitId, ushort transactionId, ushort protocolId = 0) { List <byte> list = new List <byte>(); list.Add(FunctionCode); list.Add(ByteCount); byte[] data = new byte[ByteCount]; Data.CopyTo(data, 0); foreach (var item in data) { list.Add(item); } //foreach(var item in BitBlock) //{ // list.Add(item); //} MbapHeader header = new MbapHeader() { UnitId = unitId, TransactionId = transactionId, ProtocolId = protocolId, Length = (ushort)(list.Count + 1) }; byte[] headerBytes = header.Encode(); byte[] message = new byte[headerBytes.Length + list.Count]; Buffer.BlockCopy(headerBytes, 0, message, 0, headerBytes.Length); Buffer.BlockCopy(list.ToArray(), 0, message, headerBytes.Length, list.Count); return(message); }
public override byte[] ConvertToTcp(byte unitId, ushort transactionId, ushort protocolId = 0) { int index = 0; byte[] frames = new byte[2]; frames[index++] = (byte)((1 << 7) | FunctionCode); frames[index++] = (byte)Convert.ToByte(ErrorCode); MbapHeader header = new MbapHeader() { UnitId = unitId, TransactionId = transactionId, ProtocolId = protocolId, Length = (ushort)(frames.Length + 1) }; byte[] headerBytes = header.Encode(); byte[] message = new byte[headerBytes.Length + frames.Length]; Buffer.BlockCopy(headerBytes, 0, message, 0, headerBytes.Length); Buffer.BlockCopy(frames, 0, message, headerBytes.Length, frames.Length); return(message); }
public override byte[] ConvertToTcp(byte unitId, ushort transactionId, ushort protocolId = 0) { int index = 0; byte[] frames = new byte[5]; frames[index++] = FunctionCode; frames[index++] = (byte)((StartingAddress >> 8) & 0x00FF); //MSB frames[index++] = (byte)(StartingAddress & 0x00FF); //LSB frames[index++] = (byte)((QuantityOfRegisters >> 8) & 0x00FF); //MSB frames[index++] = (byte)(QuantityOfRegisters & 0x00FF); //LSB MbapHeader header = new MbapHeader() { UnitId = unitId, TransactionId = transactionId, ProtocolId = protocolId, Length = (ushort)(frames.Length + 1) }; byte[] headerBytes = header.Encode(); byte[] message = new byte[headerBytes.Length + frames.Length]; Buffer.BlockCopy(headerBytes, 0, message, 0, headerBytes.Length); Buffer.BlockCopy(frames, 0, message, headerBytes.Length, frames.Length); return(message); }
public override byte[] ConvertToTcp(byte unitId, ushort transactionId, ushort protocolId = 0) { List <byte> list = new List <byte>(); list.Add(FunctionCode); list.Add(ByteCount); foreach (var item in RegisterValues) { list.Add((byte)((item >> 8) & 0x00FF)); list.Add((byte)(item & 0x00FF)); } MbapHeader header = new MbapHeader() { UnitId = unitId, TransactionId = transactionId, ProtocolId = protocolId, Length = (ushort)(list.Count + 1) }; byte[] headerBytes = header.Encode(); byte[] message = new byte[headerBytes.Length + list.Count]; Buffer.BlockCopy(headerBytes, 0, message, 0, headerBytes.Length); Buffer.BlockCopy(list.ToArray(), 0, message, headerBytes.Length, list.Count); return(message); }