Digital I/O

cancel
Showing results for 
Search instead for 
Did you mean: 

DAQmx synchronize digital input and digital output task

Hello.

 

I need to synchronize digital input and digital output on NI6229 or NI6535 device, for emulating i2c-like protocol receiver.

Looks like only way - use PXI_Trig or PFI lines for synchronize tasks start, but if I don't understand how to do it without hardware modifying.

 

bool CheckAck(const char *devDataLine, const char *devClockLine, bool *ackReceived)
{
//Data, Clock - low
//Clock high
//Data high
int32 error;
TaskHandle clkHandle = 0;
TaskHandle dataHandle = 0;
bool result = true;
int32 samples_written;
int32 samples_readed;
int32 bytes_per_sample;
uInt8 clock_out[] = {
0,
0,
1,
1,
0,
0,
};
uInt8 data_in[sizeof(clock_out)];

samples_written = 0;
samples_readed = 0;

DAQmxErrChk(DAQmxCreateTask("", &clkHandle));
DAQmxErrChk(DAQmxCreateTask("", &dataHandle));

DAQmxErrChk(DAQmxSetDOLogicFamily(clkHandle, "", logic_family));
DAQmxErrChk(DAQmxSetDILogicFamily(dataHandle, "", logic_family));

DAQmxErrChk(DAQmxCreateDOChan(clkHandle, devClockLine, "", DAQmx_Val_ChanPerLine));
DAQmxErrChk(DAQmxCreateDIChan(dataHandle, devDataLine, "", DAQmx_Val_ChanPerLine));

DAQmxErrChk(DAQmxCfgSampClkTiming(clkHandle, "", (double)i2c_clk, DAQmx_Val_Rising, DAQmx_Val_FiniteSamps, sizeof(clock_out)));
DAQmxErrChk(DAQmxCfgSampClkTiming(dataHandle, "", (double)i2c_clk, DAQmx_Val_Rising, DAQmx_Val_FiniteSamps, sizeof(clock_out)));

DAQmxErrChk(DAQmxWriteDigitalLines(clkHandle, sizeof(clock_out), 0, 10.0, DAQmx_Val_ChanForAllLines, clock_out, &samples_written, NULL));
DAQmxErrChk(DAQmxReadDigitalLines(dataHandle, sizeof(data_in), 10.0, DAQmx_Val_ChanForAllLines, data_in, sizeof(data_in), &samples_readed, &bytes_per_sample, NULL));

DAQmxCfgDigEdgeStartTrig(clkHandle, "PXI_Trig0", DAQmx_Val_Rising);
DAQmxCfgDigEdgeStartTrig(dataHandle, "PXI_Trig0", DAQmx_Val_Rising);

DAQmxErrChk(DAQmxStartTask(clkHandle));
DAQmxErrChk(DAQmxStartTask(dataHandle));
//how to software trigger PXI_Trig?
DAQmxErrChk(DAQmxWaitUntilTaskDone(clkHandle, 10.0));

error:

if (error_log)
{
if (DAQmxFailed(error))
{
char descr[1024];
DAQmxGetErrorString(error, descr, sizeof(descr));
printf("%s\n", descr);
}
}

if (clkHandle != 0)
{
DAQmxStopTask(clkHandle);
DAQmxClearTask(clkHandle);
}

if (dataHandle != 0)
{
DAQmxStopTask(dataHandle);
DAQmxClearTask(dataHandle);
}

return result;
}

0 Kudos
Message 1 of 1
(174 Views)