Example #1
0
int l8590___store(struct descriptor_s *niddsc_ptr, InStoreStruct *setup)
{
  int samples = 0;
  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 int latch_nid;
  static DESCRIPTOR_NID(latch,&latch_nid);
  static FUNCTION(1) value = {2,DTYPE_FUNCTION,CLASS_R,(unsigned char *)&OpcValue,0,0};
  static DESCRIPTOR_SIGNAL_1(signal,&value,&counts,&latch);
  latch_nid = setup->head_nid + L8590_N_LATCH;
  pio(setup->name,2,0,&samples);
  if (samples > 32766)
  {
    printf("Got large sample count from L8590: %s --- %d\n",setup->name,samples);
    samples=32766;
  }
  if (samples)
  {
    int samps_per_chan = samples/setup->num_active;
    unsigned short *values = calloc(samples * 2,sizeof(*values));
    unsigned short *cdata = values + samples;
    int chan;
    int i;
    int min_idx = 0;
    int max_idx = samps_per_chan - 1;
    pio(setup->mem_cts_name,19,0,&zero);
    pio(setup->mem_cts_name,18,0,&zero);
    pio(setup->mem_cts_name,25,0,0);
    pio(setup->mem_cts_name,2,0,&values[0]);
    stop(setup->mem_cts_name,2,0,samples,values);
    for (i=0;i<samples;i++) cdata[i/setup->num_active + (i % setup->num_active) * samps_per_chan] = values[i];
    for (chan=0;chan<setup->num_active;chan++)
    {
      int data_nid = setup->head_nid+L8590_N_INPUT_1+(L8590_N_INPUT_2 - L8590_N_INPUT_1)*chan;
      int start_nid = data_nid + L8590_N_INPUT_1_STARTIDX - L8590_N_INPUT_1;
      int end_nid = data_nid + L8590_N_INPUT_1_ENDIDX - L8590_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 * 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);
  }
  return status;
}
Example #2
0
int mit__clock__get_setup(Dptr niddsc_ptr, Dptr method, DecoderSetup *setup, EventMask *event_mask, Dptr *output)
{
  int status;
  InGet_setupStruct s;
  status = mit__clock___get_setup(niddsc_ptr,&s);
  if (status & 1)
  {
    static int output_nid;
    static DESCRIPTOR_NID(output_dsc,(char *)&output_nid);
    int invert = 0;
    int start_low_nid = s.head_nid + MIT__CLOCK_N_START_LOW;
    float max_period;
    float period;
    int pulses;
    int clock_source;
    memset(event_mask,0,sizeof(EventMask));
    invert = TreeIsOn(start_low_nid);
    invert = (invert == TreeOFF) || (invert == TreeBOTH_OFF);
    max_period = 1/s.frequency;
    for (clock_source = EXT_1MHZ, period = 1E-6;
       period * 65534 < max_period && clock_source <= EXT_100HZ; clock_source++, period *= 10);
    setup->output_control = TOGGLE;
    setup->start_high = invert;
    setup->count_up = 0;
    setup->bcd_count = 0;
    setup->repeat_count = 1;
    setup->double_load = 1;
    setup->special_gate = 0;
    setup->clock_source = clock_source;
    setup->falling_edge = 0;
    setup->gating = GATE_NONE;
    pulses = max_period/period + .4999;
    setup->load = pulses * s.duty_cycle + .4999;
    setup->hold = pulses - setup->load;
    if (setup->load == 0)
    {
      setup->load++;
      setup->hold--;
    }
    if (setup->hold == 0)
    {
      setup->load--;
      setup->hold++;
    }
    if (invert)
    {
      int tmp = setup->load;
      setup->load = setup->hold;
      setup->hold = tmp;
    }
    output_nid = s.head_nid + MIT__CLOCK_N_EDGES_R;
    *output = &output_dsc;
    GenDeviceFree(&s);
  }
  return status;
}
Example #3
0
int l8201___store(struct descriptor *niddsc_ptr, InStoreStruct *setup)
{
  int status;
  int upload_nid = setup->head_nid + L8201_N_UPLOAD;
  pio(9,0);
  pio(2,&buffer[0]);
  stop(2);
  pio(11,&zero);
  pio(26,0);
  if (TreeIsOn(upload_nid)&1) 
    status = TreePutRecord(upload_nid,(struct descriptor *)&data,0);
  return status;
}
Example #4
0
int h911___store(struct descriptor *nid_d_ptr, InStoreStruct *in)
{

    struct _status_reg {
        unsigned mode:2;
        unsigned over:1;
        unsigned full:1;
        unsigned :20;
    } status_reg;
    short mems;
    short chans;
    int samples;
    int status;
    int i;
    short *buffer;
    pio(0,2,(short *)&status_reg)            /* read back the status register */
    if (! status_reg.full)   return DEV$_NOT_TRIGGERED;
    pio(0,3,&mems);
    mems++;
    pio(0,4,&chans);
    chans++;
    samples = mems*32768/chans -1;
    buffer = malloc(samples*sizeof(short));
    {

        static DESCRIPTOR_A(data_dsc, sizeof(short), DTYPE_W, 0, 0);
        static DESCRIPTOR(counts_str,"counts");
        static DESCRIPTOR_WITH_UNITS(counts, &data_dsc, &counts_str);
        static int clk_nid;
        static DESCRIPTOR_NID(clock_dsc,&clk_nid);
        static DESCRIPTOR_SIGNAL_1(sig, &counts, 0, &clock_dsc);
        data_dsc.pointer = (char *)buffer;
        data_dsc.arsize = samples * sizeof(short);
        clk_nid = in->head_nid+H911_N_EXT_CLOCK;
        for (i=0,status=1; ((status&1) && (i<chans)); i++) {
            int nid = in->head_nid+H911_N_CHANNEL_01 + i;
            if (TreeIsOn(nid)) {
                short addr = i;
                pio(17,1,&addr);   /* readback mode 1 chan at a time starting with  sample 1 of this channel */
                stop(0,0,samples,buffer);
                status = TreePutRecord(nid, (struct descriptor *)&sig,0);
            }
        }
    }
    free(buffer);
    return(status);
}
Example #5
0
int ec727___store(struct descriptor *niddsc_ptr, InStoreStruct *setup)
{
  static DESCRIPTOR(sigdef,"BUILD_SIGNAL(BUILD_WITH_UNITS($,'counts'),*,$[ $ : $ ])");
  static DESCRIPTOR_A_BOUNDS(raw,sizeof(int),DTYPE_L,0,1,0);
  static DESCRIPTOR_LONG(start_d,&raw.bounds[0].l);
  static DESCRIPTOR_LONG(end_d,&raw.bounds[0].u);
  static EMPTYXD(signal);
  static int xfer_in;
  static DESCRIPTOR_NID(xfer_in_d,&xfer_in);
  int data[1024][32];
  int cdata[1024];
  int *dptr = (int *)data;
  int status;
  int i;
  int chan;
  xfer_in = setup->head_nid + EC727_N_XFER_IN;
  pio(17,0);
  for (i=0;i<4;i++,dptr += 8192) stop(0,0,8192,dptr);
  for (chan=0;((chan < 32) && (status & 1));chan++)
  {
    int c_nid = setup->head_nid + EC727_N_INPUT_01 + chan * (EC727_N_INPUT_02 - EC727_N_INPUT_01);
    int s_nid = c_nid + EC727_N_INPUT_01_STARTIDX - EC727_N_INPUT_01;
    int e_nid = c_nid + EC727_N_INPUT_01_ENDIDX - EC727_N_INPUT_01;
    if (TreeIsOn(c_nid) & 1)
    {
      status = DevLong(&s_nid,(int *)&raw.bounds[0].l);
      if (status&1) raw.bounds[0].l = min(1023,max(0,raw.bounds[0].l));
      else raw.bounds[0].l = 0;

      status = DevLong(&e_nid, (int *)&raw.bounds[0].u);
      if (status&1) raw.bounds[0].u = min(1023,max(0,raw.bounds[0].u));
      else raw.bounds[0].u = 1023;

      raw.m[0] = raw.bounds[0].u - raw.bounds[0].l + 1;
      if (raw.m[0] > 0)
      {
        for (i=0;i<1024;i++) cdata[i] = data[i][chan];
        raw.pointer = (char *)(cdata + (raw.bounds[0].l));
        raw.a0 = (char *)cdata;
        raw.arsize = raw.m[0] * 4;
        TdiCompile(&sigdef,&raw,&xfer_in_d,&start_d,&end_d,&signal MDS_END_ARG);
        status = TreePutRecord(c_nid,(struct descriptor *)signal.pointer,0);
      }
    }
  }
  return status;
}
Example #6
0
int l8206___store(struct descriptor *niddsc_ptr, InStoreStruct *setup)
{
  int status;
  int savstatus;
  int upload_nid = setup->head_nid + L8206_N_UPLOAD;
  pio(19,&zero);
  if (TreeIsOn(upload_nid)&1)
  { 
    int numpoints = 0;
    short *bptr;
    int pread;
    pio(8,0);
    if (CamQ(0) & 1)
    {
      numpoints = 65536;
    }
    else
    {
      pio(0,&numpoints);
    }
    pio(25,0);
    pio(18,&zero);
    pio(2,&buffer[0]); /* junk word */
    for (pread = 0,bptr = buffer; pread < numpoints;)
    {
      int num = numpoints - pread;
      if (num > 32767) num = 32767;
      stop(2,num,bptr);
      pread += num;
      bptr += num;
    }
    if (numpoints > 0)
    {
      data.arsize = numpoints * sizeof(short);
      status = TreePutRecord(upload_nid,(struct descriptor *)&data,0);
    }
    else
      status = L8206$_NODATA;
  }
  savstatus = status;
  pio(18,&zero);
  pio(11,&zero);
  pio(26,&zero);
  if (status & 1) status = savstatus;
  return status;
}
Example #7
0
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;
}
Example #8
0
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;
}
Example #9
0
int hv1443__get_settings(struct descriptor *niddsc_ptr, struct descriptor *meth, int max_chans, int *settings)
{
  int status = 1;
  static InGet_settingsStruct setup;
  if (max_chans != HV1443_K_CHANS) return HV1440$_WRONG_POD_TYPE;
  status = hv1443___get_settings(niddsc_ptr, &setup);
  if (status & 1)
  {
    int i;
    for (i=0; i<HV1443_K_CHANS; i++) {
      int nid = setup.head_nid + HV1443_N_VOLTAGE_01 + i;
      if (TreeIsOn(nid)&1) {
        if ((DevLong(&nid, &settings[i])&1)==0)
          settings[i] = 0;
      }
      else 
        settings[i] = 0;
    }
    GenDeviceFree(&setup);
  }
  return status;
}
Example #10
0
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;
}
Example #11
0
	/****************************************************************
	 * TclDoMethod:
	 ****************************************************************/
int TclDoMethod()
   {
    int   i;
    int   argc;
    int   sts;
    unsigned char  do_it;
    struct descriptor_xd xdarg[255];
    static int   nid;
    static unsigned short boolVal;
    static struct descriptor_s bool_dsc =
                    {sizeof(boolVal), DTYPE_W, CLASS_S, (char *)&boolVal};
    static struct descriptor nid_dsc = {4,DTYPE_NID,CLASS_S,(char *)&nid};
    static struct descriptor_xd empty_xd = {0,DTYPE_DSC,CLASS_XD,0,0};
    static DYNAMIC_DESCRIPTOR(arg);
    static DYNAMIC_DESCRIPTOR(if_clause);
    static DYNAMIC_DESCRIPTOR(method);
    static DYNAMIC_DESCRIPTOR(object);
    static void  *arglist[256] = {(void *)2,&nid_dsc,&method};

    cli_get_value("OBJECT",&object);
    sts = TreeFindNode(object.dscA_pointer,&nid);
    if (sts & 1)
       {
        do_it = (TreeIsOn(nid) | cli_present("OVERRIDE")) & 1;
        if (cli_present("IF") & 1)
           {
            cli_get_value("IF",&if_clause);
            sts = TdiExecute(&if_clause,&bool_dsc MDS_END_ARG);
            if (sts & 1)
                do_it = do_it && boolVal;
            else
                do_it = 0;
           }
        if (do_it)
           {
            int dometh_stat;
            DESCRIPTOR_LONG(dometh_stat_d,0);
            cli_get_value("METHOD",&method);
            argc = 0;
            if (cli_present("ARGUMENT") & 1)
               {
                while (cli_get_value("ARGUMENT",&arg) & 1)
                   {
                    xdarg[argc] = empty_xd;
                    sts = TdiCompile(&arg,&xdarg[argc] MDS_END_ARG);
                    if (sts & 1)
                       {
                        arglist[argc + 3] = xdarg[argc].dscA_pointer;
                        argc++;
                       }
                    else
                        break;
                   }
               }
            if (sts & 1)
               {
#ifdef vms
                arglist[0] = (void *)(argc + 2);
#else
                dometh_stat_d.dscA_pointer = (char *)&dometh_stat;
                arglist[argc+3] = &dometh_stat_d;
                arglist[argc+4] = MdsEND_ARG;
                arglist[0] = (argc + 4)+(char *)0;
#endif

		sts = (char *)LibCallg(arglist,TreeDoMethod)-(char *)0;
                if (sts & 1) sts = dometh_stat;
               }
            str_free1_dx(&arg);
            str_free1_dx(&method);
            for (i = 0; i < argc; i++)
                MdsFree1Dx(&xdarg[i],NULL);
           }
       }
    str_free1_dx(&object);
#ifdef vms
    if (!(sts & 1)) lib$signal(sts,0);
#else
	if (!(sts & 1))
	{
		char msg[512];
		sprintf(msg,"Error executing method - %s",MdsGetMsg(sts));
		TclTextOut(msg);
	}
#endif
    return sts;
   }
Example #12
0
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);
	  }
        }
      }
Example #13
0
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;
}
Example #14
0
static int Store(struct descriptor *niddsc_ptr, InStoreStruct *setup, int sort)
{
  static struct descriptor rpt_name = {0,DTYPE_T,CLASS_D,0};
  static struct descriptor name = {0,DTYPE_T,CLASS_D,0};
  static struct descriptor names[10] = {{0,DTYPE_T,CLASS_D,0},
                                              {0,DTYPE_T,CLASS_D,0},
                                              {0,DTYPE_T,CLASS_D,0},
                                              {0,DTYPE_T,CLASS_D,0},
                                              {0,DTYPE_T,CLASS_D,0},
                                              {0,DTYPE_T,CLASS_D,0},
                                              {0,DTYPE_T,CLASS_D,0},
                                              {0,DTYPE_T,CLASS_D,0},
                                              {0,DTYPE_T,CLASS_D,0},
                                              {0,DTYPE_T,CLASS_D,0}};
  static struct descriptor_xd limits[10] = {{0,DTYPE_DSC,CLASS_XD,0,0},
                                                {0,DTYPE_DSC,CLASS_XD,0,0},
                                                {0,DTYPE_DSC,CLASS_XD,0,0},
                                                {0,DTYPE_DSC,CLASS_XD,0,0},
                                                {0,DTYPE_DSC,CLASS_XD,0,0},
                                                {0,DTYPE_DSC,CLASS_XD,0,0},
                                                {0,DTYPE_DSC,CLASS_XD,0,0},
                                                {0,DTYPE_DSC,CLASS_XD,0,0},
                                                {0,DTYPE_DSC,CLASS_XD,0,0},
                                                {0,DTYPE_DSC,CLASS_XD,0,0}};

  TIME *tims[10];
  float *vals[10];  
  int   nums[10];
  int   sizes[10];

  int delete_file_nid = setup->head_nid + PARAGON_HIST_N_DELETE_FILE;
  int i;
  int status;
  char line[256];
  FILE *file;
  int isftp;
  status = PARAGON_FTP_COPY(setup->report_name,&rpt_name,&isftp);
  if (!(status & 1))
  {
    return(status);
  }
  for (i=0; i<10; i++) {
    int name_nid = setup->head_nid + PARAGON_HIST_N_NAME_0 + i;
    nums[i] = 0;
    tims[i] = NULL;
    vals[i] = NULL;
    status = DevText(&name_nid, &names[i]);
    if (status) {
      static int limit_nid;
      static DESCRIPTOR_NID(nid_dsc,&limit_nid);
      limit_nid = setup->head_nid + PARAGON_HIST_N_LIMIT_0 + i;
      status = TdiData(&nid_dsc, &limits[i] MDS_END_ARG);
      if (!(status&1)) MdsFree1Dx(&limits[i],0);
      nums[i] = 0;
      sizes[i] = INITIAL_SIZE;
      tims[i] = (TIME *)malloc(sizeof(TIME)*INITIAL_SIZE);    
      vals[i] = (float *)malloc(sizeof(float)*INITIAL_SIZE);    
    }
  }
  file = fopen(rpt_name.pointer,"r");
  if (file != NULL) {
    while(fgets(line,255,file)) {
      TIME time;
      float  value;
      if (strlen(line) >= 70) {
        if (ParseHistorian(line, &name, &value, &time) ) {
          for (i=0; i<10;) {
            if (StrCompare(&name, &names[i])==0)
              break;
            else
              i++;         
          }
          if (i < 10) {
            if (nums[i] >= sizes[i]) {
              TIME *t_time = tims[i];
              float *t_val = vals[i];
              int j;
              tims[i] = (TIME *)malloc(sizeof(TIME)*sizes[i]*2);    
              vals[i] = (float *)malloc(sizeof(float)*sizes[i]*2);    
              for (j=0; j<sizes[i]; j++) {
                (tims[i])[j] = t_time[j];              
                (vals[i])[j] = t_val[j];              
              }
              sizes[i]*=2;
              free(t_time);
              free(t_val);
            }              
            (tims[i])[nums[i]] = time;
            (vals[i])[nums[i]] = value;
            nums[i]++;
          }
        }
      }
    }
    fclose(file);
    for (i=0; i<10; i++) {
      if (nums[i]) {
        int value_nid = setup->head_nid + PARAGON_HIST_N_VALUE_0 + i;
        if (TreeIsOn(value_nid)&1)
          StoreSignal(value_nid, nums[i], vals[i], tims[i], &limits[i], sort);
      }
      if (vals[i])
        free(vals[i]);
      if (tims[i])
        free(tims[i]);
    }
    PARAGON_FTP_DELETE(setup->report_name,TreeIsOn(delete_file_nid));
  }
  return 1;
}
Example #15
0
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;
}
Example #16
0
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;
}
Example #17
0
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;
}
Example #18
0
int l2256___store(struct descriptor *niddsc, InStoreStruct *setup)
{
  static struct descriptor  name = {0,DTYPE_T,CLASS_D,0};
  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 trigger_nid;
  static DESCRIPTOR_NID(trigger_d,&trigger_nid);
  static float frequency;
  static DESCRIPTOR_FLOAT(frequency_d,&frequency);
  static DESCRIPTOR_RANGE(int_clock_d,0,0,&frequency_d);
  static int ext_clock_nid;
  static DESCRIPTOR_NID(ext_clock_d,&ext_clock_nid);
  static float coefficient = .002;
  static DESCRIPTOR_FLOAT(coef_d,&coefficient);
  static float offset = 0;
  static struct descriptor_s  offset_d    = {4,DTYPE_NATIVE_FLOAT,CLASS_S,(char *)&offset};
  static int key;
  static DESCRIPTOR_LONG(key_d,&key);
  static DESCRIPTOR_FUNCTION_1(value,(unsigned char *)&OpcValue,0);
  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 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);
  static float dts[] = {0.,5.e-6,2.e-6,1.e-6,500.e-9,200.e-9,100.e-9,50.e-9};
  static int pre[] = {0, 128, 256, 348, 512, 640, 768, 896};
  int channel_nid = setup->head_nid + L2256_N_INPUT;
  short channel_data[1024];
  int status=1;
  int maxidx;
  int minidx;
  int i;
  int pts;

#pragma member_alignment save
#pragma nomember_alignment
  struct { unsigned __attribute__ ((packed)) frequency : 3;
           unsigned __attribute__ ((packed)) pre       : 3;
           unsigned __attribute__ ((packed)) offset    : 8;
         }  reg;
#pragma member_alignment restore

  if (TreeIsOn(channel_nid) & 1)
  {
    value.ndesc = 0;
    pio(8,0);
    if ((CamXandQ(0)&1) == 0) return DEV$_NOT_TRIGGERED;
    ext_clock_nid = setup->head_nid + L2256_N_EXT_CLOCK;
    trigger_nid = setup->head_nid + L2256_N_TRIGGER;
    pio(9,0);
    pio(27,0);
    pioqrep(1,0,(short *)&reg);
    offset = reg.offset * -.002;
    frequency = dts[reg.frequency];
    pts = 1024 - pre[reg.pre];
    raw.bounds[0].u = pts;
    raw.bounds[0].l = pts - 1023;
    raw.pointer = (char *)channel_data;
    dimension.axis = (reg.frequency == 0) ? (struct descriptor *)&ext_clock_d : (struct descriptor *)&int_clock_d;
    raw.m[0] = 1024;
    raw.arsize = sizeof(channel_data);
    raw.a0 = (char *)(channel_data - raw.bounds[0].l);
    fstopw(2,0,1024,channel_data);
    if (status & 1)
        status = TreePutRecord(channel_nid,(struct descriptor *)&signal,0);
  }
  return status;
}