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: 

RS-485 Communication using VISA

Hi guys 

 

I am trying to Read RTD data using Temperature controller PIC152 .I am using Serial communication's RS485 standard to read the temperature value with help of VISA and Modbus both.

Through MODBUS I can read the data but when reading using VISA I dont get any value .

 

I just get Warning -> Number of bytes transferred is equal to the requested input count.More data might be available .

I am using property node " bytes at port " to set VISA read byte parameter.

when we see through probe "Bytes at port " gives 0 bytes and above mentioned warning comes.

 

I have attached Image of VI's.

 

 

Download All
0 Kudos
Message 1 of 18
(2,483 Views)

The simple answer could be: use MODBUS since it works. Why are you trying to use VISA?

MODBUS is a command based protocol: you ask some data to the device, the device will send an answer containing those data (hopefully).

In your VISA vi, you simply open the serial port and wait for incoming data: is the device setup to repeatedly send data automatically?

Even if the answer is yes, don't use Bytes at port! This property simply informs you whether any character is available in the input buffer of the serial port; it says nothing about the message itself. The right way to proceed depends on the features of the message to be received: is it ASCII or binary? is there a termination character? a starting character? is its length fixed?

Paolo
-------------------
LV 7.1, 2011, 2017, 2019, 2021
0 Kudos
Message 2 of 18
(2,459 Views)

Although your device my be connected through a serial port your device uses Modbus, so it does NOT use VISA.

 

Use the NI Modbus library  it's free and you can install it using VIPM

 

Actually you probably could use VISA but then you would basically have to reinvent the wheel when it comes to Modbus protocol over serial.

========================
=== Engineer Ambiguously ===
========================
0 Kudos
Message 3 of 18
(2,406 Views)

@pincpanter wrote:

 

MODBUS is a command based protocol: you ask some data to the device, the device will send an answer containing those data (hopefully).

Um... Not exactly... Modbus is a "Register Based" protocol.

 

Data, like measurements are stored in "Holding Registers" analogous to memory locations, to get a measurement you read a "holding register" (maybe two or more registers) and convert the integers returned to your measurement using the scaling information provided by the manufacturer.

 

To change settings you Write a holding register. 

 

To open or close a relay contact you write a "coil"

 

========================
=== Engineer Ambiguously ===
========================
0 Kudos
Message 4 of 18
(2,403 Views)

What pincpanter said was right, you send commands to the slave device in order to retrieve the data stored in the holding register. Master device is not reading directly the registers in the slave device. Master device sends a command (0x03 or 0x04, according to input or holding register) and the slave device is the one in charge to answer to the READ command with the register required by Master device.

Roger Garcia, Certified LabVIEW Developer

HTML tutorial

There are two ways to tell somebody thanks: Kudos and Marked Solutions
0 Kudos
Message 5 of 18
(2,400 Views)

@RTSLVU  ha scritto:

@pincpanter wrote:

 

MODBUS is a command based protocol: you ask some data to the device, the device will send an answer containing those data (hopefully).

Um... Not exactly... Modbus is a "Register Based" protocol.


It may not be the right, term, but, in practice, to read or write registers, you need to send a packet of data over the bus: and this packet is what I call a "command".

Paolo
-------------------
LV 7.1, 2011, 2017, 2019, 2021
0 Kudos
Message 6 of 18
(2,370 Views)

@pincpanter wrote:

@RTSLVU  ha scritto:

@pincpanter wrote:

 

MODBUS is a command based protocol: you ask some data to the device, the device will send an answer containing those data (hopefully).

Um... Not exactly... Modbus is a "Register Based" protocol.


It may not be the right, term, but, in practice, to read or write registers, you need to send a packet of data over the bus: and this packet is what I call a "command".


Right, there is read or write command in there someplace. But Modbus API pretty much abstracts that out. So it does not seem quite the same "command-response" based as querying a SCPI instrument.

========================
=== Engineer Ambiguously ===
========================
0 Kudos
Message 7 of 18
(2,365 Views)

In terms of VISA communication which the NI Modbus library uses internally, the Modbus protocol is certainly a command/response protocol. The device never initiates any data transfer but the controller sends a command to read or write a register or coil. The device always responds with the read data or an acknowledge package (for write commands).

 

To implement the Modbus protocol is a fun exercise but not if you are starting out with serial communication. One of its modes (RTU) is very binary based and both modes are complex enough to be a real challenge to implement properly.

 

In any case if you start out with using Bytes at Serial port, you are already on the wrong path!

Rolf Kalbermatter
My Blog
0 Kudos
Message 8 of 18
(2,355 Views)

It is Modbus RTU so data type is Binary.

 

0 Kudos
Message 9 of 18
(2,311 Views)

Thanks all for your responses .

After lot of exploration I found ,In order to read data from Modbus slave device we need to send command in following format.

slave address, function code, starting address ,quantity of registers ,CRCbits.

 

i have send command in above order but still I a not able to read the required data.

I am attaching the VI ,also the link of website where I read about the format, 

and Parameter document(From where you can know slave id ,func code ,starting address ,quantity of registers).

also I want to know how to find what would be CRC bit if we are reading data.

 

link where i got above info-  https://www.modbustools.com/modbus.html

Download All
0 Kudos
Message 10 of 18
(2,288 Views)