wrighar I need to work out what's where in the regiosters
Yeah... not really something that's easiest in bbc basic.
'r' is the entire input message, as bytes. The registers start at offset 42, and each register is 16 bits, which is why it has to combine two adjacent bytes. 42 + 72 is the upper half of register 36, and 42+73 is the lower half.
r&(28) is from the message preamble. I think it's the inverter serial number.
From the python library:
The packing format is fairly regular, though some fields appear in only
some messages. After the modbus framing comes:
uint8[10] data_adapter_serial_number : the comms dongle itself
uint64 padding
uint8 slave_addr: unit identifier
uint8 tfc: transparent function code - top bit is error flag
uint8[10] inverter serial number (all responses)
uint16 base: base register number (all except NullResponse)
uint16 count: number of registers (all except WriteHoldingRegister messages, and NullResponse)
uint16[] values: (all responses, and WriteHoldingRegister request, unless error bit is set)
uint16 crc: crc
Encoding is big-endian, except the crc which seems to be little-endian ?
(This is after 8 bytes of modbus framing, which is consistent with the values field having offset 42.)