1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
|
/*
* Remote Laboratory Instrumentation Server
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* (c) 2009 Timothy Pearson
* Raptor Engineering
* http://www.raptorengineeringinc.com
*/
#include <ctype.h>
#include <errno.h>
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <stdint.h>
#include <string.h>
#include <getopt.h>
#include "gpib_functions.h"
#include "parameters.h"
#include "gpib/ib.h"
extern char falpha[1024];
int signal_get_last_error(const char * funcgenType, int gpibDevice, char * extendedError) {
char error_array[1024];
int ei;
char * ep;
// Zero the error array
for (ei=0;ei<1024;ei++) {
error_array[ei] = 0;
}
if ((strcmp("AG33250A", funcgenType) == 0)) {
if (strcmp("AG33250A", funcgenType) == 0) {
sleep (1);
sprintf(falpha,"SYSTEM:ERROR?");
#ifdef ENABLE_EXTRA_DEBUGGING
printf("[DEBG] Writing: %s\n\r", falpha);
#endif
if (gpib_write(gpibDevice, falpha) == 0) {
ibrd(gpibDevice, error_array, 1024-1);
ep = strstr(error_array, "+0,");
if (ep != 0) {
return 0;
}
else {
sprintf(extendedError, "EXT%s%c\n\r", error_array, 176);
#ifdef ENABLE_EXTRA_DEBUGGING
printf("[DEBG] Extended error: %s\n\r", extendedError);
#endif
return 3;
}
}
else {
sprintf(extendedError, "EXTAn unknown communications error has occured!%c\n\r", 176);
#ifdef ENABLE_EXTRA_DEBUGGING
printf("[DEBG] Extended error: %s\n\r", extendedError);
#endif
return 2;
}
}
}
sprintf(extendedError, "EXTAn invalid device was selected!%c\n\r", 176);
#ifdef ENABLE_EXTRA_DEBUGGING
printf("[DEBG] Extended error: %s\n\r", extendedError);
#endif
return 1;
}
int signal_reset(const char * funcgenType, int gpibDevice, char * extendedError)
{
if ((strcmp("AG33250A", funcgenType) == 0)) {
printf("[INFO] Resetting function generator\n\r");
if (strcmp("AG33250A", funcgenType) == 0) {
sprintf(falpha,"*RST");
#ifdef ENABLE_EXTRA_DEBUGGING
printf("[DEBG] Writing: %s\n\r", falpha);
#endif
if (gpib_write(gpibDevice, falpha) == 0) {
sprintf(falpha,"*CLS");
#ifdef ENABLE_EXTRA_DEBUGGING
printf("[DEBG] Writing: %s\n\r", falpha);
#endif
if (gpib_write(gpibDevice, falpha) == 0) {
sprintf(falpha,"DISP:TEXT 'Remote Control System v%s.%s%s'", SERVER_MAJOR, SERVER_MINOR, SERVER_REVISION);
#ifdef ENABLE_EXTRA_DEBUGGING
printf("[DEBG] Writing: %s\n\r", falpha);
#endif
if (gpib_write(gpibDevice, falpha) == 0) {
sprintf(falpha,"FUNCTION SQUARE");
#ifdef ENABLE_EXTRA_DEBUGGING
printf("[DEBG] Writing: %s\n\r", falpha);
#endif
if (gpib_write(gpibDevice, falpha) == 0) {
sprintf(falpha,"OUTPUT:LOAD INFINITY");
#ifdef ENABLE_EXTRA_DEBUGGING
printf("[DEBG] Writing: %s\n\r", falpha);
#endif
if (gpib_write(gpibDevice, falpha) == 0) {
sprintf(falpha,"VOLTAGE 3.3");
#ifdef ENABLE_EXTRA_DEBUGGING
printf("[DEBG] Writing: %s\n\r", falpha);
#endif
if (gpib_write(gpibDevice, falpha) == 0) {
sprintf(falpha,"FUNCTION SQUARE");
#ifdef ENABLE_EXTRA_DEBUGGING
printf("[DEBG] Writing: %s\n\r", falpha);
#endif
if (gpib_write(gpibDevice, falpha) == 0) {
sprintf(falpha,"FUNCTION:SQUARE:DCYCLE 50");
#ifdef ENABLE_EXTRA_DEBUGGING
printf("[DEBG] Writing: %s\n\r", falpha);
#endif
if (gpib_write(gpibDevice, falpha) == 0) {
sprintf(falpha,"SYSTEM:BEEPER:STATE ON");
#ifdef ENABLE_EXTRA_DEBUGGING
printf("[DEBG] Writing: %s\n\r", falpha);
#endif
if (gpib_write(gpibDevice, falpha) == 0) {
sprintf(falpha,"OUTPUT ON");
#ifdef ENABLE_EXTRA_DEBUGGING
printf("[DEBG] Writing: %s\n\r", falpha);
#endif
if (gpib_write(gpibDevice, falpha) == 0) {
sprintf(falpha,"SYSTEM:BEEPER");
#ifdef ENABLE_EXTRA_DEBUGGING
printf("[DEBG] Writing: %s\n\r", falpha);
#endif
if (gpib_write(gpibDevice, falpha) == 0) {
return signal_get_last_error(funcgenType, gpibDevice, extendedError);
}
}
}
}
}
}
}
}
}
}
}
else {
sprintf(extendedError, "EXTAn unknown communications error has occured!�");
return 2;
}
}
}
sprintf(extendedError, "EXTAn invalid device was selected!�");
return 1;
}
int signal_set_frequency(float desired_frequency, const char * funcgenType, int gpibDevice, char * extendedError) {
if ((strcmp("AG33250A", funcgenType) == 0)) {
printf("[INFO] Setting function generator frequency to %f\n\r", desired_frequency);
if (strcmp("AG33250A", funcgenType) == 0) {
// FIXME
sprintf(falpha,"FREQUENCY %E", desired_frequency);
#ifdef ENABLE_EXTRA_DEBUGGING
printf("[DEBG] Writing: %s\n\r", falpha);
#endif
if (gpib_write(gpibDevice, falpha) == 0) {
return signal_get_last_error(funcgenType, gpibDevice, extendedError);
}
else {
sprintf(extendedError, "EXTAn unknown communications error has occured!�");
return 2;
}
}
}
else {
sprintf(extendedError, "EXTAn invalid device was selected!�");
return 1;
}
}
int signal_set_duty_cycle(float desired_dcycle, const char * funcgenType, int gpibDevice, char * extendedError) {
if ((strcmp("AG33250A", funcgenType) == 0)) {
printf("[INFO] Setting function generator period to %f\n\r", desired_dcycle);
if (strcmp("AG33250A", funcgenType) == 0) {
// FIXME
sprintf(falpha,"FUNCTION:SQUARE:DCYCLE %E", desired_dcycle);
#ifdef ENABLE_EXTRA_DEBUGGING
printf("[DEBG] Writing: %s\n\r", falpha);
#endif
if (gpib_write(gpibDevice, falpha) == 0) {
return signal_get_last_error(funcgenType, gpibDevice, extendedError);
}
else {
sprintf(extendedError, "EXTAn unknown communications error has occured!�");
return 2;
}
}
}
else {
sprintf(extendedError, "EXTAn invalid device was selected!�");
return 1;
}
}
int signal_set_waveform(char * waveform, const char * funcgenType, int gpibDevice, char * extendedError) {
if ((strcmp("AG33250A", funcgenType) == 0)) {
printf("[INFO] Setting function generator waveform to %s\n\r", waveform);
if (strcmp("AG33250A", funcgenType) == 0) {
// FIXME
sprintf(falpha,"FUNCTION %s", waveform);
#ifdef ENABLE_EXTRA_DEBUGGING
printf("[DEBG] Writing: %s\n\r", falpha);
#endif
if (gpib_write(gpibDevice, falpha) == 0) {
return signal_get_last_error(funcgenType, gpibDevice, extendedError);
}
else {
sprintf(extendedError, "EXTAn unknown communications error has occured!�");
return 2;
}
}
}
else {
sprintf(extendedError, "EXTAn invalid device was selected!�");
return 1;
}
}
int signal_set_peak_peak_voltage(float desired_voltage, const char * funcgenType, int gpibDevice, char * extendedError) {
if ((strcmp("AG33250A", funcgenType) == 0)) {
printf("[INFO] Setting function generator peak-peak voltage to %f\n\r", desired_voltage);
if (strcmp("AG33250A", funcgenType) == 0) {
// FIXME
sprintf(falpha,"VOLTAGE %E", desired_voltage);
#ifdef ENABLE_EXTRA_DEBUGGING
printf("[DEBG] Writing: %s\n\r", falpha);
#endif
if (gpib_write(gpibDevice, falpha) == 0) {
return signal_get_last_error(funcgenType, gpibDevice, extendedError);
}
else {
sprintf(extendedError, "EXTAn unknown communications error has occured!�");
return 2;
}
}
}
else {
sprintf(extendedError, "EXTAn invalid device was selected!�");
return 1;
}
}
int signal_set_offset_voltage(float desired_voltage, const char * funcgenType, int gpibDevice, char * extendedError) {
if ((strcmp("AG33250A", funcgenType) == 0)) {
printf("[INFO] Setting function generator peak-peak voltage to %f\n\r", desired_voltage);
if (strcmp("AG33250A", funcgenType) == 0) {
// FIXME
sprintf(falpha,"VOLTAGE:OFFSET %E", desired_voltage);
#ifdef ENABLE_EXTRA_DEBUGGING
printf("[DEBG] Writing: %s\n\r", falpha);
#endif
if (gpib_write(gpibDevice, falpha) == 0) {
return signal_get_last_error(funcgenType, gpibDevice, extendedError);
}
else {
sprintf(extendedError, "EXTAn unknown communications error has occured!�");
return 2;
}
}
}
else {
sprintf(extendedError, "EXTAn invalid device was selected!�");
return 1;
}
}
|