Exemple #1
0
int l4202___init(struct descriptor *niddsc, InInitStruct *setup)
{ 
  int status;
  int tries;
  struct {
           unsigned char bursts;
           unsigned      increment: 15;
           unsigned      loop : 1;
         } setup1;
  struct {
           unsigned       range    : 4;
           unsigned       overflow : 20;
         } setup2;

  setup1.bursts = setup->num_spectra - 1;
  setup1.increment = setup->router_inc/256;
  setup1.loop = 1;
  pio(setup->name,17,0,(int *)&setup1);  /* Write router command */
  pio(setup->name,16,0,&setup->offset);  /* Write offset register */
  for (setup2.range=1; setup2.range < 15 && ((1 << (setup2.range - 1)) * .15625) < setup->resolution; setup2.range++);
  setup2.overflow = setup->router_inc * setup->resolution /160 + .499999;
  pio(setup->name,18,0,(int *)&setup2); /* Write overflow register */
  pio(setup->name,9,0,0);  /* reset memory */
  pio(setup->name,10,0,0); /* reset LAM    */
  pio(setup->name,10,0,0); /* reset LAM    */
  pio(setup->name,26,0,0); /* enable LAM   */
  pio(setup->memory_name,10,0,0); /* reset LAM    */
  pio(setup->memory_name,9,0,0);  /* reset memory */
  pio(setup->memory_name,26,0,0); /* enable LAM   */
  pio(setup->memory_name,8,0,0);
  for (tries=0;(!(CamXandQ(0)&1)) && tries < max_tries;tries++) {
    float wait=.5;
    pio(setup->memory_name,8,0,0);
    LibWait(&wait);
  } /* wait for LAM */
  pio(setup->memory_name,10,0,0); /* reset LAM    */
  pio(setup->memory_name,11,0,0); /* enable front panel histogram */
  return status;
}
Exemple #2
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;
}
Exemple #3
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;
}
Exemple #4
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;
}