LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Modbus TCP/IP Help

Solved!
Go to solution

Hello Labviewers,

 

So I just hooked up a couple of Honeywell UDA2182 controllers to my computer using an ethernet connection.  I've established communications using modbus (specifically the Datalogging and Supervisory Control module's Modbus I/O server option) and I can tell that readings are coming through to the computer.  

 

My problem is that it's all in some weird alien langauge.  I can't tell which parameters I'm viewing data for, and the data that my computer is recieving are crazy huge numbers that don't relate to anything.  My guess is that I'm supposed to somehow convert these numbers but I'm not sure how to go about it.

 

Thanks for any and all help/advice,

Mike

0 Kudos
Message 1 of 29
(7,698 Views)

What is an example of a "crazy huge number"?  What do you expect the number to be?  It might be a matter of typecasting.  It might be a matter of combining two registers together to get a 32bit number.  It might be a matter of reversing the order of the bytes (most significant byte vs. least significant byte) in a register, or the pairs of registers (most significant word vs. least significant word) before doing the conversions.  These things are know as "endianism".  Big-endian vs. little-endian.

 

Without any real examples of what you are getting vs. what you expecting, it is kind of hard to help.  What does the manual for the controller say?

 

 

Message 2 of 29
(7,693 Views)

Heckler511 wrote: I can't tell which parameters I'm viewing data for

 

Do you have any guidance on what coils/registers to read? There are literally hundreds of thousands of modbus addresses you can read...so I assume you have a programmers manual or other resource to say '0x10001 is on or off, 0x30001 is to read temperature value, 0x30002 is for flow' etc. You can't just read random addresses and hope to know what they mean, especially when there are unknown units(ie. is temp in C, K, R, F?).

 

And Ravens Fan is right about the 32 bit values...several PLCs I have 32 bit numbers to transmit, since modbus only has 16 bit word values, I have to combine two input registers into a 32 bit number, and you need to know the significant word. I've never had to convert big endian and little endian on PLCs though, although I wouldnt be surprised if there were some devices out there that needed it.
Rob K
Measurements Mechanical Engineer (C-Series, USB X-Series)
National Instruments
CompactRIO Developers Guide
CompactRIO Out of the Box Video
Message 3 of 29
(7,666 Views)

agree to the above. Maybe you need to combine two registers. Also on first look - the numbers shouldnt be larger than 65535.

 

If youre not familiar with modbus or any of the above: If youd expect a number like "12.61" thats not possible to transfer though modbus (since its integers) and need to rescale that large number you read down to 12.61, but then you need to know the scaling information the controller uses on its side. To rescale its a simple divide/multiply operation and add an offset to the value. You need to know the real value at 0 and the real value at 65535 (or any lower one) (simply said a bottom value and a top value). Do you have any documentation of the controller that mentions modbus and parameter scale information?

Smiley Surprised 

Message 4 of 29
(7,643 Views)

Robbob wrote:

Heckler511 wrote: I can't tell which parameters I'm viewing data for

 

Do you have any guidance on what coils/registers to read? ...


Those are the key questions you have to answer. I have seen all different flavors of storage and representation. I even saw one PLC system that worked  exclusively in BCD, ... for what good reason.... I never did figure out.

 

Ben

Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
Message 5 of 29
(7,635 Views)

Hi Everyone!

 

Thanks so much for the help thus far.  When I first hooked up the PLC I was indeed hoping for and expecting simple, easy to understand human readable numbers like 7.07 or 13.72.  After reading through everyone's replies this morning, I have spent the better part of the day reading up on Modbus and going back through the manual that came with the PLC.  Things are starting to make sense a little more but I still need any help you might offer.

 

I've figured out that I want to read registers (decimal addresses) 30001, 30003, 30005, and 30007.  I should be able to communicate with these registers via Modbus function code 04, although, it is unclear as to whether I need to specify this function code seeing as how I'm using a Modbus I/O server in continuous operation (rather than sending one request and receiving one response at a time).  These 4 registers are all classifies as type = float and I see in my manual that is says "floating point values require two consecutive registers".  I am now assuming that to accurately read the data associated with register 30001, I will need to read and convert data from 30001 and 30002.

 

Further, it appears to me that Labview wishes to represent these register addresses with an extra 0, making 30001 -> 300001?  Earlier this morning, using the DSC module's Modbus I/O server I was able to monitor register 300001 in the Distributed System Manager.  The values reported to me were as follows (can choose any representation): 16,609(decimal); 1.6609000e+04(scientific); 40E1(hex); 40340(octal); and 100000011100001(binary).  I was expecting a value of 7.07 (pH units) but as this is only the single register 300001 perhaps these values are only half of the human readable answer.  

 

According to my controller's manual the default setting for communications is Word Swap = yes, or Big Endian, byte order 4,3,2,1.  However, this can be changed on the controller should I need to set this parameter to Little Endian.  There is also a section in the manual regarding IEEE 32-bit floating point stuff where a formula is given for calculating the floating point number from a 23 bit signed binary with 8 bit biased binary exponent.  I will admit that this formula makes no sense but I'm willing to give it a shot if needs be.  The crazy terminology here (mantissa, Endian, etc.) has really been difficult to assimilate.  

 

My goal now is to try and read registers 300001 and 300002 and somehow combine the two values to produce a final human readable number?  Does it seem like I'm on the right track?  Does anyone have any advice as to how to combine these two register values?  Thanks again.  I'll report back soon.

 

-Mike

0 Kudos
Message 6 of 29
(7,594 Views)

Mike,

 

LabVIEW does indeed represent the addresses with an extra zero in the middle. The exact reason escapes me, I will look through some of my old notes to find out why, I have just accepted the fact and coded with it successfully with the addresses being different.

 

If you are using modbus IO servers, you should never have to deal with function codes. LabVIEW takes care of this behind the scenes for you.

 

You do have to read 30001 and 30002. a floating point(single in labview) is 32 bits, and you have a single 16 bit, so you are missing half your information! It is probably easiest to do this in binary, but LabVIEW makes that part easy for you. Can you post your 30001 value, your 30002 value, and any settings you are aware of? I'd like to take a whack at this.

 

And definitely look at wikipedia's article on floating point, it will help your understanding!

Rob K
Measurements Mechanical Engineer (C-Series, USB X-Series)
National Instruments
CompactRIO Developers Guide
CompactRIO Out of the Box Video
Message 7 of 29
(7,589 Views)

Hi Rob,

 

Thanks again for the reply.  As I said before, the Modbus I/O server allows me to see register values in different formats.  Just a minute ago I scribbled down the hexadecimal representation as it was the easiest to quickly jot down.  I did this for two register couplets, 300001(2) and 300005(6).  The codes I got were 300001 = 40E4, 300002 = 8694, 300005 = 415D, and 300006 = 56A4.  Combining these gives me final hexadecimal values of 40E48694 and 415D56A4 which translate into values of pH = 7.14 and temperature = 13.83 C.  There's a calculator available here to help with the translation: http://babbage.cs.qc.edu/IEEE-754/32bit.html.  These were the values I was expecting so I'm happy so far!  My guess is that you would be able to get the same values by doing the binary translation if you so preferred.    

 

So now the question becomes, what is the best way to translate these values behind the scenes using LabVIEW?  I would like to create, use, and log shared variables that represent human readable forms of pH and temp, etc.  I'll be using the DSC module to log the data in a Citadel database and it seems to me like I should do the translation before the data are logged.  Eventually we'll have on the order of 30 PLCs being monitored simultaneously.  Also, it was my hope that I could have the Modbus I/O server process running in the background and continuously logging data and making data values available for use in coding.  Will I have to build another server to do the translation?  Should I build a .VI that somehow manipulates the raw code data and translates it for me?  

 

Thanks again for the help!

-Mike

0 Kudos
Message 8 of 29
(7,578 Views)

The period in the sentence with that url messed it up.  Calculator is available here:

 

http://babbage.cs.qc.edu/IEEE-754/32bit.html

0 Kudos
Message 9 of 29
(7,577 Views)

This reads an array of registers (such as 2 consecutive registers) and converts them to a single floating point (also in an array.)

 

If you read 8 registers (such as 30,001 to 30,008 which would be 8 registers starting at 0 in the modbus library) you will get an array of 4 values, each one representing a pair of registers.  You can index out of the array to get the individual values.

 

 

This is a snippet so you can drag and drop into a blank VI.  If you have an older version of LabVIEW, the functions in order are decimate array, join numbers, and typecast.

 

 

Message Edited by Ravens Fan on 01-19-2010 08:04 PM
Message 10 of 29
(7,568 Views)