Modbus Mapping Issue


BKnight

Recommended Posts

I need some help understanding this issue.

I was working with a customer connecting to our modbbus slave via TCP remotely. He was able to connect but the value he was reading "contactor state" value was incorrect.

He ended up figuring it out. He doesn't speak English, so I can't ask him directly.

His email says " Contactor State 400029 as the address of the register, not the position in the register itself. I was sending a packet  03 001C 0001 instead of 03 0000 0032- position 56.

  I never worked on the Master side of setting up framework, so go easy on me. Any input would be appreciated.

 

 

Link to comment
Share on other sites

I'm not quite sure, but I have a few guesses.  400029 should be the 29th holding register (packet address 28 or 0x1C).  It should be a 16 bit value (though it could be combined with 400030 to make a 32 bit value).  Contactor state is probably a discrete 0 or 1.  Depending on the manufacturer's (i.e. your) implementation, you may have put Contactor state as a single register holding just 0 or 1 (and thus "wasting" 15 bits), or you may have packed the Contactor state into register 400029 along with 15 other discretes.  Technical the discretes should probably be setup as coils or input states, but I understand why some manufacturers use holding registers for everything as some Modbus master's can only read Holding registers.  The problem is that Modbus master software won't automatically break apart a holding register into its bits, which it would do with a coil or input state, so that has to be done manually.  This is done in DAQFactory usually with the TestBit() function, but there are other more efficient ways depending on the end goals.

 

Now as to the two packets you specified:

 

03 001C 0001 will return 400029 and just 400029 as a 16 bit value

03 0000 0032 will return 400001 through 400032 as an array of 32, 16 bit values.  You'd then have to take the 29th element from that array to get 400029.

 

Note also that the only difference between 400029 and 40029 (which you'd see more often) is an extra 0.  The 4 tells us its a holding register.  The rest is the register address + 1.  They did +1 because for some reason they thought electricians (who were the ones that first installed PLCs) couldn't count from 0 like programmers.  Personally I find electricians to be really smart and could count from any value you wanted, including the square root of -1.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.