From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

Digital I/O

cancel
Showing results for 
Search instead for 
Did you mean: 

NI-PCI 6528 : Port change save

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;
}
0 Kudos
Message 1 of 4
(3,459 Views)
Hello,

A program based on event detection is probably the best solution. To help you to perform that. You can use the following functions.

DAQmxRegisterEveryNSamplesEvent
DAQmxRegisterDoneEvent
DAQmxRegisterSignalEvent

They are located in the NI-DAQmx Library >> Task Configuration/Control >> Event

Hope that will help you.

Moreover you can have have a look at the following link to have more details about the topic you are concerned with.
The first one is how to use NI-DAQmx in LabWindows/CVI
http://zone.ni.com/devzone/conceptd.nsf/webmain/2df76d8073aa2a8c86256d2c005586d2
the second one deals with the use of multithreading
http://zone.ni.com/devzone/conceptd.nsf/webmain/2df76d8073aa2a8c86256d2c005586d2

Good luck,
Best regards,

Alexandre D
National Instruments France
0 Kudos
Message 2 of 4
(3,421 Views)
Hello,

Thanks for your advise.

But I never use event. DO you have some code ?
I use port 1, 3, 5, 7, 9, 11, 13 and 15 for the event : when I have an up signal on one of this port, I store the value of the corresponding port (port 2 for port 1, port 4 for port 3...).
I use the other port (17,18,19...) to manage another system (I only read the value of the port when I want with my actual function).

best regards,

Proko
0 Kudos
Message 3 of 4
(3,349 Views)
Hello,

You will find an example under CVI at the following path:
Help >> Find examples... >> Hardware Input and Output >> DAQmx >> Digital Measurements >> ReadDigChan-ChangeDetectionEvent.

Best regards

Alexandre D
NIF
0 Kudos
Message 4 of 4
(3,316 Views)