QDaq  0.2.6
Qt-based Data Aqcuisition
 All Classes Functions Variables Typedefs Enumerations Enumerator Properties Groups Pages
Public Slots | Public Member Functions | Protected Member Functions | Properties | List of all members
QDaqDevice Class Reference

A class representing a DAQ device. More...

#include <QDaqDevice.h>

Inheritance diagram for QDaqDevice:
Inheritance graph
[legend]
Collaboration diagram for QDaqDevice:
Collaboration graph
[legend]

Public Slots

bool on ()
 Try to bring the device online and return true if succesfull.
 
void off ()
 Bring the device offline.
 
void clear ()
 Call QDaqInterface::clear_port(). Depends on type of interface.
 
int statusByte ()
 Call QDaqInterface::readStatusByte(). Return value depends on type of interface.
 
void trigger ()
 Trigger the device (Must be supported by the interface, e.g. GPIB)
 
Functions for message based communication.
int write (const QString &msg)
 Write a string message to the device. Return number of characters written.
 
bool write (const QStringList &msgs)
 Write a list of string message to the device. Return true if succesfull.
 
int writeBytes (const QByteArray &msg)
 Write a byte array to the device. Return number of bytes written.
 
QString read ()
 Read a string from the device. On error return empty string and emit QDaqError.
 
QByteArray readBytes ()
 Read bytes from the device. On error return empty array and emit QDaqError.
 
QString query (const QString &msg)
 Send message and return the answer, ie, read and write in one command.
 
Functions for register based communication (eg, MODBUS).

A register holds a 16-bit unsigned integer.

int write (int reg, int val)
 Write a value at a device register. More...
 
int write (int start_reg, int n, const QByteArray &msg)
 Write to a number of consecutive device registers. More...
 
int read (int reg)
 Return the value of the device register at address reg.
 
QByteArray read (int reg, int n)
 Read a number of consecutive device registers. More...
 
- Public Slots inherited from QDaqObject
QString errorBacktrace (int maxItems=10) const
 Print a backtrace of recent errors in this QDaqObject.
 
QString path () const
 Return the object's path in the QDaq tree. More...
 
QString objectTree () const
 Output in a string the object hierarchy beneath this object.
 
QString listProperties () const
 List the objects properties.
 
QString listFunctions () const
 List the objects scriptable functions.
 
QDaqObjectparent () const
 
QDaqObjectList children () const
 Return a list of children of this object.
 
bool hasChildren () const
 Returns true if the object has children.
 
QDaqObjectappendChild (QDaqObject *obj)
 Adds a new child QDaqObject, as the last child and returns a pointer to it.
 
QDaqObjectinsertBefore (QDaqObject *newobj, QDaqObject *existingobj)
 Adds a new child QDaqObject, before an existing child and returns a pointer to it.
 
QDaqObjectclone ()
 Clone a QDaqObject with its child objects.
 
QDaqObjectremoveChild (QDaqObject *obj)
 Remove a child and return a pointer to it.
 
QDaqObjectreplaceChild (QDaqObject *newobj, QDaqObject *oldobj)
 Replace a child and return a pointer to the old child.
 
QDaqObjectfindChild (const QString &name) const
 Find the first child QDaqObject with objectName equal to name.
 

Public Member Functions

Q_INVOKABLE QDaqDevice (const QString &name)
 QDaqDevice constructor. More...
 
virtual void detach ()
 Detach this QDaqObject from the QDaq tree. More...
 
int write (const char *msg, int len)
 Write a C-string message to the device, returns the number of characters written.
 
int write (const char *msg)
 Write a zero terminated C-string message to the device, returns the number of characters written.
 
int write (const QByteArray &msg)
 Write a byte array to the device, returns the number of bytes written.
 
bool write (const QList< QByteArray > &msglist)
 Write a list byte arrays to the device, returns true if succesfull.
 
- Public Member Functions inherited from QDaqJob
Q_INVOKABLE QDaqJob (const QString &name)
 QDaqJob constructor. More...
 
virtual void attach ()
 Attach this QDaqObject to the QDaq tree. More...
 
QDaqLooptopLoop () const
 Returns the top level loop that this job belongs to.
 
QDaqLooploop () const
 Returns the loop that this job belongs to.
 
virtual QDaqScriptEngine * loopEngine () const
 Returns the QDaqScriptEngine of the top level loop.
 
- Public Member Functions inherited from QDaqObject
Q_INVOKABLE QDaqObject (const QString &name)
 Construct a QDaqObject with a name. More...
 
bool isAttached () const
 Returns true is this object is attached to the QDaq tree.
 

Protected Member Functions

virtual bool arm_ ()
 Performs internal initialization for the job. More...
 
bool throwIfOffline ()
 Thow QDaqError and script error if called with device offline.
 
bool throwIfOnline ()
 Thow QDaqError and script error if called with device online.
 
virtual bool setOnline_ (bool on)
 Implements specific procedures for bringing device on- or offline. More...
 
- Protected Member Functions inherited from QDaqJob
virtual void disarm_ ()
 Performs internal de-initialization. More...
 
bool setArmed (bool on)
 Arms or disarms a job. More...
 
virtual bool exec ()
 Called when the job is executed. More...
 
virtual bool run ()
 This function performs the actual task of this QDaqJob. More...
 
- Protected Member Functions inherited from QDaqObject
void pushError (const QString &type, const QString &descr=QString()) const
 Push an error in the error queue.
 
void throwScriptError (const QString &msg) const
 Throw a script error with message msg.
 
bool checkName (const QString &name) const
 Check if name is a legal name for an QDaqObject. More...
 
virtual void writeh5 (H5::Group *g, QDaqH5File *f) const
 Write contents of the object to a H5 group. More...
 
virtual void readh5 (H5::Group *g, QDaqH5File *f)
 Read contents of the object from a H5 group. More...
 

Properties

uint bufferSize
 Size of the internal communication buffer.
 
int address
 Device address (depends on type of interface).
 
bool online
 True when device is online.
 
int eot
 End of transmition code.
 
int eos
 End of string code.
 
QDaqObject interface
 The underlying QDaqInterface used for communication.
 
- Properties inherited from QDaqJob
bool armed
 True if job is armed. More...
 
QString runCode
 Script code executed by the job at each repetition. More...
 
QString armCode
 Script code executed by the job in the arming face. More...
 
QString disarmCode
 Script code executed by the job in the dis-arming face. More...
 

Additional Inherited Members

- Signals inherited from QDaqObject
void propertiesChanged ()
 Fired when object properties have changed.
 
void updateWidgets ()
 Fired when widgets need update.
 
- Static Public Member Functions inherited from QDaqObject
static QDaqRootroot ()
 Obtain a pointer to the one-and-only QDaqRoot object.
 
static QDaqObjectfromPath (const QString &path)
 Return a pointer to an object given its full path in the QDaq tree. More...
 
- Public Attributes inherited from QDaqObject
QMutex comm_lock
 A recursive mutex for synching thread access to this object.
 

Detailed Description

A class representing a DAQ device.

It is used in combination with a QDaqInterface in order to communicate with the device.

In order to start communications with a device, first instantiate the interface and device objects, asign the interface to the device and then open() the interface and bring the device online with on().

QDaqRoot qdaq;
QDaqTcpip* tcp = new QDaqTcpip("tcp",'192.168.1.6',5000);
QDaqDevice* dev = new QDaqDevice("dev");
qdaq.appendChild(tcp);
qdaq.appendChild(dev);
dev->setInterface(tcp);
if (tcp->open() && dev->on())
cout << "Device online!";
else
cout << qdaq.errorBacktrace();

After the device is online the communication functions can be used either for message based or register based communication.

Definition at line 44 of file QDaqDevice.h.

Constructor & Destructor Documentation

QDaqDevice::QDaqDevice ( const QString &  name)
explicit

QDaqDevice constructor.

Parameters
nameThe QDaqObject name.

Definition at line 3 of file QDaqDevice.cpp.

Member Function Documentation

bool QDaqDevice::arm_ ( )
protectedvirtual

Performs internal initialization for the job.

It is called by the setArmed() function.

This function can be reimplemented to perform specific initialization for a job. The parent class arm_() function should be called afterwards.

In the default implementation, if a loopEngine() exists the script code is checked against the script engine for errors.

If initialization is sucessfull it returns true, otherwise the function returns false.

Reimplemented from QDaqJob.

Definition at line 127 of file QDaqDevice.cpp.

void QDaqDevice::detach ( )
virtual

Detach this QDaqObject from the QDaq tree.

This function is called just before the object becomes detached from the QDaq tree.

In the base class implementation it first calls detach() for each child QDaqObject and then signal root that the object is removed from the qdaq tree.

Subclasses may reimplement this function to perform needed actions before detaching.

Reimplemented from QDaqJob.

Definition at line 16 of file QDaqDevice.cpp.

QByteArray QDaqDevice::read ( int  reg,
int  n 
)
slot

Read a number of consecutive device registers.

Parameters
regStarting register address.
nNumber of registers.
Returns
Register data in a byte array of length 2*n.

Definition at line 230 of file QDaqDevice.cpp.

bool QDaqDevice::setOnline_ ( bool  on)
protectedvirtual

Implements specific procedures for bringing device on- or offline.

This function is called to change the online property.

Reimplement this function to define additional procedures needed in devices classes that inherit QDaqDevice.

In the base class implementation, QDaqInterface::open_port() is called with the address passed as the port number. If this returns true, then QDaqInterface::clear_port() is also called.

Parameters
onTrue for making device online, false for offline.
Returns
True if succesful.

Definition at line 41 of file QDaqDevice.cpp.

int QDaqDevice::write ( int  reg,
int  val 
)
slot

Write a value at a device register.

Parameters
regRegister address.
valValue to write. Will be truncated to 16-bit (max 0xFFFF).
Returns
Non-zero on success.

Definition at line 179 of file QDaqDevice.cpp.

int QDaqDevice::write ( int  start_reg,
int  n,
const QByteArray &  msg 
)
slot

Write to a number of consecutive device registers.

Parameters
start_regStarting register address.
nNumber of registers.
msgBuffer containing data to write. Must hold at least 2*n bytes.
Returns
Bytes written.

Definition at line 187 of file QDaqDevice.cpp.


The documentation for this class was generated from the following files: