Modbus Questions for iOS Development

Started by crunnells, August 04, 2013, 09:18:36 PM

Previous topic - Next topic

crunnells

Hey Midnite guys,

I wasn't sure what forum to post in, but I'm working on an iPhone/iPad/iOS app that does what the LocalApp does, but it'll allow me to check my system when I'm away from my computer. I'm trying to wrap my brain around Objective-C and the Modbus spec at the same time. Fortunately, there's an Objective-C wrapper for libmodbus, which is what I'm using now.

Anyway, I've been looking at the registers documentation in the classicManual.pdf and I'm just trying to figure out why some registers are reading 0 when based on the documentation there should be something there. For example, registers 4104 and 4105 should have the UNIT_SerialNumber stored there, but I'm getting a 0 for both registers. Same goes for 4109 and 4110, which should be UNIT_IP_Address, but is also reading 0.

Also, how do you find all Classics on a local network? The first method that came to mind was a scan of the subnet looking for modbus connections on port 502, then reading register 4101 to see if the LSB is a Classic model number or not. Is there a better method that you use in the LocalStatusApp?

Thanks!

RossW

Quote from: crunnells on August 04, 2013, 09:18:36 PM
Anyway, I've been looking at the registers documentation in the classicManual.pdf and I'm just trying to figure out why some registers are reading 0 when based on the documentation there should be something there. For example, registers 4104 and 4105 should have the UNIT_SerialNumber stored there, but I'm getting a 0 for both registers. Same goes for 4109 and 4110, which should be UNIT_IP_Address, but is also reading 0.

Also, how do you find all Classics on a local network? The first method that came to mind was a scan of the subnet looking for modbus connections on port 502, then reading register 4101 to see if the LSB is a Classic model number or not. Is there a better method that you use in the LocalStatusApp?

First thing, check and double check - the terms "address" and "register" are used almost interchangably, but they are DIFFERENT. The "Address" is (register+1).  That is, what's sent over the wire to access a register is one less than the address you ask for. 

Second, I don't believe the device serial number is where you are looking for it. From my own code:

        serialno=modbus_register(28673)<<16 | modbus_register(28674);   // read device serial number
        if(debug) printf("Read serial number %d from device\n",serialno);

As to how you can discover a classic, it broadcasts periodically.

   # tcpdump -nl udp and port 4626

It doesn't have any useful payload that I can see (6 bytes, but unclear what it contains).
Just watch for broadcasts to 255.255.255.255 on port 4626 UDP on the local segment, then try to query the source on port 502.

RossW
3600W on 6 tracking arrays.
7200W on 2 fixed array.
Midnite Classic 150
Outback Flexmax FM80
16 x LiFePO4 600AH cells
16 x LiFePO4 300AH cells
Selectronics SP-PRO 481 5kW inverter
Fronius 6kW AC coupled inverter
Home-brew 4-cyl propane powered 14kVa genset
2kW wind turbine

crunnells

Hey RossW,

I might need to check for an updated document if you have them listed in 28673 and 28674. The version of the Classic manual I have might be from ~2010-2011 (I couldn't find an obvious revision date), and it definitely has them listed 4104 and 4105.

Thanks for the info on the broadcast! That's a lot more efficient than my idea.

crunnells

Just checked the documents section and found an updated modbus spec, which now shows those addresses I mentioned as RESERVED, so that's one mystery solved! Back to wrapping my brain around objective-c.