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: Unable to access values in array


rwc Jun 30, 2017 07:25 PM

Hi:

I'm extracting some data from Modbus registers in a wave sensor, and have hit a puzzling roadblock.  The data in the registers is a mix of floats and integers, so I have been pulling everything out as integers and putting together values depending on their format.  

By way of explanation, I've put a screencap of the connect screen with the variables here:

The PosDate variable was initialized as a Long, and obtained with ModbusMaster: 

ModbusMaster(ModbusResult,COM2,9600,1,4,PosDate,12290,9,1,50,3)

 The first two rows of PosDate are latitude, which is a float.  So I put it together from the integers in PosDate(1) and (2): 

MoveBytes(Lat,0,HexToDec(Hex(PosDate(1)) + Hex(PosDate(2))),0,4)

 i.e. 17010 = 0x4272, 43778 = 0xAB02;  4272AB02 = 60.667

And that's worked as it ought to, as you can see in the image.

The register I'm working on now is MStatus,  that's registers with information about the magnetometer, it has 14 registers.  I've pulled those out with the same Modbus settings, but obviously a different start register: 

ModbusMaster(ModbusResult,COM2,9600,1,4,MStatus,12358,14,1,100,3)

 ...and it is populating MStatus with the integers as it ought to.  The values look right.

My problem is that I am not able to pull out the values from the MStatus array.  When I run the following:

 

Public test As Long
test = MStatus(1)

 

test returns zero (as you can see in the linked image).  I've tried initializing 'test' as different variable types without success, and verified that MStatus is initialized just like PosDate ("Public MStatus(14) As Long"). The logger is not returning any errors,  and has lots of memory available.  A stripped-down test program with no other variables has the same problem.  I expect it's something trivial, but my searching around so far has not been helpful.  Anyone have any ideas of what I'm missing?

Thanks, Rob

 


JDavis Jun 30, 2017 07:27 PM

It would be much easier to just make multiple calls to ModbusMaster. You would just have to use the option in ModbusMaster to handle the data types, and not need to worry about MoveBytes.


rwc Jun 30, 2017 07:32 PM

I started off trying that, but it hasn't worked for me.  Those particular registers are a mix of floats and 32 bit integers.  When I try to pull off everything as just floats or integers I get an error - that's the case through the CR1000 or my ModBus test program on my PC.  The offsets of the various data also varies.


JDavis Jun 30, 2017 08:00 PM

 Sometimes, you will use many calls to ModbusMaster for talking to a single device. In this piece from a recent program, I grabbed two different sections of floating point registers and 1 set of integers.

 ModbusMaster (MeterCommState,MeterSocket,9600,1,3,MeterBlock1(),1000,15,3,10,2)
 ModbusMaster (MeterCommState,MeterSocket,9600,1,3,MeterBlock2(),1500,9,3,10,2)
 ModbusMaster (MeterCommState,MeterSocket,9600,1,3,MeterStatus,4501,1,3,10,3)

 


rwc Jun 30, 2017 08:13 PM

That would definitely be the way to go.  Unfortunately for me, this particular sensor does not support polling individual registers - each group of registers must be requested as a complete group.


JDavis Jun 30, 2017 10:04 PM

It is important to note the the CR1000 uses big endian byte order. A CR300 uses little endian byte order. If you need to reverse the order of bytes, there is an example in the help for MoveBytes.

 Take a look at this simple test of MoveBytes.

Public Integers(3) As Long = {&h000005AC, &h3F9DF3B6, &h0001E240}
Public FloatingPoint As Float

BeginProg
  Scan (1,Sec,0,0)
    MoveBytes (FloatingPoint,0,Integers(2),0,4)
  NextScan
EndProg

 It is easiest to bring all the registers in as 32 bit integers, then move the floats out to their variables. 


rwc Jun 30, 2017 10:28 PM

Hi:  I'm using a CR1000, and the wave sensor also uses Big Endian.  I'm able to retrieve the data from every other register and work with it in arrays but the Mstatus one.  I'm baffled why I can see the numbers in the variable in the connect screen, but I cannot assign them to a variable.

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