Hi, I’m a beginner and I need help with this code. I would like to point out that I procured the Fault specifically to be able to test the code. So, according to the table below I should get the second (bit 1) and fourth (bit 3) string of the first byte (byte 0), instead I get the second and fourth string of the second byte (byte 1). Can you help me fix the code?
- platform: modbus_controller
modbus_controller_id: zcs
name: Fault 1
id: fault1
register_type: holding
address: 0x0405
register_count: 10
response_size: 2
raw_encode: HEXBYTES
lambda: |-
std::string z = "";
int idx = item->offset;
//byte[0]
if ((data[idx] & 0x1) != 0) z += "GridOVP,";
if ((data[idx] & 0x2) != 0) z += "GridUVP,";
if ((data[idx] & 0x4) != 0) z += "GridOFP,";
if ((data[idx] & 0x8) != 0) z += "GridUFP,";
if ((data[idx] & 0x10) != 0) z += "PVUVP,";
if ((data[idx] & 0x20) != 0) z += "GridLVRT,";
if ((data[idx] & 0x40) != 0) z += "reserve-ID7,";
if ((data[idx] & 0x80) != 0) z += "reserve-ID8,";
//byte[1]
idx++;
if ((data[idx] & 0x1) != 0) z += "PVOVP,";
if ((data[idx] & 0x2) != 0) z += "GridOVPInstant2,";
if ((data[idx] & 0x4) != 0) z += "PvConfigSetWrong,";
if ((data[idx] & 0x8) != 0) z += "InvOVP,";
if ((data[idx] & 0x10) != 0) z += "PhaseSequenceFault,";
if ((data[idx] & 0x20) != 0) z += "HwBoostOCP,";
if ((data[idx] & 0x40) != 0) z += "HwAcOCP,";
if ((data[idx] & 0x80) != 0) z += "AcRmsOCP,";
//byte[2]
idx++;
## the code continue with other byte and finish with ##
if(z.length() > 0){
z.pop_back();
}
return {z};