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 Modbus(1) As Long
...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
MBoutstr = CHR(&h01)+CHR(&h04)+CHR(&h10)+CHR(&h00)+CHR(&h00)+CHR(&h01)+CHR(&h35)+CHR(&h0A)
....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?
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.
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.
What a huge help! Unfortunately, while I had the proper concept, I had the wrong number. With time and practice, I believe I will be able to master not just MoveBytes, but also SerialOutBlock. basketball stars
This post is under review.