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.

CR1000 ModbusMaster help needed


Hudi Nov 12, 2021 01:50 AM

I'm trying to talk to a silicon reference cell (IMT Si-RS485TC-2T-v-MB) that uses ModBus.

I want to give it a command such as:

01 04 00 00 00 03 B0 0B
which is
Modbus ID: 1
Function: 4 (read input registers)
Register start: 1
Num registers: 3
CRC16 2992

The output should be something like:
01 04 06 00 18 01 F7 03 E9
which is
Modbus ID: 1
Function: 4
Byte count: 6
Data0: 24
Data1: 503
Data2: 1001
CRC16: 8688

My knowledge of serial programming is minimal, but I know that this works because I've been able to do it using a Moxa Modbus-TCP gateway, as well as using the simple configuration tool that came with the sensor (along with a USB-RS485 adapter).

So here's my code:

-------------------------------------------------
Public ModbusResult1
Public Ref1_mbResult As String
Public Modbus(3) As Long
Public Ref1_Irr : Units Ref1_Irr = W/m²

Function ModbusResultDecode (Code) As String
If (Code > 0) Then
ModbusResultDecode = "Offline: " + Code
ExitFunction
EndIf
Select Case Code
Case 0
ModbusResultDecode = "Success"
Case -1
...
Case -20
ModbusResultDecode = "ModbusMaster error (Variable not dimensioned large enough to store result)"
Case Else
ModbusResultDecode = "Unknown Error"
EndSelect
EndFunction

BeginProg
SerialOpen(Com3,9600,0,200,1000)
Scan(10,Sec,1,0)

ModbusMaster(ModbusResult1,Com3,9600,1,4,Modbus(),1,3,1,100,1)
Ref1_mbResult = ModbusResultDecode(ModbusResult1)
If ModbusResult1 = 0 Then
Ref1_Irr = Modbus(1)
Else
Ref1_Irr = NAN
EndIf
NextScan
EndProg
-----------------------------------------------------

When viewed in the Terminal in Device Config, I see this:

17:35:10.01 T 01 04 00 00 00 03 B0 0B ........
17:35:10.02 R 01 04 00 00 00 03 B0 F8 ........
17:35:20.01 T 01 04 00 00 00 03 B0 0B ........
17:35:20.02 R EC E1 ..
17:35:30.01 T 01 04 00 00 00 03 B0 0B ........
17:35:30.02 R 80 80 FE E1 ....
17:35:40.01 T 01 04 00 00 00 03 B0 0B ........
17:35:40.02 R 80 80 80 03 B0 0B ......
17:35:50.01 T 01 04 00 00 00 03 B0 0B ........
17:35:50.02 R FE .
17:36:00.01 T 01 04 00 00 00 03 B0 0B ........
17:36:00.02 R B6 E1 ..
17:36:10.01 T 01 04 00 00 00 03 B0 0B ........
17:36:10.02 R FB F8 ..
17:36:20.01 T 01 04 00 00 00 03 B0 0B ........
17:36:20.02 R C0 .
17:36:20.02 R F0 B6 E1 ...

The response is of different lengths, sometimes it's an echo of the poll, and I can't make sense of any of it.

In Data Monitor, the result is always a communication error.

I think I must be missing something obvious, but I've spent about 10 hours digging through articles and forums, but I can't find any info about this. I've also done a lot of trial-and-error with various settings, but the results are always the same.

Help would be greatly appreciated.


Thein Nov 13, 2021 09:45 AM

Hi Hudi,

I have siimilar problem before. It was ok by increasing the delay. Try increase the scan interval to 1minute and increase the delay to 500, see what happen.

Thein


JDavis Nov 15, 2021 10:16 PM

Initially using a longer timeout is good advice.

Also, try a 120 termination resistor between A and B(C3 and C4).

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