I am all new to LabVIEW and Modbus (bear with me).
I have a digital sensor that communicates via Modbus RTU-485 dongle, 4-wire (outputs 4-20mA, 2-wire). The communication use two separate lines A and B and the dongle connects to a PC through USB.
I want to build a program in LabVIEW that can read and save the data from the sensor in a excel file.
The sensor uses Read Input Registers (baud=9600, no parity, 2 stopbits) and Write Holding Registers.
I have started a VI (see attached file) - so far I have setup the serial port, but I am not sure what the next step is and how to work/connect the read/write slave registers..
I appreciate every tip and guidance 🙂
Solved! Go to Solution.
Make sure you don't do these operations in parallel. Use the purple VISA wires and the yellowish error wires so they operate in serial (otherwise messages will stomp on each other.)
Read the manual for your device to determine what registers you are interested in.
Input registers are read-only and start with a 3 So 30105 for example.
Holding registers are read and or write and start with a 4, so 40208 for example.
If your manual gives you an address like 40208, drop the 4 and subtract 1. So your starting address in the command would be 207. If it gives it as a hex number without the prefix 4 (or 3 for the input register), you might be able to use it as is. It gets confusing because the modbus addresses are usually defined with a prefix and a numbering system that starts at 1. (300001, 400001, 100001), but the actual bytes that are transmitted for the address don't' have the prefix and are based at 0.
Okay. Does it matter what order the blocks of Input Read Reg. and Write Holding Reg. are in?
I can't connect the VISA wire to the Write reg. block. It doesn't have any more inputs/outputs.
Good to know about the zero-indexing!
No. They are two different groups of registers anyway. They have nothing to do with each other.
I have no idea what you mean you can't wire the VISA wire. It has an input and output for the VISA reference wire just like the one you already have wired up.
Ok, so I can have the blocks like the last picture?
The only inputs/outputs on the "Write Holding Register"-block that shows up is starting address, holding regs and error input/output. 😐
You dropped the Slave version of the VI. Go back and drop the Master version, the instance is called Write Multiple Registers.
I've never used the slave versions because my PC is always the master talking to slave devices. This particular VI you dropped on your diagram is a wrapper around an action engine or functional global variable to have a place to store data for the registers in the situation where you might want your PC to act as a slave device and have another modbus master somewhere talking to it.
Thanks for the explanation!
I can read values from the Input register now. I get for example, temperature (float, two spots in the register) value 16872 and 0 (engineering units). How do I convert this to Celsius?
This is a dynamic variable, and I would like to save some values into a file. Do I use the "Write to Measurement file" inside the loop?
Typecast to a single precision floating point number.
Sure, you can try using to Write to Measurement File in the loop.
My "Single precision float" seems to be different from the typecast output. Pink vs orange? 😐
A couple of values have two register addresses next to each other in the read register (due to float?). For example "Temperature (Secondary Value), degrees C, register 1010-1011".. Does these values have to be merged before the type casting? Or how does that work? And if I want to read values from different addresses, with different units - how do I handle that?
In order logg data from, lets say the temperature over 60sec or so, do I connect the typecast output to the Signal on the Write to Measurement File?
I did a similar application with the library below. Pretty straight forward if you are little familiar with Labview.
Serial port can be easily configured too with this.