#include #include #include #include #include int main(){ int ret; //#################################### Open digitizer uint64_t dev_handle; ret = CAEN_FELib_Open("dig2://192.168.0.100", &dev_handle); //#################################### Get some values char value[256]; ret = CAEN_FELib_GetValue(dev_handle, "/par/ModelName", value); printf("Model name:\t%s\n", value); ret = CAEN_FELib_GetValue(dev_handle, "/par/NumCh", value); short NChannel = atoi(value); printf("Channels:\t%u\n", NChannel); //#################################### Reset ret = CAEN_FELib_SendCommand(dev_handle, "/cmd/reset"); //#################################### Program digitizer /// Channel enable ret = CAEN_FELib_SetValue(dev_handle, "/ch/0..63/par/ChEnable", "true"); /// Global trigger configuration ret = CAEN_FELib_SetValue(dev_handle, "/par/GlobalTriggerSource", "SwTrg | TestPulse"); // use test Pulse ret = CAEN_FELib_SetValue(dev_handle, "/par/TestPulsePeriod", "100000000"); /// ns ret = CAEN_FELib_SetValue(dev_handle, "/par/TestPulseWidth", "16"); ///ns /// Wave configuration ret = CAEN_FELib_SetValue(dev_handle, "/ch/0..63/par/ChRecordLengthS", "512"); ret = CAEN_FELib_SetValue(dev_handle, "/ch/0..63/par/WaveTriggerSource", "GlobalTriggerSource"); ret = CAEN_FELib_SetValue(dev_handle, "/ch/0..63/par/WaveResolution", "RES8"); ret = CAEN_FELib_SetValue(dev_handle, "/ch/0..63/par/WaveAnalogProbe0", "ADCInput"); ret = CAEN_FELib_SetValue(dev_handle, "/ch/0..63/par/WaveAnalogProbe1", "TimeFilter"); ret = CAEN_FELib_SetValue(dev_handle, "/ch/0..63/par/WaveDigitalProbe0", "Trigger"); ret = CAEN_FELib_SetValue(dev_handle, "/ch/0..63/par/WaveDigitalProbe1", "TimeFilterArmed"); ret = CAEN_FELib_SetValue(dev_handle, "/ch/0..63/par/WaveDigitalProbe2", "EnergyFilterBaselineFreeze"); ret = CAEN_FELib_SetValue(dev_handle, "/ch/0..63/par/WaveDigitalProbe3", "EnergyFilterPeakReady"); ret = CAEN_FELib_SetValue(dev_handle, "/ch/0..63/par/ChPreTriggerS", "200"); /// Event configuration ret = CAEN_FELib_SetValue(dev_handle, "/ch/0..63/par/EventTriggerSource", "GlobalTriggerSource"); /// Filter parameters ret = CAEN_FELib_SetValue(dev_handle, "/ch/0..63/par/TimeFilterRiseTimeS", "10"); ret = CAEN_FELib_SetValue(dev_handle, "/ch/0..63/par/EnergyFilterRiseTimeS", "100"); ret = CAEN_FELib_SetValue(dev_handle, "/ch/0..63/par/EnergyFilterFlatTopS", "100"); ret = CAEN_FELib_SetValue(dev_handle, "/ch/0..63/par/TriggerThr", "3"); ret = CAEN_FELib_SetValue(dev_handle, "/ch/0..63/par/EnergyFilterPeakingPosition", "80"); ret = CAEN_FELib_SetValue(dev_handle, "/ch/0..63/par/EnergyFilterPoleZeroS", "1000"); ret = CAEN_FELib_SetValue(dev_handle, "/ch/0..63/par/TimeFilterRetriggerGuardS", "10"); ret = CAEN_FELib_SetValue(dev_handle, "/ch/0..63/par/EnergyFilterPileupGuardT", "10"); ret = CAEN_FELib_SetValue(dev_handle, "/ch/0..63/par/EnergyFilterBaselineGuardS", "100"); ret = CAEN_FELib_SetValue(dev_handle, "/ch/0..63/par/PulsePolarity", "Positive"); ret = CAEN_FELib_SetValue(dev_handle, "/ch/0..63/par/EnergyFilterLFLimitation", "Off"); ret = CAEN_FELib_SetValue(dev_handle, "/ch/0..63/par/EnergyFilterBaselineAvg", "Medium"); ret = CAEN_FELib_SetValue(dev_handle, "/ch/0..63/par/EnergyFilterFineGain", "1.0"); //#################################### Set the end point for data {//----------------------- RAW uint64_t ep_handle; ret = CAEN_FELib_GetHandle(dev_handle, "/endpoint/raw", &ep_handle); //---------- configure endpoint uint64_t ep_folder_handle; ret = CAEN_FELib_GetParentHandle(ep_handle, NULL, &ep_folder_handle); ret = CAEN_FELib_SetValue(ep_folder_handle, "/par/activeendpoint", "raw"); ret = CAEN_FELib_SetReadDataFormat(ep_handle, " [ \ { \"name\": \"DATA\", \"type\": \"U8\", \"dim\": 1 }, \ { \"name\": \"SIZE\", \"type\": \"SIZE_T\" }, \ { \"name\": \"N_EVENTS\", \"type\": \"U32\" }, \ ]" ); uint8_t* data = new uint8_t[200000]; size_t size; /// number of byte of the data uint32_t n_events; printf("Starting ACQ\n"); ret = CAEN_FELib_SendCommand(dev_handle, "/cmd/armacquisition"); ret = CAEN_FELib_SendCommand(dev_handle, "/cmd/swstartacquisition"); int count = 0; for( int i = 0; i < 2; i++){ usleep(10000); ret = CAEN_FELib_ReadData(ep_handle, 100, data, &size, &n_events ); count ++; if( ret == CAEN_FELib_Success ) { printf("================= %u, %ld, %d \n", n_events, size, count); uint64_t haha ; unsigned short dataType; int word = 0; for( int i =0 ; i < std::min((int)size / 8, 100) ; i++){ ///the data is array of 1 byte. /// by get the point of the data[8*i] /// cast it into uint64_t pointer, that will get 8 bytes all togteher /// get this point value, and bit swap it. haha = __builtin_bswap64(*(uint64_t *)&(data[8*i])); printf("%7d | 0x%016lX \n", i, haha); if ( word == 0 ){ /// aggregation header, or start header, or end header dataType = ( haha >> 55 ) & 0xFF ; if ( dataType == 0x30 ){ /// start Run data } if ( dataType == 0x32 ){ /// stop Run data } if ( (dataType >> 4) == 0x2 ){ /// data aggregation } } if ( word == 1 ){ unsigned short channel = ((haha >> 56) & 0x7F); unsigned short SE = ((haha >> 55) & 0x1); uint64_t timestamp = (haha & 0xFFFFFFFFFFFF); printf("ch %u, SE %u, %llu \n", channel, SE, timestamp); } if ( word == 2 ){ unsigned short W = ((haha >> 62) & 0x1); unsigned short fl = (( haha >> 50) & 0x1FFF); unsigned short fh = (( haha >> 41) & 0xFF); unsigned short energy = (haha & 0xFFFF); unsigned short fTime = ((haha >> 15) & 7FF); printf("energy %u, fTiem %u, fl %u, fh %u, W %u\n", energy, fTime, fl, fh, W); }*/ word++; } } } printf("Stop ACQ\n"); ret = CAEN_FELib_SendCommand(dev_handle, "/cmd/disarmacquisition"); } /** {//------------------------ DPPPHA uint64_t ep_handle; ret = CAEN_FELib_GetHandle(dev_handle, "/endpoint/dpppha", &ep_handle); //---------- configure endpoint uint64_t ep_folder_handle; ret = CAEN_FELib_GetParentHandle(ep_handle, NULL, &ep_folder_handle); ret = CAEN_FELib_SetValue(ep_folder_handle, "/par/activeendpoint", "dpppha"); ret = CAEN_FELib_SetReadDataFormat(ep_handle, " [ \ { \"name\" : \"CHANNEL\", \"type\" : \"U8\" }, \ { \"name\" : \"TIMESTAMP\", \"type\" : \"U64\" }, \ { \"name\" : \"FINE_TIMESTAMP\", \"type\" : \"U16\" }, \ { \"name\" : \"ENERGY\", \"type\" : \"U16\" }, \ { \"name\" : \"ANALOG_PROBE_1\", \"type\" : \"I32\", \"dim\" : 1 }, \ { \"name\" : \"ANALOG_PROBE_2\", \"type\" : \"I32\", \"dim\" : 1 }, \ { \"name\" : \"DIGITAL_PROBE_1\", \"type\" : \"U8\", \"dim\" : 1 }, \ { \"name\" : \"DIGITAL_PROBE_2\", \"type\" : \"U8\", \"dim\" : 1 }, \ { \"name\" : \"DIGITAL_PROBE_3\", \"type\" : \"U8\", \"dim\" : 1 }, \ { \"name\" : \"DIGITAL_PROBE_4\", \"type\" : \"U8\", \"dim\" : 1 }, \ { \"name\" : \"ANALOG_PROBE_1_TYPE\", \"type\" : \"U8\" }, \ { \"name\" : \"ANALOG_PROBE_2_TYPE\", \"type\" : \"U8\" }, \ { \"name\" : \"DIGITAL_PROBE_1_TYPE\", \"type\" : \"U8\" }, \ { \"name\" : \"DIGITAL_PROBE_2_TYPE\", \"type\" : \"U8\" }, \ { \"name\" : \"DIGITAL_PROBE_3_TYPE\", \"type\" : \"U8\" }, \ { \"name\" : \"DIGITAL_PROBE_4_TYPE\", \"type\" : \"U8\" }, \ { \"name\" : \"WAVEFORM_SIZE\", \"type\" : \"SIZE_T\" }, \ { \"name\" : \"FLAGS_LOW_PRIORITY\", \"type\" : \"U16\"}, \ { \"name\" : \"FLAGS_HIGH_PRIORITY\", \"type\" : \"U16\" }, \ { \"name\" : \"EVENT_SIZE\", \"type\" : \"SIZE_T\" } \ ] \ " ); uint8_t channel; uint64_t timestamp; uint16_t fine_timestamp; uint16_t energy; int32_t* analog_probes[2]; uint8_t* digital_probes[4]; analog_probes[0] = new int32_t[512]; analog_probes[1] = new int32_t[512]; digital_probes[0] = new uint8_t[512]; digital_probes[1] = new uint8_t[512]; digital_probes[2] = new uint8_t[512]; digital_probes[3] = new uint8_t[512]; uint8_t analog_probes_type[2]; uint8_t digital_probes_type[4]; size_t n_samples; uint16_t flags_low_priority; uint16_t flags_high_priority; size_t event_size; //#################################### Read data loop printf("Starting ACQ\n"); ret = CAEN_FELib_SendCommand(dev_handle, "/cmd/armacquisition"); ret = CAEN_FELib_SendCommand(dev_handle, "/cmd/swstartacquisition"); int count = 0; for( int i = 0; i < 10; i++){ usleep(10000); ret = CAEN_FELib_ReadData(ep_handle, 100, &channel, ×tamp, &fine_timestamp, &energy, analog_probes[0], analog_probes[1], digital_probes[0], digital_probes[1], digital_probes[2], digital_probes[3], &analog_probes_type[0], &analog_probes_type[1], &digital_probes_type[0], &digital_probes_type[1], &digital_probes_type[2], &digital_probes_type[3], &n_samples, &flags_low_priority, &flags_high_priority, &event_size ); count ++; if( ret == CAEN_FELib_Success ) { printf("================= %ld, %d \n", event_size, count); printf("ch : %u, energy : %u, time : %lu, fTime : %u \n", channel, energy, timestamp, fine_timestamp); printf("nSample: %ld, Flag low: %u, Flag high : %u\n", n_samples, flags_low_priority, flags_high_priority); printf("Ana prob type: %u, %u, Digi : %u %u %u %u\n", analog_probes_type[0], analog_probes_type[1], digital_probes_type[0], digital_probes_type[1], digital_probes_type[2], digital_probes_type[3] ); for( int i = 0; i < n_samples; i++){ if( i % 100 == 0 ) printf("%3d | %d, %d, %u, %u, %u, %u \n", i, analog_probes[0][i], analog_probes[1][i], digital_probes[0][i], digital_probes[1][i], digital_probes[2][i], digital_probes[3][i]); } } } printf("Stop ACQ\n"); ret = CAEN_FELib_SendCommand(dev_handle, "/cmd/disarmacquisition"); }/**/ //#################################### Close digitizer ret = CAEN_FELib_Close(dev_handle); }