int l2415___store(struct descriptor *niddsc, InStoreStruct *setup) { static int polarity_nid; static int range_nid; static int volt_out_nid; static int curr_out_nid; static DESCRIPTOR_NID(polarity_dsc,&polarity_nid); static DESCRIPTOR_NID(range_dsc,&range_nid); static struct descriptor_xd out_xd = {0, DTYPE_DSC, CLASS_XD, 0, 0}; int status=1; static short voltage; static struct descriptor voltage_dsc = {sizeof(short), DTYPE_W, CLASS_S, (char *)&voltage}; static DESCRIPTOR(volt_expr, "BUILD_WITH_UNITS($ * $ * ($ == 3500. ? 1. : 2.), 'Volts')"); static short current; static struct descriptor current_dsc = {sizeof(short), DTYPE_W, CLASS_S, (char *)¤t}; static DESCRIPTOR(current_expr, "BUILD_WITH_UNITS($ * ( $ == 3500. ? .0025/4096. : .001/4096.) , 'Amps')"); polarity_nid = setup->head_nid + L2415_N_POLARITY; range_nid = setup->head_nid + L2415_N_RANGE; pio(26,0,0); /* convert output voltage to digital */ qrep(0,0,1,&voltage); /* read it when we get q back */ TdiCompile(&volt_expr, &voltage_dsc, &polarity_dsc, &range_dsc, &out_xd MDS_END_ARG); volt_out_nid = setup->head_nid + L2415_N_VOLT_OUT; return_on_error(TreePutRecord(volt_out_nid, (struct descriptor *)&out_xd, 0), status); pio(26,1,0); /* convert output current to digital */ qrep(0,0,1,¤t); /* read it when we get q back */ TdiCompile(¤t_expr, ¤t_dsc, &range_dsc, &out_xd MDS_END_ARG); curr_out_nid = setup->head_nid + L2415_N_CURR_OUT; return_on_error(TreePutRecord(curr_out_nid, (struct descriptor *)&out_xd, 0), status); /* turn it off */ /* pio(16,0,0) pio(16,1,0) */ return 1; }
int joerger_adcp___store(struct descriptor *nid_dsc, InStoreStruct *setup) { int status; int chan; static int c_nids[JOERGER_ADCP_K_CONG_NODES]; static DESCRIPTOR(output_expr, "$*$"); static short int buffer[16]; static DESCRIPTOR_A(buffer_dsc, sizeof(short int), DTYPE_W, &buffer, sizeof(buffer)); static float coef; static DESCRIPTOR_FLOAT(coef_dsc, &coef); static struct descriptor_xd output_xd = {0, DTYPE_DSC, CLASS_XD, 0, 0}; static float coefs[] = {20.48/4096, 10.24/4096, 10.24/4096, 5.12/4096}; struct _op_mode { unsigned int mode:2; unsigned int coef:2; unsigned int cont:1; unsigned int :11; } operating_mode; return_on_error(DevNids(nid_dsc,sizeof(c_nids),c_nids)); if (setup->no_trig) { float wait = 10E-6*16; pio(26, 0, 0); return_on_error(DevWait(wait)); } for (chan=0; chan<16; chan++) pio(0,chan,&buffer[chan]); pio(1,15, (short *)&operating_mode); coef = coefs[operating_mode.coef]; return_on_error(TdiCompile(&output_expr, &buffer_dsc, &coef_dsc, &output_xd MDS_END_ARG)); status = TreePutRecord(c_nids[JOERGER_ADCP_N_INPUTS], (struct descriptor *)&output_xd,0); return status; }
static int get_var_nbytes(void *self, const char *name, int *nbytes) { int id, size, itemsize; return_on_error(get_var_grid(self, name, &id)); return_on_error(get_grid_size(self, id, &size)); return_on_error(get_var_itemsize(self, name, &itemsize)); *nbytes = itemsize * size; return BMI_SUCCESS; }
int fera___init(struct descriptor_s *niddsc_ptr, InInitStruct *setup ) { int status=1; int num_dig; int num_mem; #define return_on_error(f,retstatus) if (!((status = f) & 1)) return retstatus; last_nid = 0; /* Reset the controler */ return_on_error(DevCamChk(CamPiow(setup->cntrl_name,0,9,0,16,0),&one,&one),status); /* setup the digitizers */ if((num_dig = NElements(setup->head_nid + FERA_N_DIG_NAME))) { int i; for(i=0; i<num_dig; i++) { char *name = ArrayRef(setup->head_nid + FERA_N_DIG_NAME, i); if(name) { static short ecl_cam = 0x2400; return_on_error(DevCamChk(CamPiow(name,0,9,0,16,0),&one,&one),status); /* reset digitizer */ return_on_error(DevCamChk(CamPiow(name,0,16, &ecl_cam, 16, 0),&one,&one),status); /* goto ECL/CAM mode */ } else { status = FERA$_DIGNOTSTRARRAY; break; } } } else status = FERA$_NODIG; /* setup the memory modules */ if (status&1) { if ((num_mem = NElements(setup->head_nid + FERA_N_MEM_NAME)) ) { int i; for(i=0; i<num_mem; i++) { char *name = ArrayRef(setup->head_nid + FERA_N_MEM_NAME, i); if(name) { return_on_error(DevCamChk(CamPiow(name, 1, 17, &one, 16, 0),&one,&one),status); return_on_error(DevCamChk(CamPiow(name, 0, 24, 0, 16, 0),&one,&one),status); return_on_error(DevCamChk(CamPiow(name, 0, 17, &zero, 16, 0),&one,&one),status); return_on_error(DevCamChk(CamPiow(name, 1, 17, &three, 16, 0),&one,&one),status); } else { status = FERA$_MEMNOTSTRARRAY; break; } } } else status = FERA$_NOMEM; } /* Reset the controler */ return_on_error(DevCamChk(CamPiow(setup->cntrl_name, 0, 9, 0, 16, 0),&one,&one),status); return status; }
static int ReadChannel(char *name, int chan, int *samples_ptr, short *data_ptr) { int tries; int status; int samples_read = 0; int samples_to_read = *samples_ptr; int read_size; short int dummy; pio(16,5,&zero,1); pio(16,6,&zero,1); pio(16,7,&zero,1); { short int a = chan+1; pio(18,a, &zero, 1); } wait; pio(2,0,&dummy,1); /* throw one out for good measure */ for(samples_to_read = *samples_ptr; samples_to_read; samples_to_read -= read_size) { read_size = min(32767, samples_to_read); return_on_error(DevCamChk(CamQstopw(name,0,2,read_size,data_ptr+samples_read,16,0),&one,0)); samples_read += read_size; } pio(25,1,0,1); /* abort the read of this channel */ pio(2,0,&dummy,0); /* throw one out for good measure */ return 1; }
int l8590_mem___init(struct descriptor_s *niddsc_ptr, InInitStruct *setup) { static DESCRIPTOR(sclr_wild, "L8590_%"); int status; int old_def; void *ctx; int setup_status = 0; static InGet_setupStruct sclr_setup; static int sclr_nid; static DESCRIPTOR_NID(sclr_niddsc,&sclr_nid); TreeGetDefaultNid(&old_def); TreeSetDefaultNid(*(int *)niddsc_ptr->pointer); for (ctx=0; TreeFindNodeWild("L85090_%", &sclr_nid, &ctx, -1)&1;) { setup_status = l8590_sclr___get_setup(&sclr_niddsc,&sclr_setup); if (setup_status & 1) { pio(sclr_setup.name,9,0,0); pio(sclr_setup.name,10,0,0); pio(sclr_setup.name,18,0,&sclr_setup.num_active_convert); pio(sclr_setup.name,26,0,0); pio(sclr_setup.name,18,0,&sclr_setup.num_active_convert); pio(sclr_setup.name,26,0,0); GenDeviceFree(&sclr_setup); } else { return_on_error(setup_status,status); } } pio(setup->name,9,0,0); pio(setup->name,25,0,0); pio(setup->name,11,0,0); TreeSetDefaultNid(old_def); return status; }
int mdsdcl___execute(struct descriptor_s *niddsc_ptr, InExecuteStruct *setup) { int status; char *line; for (line=strtok(setup->verbs,"\n");line;line=strtok(0,"\n")) { char cmd[128]; strcpy(cmd,"set command "); strcat(cmd,line); return_on_error(mdsdcl_do_command(cmd),status); } for (line=strtok(setup->commands,"\n");line;line=strtok(0,"\n")) { if (strlen(line)) return_on_error(mdsdcl_do_command(line),status); } return status; }
int l8201___init(struct descriptor *niddsc_ptr, InInitStruct *setup) { int status; return_on_error(TdiData(setup->download,&data MDS_END_ARG),status); pio(9,0); stop(16); pio(11,&zero); pio(26,0); return status; }
static int set_value(void *self, const char *name, void *array) { void *dest = NULL; if (get_value_ptr(self, name, &dest) == BMI_FAILURE) { return BMI_FAILURE; } else { int nbytes = 0; return_on_error(get_var_nbytes(self, name, &nbytes)); memcpy(dest, array, nbytes); return BMI_SUCCESS; } }
static int get_value(void *self, const char *name, void *dest) { void *src = NULL; if (get_value_ptr(self, name, &src) == BMI_FAILURE) { return BMI_FAILURE; } else { int nbytes; return_on_error(get_var_nbytes(self, name, &nbytes)); memcpy(dest, src, nbytes); } return BMI_SUCCESS; }
int joerger_dac16___init(struct descriptor *nid_dsc, InInitStruct *setup) { int i; static int c_nids[JOERGER_DAC16_K_CONG_NODES]; int status; unsigned int module_id; int range; short int bad_chans = 0; float *outputs; outputs = &setup->output_01; return_on_error(DevNids(nid_dsc,sizeof(c_nids),c_nids)); pio24(1, 15, &module_id); range = module_id & 3; for (i=0; i < 16; i++) { if (TreeIsOn(c_nids[JOERGER_DAC16_N_OUTPUT_01+i])&1) { switch (range) { case 0: if ((outputs[i] >= 0) && (outputs[i] <= 10)) { short int data = outputs[i]/10.0*4096; pio(16, i, &data); } else bad_chans |= 1<<i; break; case 1: if ((outputs[i] >= 0) && (outputs[i] <= 5)) { short int data = outputs[i]/5.0*4096; pio(16, i, &data); } else bad_chans |= 1<<i; break; case 2: if ((outputs[i] >= -10) && (outputs[i] <= 10)) { short int data = (outputs[i]+10)/20.0*4096; pio(16, i, &data); } else bad_chans |= 1<<i; break; case 3: if ((outputs[i] >= -5) && (outputs[i] <= 5)) { short int data = (outputs[i]+5)/10.0*4096; pio(16, i, &data); } else bad_chans |= 1<<i; break; } } } return (bad_chans != 0) ? J_DAC$_OUTRNG : 1; }
int l8206___init(struct descriptor *niddsc_ptr, InInitStruct *setup) { int status; int download_nid = setup->head_nid + L8206_N_DOWNLOAD; pio(9,0); if (TreeIsOn(download_nid) & 1) { data.arsize = sizeof(buffer); return_on_error(TdiData(setup->download,&data MDS_END_ARG),status); stop(16,16384,buffer); stop(16,16384,&buffer[16384]); stop(16,16384,&buffer[32768]); stop(16,16384,&buffer[49152]); } pio(18,&zero); pio(11,&zero); pio(26,&zero); return status; }
static int ReadChannel(InStoreStruct *setup, int *max_samps_ptr, int chan, int *samples_ptr, short *data_ptr) { short *in_ptr = data_ptr; short *end_ptr = data_ptr + *samples_ptr; int pnts_to_read; struct { unsigned short status; unsigned short bytcnt; unsigned short fill[2]; } iosb; int lamchks = 10; unsigned short dum_read; int status; pio(10,0,0); pio(16,chan,&zero); while (pnts_to_read = max(0,min(32767,end_ptr-in_ptr))) { return_on_error(DevCamChk(CamQrepw(setup->name,0,2,pnts_to_read,in_ptr,16,0),&one,0),status); CamGetStat((short *)&iosb); if ((!(CamQ((short *)&iosb)&1)) && (iosb.bytcnt == 0)) in_ptr = end_ptr; else in_ptr += iosb.bytcnt/2; } if (*max_samps_ptr != *samples_ptr) { pio(24,0,0); pio(2,0,&dum_read); pio(26,0,0); } while (lamchks) { pio(8,0,0); if (CamQ(0)&1) lamchks = 0; else lamchks--; } return 1; }
int joerger_adc___store(int *niddsc, InStoreStruct *setup) { int status; int data_nid = setup->head_nid + JOERGER_ADC_N_DATA; if (TreeIsOn(data_nid)&1) { static short raw[64]; static ARRAY_BOUNDS(short,1) raw_d = {4,DTYPE_W,CLASS_A,raw,0,0,{0,0,1,1,1},1,sizeof(raw),raw-1,32,1,32}; static int vstrap_nid; static DESCRIPTOR_NID(vstrap_d,&vstrap_nid); static EMPTYXD(xd); static DESCRIPTOR(expr,"BUILD_WITH_UNITS($ * $/4095,'VOLTS'"); int bytcnt; vstrap_nid = setup->head_nid + JOERGER_ADC_N_VSTRAP; return_on_error(DevCamChk(CamQstopw(setup->name,0,2,64,&raw,16,0),&one,0),status); bytcnt = CamBytcnt(0); raw_d.arsize = bytcnt; raw_d.m[0] = raw_d.bounds[0].u = bytcnt/2; TdiCompile(expr,&raw_d,&vstrap_d,&xd MDS_END_ARG); status = TreePutRecord(data_nid,(struct descriptor *)&xd,0); } return status; }
static int ReadChannel(InStoreStruct *setup, int chunk,int samples,unsigned short *buffer,int *samples_read,int *nid,float *calib) { int chunk_address = 0x0B000 | chunk; int points_to_read; int status=1; int tries; for (points_to_read = chunksize; status & 1 && points_to_read; points_to_read = chunksize) { struct { unsigned short status; unsigned short bytcnt; unsigned int dummy;} iosb = {0,0}; int try; static DESCRIPTOR_A(calib_a, sizeof(*calib), DTYPE_NATIVE_FLOAT, 0, 2*sizeof(*calib)); static DESCRIPTOR_NID(nid_dsc,0); void *arglist[] = {0,&nid_dsc,&calib_a MDS_END_ARG}; calib_a.pointer = (char *)calib; nid_dsc.pointer = (char *)nid; arglist[0] = (void *)(sizeof(arglist)/sizeof(arglist[0])); AccessTraq(setup,chunk_address,24,arglist,TdiData); pio(8,0,0); for (try = 0;(try < 20) && (!(CamQ(0)&1)) && (status & 1);try++) {pio(8,0,0);} pio(10,0,0); return_on_error(DevCamChk(CamQstopw(setup->name,0,2,points_to_read,buffer + *samples_read,16,(short *)&iosb),&one,0),status); status = status & 1 ? iosb.status : status; *samples_read += iosb.bytcnt/2; if (iosb.bytcnt/2 != points_to_read) break; chunk_address += max_chunks_per_io; } return status; } static int AccessTraq(InStoreStruct *setup, int data,int memsize,void *arglist,int (*routine)()) { int try; int status; int called = 0; if (max_time > 0) { if ((time(0)-start_time) > max_time) { printf("T4012 AccessTraq timeout, data=%d\n",data); return DEV$_BAD_MODE; } } piomem(17,0,&data,memsize); for (try = 0;(try < 30) && (!(CamQ(0)&1)) && (status &1);try++) { if (arglist && !called) { called = 1; LibCallg(arglist,routine); } else DevWait((float).001); piomem(17,0,&data,memsize); } if (try == 30) status = DEV$_CAM_NOSQ; if (arglist &&!called) LibCallg(arglist,routine); return status; } int t4012__dw_setup( struct descriptor *niddsc, struct descriptor *methoddsc, Widget parent) { static String uids[] = {"T4012.uid"}; static int nid; static MrmRegisterArg uilnames[] = {{"nid",(XtPointer)0},{"Load",(XtPointer)Load}}; static NCI_ITM nci[] = {{4, NciCONGLOMERATE_NIDS, (unsigned char *)&nid, 0}, {0, NciEND_OF_LIST, 0, 0}}; TreeGetNci(*(int *)niddsc->pointer, nci); uilnames[0].value = (char *)0+nid; return XmdsDeviceSetup(parent, (int *)niddsc->pointer, uids, XtNumber(uids), "T4012", uilnames, XtNumber(uilnames), 0); } static void Load(Widget w) { char *t4012name; char dignam[512]; int i; XtPointer user_data; int nid; int found = False; XtVaGetValues(w, XmNuserData, &user_data, NULL); nid = (intptr_t)user_data; t4012name = TreeGetPath(nid); strcpy(dignam,t4012name); strcat(dignam,":T28%%_"); TreeFree(t4012name); XmListDeleteAllItems(w); for (i=1;i<17;i++) { int dig_nid; int status; XmString item; int len = strlen(dignam); dignam[len++]=i<10 ? '0' : '1'; dignam[len++]='0'+(i % 10); dignam[len++]=0; status = TreeFindNode(dignam,&dig_nid); if (status & 1) { NCI_ITM itmlst[] = {{512,NciNODE_NAME,0,0},{0,0,0,0}}; itmlst[0].pointer = dignam; TreeGetNci(dig_nid,itmlst); item = XmStringCreateSimple(dignam); XmListAddItem(w, item, 0); XmStringFree(item); found = True; } else break; } if (!found) { XmString item = XmStringCreateSimple("Add T28xx_01"); XmListAddItem(w, item, 0); XmStringFree(item); } }
int t4012___store(int *niddsc, InStoreStruct *setup) { int channels; int pts; int memPerChannel; int channels_read; int dig; int dig_nid; static int memsize=0; static unsigned short *mem; int idxmin; int idxmax; char digname[512]; char *nodename; int chan_nid = 0; struct _t4012_status { unsigned sampling : 1; unsigned calibrate : 1; unsigned master_armed : 1; unsigned master_enabled : 1; unsigned stop_received : 1; unsigned triggered : 1; unsigned t4012p : 1; unsigned cal_mem : 1; unsigned : 24; } dig_status; int status; static short offset; static float coefficient; static float f[2]; static DESCRIPTOR_A_BOUNDS(raw,sizeof(short),DTYPE_W,0,1,0); static int *lbound = &raw.bounds[0].l; static int *ubound = &raw.bounds[0].u; static unsigned int *acoef = &raw.m[0]; static DESCRIPTOR_A(f2_d,sizeof(f[0]),DTYPE_NATIVE_FLOAT,f,8); static DESCRIPTOR(counts_str,"counts"); static DESCRIPTOR(volts_str,"volts"); static DESCRIPTOR(seconds_str,"seconds"); static DESCRIPTOR_LONG(start_d,&raw.bounds[0].l); static DESCRIPTOR_LONG(end_d,&raw.bounds[0].u); static int trigger_nid; static DESCRIPTOR_NID(stop_d,&trigger_nid); static int switch_trig_nid; static DESCRIPTOR_NID(swi_d,&switch_trig_nid); static int extern_clock_nid; static DESCRIPTOR_NID(ext_clock_d,&extern_clock_nid); static struct descriptor offset_d = {2,DTYPE_W, CLASS_S, (char *)&offset}; static DESCRIPTOR_FLOAT(coef_d,&coefficient); static DESCRIPTOR_FLOAT(f1_d,f); static int _roprand = 32768; static DESCRIPTOR_FLOAT(roprand,&_roprand); static FUNCTION(1) value = {2,DTYPE_FUNCTION,CLASS_R,(unsigned char *)&OpcValue,0,0}; static DESCRIPTOR_FUNCTION_2(subtract_exp,(unsigned char *)&OpcSubtract,&value,&offset_d); static DESCRIPTOR_FUNCTION_2(mult_exp,(unsigned char *)&OpcMultiply,&coef_d,&subtract_exp); static DESCRIPTOR_WITH_UNITS(counts,&raw,&counts_str); static DESCRIPTOR_WITH_UNITS(volts,&mult_exp,&volts_str); static DESCRIPTOR_FUNCTION_2(rangesub,(unsigned char *)&OpcSubtract,0,&f1_d); static DESCRIPTOR_WINDOW(window,&start_d,&end_d,&stop_d); static struct descriptor *begin_ptrs[] = {&roprand,0}; static struct descriptor *end_ptrs[] = {(struct descriptor *)&rangesub,&roprand}; static DESCRIPTOR_APD(begin_apd,0,begin_ptrs,2); static DESCRIPTOR_APD(end_apd,0,end_ptrs,2); static DESCRIPTOR_RANGE(int_clock1_d,0,0,&f1_d); static DESCRIPTOR_RANGE(int_clock2_d,&begin_apd,&end_apd,&f2_d); static int clock_out_nid; static DESCRIPTOR_NID(clock_out_d,&clock_out_nid); static DESCRIPTOR_DIMENSION(dimension,&window,&clock_out_d); static DESCRIPTOR_WITH_UNITS(seconds,&dimension,&seconds_str); static DESCRIPTOR_SIGNAL_1(signal,&volts,&counts,&seconds); void *ctx = 0; max_time=-1; trigger_nid = setup->head_nid + T4012_N_TRIGGER; switch_trig_nid = setup->head_nid + T4012_N_SWITCH_TRIG; extern_clock_nid = setup->head_nid + T4012_N_EXTERN_CLOCK; clock_out_nid = setup->head_nid + T4012_N_CLOCK_OUT; pio(8,0,0); status = Input(setup,14); dig_status = *(struct _t4012_status *)&status; if (dig_status.sampling) { return DEV$_NOT_TRIGGERED; } channels = Input(setup,1); pts = Input(setup,2); memPerChannel = Input(setup,3) * 1024; if (Input(setup,7) == 1) TreePutRecord(clock_out_nid,(struct descriptor *)&ext_clock_d,0); else { int shift = Input(setup,6); f[0] = freqs[Input(setup,4)]; if (shift) { f[1] = freqs[Input(setup,5)]; rangesub.arguments[0] = begin_ptrs[1] = (shift == 1) ? &swi_d : &stop_d; TreePutRecord(clock_out_nid,(struct descriptor *)&int_clock2_d,0); } else TreePutRecord(clock_out_nid,(struct descriptor *)&int_clock1_d,0); } idxmin = (pts - 8.)/8. * memPerChannel; idxmax = idxmin + memPerChannel - 1; if (memsize < (memPerChannel * 2)) { if (memsize) free(mem); memsize = memPerChannel * 2; mem = malloc(memsize); } return_on_error(AccessTraq(setup,0x8001,16,0,0),status); /* Remote control */ nodename = TreeGetPath(setup->head_nid); strcpy(digname,nodename); TreeFree(nodename); strcat(digname,":T28%%_%%"); status = TreeFindNodeWild(digname,&dig_nid,&ctx,1 << TreeUSAGE_DEVICE); for (dig=1,channels_read=0;(channels_read < channels) && (status & 1);dig++) { static int dig_nids[1+8*T28XX_K_NODES_PER_INP]; static int nidlen; static NCI_ITM itmlst[] = {{sizeof(dig_nids),NciCONGLOMERATE_NIDS,(unsigned char *)&dig_nids,&nidlen}, {0,NciEND_OF_LIST,0,0}}; if (status & 1) { int i; int digchannels; status = TreeGetNci(dig_nid,itmlst); digchannels = (nidlen/sizeof(dig_nid)-1)/T28XX_K_NODES_PER_INP; for (i=0;i<digchannels && (status & 1) && channels_read < channels;i++) { if (TreeIsOn(CNID(i,HEAD))&1) { int channel_select = 0x0A000 | (channels_read + 1); AccessTraq(setup,channel_select,24,0,0); if (chan_nid && (*acoef > 1)) { return_on_error(TreePutRecord(chan_nid,(struct descriptor *)&signal,0),status); chan_nid = 0; } else DevWait((float).005); chan_nid = CNID(i,HEAD); *lbound = (DevLong(&CNID(i,STARTIDX),(int *)lbound) & 1) ? min(idxmax,max(idxmin,*lbound)) : idxmin; *ubound = (DevLong(&CNID(i,ENDIDX), (int *)ubound) & 1) ? min(idxmax,max(idxmin,*ubound)) : idxmax; *acoef = *ubound - *lbound + 1; if (*acoef > 0) { int points_read = 0; int first_sample_offset = *lbound-idxmin; int chunk = first_sample_offset/1024; int chunk_offset = first_sample_offset % 1024; float calib[]={0,0}; status = ReadChannel(setup, chunk,*acoef+chunk_offset,mem,&points_read,&CNID(i,CALIBRATION),calib); if (status & 1) { offset = calib[0]; if (calib[0] == calib[1]) coefficient = (offset > 1000) ? 10./4096 : 5./4096.; else coefficient = calib[1]; raw.pointer = (char *)(mem + chunk_offset); raw.a0 = raw.pointer - *lbound * sizeof(*mem); *ubound = (points_read - chunk_offset) + *lbound - 1; *acoef = (points_read - chunk_offset); raw.arsize = *acoef * 2; } } } channels_read++; } } if (channels_read < channels && (status & 1)) status = TreeFindNodeWild(digname,&dig_nid,&ctx,1 << TreeUSAGE_DEVICE); } TreeFindNodeEnd(&ctx); if (chan_nid && (*acoef > 1)) return_on_error(TreePutRecord(chan_nid,(struct descriptor *)&signal,0),status); return status; }
int l6810___store(struct descriptor *niddsc_ptr, InStoreStruct *in_struct) { #undef return_on_error #define return_on_error(f) if (!((status = f) & 1)) return status; #undef pio #define pio(f,a,d,q) return_on_error(DevCamChk(CamPiow(in_struct->name, a, f, d, 16, 0), &one, &q)) #define CHAN_NID(chan, field) c_nids[L6810_N_CHANNELS+chan*L6810_K_NODES_PER_CHANNEL+field] static int one = 1; static int c_nids[L6810_K_CONG_NODES]; static DESCRIPTOR_A_BOUNDS(raw,sizeof(short),DTYPE_W,0,1,0); static DESCRIPTOR(counts_str,"counts"); static DESCRIPTOR_WITH_UNITS(counts,&raw,&counts_str); static DESCRIPTOR_LONG(one_d,&one); static DESCRIPTOR_LONG(start_d,&raw.bounds[0].l); static DESCRIPTOR_FUNCTION_2(start_expr_d,(unsigned char *)&OpcAdd,&start_d,&one_d); static DESCRIPTOR_LONG(end_d,&raw.bounds[0].u); static DESCRIPTOR_FUNCTION_2(end_expr_d,(unsigned char *)&OpcAdd,&end_d,&one_d); static DESCRIPTOR_NID(trigger_d,&c_nids[L6810_N_STOP_TRIG]); static float frequency = 4E-6; static DESCRIPTOR_FLOAT(frequency_d,&frequency); static DESCRIPTOR_RANGE(int_clock_d,0,0,&frequency_d); static DESCRIPTOR_NID(ext_clock_d,&c_nids[L6810_N_EXT_CLOCK_IN]); static float coeffs[] = {100E-6, 250E-6, 500E-6, 1E-3, 2.5E-3, 6.26E-3, 12.5E-3, 25E-3}; static float coefficient; static DESCRIPTOR_FLOAT(coef_d,&coefficient); static short offset = -2048; static struct descriptor_s offset_d = {2,DTYPE_W,CLASS_S,(char *)&offset}; static DESCRIPTOR_FUNCTION_1(dvalue,(unsigned char *)&OpcValue,0); static DESCRIPTOR_FUNCTION_2(add_exp,(unsigned char *)&OpcAdd,&offset_d,&dvalue); static DESCRIPTOR_FUNCTION_2(mult_exp,(unsigned char *)&OpcMultiply,&coef_d,&add_exp); static DESCRIPTOR(volts_str,"volts"); static DESCRIPTOR_WITH_UNITS(volts,&mult_exp,&volts_str); static DESCRIPTOR_WINDOW(window,&start_expr_d,&end_expr_d,&trigger_d); static DESCRIPTOR_DIMENSION(dimension,&window,0); static DESCRIPTOR(time_str,"seconds"); static DESCRIPTOR_WITH_UNITS(time,&dimension,&time_str); static DESCRIPTOR_SIGNAL_1(signal,&volts,&counts,&time); short *channel_data; int status; int chan; int samples_to_read; int i; int min_idx; int max_idx; int post_trig; int samples_per_channel; struct setup setup; return_on_error(DevNids(niddsc_ptr,sizeof(c_nids),c_nids)); dvalue.ndesc = 0; return_on_error(DevCamChk(CamPiow(in_struct->name, 0, 8, 0, 16, 0), &one, 0)); if ((CamXandQ(0)&1) == 0) return DEV$_NOT_TRIGGERED; pio(18, 0, &zero, one); /* prepare to read setup information */ stop(2,1,33,&setup); /* read the setup information */ if (setup.f1_freq == 0) { dimension.axis = (struct descriptor *)(&ext_clock_d); } else { static float freqs[] = {0.0, 1/20., 1/50., 1/100., 1/200., 1/500., 1/1000., 1/2000., 1/5000., 1/10000., 1/20000., 1/50000., 1/100000., 1/200000., 1/500000., 1/1000000., 1/2000000., 1/5000000.}; dimension.axis = (struct descriptor *)(&int_clock_d); frequency = freqs[setup.f1_freq]; } samples_per_channel = (1<<setup.samps_per_seg)*1024; post_trig = samples_per_channel; min_idx = 0; max_idx = post_trig - 2; channel_data = (short *)malloc(samples_per_channel*sizeof(short)); #undef return_on_error #define return_on_error(f) if (!((status = f) & 1)) {free(channel_data); return status;} for (chan=0;((chan < 4) && (status & 1));chan++) { if (TreeIsOn(CHAN_NID(chan,L6810_N_CHAN_HEAD)) & 1) { status = DevLong(&CHAN_NID(chan,L6810_N_CHAN_STARTIDX),(int *)&raw.bounds[0].l); if (status&1) raw.bounds[0].l = min(max_idx,max(min_idx,raw.bounds[0].l)); else raw.bounds[0].l = min_idx; status = DevLong(&CHAN_NID(chan,L6810_N_CHAN_ENDIDX), (int *)&raw.bounds[0].u); if (status&1) raw.bounds[0].u = min(max_idx,max(raw.bounds[0].l,raw.bounds[0].u)); else raw.bounds[0].u = max_idx; raw.m[0] = raw.bounds[0].u - raw.bounds[0].l + 1; if (raw.m[0] > 0) { samples_to_read = raw.bounds[0].u - min_idx + 1; status = ReadChannel(in_struct->name,chan,&samples_to_read,channel_data); if (status & 1) { coefficient = coeffs[setup.sensitivity[chan]]; raw.pointer = (char *)(channel_data + (raw.bounds[0].l - min_idx)); raw.a0 = raw.pointer - (raw.bounds[0].l * sizeof(channel_data[0])); raw.arsize = raw.m[0] * 2; status = TreePutRecord(CHAN_NID(chan,L6810_N_CHAN_HEAD),(struct descriptor *)&signal,0); } } } } free(channel_data); return status; }
int b2408___store(struct descriptor *niddsc, InStoreStruct *setup) { int i; int j; int npts; int status = 1; static int trig_nid; static DESCRIPTOR_NID(trig_dsc, &trig_nid); static int ext_clock_nid; static DESCRIPTOR_NID(clock_dsc, &ext_clock_nid); static int buffer[2048]; static DESCRIPTOR_A(buffer_dsc, sizeof(int), DTYPE_L, buffer, 0); static float clock_mult; static DESCRIPTOR_FLOAT(clock_mult_dsc, &clock_mult); static struct descriptor_xd xd = {0, DTYPE_DSC, CLASS_XD, 0, 0}; static DESCRIPTOR(expr, "BUILD_SIGNAL(BUILD_WITH_UNITS(SLOPE_OF($)*$*$VALUE+$,\"Seconds\"), $, *)"); static DESCRIPTOR(int_clock_expr, "BUILD_SIGNAL(BUILD_WITH_UNITS(1E-6*$*$VALUE+$,\"Seconds\"), $, *)"); static float multipliers[] = {1, 10, 100, 1000}; static int zero = 0; int output_nid = setup->head_nid+B2408_N_TIMEBASE; StatusReg status_reg; ext_clock_nid = setup->head_nid+B2408_N_EXT_CLOCK; trig_nid = setup->head_nid+B2408_N_TRIGGER; if (XmdsIsOn(output_nid)) { pio(24,0,0,16); pio(1,0,(int *)&status_reg,24); npts = status_reg.npts; clock_mult = multipliers[status_reg.freq]; if (npts > 0) { int ok,tries; for (ok=0,tries=0;tries < 100 && !ok; tries++) { pio(16,0,&zero,16); stop(2,0,npts,buffer); ok = 1; for (j=1;j<npts;j++) { if (buffer[j-1] > buffer[j]) { ok = 0; break; } } } if (tries > 1) { char comment_c[80]; struct descriptor comment={0,DTYPE_T,CLASS_S,0}; int comment_nid = setup->head_nid+B2408_N_COMMENT; sprintf(comment_c,"Increasing times %sobtained after %d attempts",ok ? "" : "not ",tries); comment.length = strlen(comment_c); comment.pointer = comment_c; TreePutRecord(comment_nid, (struct descriptor *)&comment,0); } } else return DEV$_NOT_TRIGGERED; buffer_dsc.arsize = npts*sizeof(int); /* if (status_reg.ext_clk) { */ if (1) { return_on_error(TdiCompile(&expr, &clock_dsc, &clock_mult_dsc, &trig_dsc, &buffer_dsc, (struct descriptor *)&xd MDS_END_ARG),status); } else { return_on_error(TdiCompile(&int_clock_expr, &clock_mult_dsc, &trig_dsc, &buffer_dsc, (struct descriptor *)&xd MDS_END_ARG),status); } return_on_error(TreePutRecord(output_nid, (struct descriptor *)&xd,0), status); } /* return (status_reg.overflow) ? B2408$_OVERFLOW : (status_reg.trig_lim) ? B2408$_TRIG_LIM : 1; */ return (status_reg.overflow) ? B2408$_OVERFLOW : 1; }
int l8501___init(struct descriptor *niddsc_ptr, InInitStruct *setup) { static float freqs[] = { 0.02, 0.05, 0.1, 0.2, 0.5, 1.0, 2.0, 5.0, 10.0, 20.0, 50.0, 100.0, 200.0, 500.0, 1000.0, 2000.0, 5000.0, 10000.0, 20000.0}; float freq; int count; int i; short range; short clk[3]; unsigned short clk_word; int status; int f2_count_nid = setup->head_nid + L8501_N_F2_COUNT; int f3_count_nid = setup->head_nid + L8501_N_F3_COUNT; static int retlen; /********************************************* Read in the name and mode records. If any problem is encountered then return the error status. **********************************************/ /*************************************************** Switch on the mode. 0 - multi frequency f2 and f3 counted. 1 - multi frequency trigerable frequency shift. 2 - Interleaved clock (single frequency 3 - Burst mode (f2 and f2_count) NOTE: No break at end of case 0. The only difference between 0 and 1 is that 0 needs the counts. ****************************************************/ switch (setup->mode_convert) { case 0: return_on_error(DevLong(&f2_count_nid,&count),status); pio(0,16,&count); return_on_error(DevLong(&f3_count_nid, &count),status); pio(1,16,&count); case 1: GET_FREQ_IDX(0,L8501_N_FREQ1); GET_FREQ_IDX(1,L8501_N_FREQ2); GET_FREQ_IDX(2,L8501_N_FREQ3); if ((clk[0] < 3) || (clk[1] < 3) || (clk[2] < 3)) if ((clk[0] > 15) || (clk[1] > 15) || (clk[2] > 15)) return DEV$_BAD_FREQ; else { range = 2; clk_word = clk[0] | (clk[1] << 4) | (clk[2] << 8); } else { range = 1; clk_word = (clk[0] - 3) | ((clk[1]-3) << 4) | ((clk[2]-3) << 8); } break; case 2: GET_FREQ_IDX(0,L8501_N_FREQ1); if (clk[0] <= 3) { range = 1; clk_word = clk[0]-3; } else { range = 2; clk_word = clk[0]; } break; case 3: return_on_error(DevLong(&f2_count_nid,&count),status); pio(0,16,&count); GET_FREQ_IDX(1,L8501_N_FREQ2); if (clk[1] <= 3) { range = 2; clk_word = clk[1] << 4; } else { range = 1; clk_word = (clk[1]-3) << 4; } break; } /*************************************** Write frequency range to the module **************************************/ pio(2,16,&range); /*************************************** Write the frequency control word to the module. ***************************************/ pio(3,16,&clk_word); /*************************************** Set the mode ***************************************/ pio(setup->mode_convert,26,0); /*************************************** Reset sequence ***************************************/ pio(0,25,0); return status; }
int hv1440___store(struct descriptor *niddsc, InStoreStruct *setup) { int count; int need_pod=0; int status = 1; int pod; int ind; int i; int j; float volt; int vmax; int vfmax=0; int nfmax=0; int pods[HV1440_K_MAX_PODS]; int f2; static int settings[HV1440_K_MAX_CHANNELS]; static float f_settings[HV1440_K_MAX_CHANNELS]; static DESCRIPTOR(out_dsc, "BUILD_WITH_UNITS($, 'Volts')"); static DESCRIPTOR_A(settings_dsc, sizeof(float), DTYPE_F, f_settings, sizeof(f_settings)); static struct descriptor_xd out_xd = {0, DTYPE_DSC, CLASS_XD, 0, 0}; vmax = ((setup->range == 1.0) || (setup->range == .625)) ? 2500 : (setup->range == .5) ? 2046 : (setup->range == .375) ? 1534 : 0; if (! vmax) return HV1440$_BAD_RANGE; for (pod=0,ind=0; pod<HV1440_K_MAX_PODS; pod++, ind+= HV1440_K_CHANS_PER_POD) pods[pod] = GetPodSettings(setup->head_nid + HV1440_N_POD_01 + pod, &settings[ind]); for (i=0; i<HV1440_K_MAX_CHANNELS; i++) { int abset = abs(settings[i]); if (abset > vmax) return HV1440$_OUTRNG; if (abset > vfmax) { vfmax = abset; nfmax = i; } } pio(9,0,0); pio(10,0,0); pio(26,1,0); f2 = setup->frame*2; send_hv(0, nfmax, f2, 0); for (i=0; i<HV1440_K_MAX_PODS; i++) { if (pods[i]) { need_pod = i+1; for(j=0; j<HV1440_K_CHANS_PER_POD; j++) { struct v_read { unsigned tag : 3; unsigned voltage : 12; unsigned sign_bit : 1; } voltage; int i0 = i*HV1440_K_CHANS_PER_POD+j; send_hv(0, i0, 8, 3); for (voltage.tag=0, count = 0; ((count < 25) && (voltage.tag != 2)); count++) { static float time = .1; LibWait(&time); pio(2, 0, (short *)&voltage); } if (count > 1) printf("Readback took %d tries\n", count); if (count == 25) return HV1440$_STUCK; f_settings[i*HV1440_K_CHANS_PER_POD+j] = voltage.voltage*setup->range* (voltage.sign_bit ? 1. : -1.); } } else for(j=0; j < HV1440_K_CHANS_PER_POD; j++) f_settings[i*HV1440_K_CHANS_PER_POD+j] = 0; } settings_dsc.arsize = sizeof(float)*need_pod*HV1440_K_CHANS_PER_POD; if (need_pod) { int readout_nid = setup->head_nid + HV1440_N_READOUT; return_on_error(TdiCompile(&out_dsc, &settings_dsc, &out_xd MDS_END_ARG), status); return_on_error(TreePutRecord(readout_nid, (struct descriptor *)&out_xd, 0), status); MdsFree1Dx(&out_xd,0); } return 1; }
int fera___store(struct descriptor_s *niddsc_ptr, InStoreStruct *setup) { int mem_status = 1; int put_status = 1; int status; int num_dig; int num_mem; int i; int num_chan; int total_data; int *num_pts; unsigned short *buffer; int ind; #define return_on_error(f,retstatus) if (!((status = f) & 1)) return retstatus; last_nid = 0; num_dig = NElements(setup->head_nid + FERA_N_DIG_NAME); if (num_dig == 0) return FERA$_NODIG; num_chan = num_dig*16; total_data = 0; num_mem = NElements(setup->head_nid+FERA_N_MEM_NAME); if (num_mem == 0) return FERA$_NOMEM; num_pts = malloc(sizeof(int)*num_mem); for(i=0; i<num_mem; i++) { char *name = ArrayRef(setup->head_nid+FERA_N_MEM_NAME, i); num_pts[i] = 0; if (name) { return_on_error(DevCamChk(CamPiow(name, 1, 17, &one, 16, 0),&one,&one),status); return_on_error(DevCamChk(CamPiow(name, 0, 2, &num_pts[i], 16, 0),&one,&one),status); if (num_pts[i] >= 16*1024) { num_pts[i] = 16*1024; if (i==num_mem-1) mem_status = FERA$_OVER_RUN; } total_data += num_pts[i]; } } if (total_data % num_chan != 0) { status = FERA$_PHASE_LOST; return status; } buffer = malloc(total_data*sizeof(short)); for (i=0,ind=0; i< num_mem; ind+=num_pts[i],i++) { if (num_pts[i]) { char *name = ArrayRef(setup->head_nid+FERA_N_MEM_NAME, i); if (name) { return_on_error(DevCamChk(CamQstopw(name, 0, 2, num_pts[i], &buffer[ind], 16, 0), &one, &one), status) } } } status = Unpack(&buffer, num_pts, num_mem, num_chan, total_data/num_chan); if ((status&1) || (status == FERA$_CONFUSED) || (status == FERA$_OVERFLOW)) put_status = Put(buffer, total_data/num_chan, num_chan, setup->head_nid + FERA_N_EXT_CLOCK, setup->head_nid +FERA_N_OUTPUT); free(buffer); return (put_status &1) ? ((status&1) ? mem_status : status) : put_status; }
int l8501___store(struct descriptor *niddsc_ptr, InStoreStruct *setup) { static float one_thous = 1.E-3; static DESCRIPTOR_FLOAT(one_thousandth,&one_thous); static int freq1_nid; static DESCRIPTOR_NID(freq1,&freq1_nid); static int freq2_nid; static DESCRIPTOR_NID(freq2,&freq2_nid); static int freq3_nid; static DESCRIPTOR_NID(freq3,&freq3_nid); static int f2_count_nid; static DESCRIPTOR_NID(f2_count,&f2_count_nid); static int f3_count_nid; static DESCRIPTOR_NID(f3_count,&f3_count_nid); static int trigger1_nid; static DESCRIPTOR_NID(trigger1,&trigger1_nid); static int trigger2_nid; static DESCRIPTOR_NID(trigger2,&trigger2_nid); static int trigger3_nid; static DESCRIPTOR_NID(trigger3,&trigger3_nid); static DESCRIPTOR(seconds,"seconds"); static int mode; unsigned short lam; int status; static DESCRIPTOR_FUNCTION_2(dt1,(unsigned char *)&OpcDivide,&one_thousandth,&freq1); static DESCRIPTOR_FUNCTION_2(dt2,(unsigned char *)&OpcDivide,&one_thousandth,&freq2); static DESCRIPTOR_FUNCTION_2(dt3,(unsigned char *)&OpcDivide,&one_thousandth,&freq3); static float past_val = -1.E30; static DESCRIPTOR_FLOAT(past,&past_val); static float future_val = 1.E30; static DESCRIPTOR_FLOAT(future,&future_val); int clock_out_nid = setup->head_nid + L8501_N_CLOCK_OUT; int stop_out_nid = setup->head_nid + L8501_N_STOP_OUT; freq1_nid = setup->head_nid + L8501_N_FREQ1; freq2_nid = setup->head_nid + L8501_N_FREQ2; freq3_nid = setup->head_nid + L8501_N_FREQ3; f2_count_nid = setup->head_nid + L8501_N_F2_COUNT; f3_count_nid = setup->head_nid + L8501_N_F3_COUNT; trigger1_nid = setup->head_nid + L8501_N_TRIGGER1; trigger2_nid = setup->head_nid + L8501_N_TRIGGER2; trigger3_nid = setup->head_nid + L8501_N_TRIGGER3; /********************************************* Read in the clock mode record. **********************************************/ switch (setup->mode_convert) { /************************************** Mode 1 is Counted frequency shifts. clock runs at F1 until Trigger 1 then runs at F2 for a preset number of pulses and then switches to F3 for a preset number of pulses and then generates a stop trigger. ****************************************/ case 0: if (TreeIsOn(clock_out_nid) & 1) { static DESCRIPTOR_FUNCTION_2(mult,(unsigned char *)&OpcMultiply,&dt2,&f2_count); static DESCRIPTOR_FUNCTION_2(fswitch,(unsigned char *)&OpcAdd,&mult,&trigger1); static FUNCTION(3) r_start = {sizeof(unsigned short), DTYPE_FUNCTION, CLASS_R, (unsigned char *)&OpcVector, 3, __fill_name__ (struct descriptor *)&past, (struct descriptor *)&trigger1, (struct descriptor *)&fswitch}; static FUNCTION(3) r_end = {sizeof(unsigned short), DTYPE_FUNCTION, CLASS_R, (unsigned char *)&OpcVector, 3, __fill_name__ (struct descriptor *)&trigger1, (struct descriptor *)&fswitch, (struct descriptor *)&future}; static FUNCTION(3) r_delta = {sizeof(unsigned short), DTYPE_FUNCTION, CLASS_R, (unsigned char *)&OpcVector, 3, __fill_name__ (struct descriptor *)&dt1, (struct descriptor *)&dt2, (struct descriptor *)&dt3}; static DESCRIPTOR_RANGE(range,&r_start,&r_end,&r_delta); static DESCRIPTOR_WITH_UNITS(clock,&range,&seconds); return_on_error(TreePutRecord(clock_out_nid, (struct descriptor *)&clock,0),status); /****************************** If stop trigger is wanted then declare an expression for the time of the stop trigger and write it out. ******************************/ if (status & 1 && TreeIsOn(stop_out_nid) & 1) { static DESCRIPTOR_FUNCTION_2(trig_mult_exp, (unsigned char *)&OpcMultiply, &dt3, &f3_count); static DESCRIPTOR_FUNCTION_2(trig_add_exp, (unsigned char *)&OpcAdd, &fswitch, &trig_mult_exp); static DESCRIPTOR_WITH_UNITS(stop, &trig_add_exp, &seconds); return_on_error(TreePutRecord(stop_out_nid, (struct descriptor *)&stop,0),status); } } break; /************************************ Mode 2 is triggered frequency shift mode. clock runs at F1 until Trigger 1 then runs at F2 until Trigger 2 and then switches to F3. *************************************/ case 1: if (TreeIsOn(clock_out_nid) & 1) { /********************************** Read the lam register. If there were overflows then store information based on the triggers. ************************************/ pio(2,0,&lam); if (lam & 6) { static FUNCTION(3) r_start = {sizeof(unsigned short), DTYPE_FUNCTION, CLASS_R, (unsigned char *)&OpcVector, 3, __fill_name__ (struct descriptor *)&past, (struct descriptor *)&trigger1, (struct descriptor *)&trigger2}; static FUNCTION(3) r_end = {sizeof(unsigned short), DTYPE_FUNCTION, CLASS_R, (unsigned char *)&OpcVector, 3, __fill_name__ (struct descriptor *)&trigger1,(struct descriptor *)&trigger2, (struct descriptor *)&future}; static FUNCTION(3) r_delta = {sizeof(unsigned short), DTYPE_FUNCTION, CLASS_R, (unsigned char *)&OpcVector, 3, __fill_name__ (struct descriptor *)&dt1, (struct descriptor *)&dt2, (struct descriptor *)&dt3}; static DESCRIPTOR_RANGE(range, &r_start, &r_end, &r_delta); static DESCRIPTOR_WITH_UNITS(clock,&range,&seconds); return_on_error(TreePutRecord(clock_out_nid, (struct descriptor *)&clock,0),status); /*************************** write out the stop trigger record. ****************************/ if (TreeIsOn(stop_out_nid) & 1) { DESCRIPTOR_WITH_UNITS(stop, &trigger3, &seconds); return_on_error(TreePutRecord(stop_out_nid, (struct descriptor *)&stop,0),status); } } else /**************************** otherwise store information based on the counters. *****************************/ { static short f2_count_act; static struct descriptor f2_count_actual = {sizeof(f2_count_act),DTYPE_W,CLASS_S,(char *)&f2_count_act}; static DESCRIPTOR_FUNCTION_2(mult,(unsigned char *)&OpcMultiply,&dt2,&f2_count_act); static DESCRIPTOR_FUNCTION_2(fswitch,(unsigned char *)&OpcAdd,&mult,&trigger1); static FUNCTION(3) r_start = {sizeof(unsigned short), DTYPE_FUNCTION, CLASS_R, (unsigned char *)&OpcVector, 3, __fill_name__ (struct descriptor *)&past, (struct descriptor *)&trigger1, (struct descriptor *)&fswitch}; static FUNCTION(3) r_end = {sizeof(unsigned short), DTYPE_FUNCTION, CLASS_R, (unsigned char *)&OpcVector, 3, __fill_name__ (struct descriptor *)&trigger1, (struct descriptor *)&fswitch, (struct descriptor *)&future}; static FUNCTION(3) r_delta = {sizeof(unsigned short), DTYPE_FUNCTION, CLASS_R, (unsigned char *)&OpcVector, 3, __fill_name__ (struct descriptor *)&dt1, (struct descriptor *)&dt2, (struct descriptor *)&dt3}; static DESCRIPTOR_RANGE(range, (struct descriptor *)&r_start, (struct descriptor *)&r_end, (struct descriptor *)&r_delta); static DESCRIPTOR_WITH_UNITS(clock, &range, &seconds); pio(0,0,&f2_count_act); return_on_error(TreePutRecord(clock_out_nid, (struct descriptor *)&clock,0),status); /****************************** if stop trigger is wanted then declare an expression for the time of the stop trigger and write it out. ******************************/ if (TreeIsOn(stop_out_nid) & 1) { static short f3_count_act; static struct descriptor f3_count_actual = {sizeof(f3_count_act),DTYPE_W,CLASS_S,(char *)&f3_count_act}; static DESCRIPTOR_FUNCTION_2(mult,(unsigned char *)&OpcMultiply,&dt3,&f3_count_act); static DESCRIPTOR_FUNCTION_2(fswitch2,(unsigned char *)&OpcAdd,&mult,&fswitch); static DESCRIPTOR_WITH_UNITS(stop, &fswitch2, &seconds); pio(1,0,&f3_count); return_on_error(TreePutRecord(stop_out_nid, (struct descriptor *)&stop,0),status); } } }
int l8590_mem___store(struct descriptor_s *niddsc_ptr, InStoreStruct *setup) { int total_chans = 0; int total_samps = 0; void *ctx; int sclrs; int sclr_nids[L8590_MEM_K_MAX_SCALERS]; int active[L8590_MEM_K_MAX_SCALERS]; int samples[L8590_MEM_K_MAX_SCALERS]; int old_def; int status; static DESCRIPTOR_A_BOUNDS(raw,sizeof(unsigned short),DTYPE_WU,0,1,0); static DESCRIPTOR(counts_str,"counts"); static DESCRIPTOR_WITH_UNITS(counts,&raw,&counts_str); static InGet_setupStruct sclr_setup; static DESCRIPTOR_NID(sclr_niddsc,0); static int latch_nid; static DESCRIPTOR_NID(latch,&latch_nid); static FUNCTION(1) dvalue = {2,DTYPE_FUNCTION,CLASS_R,(unsigned char *)&OpcValue,0,0}; static DESCRIPTOR_SIGNAL_1(signal,&dvalue,&counts,&latch); int setup_status = 0; latch_nid = setup->head_nid + L8590_MEM_N_LATCH; TreeGetDefaultNid(&old_def); TreeSetDefaultNid(*(int *)niddsc_ptr->pointer); for (ctx=0,sclrs=0; TreeFindNodeWild("L8590_%", &sclr_nids[sclrs], &ctx, -1)&1;sclrs++) { sclr_niddsc.pointer = (char *)&sclr_nids[sclrs]; setup_status = l8590_sclr___get_setup(&sclr_niddsc,&sclr_setup); if (setup_status & 1) { samples[sclrs] = 0; active[sclrs] = sclr_setup.num_active; pio(sclr_setup.name,2,0,&samples[sclrs]); total_samps += samples[sclrs]; total_chans += active[sclrs]; GenDeviceFree(&sclr_setup); } else { return_on_error(setup_status,status); } } if (total_samps > 32766) { printf("Total samples too large for L8590_MEM: %s --- %d\n",setup->name,total_samps); total_samps = 32767; } if (!(TreeIsOn(setup->head_nid + L8590_MEM_N_COMMENT) & 1)) { total_samps = total_chans*2000; } if (total_samps) { int chan; int chan_idx; unsigned short *values = calloc(total_samps * 2,sizeof(*values)); unsigned short *cdata = values + total_samps; int samps_per_chan = total_samps/total_chans; int min_idx = 0; int max_idx = samps_per_chan - 1; int i; int sclr; pio(setup->name,19,0,&zero); pio(setup->name,18,0,&zero); pio(setup->name,25,0,0); pio(setup->name,2,0,&values[0]); pio(setup->name,19,0,&zero); stop(setup->name,2,0,total_samps,values); for (i=0;i<total_samps;i++) cdata[i/total_chans + (i % total_chans) * samps_per_chan] = values[i]; for (chan_idx=0, sclr=0; sclr<sclrs; sclr++) { for (chan=0; chan<active[sclr]; chan++, chan_idx++) { int data_nid = sclr_nids[sclr]+L8590_SCLR_N_INPUT_1+(L8590_SCLR_N_INPUT_2 - L8590_SCLR_N_INPUT_1)*chan; int start_nid = data_nid + L8590_SCLR_N_INPUT_1_STARTIDX - L8590_SCLR_N_INPUT_1; int end_nid = data_nid + L8590_SCLR_N_INPUT_1_ENDIDX - L8590_SCLR_N_INPUT_1; if (TreeIsOn(data_nid) & 1) { status = DevLong(&start_nid,(int *)&raw.bounds[0].l); if (status&1) raw.bounds[0].l = min(max_idx,max(min_idx,raw.bounds[0].l)); else raw.bounds[0].l = min_idx; status = DevLong(&end_nid, (int *)&raw.bounds[0].u); if (status&1) raw.bounds[0].u = min(max_idx,max(min_idx,raw.bounds[0].u)); else raw.bounds[0].u = max_idx; raw.m[0] = raw.bounds[0].u - raw.bounds[0].l + 1; if (raw.m[0] > 0) { raw.pointer = (char *)(cdata + chan_idx * samps_per_chan + raw.bounds[0].l); raw.a0 = raw.pointer - raw.bounds[0].l * sizeof(*cdata); raw.arsize = raw.m[0] * 2; status = TreePutRecord(data_nid,(struct descriptor *)&signal,0); } } } } free(values); } TreeSetDefaultNid(old_def); return status; }
int l8210___store(struct descriptor *niddsc_ptr, InStoreStruct *setup) { static DESCRIPTOR_A_BOUNDS(raw,sizeof(short),DTYPE_W,0,1,0); static DESCRIPTOR(counts_str,"counts"); static DESCRIPTOR_WITH_UNITS(counts,&raw,&counts_str); static DESCRIPTOR_LONG(start_d,&raw.bounds[0].l); static DESCRIPTOR_LONG(end_d,&raw.bounds[0].u); static int stop_trig_nid; static DESCRIPTOR_NID(trigger_d,&stop_trig_nid); static float frequency; static DESCRIPTOR_FLOAT(frequency_d,&frequency); static DESCRIPTOR_RANGE(int_clock_d,0,0,&frequency_d); static int ext_clock_in_nid; static DESCRIPTOR_NID(ext_clock_d,&ext_clock_in_nid); static float coefficient = 10.0/1024; static DESCRIPTOR_FLOAT(coef_d,&coefficient); static short offset = -512; static struct descriptor offset_d = {2,DTYPE_W,CLASS_S,(char *)&offset}; #define DESCRIPTOR_VALUE(name)\ struct descriptor_function_0 { RECORD_HEAD } name =\ {2, DTYPE_FUNCTION, CLASS_R, (unsigned char *)&OpcValue, 0} static DESCRIPTOR_VALUE(value); static DESCRIPTOR_FUNCTION_2(add_exp,(unsigned char *)&OpcAdd,&offset_d,&value); static DESCRIPTOR_FUNCTION_2(mult_exp,(unsigned char *)&OpcMultiply,&coef_d,&add_exp); static DESCRIPTOR(volts_str,"volts"); static DESCRIPTOR_WITH_UNITS(volts,&mult_exp,&volts_str); static DESCRIPTOR_WINDOW(window,&start_d,&end_d,&trigger_d); static int clock_out_nid; static DESCRIPTOR_NID(clock_out,&clock_out_nid); static DESCRIPTOR_DIMENSION(dimension,&window,&clock_out); static DESCRIPTOR(time_str,"seconds"); static DESCRIPTOR_WITH_UNITS(time,&dimension,&time_str); static DESCRIPTOR_SIGNAL_1(signal,&volts,&counts,&time); int samples_per_channel; int min_idx; int max_idx; int num_chans; int vm_size; short *channel_data_ptr; int status; int chan; int samples_to_read; int i; float wait_time; stop_trig_nid = setup->head_nid + L8210_N_STOP_TRIG; ext_clock_in_nid = setup->head_nid + L8210_N_EXT_CLOCK_IN; clock_out_nid = setup->head_nid + L8210_N_CLOCK_OUT; pio(26,0,0); wait_time = setup->memories*30E-3; DevWait(wait_time); pio(8,0,0); if ((CamXandQ(0)&1) == 0) return DEV$_NOT_TRIGGERED; return_on_error(ReadSetup(setup, &setup->memories, setup->header, &samples_per_channel, &min_idx, &max_idx, &frequency, &num_chans), status); channel_data_ptr = malloc(samples_per_channel * sizeof(short)); status = TreePutRecord(clock_out_nid, (struct descriptor *)(frequency == 0.0) ? &ext_clock_d : (struct descriptor *)(&int_clock_d),0); for (chan=0;((chan<num_chans) && (status & 1));chan++) { int channel_nid = setup->head_nid + L8210_N_INPUT_1 + chan * (L8210_N_INPUT_2 - L8210_N_INPUT_1); int usetimes_nid = channel_nid + L8210_N_INPUT_1_USETIMES - L8210_N_INPUT_1; int startidx_nid = channel_nid + L8210_N_INPUT_1_STARTIDX - L8210_N_INPUT_1; int endidx_nid = channel_nid + L8210_N_INPUT_1_ENDIDX - L8210_N_INPUT_1; if (TreeIsOn(channel_nid) & 1) { int use_times = 0; DevLong(&usetimes_nid,&use_times); if(use_times) { float start_time, end_time; raw.bounds[0].l = min_idx; raw.bounds[0].u = max_idx; status = DevFloat(&startidx_nid,&start_time); if (~status&1) start_time = -1; status = DevFloat(&endidx_nid,&end_time); if (~status&1) end_time = -1; status = DevXToI(start_time, end_time, &dimension, min_idx, max_idx, &raw.bounds[0].l, &raw.bounds[0].u); if (~status&1) { raw.bounds[0].l = min_idx; raw.bounds[0].u = max_idx; } } else { status = DevLong(&startidx_nid,(int *)&raw.bounds[0].l); if (status&1) raw.bounds[0].l = min(max_idx,max(min_idx,raw.bounds[0].l)); else raw.bounds[0].l = min_idx; status = DevLong(&endidx_nid, (int *)&raw.bounds[0].u); if (status&1) raw.bounds[0].u = min(max_idx,max(min_idx,raw.bounds[0].u)); else raw.bounds[0].u = max_idx; } raw.m[0] = raw.bounds[0].u - raw.bounds[0].l + 1; if (raw.m[0] > 0) { samples_to_read = raw.bounds[0].u - min_idx + 1; status = ReadChannel(setup,&samples_per_channel,chan,&samples_to_read,channel_data_ptr); if (status & 1) { raw.pointer = (char *)(channel_data_ptr + (raw.bounds[0].l - min_idx)); raw.a0 = raw.pointer - raw.bounds[0].l * sizeof(*channel_data_ptr); raw.arsize = raw.m[0] * 2; status = TreePutRecord(channel_nid,(struct descriptor *)&signal,0); } } } } free(channel_data_ptr); return status; }