LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Modbus RTU

Solved!
Go to solution

Hi!

I'm making a project and I have some troubles with communication via Modbus RTU. I'm trying to collect and save data from Presys ST501 Thermometer. I didn't had original converter for connection so I used a CP2012 USB-UART converter like this one below:

Buy USB-UART converter CP2102 - USB plug - Botland - Robotic Shop

It looks like it'ś working and by working I mean sending and receiving massages but I don't know how to get selected (temperature) from responses. I'm not sure about correctness of the query also.

I found manual for the ST501 and in section 5 it's explained how to use the Modbus connection in some way but I don't know what I'm making wrong and what should I correct in my program. 

I don't have much experience in LabView so any help will be useful.

Download All
0 Kudos
Message 1 of 7
(3,219 Views)

I forgot to paste the link to the manual:

manual_2_111.pdf (akrimet.com)

0 Kudos
Message 2 of 7
(3,218 Views)

I made some cosmetic job for clarify visual content. By the way I noticed something strange. Even if the thermometer is turned off and the program is runnig it's still getting response from ST501. Is it correct? 

0 Kudos
Message 3 of 7
(3,189 Views)
Solution
Accepted by topic author Eyyk

When you deal with ModBus devices you should consider the following points/suggestions:

 

  • Unit ID of the ModBus device you communicate to. Every ModBus slave has an unit ID (a sort of device address). In the datasheet it is called Slave address. The Unit ID is a number from 0 to 255. By default, usually, the default Unit ID is 0 or 255. In your code you should specifiy the Unit ID to use. I was not able to find the used Unit ID in the datasheet. 
  • Be sure that you are using the right read function. ModBus supports different kinds of read mode and different kind of "area memories" (read single input register, read multiple input registers, read single holding register, read multiple holding registers, ecc..). For each of these "modes" corresponds a function code. In your case, the datasheet reports that you can use read input and holding registers.
  • Be sure that your are reading the right register. ModBus registers can be 0-based or 1-based. For experience, given the address X to read, I suggest you to try to read X, X-1 and X+1.
  • Data conversion. Data in a ModBus register is a chunk of bit. Every register occupies 16 bits. But you should know how the vendor is representing the data in the modbus register. Some examples of required conversions are: convert to floating point, convert to integer with sign, data/10, convert to fixed point, etc...
  • Try to use a thirdy party modbus master, like ModBus pool.

 

0 Kudos
Message 4 of 7
(3,139 Views)

At first thank you for your answer. 

 

I tested different unit ID numbers from 0 to 255 and all works the same. I don't know why. By changing "Strating adress" I'm getting quadrupled values. For example for adress 0 value is 0, for 1 it's 2,35099E-38, for 127 it's 1,70141E+38. At 128 it's -0 (?) and for 129 it's again -2,35099E-38. Register values works the same way but also repeat themselves every 256 adresses. What's the worst I'm not able to use different Modbus master because I need to have everything in LabView. I'm devasteded and I don't know what to do. It's completly not my field. I work in energy sector on all voltages but I can't handle somthing like this. 😞

I'm adding some screenshots to show how it's working right now.

0 Kudos
Message 5 of 7
(3,099 Views)
Solution
Accepted by topic author Eyyk

From your screenshot the ModBus read function returns some values. It means the UnitID is correct. Keep using Unit ID = 1.

 

Now, you need to convert ModBus data in real data. There is not a specific rule for doing this. Vendor of the device you are using has defined its own way to represent data and this is (should be) specified in the datasheet.

The datasheet is quite generic and not well detailed about data representation. Please, ask the vendor to give more pieces of information about data representantion in ModBus communication. 

 

Anyway, the datasheet reports the following sentence:

 

The values formed by 4 consecutive registers have a long integer format, each
register corresponding to one byte of the long integer (the most significant byte belongs
to the register with the smallest identification number). For instance, the value 300001
(000493E1h, in hexadecimal system) is read by registers 50 to 53 as: 0|4|147|225 or
0h|4h|93h|E1h (in hexadecimal system).

and reports also this:

 

The value ranges of certain registers listed in the table above have a fixed
number of decimals.

So, in my opinion, for the registers 50 to 53, you should:

- Read registers 50 to 53. ModBus read function will return an array of 4 integers.

- Convert these 4 integers in a long integer (let's call it X).

- Read the number of used decimal from ModBus register 54. (let's call it D)

- Convert your data in the following way: data = X*10^(-D)

 

In attachment, you can see a small piece of code for converting the 4 registers into a decimal number (as specified above).

 

 

 

Message 6 of 7
(3,089 Views)

Thank You for your help. Everything works great! 🙂

0 Kudos
Message 7 of 7
(3,001 Views)