33typedef long Device_Link;
34typedef long Device_Flags;
35typedef long Device_ErrorCode;
38 Device_ErrorCode error;
51 Device_ErrorCode error;
71 Device_ErrorCode error;
87 Device_ErrorCode error;
97#define device_write 11
99#define destroy_link 23
101#define VXI11_DEFAULT_TIMEOUT 10000
102#define VXI11_READ_TIMEOUT 2000
103#define VXI11_CLIENT CLIENT
104#define VXI11_LINK Create_LinkResp
105#define VXI11_MAX_CLIENTS 256
106#define VXI11_NULL_READ_RESP 50
109#define VXI11_NULL_WRITE_RESP 51
113 VXI11_CLIENT *client;
118#define DEVICE_CORE 0x0607AF
119#define DEVICE_CORE_VERSION 1
120#define RCV_END_BIT 0x04
121#define RCV_CHR_BIT 0x02
124char VXI11_IP_ADDRESS[VXI11_MAX_CLIENTS][20];
125CLIENT *VXI11_CLIENT_ADDRESS[VXI11_MAX_CLIENTS];
126int VXI11_DEVICE_NO = 0;
127int VXI11_LINK_COUNT[VXI11_MAX_CLIENTS];
129static struct timeval TIMEOUT = { 25, 0 };
142BOOL sc(
char *con,
char *var);
144int agilent_init(
CLINK *clink);
145int agilent_set_averages(
CLINK *clink,
147void agilent_set_for_auto(
CLINK *clink);
148long agilent_get_data(
CLINK *clink,
151 unsigned long buf_len,
152 unsigned long timeout);
153long agilent_get_data(
CLINK *clink,
157 unsigned long buf_len,
158 unsigned long timeout);
159int agilent_get_preamble(
CLINK *clink,
161 unsigned long buf_len);
162void agilent_scope_channel_str(
char chan,
164int agilent_set_for_capture(
CLINK *clink,
167 unsigned long timeout);
168long agilent_calculate_no_of_bytes(
CLINK *clink,
170 unsigned long timeout);
172int vxi11_open_device(
const char *ip,
174int vxi11_open_device(
const char *ip,
177int vxi11_open_device(
const char *ip,
181int vxi11_open_link(
const char *ip,
185int vxi11_send(
CLINK *clink,
187int vxi11_send(
CLINK *clink,
190int vxi11_send(CLIENT *client,
193int vxi11_send(CLIENT *client,
197int vxi11_close_device(
const char *ip,
199int vxi11_close_device(
const char *ip,
202int vxi11_close_link(
const char *ip,
205double vxi11_obtain_double_value(
CLINK *clink,
207double vxi11_obtain_double_value(
CLINK *clink,
209 unsigned long timeout);
210long vxi11_send_and_receive(
CLINK *clink,
213 unsigned long buf_len,
214 unsigned long timeout);
215long vxi11_receive(
CLINK *clink,
218long vxi11_receive(CLIENT *client,
222 unsigned long timeout);
223long vxi11_receive(
CLINK *clink,
226 unsigned long timeout);
227long vxi11_obtain_long_value(
CLINK *clink,
229 unsigned long timeout);
230long vxi11_obtain_long_value(
CLINK *clink,
232long vxi11_receive_data_block(
CLINK *clink,
235 unsigned long timeout);
243enum clnt_stat destroy_link_1(Device_Link *argp,
250bool_t xdr_Create_LinkParms (XDR *xdrs,
252bool_t xdr_Create_LinkResp (XDR *xdrs,
254bool_t xdr_Device_ErrorCode (XDR *xdrs,
255 Device_ErrorCode *objp);
256bool_t xdr_Device_Link (XDR *xdrs,
258bool_t xdr_Device_WriteParms (XDR *xdrs,
260bool_t xdr_Device_WriteResp (XDR *xdrs,
262bool_t xdr_Device_Flags (XDR *xdrs,
264bool_t xdr_Device_Error (XDR *xdrs,
266bool_t xdr_Device_ReadParms (XDR *xdrs,
268bool_t xdr_Device_ReadResp (XDR *xdrs,
271int main(
int argc,
char **argv)
273 static char *progname;
274 static char *serverIP;
280 unsigned long timeout=10000;
284 BOOL got_scope_channel=FALSE;
286 BOOL got_no_averages=FALSE;
291 double actual_s_rate;
296 double vgain,voffset,hinterval,hoffset;
305 if(sc(argv[index],(
char*)
"-filename")||sc(argv[index],(
char*)
"-f")||sc(argv[index],(
char*)
"-file")){
306 snprintf(wfname,256,
"%s.sdds",argv[++index]);
310 if(sc(argv[index],(
char*)
"-ip")||sc(argv[index],(
char*)
"-ip_address")||sc(argv[index],(
char*)
"-IP")){
311 serverIP = argv[++index];
315 if(sc(argv[index],(
char*)
"-channel")||sc(argv[index],(
char*)
"-c")||sc(argv[index],(
char*)
"-scope_channel")){
316 sscanf(argv[++index],
"%c",&chnl);
317 got_scope_channel=TRUE;
320 if(sc(argv[index],(
char*)
"-sample_rate")||sc(argv[index],(
char*)
"-s")||sc(argv[index],(
char*)
"-rate")){
321 sscanf(argv[++index],
"%lg",&s_rate);
324 if(sc(argv[index],(
char*)
"-no_points")||sc(argv[index],(
char*)
"-n")||sc(argv[index],(
char*)
"-points")){
325 sscanf(argv[++index],
"%ld",&npoints);
328 if(sc(argv[index],(
char*)
"-averages")||sc(argv[index],(
char*)
"-a")||sc(argv[index],(
char*)
"-aver")){
329 sscanf(argv[++index],
"%d",&no_averages);
330 got_no_averages=TRUE;
333 if(sc(argv[index],(
char*)
"-timeout")||sc(argv[index],(
char*)
"-t")){
334 sscanf(argv[++index],
"%lu",&timeout);
340 if(got_file==FALSE||got_scope_channel==FALSE||got_ip==FALSE){
341 printf(
"%s: grabs a waveform from an Agilent scope via ethernet, by Steve (June 06)\n",progname);
342 printf(
"Run using %s [arguments]\n\n",progname);
343 printf(
"REQUIRED ARGUMENTS:\n");
344 printf(
"-ip -ip_address -IP : IP address of scope (eg 128.243.74.232)\n");
345 printf(
"-f -filename -file : filename (without extension)\n");
346 printf(
"-c -scope_channel -channel : scope channel (1,2,3,4,A,B,C,D)\n");
347 printf(
"OPTIONAL ARGUMENTS:\n");
348 printf(
"-t -timeout : timout (in milliseconds)\n");
349 printf(
"-s -sample_rate -rate : set sample rate (eg 1e9 = 1GS/s)\n");
350 printf(
"-n -no_points -points : set minimum no of points\n");
351 printf(
"-a -averages -aver : set no of averages (<=0 means none)\n\n");
352 printf(
"OUTPUTS:\n");
353 printf(
"filename.sdds : ascii data of waveform\n\n");
354 printf(
"EXAMPLE:\n");
355 printf(
"%s -ip 128.243.74.232 -f output -c 2 -s 1e9\n",progname);
359 f_wf=fopen(wfname,
"w");
361 if (vxi11_open_device(serverIP,clink) != 0) {
362 printf(
"Quitting...\n");
366 if (agilent_init(clink) !=0 ) {
367 printf(
"Quitting...\n");
371 agilent_set_for_capture(clink, s_rate, npoints, timeout);
373 if (got_no_averages == TRUE) agilent_set_averages(clink, no_averages);
376 buf_size = agilent_calculate_no_of_bytes(clink, chnl, timeout);
377 buf=
new char[buf_size];
379 hinterval = vxi11_obtain_double_value(clink,
":WAV:XINC?", timeout);
380 hoffset = vxi11_obtain_double_value(clink,
":WAV:XORIGIN?");
381 vgain = vxi11_obtain_double_value(clink,
":WAV:YINC?");
382 voffset = vxi11_obtain_double_value(clink,
":WAV:YORIGIN?");
384 bytes_returned = agilent_get_data(clink, chnl, 0, buf, buf_size, timeout);
385 if (bytes_returned <=0) {
386 printf(
"Problem reading the data, quitting...\n");
390 actual_s_rate = vxi11_obtain_double_value(clink,
":ACQ:SRAT?");
391 actual_npoints = vxi11_obtain_long_value(clink,
":ACQ:POINTS?");
392 printf(
"Sample rate used: %g (%g GSa/s); acquisition points: %ld\n",actual_s_rate, (actual_s_rate/1e9),actual_npoints);
394 agilent_set_for_auto(clink);
396 fprintf(f_wf,
"SDDS1\n");
397 fprintf(f_wf,
"¶meter name=VerticalGain, type=double, &end\n");
398 fprintf(f_wf,
"¶meter name=VerticalOffset, type=double, &end\n");
399 fprintf(f_wf,
"¶meter name=HorizontalInterval, type=double, &end\n");
400 fprintf(f_wf,
"¶meter name=HorizontalOffset, type=double, &end\n");
401 fprintf(f_wf,
"&column name=Index, type=long, &end\n");
402 fprintf(f_wf,
"&column name=Waveform, type=double, &end\n");
403 fprintf(f_wf,
"&column name=Timebase, type=double, &end\n");
404 fprintf(f_wf,
"&column name=DelayedTimebase, type=double, &end\n");
405 fprintf(f_wf,
"&data mode=ascii, &end\n");
406 fprintf(f_wf,
"%lg\n", vgain);
407 fprintf(f_wf,
"%lg\n", voffset);
408 fprintf(f_wf,
"%lg\n", hinterval);
409 fprintf(f_wf,
"%lg\n", hoffset);
410 fprintf(f_wf,
"\t%ld\n", bytes_returned / 2);
412 for (i=0; i < bytes_returned; i += 2) {
413 *((
char*)(&val)) = buf[i];
414 *((
char*)(&val)+1) = buf[i+1];
415 fprintf(f_wf,
"%ld %lg %lg %lg\n", (i/2), val * vgain - voffset, (i/2) * hinterval, (i/2) * hinterval + hoffset);
421 vxi11_close_device(serverIP,clink);
425 printf(
"error: could not open file for writing, quitting...\n");
431BOOL sc(
char *con,
char *var) {
432 if(strcmp(con,var)==0){
438int vxi11_open_device(
const char *ip,
CLINK *clink) {
440 strncpy(device,
"inst0",6);
441 return vxi11_open_device(ip, clink, device);
444int vxi11_open_device(
const char *ip, CLIENT **client, VXI11_LINK **link,
char *device) {
447 *client = clnt_create((
char*)ip, DEVICE_CORE, DEVICE_CORE_VERSION,
"tcp");
449 *client = clnt_create(ip, DEVICE_CORE, DEVICE_CORE_VERSION,
"tcp");
452 if (*client == NULL) {
454 clnt_pcreateerror((
char*)ip);
456 clnt_pcreateerror(ip);
461 return vxi11_open_link(ip, client, link, device);
464int vxi11_open_device(
const char *ip,
CLINK *clink,
char *device) {
469 for (l=0; l<VXI11_MAX_CLIENTS; l++){
470 if (strcmp(ip,VXI11_IP_ADDRESS[l]) == 0 ) {
476 if (VXI11_DEVICE_NO >= VXI11_MAX_CLIENTS) {
477 printf(
"Error: maximum of %d clients allowed\n",VXI11_MAX_CLIENTS);
478 ret = -VXI11_MAX_CLIENTS;
480 ret = vxi11_open_device(ip, &(clink->client), &(clink->link), device);
481 strncpy(VXI11_IP_ADDRESS[VXI11_DEVICE_NO],ip,20);
482 VXI11_CLIENT_ADDRESS[VXI11_DEVICE_NO] = clink->client;
483 VXI11_LINK_COUNT[VXI11_DEVICE_NO]=1;
487 clink->client = VXI11_CLIENT_ADDRESS[device_no];
488 ret = vxi11_open_link(ip, &(clink->client), &(clink->link), device);
489 VXI11_LINK_COUNT[device_no]++;
494int vxi11_open_link(
const char *ip, CLIENT **client, VXI11_LINK **link,
char *device) {
499 link_parms.clientId = (long) *client;
500 link_parms.lockDevice = 0;
501 link_parms.lock_timeout = VXI11_DEFAULT_TIMEOUT;
502 link_parms.device = device;
506 if (create_link_1(&link_parms, *link, *client) != RPC_SUCCESS) {
508 clnt_perror(*client, (
char*)ip);
510 clnt_perror(*client, ip);
519 return (clnt_call(clnt, create_link,
520 (xdrproc_t) xdr_Create_LinkParms, (caddr_t) argp,
521 (xdrproc_t) xdr_Create_LinkResp, (caddr_t) clnt_res,
528#if defined(SOLARIS) && !defined(_LP64)
531 register int32_t *buf;
534 if (xdrs->x_op == XDR_ENCODE) {
535 buf = XDR_INLINE (xdrs, 3 * BYTES_PER_XDR_UNIT);
537 if (!xdr_long (xdrs, &objp->clientId))
539 if (!xdr_bool (xdrs, &objp->lockDevice))
541 if (!xdr_u_long (xdrs, &objp->lock_timeout))
545 IXDR_PUT_INT32(buf, objp->clientId);
546 IXDR_PUT_BOOL(buf, objp->lockDevice);
547 IXDR_PUT_U_INT32(buf, objp->lock_timeout);
549 if (!xdr_string (xdrs, &objp->device, ~0))
552 }
else if (xdrs->x_op == XDR_DECODE) {
553 buf = XDR_INLINE (xdrs, 3 * BYTES_PER_XDR_UNIT);
555 if (!xdr_long (xdrs, &objp->clientId))
557 if (!xdr_bool (xdrs, &objp->lockDevice))
559 if (!xdr_u_long (xdrs, &objp->lock_timeout))
563 objp->clientId = IXDR_GET_INT32(buf);
564 objp->lockDevice = IXDR_GET_BOOL(buf);
565 objp->lock_timeout = IXDR_GET_U_INT32(buf);
567 if (!xdr_string (xdrs, &objp->device, ~0))
572 if (!xdr_long (xdrs, &objp->clientId))
574 if (!xdr_bool (xdrs, &objp->lockDevice))
576 if (!xdr_u_long (xdrs, &objp->lock_timeout))
578 if (!xdr_string (xdrs, &objp->device, ~0))
585 if (!xdr_Device_ErrorCode (xdrs, &objp->error))
587 if (!xdr_Device_Link (xdrs, &objp->lid))
589 if (!xdr_u_short (xdrs, &objp->abortPort))
591 if (!xdr_u_long (xdrs, &objp->maxRecvSize))
596bool_t xdr_Device_ErrorCode (XDR *xdrs, Device_ErrorCode *objp)
598 if (!xdr_long (xdrs, objp))
603bool_t xdr_Device_Link (XDR *xdrs, Device_Link *objp)
605 if (!xdr_long (xdrs, objp))
610int agilent_init(
CLINK *clink) {
612 ret=vxi11_send(clink,
":SYSTEM:HEADER 0");
614 printf(
"Error: vxi11_send_and_receive: could not send cmd.\n");
615 printf(
" The function vxi11_send returned %d. ",ret);
618 vxi11_send(clink,
":ACQUIRE:COMPLETE 100");
620 vxi11_send(clink,
":WAVEFORM:BYTEORDER LSBFIRST");
622 vxi11_send(clink,
":WAVEFORM:BYTEORDER MSBFIRST");
624 vxi11_send(clink,
":WAVEFORM:FORMAT BINARY");
628int vxi11_send(
CLINK *clink,
const char *cmd) {
629 return vxi11_send(clink, cmd, strlen(cmd));
632int vxi11_send(
CLINK *clink,
const char *cmd,
unsigned long len) {
633 return vxi11_send(clink->client, clink->link, cmd, len);
636int vxi11_send(CLIENT *client, VXI11_LINK *link,
const char *cmd) {
637 return vxi11_send(client, link, cmd, strlen(cmd));
640int vxi11_send(CLIENT *client, VXI11_LINK *link,
const char *cmd,
unsigned long len) {
642 int bytes_left = (int)len;
645 send_cmd =
new char[len];
646 memcpy(send_cmd, cmd, len);
648 write_parms.lid = link->lid;
649 write_parms.io_timeout = VXI11_DEFAULT_TIMEOUT;
650 write_parms.lock_timeout = VXI11_DEFAULT_TIMEOUT;
657 memset(&write_resp, 0,
sizeof(write_resp));
659 if ((
unsigned int)bytes_left <= link->maxRecvSize) {
660 write_parms.flags = 8;
661 write_parms.data.data_len = bytes_left;
664 write_parms.flags = 0;
669 if (link->maxRecvSize > 0) {
670 write_parms.data.data_len = link->maxRecvSize;
673 write_parms.data.data_len = 4096;
676 write_parms.data.data_val = send_cmd + (len - bytes_left);
678 if(device_write_1(&write_parms, &write_resp, client) != RPC_SUCCESS) {
680 return -VXI11_NULL_WRITE_RESP;
686 if (write_resp . error != 0) {
687 printf(
"vxi11_user: write error: %d\n",(
int)(write_resp . error));
689 return -(write_resp . error);
691 bytes_left -= write_resp . size;
692 }
while (bytes_left > 0);
700 return (clnt_call(clnt, device_write,
701 (xdrproc_t) xdr_Device_WriteParms, (caddr_t) argp,
702 (xdrproc_t) xdr_Device_WriteResp, (caddr_t) clnt_res,
708 if (!xdr_Device_Link (xdrs, &objp->lid))
710 if (!xdr_u_long (xdrs, &objp->io_timeout))
712 if (!xdr_u_long (xdrs, &objp->lock_timeout))
714 if (!xdr_Device_Flags (xdrs, &objp->flags))
716 if (!xdr_bytes (xdrs, (
char **)&objp->data.data_val, (u_int *) &objp->data.data_len, ~0))
723 if (!xdr_Device_ErrorCode (xdrs, &objp->error))
725 if (!xdr_u_long (xdrs, &objp->size))
730bool_t xdr_Device_Flags (XDR *xdrs, Device_Flags *objp)
732 if (!xdr_long (xdrs, objp))
737int agilent_set_averages(
CLINK *clink,
int no_averages) {
740 if (no_averages <= 0) {
741 return vxi11_send(clink,
":ACQ:AVER 0");
744 sprintf(cmd,
":ACQ:COUNT %d", no_averages);
745 vxi11_send(clink, cmd);
746 return vxi11_send(clink,
":ACQ:AVER 1");
750void agilent_set_for_auto(
CLINK *clink) {
751 vxi11_send(clink,
":ACQ:SRAT:AUTO 1;:ACQ:POINTS:AUTO 1;:RUN");
755int vxi11_close_device(
const char *ip,
CLINK *clink) {
760 for (l=0; l<VXI11_MAX_CLIENTS; l++){
761 if (strcmp(ip,VXI11_IP_ADDRESS[l]) == 0 ) {
766 if (device_no == -1) {
767 printf(
"vxi11_close_device: error: I have no record of you ever opening device\n");
768 printf(
" with IP address %s\n",ip);
773 if (VXI11_LINK_COUNT[device_no] > 1 ) {
774 ret = vxi11_close_link(ip,clink->client, clink->link);
775 VXI11_LINK_COUNT[device_no]--;
780 ret = vxi11_close_device(ip, clink->client, clink->link);
786int vxi11_close_device(
const char *ip, CLIENT *client, VXI11_LINK *link) {
789 ret = vxi11_close_link(ip, client, link);
791 clnt_destroy(client);
796int vxi11_close_link(
const char *ip, CLIENT *client, VXI11_LINK *link) {
798 memset(&dev_error, 0,
sizeof(dev_error));
800 if (destroy_link_1(&link->lid, &dev_error, client) != RPC_SUCCESS) {
802 clnt_perror(client,(
char*)ip);
804 clnt_perror(client,ip);
812enum clnt_stat destroy_link_1(Device_Link *argp,
Device_Error *clnt_res, CLIENT *clnt)
814 return (clnt_call(clnt, destroy_link,
815 (xdrproc_t) xdr_Device_Link, (caddr_t) argp,
816 (xdrproc_t) xdr_Device_Error, (caddr_t) clnt_res,
822 if (!xdr_Device_ErrorCode (xdrs, &objp->error))
827double vxi11_obtain_double_value(
CLINK *clink,
const char *cmd) {
828 return vxi11_obtain_double_value(clink, cmd, VXI11_READ_TIMEOUT);
831double vxi11_obtain_double_value(
CLINK *clink,
const char *cmd,
unsigned long timeout) {
835 if (vxi11_send_and_receive(clink, cmd, buf, 50, timeout) != 0) {
836 printf(
"Returning 0.0\n");
839 val = strtod(buf, (
char **)NULL);
843long vxi11_send_and_receive(
CLINK *clink,
const char *cmd,
char *buf,
unsigned long buf_len,
unsigned long timeout) {
847 ret = vxi11_send(clink, cmd);
849 if (ret != -VXI11_NULL_WRITE_RESP) {
850 printf(
"Error: vxi11_send_and_receive: could not send cmd.\n");
851 printf(
" The function vxi11_send returned %d. ",ret);
854 else printf(
"(Info: VXI11_NULL_WRITE_RESP in vxi11_send_and_receive, resending query)\n");
857 bytes_returned = vxi11_receive(clink, buf, buf_len, timeout);
858 if (bytes_returned <= 0) {
859 if (bytes_returned >-VXI11_NULL_READ_RESP) {
860 printf(
"Error: vxi11_send_and_receive: problem reading reply.\n");
861 printf(
" The function vxi11_receive returned %ld. ",bytes_returned);
864 else printf(
"(Info: VXI11_NULL_READ_RESP in vxi11_send_and_receive, resending query)\n");
866 }
while (bytes_returned == -VXI11_NULL_READ_RESP || ret == -VXI11_NULL_WRITE_RESP);
870long vxi11_receive(CLIENT *client, VXI11_LINK *link,
char *buffer,
unsigned long len,
unsigned long timeout) {
875 read_parms.lid = link->lid;
876 read_parms.requestSize = len;
877 read_parms.io_timeout = timeout;
878 read_parms.lock_timeout = timeout;
879 read_parms.flags = 0;
880 read_parms.termChar = 0;
883 memset(&read_resp, 0,
sizeof(read_resp));
885 read_resp.data.data_val = buffer + curr_pos;
886 read_parms.requestSize = len - curr_pos;
888 if(device_read_1(&read_parms, &read_resp, client) != RPC_SUCCESS) {
889 return -VXI11_NULL_READ_RESP;
893 if (read_resp . error != 0) {
903 printf(
"vxi11_user: read error: %d\n",(
int)(read_resp . error));
904 return -(read_resp . error);
907 if((
unsigned long)(curr_pos + read_resp . data.data_len) <= len) {
908 curr_pos += read_resp . data.data_len;
910 if( (read_resp.reason & RCV_END_BIT) || (read_resp.reason & RCV_CHR_BIT) ) {
913 else if( (
unsigned long)curr_pos == len ) {
914 printf(
"xvi11_user: read error: buffer too small. Read %ld bytes without hitting terminator.\n", curr_pos );
922long vxi11_receive(
CLINK *clink,
char *buffer,
unsigned long len) {
923 return vxi11_receive(clink, buffer, len, VXI11_READ_TIMEOUT);
926long vxi11_receive(
CLINK *clink,
char *buffer,
unsigned long len,
unsigned long timeout) {
927 return vxi11_receive(clink->client, clink->link, buffer, len, timeout);
932 return (clnt_call(clnt, device_read,
933 (xdrproc_t) xdr_Device_ReadParms, (caddr_t) argp,
934 (xdrproc_t) xdr_Device_ReadResp, (caddr_t) clnt_res,
940#if defined(SOLARIS) && !defined(_LP64)
943 register int32_t *buf;
946 if (xdrs->x_op == XDR_ENCODE) {
947 if (!xdr_Device_Link (xdrs, &objp->lid))
949 buf = XDR_INLINE (xdrs, 3 * BYTES_PER_XDR_UNIT);
951 if (!xdr_u_long (xdrs, &objp->requestSize))
953 if (!xdr_u_long (xdrs, &objp->io_timeout))
955 if (!xdr_u_long (xdrs, &objp->lock_timeout))
959 IXDR_PUT_U_INT32(buf, objp->requestSize);
960 IXDR_PUT_U_INT32(buf, objp->io_timeout);
961 IXDR_PUT_U_INT32(buf, objp->lock_timeout);
963 if (!xdr_Device_Flags (xdrs, &objp->flags))
965 if (!xdr_char (xdrs, &objp->termChar))
968 }
else if (xdrs->x_op == XDR_DECODE) {
969 if (!xdr_Device_Link (xdrs, &objp->lid))
971 buf = XDR_INLINE (xdrs, 3 * BYTES_PER_XDR_UNIT);
973 if (!xdr_u_long (xdrs, &objp->requestSize))
975 if (!xdr_u_long (xdrs, &objp->io_timeout))
977 if (!xdr_u_long (xdrs, &objp->lock_timeout))
981 objp->requestSize = IXDR_GET_U_INT32(buf);
982 objp->io_timeout = IXDR_GET_U_INT32(buf);
983 objp->lock_timeout = IXDR_GET_U_INT32(buf);
985 if (!xdr_Device_Flags (xdrs, &objp->flags))
987 if (!xdr_char (xdrs, &objp->termChar))
992 if (!xdr_Device_Link (xdrs, &objp->lid))
994 if (!xdr_u_long (xdrs, &objp->requestSize))
996 if (!xdr_u_long (xdrs, &objp->io_timeout))
998 if (!xdr_u_long (xdrs, &objp->lock_timeout))
1000 if (!xdr_Device_Flags (xdrs, &objp->flags))
1002 if (!xdr_char (xdrs, &objp->termChar))
1009 if (!xdr_Device_ErrorCode (xdrs, &objp->error))
1011 if (!xdr_long (xdrs, &objp->reason))
1013 if (!xdr_bytes (xdrs, (
char **)&objp->data.data_val, (u_int *) &objp->data.data_len, ~0))
1018long vxi11_obtain_long_value(
CLINK *clink,
const char *cmd,
unsigned long timeout) {
1021 if (vxi11_send_and_receive(clink, cmd, buf, 50, timeout) != 0) {
1022 printf(
"Returning 0\n");
1025 return strtol(buf, (
char **)NULL, 10);
1029long vxi11_obtain_long_value(
CLINK *clink,
const char *cmd) {
1030 return vxi11_obtain_long_value(clink, cmd, VXI11_READ_TIMEOUT);
1033long agilent_get_data(
CLINK *clink,
char chan,
char *buf,
unsigned long buf_len,
unsigned long timeout) {
1034 return agilent_get_data(clink, chan, 1, buf, buf_len, timeout);
1037long agilent_get_data(
CLINK *clink,
char chan,
int digitise,
char *buf,
unsigned long buf_len,
unsigned long timeout) {
1041 long bytes_returned;
1043 memset(source,0,20);
1044 agilent_scope_channel_str(chan, source);
1045 sprintf(cmd,
":WAV:SOURCE %s",source);
1046 ret=vxi11_send(clink, cmd);
1048 printf(
"error, could not send :WAV:SOURCE %s cmd, quitting...\n",source);
1052 if (digitise != 0) {
1053 ret=vxi11_send(clink,
":DIG");
1057 ret=vxi11_send(clink,
":WAV:DATA?");
1058 bytes_returned=vxi11_receive_data_block(clink, buf, buf_len, timeout);
1059 }
while (bytes_returned == -VXI11_NULL_READ_RESP);
1061 return bytes_returned;
1064int agilent_get_preamble(
CLINK *clink,
char* buf,
unsigned long buf_len) {
1066 long bytes_returned;
1068 ret=vxi11_send(clink,
":WAV:PRE?");
1070 printf(
"error, could not send :WAV:PRE? cmd, quitting...\n");
1074 bytes_returned=vxi11_receive(clink, buf, buf_len);
1076 return (
int) bytes_returned;
1079void agilent_scope_channel_str(
char chan,
char *source) {
1082 case 'a' : strcpy(source,
"FUNC1");
1085 case 'b' : strcpy(source,
"FUNC2");
1088 case 'c' : strcpy(source,
"FUNC3");
1091 case 'd' : strcpy(source,
"FUNC4");
1093 case '1' : strcpy(source,
"CHAN1");
1095 case '2' : strcpy(source,
"CHAN2");
1097 case '3' : strcpy(source,
"CHAN3");
1099 case '4' : strcpy(source,
"CHAN4");
1101 default : printf(
"error: unknown channel '%c', using channel 1\n",chan);
1102 strcpy(source,
"CHAN1");
1107long vxi11_receive_data_block(
CLINK *clink,
char *buffer,
unsigned long len,
unsigned long timeout) {
1110 unsigned long necessary_buffer_size;
1114 unsigned long returned_bytes;
1117 necessary_buffer_size=len+12;
1118 in_buffer=
new char[necessary_buffer_size];
1119 ret=vxi11_receive(clink, in_buffer, necessary_buffer_size, timeout);
1120 if (ret < 0)
return ret;
1121 if (in_buffer[0] !=
'#') {
1122 printf(
"vxi11_user: data block error: data block does not begin with '#'\n");
1123 printf(
"First 20 characters received were: '");
1125 printf(
"%c",in_buffer[l]);
1132 sscanf(in_buffer,
"#%1d",&ndigits);
1136 sprintf(scan_cmd,
"#%%1d%%%dlu",ndigits);
1137 sscanf(in_buffer,scan_cmd,&ndigits,&returned_bytes);
1138 memcpy(buffer, in_buffer+(ndigits+2), returned_bytes);
1140 return (
long) returned_bytes;
1145int agilent_set_for_capture(
CLINK *clink,
double s_rate,
long npoints,
unsigned long timeout) {
1146 long actual_npoints;
1150 double expected_s_rate;
1151 double actual_s_rate;
1154 char etim_result[256];
1156 int not_enough_memory = 0;
1164 vxi11_send_and_receive(clink,
":ACQ:MODE?", etim_result, 256, VXI11_READ_TIMEOUT);
1167 if (strncmp(
"ETIM",etim_result,4) == 0) {
1169 time_range = vxi11_obtain_double_value(clink,
":TIM:RANGE?");
1172 auto_npoints = vxi11_obtain_long_value(clink,
":ACQ:POINTS?");
1175 vxi11_send(clink,
":ACQ:POINTS:AUTO 0");
1178 npoints = auto_npoints;
1184 sprintf(cmd,
":ACQ:POINTS %ld",(2*npoints)-1);
1185 vxi11_send(clink, cmd);
1189 vxi11_send(clink,
":DIG");
1192 xinc = vxi11_obtain_double_value(clink,
":WAV:XINC?", timeout);
1195 actual_npoints = (long) ( (time_range / xinc) + 0.5);
1199 sprintf(cmd,
":ACQ:POINTS %ld",actual_npoints);
1200 vxi11_send(clink, cmd);
1208 sprintf(cmd,
":ACQ:SRAT %G", (1/xinc));
1209 vxi11_send(clink, cmd);
1226 auto_srat = vxi11_obtain_double_value(clink,
":ACQ:SRAT?");
1229 vxi11_send(clink,
":ACQ:SRAT:AUTO 0;:ACQ:POINTS:AUTO 0");
1232 time_range = vxi11_obtain_double_value(clink,
":TIM:RANGE?");
1242 s_rate = (double) npoints / time_range;
1249 expected_s_rate = s_rate;
1257 sprintf(cmd,
":ACQ:SRAT %G",s_rate);
1258 vxi11_send(clink, cmd);
1261 actual_s_rate = vxi11_obtain_double_value(clink,
":ACQ:SRAT?");
1264 npoints = (long) ((time_range * actual_s_rate)+0.5);
1269 sprintf(cmd,
":ACQ:POINTS %ld",npoints);
1270 vxi11_send(clink, cmd);
1273 actual_npoints = vxi11_obtain_long_value(clink,
":ACQ:POINTS?");
1275 if (actual_npoints < npoints) {
1276 not_enough_memory = 1;
1278 s_rate = s_rate * 0.75 * (double) ( (
double) actual_npoints / (
double) npoints );
1281 not_enough_memory = 0;
1283 }
while (not_enough_memory == 1);
1286 if (actual_s_rate != expected_s_rate) {
1289 if (ret_val == -1) {
1301long agilent_calculate_no_of_bytes(
CLINK *clink,
char chan,
unsigned long timeout) {
1304 double hinterval,time_range;
1307 char etim_result[256];
1311 agilent_scope_channel_str(chan, source);
1312 sprintf(cmd,
":WAV:SOURCE %s",source);
1313 vxi11_send(clink, cmd);
1314 vxi11_send(clink,
":DIG");
1317 hinterval = vxi11_obtain_double_value(clink,
":WAV:XINC?", timeout);
1318 time_range = vxi11_obtain_double_value(clink,
":TIM:RANGE?");
1322 vxi11_send_and_receive(clink,
":ACQ:MODE?", etim_result, 256, VXI11_READ_TIMEOUT);
1324 if (strncmp(
"ETIM",etim_result,4) == 0) {
1325 no_of_bytes = (long) ( 2*((time_range / hinterval) + 0.5) );
1328 srat = vxi11_obtain_double_value(clink,
":ACQ:SRAT?");
1330 no_of_bytes = (long) (2*(((time_range-(1/srat)) / hinterval)+1) + 0.5);
SDDS (Self Describing Data Set) Data Types Definitions and Function Prototypes.
int32_t SDDS_IsBigEndianMachine()
Determines whether the current machine uses big-endian byte ordering.