internal static void CopyTo(this IModbusCoilsTable table, IMessageBufferWriter bufferWriter, int offset, int count) { var n = Math.DivRem(count, 8, out var res); if (res > 0) { n++; } bufferWriter.Push((byte)n); for (var i = 0; i < n; i++) { byte currentByte = 0; for (var j = 0; j < 8 && count > 0; j++) { var index = i * 8 + j + offset; if (index < table.Length && table[index]) { currentByte |= (byte)(0x1 << j); } count--; } bufferWriter.Push(currentByte); } }
public override void WriteResponse(ModbusDevice device, IMessageBufferWriter writer) { writer.Push((byte)((device.Address >> 0) & 0xFF)); writer.Push((byte)ModbusFunctionCode.ReadCoils); device.MemoryMap.OutputCoils.CopyTo(writer, Offset, Count); }
internal static void CopyTo(this bool[] table, IMessageBufferWriter bufferWriter) { var n = Math.DivRem(table.Length, 8, out var res); if (res > 0) { n++; } bufferWriter.Push((byte)n); for (var i = 0; i < n; i++) { byte currentByte = 0; for (var j = 0; j < 8; j++) { var index = i * 8 + j; if (index < table.Length && table[index]) { currentByte |= (byte)(0x1 << j); } } bufferWriter.Push(currentByte); } }
public override void WriteResponse(ModbusDevice device, IMessageBufferWriter writer) { writer.Push((byte)((device.Address >> 0) & 0xFF)); writer.Push((byte)FunctionCode); writer.Push((byte)((Offset >> 8) & 0xFF)); writer.Push((byte)((Offset >> 0) & 0xFF)); writer.Push((byte)((Count >> 8) & 0xFF)); writer.Push((byte)((Count >> 0) & 0xFF)); }
public override void WriteResponse(ModbusDevice device, IMessageBufferWriter writer) { writer.Push((byte)((device.Address >> 0) & 0xFF)); writer.Push((byte)ModbusFunctionCode.WriteSingleRegister); writer.Push((byte)((Offset >> 8) & 0xFF)); writer.Push((byte)((Offset >> 0) & 0xFF)); writer.Push((byte)((device.MemoryMap.OutputRegisters[Offset] >> 8) & 0xFF)); writer.Push((byte)((device.MemoryMap.OutputRegisters[Offset] >> 0) & 0xFF)); }
internal static void CopyTo(this IModbusRegistersTable table, IMessageBufferWriter bufferWriter, int offset, int count) { bufferWriter.Push((byte)(count * 2)); for (var i = 0; i < count; i++) { bufferWriter.Push((byte)((table[i + offset] >> 8) & 0xFF)); bufferWriter.Push((byte)(table[i + offset] & 0xFF)); } }
internal static void CopyTo(this int[] table, IMessageBufferWriter bufferWriter) { bufferWriter.Push((byte)(table.Length * 2)); for (var i = 0; i < table.Length; i++) { bufferWriter.Push((byte)((table[i] >> 8) & 0xFF)); bufferWriter.Push((byte)(table[i] & 0xFF)); } }
public abstract void WriteResponse(ModbusDevice device, IMessageBufferWriter writer);