public ModbusMemoryMap(IModbusCoilsTable inputCoils, IModbusCoilsTable outputCoils, IModbusRegistersTable inputRegisters, IModbusRegistersTable outputRegisters) { InputCoils = inputCoils ?? throw new ArgumentNullException(nameof(inputCoils)); OutputCoils = outputCoils ?? throw new ArgumentNullException(nameof(outputCoils)); InputRegisters = inputRegisters ?? throw new ArgumentNullException(nameof(inputRegisters)); OutputRegisters = outputRegisters ?? throw new ArgumentNullException(nameof(outputRegisters)); }
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); } }
internal static void CopyFrom(this IModbusCoilsTable table, MessageBufferSpan messageBufferSpan, int offset, int count) { var n = Math.DivRem(count, 8, out var res); if (res > 0) { n++; } for (var i = 0; i < n; i++) { byte currentByte = messageBufferSpan[i]; 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)) > 0); } count--; } } }
public ModbusMemoryMap(IModbusCoilsTable coils, IModbusRegistersTable registers) { InputCoils = OutputCoils = coils ?? throw new ArgumentNullException(nameof(coils)); InputRegisters = OutputRegisters = registers ?? throw new ArgumentNullException(nameof(registers)); }