int vxi11_close_device(const char *ip, CLINK *clink) { int l,ret; int device_no = -1; /* Which instrument are we referring to? */ for (l=0; l<VXI11_MAX_CLIENTS; l++){ if (strcmp(ip,VXI11_IP_ADDRESS[l]) == 0 ) { device_no=l; } } /* Something's up if we can't find the IP address! */ if (device_no == -1) { printf("vxi11_close_device: error: I have no record of you ever opening device\n"); printf(" with IP address %s\n",ip); ret = -4; } else { /* Found the IP, there's more than one link to that instrument, * so keep track and just close the link */ if (VXI11_LINK_COUNT[device_no] > 1 ) { ret = vxi11_close_link(ip,clink->client, clink->link); VXI11_LINK_COUNT[device_no]--; } /* Found the IP, it's the last link, so close the device (link * AND client) */ else { ret = vxi11_close_device(ip, clink->client, clink->link); } } return ret; }
int main(int argc,char **argv) { static char *progname; static char *serverIP; char comm[256]; long bytes_returned; BOOL got_ip=FALSE; BOOL got_comm=FALSE; int index=1; CLINK *clink; /* client link (actually a structure contining CLIENT and VXI11_LINK pointers) */ char outputbuf[BUF_LEN]; clink = new CLINK; /* allocate some memory */ progname = argv[0]; while(index<argc){ if(sc(argv[index],(char*)"-ip")||sc(argv[index],(char*)"-ip_address")||sc(argv[index],(char*)"-IP")){ serverIP = argv[++index]; got_ip = TRUE; } if(sc(argv[index],(char*)"-command")||sc(argv[index],(char*)"-c")||sc(argv[index],(char*)"-comm")){ snprintf(comm,256,"%s",argv[++index]); got_comm=TRUE; } index++; } if(got_ip==FALSE||got_comm==FALSE){ printf("%s: sends commands to an Agilent scope via ethernet\n",progname); printf("Run using %s [arguments]\n\n",progname); printf("REQUIRED ARGUMENTS:\n"); printf("-ip -ip_address -IP : IP address of scope (eg 128.243.74.232)\n"); printf("-c -command -comm : command or query to send\n\n"); printf("DOCUMENTATION:\n"); printf("http://cp.literature.agilent.com/litweb/pdf/54855-97017.pdf\n"); exit(1); } if (vxi11_open_device(serverIP,clink) != 0) { printf("Quitting...\n"); exit(2); } vxi11_send(clink, comm); if (strstr(comm, "?") != 0) { bytes_returned = vxi11_receive(clink, outputbuf, BUF_LEN); vxi11_close_device(serverIP,clink); if (bytes_returned > 0) { printf("%s",outputbuf); } else if (bytes_returned == -15) { printf("Error: Nothing received after sending scope command %s\n", comm); return(1); } } else { vxi11_close_device(serverIP,clink); } }
/* Again, just a wrapper */ int lecroy_close(VXI11_CLINK * clink, const char *ip) { vxi11_send_printf(clink, "MSG"); /* remove message on bottom of screen */ return vxi11_close_device(clink, ip); }