I found this....
"Select Listening in Modbus TCP Enabled to enable Modbus communication"
In the Combox manual. Not sure where that is located though.
What register are you trying to read? 40278 would be a register at decimal 278 or &H116 hex. &H116 is the seconds that the grid has been active in the XW.
I read the watts of the Grid AC1 input at &H66 and the output watts at &H9A
In Decimal those would be 102 or 40102 with the register type. But it is also a 32 bit value, so you need to read 2 words and join them. Same 32 bit read for Output Watts at decimal 154 or 40154.
Here is the structure I use in the PLC to read the output watts
' Read output watts
DM[9] = &H9A
READMB2 4,10,DM[9],DM[10],2
O = DM[11]
SETHIGH16 O,DM[10]
DM[15] = O
DM[9] register is set to the location I want to read, in this case HEX 9A
The READMB2 line is using virtual com 4 which was setup as Modbus TCP to the gateway ip address.
10 is the device id of the first XW inverter, I only have one.
DM[9] is telling it which register to read
DM[10] is where it will store the response of the first word
2 on the end is read 2 16 bit registers, the second one goes into DM[11]
"O" is the variable where I store the resulting 32 bit watts reading.
DM[11] holds the low 16 bits so they get copied first. The "SETHIGH" appends the upper 16 bits from DM[10] which has the high 16 bits.
I also copy "O" to DM[15] for use in other calculations.
I am sure this could be done a little cleaner, but it made it easy to just pick any register and have the same lines able to pull any 32 bit value, so I have copied this section many times.
Reading the watts from the main panel PZEM meters is a bit different on serial Modbus
Here is the L1 power reading
READMB2 11,4,0,DM[41],10
If STATUS(2) = 1 THEN
DM[39] = 1
N = DM[44]
SETHIGH16 N,DM[45]
ELSE
DM[39] = 0
ENDIF
READMB2 this time is reading from COM 11. That is actually COM1 physical port on the Nano-10 but if I use COM 1 it uses Modbus ASCII and we want Modbus RTU, so they signal that by adding 10 to the com number. 4 is device id again, that is the L1 PZEM power meter.
0 means starting from the first register. Store the data starting at DM[41] and take 10 registers.
Watts is again 32 bits like the XW, but, not signed, and multiplied by 10 so 200 watts is 2000 here. DM[44] has the low 16 bits, and then SETHIG from DM[45] with the high 16 bits.
The "If STATUS(2)" check returns a 1 for a read success. If a bad read, set the read status to zero at DM[39]. Before the read I set that to 41 for debugging, and it is set to one if the read is good.
So now "O" has the watts going out of the XW and "N" has the watts being used from L1 in the main panel.
It's a little cryptic, but once you got working in it, it starts making some sense. I know I can clean up my code a lot, and I need to add more comments, even for myself, let alone someone else trying to read through it.
First thing you should do is just make it monitor the values and make sure you are getting the correct data. It is very easy to read the wrong register, get bytes or words flipped, or treat a signed variable as unsigned etc.