Announcement

REXYGEN forum has been moved. This one is closed.
Head over to the new REXYGEN Community Forum at https://forum.rexygen.com.

Looking forward to meeting you there!
 

#1 2017-05-07 20:04:26

hendrik
Member
Registered: 2015-11-01
Posts: 49

Reading temperature - Modbus

Hi,

I am using a 1 wire DS18B20 temperature sensor on a 3rd party device, I then send the temperature reading over Modbus to my unipi.

Question, how do I convert the value which I receive over Modbus to a decimal number to display the actual temperature? Please see the attached.temp.png

(16 bit register - Modbus)

Thanks,
Hendrik

Offline

#2 2017-05-07 21:31:37

scoobsalamander
Member
From: Belgium - Hulshout
Registered: 2015-10-27
Posts: 217

Re: Reading temperature - Modbus

What temperature are you measuring?

This might be the solution :

If the value should be somewhere around 19°C then I think you should divide by 256 (= 8 bit shift to the right) and then divide by 10 to get 19,3°C. 

49408    -->   1100000100000000

divide by 256

193   -->   11000001

divide by 10

19,3°C

...I'm just guessing

(edit : maybe it's a big vs little endian thing and you need to swap both bytes and then divide by 10 to get your value....in this case it will be 19,3°C as well. ...)

Last edited by scoobsalamander (2017-05-07 22:02:04)

Offline

#3 2017-05-09 09:23:52

hendrik
Member
Registered: 2015-11-01
Posts: 49

Re: Reading temperature - Modbus

Hi,

I am measuring temperatures inside control panels and rooms, the temperature range will be 0 - 50degC
The idea is to display the temperature values on my custom Rex HMI and also use the values (Hi/Lo temp) to perform certain actions

Offline

#4 2017-05-09 10:19:49

scoobsalamander
Member
From: Belgium - Hulshout
Registered: 2015-10-27
Posts: 217

Re: Reading temperature - Modbus

If my assumption was ok then you could try something like this : EXAMPLE

REX_20170509.jpg

Offline

#5 2017-05-09 12:25:47

jaroslav_sobota
Administrator
Registered: 2015-10-27
Posts: 535

Re: Reading temperature - Modbus

@hendrik: Please clarify how the value 49408 is obtained and what value it represents (at least approximately). What 3rd party device are you using?

@scoobsalamander: Excellent work. One could also solve that using standard function blocks. Let's wait for additional input from hendrik.

Jaroslav

Offline

#6 2017-05-10 12:04:04

hendrik
Member
Registered: 2015-11-01
Posts: 49

Re: Reading temperature - Modbus

One of the devices I am using is a PLC2011 B1 alarm module. I am connecting a DS18B20 temperature sensor (OWS) to the PLC2011B1

See attached.
ds18.png

Thanks.

Offline

#7 2017-05-11 19:46:14

jaroslav_sobota
Administrator
Registered: 2015-10-27
Posts: 535

Re: Reading temperature - Modbus

According to the PLC2011 B1 manual, page 111, you should divide the value in the Modbus register by 16 to obtain the value in degrees Celsius.

The value 49408 is 1100000100000000 in binary form which is not a valid value for the DS18B20 sensor. See table 1 in the DS18B20 datasheet. Therefore you need to swap HIGH and LOW bytes of the Modbus register. You can do so in the Modbus driver configuration. Just tick the "Swap bytes" option. Remember to tick also the "Signed" option because DS18B20 uses signed 16-bit numbers.

Afterwards you get the value 193 (0000000011000001 in binary form), which gives you the temperature of 193/16=12.0625 deg Celsius.

Hope I'm right, it's tough without the device to validate my thoughts...

Jaroslav

Offline

Board footer

Powered by FluxBB