コード例 #1
0
ファイル: feserial.c プロジェクト: cjpl/midas
INT read_trigger_event(char *pevent, INT off)
{
   WORD *pdata, a;
   INT j;

   /* init bank structure */
   bk_init(pevent);

   /* create structured ADC0 bank */
   bk_create(pevent, "ADC0", TID_WORD, &pdata);
   /* Use following code to "simulate" data */
   for (a = 0; a < 3; a++)
      *pdata++ = rand() % 1024;
   rs232(CMD_GETS, info, strin, 256, 0, 500);
   for (j=0;j<256;j++) {
    if (strin[j] != 0)
      *pdata++ = strin[j];
   }

   bk_close(pevent, pdata);

   /* create variable length TDC bank */
   bk_create(pevent, "TDC0", TID_WORD, &pdata);
   /* Use following code to "simulate" data */
   for (a = 0; a < 3; a++)
      *pdata++ = rand() % 1024;
   bk_close(pevent, pdata);

   return bk_size(pevent);
}
コード例 #2
0
ファイル: mscb_ring.c プロジェクト: uwmuonlab/gm2-nmr-daq
//fill mbank from /equip/environ/variables
INT read_periodic_event(char *pevent, INT off){
  printf("Reading Periodic Event\n");
  HNDLE hDB;
  cm_get_experiment_database(&hDB, NULL);

  HNDLE hkey;
  float temp1[3];
  INT size;
  // get key handle for temp
  db_find_key(hDB, 0, "/Equipment/Temperature/Variables/Input", &hkey);
  // return temp
  size = sizeof(temp1);
  db_get_data(hDB, hkey, &temp1, &size, TID_FLOAT);

  //char *pevent;
  bk_init(pevent);
  float *pdata;
  //  *pdata = temp1[0];
   // create SCLR bank
     bk_create(pevent, "NEW1", TID_FLOAT, &pdata);


// *pdata = 29.3;
printf("%f\n",temp1[0]);

   // close SCLR bank
bk_close(pevent, pdata);
printf("eo fB\n");
   return bk_size(pevent);


}
コード例 #3
0
ファイル: tinyfe.c プロジェクト: cjpl/midas
INT read_tiny_event(char *pevent, INT offset)
{
   static WORD *pdata = NULL;
   static WORD sub_counter = 0;
   // Super event structure 
   if (offset == 0) {           // FIRST event of the Super event 
      bk_init(pevent);
      bk_create(pevent, "SUPR", TID_WORD, &pdata);
      sub_counter = 1;
   } else if (offset == -1) {   // CLOSE Super event
      bk_close(pevent, pdata);
      return bk_size(pevent);
   }
   // READ event
   *pdata++ = 0xB0E;
   *pdata++ = sub_counter++;
   *pdata++ = 0xE0E;

   if (offset == 0) {
      // Compute the proper event length on the FIRST event in the Super Event
      // NWORDS correspond to the !! NWORDS WORD above !!
      // sizeof(BANK_HEADER) + sizeof(BANK) will make the 16 bytes header
      // sizeof(WORD) is defined by the TID_WORD in bk_create()
      return NWORDS * sizeof(WORD) + sizeof(BANK_HEADER) + sizeof(BANK);
   } else {
      // Return the data section size only
      // sizeof(WORD) is defined by the TID_WORD in bk_create()
      return NWORDS * sizeof(WORD);
   }
}
コード例 #4
0
ファイル: cd_fgd.c プロジェクト: cjpl/midas
INT cd_fgd_read(char *pevent, int offset)
{
   float *pdata;
   FGD_INFO *fgd_info;
   EQUIPMENT *pequipment;

   pequipment = *((EQUIPMENT **) pevent);
   fgd_info = (FGD_INFO *) pequipment->cd_info;

   if (fgd_info->format == FORMAT_FIXED) {
      memcpy(pevent, fgd_info->demand, sizeof(float) * fgd_info->num_channels);
      pevent += sizeof(float) * fgd_info->num_channels;

      memcpy(pevent, fgd_info->measured, sizeof(float) * fgd_info->num_channels);
      pevent += sizeof(float) * fgd_info->num_channels;

      return 2 * sizeof(float) * fgd_info->num_channels;
   } else if (fgd_info->format == FORMAT_MIDAS) {
      bk_init(pevent);

      /* create VDMD bank */
      bk_create(pevent, "VDMD", TID_FLOAT, &pdata);
      memcpy(pdata, fgd_info->demand, sizeof(float) * fgd_info->num_channels);
      pdata += fgd_info->num_channels;
      bk_close(pevent, pdata);

      /* create IMES bank */
      bk_create(pevent, "IMES", TID_FLOAT, &pdata);
      memcpy(pdata, fgd_info->measured, sizeof(float) * fgd_info->num_channels);
      pdata += fgd_info->num_channels;
      bk_close(pevent, pdata);

      /* create TEMP1 bank */
      bk_create(pevent, "TEM1", TID_FLOAT, &pdata);
      memcpy(pdata, fgd_info->temp1, sizeof(float) * fgd_info->num_channels);
      pdata += fgd_info->num_channels;
      bk_close(pevent, pdata);

      /* create TEMP2 bank */
      bk_create(pevent, "TEM2", TID_FLOAT, &pdata);
      memcpy(pdata, fgd_info->temp2, sizeof(float) * fgd_info->num_channels);
      pdata += fgd_info->num_channels;
      bk_close(pevent, pdata);

      /* create TEMP1 bank */
      bk_create(pevent, "TEM3", TID_FLOAT, &pdata);
      memcpy(pdata, fgd_info->temp3, sizeof(float) * fgd_info->num_channels);
      pdata += fgd_info->num_channels;
      bk_close(pevent, pdata);

      return bk_size(pevent);
   } else if (fgd_info->format == FORMAT_YBOS) {
     printf("Not implemented\n");
     return 0;
   } else
     return 0;
}
コード例 #5
0
ファイル: frontend.c プロジェクト: cjpl/mdaq-samples
INT read_scaler_event(char *pevent, INT off)
{
   DWORD *pdata, a;

   /* init bank structure */
   bk_init(pevent);

   /* create SCLR bank */
   bk_create(pevent, "SCLR", TID_DWORD, &pdata);

   /* read scaler bank */
   for (a = 0; a < N_SCLR; a++)
      cam24i(CRATE, SLOT_SCLR, a, 0, pdata++);

   bk_close(pevent, pdata);

   return bk_size(pevent);
}
コード例 #6
0
ファイル: generic.c プロジェクト: gm2-pisa/midas
INT cd_gen_read(char *pevent, int offset)
{
   float *pdata;
   GEN_INFO *gen_info;
   EQUIPMENT *pequipment;
#ifdef HAVE_YBOS
   DWORD *pdw;
#endif

   pequipment = *((EQUIPMENT **) pevent);
   gen_info = (GEN_INFO *) pequipment->cd_info;

   if (gen_info->format == FORMAT_FIXED) {
      memcpy(pevent, gen_info->demand, sizeof(float) * gen_info->num_channels);
      pevent += sizeof(float) * gen_info->num_channels;

      memcpy(pevent, gen_info->measured, sizeof(float) * gen_info->num_channels);
      pevent += sizeof(float) * gen_info->num_channels;

      return 2 * sizeof(float) * gen_info->num_channels;
   } else if (gen_info->format == FORMAT_MIDAS) {
      bk_init(pevent);

      /* create DMND bank */
      bk_create(pevent, "DMND", TID_FLOAT, (void **)&pdata);
      memcpy(pdata, gen_info->demand, sizeof(float) * gen_info->num_channels);
      pdata += gen_info->num_channels;
      bk_close(pevent, pdata);

      /* create MSRD bank */
      bk_create(pevent, "MSRD", TID_FLOAT, (void **)&pdata);
      memcpy(pdata, gen_info->measured, sizeof(float) * gen_info->num_channels);
      pdata += gen_info->num_channels;
      bk_close(pevent, pdata);

      return bk_size(pevent);
   } else if (gen_info->format == FORMAT_YBOS) {
#ifdef HAVE_YBOS
      ybk_init((DWORD *) pevent);

      /* create EVID bank */
      ybk_create((DWORD *) pevent, "EVID", I4_BKTYPE, (DWORD *) (&pdw));
      *(pdw)++ = EVENT_ID(pevent);      /* Event_ID + Mask */
      *(pdw)++ = SERIAL_NUMBER(pevent); /* Serial number */
      *(pdw)++ = TIME_STAMP(pevent);    /* Time Stamp */
      ybk_close((DWORD *) pevent, pdw);

      /* create DMND bank */
      ybk_create((DWORD *) pevent, "DMND", F4_BKTYPE, (DWORD *) & pdata);
      memcpy(pdata, gen_info->demand, sizeof(float) * gen_info->num_channels);
      pdata += gen_info->num_channels;
      ybk_close((DWORD *) pevent, pdata);

      /* create MSRD bank */
      ybk_create((DWORD *) pevent, "MSRD", F4_BKTYPE, (DWORD *) & pdata);
      memcpy(pdata, gen_info->measured, sizeof(float) * gen_info->num_channels);
      pdata += gen_info->num_channels;
      ybk_close((DWORD *) pevent, pdata);

      return ybk_size((DWORD *) pevent);
#else
      assert(!"YBOS support not compiled in");
#endif
   }

   return 0;
}
コード例 #7
0
ファイル: frontend.c プロジェクト: cjpl/mdaq-samples
INT read_trigger_event(char *pevent, INT off)
{
   WORD *pdata, a;
   INT q, timeout;

   /* init bank structure */
   bk_init(pevent);

   /* create structured ADC0 bank */
   bk_create(pevent, "ADC0", TID_WORD, &pdata);

   /* wait for ADC conversion */
   for (timeout = 100; timeout > 0; timeout--) {
      camc_q(CRATE, SLOT_ADC, 0, 8, &q);
      if (q)
         break;
   }
   if (timeout == 0)
      ss_printf(0, 10, "No ADC gate!");

   /* use following code to read out real CAMAC ADC */
   /*
      for (a=0 ; a<N_ADC ; a++)
      cami(CRATE, SLOT_ADC, a, 0, pdata++);
    */

   /* Use following code to "simulate" data */
   for (a = 0; a < N_ADC; a++)
      *pdata++ = rand() % 1024;

   /* clear ADC */
   camc(CRATE, SLOT_ADC, 0, 9);

   bk_close(pevent, pdata);

   /* create variable length TDC bank */
   bk_create(pevent, "TDC0", TID_WORD, &pdata);

   /* use following code to read out real CAMAC TDC */
   /*
      for (a=0 ; a<N_TDC ; a++)
      cami(CRATE, SLOT_TDC, a, 0, pdata++);
    */

   /* Use following code to "simulate" data */
   for (a = 0; a < N_TDC; a++)
      *pdata++ = rand() % 1024;

   /* clear TDC */
   camc(CRATE, SLOT_TDC, 0, 9);

   bk_close(pevent, pdata);

   /* clear IO unit LAM */
   camc(CRATE, SLOT_IO, 0, 10);

   /* clear LAM in crate controller */
   cam_lam_clear(CRATE, SLOT_IO);

   /* reset external LAM Flip-Flop */
   camo(CRATE, SLOT_IO, 1, 16, 0xFF);
   camo(CRATE, SLOT_IO, 1, 16, 0);

   ss_sleep(10);

   return bk_size(pevent);
}
コード例 #8
0
ファイル: multi.c プロジェクト: gm2-pisa/midas
INT cd_multi_read(char *pevent, int offset)
{
   float *pdata;
   MULTI_INFO *m_info;
   EQUIPMENT *pequipment;
#ifdef HAVE_YBOS
   DWORD *pdw;
#endif

   pequipment = *((EQUIPMENT **) pevent);
   m_info = (MULTI_INFO *) pequipment->cd_info;

   if (m_info->format == FORMAT_FIXED) {
      memcpy(pevent, m_info->var_input, sizeof(float) * m_info->num_channels_input);
      pevent += sizeof(float) * m_info->num_channels_input;

      memcpy(pevent, m_info->var_output, sizeof(float) * m_info->num_channels_output);
      pevent += sizeof(float) * m_info->num_channels_output;

      return sizeof(float) * (m_info->num_channels_input + m_info->num_channels_output);
   } else if (m_info->format == FORMAT_MIDAS) {
      bk_init(pevent);

      /* create INPT bank */
      if (m_info->num_channels_input) {
         bk_create(pevent, "INPT", TID_FLOAT, (void **)&pdata);
         memcpy(pdata, m_info->var_input, sizeof(float) * m_info->num_channels_input);
         pdata += m_info->num_channels_input;
         bk_close(pevent, pdata);
      }

      /* create OUTP bank */
      if (m_info->num_channels_output) {
         bk_create(pevent, "OUTP", TID_FLOAT, (void **)&pdata);
         memcpy(pdata, m_info->var_output, sizeof(float) * m_info->num_channels_output);
         pdata += m_info->num_channels_output;
         bk_close(pevent, pdata);
      }

      return bk_size(pevent);
   } else if (m_info->format == FORMAT_YBOS) {
#ifdef HAVE_YBOS
      ybk_init((DWORD *) pevent);

      /* create EVID bank */
      ybk_create((DWORD *) pevent, "EVID", I4_BKTYPE, (DWORD *) (&pdw));
      *(pdw)++ = EVENT_ID(pevent);      /* Event_ID + Mask */
      *(pdw)++ = SERIAL_NUMBER(pevent); /* Serial number */
      *(pdw)++ = TIME_STAMP(pevent);    /* Time Stamp */
      ybk_close((DWORD *) pevent, pdw);

      /* create INPT bank */
      ybk_create((DWORD *) pevent, "INPT", F4_BKTYPE, (DWORD *) & pdata);
      memcpy(pdata, m_info->var_input, sizeof(float) * m_info->num_channels_input);
      pdata += m_info->num_channels_input;
      ybk_close((DWORD *) pevent, pdata);

      /* create OUTP bank */
      ybk_create((DWORD *) pevent, "OUTP", F4_BKTYPE, (DWORD *) & pdata);
      memcpy(pdata, m_info->var_output, sizeof(float) * m_info->num_channels_output);
      pdata += m_info->num_channels_output;
      ybk_close((DWORD *) pevent, pdata);

      return ybk_size((DWORD *) pevent);
#lese
      assert(!"YBOS support not compiled in");
#endif
   }

   return 0;
}
コード例 #9
0
ファイル: frontend.c プロジェクト: alcap-org/AlcapDAQ
INT read_temperature_probe(char *pevent, INT off){
//
//  static char oldtimestamp[80];
//  char timestamp[80];
//  char timestring[80];
//  FILE *infile=NULL;
  float *pdata;
//  static float lastHVs[4] = {-1., -1., -1., -1.};
//  static int initDone = 0;
//  int i;
//
//  size = sizeof(sepDemand);
//  db_get_value(hDB,0, "/Experiment/Edit on start/Temperature HV",
//	       &sepDemand, &size, TID_INT, 1);
//
//  timestamp[0]='\0';
//
//  infile=fopen("/tmp/temperature.txt","r");
//  if (infile==NULL){
//    cm_msg(MERROR,frontend_name,
//	   "Could not open tempfile. temperature_daemon.pl not running?");
//    temperature_data.hv =-1;
//    temperature_data.vac =-1;
//    temperature_data.sep_stat =-1;
//  }
//  else{
//    fscanf(infile,"%s\n%f\n%f\n%f\n%f",timestamp,&temperature_data.hv,
//	   &temperature_data.current,&temperature_data.vac,
//	   &temperature_data.sep_stat);
//    fclose(infile);
//    
//    if(!strcmp(oldtimestamp, timestamp)){
//      temperature_data.hv=-1;
//      temperature_data.vac=-1;
//      temperature_data.sep_stat=-1;
//    }
//  }  
//  
//  if(initDone == 0){
//    for(i=0; i<4; i++) lastHVs[i] = temperature_data.hv;
//    initDone = 1;
//  }
//  else{
//    for(i=0; i<3; i++) lastHVs[i] = lastHVs[i+1];
//    lastHVs[3] = temperature_data.hv;
//  }
//
//  //for(i=0; i<4; i++) printf("HV[%d]=%d\n",i,(int)lastHVs[i]);
//  //printf("Demand = %d\n", sepDemand);
//
  //Send to midas:
  bk_init(pevent);
//bk_create(pevent,"SEPA",TID_FLOAT,&pdata);
//pdata[0] = 1;
//  pdata[1] = temperature_data.current;
//  pdata[2] = temperature_data.vac;
//  pdata[3] = temperature_data.sep_stat;
//bk_close(pevent,pdata+0);
//
//  int sepError = 1;
//
//  for(i=0; i<4; i++){
//    if((int)lastHVs[i] == sepDemand) sepError = 0;
//  }
//
//  if(sepError==1){
//    if(strcmp(oldtimestamp, timestamp)){
//      cm_msg(MERROR,frontend_name,"Temperature high voltage not same as demand!");
//      printf("Demand = %d", sepDemand);
//    }
//    else{
//      cm_msg(MERROR,frontend_name,"Old and new timestamps identical."
//	     " Refresh too high or temperature_daemon.pl not running.");
//    }
//    int on = 1;
//    db_set_value(hDB, 0, Alarm, &on, sizeof(on), 1, TID_INT);
//  }
//  else{
//    int off = 0;
//    db_set_value(hDB, 0, Alarm, &off, sizeof(off), 1, TID_INT);
//  }
//
//  strcpy(oldtimestamp,timestamp);
//  
//  return bk_size(pevent);
//
  static int count=0;
  printf("hello from temperature probe %d\n", count++);
  return 1;
}
コード例 #10
0
ファイル: frontend.c プロジェクト: alcap-org/AlcapDAQ
INT ge_ln2_read(char *pevent, INT off) {

  static INT    status, size;
  static DWORD  lastfilled, now, timelimit;
  static BOOL   justfilled;
  static DWORD  *timesincefill;

  bk_init(pevent);
  timesincefill = NULL;

  // Get recent values
  size = sizeof(lastfilled);
  status = db_get_value(hDB, 0, sLastFilled, &lastfilled, &size, TID_DWORD, FALSE);
  if (status != DB_SUCCESS) {
    cm_msg(MERROR, "ge_ln2_read", "Error getting last filled time");
    return 0;
  }

  size = sizeof(justfilled);
  status = db_get_value(hDB, 0, sJustFilled, &justfilled, &size, TID_BOOL, FALSE);
  if (status != DB_SUCCESS) {
    cm_msg(MERROR, "ge_ln2_read", "Error getting just filled status");
    return 0;
  }

  size = sizeof(timelimit);
  status = db_get_value(hDB, 0, sTimeLimit, &timelimit, &size, TID_DWORD, FALSE);
  if (status != DB_SUCCESS) {
    cm_msg(MERROR, "ge_ln2_read", "Error getting time limit between fills");
    return 0;
  }

  // If just filled, write time to ODB
  if (justfilled == TRUE) {
    lastfilled = (DWORD)time(NULL);
    status = db_set_value(hDB, 0, sLastFilled, &lastfilled, sizeof(lastfilled), 1, TID_DWORD);
    if (status != DB_SUCCESS) {
      cm_msg(MERROR, "gn_ln2_read", "Error setting last filled time");
      return 0;
    }
    justfilled = FALSE;
    status = db_set_value(hDB, 0, sJustFilled, &justfilled, sizeof(justfilled), 1, TID_BOOL);
    if (status != DB_SUCCESS) {
      cm_msg(MERROR, "gn_ln2_read", "Error setting just filled status");
      return 0;
    }

    al_reset_alarm(sAlarmName);

    bk_create(pevent, "LN2F", TID_DWORD, &timesincefill);
    *timesincefill = 0;
    bk_close(pevent, ++timesincefill);

    return bk_size(pevent);
  }

  // Check the status
  bk_create(pevent, "LN2F", TID_DWORD, &timesincefill);
  now = (DWORD) time(NULL);
  *timesincefill = now - lastfilled;
  if (*timesincefill > timelimit) {
    al_trigger_alarm(sAlarmName, "Germanium must be filled!", "Alarm", "", AT_INTERNAL);
    printf("Alarm!\n");
  }
  bk_close(pevent, ++timesincefill);

  return bk_size(pevent);
}