A Forum run by Enthusiasts of MidNite Solar

General Category => General Discussion => Topic started by: crunnells on August 04, 2013, 09:18:36 PM

Title: Modbus Questions for iOS Development
Post by: crunnells on August 04, 2013, 09:18:36 PM
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!
Title: Re: Modbus Questions for iOS Development
Post by: RossW on August 04, 2013, 10:28:00 PM
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
Title: Re: Modbus Questions for iOS Development
Post by: crunnells on August 04, 2013, 11:06:27 PM
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.
Title: Re: Modbus Questions for iOS Development
Post by: crunnells on August 04, 2013, 11:11:18 PM
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.