Skip to content
This repository has been archived by the owner. It is now read-only.

Commit

Permalink
Changed bit flipping setting to fixed setting with bolean value for
Browse files Browse the repository at this point in the history
frequency generator activation
  • Loading branch information
MPIBR-kretschmerf committed Dec 19, 2016
1 parent 470a092 commit bc07af8
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 14 deletions.
66 changes: 56 additions & 10 deletions NIDAQmxInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,12 @@ void NIDAQmxInterface::DAQmxSetDefaultEngine()
daq->di_bit_prev = DAQ_PORT_NULL;
daq->do_bit_wrt = DAQ_PORT_NULL;
daq->do_bit_qry = DAQ_PORT_NULL;
daq->flag_scanner = DAQ_PORT_NULL;

/* event counters uInt32 */
daq->di_cntr_lick = 0;
daq->di_cntr_frame = 0;
daq->di_cntr_imaq = 0;
daq->di_cntr_cameraTrigger = 0;

return;
}
Expand Down Expand Up @@ -214,6 +214,45 @@ void NIDAQmxInterface::DAQmxTriggerDO(uInt8 qry_port_bit, bool arm_timer)
return;
}

void NIDAQmxInterface::DAQmxSetDO(uInt8 qry_port_bit, bool arm_timer, bool isSet)
{
int32 written = 0;
bool32 done = TRUE;

/* flip query bit to switch on qry bit */
if (daq->do_port != 0)
{
if(isSet){
daq->do_bit_wrt |= 1 << qry_port_bit;
}else{
daq->do_bit_wrt &= ~(1 << qry_port_bit);
}
DAQmxErrChk(DAQmxWriteDigitalU8(daq->do_port, 1, 1, 10.0, DAQmx_Val_GroupByChannel, &daq->do_bit_wrt, &written, NULL));
}

/* check for error */
if (written == 0)
{
fprintf(stderr, "Error::NIDAQmxInterface/DAQmxTriggerDO:\n\tfailed to write to DO port!\n");
exit(EXIT_FAILURE);
}

/* arm time out if required */
if ((daq->do_clk != 0) & (arm_timer == TRUE))
{

DAQmxErrChk(DAQmxIsTaskDone(daq->do_clk, &done));
daq->do_bit_qry = (done) ? qry_port_bit : (daq->do_bit_qry | qry_port_bit);
DAQmxErrChk(DAQmxStopTask(daq->do_clk));
DAQmxErrChk(DAQmxStartTask(daq->do_clk));
}
/* log trigger */
QString timeString = QTime::currentTime().toString("hh:mm:ss.zzz");
emit(writeToLogFile("TRIGGER", qry_port_bit, (qry_port_bit & daq->do_bit_wrt) == qry_port_bit, timeString));

return;
}

/* Detect Input Callback */
int32 CVICALLBACK NIDAQmxInterface::FcnCbckDetectDI(TaskHandle taskHandle, int32 signalID)
{
Expand All @@ -225,28 +264,27 @@ int32 CVICALLBACK NIDAQmxInterface::FcnCbckDetectDI(TaskHandle taskHandle, int32

if (read)
{

/* SHUTTER ON condition, SHUTTER line changes from 0 to 1 */
if (((daq->di_bit_prev & DAQ_PORT_DI_SHUTTER) == DAQ_PORT_NULL) &
((daq->di_bit_now & DAQ_PORT_DI_SHUTTER) == DAQ_PORT_DI_SHUTTER) &
(daq->flag_scanner == DAQ_PORT_NULL))
((daq->di_bit_now & DAQ_PORT_DI_SHUTTER) == DAQ_PORT_DI_SHUTTER))
{
daq->flag_scanner = DAQ_PORT_TRUE;
daq->di_cntr_imaq++;
daq->di_cntr_frame = 0;

/* switch OFF box internal resonance generator */
DAQmxTriggerDO(DAQ_PORT_DO_FREQGEN, FALSE);
//DAQmxTriggerDO(DAQ_PORT_DO_FREQGEN, FALSE);
DAQmxSetDO(DAQ_PORT_DO_FREQGEN, FALSE, FALSE);

}

/* SHUTTER OFF condition, SHUTTER line changes from 1 to 0 */
if (((daq->di_bit_prev & DAQ_PORT_DI_SHUTTER) == DAQ_PORT_DI_SHUTTER) &
((daq->di_bit_now & DAQ_PORT_DI_SHUTTER) == DAQ_PORT_NULL) &
(daq->flag_scanner == DAQ_PORT_TRUE))
((daq->di_bit_now & DAQ_PORT_DI_SHUTTER) == DAQ_PORT_NULL))
{
daq->flag_scanner = DAQ_PORT_NULL;

/* switch ON box internal resonance generator */
DAQmxTriggerDO(DAQ_PORT_DO_FREQGEN, FALSE);
//DAQmxTriggerDO(DAQ_PORT_DO_FREQGEN, FALSE);
DAQmxSetDO(DAQ_PORT_DO_FREQGEN, FALSE, TRUE);
}

/* FRAME condition, line 2 changes from 1 to 0 */
Expand All @@ -272,6 +310,14 @@ int32 CVICALLBACK NIDAQmxInterface::FcnCbckDetectDI(TaskHandle taskHandle, int32

}

/* CAMERATRIGGER condition, line 7 changes from 1 to 0 */
if (((daq->di_bit_prev & DAQ_PORT_DI_CAMERATRIGGER) == DAQ_PORT_DI_CAMERATRIGGER) & ((daq->di_bit_now & DAQ_PORT_DI_CAMERATRIGGER) == DAQ_PORT_NULL))
{
daq->di_cntr_cameraTrigger++;
QString timeString = QTime::currentTime().toString("hh:mm:ss.zzz");
emit(writeToLogFile("CAMERATRIGGER", DAQ_PORT_DI_CAMERATRIGGER, daq->di_cntr_cameraTrigger, timeString));
}

/* update bit history */
daq->di_bit_prev = daq->di_bit_now;
}
Expand Down
13 changes: 9 additions & 4 deletions NIDAQmxInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ class NIDAQmxInterface: public QObject
uInt8 di_bit_prev;
uInt8 do_bit_wrt;
uInt8 do_bit_qry;
uInt8 flag_scanner;
uInt32 di_cntr_lick;
uInt32 di_cntr_frame;
uInt32 di_cntr_cameraTrigger;
uInt32 di_cntr_imaq;
} DAQmxEngine;

Expand All @@ -55,9 +55,13 @@ class NIDAQmxInterface: public QObject
static const int DAQ_PORT_DI_SHUTTER = 0x01;
static const int DAQ_PORT_DI_BACKLIGHT = 0x02;
static const int DAQ_PORT_DI_FRAME = 0x04;
static const int DAQ_PORT_DI_AIR = 0x08;
static const int DAQ_PORT_DI_WATER = 0x10;
static const int DAQ_PORT_DI_SOUND = 0x20;

static const int DAQ_PORT_DI_CAMERATRIGGER = 0x8;

// static const int DAQ_PORT_DI_AIR = 0x08;
// static const int DAQ_PORT_DI_WATER = 0x10;
// static const int DAQ_PORT_DI_SOUND = 0x20;

static const int DAQ_PORT_DI_LICK = 0x40;
static const int DAQ_PORT_DI_SCANNER = 0x80;

Expand All @@ -84,6 +88,7 @@ class NIDAQmxInterface: public QObject
void DAQmxStartCustomTask(TaskHandle);
void DAQmxStopCustomTask(TaskHandle);
void DAQmxTriggerDO(uInt8, bool);
void DAQmxSetDO(uInt8, bool, bool);
void DAQmxWriteDO(uInt8);
DAQmxEngine* daq; /*MAKE PRIVATE*/

Expand Down

0 comments on commit bc07af8

Please sign in to comment.