Modbus start address reading


joza921

Recommended Posts

Hello , 

I have problem with reading registars on modbus tcp. 

Problem is :

I use beckhoff plc and start address is 32768 and when i want to read one registar i receive error ( P-ModbusTCP 0002: Illegal Data Address: citanje Line 5 - Uncaught error in sequence)

what I noticed in command/Alert program didnt accept start address.

Here is code and command/Alert:

 

command.jpg.2737ce04b0c17898d895c5c2cf0c2f8e.jpgcode.jpg.5af8650744000cebf0f571eebe8ea8c1.jpg

Anyone has same problem??

 


 

Link to comment
Share on other sites

The problem is that there are two different ways of notating Modbus:

1) using 40,001 notation, where holding registers go from 40001-49999, input registers from 30001-39999, etc.  The problem with this notation is that it isn't real.  It is just documentation.  When you ask for 40001, what is actually sent over the serial / ethernet connection is 0.  The 10,000 place is stripped and then the subtract 1.  This is the original Modbus spec and it was done because at the time they thought electricians couldn't count from 0 like programmers.  Personally I find electricians to be very smart and more than capable of counting from 0, but then they didn't ask me.

2) using 0 notation, where all registers start at 0 and there is no translation.  In this case, when you ask for holding register 0, what is actually sent is 0.  And when you ask for 40001, what is actually sent is 40001.

Unfortunately, some manufacturers don't understand this and their documentation is messed up.  It takes some experimentation and testing to figure it out.  

DAQFactory attempts to automatically handle this for you.  It does this by assuming that when you request a register between 30001 and 49999 that you are using the first, 40,001 based notation.  Until that point it assumes you are using the second, zero based notation.  Where it runs into trouble is what you are seeing, where you want registers in the 30,001-49,999 range but its not in 40,001 notation.  You can see it: 0x0ACF = 2767, which is 32768 with the 3 stripped and subtract 1.

To keep DAQFactory from using this mode, simply do a single read of a register > 50000.  You can do this in an auto-start sequence.  You only have to do it once.  Add  a try / catch so it doesn't error out:

try
   device.plc_1.readholdingU16(0,50001,1)
catch()
endcatch

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.