57 static const char NUL =
'\x00';
58 static const char ACK =
'\x06';
59 static const char NAK =
'\x15';
60 static const char ENQ =
'\x05';
61 static const char ETX =
'\x03';
62 static const char LF =
'\n';
63 static const char CR =
'\r';
64 static const char EOM[] =
"\n\r";
75 {
"PRS0", TID_INT, 1, NULL },
76 {
"PRM0", TID_FLOAT, 1, NULL },
77 {
"SP1S", TID_BOOL, 1, NULL },
78 {
"SP2S", TID_BOOL, 1, NULL },
79 {
"SP1L", TID_FLOAT, 1, NULL },
80 {
"SP1H", TID_FLOAT, 1, NULL },
81 {
"SP2L", TID_FLOAT, 1, NULL },
82 {
"SP2H", TID_FLOAT, 1, NULL },
141 cm_get_experiment_database(&
hDB, NULL);
145 printf(
"Opening vacuum gauge port...");
149 cm_msg(MERROR,
"vacuum_gauge_init",
150 "Error opening vacuum gauge (errno %d)", err);
154 printf(
"Getting current serial port attributes...");
159 cm_msg(MERROR,
"vacuum_gauge_init",
160 "Error getting vacuum gauge serial port attributes (errno %d)", err);
169 IGNPAR | INLCR | INPCK | ISTRIP |
170 IUCLC | IXANY | IXOFF | IXON |
174 HUPCL | PARENB | PARODD);
176 ICANON | IEXTEN | ISIG | NOFLSH |
197 printf(
"Setting new serial port attributes...");
202 cm_msg(MERROR,
"vacuum_gauge_init",
203 "Error setting vacuum gauge serial port attributes (errno %d)", err);
209 printf(
"Setting vacuum gauge to measurement request mode...");
214 cm_msg(MERROR,
"vacuum_gauge_init",
215 "Error writing to vacuum gauge to set inquire mode (errno %d)", errno);
219 printf(
"Checking vacuum acknowledgement...");
226 cm_msg(MERROR,
"vacuum_gauge_init",
227 "Vacuum gauge did not acknowledge measurement request mode (nothing received)");
234 cm_msg(MERROR,
"vacuum_gauge_init",
235 "Vacuum gauge did not acknowledge measurement request mode (errno %d)", errno);
240 cm_msg(MERROR,
"vacuum_gauge_init",
241 "Vacuum gauge did not acknowledge measurement request mode (something other than ACK received)");
303 static BOOL *sp1, *sp2;
304 static float *sp1l, *sp1h;
305 static float *sp2l, *sp2h;
310 static char status_str[1+1];
311 static char sp1_str[1+1], sp2_str[1+1];
312 static char sp1l_str[10+1], sp1h_str[10+1];
313 static char sp2l_str[10+1], sp2h_str[10+1];
314 static char pres_str[10+1];
317 sp1_str[1] =
NUL; sp2_str[1] =
NUL;
318 sp1l_str[10] =
NUL; sp1h_str[10] =
NUL;
319 sp2l_str[10] =
NUL; sp2h_str[10] =
NUL;
330 printf(
"Error writing to vacuum gauge to enable set point request mode (errno %d)\n", err);
337 printf(
"Vacuum gauge did not acknowledge set point request mode (nothing received)\n");
343 printf(
"Vacuum gauge did not acknowledge set point request mode (errno %d)\n", err);
346 printf(
"Vacuum gauge did not acknowledge set point request mode (something other than ACK received)\n");
353 printf(
"Error writing to vacuum gauge to request status of set points (errno %d)\n", err);
360 printf(
"Vacuum gauge did not send status of set points.\n");
366 printf(
"Error reading status of set points from vacuum gaige (errno %d)\n", err);
368 }
else if (ret != 9) {
369 printf(
"Received incorrect response size (expected 9, received %d)", ret);
373 sp1_str[0] =
resp[0];
374 sp2_str[0] =
resp[2];
382 printf(
"Error writing to vacuum gauge to enable set point request mode (errno %d)\n", err);
389 printf(
"Vacuum gauge did not acknowledge set point request mode (nothing received)\n");
395 printf(
"Vacuum gauge did not acknowledge set point request mode (errno %d)\n", err);
398 printf(
"Vacuum gauge did not acknowledge set point request mode (something other than ACK received)\n");
405 printf(
"Error writing to vacuum gauge to request status of set points (errno %d)\n", err);
412 printf(
"Vacuum gauge did not send status of set points.\n");
418 printf(
"Error reading status of set points from vacuum gaige (errno %d)\n", err);
420 }
else if (ret != 9) {
421 printf(
"Received incorrect response size (expected 25, received %d)\n", ret);
424 if (
resp[0] !=
'1') {
425 printf(
"Received incorrect set point value (expect 1, received %c)\n",
resp[0]);
428 for (i = 0; i < 10; i++) {
429 sp1l_str[
i] =
resp[i + 2];
430 sp1h_str[
i] =
resp[i + 13];
437 printf(
"Error writing to vacuum gauge to enable set point request mode (errno %d)\n", err);
444 printf(
"Vacuum gauge did not acknowledge set point request mode (nothing received)\n");
450 printf(
"Vacuum gauge did not acknowledge set point request mode (errno %d)\n", err);
453 printf(
"Vacuum gauge did not acknowledge set point request mode (something other than ACK received)\n");
460 printf(
"Error writing to vacuum gauge to request status of set points (errno %d)\n", err);
467 printf(
"Vacuum gauge did not send status of set points.\n");
473 printf(
"Error reading status of set points from vacuum gaige (errno %d)\n", err);
475 }
else if (ret != 9) {
476 printf(
"Received incorrect response size (expected 25, received %d)\n", ret);
479 if (
resp[0] !=
'2') {
480 printf(
"Received incorrect set point value (expect 2, received %c)\n",
resp[0]);
483 for (i = 0; i < 10; i++) {
484 sp2l_str[
i] =
resp[i + 2];
485 sp2h_str[
i] =
resp[i + 13];
493 printf(
"Error writing to vacuum gauge to set inquire mode (errno %d)\n", err);
500 printf(
"Vacuum gauge did not acknowledge measurement request mode (nothing received)\n");
506 printf(
"Vacuum gauge did not acknowledge measurement request mode (errno %d)\n", errno);
510 printf(
"Vacuum gauge did not acknowledge measurement request mode (something other than ACK received)\n");
516 printf(
"Cannot write to vacuum gauge to request measurement (errno %d)", errno);
523 printf(
"Nothing to be read from vacuum gauge");
528 printf(
"Cannot read from vacuum gauge to get requested reading (errno %d)", errno);
530 }
else if (ret != 15) {
531 printf(
"Received incorrect size response (expected 15, received %d)", ret);
534 status_str[0] =
resp[0];
535 for (i = 0; i < 10; i++) {
536 pres_str[
i] =
resp[i + 4];
541 bk_create(pevent,
"PRS0", TID_INT, &status);
542 *status++ = atoi(status_str); stat = *
status;
543 bk_close(pevent, status);
544 bk_create(pevent,
"PRM0", TID_FLOAT, &pres);
545 *pres++ = atof(pres_str);
546 bk_close(pevent, pres);
547 bk_create(pevent,
"SP1S", TID_BOOL, &sp1);
548 *sp1++ = atoi(sp1_str);
549 bk_close(pevent, sp1);
550 bk_create(pevent,
"SP2S", TID_BOOL, &sp2);
551 *sp2 = atoi(sp2_str);
552 bk_close(pevent, sp2);
553 bk_create(pevent,
"SP1L", TID_FLOAT, &sp1l);
554 *sp1l = atof(sp1l_str);
555 bk_close(pevent, sp1l);
556 bk_create(pevent,
"SP1H", TID_FLOAT, &sp1h);
557 *sp1h = atof(sp1h_str);
558 bk_close(pevent, sp1h);
559 bk_create(pevent,
"SP2L", TID_FLOAT, &sp2l);
560 *sp2l = atof(sp2l_str);
561 bk_close(pevent, sp2l);
562 bk_create(pevent,
"SP2H", TID_FLOAT, &sp2h);
563 *sp2h = atof(sp2h_str);
564 bk_close(pevent, sp2h);
570 case 1:
printf(
"Vacuum gauge under range.\n");
break;
571 case 2:
printf(
"Vacuum gauge over range.\n");
break;
572 case 3:
printf(
"Vacuum gauge error.\n");
break;
573 case 4:
printf(
"Vacuum gauge off.\n");
break;
574 case 5:
printf(
"Vacuum gauge not attached.\n");
break;
575 case 6:
printf(
"Vacuum gauge unidentifiable.\n");
break;
576 default:
printf(
"Vacuum gauge unknown status (status %d)\n", *status);
break;
582 return bk_size(pevent);