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.

ModBusMaster, CR1000 problems with communication


John_K Mar 3, 2015 03:43 PM

Dear all,

we have a big problem getting a modbus sensor working on a CR1000. Connected to a computer the sensor is running perfectly.
To be more specific: the sensor (radiometer with 3 irradiance value outputs) has a RS485 modbus RTU protokoll. The sensor refreshes the output data registers each second. We have connected a RS485 – RS232 converter and this to the COM3 of the CR1000.
I copied the corresponding part of the CR1000 program below. The OSVersion is: CR1000.Std.27
Some other analog device connected to the same logger runs (voltage measurements via VoltDiff), a data table is generated, the analog values are nonzero, but the values for the modbus device are always 0.

We checked the modbus sensor with the RS485-232 converter directly on a computer using a python script (program below) and we captured the serial communication.
The python computer is sending:
0A 03 00 49 00 01 54 A7
0A 03 00 4B 00 01 F5 67
0A 03 00 4C 00 01 44 A6
in which are 0A=10=modbus address, function 03=read, 49 (73) 4B (75) 4C (76) = registers.
And the sensor returns the 3 values to computer. So, everything is fine and works with python at the computer!

Then we checked the communication between CR1000 and modbus sensor: there was just one call from the ModBusMaster each second as follows:
03 00 4A 00 02 E4 3F
20 00 29 00 20 4F FC
20 20 29 00 20 4F F8
To us these hex numbers make no sense, they have nothing to do with the ModBusMaster settings. There was no reply by the sensor, because the modbus address seems to be incorrect transmitted. We have no clue why the modbus address was wrong in the transmitted signal of the CR.
We would be very thankful and happy if someone of you could give us a hint.

Thank you & best regards,
John

--------------------------
Python programm
---------------------------
#!/usr/bin/env python
import minimalmodbus
import serial

instrument = minimalmodbus.Instrument('/dev/ttyUSB0', 10) # Modbus address=10

instrument.serial.port # this is the serial port name
instrument.serial.baudrate = 9600 # Baud
instrument.serial.bytesize = 8
instrument.serial.parity = serial.PARITY_NONE
instrument.serial.stopbits = 2
instrument.serial.timeout = 0.05 # seconds
instrument.mode = minimalmodbus.MODE_RTU # rtu or ascii mode

while True:
try:
print instrument.read_register(73,1,3),
instrument.read_register(75,1,3), instrument.read_register(76,1,3) #registers
time.sleep(1)
except IOError:
print "IOError"
continue

---------------------------
CR1000 program
---------------------------
' ESA Settingsa
Const ESA_Baud = 9600
Const ESA_mod_reg = 10 ' sensor address

' Declare variables and constants
Public ESA_GHI(1)
Public ESA_DHI(1)
Public ESA_DNI(1)
Public Result
Public Result1
Public Result2
Public Result3
Public StringR
Public test As Float
Dim Read_Chars ' number of characters read by SerialInRecord

Units ESA_GHI = W/m^2
Units ESA_DHI = W/m^2
Units ESA_DNI = W/m^2

' Define Data Tables
DataTable(Data,1,-1)
DataInterval(0,0,mSec,10)
Sample(1,TDome,IEEE4)
Sample(1,TBody,IEEE4)
Sample(1,LWD,IEEE4)
Sample(1,ESA_GHI,IEEE4)
Sample(1,ESA_DHI,IEEE4)
Sample(1,ESA_DNI,IEEE4)
EndTable

' Main Program
BeginProg

'SerialOpen(Com3,ESA_Baud,0,0,1024)
'Clear Buffer
'SerialFlush(Com3)
'''''''''''''''''''
' primary program loop
'''''''''''''''''''
Scan(1000,mSec,0,0)

ModBusMaster(Result1,Com3,ESA_Baud,ESA_mod_reg,03,ESA_DHI,75,1,5,5)
ModBusMaster(Result2,Com3,ESA_Baud,ESA_mod_reg,04,ESA_GHI,73,1,5,5)
ModBusMaster(Result3,Com3,ESA_Baud,ESA_mod_reg,03,ESA_DNI,76,2,5,5)

'Delay(0,100,msec)

' Call Output Tables
CallTable data
NextScan

EndProg

* Last updated by: John_K on 3/3/2015 @ 9:09 AM *


BobCrane86 Mar 25, 2015 12:14 AM

Hi John,

I'm interested if you had any luck solving this problem.

I need to send modbus data over 2 wire RS485 to a PLC.

At this stage I am using "Modbus Poll" to check things in the Lab. Everything works fine if I connect my PC directly to the RS232 port found on the Campbell. I see a message transmitted from the PC requesting the required registers and the CR1000 responds as expected.

To test the RS485 side of things I am using a RS232-RS485 converter together with a RS485-USB convertor. I believe both these devices operate fine and a loopback test seems to prove this. Using these devices between the PC and the CR1000 however result in no coms. Messages are transmitted from "Modbus Poll"on my PC and nothing comes back.

If you, or anyone else has any nuggets of wisdom that may help me I would appreciate it greatly.

Cheers,

Mick


aps Mar 25, 2015 09:01 AM

I suggest you check the details of the RS232-RS485 convertor and check the wiring to the logger. Many will steal power from the RS232 port they are connected to or require RTS/CTS support (which is off by default on the logger). The RS232 port on the CR1000 has a slightly non-standard configuration and the logger will turn it off completely after a period of inactivity, which may be blocking communications.


hkleta Mar 30, 2015 09:49 AM

Hi,

at least for John's setup I can assure that the serial converter is no issue.

It looks more as if the CR1000 uses a "ModBus dialect" different from the one expected by the sensor, although I have to admit that the one from the sensor - as tested with those python scripts - makes sense to me and after all it works fine there.

But the CR1000 is different (and the data sent from the CR1000 is different as shown above), so the question is whether there are further details that can be / have to be setup differently?


Thanks in advance and best regards,

Henry


Sam Apr 27, 2015 06:23 AM

0A 03 00 49 00 01 54 A7
0A 03 00 4B 00 01 F5 67
0A 03 00 4C 00 01 44 A6

To make a logger recreate these queries,

Public Result1, Var1 As Long
Public Result2, Var2 As Long
Public Result3, Var3 As Long
ModbusMaster(Result1,Com,Baud,10,3,Var1,74,1,1,100,1)
ModbusMaster(Result2,Com,Baud,10,3,Var2,76,1,1,100,1)
ModbusMaster(Result3,Com,Baud,10,3,Var3,77,1,1,100,1)


0A = 10 = Modbus Slave Address

03 = Function Code 3

00 49 = Offset 73 = Register # 74
00 4B = Offset 75 = Register # 76
00 4C = Offset 76 = Register # 77

00 01 = Requesting 1, 2-byte / 16 bit, register

To get a 16 bit register, you need to set your modbus option to a 16 bit data type option and make your destination variable a CRBasic LONG.

ModbusOption = 1 = interpret data returned as a 16 bit signed integer

ModbusOption = 3 = interpret data returned as a 16 bit unsigned integer (datalogger OS 28+)


You may also need a SerialOpen() after BeginProg to get your 9600/8/N/2
SerialOpen (COM,9600,7,0,50)

* Last updated by: Sam on 4/27/2015 @ 9:21 AM *


Sam Apr 27, 2015 06:27 AM

-removed-

* Last updated by: Sam on 4/27/2015 @ 9:21 AM *

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