From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Modbus Unit32 starting address

Hello,

 

I'm working with a communications gateway that has Modbus capability. I used the Modbus libraries to communicate with this device; however, I have a problem with some of the starting addresses. For my communications gateway, several starting addresses are Unit32, and the Modbus library is designed for starting addresses of Unit16. I tried manually changing the input from U16 to U32, but there was no response. The communications gateway does respond when the starting address is at U16, but the output register is not accurate.

 

Thanks in advance,

 

Jose

0 Kudos
Message 1 of 12
(3,496 Views)

Hey Jose,

The LabVIEW Modbus library is designed to use the standard U16 starting address so I don't think you will want to change that.  You can find more information about the LabVIEW library here: http://zone.ni.com/devzone/cda/tut/p/id/4722.  A good reference on addressing using the Modbus protocol can be found here:http://www.modbustools.com/PI_MBUS_300.pdf.  Can you provide more details on your communications gateway and the issues you are seeing with the output register?

Kevin Fort
Principal Software Engineer
NI
0 Kudos
Message 2 of 12
(3,480 Views)

Ok,

 

I tried by changing the "Quantity" value to 2, thus having two Unit16's. However, now I'm getting Time Out error 6101. I know that I'm using the right commands, because I'm trying to do an example from the communications gateway manual (Section 4.1.1 from attachment). The image I uploaded before demonstrates how I'm entering the starting address, quantity, slave address, etc. 

 

Jose

0 Kudos
Message 3 of 12
(3,470 Views)

Hey Jose,

There are a lot of forum posts on the 6601 error that I would take a look at first. I will link a couple of the ones that seem most relevant for cyour application:http://forums.ni.com/t5/LabVIEW/Modbus-error-6101/m-p/489672?requireLogin=False  

http://forums.ni.com/t5/LabVIEW/Timeout-errors-with-Modbus-serial-master-query/td-p/485918/page/2

http://forums.ni.com/t5/LabVIEW/Timeout-error-code-6101-for-acquisition-from-MODBUS-instrument/td-p/...

 

Are you getting the time out error on every command you try to use with the device or is it only certain commands or when you use multiple commands?

Kevin Fort
Principal Software Engineer
NI
0 Kudos
Message 4 of 12
(3,458 Views)

Alright, 

 

I rebuilt the VI and now is working better. However, there is something that I'm not understanding. In the MB Serial Master Query, when I enter the command to get time (8010h) in the starting address, the register equals 4096 which is the buffer size. I should get a Unit32 decimal number that represents the time according to the manual. Is it that the MB Serial Master Query vi only reads the buffer size of a starting address and no the value of that address?

 

Thanks,

 

Jose

0 Kudos
Message 5 of 12
(3,447 Views)

Hey Jose,

You should be able to use that command to get the data you are looking for.  This tutorial provides an example of doing this towards the bottom:http://zone.ni.com/devzone/cda/tut/p/id/7675.  It would help debug the issue you are seeing if we could get a screenshot of the VI with the commands you are using.  Please post back if you have any additional questions.

Kevin Fort
Principal Software Engineer
NI
0 Kudos
Message 6 of 12
(3,443 Views)

Hello,

 

I've attached an image of the vi with the values given and the results. I'll be looking at the link you provided, but there is one thing about the communications gateway manual that worries me. I noticed that some of the responses are presented as follows:

 

| Slave Address| Function Code| Byte Count| Register Data Hi|Register data lo|    .......    | CRC lo| CRC Hi|

 

Normally the outputs are 16-bit - 32-bit divided into two or four groups of 8-bit integers. However, it seems that for the communications gateway, the outputs may vary in bytes. Do the Modbus vi's that come with the library know how many bytes are in the output and adjust their size accordingly? 

 

Jose

0 Kudos
Message 7 of 12
(3,437 Views)

You will get an array of 16 bit values, 1 for each register.  You will need to do your own programming to combine registers and convert them to 32 bit values where appropriate.  Index Array and typecast will be your friends in doing that.

0 Kudos
Message 8 of 12
(3,432 Views)

Alright,

 

I tried using the typecasts, and I used other function rather than the Modbus library VI's. I'm getting better results, but everytime I run the program I get different resutls. Sometimes is identical to the input. Other times is an array of 10, 11, or more rows, and so on. I don't understand why is this happening...

 

Jose

0 Kudos
Message 9 of 12
(3,427 Views)

Hey Jose,

Are you getting a consistent number of bytes available at the serial port when you run your code?  It may be that the device has not finished writing data to the serial port at the time when you perform the read operation.

Kevin Fort
Principal Software Engineer
NI
0 Kudos
Message 10 of 12
(3,412 Views)