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.

Modbus over CR1000


rwc Jun 29, 2017 07:24 PM

Hi:

I'm trying to communicate with a wave sensor that uses Modbus and am not able to get the right strings out to it.  I've been up and down the documentation and all over the googles without success, I'm hoping someone here can clue me in.  It's using RTU protocol through an RS232 converter, and it uses big endian.

Here's an example:

The Modbus address (1) is stored in the input registers (Function 4) at starting register 0x1000 (i.e. 4096) in a single register.  The request for that is:

01 04 10 00 00 01 35 0A

... if I send it that through a terminal program it sends back 01 04 02 00 01 78 F0  (the address, 1, is the third to last byte).

I've tried to use the ModbusMaster command, here' s a simple program to do that:

Public ModbusResult
Public Modbus(1) As Long

DataTable(Waves,True,-1)
DataInterval(0,10,Sec,10)
Sample(1,Modbus(1),FP2)
EndTable

BeginProg
SerialOpen(COM2,9600,3,0,1000)
Scan(10,Sec,1,0)
ModbusMaster(ModbusResult,COM2,9600,1,4,Modbus(),4096,1,3,100,1)
CallTable Waves
NextScan
EndProg

...That sends out 01 04 0F FF 00 01 02 EE;  I've tried the other ModbusOptions settings to make sure I didn't have that wrong.  I'm thinking that I must have the offset wrong for the starting register, and have tried a few educated guesses without success.  What am I missing here?

OK says I, maybe I can do it via SerialOutBlock.  That might even be preferable, because a lot of the data is a mix of different formats (floats and u16) with varying offsets, so will have to be pulled out and converted manually.  So I tried this:

Public MBstring As String
Public MBoutstr As String

DataTable(Test,True,-1)
DataInterval(0,10,Sec,10)
Sample(1,MBstring,FP2)
EndTable

BeginProg
SerialOpen(COM2,9600,3,0,1000)
Scan(10,Sec,1,0)
MBoutstr = CHR(&h01)+CHR(&h04)+CHR(&h10)+CHR(&h00)+CHR(&h00)+CHR(&h01)+CHR(&h35)+CHR(&h0A)
SerialOutBlock(Com2,MBoutstr,8)
SerialIn(MBstring,com2,10,-1,100)
CallTable Test
NextScan
EndProg

....That is sending out 01 04 10 01 35 0A 00 00, so it's all there, but in the wrong order.  Can anyone explain why that is, and what I need to do to have it send out what I want?

Thanks,

Rob


JDavis Jun 29, 2017 08:14 PM

Put your starting register in as 4097. That should fix it.

We use 1-based register mapping in documentation, which is most common. Modbus trasmits 0-based. Some devices use the 0-based addressing in their documentation. If that is the case, you need to add 1 to the register numbers in CRBasic to compensate for the difference.


rwc Jun 29, 2017 10:32 PM

Thanks so much!  I had the right idea but the sign wrong: I had tried 4095.  As I'm learning more about MoveBytes I think I might be able to figure out SerialOutBlock too.

Cheers, Rob

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