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.

Communication with sensor via MODBUS


DSB Dec 9, 2010 09:56 PM

Good afternoon,

I've got a CR1000 that needs to read from a sensor via MODBUS, and I'm not sure if I'm setting things up correctly in the code. I'm fairly new to using MODBUS, so it could be that I'm just making an elementary mistake somewhere...

The sensor is set to be on com 1, address 4, baud rate 38400, odd parity. The data I need to pull starts at address 008A and is length 2. (The full MODBUS command, according to the PC software for the sensor, should be 0404 008A 0002 5074)

So if I understand correctly, using the CRBasic editor the important commands should be:

serialOpen(com1,38400,1,0,50)
modbusMaster(r1, com1, 38400, 4,4,v1,138,2,3,1000,2)

Where r1 and v1 are variables declared at the start of the program to hold the response code and the variable array, and the value v1 should then hold the value that I want to write to the data table, correct?

Hoping for any clarifications if I'm on the wrong track,

-David


IslandMan Dec 10, 2010 11:32 AM

David,
You don't need the SerialOpen, ModBusMaster will take care of that.
Please supply more information on the sensor and where to get the manual for it.

I would at least change this:
modbusMaster(r1, com1, 38400, 4,4,v1,138,2,3,1000,2)
to this:
ModBusMaster(r1, com1, 38400,4,3,v1,138,1,3,1000,2)
You probably want to read a holding register, not an input register.
Depending on your main scan rate in the program, 3 retries at 10 seconds each might cause a problem.

* Last updated by: IslandMan on 12/10/2010 @ 4:34 AM *

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