qpidctrl  0.7.1
Public Slots | Signals | Public Member Functions | Public Attributes | Private Member Functions | Private Attributes | List of all members
QWatlowDevice Class Reference

#include <qwatlowdevice.h>

Inheritance diagram for QWatlowDevice:
Inheritance graph

Public Slots

void timerEvent (QTimerEvent *)
 
void onReadyRead ()
 
void onDsrChanged (bool status)
 
void onTimeout ()
 
void start ()
 
void stop ()
 
void setParameter (QString param, double val)
 
void getParameter (QString param)
 
void pushCommand (QString cmd)
 
void sendCommand (QString cmd)
 
void readoutInitial ()
 
void readoutPolling ()
 
void readoutTimeout ()
 
void changeSetPoint (double setPoint)
 
void changeRampRate (double rate)
 
void changeProportional (double prop)
 
void changeIntegral (double integ)
 
void changeDerivative (double deriv)
 
void enable (bool on)
 
bool canAutoTune ()
 
void autoTune ()
 
void onGraphingTimeout ()
 
void onLoggingTimeout ()
 
- Public Slots inherited from QPidDevice
void printMessage (QString msg, QDateTime ts=QDateTime::currentDateTime())
 
virtual void readoutInitial ()=0
 
virtual void readoutPolling ()=0
 
virtual void readoutTimeout ()=0
 
virtual void sendCommand (QString cmd)=0
 
virtual void changeSetPoint (double setPoint)=0
 
virtual void changeRampRate (double rate)=0
 
virtual void changeProportional (double prop)=0
 
virtual void changeIntegral (double integ)=0
 
virtual void changeDerivative (double deriv)=0
 
virtual void enable (bool on)=0
 
virtual void loopEnable (bool on)
 
virtual bool canAutoTune ()=0
 
virtual void autoTune ()=0
 
virtual void readyRead ()
 
virtual void onGraphingTimeout ()
 
virtual void onLoggingTimeout ()
 
virtual void start ()
 
virtual void stop ()
 
virtual void restart ()
 
virtual void changeRunState (int state)
 
virtual void changePollingInterval (double interval)
 
virtual void changeTimeoutInterval (double interval)
 
virtual void changeGraphingInterval (double interval)
 
virtual void changeLoggingInterval (double interval)
 
virtual void write (QString cmd)
 
virtual QString readLine (int sz=0)
 
virtual int waitForReadyRead (int tmout=0)
 
virtual int bytesAvailable ()
 
virtual int canReadLine ()
 

Signals

void newParameterValue (QString param, double value)
 
- Signals inherited from QPidDevice
void inputChannelChanged (QString name, QString units)
 
void outputChannelChanged (QString name, QString units)
 
void loggedChannelNames (QStringList names)
 
void loggedChannelValues (QcepDoubleList values)
 
void graphedChannelNames (QStringList names)
 
void graphedChannelValues (QcepDoubleList values)
 

Public Member Functions

 QWatlowDevice (QPidControllerWPtr ctrl, QcepSettingsSaverWPtr saver, QString deviceName)
 
virtual void writeSettings (QSettings *set, QString section)
 
virtual void readSettings (QSettings *set, QString section)
 
void configurationDialog ()
 
void writeOutput (QString cmd)
 
- Public Member Functions inherited from QPidDevice
 QPidDevice (QPidControllerWPtr ctrl, QcepSettingsSaverWPtr saver, int deviceType, QString deviceName, int pollIntervalMsec, int timeoutMsec)
 
virtual ~QPidDevice ()
 
QPidControllerWPtr controller () const
 
double cK2K (double cK)
 
double K2cK (double K)
 
double K2degC (double K)
 
double degC2K (double degC)
 
void updateConnected (double newConnected)
 
void updateTemperature (double newTemperature)
 
void updateRampPoint (double newRampPoint)
 
void updateOutputLevel (double newOutputLevel)
 
void resetTimeout ()
 
void pushCommand (QPidDeviceCommandPtr cmd)
 
void issueCommand ()
 
void completeCommand (QByteArray response)
 
void flushCommandQueue ()
 
int slowly (int msec)
 
QPidCommPortPtr commPort ()
 

Public Attributes

QPidObjectNamer m_ObjectNamer
 

Private Member Functions

void issueCommand ()
 
void completeCommand ()
 
void abandonCommand ()
 
QString errorMessage (int val)
 

Private Attributes

QStringList m_CommandQueue
 
QTimer m_CommandTimer
 
QString m_Parameter
 
QString m_Reply
 
QWatlowDeviceDialogPtr m_DeviceDialog
 
int m_TimerID
 

Additional Inherited Members

- Public Types inherited from QPidDevice
enum  {
  NoDevice = 0, WatlowDevice = 1, PTC10Device = 2, LakeshoreDevice = 3,
  CryostreamDevice = 4, EurothermDevice = 5
}
 
- Static Public Member Functions inherited from QPidDevice
static QString deviceTypeName (int typ)
 
static QString deviceLongTypeName (int typ)
 
static int deviceTypeCount ()
 
- Properties inherited from QPidDevice
int deviceType
 
QString deviceTypeName
 
QString deviceLongTypeName
 
QString deviceName
 
int runState
 
double pollingInterval
 
double timeoutInterval
 

Detailed Description

Definition at line 16 of file qwatlowdevice.h.

Constructor & Destructor Documentation

QWatlowDevice::QWatlowDevice ( QPidControllerWPtr  ctrl,
QcepSettingsSaverWPtr  saver,
QString  deviceName 
)
explicit

Definition at line 7 of file qwatlowdevice.cpp.

7  :
8  QPidDevice(ctrl, saver, WatlowDevice, deviceName, 1000, 2000),
9  m_ObjectNamer(this, "watlow"),
10  m_TimerID(0)
11 {
12 }
QPidDevice(QPidControllerWPtr ctrl, QcepSettingsSaverWPtr saver, int deviceType, QString deviceName, int pollIntervalMsec, int timeoutMsec)
Definition: qpiddevice.cpp:9
QString deviceName
Definition: qpiddevice.h:133
QPidObjectNamer m_ObjectNamer
Definition: qwatlowdevice.h:68

Member Function Documentation

void QWatlowDevice::abandonCommand ( )
private

Definition at line 199 of file qwatlowdevice.cpp.

References issueCommand(), m_CommandQueue, and m_CommandTimer.

Referenced by onTimeout().

200 {
201  if (m_CommandQueue.length() > 0) {
202  m_CommandTimer.stop();
203 
204  QString cmd = m_CommandQueue.takeFirst();
205 
206  issueCommand();
207  }
208 }
QStringList m_CommandQueue
Definition: qwatlowdevice.h:71
QTimer m_CommandTimer
Definition: qwatlowdevice.h:72
void QWatlowDevice::autoTune ( )
slot

Definition at line 317 of file qwatlowdevice.cpp.

References setParameter().

318 {
319  setParameter("AUT", 1);
320 }
void setParameter(QString param, double val)
bool QWatlowDevice::canAutoTune ( )
slot

Definition at line 312 of file qwatlowdevice.cpp.

313 {
314  return true;
315 }
void QWatlowDevice::changeDerivative ( double  deriv)
slot

Definition at line 303 of file qwatlowdevice.cpp.

304 {
305 }
void QWatlowDevice::changeIntegral ( double  integ)
slot

Definition at line 299 of file qwatlowdevice.cpp.

300 {
301 }
void QWatlowDevice::changeProportional ( double  prop)
slot

Definition at line 295 of file qwatlowdevice.cpp.

296 {
297 }
void QWatlowDevice::changeRampRate ( double  rate)
slot

Definition at line 285 of file qwatlowdevice.cpp.

References setParameter().

286 {
287  if (rate <= 0) {
288  setParameter("RP", 0);
289  } else {
290  setParameter("RP", 2);
291  setParameter("RATE", rate);
292  }
293 }
void setParameter(QString param, double val)
void QWatlowDevice::changeSetPoint ( double  setPoint)
slot

Definition at line 280 of file qwatlowdevice.cpp.

References setParameter().

281 {
282  setParameter("SP1", setPoint);
283 }
void setParameter(QString param, double val)
void QWatlowDevice::completeCommand ( )
private

Definition at line 155 of file qwatlowdevice.cpp.

References QPidDevice::controller(), errorMessage(), issueCommand(), m_CommandQueue, m_CommandTimer, m_Reply, newParameterValue(), and QPidDevice::printMessage().

Referenced by onReadyRead().

156 {
157  if (m_CommandQueue.length() > 0) {
158  m_CommandTimer.stop();
159 
160  QString cmd = m_CommandQueue.takeFirst();
162 
163  if (cmd[0] == '?') {
164  QString parm = cmd.mid(2);
165  bool ok;
166  double val = m_Reply.mid(2).toDouble(&ok);
167 
168  if (ok) {
169  if (parm == "SP1") {
170  if (ctl) {
171  ctl->set_RampPoint(val);
172  }
173  } else if (parm == "PWR") {
174  if (ctl) {
175  ctl->set_OutputLevel(val);
176  }
177  } else if (parm == "C1") {
178  if (ctl) {
179  ctl->set_Temperature(val);
180  }
181  } else if (parm == "RATE") {
182  if (ctl) {
183  ctl->set_RampRate(val);
184  }
185  } else if (parm == "ER2") {
186  if (val != 0) {
187  printMessage(tr("ER2 = %1 : %2").arg(val).arg(errorMessage(val)));
188  }
189  }
190 
191  emit newParameterValue(cmd.mid(2), val);
192  }
193  }
194 
195  issueCommand();
196  }
197 }
QStringList m_CommandQueue
Definition: qwatlowdevice.h:71
QPidControllerWPtr controller() const
Definition: qpiddevice.cpp:316
QString errorMessage(int val)
QSharedPointer< QPidController > QPidControllerPtr
QTimer m_CommandTimer
Definition: qwatlowdevice.h:72
void printMessage(QString msg, QDateTime ts=QDateTime::currentDateTime())
Definition: qpiddevice.cpp:321
QString m_Reply
Definition: qwatlowdevice.h:74
void newParameterValue(QString param, double value)
void QWatlowDevice::configurationDialog ( )
virtual

Implements QPidDevice.

Definition at line 268 of file qwatlowdevice.cpp.

References m_DeviceDialog.

269 {
270  if (m_DeviceDialog == NULL) {
272  }
273 
274  if (m_DeviceDialog) {
275  m_DeviceDialog->show();
276  m_DeviceDialog->raise();
277  }
278 }
QSharedPointer< QWatlowDeviceDialog > QWatlowDeviceDialogPtr
QSharedPointer< QWatlowDevice > QWatlowDevicePtr
QWatlowDeviceDialogPtr m_DeviceDialog
Definition: qwatlowdevice.h:75
void QWatlowDevice::enable ( bool  on)
slot

Definition at line 307 of file qwatlowdevice.cpp.

References QPidDevice::printMessage().

308 {
309  printMessage("<i>Enable not implemented</i>");
310 }
void printMessage(QString msg, QDateTime ts=QDateTime::currentDateTime())
Definition: qpiddevice.cpp:321
QString QWatlowDevice::errorMessage ( int  val)
private

Definition at line 220 of file qwatlowdevice.cpp.

Referenced by completeCommand().

221 {
222  switch (code) {
223  case 0: return "No error";
224  case 1: return "Transmit buffer overflow";
225  case 2: return "Receive buffer overflow";
226  case 3: return "Framing error";
227  case 4: return "Overrun error";
228  case 5: return "Parity error";
229  case 6: return "Talking out of turn";
230  case 7: return "Invalid reply error";
231  case 8: return "Noise error";
232  case 20: return "Command not found";
233  case 21: return "Prompt not found";
234  case 22: return "Incomplete command line";
235  case 23: return "Invalid character";
236  case 24: return "Number of chars. overflow";
237  case 25: return "Input out of limit";
238  case 26: return "Read only command";
239  case 27: return "Write allowed only";
240  case 28: return "Prompt not active";
241  case 30: return "Request to RUN invalid";
242  case 31: return "Request to HOLD invalid";
243  case 32: return "Command invalid in RUN Mode";
244  case 33: return "Command invalid in HOLD Mode";
245  case 34: return "Output 3 is not an Event";
246  case 35: return "Output 4 is not an Event";
247  case 38: return "Asterisk not allowed";
248  case 39: return "Infinite loop error";
249  default:
250  return "Unkown Error";
251  }
252 }
void QWatlowDevice::getParameter ( QString  param)
slot

Definition at line 215 of file qwatlowdevice.cpp.

References pushCommand().

Referenced by timerEvent().

216 {
217  pushCommand(tr("? %1").arg(param));
218 }
void pushCommand(QString cmd)
void QWatlowDevice::issueCommand ( )
private

Definition at line 133 of file qwatlowdevice.cpp.

References QPidDevice::commPort(), DEBUG_WATLOW, m_CommandQueue, m_CommandTimer, QPidDevice::printMessage(), and QPidDevice::write().

Referenced by abandonCommand(), completeCommand(), and pushCommand().

134 {
135  if (m_CommandQueue.length() > 0) {
136  m_CommandTimer.setSingleShot(true);
137  m_CommandTimer.start(2000);
138 
139  QString cmd = m_CommandQueue[0];
140 
141  if (cmd[0] == '=') {
142  printMessage(tr("Set: %1").arg(cmd));
143  }
144 
145  if (commPort()) {
146  if (qcepDebug(DEBUG_WATLOW)) {
147  printMessage(tr("Sent command: %1").arg(cmd));
148  }
149 
150  commPort() -> write(qPrintable(cmd+"\r"));
151  }
152  }
153 }
QStringList m_CommandQueue
Definition: qwatlowdevice.h:71
virtual void write(QString cmd)
Definition: qpiddevice.cpp:525
QTimer m_CommandTimer
Definition: qwatlowdevice.h:72
QPidCommPortPtr commPort()
Definition: qpiddevice.cpp:121
void printMessage(QString msg, QDateTime ts=QDateTime::currentDateTime())
Definition: qpiddevice.cpp:321
void QWatlowDevice::newParameterValue ( QString  param,
double  value 
)
signal

Referenced by completeCommand().

void QWatlowDevice::onDsrChanged ( bool  status)
slot

Definition at line 119 of file qwatlowdevice.cpp.

References QPidDevice::printMessage().

120 {
121  printMessage(tr("DSR Changed %1").arg(status));
122 }
void printMessage(QString msg, QDateTime ts=QDateTime::currentDateTime())
Definition: qpiddevice.cpp:321
void QWatlowDevice::onGraphingTimeout ( )
slot

Definition at line 383 of file qwatlowdevice.cpp.

References QPidDevice::controller(), and QPidDevice::graphedChannelValues().

384 {
385  QcepDoubleList res;
386 
388  QDateTime ts(QDateTime::currentDateTime());
389 
390  res.append(ts.toTime_t());
391  res.append(ts.date().day());
392  res.append(ts.time().hour());
393  res.append(ts.time().minute());
394  res.append(ts.time().second());
395 
396  res.append(ctl->get_Temperature());
397  res.append(ctl->get_OutputLevel());
398  res.append(ctl->get_RampPoint());
399 
400  emit graphedChannelValues(res);
401 }
QPidControllerWPtr controller() const
Definition: qpiddevice.cpp:316
void graphedChannelValues(QcepDoubleList values)
QSharedPointer< QPidController > QPidControllerPtr
void QWatlowDevice::onLoggingTimeout ( )
slot

Definition at line 403 of file qwatlowdevice.cpp.

References QPidDevice::controller(), and QPidDevice::loggedChannelValues().

404 {
405  QcepDoubleList res;
406 
408  QDateTime ts(QDateTime::currentDateTime());
409 
410  res.append(ts.toTime_t());
411  res.append(ts.date().day());
412  res.append(ts.time().hour());
413  res.append(ts.time().minute());
414  res.append(ts.time().second());
415 
416  res.append(ctl->get_Temperature());
417  res.append(ctl->get_OutputLevel());
418  res.append(ctl->get_RampPoint());
419 
420  emit loggedChannelValues(res);
421 }
QPidControllerWPtr controller() const
Definition: qpiddevice.cpp:316
QSharedPointer< QPidController > QPidControllerPtr
void loggedChannelValues(QcepDoubleList values)
void QWatlowDevice::onReadyRead ( )
slot

Definition at line 81 of file qwatlowdevice.cpp.

References QPidDevice::bytesAvailable(), QPidDevice::commPort(), completeCommand(), DEBUG_WATLOW, m_CommandQueue, m_Reply, and QPidDevice::printMessage().

82 {
83  QByteArray bytes;
84 
85  int a = commPort() -> bytesAvailable();
86 
87  bytes.resize(a);
88 
89  bytes = commPort() -> read(bytes.size());
90 
91  m_Reply.append(bytes);
92 
93  if (qcepDebug(DEBUG_WATLOW)) {
94  printMessage(tr("Bytes received '%1' (%2)").arg(bytes.data()).arg(bytes.size()));
95  }
96 
97  if (m_CommandQueue.length()) {
98  QString cmd = m_CommandQueue.first();
99 
100  if (cmd[0] == '?') {
101  if (m_Reply.endsWith(QChar(13))) {
102  completeCommand();
103  m_Reply = "";
104  }
105  } else if (cmd[0] == '=') {
106  if (m_Reply.endsWith(QChar(17))) {
107  completeCommand();
108  m_Reply = "";
109  }
110  }
111  }
112 }
QStringList m_CommandQueue
Definition: qwatlowdevice.h:71
void completeCommand()
virtual int bytesAvailable()
Definition: qpiddevice.cpp:540
QPidCommPortPtr commPort()
Definition: qpiddevice.cpp:121
void printMessage(QString msg, QDateTime ts=QDateTime::currentDateTime())
Definition: qpiddevice.cpp:321
QString m_Reply
Definition: qwatlowdevice.h:74
void QWatlowDevice::onTimeout ( )
slot

Definition at line 74 of file qwatlowdevice.cpp.

References abandonCommand(), m_CommandQueue, and QPidDevice::printMessage().

Referenced by start().

75 {
76  printMessage(tr("Timeout on %1").arg(m_CommandQueue.first()));
77 
79 }
QStringList m_CommandQueue
Definition: qwatlowdevice.h:71
void printMessage(QString msg, QDateTime ts=QDateTime::currentDateTime())
Definition: qpiddevice.cpp:321
void QWatlowDevice::pushCommand ( QString  cmd)
slot

Definition at line 124 of file qwatlowdevice.cpp.

References issueCommand(), and m_CommandQueue.

Referenced by getParameter(), sendCommand(), and setParameter().

125 {
126  m_CommandQueue.append(cmd);
127 
128  if (m_CommandQueue.length() == 1) {
129  issueCommand();
130  }
131 }
QStringList m_CommandQueue
Definition: qwatlowdevice.h:71
void QWatlowDevice::readoutInitial ( )
slot

Definition at line 33 of file qwatlowdevice.cpp.

References QPidDevice::graphedChannelNames(), and QPidDevice::loggedChannelNames().

34 {
35  QStringList channels;
36 
37  channels.append("Epoch");
38  channels.append("Day");
39  channels.append("Hours");
40  channels.append("Minutes");
41  channels.append("Seconds");
42  channels.append("Temperature");
43  channels.append("OutputLevel");
44  channels.append("SetPoint");
45 
46  emit loggedChannelNames(channels);
47  emit graphedChannelNames(channels);
48 }
void graphedChannelNames(QStringList names)
void loggedChannelNames(QStringList names)
void QWatlowDevice::readoutPolling ( )
slot

Definition at line 50 of file qwatlowdevice.cpp.

51 {
52 }
void QWatlowDevice::readoutTimeout ( )
slot

Definition at line 54 of file qwatlowdevice.cpp.

55 {
56 }
void QWatlowDevice::readSettings ( QSettings *  set,
QString  section 
)
virtual

Reimplemented from QPidDevice.

Definition at line 261 of file qwatlowdevice.cpp.

References QPidDevice::readSettings().

262 {
263  QPidDevice::readSettings(set, section+"/watlow");
264 
265  QcepProperty::readSettings(this, &staticMetaObject, section+"/watlow", set);
266 }
virtual void readSettings(QSettings *set, QString section)
Definition: qpiddevice.cpp:375
void QWatlowDevice::sendCommand ( QString  cmd)
slot

Definition at line 114 of file qwatlowdevice.cpp.

References pushCommand().

115 {
116  pushCommand(cmd);
117 }
void pushCommand(QString cmd)
void QWatlowDevice::setParameter ( QString  param,
double  val 
)
slot

Definition at line 210 of file qwatlowdevice.cpp.

References pushCommand().

Referenced by autoTune(), changeRampRate(), and changeSetPoint().

211 {
212  pushCommand(tr("= %1 %2").arg(param).arg(val));
213 }
void pushCommand(QString cmd)
void QWatlowDevice::start ( )
slot

Definition at line 14 of file qwatlowdevice.cpp.

References m_CommandTimer, m_TimerID, onTimeout(), and QPidDevice::start().

15 {
17 
18  connect(&m_CommandTimer, SIGNAL(timeout()), this, SLOT(onTimeout()));
19 
20  m_TimerID = startTimer(2000);
21 }
QTimer m_CommandTimer
Definition: qwatlowdevice.h:72
virtual void start()
Definition: qpiddevice.cpp:139
void QWatlowDevice::stop ( )
slot

Definition at line 23 of file qwatlowdevice.cpp.

References m_TimerID, and QPidDevice::stop().

24 {
25  if (m_TimerID) {
26  killTimer(m_TimerID);
27  m_TimerID = 0;
28  }
29 
31 }
virtual void stop()
Definition: qpiddevice.cpp:189
void QWatlowDevice::timerEvent ( QTimerEvent *  )
slot

Definition at line 58 of file qwatlowdevice.cpp.

References DEBUG_WATLOW, getParameter(), m_CommandQueue, and QPidDevice::printMessage().

59 {
60  if (m_CommandQueue.count() > 2) {
61  if (qcepDebug(DEBUG_WATLOW)) {
62  printMessage(tr("Discarding %1 outstanding commands").arg(m_CommandQueue.count()));
63  // m_CommandQueue.clear();
64  printMessage(tr("%1 outstanding commands, skipping polling commands").arg(m_CommandQueue.count()));
65  }
66  } else {
67  getParameter("SP1");
68  getParameter("ER2");
69  getParameter("C1");
70  getParameter("PWR");
71  }
72 }
QStringList m_CommandQueue
Definition: qwatlowdevice.h:71
void printMessage(QString msg, QDateTime ts=QDateTime::currentDateTime())
Definition: qpiddevice.cpp:321
void getParameter(QString param)
void QWatlowDevice::writeOutput ( QString  cmd)

Definition at line 322 of file qwatlowdevice.cpp.

323 {
324 }
void QWatlowDevice::writeSettings ( QSettings *  set,
QString  section 
)
virtual

Reimplemented from QPidDevice.

Definition at line 254 of file qwatlowdevice.cpp.

References QPidDevice::writeSettings().

255 {
256  QPidDevice::writeSettings(set, section+"/watlow");
257 
258  QcepProperty::writeSettings(this, &staticMetaObject, section+"/watlow", set);
259 }
virtual void writeSettings(QSettings *set, QString section)
Definition: qpiddevice.cpp:366

Member Data Documentation

QStringList QWatlowDevice::m_CommandQueue
private
QTimer QWatlowDevice::m_CommandTimer
private

Definition at line 72 of file qwatlowdevice.h.

Referenced by abandonCommand(), completeCommand(), issueCommand(), and start().

QWatlowDeviceDialogPtr QWatlowDevice::m_DeviceDialog
private

Definition at line 75 of file qwatlowdevice.h.

Referenced by configurationDialog().

QPidObjectNamer QWatlowDevice::m_ObjectNamer

Definition at line 68 of file qwatlowdevice.h.

QString QWatlowDevice::m_Parameter
private

Definition at line 73 of file qwatlowdevice.h.

QString QWatlowDevice::m_Reply
private

Definition at line 74 of file qwatlowdevice.h.

Referenced by completeCommand(), and onReadyRead().

int QWatlowDevice::m_TimerID
private

Definition at line 76 of file qwatlowdevice.h.

Referenced by start(), and stop().


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