Labview Modbus Serial Example

While exchanging with our customers on the best ways to interface industrial controllers, we noticed that nowadays the small secrets enabling you to use an RS485 interface were sometimes unknown from engineers implementing computer or internet based automation. So here is a quick remedial course..

MODBUS communication. This will help you identify problems that may appear during serial communication and prevent them. What should I look at as an issue. See manual for addition. The original Modbus Protocol specification, published in 1979, describes Serial Communications where data is transmitted one bit at a time. A later update to the standard, called Modbus TCP, describes how to use Modbus in TCP/IP networks. The rest of this article describes the Modbus protocol is more detail: Modbus Data Types. Creates a serial or TCP Modbus master instance. You must manually select the polymorphic instance to use. You can use the Modbus master instance to perform read and write operations on Modbus slaves. The default read and write operation timeout is 5,000 ms. You can use the Property Node or the Set Timeouts VI to change the timeout. Labview Modbus Rs232 Example xAP protocol always uses broadcast for sending the messages. Suitable for monitoring circuit breakers, flow meters, PLCs etc. Modbus is a very simple protocol. Modbus Library Modbus Library. Edit edit your slave data in Excel.

What is RS485?


RS485 is a serial transmission standard, a little bit like RS232, but using other electric signals. An important advantage of RS485 is that you can put several RS485 devices on the same bus. Therefore, you don't have to multiply RS485 interfaces on the host to question several devices. However, there is a small trick to do so: at each end of the bus, you must put a bus terminator. Sometimes this means that you must screw a small resistance on a terminal, or simply move a switch in the adequate position.

Installing cracked apps on iphone without jailbreak.
An RS485 bus is often made of just two wires and a resistor at the extremities..


RS485 and RS232 are not directly compatible: you must use the correct type of interface, or the signals won't go through. There are indeed RS232 to RS485 gateways, but they are not interesting nowadays: it's as easy to use an RS485 to USB, to Ethernet, or to GSM directly. It's cheaper and it's one less component in the system.
The main particularity when using RS485 is in the format of the exchanged data. While with RS232 many devices simply use text (ASCII) protocols, with RS485 most devices use the MODBUS protocol. You must therefore know a minimum of MODBUS to interface an RS485 device.

Serial

What is MODBUS?


MODBUS is a protocol between a host (master) and devices (slaves) to access the configuration of the devices and to read the measures. MODBUS messages correspond to relatively simple operations to read and write 16 bit words and binary registers (often called 'coils'). The host systematically initiates the exchange and the 'slave' device answers. The slave doesn't sent any message before the host requests it.
As there can be several devices connected in parallel on the RS485 bus, each slave device must use a unique MODBUS Slave ID on the bus. Each MODBUS request starts with the Slave ID of the intended device, each answer starts with Slave ID of the slave sending it. So, in order for the MODBUS communication to work, you must check in the device configuration its Slave ID and change it if necessary. On the way, check also communication speed and parity (same principle as RS232).
You cannot easily craft MODBUS messages 'by hand', as you would have done with ASCII protocols used on RS232: each MODBUS message ends with a checksum code, computed from the full content of the message. To exchange MODBUS messages, you must therefore use:

  • either a specific program provided by the device vendor, with a compatible interface;
  • or a simple RS485 interface with a programming library which encodes and decodes MODBUS messages;
  • or a smart RS485 interface able to encode and decode by itself the MODBUS messages, such as the Yocto-RS485.


Note as well that there are two variants of the MODBUS protocol: the MODBUS ASCII mode, where messages are exchanged as lines of hexadecimal codes, and the MODBUS RTU mode, where messages are exchanged directly as binary frames. To talk with a MODBUS device, you must imperatively use the same mode as configured in the device. All the devices which truly follow the standard support the MODBUS RTU mode. In real life, its always this latter mode which is used: MODBUS ASCII has no advantage as all the messages are in any case difficult to code by hand.


A small temperature controller with built-in PID, fuzzy logic, .. and a MODBUS interface on RS485


Accessing MODBUS registers


When you have theoretically understood how to exchange information, you still must know which register to request to obtain measures, and which registers to change to configure the device. At this level, register addresses change from one device to another, but there are MODBUS conventions useful to know to understand technical user guides, which are often not as clear as one could hope.
There are 4 types of MODBUS registers:

Example
  • The coils, corresponding to on/off binary outputs, such as relays.
  • The input bits, corresponding to binary inputs (read only).
  • The input registers, corresponding to analog inputs (read only).
  • The holding registers, corresponding to analog parameters which can be changed.

Labview Modbus Serial Example Diagram


The technical user guide of a MODBUS device usually contains a list of all the available registers, listed by type. For each type of register corresponds a range of register numbers, following this convention:

  • The coils are numbered from 00001 onward
  • The input bits are numbered from 10001 onward
  • The input registers are numbered from 30001 onward
  • The holding registers are numbered from 40001 onward


Note that when one uses this convention, the first register of each category always ends by digit 1 (zero is not used).
Sometimes, rather than indicating the unique register number, the vendor indicates the type of register with the identifier of the MODBUS function which allows you to read them:

  • 01h for the coils
  • 02h for the input bits
  • 04h for the input registers
  • 03h for the holding registers


In this case, it's often the relative position of the register in its group which is indicated, with the 0 position for the first element. Thus, register 0 of the 04h function corresponds to the first input register, which you can also call register 30001. Take care not to be confused by the incoherence between register ranges which do not correspond to the MODBUS function identifiers, and the incoherence of relative positions starting at 0 while absolute positions start at 1..
When you know which register to access, you must still know how to interpret it. As analog registers are coded using 16 bits, there are usually two conventions. The first one consists in using a value range defined in the device configuration, and to make an linear mapping of the 0-65535 register value to this value range. The second consists in storing directly the value in decimal fixed point, in engineering unit: for example, 2345 represents 23.45 degrees Celsius. Some vendors provide simultaneously the values in the two formats: for example, register 30001 for the version proportional to the defined range and register 31001 for the decimal version.

A concrete example


Let's see concretely how you can access the temperature measurement and the setpoint value of a Schneider Electric Zelio REG48 temperature controller. Here is an extract of the technical user guide:

Diagram

Pixel gun 3d hack apk mod menu.
Extract of the register table of the Zelio REG48 controller

Labview Modbus Serial Example Key


If you have paid attention, you have understood that this table describes input registers. The base register use the proportional format, and the one at offset +1000 is in decimal form (engineering unit). If you use a Yocto-RS485 you can thus access it with the modbusReadRegisters() function. Beware, as indicated in the documentation, this function uses the relative position of the register (indexed from zero):

Modbus Rtu Example

// Retrieve our RS485 interface
var serial =YSerialPort.FindSerialPort('RS485-REG48');
// Read first two registers, in 'engineering unit'
var slaveID =1;
var firstRegs = serial.modbusReadInputRegisters(slaveID,1000,2);
// Decode fixed point decimal number
var processVal = firstRegs[0]/10;
var setpointVal = firstRegs[1]/10;

Hiren boot cd latest version 2019 download iso.
Another possibility of use with the Yocto-RS485: you can configure it with the web interface so that it automatically reads those registers, without needing you to interact with a computer to trigger the measures.


A job to periodically read a register


Thanks to this, the Yocto-RS485 can serve as a data logger to store the measures received by RS485 on its flash memory (up to 500'000 measures).
You can go even farther: if you connect the Yocto-RS485 on a YoctoHub-Ethernet and if you load on it a small web page with some JavaScript, you can transform this simple RS485 temperature controller based on technology from the 70's into a connected product in the fashion of the Internet of Things. Any browser running on a tablet can then connect to the interface and interact with the temperature controller:

Modbus Tcp Labview


Neat, isn't it?

JavaScript is disabled. Details

Labview Modbus Rtu Example

The master uses this VI to read the slaves' holding registers. This corresponds to a public function code of 3 in the MODBUS protocol.

Labview Modbus Serial Example Reference

Serial Parameters are parameters that modify the way the MODBUS frame is structured. Refer to the MODBUS specification for more information about the MODBUS Frame. The Serial Parameters in LabVIEW is a cluster containing an enum (Mode) and an integer (Slave Address).

Mode

RTUData is represented in binary format.

ASCII
Data is represented in ASCII, so it is human readable.

Slave Address

This is the address of the slave you are communicating with. This property is usually valid for RS-485 networks, which can have multiple MODBUS devices connected to the same network.
Note: Consult your device documentation to find out how to validate/change the address of your device.

VISA resource name specifies the resource to be opened. This control also specifies the session and class. For more information about VISA resource names, refer to the NI-VISA Help.
Starting Address is the first address location of the holding register to read. This address is sometimes referred to as offset. Refer to your device's documentation to find the holding register address mapping.
Be sure to specify the correct address in the MODBUS device configuration software for the register you want to use in LabVIEW. In most MODBUS device configuration software, you must enter a name for the register you want to use. Per MODBUS convention, the register address of the slave device is calculated by subtracting 1 from the register name that you specify in the master device configuration software. The MODBUS LabVIEW library expects register addresses, not register names, so you may need to subtract 1 from the address you defined in the MODBUS device configuration software. For example, a register name defined as 2 in a MODBUS configuration device translates to register address 1 in the Holding Registers table of the LabVIEW MODBUS library, as shown below.
MODBUS DeviceHolding Register Name = 2
LabVIEWHolding Register Address = 1
Quantity represents how many holding registers to read from the slave. The VI returns the holding register at Starting Address and each following holding register up to Quantity.For example, if Starting Address is 0 and Quantity is 4, the VI reads holding registers from the slave at address 0, 1, 2, and 3.
Timeout specifies the maximum time period, in milliseconds, that the VI waits for the slave's response before throwing an error.
error in describes error conditions that occur before this VI or function runs. The default is no error. If an error occurred before this VI or function runs, the VI or function passes the error in value to error out. If an error occurs while this VI or function runs, the VI or function runs normally and sets its own error status in error out. Use the Simple Error Handler or General Error Handler VIs to display the description of the error code. Use error in and error out to check errors and to specify execution order by wiring error out from one node to error in of the next node.
status is TRUE (X) if an error occurred before this VI or function ran or FALSE (checkmark) to indicate a warning or that no error occurred before this VI or function ran. The default is FALSE.
code is the error or warning code. The default is 0. If status is TRUE, code is a negative error code. If status is FALSE, code is 0 or a warning code.
source identifies where an error occurred. The source string includes the name of the VI that produced the error, what inputs are in error, and how to eliminate the error.
VISA resource name out is the resource to which a VISA session is opened and its class. The class matches that of the VISA resource name input. For more information about VISA resource names, refer to the NI-VISA Help.
Holding Registers represents the data read from the slave (array of U16).
Exception Code is nonzero if a MODBUS error has occurred. The exception code mapping is as follows:
0No error
1Illegal function
2Illegal data address
3Illegal data value
4Failure in associated device
5Acknowledge
6Busy, rejected message
7NAK—Negative acknowledge
For more information about these error codes, refer to your device's documentation.
error out contains error information. If error in indicates that an error occurred before this VI or function ran, error out contains the same error information. Otherwise, it describes the error status that this VI or function produces. Right-click the error out front panel indicator and select Explain Error from the shortcut menu for more information about the error.
status is TRUE (X) if an error occurred or FALSE (checkmark) to indicate a warning or that no error occurred.
code is the error or warning code. If status is TRUE, code is a nonzero error code. If status is FALSE, code is 0 or a warning code.
source describes the origin of the error or warning and is, in most cases, the name of the VI or function that produced the error or warning.