LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

connecting HMI controller using Modbus

Solved!
Go to solution

I want to connect a HMI controller for reading and writing a parameter via LaVIEW and Modbus RTU protocol (RS485).
The HMI controller is not popular so I cannot find any library for my purpose using Modbus RTU.

 

Due to the modbus tutorial at http://www.simplymodbus.ca/FAQ.htm, I can learn the basic information of modbus.

 

The standard format like the following.
Format: the slave address, function code, The data address of the first register requested, The total number of registers requested, CRC

 

I am wondering if I can try to communicate with the attached protocol provided by a manufacturer.
For example, how can I guess 'function code' and 'The total number of registers requested'?
How can I interpret the float-format of register like "40003.14".

 

Can you guide me the basic?

 

Is there some favorite Modbus library for an indispensable stuffs like conversion of various data types and CRC?
*)Actually, I downloaded "NI Modbus" library but it was very complicated for me.

 

labmaster.

0 Kudos
Message 1 of 8
(3,228 Views)
Solution
Accepted by topic author labmaster

Hi Labmaster,

 

read the manual more carefully: these are boolean values and the notation says "Register 40003, Bit #14"…

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 2 of 8
(3,213 Views)
Solution
Accepted by topic author labmaster

First, there is no need to implement Modbus yourself and I would suggest not using the old NI library, because it's not very good. There are better implementations of Modbus around, like this one - https://sine.ni.com/nips/cds/view/p/lang/en/nid/214230

 

There are probably others too, but I don't have much experience with any of them.

 

For the function code, you want to read or write holding or input registers registers, because the addresses in your device are between 30000 and 50000. See for example the table here - https://www.simplymodbus.ca/FAQ.htm#Stored

 

Note that usually the actual address you will put into the specific function starts with 1, so if you want address 40013, then it will usually be read holding registers with address 13.

 

The number of registers you want to read depends on the range you want. If you want to get data from register 1 and 8 in the same call, then you will need to set 1 as the start register and at least 8 as the number of registers.

 

The 40003.14 is not actually a float, because its data type as marked as B, which means boolean. What they probably mean is that the register is actually a bitfield and this is bit 14. You can convert these using Number to Boolean Array.

 

The ones that are floats are actually a good question. Each Modbus register is 16 bit and the commonly used floating point format use either 32 or 64 bits. In this case, it's likely they're using single precision floating point, which is 32 bits, and you will need to read two consecutive registers and then convert them to a SGL value using the Type Cast function. For example:

Convert to float.png

 

Depending on exactly how the device formats these values, you might need to reorder the bytes before converting. This can be done, for instance, by using Split Number and Join Numbers.


___________________
Try to take over the world!
0 Kudos
Message 3 of 8
(3,208 Views)

Thank you for the comments.

Your comments are very helpful.

I will post the next problems.

 

labmaster.

0 Kudos
Message 4 of 8
(3,172 Views)

I was depressed from RS-485 as a beginner.

 

I just tried to connect the slave today.
In any way, I wrote a code for reading a boolean using the Plasmionique libray as you recommended but it failed to read the value from the HMI screen in LabVIEW.
Of course, I harmonized the serial connection parameters in master (my PC) with that of slave (HMI screen) on my program.

 

I verified this result using the 3rd party utility, mbreader2.exe from Watlow Inc.
My RS485 adapter supports echo mode of command and the setting of terminating resistance.
As you can see the attachment, the message of echo was received but case of CRC/LRC error.

In normal (non-echo) mode, there is an error of time-out which is the same result in LabVIEW.
*) Can you suggest more popular utility for Modbus read/write for checking normal operation?

 

I also got to know there is no possibility to make a mistake in wiring #3(TRXD+)/#8(-) of a Dsub 9 pin connector contrary to the possible case in RS-232.

 

In my rough thinking, rebooting of HMI screen is remained but I know this is not a great idea.

 

What do I need to check more?

 

labmaster.

 

Download All
0 Kudos
Message 5 of 8
(3,137 Views)
Solution
Accepted by topic author labmaster

Are you sure you have the controller address correct?  (More commonly known as slave address.)

 

You have it set to 1 in your program.  If the device is set for a different slave address, it will ignore the message you sent it and you will get no response.

0 Kudos
Message 6 of 8
(3,124 Views)

Surprisingly, I got the newly updated manual contained a different protocol from a manufacturer.

They didn't know about the detail of Modbus so I need to test it more.

I will be back to here after my testing.

 

labmaster.

0 Kudos
Message 7 of 8
(3,122 Views)

I got to know the pin layout of slave is different to what I know.

The #7/#8 in Dsub connector should be interchanged in RS485 adapter.

The connection has no problem and I can get some U16 data.

 

Thank you much, Knights!

 

labmaster.

0 Kudos
Message 8 of 8
(3,092 Views)