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.

CR300 & ModBus RTU 485 Sensor


Nicolas Jan 9, 2021 05:52 PM

Hello,

before posting this question, I read all the forum messages relating to the modbus RTU RS485. I hope you can help me.

I want to retrieve data from a CO2 sensor using the Modbus RTU protocol

1.hardware and connections

One CR300 logger

One RS232 / RS485 adapter (https://www.digitus.info/de/produkte/kabel-und-adapter/computerkabel/serielleparallele-kabel-und-adapter/da-70161/)

One cable (between CR300 COMRS232 & Adapter) which connects the gounrd (pin 5) together, the Rx from the first DB9 to the Tx second DB9 and the Tx from the first DB9 to the Rx second DB9, that’s all.

One CO2 sensor: https://www.evikon.eu/pdf/evikon/E2618-CO2_UM_EN.pdf The sensor (tested by a USB / RS485 interface and supplier software) is functional. It physical address is 01h and the other parameters are those listed in the data sheet

Between the RS485 bus cables, I placed a 100 Ohm resistor. The length of the bus is about 20 inch (50 cm) .... I use electric cables that do not have the right characteristic impedance

2. The little program 

The idea of ​​this code, at first, is simply to retrieve the serial number of the sensor

 'Declare Variables and Units

Public BattV

Public PTemp_C

Public Com_Failed

Public ModbusData(20) 'Création d'une variable

Units BattV=Volts

Units PTemp_C=Deg C

'Define Data Tables

DataTable(Every_9s,True,-1)

                DataInterval(0,9,Sec,10)

                Average(1,BattV,FP2,False)

                Average(1,PTemp_C,FP2,False)

                Sample(1,Com_Failed,FP2,False)

                Sample(1,ModbusData,FP2,False)

EndTable

'Main Program

BeginProg

SerialOpen (ComRS232,9600,0,0,1000)

                'Main Scan

                Scan(3,Sec,1,0)

                               'Default CR300 Datalogger Battery Voltage measurement 'BattV'

                               Battery(BattV)

                               'Default CR300 Datalogger Processor Temperature measurement 'PTemp_C'

                               PanelTemp(PTemp_C,50)

                               'Récupération des données Modbus. ModbusMaster(ResultCode, ComPort, BaudRate, ModbusAddr, Function, Variable, Start, Length, Tries, TimeOut, ModbusOption)

                               ModbusMaster(Com_Failed,ComRS232,9600,1,3,ModbusData(),40005,1,1,50)

                                                               CallTable Every_9s

                NextScan

EndProg

 3. the problems 

  • the com_Failed variable systematically returns 1 and increments on each attempt
  • the ModbusData () variable is always 0

 4. My tests

A. RS485 adapter Output

To be sure that the frame is well generated at the output of the RS232 / RS485 adapter, I put the oscilloscope. We can see the frame every 3 seconds.

To make sure that pins 2 and 3 of my cable must be crossed, I tested with Rx on Rx and Tx on TX. Under these conditions, no frame is generated.

 B. Pinout connexion of the sensor

the CO2 sensor informs the terminal connexiotn by A and B (name for which there is often confusion compared to the standard) while the adapter informs + and -, I tested the two combinations, without success

C. Device configuration Terminal

Through the terminal, I make sure that the hex values ​​correspond to the needs of the C02 sensor ....

D. Oscilloscope

As the oscillospce can influence the impedance of the bus, I unplug it to do the tests.

 

In advance, thank you for your feedback and your sharing of skills.

Nicolas


Nicolas Jan 10, 2021 02:45 PM

After having carried out many tests, I was finally able to understand. The registers of the sensors are on 1 byte while the request waited for 32 bits.
It was therefore a simple code error

Nicolas


ipantev Jan 21, 2021 04:52 PM

Hi Nicolas,

Happy you were able to solve the problem. In the end - how did you resolve the mismatch between sizes of the request and registers on the sensor?

I am struggling with a similar problem (I think) - connection keeps timing out and the Modbus variable remains zero.


Nicolas Jan 22, 2021 04:49 PM

Hi,

the problem came from the "Length" parameter and the choice of the "modbus option" parameter. it obviously depends on your sensor (16 bits or 32 ...)

the combination of the two is important

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