示例#1
0
文件: fera.c 项目: LucyScott/mdsplus
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;
}
示例#2
0
文件: l6810.c 项目: LucyScott/mdsplus
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;
}
示例#3
0
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;
}
示例#4
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;
}
示例#5
0
文件: t4012.c 项目: LucyScott/mdsplus
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);
  }
}
示例#6
0
文件: l6810.c 项目: LucyScott/mdsplus
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;
}
示例#7
0
文件: fera.c 项目: LucyScott/mdsplus
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;
}