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 Registers


TaCaPica Mar 14, 2011 07:40 PM

Hi there

Im trying to get a CR800 to work in a network, serving as a slave modbus unit to a PLC.
As i was testing the modbus protocol in the logger i notice that the registers always jumped one. I have register in 40000, in 40002, in 40004 and so on, leving the intermediate with zeros....

Is this a normal behavior?

the code i used was:

Public MBV(11) As Long
Public Var(11)

'Main Program
BeginProg

ModBusSlave (Com1,9600,1,MBV(),0)

Scan (5,Sec,0,0)

Var(1)=Var(1)+1 'just to generate results
Var(2)=Var(1)+1
Var(3)=Var(2)+1
Var(4)=Var(3)+1
Var(5)=Var(4)+1
Var(6)=Var(5)+1
Var(7)=Var(6)+1
Var(8)=Var(7)+1
Var(9)=Var(8)+1
Var(10)=Var(9)+1
Var(11)=Var(10)+1

'-------------------------------------------------

MBV(1)=Var(1)
MBV(2)=Var(2)
MBV(3)=Var(3)
MBV(4)=Var(4)
MBV(5)=Var(5)
MBV(6)=Var(6)
MBV(7)=Var(7)
MBV(8)=Var(8)
MBV(9)=Var(9)
MBV(10)=Var(10)
MBV(11)=Var(11)

NextScan
EndProg

* Last updated by: TaCaPica on 3/14/2011 @ 1:40 PM *


IslandMan Mar 15, 2011 10:49 AM

From the help file in CRBasic

The ModBusVariable parameter is used to specify the variable array that is used as the source of data for the ModBusMaster, or the variable array that is used as the destination for data received from the ModBusMaster. This variable can be formatted as either Floating Point or Integer. If Variable is declared as Long or Boolean, then this parameter is set as a ModBus integer; otherwise, floating point ModBus will be used. Longs are assumed to be signed integers (numbers will be in the range -32768..+32767). The datalogger does not differentiate between holding and input registers. The only difference is the address offset. The specified array will be used for requests of input (address offset of 30000) or holding (address offset of 40000) registers.

Floating point variables take two ModBus registers. The ModBus input registers are offset by 30000; ModBus holding registers are offset by 40000. Therefore, the first register corresponding to any array location X is holding register 40000+2X-1. For example, to retrieve array value number 3, you would ask for two registers starting with 40005.

If the ModBusSlave is queried by the master using an odd number of registers, the then ModBusSlave datalogger assumes the request is for a 16 bit integer.

Hope this helps


TaCaPica Mar 18, 2011 11:23 AM

Before posting, I read the help CRBasic (I have an older version on my PC and I had not the last paragraph you posted).
I tried several kinds of definitions for the variables and my reading was always a 32-bit (2 records) number, for each variable.


My question now is: can I set, in the slave, the length of the variable that I will send to the master, not depending if the number of registers that the master asks, even or odd?

* Last updated by: TaCaPica on 3/22/2011 @ 1:28 PM *

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