#include #include #include #include #include #include #include #include /* the header of the shared library */ #include "daq.h" #define DEVICE_NAME "/dev/cc32_1" /* definiram lokacije diskriminatorja, stevca in vhodno/izhodnega registra*/ #define NIO 10 /* CAEN C219 */ #define NSC 12 /* CAEN C257 */ #define NDI 16 /* Philips 7106 */ CC32_HANDLE handle; int daq::start(int thr_set){ printf("Nastavljam threshold na %d \n",thr_set); cc32_write_word (handle, NIO, 0, 16, 0x1); /* postavimo zeljeni prag prozenja */ cc32_write_word (handle, NDI, 0, 17, thr_set); cc32_write_word (handle, NDI, 1, 17, 0); /* stevec postavim na nic */ cc32_read_long (handle, NSC, 0, 9); /* oblikujem poslani signal */ cc32_write_word (handle, NIO, 0, 16, 0x0); sleep ( 1 ) ; cc32_write_word (handle, NIO, 0, 16, 0x1); return 0; } int daq::count(){ /* prestejem sunke na posameznem kanalu */ for ( int ch=0 ; ch<16 ; ch ++ ) { unsigned int data=cc32_read_long (handle, NSC, ch, 0); gData[ch]=data; //printf("%d %d 0x%x\n",ch,data,data); } return 0; } int daq::save(){ /* shrani */ FILE *fp; int ch; if ( ( fp = fopen ( "scaler.txt", "w+" ) ) == NULL ) printf ( "ERROR" ) ; for ( ch=0; ch<16 ; ch++ ) { fprintf ( fp, "%d\t%d\n", ch, gData[ch] ) ; } fclose ( fp ) ; return 0; } int daq::append(char *filename){ /* zapisi v tekstovno datoteko */ //GetCtrlVal (p1h, P1_APFILE, filename); FILE *fp=fopen ( filename, "a" ); if ( fp!= NULL ){ for ( int ch=0; ch<16 ; ch++ ) fprintf ( fp, "%d\t", gData[ch] ) ; fprintf ( fp, "\n" ) ; fclose ( fp ) ; printf("Rezultati meritve so dodani v datoteko %s\n",filename); } else { printf ( "ERROR" ) ; } return 0; } int daq::init(){ /* inicializacija vhodno/izhodnega registera */ cc32_read_word (handle, NIO, 0, 9); /* Status register */ cc32_write_word (handle, NIO, 0, 17, 0x6); /* (0).. 1 output..input 0 ..(2) negative..positive logic 0 ..(4) glitched..normal work. mode (0).. 8 transparent..externally strobed */ cc32_write_word (handle, NDI, 0, 16, 0xffff); cc32_write_word (handle, NDI, 0, 26, 0); return 0; } int daq::connect(){ char *fname = DEVICE_NAME; int error; if ((error = cc32_open(fname, &handle))) { fprintf(stderr, "%s: %s\n", fname, strerror(error)); exit(1); } else printf("cc32 opened\n"); return 0; } int daq::disconnect(){ /* zakljuci */ cc32_close(handle); printf("cc32 closed.\n"); return 0; } daq::daq(){ connect(); init(); } daq::~daq(){ disconnect(); } #ifdef MAIN int main (int argc, char **argv){ int threshold=250; char *filename="output.txt"; if (argc>1) threshold = atoi(argv[1]); if (argc>2) filename = argv[2]; daq *d= new daq(); d->init(); d->start(threshold); // threshold d->count(); d->append(filename); delete d; return 0; } #endif