LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Reading Modbus Holding Register

Solved!
Go to solution

I need to read the value of 12  Holding registers that are received by Modbus protocol. Verified to be valid data using the Modscan32 tool. 

 

Refer the VI attached ( LV2017) . I am able to read but the values are not right … I am not sure what value should I input in the Address . My valid address  are 40001 to 40012. Am I making a mistake some where ? 

ReadET200_Modbus.png

Raghunathan
LabVIEW to Automate Hydraulic Test rigs.
0 Kudos
Message 1 of 8
(6,138 Views)

What is not right about the values?  What do you get and what do you expect?

 

For 40001 to 40012, then a start address of 0 and a quantity of 12 is correct. (Basically drop the 4, and subtract 1).

You could try a start address of 1, but that isn't common.  LabVIEW and the base commnunication protocol starts at 0 even though the human readable listing of registers in manuals starts at 40001 for holding registers, 30001 for input registers,   and other prefixes x0001 for the other various types of registers.

 

 

0 Kudos
Message 2 of 8
(6,106 Views)

@RavensFan wrote:

What is not right about the values?  What do you get and what do you expect?

 

For 40001 to 40012, then a start address of 0 and a quantity of 12 is correct. (Basically drop the 4, and subtract 1).

You could try a start address of 1, but that isn't common.  LabVIEW and the base commnunication protocol starts at 0 even though the human readable listing of registers in manuals starts at 40001 for holding registers, 30001 for input registers,   and other prefixes x0001 for the other various types of registers.

 


First Image : LV2017 code readout; Second image : Modscan32 readout ( Integer mode) . Note : The first register 40001 is a Digital Input - 8Bits ; Rest are all Analog Inputs of 4-20mA mapped to 0-27500. My interest is in the first 12 register and the last one has a temp probe connected to show the setup is working.

 

LV2017_ReadValues.JPG

Modscan32_ReadValues.JPG

Raghunathan
LabVIEW to Automate Hydraulic Test rigs.
0 Kudos
Message 3 of 8
(6,061 Views)

I don't see anything wrong in the code itself aside the possible lack of error handling

Numbering is correct - the offset comes from the Modbus data model vs. addressing model offset, explained in this document: http://www.modbus.org/docs/Modbus_Application_Protocol_V1_1b.pdf

 

Are you sure you're not getting an exception from the communication?

Do you have automatic error handling turned on, or are you handling errors in some other way?

Maybe the serial port settings are incorrect and you get CRC error?

 

I dislike that driver, because the diagram is password protected, and I myself usually would like to have a better control over the functionality.

 

There are drivers that let you see the diagram, you might want to check for example the plasmionique version in tools network (here: http://sine.ni.com/nips/cds/view/p/lang/fi/nid/214230).

It has also an example that let's you easily check the communication. Maybe it will be more informative and point you to correct direction?

 

Good luck.

 

 

Message 4 of 8
(6,041 Views)
Solution
Accepted by topic author MogaRaghu

What is the display format of your array?  It looks like it is binary and you are seeing 1 followed by 15 0-bits. 

 

Guess what, 1000 0000 0000 0000 as a string of binary bits is exactly equal to -32768 when those 16 bits are interpreted as a I16  (signed 16-bit) integer!

 

Your 0th element of that array is 0100 0000 0000 0000 (it has one less zero), which is 16384 when interpreted as an I16 integer.

 

 

So, what do you think is wrong?  You might need to typecast the U16 array to an I16 array.  Otherwise, set your numeric format in that array indicator to be I16 rather than binary.

 

 

Message 5 of 8
(6,025 Views)

Thanks.  That was a good point on the data type.

 

So afterall the Modbus toolkit is not bad Smiley Wink

Raghunathan
LabVIEW to Automate Hydraulic Test rigs.
0 Kudos
Message 6 of 8
(6,000 Views)

Though my issue is resolved, I just thought I will also check out the Plasmionique toolkit. But on the Download page it says Download Evaluation.  Is it a paid version … visited the site but could not locate any pricing. 

 

Thanks for the link !!

Raghunathan
LabVIEW to Automate Hydraulic Test rigs.
0 Kudos
Message 7 of 8
(5,991 Views)

Plasmionique Modbus Master is FOSS, BSD License.

You can download it directly through VI Package manager or here: https://lavag.org/files/file/286-plasmionique-modbus-master/

 

If you want to report an issue or make modifications to it, you can find the development project on github: https://github.com/rfporter/Modbus-Master

0 Kudos
Message 8 of 8
(5,941 Views)