DRS4 Forum
  DRS4 Discussion Forum  Not logged in ELOG logo
Entry  Tue Sep 10 10:31:30 2013, Akira Okumura, USB connection stops drs_simple.cpp
    Reply  Wed Sep 11 02:41:28 2013, Andrey Kuznetsov, USB connection stops 
       Reply  Wed Sep 25 14:42:00 2013, Akira Okumura, USB connection stops 
    Reply  Wed Jan 15 15:48:55 2014, Stefan Ritt, USB connection stops 
Message ID: 292     Entry time: Tue Sep 10 10:31:30 2013     Reply to this: 293   324
Author: Akira Okumura 
Subject: USB connection stops 
Hello the DRS4 team,

I and some of my colleagues are using DRS4 evaluation boards (ver. 3) for the R&D of the Cherenkov Telescope Array project. During 
our PMT measurements, we have encountered a problem which is probably related to USB connection. In fact, I cannot reproduce this 
problem with my Linux virtual machine (Scientific Linux 5 64 bit), but other colleagues from three different universities in Japan 
reported the same problem with their real machines.

=== Short Summary ===
DRSBoard::SetFrequency occasionally stops

=== Environment ===
- drs-3.0.0
- Scientific Linux 5.5 (32 bit)
- lib-usb-devel-0.1.12-5.1.i386

=== Steps to Reproduce the Problem ===
1. Compile the attached file drs_simple.cpp with drs-3.0.0
2. Repeat the following command several times from a terminal

$ drs_simple -0.05 1000 ./outputfilename.dat true 2.

3. The above command may stop. In that case, you need to kill the command by Ctrl-C.

=== Comments ===
- Once the command stops, we cannot run the above command properly.
- If we unplug and plug the USB cable again, the command can be executed again.
- It seems that the program stops inside DRSBoard::SetFrequency

I would very appreciate it if you could give me any advise. If you need further information, please let me know.

Akira
Attachment 1: drs_simple.cpp  5 kB  | Hide | Hide all
/********************************************************************\

  Name:         drs_simple.cpp
  Modified : Hide Katagiri
  Originally created by:   Stefan Ritt

  Contents:     Simple example application to read out a DRS4
                evaluation board

  $Id: drs_exam.cpp 13344 2009-04-28 07:34:45Z ritt@PSI.CH $

\********************************************************************/

#include <math.h>

#ifdef _MSC_VER

#include <windows.h>

#elif defined(OS_LINUX)

#define O_BINARY 0

#include <unistd.h>
#include <ctype.h>
#include <sys/ioctl.h>
#include <errno.h>

#define DIR_SEPARATOR '/'

#endif

#include <stdio.h>
#include <string.h>
#include <stdlib.h>

#include "strlcpy.h"
#include "DRS.h"

#include <fstream>
#include <iostream.h>//20130814 add tanaka

/*------------------------------------------------------------------*/

//std::cerr << "debug output 1" << std::endl;

int main(int argc, char *argv[])
{
   int i, j, nBoards;
   DRS *drs;
   DRSBoard *b;
   float time_array[1024];
   float wave_array[1][1024];// old ver. [8][1024]

std::cerr << "debug output 2" << std::endl;
   //// arguments, inirialization
   //
   float threshold=0.1;
   if (argc > 1) {
     threshold=atof(argv[1]); // in volt
   };
   //
std::cerr << "debug output 3" << std::endl;
   int nevent=10;
   if (argc > 2) {
     nevent=atoi(argv[2]); 
   };
   //
std::cerr << "debug output 4" << std::endl;
   char *fname="tmp.dat";
   if (argc > 3) {
     fname=argv[3]; 
   };
   //
std::cerr << "debug output 5" << std::endl;
   bool negative_edge=false; // true is negative
   if (argc > 3) {
     if (argv[4]=="true") {
       negative_edge=true; 
     };
   };
   //
std::cerr << "debug output 6" << std::endl;
   float freq=2.; // sampling frequency (GHz)
   if (argc > 4) {
     freq=atof(argv[5]); 
   };

std::cerr << "debug output 7" << std::endl;
   std::ofstream fout;
   fout.open(fname); // attention! file is truncated if the file fname already exists.
   if (!fout.is_open()) {
     exit(1);            
   }

std::cerr << "debug output 8" << std::endl;
   /* do initial scan */
   drs = new DRS();

std::cerr << "debug output 9" << std::endl;
   /* show any found board(s) */
   for (i=0 ; i<drs->GetNumberOfBoards() ; i++) {
      b = drs->GetBoard(i);
      printf("Found DRS4 evaluation board, serial #%d, firmware revision %d\n", 
         b->GetBoardSerialNumber(), b->GetFirmwareVersion());
   }

std::cerr << "debug output 10" << std::endl;
   /* exit if no board found */
   nBoards = drs->GetNumberOfBoards();
   if (nBoards == 0) {
      printf("No DRS4 evaluation board found\n");
      return 0;
   }

std::cerr << "debug output 11" << std::endl;
   /* continue working with first board only */
   b = drs->GetBoard(0);

std::cerr << "debug output 12" << std::endl;
   /* initialize board */
   b->Init();

std::cerr << "debug output 13" << std::endl;
   /* set sampling frequency */
   b->SetFrequency(freq, true);

std::cerr << "debug output 14" << std::endl;
   /* enable transparent mode needed for analog trigger */
   b->SetTranspMode(1);

std::cerr << "debug output 15" << std::endl;
   /* use following line to disable hardware trigger */
   //b->EnableTrigger(0, 0);

   /* use following line to enable external hardware trigger (Lemo) */
   b->EnableTrigger(1, 0);

std::cerr << "debug output 16" << std::endl;
   /* set input range to -0.5V ... +0.5V */
  // b->SetInputRange(0);
   b->SetInputRange(0.45); //does not work?

std::cerr << "debug output 17" << std::endl;
   /* use following lines to enable hardware trigger on CH1 at 250 mV positive edge */
   // b->EnableTrigger(0, 1);              // lemo off, analog trigger on
   // b->SetTriggerSource(0);              // use CH1 as source
   // b->SetTriggerLevel(0.25, false, 0);  // 0.25 V, positive edge, zero delay
   // b->SetTriggerLevel(threshold, negative_edge);  // -0.05 V, negative edge
   b->SetTriggerDelay(120);               // zero trigger delay, this places pulse in

std::cerr << "debug output 18" << std::endl;
   /* repeat nevent times */
   for (j=0 ; j<nevent ; j++) {

      /* start board (activate domino wave) */
      b->StartDomino();

//std::cerr << "debug output 19" << std::endl;
      /* wait for trigger */
      //fout << "% Start to read Event #" << j << std::endl;
      while (b->IsBusy());

//std::cerr << "debug output 20" << std::endl;      
      /* read all waveforms */
      b->TransferWaves(0, 8);

//std::cerr << "debug output 21" << std::endl;
      /* read time (X) array in ns */
      b->GetTime(0, time_array);

//std::cerr << "debug output 22" << std::endl;
      /* decode waveform (Y) array first channel in mV */
      b->GetWave(0, 0, wave_array[0]);

      /* decode waveform (Y) array second channel in mV*/
      // b->GetWave(0, 1, wave_array[1]);

      /* process waveform: add here some code to display or save waveform X=time[i], Y=wave_array[n][i] */

//std::cerr << "debug output 23" << std::endl;
      for (i=0;i<1024;i++) {
	fout << time_array[i] << " " << wave_array[0][i] << std::endl;
      }

//std::cerr << "debug output 24" << std::endl;
      /* print some progress indication */
      //fout << "% Event #" << j << " read successfully" << std::endl;
//std::cerr << "debug output 25" << std::endl;
   }

//std::cerr << "debug output 26" << std::endl;
   fout.close();
//std::cerr << "debug output 27" << std::endl;
   /* delete DRS object -> close USB connection */
   delete drs;
//std::cerr << "debug output 28" << std::endl;
}
ELOG V3.1.5-fe60aaf