/* gcc -Wall -c -I /home/jum/alice/vxi11/vxi11-master/library/ vxi11-data.c gcc -o vxi11-data vxi11-data.o -L /home/jum/alice/vxi11/vxi11-master/library/ -llibvxi11.so.1 */ #include #include #include /* String function definitions */ #include "vxi11_user.h" #define MAX_ITEM 131072 #define BUFFER_SIZE 6 * MAX_ITEM #define MAX_VALUE 16382 int readscv(int *items,char *filename,unsigned short *data); int readscv(int *items,char *filename,unsigned short *data) { FILE *fin; char inbuf[BUFFER_SIZE]; char *tok; int item, line, value; if ((fin = fopen(filename,"r")) == NULL) { printf("Could not open file %s\n",filename); return 1; } line = 0; while (fgets(inbuf,BUFFER_SIZE-1,fin) != NULL) { inbuf[BUFFER_SIZE] = 0; if((strlen(inbuf) != 0) && (strlen(inbuf) < BUFFER_SIZE)) { if (inbuf[0] != '#') { item = 0; for (tok = strtok(inbuf, ";"); (tok && *tok) && (item < MAX_ITEM); tok = strtok(NULL, ";\n")) { value = atoi(tok); if ((value < 0) || (value > MAX_VALUE)) { printf("ERROR: line %d item %d value must be 0-%d, is %d\n",line,item,MAX_VALUE,value); fclose(fin); return 1; } data[item] += value; if (data[item] > MAX_VALUE) { printf("ERROR: line %d item %d summed value must be 0-%d, is %d\n",line,item,MAX_VALUE,data[item]); fclose(fin); return 1; } item++; } } if (item > *items) *items = item; line++; } else { printf("ERROR: line %d too long\n",line); fclose(fin); return 1; } } fclose(fin); printf("Lines read %d items %d\n",line,*items); return 0; } int main(int argc, char *argv[]) { static char *device_ip; VXI11_CLINK *clink; unsigned short data[MAX_ITEM]; unsigned char *ptr,*buffer; int items = 0; int j; if (argc < 3) { printf("usage: %s your.inst.ip.addr csvfilename\n", argv[0]); exit(1); } device_ip = argv[1]; printf("Open device %s\n",device_ip); if(vxi11_open_device(&clink, device_ip, NULL)){ printf("Error: could not open device %s, quitting\n", device_ip); exit(2); } memset(data,0,sizeof(data)); if (readscv(&items,argv[2],data) != 0) exit(1); buffer = (unsigned char *)malloc(items << 1); ptr = buffer; for (j = 0; j < items; j++) { *ptr++ = data[j] >> 8; *ptr++ = data[j] & 0xFF; } vxi11_send_data_block(clink,"TRACE:DATA EMEMORY,", (char *)buffer,items<<1); vxi11_close_device(clink, device_ip); ptr = buffer; for (j = 0; j < items; j++) { printf(" %6d[%02X%02X]",(int)data[j],*ptr,*(ptr+1)); ptr += 2; if (((j+1) % 8) == 0) putchar('\n'); } putchar('\n'); free(buffer); return 0; }