LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Read MODBUS Registers

Solved!
Go to solution

Hello all,

 

I've been over the manuals/threads of using the Modbus library to communicate via serial. However, I'm not sure what exactly I'm doing wrong. If I use a program such as Modbus Poll and send 02 03 00 02 00 02 65 F8 I get a response back: 02 03 04 39 20 3F 90 D5 F9. Looking at the manual for the device I'm communicating with (a pressure transmitter), the request is in the following format:

 

02 - Address

03 - Function

00 - StAdd H

02 - StAdd L

00 - # Reg H

02 - # Reg L

65 - CRC16 L

F8 - CRC16 H

 

The response is in this format:

 

02 - Address

03 - Function

04 - # of Bytes

39 - Data H

20 - Data L

3F - Data H

90 - Data L

D5 - CRC16 L

F9 - CRC16 H

 

So, in LabVIEW this is how I have it setup:

 

modbus.png

 

I set the "Starting Address" at 1 because I read it has to be 1 less in LabVIEW than what the actual starting address is (n-1). I'm expecting the same response as above using Modbus Poll. In the block diagram above, I receive the following from the registers, beginning at index 0: 256, 661, 63490, 33538

 

Obviously the response isn't in Hex as above, but it's nowhere close to what it should be.

 

Thanks for the help!!!

0 Kudos
Message 1 of 32
(4,894 Views)

I haven't done any Modbus for a while but from memory the address is not decremented so addr 2 = 2 etc. The -1 was for the port number on the old serial commands.

0 Kudos
Message 2 of 32
(4,874 Views)

If I have the starting address at 2 I get a Timeout Error, code 6101.

0 Kudos
Message 3 of 32
(4,871 Views)

What make/model transducer is it?

0 Kudos
Message 4 of 32
(4,868 Views)

Attached is the communication protocol for it. Modbus specs start at page 9. Thanks for taking the time, ssk!

0 Kudos
Message 5 of 32
(4,863 Views)

buickgn,

 

By default Visa Configure Serial Port.vi enables the termination character.  You need to disable it.

0 Kudos
Message 6 of 32
(4,848 Views)

Wayne,

 

I disabled it and still receive the same response if I use the starting address as 1. If I have the starting address as 2 I still receive a timeout error.

0 Kudos
Message 7 of 32
(4,844 Views)

buickgn,

 

Suggest you use NI-Spy to monitor what is actually being transmitted and compare to your known good packet.

Message 8 of 32
(4,842 Views)

Wayne,

 

Great idea. I ran the trace and setting the starting address at 2 I see the correct request "02 03 00 02 00 02 65 F8". However, under the "VISA Write" that contains that request, there are about 2000 VISA Get Attribute/VISA Read.

0 Kudos
Message 9 of 32
(4,834 Views)

buickgn,

 

All the get attributes are where the modbus vi is checking to see what has been received by the UART.  What kind of hardware are you using for your COM port?

0 Kudos
Message 10 of 32
(4,831 Views)