Our full technical support staff does not monitor this forum. If you need assistance from a member of our staff, please submit your question from the Ask a Question page.


Log in or register to post/reply in the forum.

Reading 32-bit data from a Modbus/RS485 sensor using CR6


Italo Feb 22, 2018 08:56 PM

4I'm trying to do a really simple program to read temperature from a sensor, but I'm struggling with variable type.

The data is a 32-bit float and the register numbers are 13-14. This is my program

 

'Declare Variables and Units
Public BattV
Public PTemp_C
Public ModbusResult
Public Temperatura As Float

Units BattV=Volts
Units PTemp_C=Deg C

'Define Data Tables
DataTable(Table1,True,-1)
	DataInterval(0,5,Sec,10)
	Sample(1,ModbusResult,IEEE4)
	Sample(1,Temperatura,Float)
EndTable

'Main Program
BeginProg
	'Main Scan
	Scan(1 ,Sec,1,0)
		'Default CR800 Datalogger Battery Voltage measurement 'BattV'
		Battery(BattV)
		'Default CR800 Datalogger Wiring Panel Temperature measurement 'PTemp_C'
		PanelTemp(PTemp_C,_60Hz)
		'Modbus Master Instruction
		ModbusMaster(ModbusResult,ComC1,19200,1,3,Temperatura,13,1,1,100)
		'Call Data Tables and Store Data
		CallTable Table1
	NextScan
EndProg

 

I'm monitoring the serial bus with a RS485<>USB converter and the data logger is sending the correct modbus message and the sensor is answering as expected, but for some reason my 'ModbusResult' keep incrementing, while nothing is happening at 'Temperatura'.

Is it a problem on my variable type?

 These are the hex messages of data-logger and sensor:

01 03 00 0c 00 02 04 08

01 03 04 41 d3 d7 0a c0 01 

0x41d3d70a = 26.48 (IEEE754), so the sensor answer makes sense.


JDavis Feb 22, 2018 09:07 PM

Watch the response time of the sensor in the terminal. It might need a longer timeout.

If you get result 0, and Temperatura looks like a crazy number, try adding the parameter to chose data type code 2.

ModbusMaster(ModbusResult,ComC1,19200,1,3,Temperatura,13,1,1,100,2)

Log in or register to post/reply in the forum.