Details | Last modification | View Log | RSS feed
| Rev | Author | Line No. | Line |
|---|---|---|---|
| 145 | f9daq | 1 | /* vxi11_cmd.c |
| 2 | * Copyright (C) 2006 Steve D. Sharples |
||
| 3 | * |
||
| 4 | * A simple interactive utility that allows you to send commands and queries to |
||
| 5 | * a device enabled with the VXI11 RPC ethernet protocol. Uses the files |
||
| 6 | * generated by rpcgen vxi11.x, and the vxi11_user.h user libraries. |
||
| 7 | * |
||
| 8 | * This program is free software; you can redistribute it and/or |
||
| 9 | * modify it under the terms of the GNU General Public License |
||
| 10 | * as published by the Free Software Foundation; either version 2 |
||
| 11 | * of the License, or (at your option) any later version. |
||
| 12 | * |
||
| 13 | * This program is distributed in the hope that it will be useful, |
||
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
||
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||
| 16 | * GNU General Public License for more details. |
||
| 17 | * |
||
| 18 | * You should have received a copy of the GNU General Public License |
||
| 19 | * along with this program; if not, write to the Free Software |
||
| 20 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
||
| 21 | * |
||
| 22 | * The author's email address is steve.sharples@nottingham.ac.uk |
||
| 23 | */ |
||
| 24 | |||
| 25 | #include "vxi11_user.h" |
||
| 26 | #define BUF_LEN 100000 |
||
| 27 | |||
| 28 | int main(int argc, char *argv[]) { |
||
| 29 | |||
| 30 | static char *device_ip; |
||
| 31 | static char *device_name; |
||
| 32 | char cmd[256]; |
||
| 33 | char buf[BUF_LEN]; |
||
| 34 | int ret; |
||
| 35 | long bytes_returned; |
||
| 36 | CLINK *clink; |
||
| 37 | |||
| 38 | clink = new CLINK; |
||
| 39 | |||
| 40 | if (argc < 2) { |
||
| 41 | printf("usage: %s your.inst.ip.addr [device_name]\n",argv[0]); |
||
| 42 | exit(1); |
||
| 43 | } |
||
| 44 | |||
| 45 | device_ip = argv[1]; |
||
| 46 | if (argc > 2) { |
||
| 47 | device_name = argv[2]; |
||
| 48 | ret=vxi11_open_device(device_ip,clink,device_name); |
||
| 49 | } |
||
| 50 | else { |
||
| 51 | ret=vxi11_open_device(device_ip,clink); |
||
| 52 | } |
||
| 53 | |||
| 54 | if (ret != 0) { |
||
| 55 | printf("Error: could not open device %s, quitting\n",device_ip); |
||
| 56 | exit(2); |
||
| 57 | } |
||
| 58 | |||
| 59 | while(1){ |
||
| 60 | memset(cmd, 0, 256); // initialize command string |
||
| 61 | memset(buf, 0, BUF_LEN); // initialize buffer |
||
| 62 | printf("Input command or query ('q' to exit): "); |
||
| 63 | fgets(cmd,256,stdin); |
||
| 64 | cmd[strlen(cmd)-1] = 0; // just gets rid of the \n |
||
| 65 | if (strncasecmp(cmd, "q",1) == 0) break; |
||
| 66 | |||
| 67 | if (vxi11_send(clink, cmd) < 0) break; |
||
| 68 | if (strstr(cmd, "?") != 0) { |
||
| 69 | bytes_returned = vxi11_receive(clink, buf, BUF_LEN); |
||
| 70 | if (bytes_returned > 0) { |
||
| 71 | printf("%s\n",buf); |
||
| 72 | } |
||
| 73 | else if (bytes_returned == -15) { |
||
| 74 | printf("*** [ NOTHING RECEIVED ] ***\n"); |
||
| 75 | } |
||
| 76 | else break; |
||
| 77 | } |
||
| 78 | } |
||
| 79 | |||
| 80 | ret=vxi11_close_device(device_ip,clink); |
||
| 81 | return 0; |
||
| 82 | } |
||
| 83 |