qpidctrl  0.7.1
qcryostreamdevice.cpp
Go to the documentation of this file.
1 #include "qcryostreamdevice.h"
2 #include "qpidcontroller.h"
3 #include "qpidcommport.h"
4 
5 typedef struct {
6  unsigned char Length; /* Length of this packet, = 32 (bytes) */
7  unsigned char Type; /* Status Packet ID = 1 for standard packet */
8  unsigned short GasSetPoint; /* Set Temp 100*K */
9  unsigned short GasTemp; /* Gas Temp 100*K */
10  signed short GasError; /* Error 100*K */
11  unsigned char RunMode; /* The current run mode */
12  unsigned char PhaseId; /* The id of the current phase - see below */
13  unsigned short RampRate; /* The ramp rate of the current phase */
14  unsigned short TargetTemp; /* The target temperature of the current phase */
15  unsigned short EvapTemp; /* Evap temp, 100*K */
16  unsigned short SuctTemp; /* Suct temp, 100*K */
17  unsigned short Remaining; /* Time remaining in phase */
18  unsigned char GasFlow; /* Gas flow, 10*l/min */
19  unsigned char GasHeat; /* Gas heater, % */
20  unsigned char EvapHeat; /* Evap heater, % */
21  unsigned char SuctHeat; /* Suct heater, % */
22  unsigned char LinePressure; /* Back pressure, 100*bar */
23  unsigned char AlarmCode; /* Indicates most serious alarm condition */
24  unsigned short RunTime; /* Time in minutes pump has been up */
25  unsigned short ControllerNumber; /* Controller number, from ROM */
26  unsigned char SoftwareVersion; /* Software version */
27  unsigned char EvapAdjust; /* EvapAdjust vacuum compensation */
29 
30 typedef struct {
31  unsigned char Length; /* Length of this packet, = 42 (bytes) */
32  unsigned char Type; /* Status Packet ID = 2 for extended packet */
33  unsigned short GasSetPoint; /* Set Temp 100*K */
34  unsigned short GasTemp; /* Gas Temp 100*K */
35  signed short GasError; /* Error 100*K */
36  unsigned char RunMode; /* The current run mode */
37  unsigned char PhaseId; /* The id of the current phase - see below */
38  unsigned short RampRate; /* The ramp rate of the current phase */
39  unsigned short TargetTemp; /* The target temperature of the current phase */
40  unsigned short EvapTemp; /* Evap temp, 100*K */
41  unsigned short SuctTemp; /* Suct temp, 100*K */
42  unsigned short Remaining; /* Time remaining in phase */
43  unsigned char GasFlow; /* Gas flow, 10*l/min */
44  unsigned char GasHeat; /* Gas heater, % */
45  unsigned char EvapHeat; /* Evap heater, % */
46  unsigned char SuctHeat; /* Suct heater, % */
47  unsigned char LinePressure; /* Back pressure, 100*bar */
48  unsigned char AlarmCode; /* Indicates most serious alarm condition */
49  unsigned short RunTime; /* Time in minutes pump has been up */
50  unsigned short ControllerNumber; /* Controller number, from ROM */
51  unsigned char SoftwareVersion; /* Software version */
52  unsigned char EvapAdjust; /* EvapAdjust vacuum compensation */
53  unsigned char TurboMode; /* In Turbo mode ? */
54  unsigned char HardwareType; /* Cryostream or Cryostream Plus, with/without Shutter */
55  unsigned char ShutterState; /* Shutter status */
56  unsigned char ShutterTime; /* Shutter time remaining */
57  unsigned char UnusedOne; /* For expansion */
58  unsigned char UnusedTwo; /* For expansion */
59  unsigned short UnusedThree; /* For expansion */
60  unsigned short UnusedFour; /* For expansion */
62 
63 typedef struct {
64  unsigned char Length; /* Length of this packet, = 44 (bytes)*/
65  unsigned char Type; /* Packet ID, = 150 for Cobra status packets */
66  unsigned short GasSetPoint; /* Set Temp 100*K */
67  unsigned short GasTemp; /* Gas Temp 100*K */
68  signed short GasError; /* Error 100*K */
69  unsigned char RunMode; /* The current run mode */
70  unsigned char PhaseId; /* The id of the current phase - see below */
71  unsigned short RampRate; /* The ramp rate of the current phase */
72  unsigned short TargetTemp; /* The target temperature of the current phase */
73  unsigned short RefrTemp; /* Refrigerator temp, 100*K */
74  unsigned short VacuumGauge; /* Vacuum gauge reading */
75  unsigned short Remaining; /* Time remaining in phase */
76  unsigned char GasFlow; /* Gas flow, 10*l/min */
77  unsigned char GasHeat; /* Gas heater, % */
78  unsigned char RefrHeat; /* Refrigerator heater, % */
79  unsigned char UnusedZero; /* NOT USED */
80  unsigned char LinePressure; /* Back pressure, 100*bar */
81  unsigned char AlarmCode; /* Indicates most serious alarm condition */
82  unsigned short RunTime; /* Time in minutes pump has been up */
83  unsigned short ControllerNumber; /* Controller number, from ROM */
84  unsigned char SoftwareVersion; /* Software version */
85  unsigned char CryoStatus; /* Cryodrive status */
86  unsigned char CryoAdjust; /* Cryodrive speed boost */
87  unsigned char CryoSpeed; /* Cryodrive speed */
88  unsigned char TurboMode; /* In Turbo mode ? */
89  unsigned char HardwareType; /* With/without CryoShutter */
90  unsigned char ShutterState; /* CryoShutter status */
91  unsigned char ShutterTime; /* CryoShutter time remaining */
92  unsigned char UnusedOne; /* For expansion */
93  unsigned char UnusedTwo; /* For expansion */
94  unsigned short UnusedThree; /* For expansion */
95  unsigned short UnusedFour; /* For expansion */
96 } CobraStatus;
97 
98 typedef struct {
99  unsigned char Length; /* Length of this packet = 32 (bytes) */
100  unsigned char Type; /* Status Packet ID = 100 */
101  unsigned short SampleSetPoint; /* Set Temp 100*K */
102  unsigned short SampleTemp; /* Sample Temp 100*K */
103  signed short SampleError; /* Error 100*K */
104  unsigned char RunMode; /* The current run mode */
105  unsigned char PhaseId; /* The id of the current phase - see below */
106  unsigned short RampRate; /* The ramp rate of the current phase */
107  unsigned short TargetTemp; /* The target temperature of the current phase */
108  unsigned short ShieldTemp; /* Shield temp, 100*K */
109  unsigned short Unused1; /* Unused in PheniX */
110  unsigned short Remaining; /* Time remaining in phase */
111  unsigned char CryoSpeed; /* Cryodrive speed */
112  unsigned char SampleHeat; /* Sample stage heater, % */
113  unsigned char ShieldHeat; /* Shield heater, % */
114  unsigned char Unused2; /* Unused in PheniX */
115  unsigned char CryoStatus; /* Cryodrive status */
116  unsigned char AlarmCode; /* Indicates most serious alarm condition */
117  unsigned short RunTime; /* Time in minutes pump has been up */
118  unsigned short ControllerNumber; /* Controller number, from ROM */
119  unsigned char SoftwareVersion; /* Software version */
120  unsigned char CryoAdjust; /* Cryodrive speed adjustment */
121 } PhenixStatus;
122 
123 typedef struct {
124  unsigned char Length; /* Length of this packet, = 46 (bytes)*/
125  unsigned char Type; /* Packet ID, = 200 for HeliX status packets */
126  unsigned short GasSetPoint; /* Gas set point Temp 100*K */
127  unsigned short GasTemp; /* Gas temp 100*K */
128  signed short GasError; /* Gas error 100*K */
129  unsigned char RunMode; /* The current run mode */
130  unsigned char PhaseId; /* The id of the current phase - see below */
131  unsigned short RampRate; /* The ramp rate of the current phase */
132  unsigned short TargetTemp; /* The target temperature of the current phase */
133  unsigned short ShieldTemp; /* Shield temp, 100*K */
134  unsigned short NozzleTemp; /* Nozzle temperature, 100*K */
135  unsigned short Remaining; /* Time remaining in phase */
136  unsigned char CryoSpeed; /* Cryodrive speed */
137  unsigned char GasHeat; /* Sample stage heater, % */
138  unsigned char ShieldHeat; /* Shield heater, % */
139  unsigned char NozzleHeat; /* Nozzle heater, % */
140  unsigned char CryoStatus; /* Cryodrive status */
141  unsigned char AlarmCode; /* Indicates most serious alarm condition */
142  unsigned short RunTime; /* Time in minutes the machine has been running */
143  unsigned short ControllerNumber; /* Controller number, from ROM */
144  unsigned char SoftwareVersion; /* Software version */
145  unsigned char GasFlow; /* Gas flow, 10*l/min */
146  unsigned char LinePressure; /* Back pressure, 100*bar */
147  unsigned char CryoAdjust; /* Cryodrive speed boost */
148  unsigned char OuterFlow; /* Flow rate in outer stream */
149  unsigned char GasType; /* Helium or nitrogen in cold stream */
150  unsigned char TurboMode; /* In Turbo mode ? */
151  unsigned char HardwareType; /* Cryostream, Plus, with/without Shutter */
152  unsigned char ShutterState; /* Shutter status */
153  unsigned char ShutterTime; /* Shutter time remaining */
154  unsigned char UnusedOne; /* For expansion */
155  unsigned char UnusedTwo; /* For expansion */
156  unsigned short UnusedThree; /* For expansion */
157  unsigned short UnusedFour; /* For expansion */
158 } NHelixStatus;
159 
161  CSCOMMAND_RESTART=10, /* Restart a Cryostream which has shutdown */
162  CSCOMMAND_RAMP=11, /* Ramp command identifier - parameters follow */
163  CSCOMMAND_PLAT=12, /* Plat command identifier - parameter follows */
164  CSCOMMAND_HOLD=13, /* Hold command identifier - enter programmed Hold */
165  CSCOMMAND_COOL=14, /* Cool command identifier - parameter follows */
166  CSCOMMAND_END=15, /* End command identifier - parameter follows */
167  CSCOMMAND_PURGE=16, /* Purge command identifier */
168  CSCOMMAND_PAUSE=17, /* Pause command identifier - enter temporary Hold */
169  CSCOMMAND_RESUME=18, /* Resume command identifier - exit temporary Hold */
170  CSCOMMAND_STOP=19, /* Stop command identifier */
171  CSCOMMAND_TURBO=20, /* Turbo command identifier - parameter follows */
172  CSCOMMAND_SETSTATUSFORMAT=40, /* Set status packet format. Parameter follows */
173  CSCOMMAND_CRYOSHUTTER_START_AUTO=80, /* Shut the CryoShutter for the specified length of time. - parameter follows */
174  CSCOMMAND_CRYOSHUTTER_START_MAN=81, /* Shut the CryoShutter until a CSCOMMAND_CRYOSHUTTER_STOP is received */
175  CSCOMMAND_CRYOSHUTTER_STOP=82 /* Open the CryoShutter */
176 };
177 
178 QCryostreamDevice::QCryostreamDevice(QPidControllerWPtr ctrl, QcepSettingsSaverWPtr saver, QString deviceName) :
179  QPidDevice(ctrl, saver, QPidDevice::CryostreamDevice, deviceName, 1000, 2000),
180  m_ObjectNamer(this, "cryostream"),
181  m_CryostreamDeviceType(QcepSettingsSaverPtr(), this, "cryostreamDeviceType", UnknownDevice, "Detected Device Type")
182 {
183 }
184 
186 {
187 }
188 
190 {
191 }
192 
194 {
195 }
196 
198 {
199  m_Buffer.append(commPort()->readAll());
200 
202 }
203 
204 int QCryostreamDevice::makeWord(int hi, int lo)
205 {
206  return (hi&0xff << 8) | (lo&0xff);
207 }
208 
210 {
211  while (m_Buffer.count() >= 2) {
212  printMessage(tr("parseStatusPacket(len=%1)").arg(m_Buffer.count()));
213 
214  unsigned char len = m_Buffer[0];
215  unsigned char typ = m_Buffer[1];
216 
217  if ((len == 32 && typ == 1) || // Standard status packet
218  (len == 42 && typ == 2) || // Extended status packet
219  (len == 44 && typ == 150) || // Cobra status packet
220  (len == 32 && typ == 100) || // Phenix status packet
221  (len == 46 && typ == 200)) { // Helix status packet
222 
223  if (m_Buffer.count() >= 32) {
224  int setPoint = makeWord(m_Buffer[2], m_Buffer[3]);
225  int temperature = makeWord(m_Buffer[4], m_Buffer[5]);
226  int temperror = makeWord(m_Buffer[6], m_Buffer[7]);
227  int output = m_Buffer[21];
228  int runMode = m_Buffer[8];
229  int phaseID = m_Buffer[9];
230  int alarmCode = m_Buffer[25];
231 
232  if ((runMode >= 0 && runMode <= 6) && // run mode 0..6
233  (phaseID >= 0 && phaseID <= (typ<10?10:9)) && // Cryostream phaseID 0..10, others 0..9
234  (alarmCode >= 0 && alarmCode <= 26) && // alarm code 0..26
235  (temperature - setPoint == temperror)) { // temperature error OK?
236  if (m_Buffer.count() >= len) {
237  switch(typ) {
238  case 1:
239  case 2:
240  set_CryostreamDeviceType(CryostreamDevice);
241  break;
242 
243  case 100:
244  set_CryostreamDeviceType(PhenixDevice);
245  break;
246 
247  case 150:
248  set_CryostreamDeviceType(CobraDevice);
249  break;
250 
251  case 200:
252  set_CryostreamDeviceType(HelixDevice);
253  break;
254 
255  default:
256  set_CryostreamDeviceType(UnknownDevice);
257  }
258 
260 
261  if (ctl) {
262  ctl->set_Temperature(K2degC(cK2K(temperature)));
263  ctl->set_SetPoint(K2degC(cK2K(setPoint)));
264  ctl->set_OutputLevel(output);
265  ctl->set_Enabled(runMode==3);
266  }
267 
268  m_Buffer.remove(0, len);
269  } else {
270  break;
271  }
272  } else {
273  // Not a valid status packet - drop 1 byte and try again
274  m_Buffer.remove(0,1);
275  }
276  }
277  } else {
278  m_Buffer.remove(0,1);
279  }
280  }
281 }
282 
283 void QCryostreamDevice::writeSettings(QSettings *set, QString section)
284 {
285  QPidDevice::writeSettings(set, section+"/cryostream");
286 
287  QcepProperty::writeSettings(this, &staticMetaObject, section+"/cryostream", set);
288 }
289 
290 void QCryostreamDevice::readSettings(QSettings *set, QString section)
291 {
292  QPidDevice::readSettings(set, section+"/cryostream");
293 
294  QcepProperty::readSettings(this, &staticMetaObject, section+"/cryostream", set);
295 }
296 
298 {
299  if (m_DeviceDialog == NULL) {
301  }
302 
303  if (m_DeviceDialog) {
304  m_DeviceDialog->show();
305  m_DeviceDialog->raise();
306  }
307 }
308 
309 void QCryostreamDevice::sendCommand(QString /*cmd*/)
310 {
311 }
312 
314 {
316 
317  if (ctl) {
318  sendCryoCommand(CSCOMMAND_RAMP, cryoRate(ctl->get_RampRate())+cryoTemperature(setPoint));
319  }
320 }
321 
323 {
324 }
325 
327 {
328 }
329 
330 void QCryostreamDevice::changeIntegral(double /*integ*/)
331 {
332 }
333 
335 {
336 }
337 
339 {
340  if (on) {
342  } else {
344  }
345 }
346 
348 {
349  return false;
350 }
351 
353 {
354 }
355 
356 void QCryostreamDevice::sendCryoCommand(int cmd, QByteArray args)
357 {
358  printMessage(tr("sendCryoCommand(%1,QByteArray(len=%2))").arg(cmd).arg(args.count()));
359 
360  if (get_DeviceType() == 0) {
361  printMessage("Warning: Sending command to unknown device");
362  }
363 
364  QByteArray msg;
365 
366  msg.append(2+args.count());
367  msg.append(cmd);
368  msg.append(args);
369 
370  if (commPort()->isWritable()) {
371  commPort()->write(msg);
372  } else {
373  printMessage("Serial port is not writable");
374  }
375 }
376 
377 QByteArray QCryostreamDevice::cryoRate(double rate)
378 {
379  QByteArray res;
380 
381  short rateint = (short)(rate*60);
382 
383  res.append((unsigned char) ((rateint>>8) & 0xff));
384  res.append((unsigned char) (rateint & 0xff));
385 
386  return res;
387 }
388 
389 QByteArray QCryostreamDevice::cryoTemperature(double temp)
390 {
391  QByteArray res;
392 
393  short cKTemp = (short)(K2cK(degC2K(temp)));
394 
395  res.append((unsigned char) ((cKTemp>>8) & 0xff));
396  res.append((unsigned char) (cKTemp & 0xff));
397 
398  return res;
399 }
CryostreamCommand
unsigned char RunMode
unsigned short RunTime
unsigned short ControllerNumber
unsigned char UnusedOne
QByteArray cryoRate(double rate)
unsigned char UnusedTwo
QPidControllerWPtr controller() const
Definition: qpiddevice.cpp:316
unsigned char GasType
unsigned short RunTime
unsigned short UnusedThree
unsigned char Type
void changeSetPoint(double setPoint)
virtual void writeSettings(QSettings *set, QString section)
Definition: qpiddevice.cpp:366
unsigned char AlarmCode
unsigned short SampleTemp
unsigned char GasFlow
unsigned char GasFlow
QWeakPointer< QPidController > QPidControllerWPtr
unsigned char PhaseId
signed short GasError
unsigned char UnusedZero
unsigned short GasTemp
unsigned short TargetTemp
unsigned char LinePressure
unsigned short GasTemp
unsigned char CryoAdjust
unsigned char Type
unsigned short TargetTemp
unsigned char ShutterState
unsigned char Type
unsigned short EvapTemp
QSharedPointer< QPidController > QPidControllerPtr
unsigned char CryoStatus
unsigned char ShieldHeat
unsigned short RampRate
signed short GasError
virtual void writeSettings(QSettings *set, QString section)
unsigned char UnusedOne
QSharedPointer< QCryostreamDeviceDialog > QCryostreamDeviceDialogPtr
unsigned short Remaining
unsigned char Length
unsigned char ShutterTime
unsigned short RefrTemp
double K2cK(double K)
Definition: qpiddevice.cpp:389
unsigned char AlarmCode
unsigned short RunTime
unsigned short Remaining
unsigned char CryoAdjust
unsigned char SoftwareVersion
unsigned short RampRate
int makeWord(int hi, int lo)
unsigned short Remaining
unsigned char CryoSpeed
unsigned char PhaseId
unsigned char Length
unsigned char Unused2
unsigned char LinePressure
unsigned short VacuumGauge
unsigned short UnusedFour
unsigned char CryoSpeed
unsigned char CryoStatus
unsigned char SoftwareVersion
unsigned char ShutterTime
unsigned char EvapAdjust
unsigned short RampRate
void changeIntegral(double integ)
unsigned short ControllerNumber
unsigned char PhaseId
unsigned char Length
QPidCommPortPtr commPort()
Definition: qpiddevice.cpp:121
void sendCryoCommand(int cmd, QByteArray args=QByteArray())
unsigned short SuctTemp
void changeProportional(double prop)
unsigned char CryoSpeed
unsigned char RunMode
unsigned char UnusedTwo
double K2degC(double K)
Definition: qpiddevice.cpp:394
unsigned short NozzleTemp
unsigned char GasFlow
unsigned short GasSetPoint
signed short SampleError
unsigned char LinePressure
QByteArray cryoTemperature(double temp)
unsigned char RunMode
unsigned short Remaining
unsigned short GasTemp
unsigned char TurboMode
double degC2K(double degC)
Definition: qpiddevice.cpp:399
QSharedPointer< QCryostreamDevice > QCryostreamDevicePtr
unsigned char ShutterState
unsigned short GasSetPoint
unsigned short GasSetPoint
unsigned char HardwareType
virtual void readSettings(QSettings *set, QString section)
Definition: qpiddevice.cpp:375
unsigned char CryoAdjust
unsigned char GasHeat
unsigned char AlarmCode
unsigned char PhaseId
unsigned char RefrHeat
unsigned char AlarmCode
unsigned char TurboMode
unsigned short UnusedFour
unsigned short ShieldTemp
unsigned char ShieldHeat
unsigned short ControllerNumber
QCryostreamDeviceDialogPtr m_DeviceDialog
void sendCommand(QString cmd)
unsigned char EvapHeat
unsigned short TargetTemp
double cK2K(double cK)
Definition: qpiddevice.cpp:384
unsigned short RunTime
unsigned char GasHeat
unsigned char SuctHeat
unsigned char OuterFlow
unsigned char RunMode
unsigned char SampleHeat
unsigned char NozzleHeat
unsigned char Length
unsigned short ControllerNumber
void printMessage(QString msg, QDateTime ts=QDateTime::currentDateTime())
Definition: qpiddevice.cpp:321
void changeRampRate(double rate)
unsigned short RampRate
virtual void readSettings(QSettings *set, QString section)
unsigned char SoftwareVersion
unsigned short ShieldTemp
unsigned short Unused1
unsigned short TargetTemp
unsigned char Type
unsigned char CryoStatus
unsigned short UnusedThree
unsigned char HardwareType
QCryostreamDevice(QPidControllerWPtr ctrl, QcepSettingsSaverWPtr saver, QString deviceName)
void changeDerivative(double deriv)
unsigned short SampleSetPoint
unsigned char GasHeat
unsigned char SoftwareVersion