Hello,
First, escuse me for my bad english.
I use a NI-PCI 6528 card to acquire signals.
Actually, I used a fonction wich scan the state of all ports when I want ; but my need change :
All ports are used by two.
The different port states change in the time at different moment and I want to have the evolution on a period.
For exemple for 8 ports :
- time 1 : all states : 0
- time 2 : port 1 and port 3 states : 1 --> I save port 2 et 4 states
- time 3 : all states : 0
- time 4 : all states : 0
- time 5 : port 5 state : 1 --> I save port 6 state
at time 6, I need to use the states of my ports during the last 5 time and to have a table like this :
Port 1 : 1
Port 2 : state save (0 or 1)
Port 3 : 1
Port 4 : state save (0 or 1)
Port 5 : 1
Port 6 : state save (0 or 1)
Port 7 : 0
Port 8 : 0
For the moment, I used a function which scan continously my card and store state in a table but here is a problem because I lose some state and the CPU is 100% used !
I think to use 2 function but i don't know how to implement them and which is the best :
- Use a thread which is waiting for the card transmit it the state when there is a state modification (event)
- Use a function which save a table from the card wich store the state on a period.
What to you advise me, how can I implement them, Do you some source code ?
I precise that I need to use ports for differents applications : control other PC, light del... then I think a function based on event (state change) is best : The thread transmit the state of ports to different functions according the port which changed.
Please help me, it's very urgent.
Best regards
Proko
here is the function code I used the scan the card :
I used it in a while function to scan continously.
#include
#include
#include
#include
#pragma comment(lib, "NIDAQmx")
using namespace std;
int main(int argc, char *argv[])
{
int32 read,bytesPerSamp;
uInt8 data[100];
TaskHandle mytaskHandle=0;
int sizeOfData=100,error;
char errBuff[2048]={'\0'};
int32 i;
DAQmxErrChk (DAQmxCreateTask("",&mytaskHandle));
DAQmxErrChk (DAQmxCreateDIChan(mytaskHandle,"Dev1/port0/line0:7","",DAQmx_Val_ChanForAllLines));
DAQmxErrChk (DAQmxStartTask(mytaskHandle));
DAQmxErrChk (DAQmxReadDigitalLines(mytaskHandle,1,10.0,DAQmx_Val_GroupByChannel,data,sizeOfData,&read,&bytesPerSamp,NULL));
DAQmxErrChk (DAQmxStopTask(mytaskHandle));
DAQmxErrChk (DAQmxClearTask(mytaskHandle));
Error:
if( DAQmxFailed(error) )
DAQmxGetExtendedErrorInfo(errBuff,2048);
if( mytaskHandle!=0 )
{
DAQmxStopTask(mytaskHandle);
DAQmxClearTask(mytaskHandle);
}
if( DAQmxFailed(error) )
printf("DAQmx Error: %s\n",errBuff);
else
for(i=0;i<8;++i)
printf("Données acquise, channel %d: 0x%X\n",i,data[i]);
system("PAUSE");
return 0;
}