Index: Makefile =================================================================== RCS file: /cvs/emc2/src/Makefile,v retrieving revision 1.188 diff -u -p -u -r1.188 Makefile --- Makefile 3 Jan 2007 17:27:48 -0000 1.188 +++ Makefile 4 Jan 2007 13:38:17 -0000 @@ -56,7 +56,7 @@ SUBDIRS := \ \ emc/usr_intf/axis \ emc/usr_intf emc/nml_intf emc/task emc/iotask emc/kinematics emc/canterp \ - emc/motion emc/ini emc/rs274ngc emc \ + emc/motion emc/ini emc/rs274ngc emc emc/qt_dro \ \ module_helper \ \ --- /dev/null 2007-01-03 10:35:48.551353088 -0600 +++ emc/qt_dro/qtdro.cc 2007-01-04 07:36:18.000000000 -0600 @@ -0,0 +1,211 @@ +/******************************************************************** +* +* Description: qtdro.cc +* A simple demo for NML and Qt to display the XYZ commanded coordinates +* of a running EMC. +* +* +* Author: Paul Corner +* License: GPL Version 2 +* System: Linux +* +* Copyright (c) 2005 Paul Corner All rights reserved. +* +* Last change: +* $Revision: 1.2 $ +* $Author: paul_c $ +* $Date: 2005/03/16 11:11:07 $ +********************************************************************/ + +#include +#include +#include +#include +#include +#include +#include "qstring.h" +#include "qlayout.h" +#include "qfont.h" + +#include "qtdro.hh" + +#include "rcs.hh" // etime() +#include "emc.hh" // EMC NML +#include "emcglb.h" // EMC_NMLFILE, TRAJ_MAX_VELOCITY, TOOL_TABLE_FILE +#include "emccfg.h" // DEFAULT_TRAJ_MAX_VELOCITY +#include "inifile.hh" // INIFILE + +#define UPDATE_MSECS 250 + +// the NML channels to the EMC task +static RCS_STAT_CHANNEL *emcStatusBuffer = 0; +EMC_STAT *emcStatus = 0; + +int main(int argc, char* argv[]) +{ + Inifile inifile; + const char *inistring; + /* Set libnml to print all diagnostics to stdout */ + set_rcs_print_destination(RCS_PRINT_TO_STDOUT); + + /* use the libemc.a functions to check the args are correct + This keeps the syntax the same across all apps. */ + if (0 != emcGetArgs(argc, argv)) { + rcs_print_error("error in argument list\n"); + return -1; + } + /* Try to open the ini file - Return if not found. */ + if (-1 == inifile.open(EMC_INIFILE)) { + rcs_print_error("No file found %s\n", EMC_INIFILE); + return -1; + } + /* Extract the name of the nml config...*/ + if (NULL != (inistring = inifile.find("NML_FILE", "EMC"))) { + strcpy(EMC_NMLFILE, inistring); + } else { + /* Exit if not found. */ + return -1; + } + + /* Now use the NML_FILE to open the emcStatus channel to EMC... */ + if (emcStatusBuffer == 0) { + /* Connect to the emcStatus buffer as the xemc process - We really should think + about changing the process name to something more generic.. hmi or gui perhaps ? */ + emcStatusBuffer = new RCS_STAT_CHANNEL(emcFormat, "emcStatus", "xemc", EMC_NMLFILE); + if (! emcStatusBuffer->valid() || EMC_STAT_TYPE != emcStatusBuffer->peek()) { + /* If an error occured, exit now. It probably means EMC is not + running or the NML_FILE is not the right one. */ + delete emcStatusBuffer; + return -1; + } else { + /* Having opened the NML channel, get a pointer to the stored + data - This gets used as the base address for a "struct" */ + emcStatus = (EMC_STAT *) emcStatusBuffer->get_address(); + } + } + + /* Now for the Qt stuff to set up the widgets and + display the data.. */ + + QApplication app(argc, argv); + + /* This be the top level window that contains the + axis readouts.. */ + QWidget* widget = new QWidget; + + QtDisplay* readout = new QtDisplay(widget, "DRO"); + + app.setMainWidget(readout); + /* Now get the show on the road */ + readout->show(); + /* And pass execution over to Qt. */ + int ret = app.exec(); + + /* If we get here, the show is over. */ + return ret; +} + +/*################################################## + + Qt Code - Want to use QLCDNumber but force it to + use the position data passed via NML. To do this + we need set up a periodic timer that calls the + NML update function before reading the data. + Once the data has been accessed, it then has to + be formatted with a fixed decimal point. + +##################################################*/ + +//AxisNumber::AxisNumber(int digit, QWidget *parent, const char* name):QLCDNumber(digit, parent, name) +AxisNumber::AxisNumber(QWidget *parent, const char* name):QLineEdit(parent, name) +{ + /* Constructor for Axis readout - Derived from the LCD Qt class. */ + axis = name[0]; /* Record the axis name for use in the digitUpdate function */ + QFont font("Helvetica", 48); + setFont (font); + setAlignment(AlignRight); + + /* Start a timer with a 100mSec period - sshot is FALSE so + it restarts on time-out automatically. */ + timer.start(UPDATE_MSECS, FALSE); + /* Connect the timeout signal to the digitUpdate function */ + connect(&timer, SIGNAL(timeout()), this, SLOT(digitUpdate())); +} + +AxisNumber::~AxisNumber(void) +{ + /* Destructor - Don't need to stop the timer or destroy it as the Qt system takes + care of the cleanup, but we do it just to keep things neat & tidy. */ + timer.stop(); +} + +void AxisNumber::digitUpdate(void) +{ + + /* This is the function that does all the hard work - What little there is ! */ + QString str; + + if (emcStatusBuffer == 0) { + /* Return if the status buffer is not available. */ + return; + } + + /* Grab a snapshot of the latest status buffer - Note: This is NOT + the shm buffer used by emcmot. It is a copy of the status NML + buffer. See emc.hh Classes EMC_TASK_STAT, EMC_MOTION_STAT + and EMC_IO_STAT - These are all members of the EMC_STAT class.*/ + emcStatusBuffer->peek(); + + switch (axis){ + case 'X': + /* Just as a sample, we use the absolute commanded position. */ + str = QString("%L1") + .arg(emcStatus->motion.traj.position.tran.x, 0, 'f', 4); + break; + case 'Y': + str = QString("%L1") + .arg(emcStatus->motion.traj.position.tran.y, 0, 'f', 4); + break; + case 'Z': + str = QString("%L1") + .arg(emcStatus->motion.traj.position.tran.z, 0, 'f', 4); + break; + default: + /* Display zero if the axis name is void...*/ + str = "0.0000"; + break; + } + /* This function displays the formatted data in the correct widget */ + setText(str); +} + +QtDisplay::QtDisplay(QWidget *parent, const char *name):QDialog(parent, name) +{ + QGridLayout* layout = new QGridLayout; + + /* In this version, we pack the digit readout in a + layout box - This saves us from having to manage + resizing events */ + AxisNumber* X = new AxisNumber(this,"X"); // X display + X->setReadOnly(TRUE); // Set to ReadOnly + X->setFrame(FALSE); // and no frame to the box + + AxisNumber* Y = new AxisNumber(this,"Y"); + Y->setReadOnly(TRUE); + Y->setFrame(FALSE); + + AxisNumber* Z = new AxisNumber(this,"Z"); + Z->setReadOnly(TRUE); + Z->setFrame(FALSE); + + /* Pack the dislay boxes.. */ + + layout->addWidget(X, 0, 0); + layout->addWidget(Y, 1, 0); + layout->addWidget(Z, 2, 0); + + QHBoxLayout* mainLayout = new QHBoxLayout(this); + mainLayout->setMargin(11); + mainLayout->setSpacing(6); + mainLayout->addLayout(layout); +} --- /dev/null 2007-01-03 10:35:48.551353088 -0600 +++ emc/qt_dro/qtdro.hh 2007-01-03 11:24:43.000000000 -0600 @@ -0,0 +1,61 @@ +/******************************************************************** +* +* Description: qtdro.hh +* A simple demo for NML and Qt to display the XYZ commanded coordinates +* of a running EMC. +* +* +* Author: Paul Corner +* License: GPL Version 2 +* System: Linux +* +* Copyright (c) 2005 Paul Corner All rights reserved. +* +* Last change: +* $Revision: 1.2 $ +* $Author: paul_c $ +* $Date: 2005/03/16 11:11:07 $ +********************************************************************/ +#ifndef QTDRO_HH +#define QTDRO_HH + +#include +#include +#include +#include +#include +#include +#include +#include + +//class AxisNumber:public QLCDNumber +class AxisNumber:public QLineEdit +{ + Q_OBJECT + + public: +// AxisNumber(int digit, QWidget *parent, const char* name); + AxisNumber(QWidget *parent, const char* name); + ~AxisNumber(void); + private: + /* The first char from name - This is used + to identify which axis is being updated. */ + char axis; + /* Periodic timer to trigger the updates */ + QTimer timer; + + private slots: + /* The private function that gets called on timeout + to update the LCD widget - One per axis */ + void digitUpdate(void); +}; + +class QtDisplay: public QDialog +{ + Q_OBJECT + + public: + QtDisplay(QWidget *parent, const char *name); +}; + +#endif --- /dev/null 2007-01-03 10:35:48.551353088 -0600 +++ emc/qt_dro/Submakefile 2007-01-04 07:37:31.000000000 -0600 @@ -0,0 +1,7 @@ +emc/qt_dro/moc_qtdro.cc: emc/qt_dro/qtdro.hh + moc -o $@ $< + +../bin/qtdro: emc/qt_dro/qtdro.cc emc/qt_dro/moc_qtdro.cc ../lib/libemc.a ../lib/libnml.so + $(CXX) $(CXXFLAGS) -I/usr/include/qt3 -o $@ $^ -lqt-mt + +userspace: ../bin/qtdro