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.

Limited data type and modbus problem


Nigel Feb 13, 2014 09:26 PM

Hi,


I am using a CR3000 connected to a S::CAN G series UV spectrometer where I'm trying to control, take measures and return data results in an event based system.

It connects via a propritory S::CAN "Connect" interface which supplies power(12v) and allows connection via USB(laptop) and RS485(logger).
Protocol is Modbus.

I am using a MD485 interface.

For testing I have public floats for all inputs of the modbus command to test returns and run the following.

If SCANRegistery = true Then
Timer (2,mSec,2)
ModbusMaster (RC,ComSDC7,38400,BusAddress,BusFunction,Variable,RegStartAddress,Length,3,100,Option)

SCANRegistery = false
Elapsed(2) = Timer (2,mSec,4)
EndIf

Although I am held by NDA about specfific registry entry names and numbers, I can descibe the problem I am having and how it relates to CRbasic.

I have a problem with data types, or specifically the limited data types of CRbasic; Float,long,Boolean and String.

The device input registers 16bit RO, holding registers RW use various data types

Char[x], string, x bytes
Bitmask, bitmask of 16 units, 2 bytes
Int16, signed 16 bit integer, 2 bytes
Uint16 unsigned 16 bit integer, 2 bytes
Float IEEE754 floating point, 4 bytes
enum, enum type, 2 bytes
timestamp(TAI64N), timestamp, 6 bytes

Because CRbasic has only 4 types, I cannot access, request or switch anything but the Floats contained in the registers.

I specfifically need enum to control switching 0,1 and 0,1,2
which control meausrement, modes such as on/off on/off/auto

I saw a note about firmware OS27(which is what my CR3000 is at) has issues with error codes not reporting, which I think I need, but I need help on creating enum in CRbasic or ways to fool the device that it is a an enum being sent/ retrieved.

thanks
Nigel


Sam Jan 21, 2018 05:21 AM

 

Public Result(10) As Long
Public single As Float
Public integer As Long
Public temp(5) As Long
Public str As String * 20

BeginProg
  Scan (10,Sec,0,0)

    'Float IEEE754 floating point, 4 bytes
    'READ
    ModbusMaster (Result(1),Com1,115200,1,3,single,1,1,1,100,2)
    'WRITE
    ModbusMaster (Result(2),Com1,115200,1,16,single,1,1,1,100,2)

    'Int16, signed 16 bit integer, 2 bytes
    'READ
    ModbusMaster (Result(3),Com1,115200,1,3,integer,1,1,1,100,1)
    'WRITE
    ModbusMaster (Result(4),Com1,115200,1,16,integer,1,1,1,100,1)

    'Bitmask, bitmask of 16 units, 2 bytes
    'Uint16 unsigned 16 bit integer, 2 bytes
    'enum, enum type, 2 bytes
    'All of these are unsigned 16 bit integers
    'READ
    ModbusMaster (Result(6),Com1,115200,1,3,integer,1,1,1,100,3)
    'WRITE
    ModbusMaster (Result(7),Com1,115200,1,16,integer,1,1,1,100,3)

    'Char[x], string, x bytes
    'READ
    'Read modbus registers containing ASCII characters
    'into array of LONG. Then move the bytes of the array
    'into a local STRING variable.
    ModbusMaster (Result(8),Com1,115200,1,3,temp,1,5,1,100,2)
    MoveBytes (str,0,temp,0,20)
   
    'Char[x], string, x bytes
    'WRITE
    'Move bytes of local STRING variable into array of LONG.
    'Write modbus registers with data in array of LONG.
    MoveBytes (temp,0,str,0,20)
    ModbusMaster (Result(9),Com1,115200,1,16,temp,1,5,1,100,2)

  NextScan
EndProg

 

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