buildReadRequest static method
Build an FC03 Read Holding Registers request (8 bytes).
Implementation
static Uint8List buildReadRequest({
required int slaveAddress,
required int startRegister,
required int registerCount,
}) {
final frame = Uint8List(8);
frame[0] = slaveAddress & 0xFF;
frame[1] = 0x03; // FC: Read Holding Registers
frame[2] = (startRegister >> 8) & 0xFF;
frame[3] = startRegister & 0xFF;
frame[4] = (registerCount >> 8) & 0xFF;
frame[5] = registerCount & 0xFF;
final crc = calculateCrc16(frame, 6);
frame[6] = crc & 0xFF; // CRC lo byte
frame[7] = (crc >> 8) & 0xFF; // CRC hi byte
return frame;
}