FreeCalypso > hg > fc-rfcal-tools
comparison cmu200/sercmd.c @ 0:bd62be88259d
initial import of rfcal code and docs from freecalypso-tools repository
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Sat, 20 May 2017 18:49:35 +0000 |
parents | |
children | aeffe53e110d |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:bd62be88259d |
---|---|
1 /* | |
2 * This module contains the functions that send serial commands to the CMU200 | |
3 * and collect the instrument's serial responses. | |
4 */ | |
5 | |
6 #include <sys/types.h> | |
7 #include <ctype.h> | |
8 #include <stdio.h> | |
9 #include <stdlib.h> | |
10 #include <unistd.h> | |
11 #include <string.h> | |
12 #include <strings.h> | |
13 | |
14 extern int target_fd; | |
15 | |
16 char instrument_response[4096]; | |
17 | |
18 send_scpi_cmd(cmd) | |
19 char *cmd; | |
20 { | |
21 printf("Command to CMU: %s", cmd); | |
22 write(target_fd, cmd, strlen(cmd)); | |
23 } | |
24 | |
25 collect_instr_response() | |
26 { | |
27 char buf[BUFSIZ]; | |
28 int cc, pos; | |
29 | |
30 for (pos = 0; ; ) { | |
31 cc = read(target_fd, buf, sizeof buf); | |
32 if (cc <= 0) { | |
33 perror("error reading from serial port"); | |
34 exit(1); | |
35 } | |
36 if (pos + cc > sizeof instrument_response) { | |
37 fprintf(stderr, | |
38 "error: response from CMU200 exceeds our buffer size\n"); | |
39 exit(1); | |
40 } | |
41 bcopy(buf, instrument_response + pos, cc); | |
42 pos += cc; | |
43 if (instrument_response[pos-1] == '\n') | |
44 break; | |
45 } | |
46 instrument_response[pos-1] = '\0'; | |
47 printf("Instrument response: %s\n", instrument_response); | |
48 } | |
49 | |
50 collect_staropc_response() | |
51 { | |
52 collect_instr_response(); | |
53 if (instrument_response[0] != '1' || | |
54 instrument_response[1] && !isspace(instrument_response[1])) { | |
55 fprintf(stderr, "error: unexpected response to *OPC?\n"); | |
56 exit(1); | |
57 } | |
58 } |