Digital I/O

cancel
Showing results for 
Search instead for 
Did you mean: 

How to use control PCI-6518 with VC

Dear master

Hello?

This is south korea
I'm student.
I bought PCI-6518 (DIO) It's my 1st time..
I wamma control it in VC++

I saw example code... but I can't understand it.


for example...
CH07 is sensor input
CH37 is step motor cw
CH36 is step motor ccw

When I click the button then check CH07
If CH07 is Low then make pulse in CH37
else CH07 is High then make pulse in CH36


How to coding it?

Please check my code...



This is my code...

#include
#include "NIDAQmx.h"

#define DAQmxErrChk(functionCall) { if( DAQmxFailed(error=(functionCall)) ) { goto Error; } }

#define CH_00 "Dev1/port0/line0"

#define CH_36 "Dev1/port3/line6"
#define CH_37 "Dev1/port3/line7"


int main(int argc, char *argv[])
{
int32 error=0;
TaskHandle taskHandle=0;
int8 data=0;
int8 High=1, Low=0;
char errBuff[2048]={'\0'};
int32 i;
int32 read,bytesPerSamp;


/*********************************************/
/*/ DAQmx Configure Code
/*********************************************/
DAQmxErrChk (DAQmxCreateTask("",&taskHandle));
DAQmxErrChk (DAQmxCreateDIChan(taskHandle,CH_00,"",DAQmx_Val_ChanForAllLines));
DAQmxErrChk (DAQmxCreateDOChan(taskHandle,CH_36,"",DAQmx_Val_ChanForAllLines));
DAQmxErrChk (DAQmxCreateDOChan(taskHandle,CH_37,"",DAQmx_Val_ChanForAllLines));

/*********************************************/
/*/ DAQmx Start Code
/*********************************************/
DAQmxErrChk (DAQmxStartTask(taskHandle));

/*********************************************/
/*/ DAQmx Read Code
/*********************************************/
DAQmxErrChk (DAQmxReadDigitalLines(taskHandle,1,10.0,DAQmx_Val_GroupByChannel,data,100,&read,&bytesPerSamp,NULL));
if(data == Low)
{
while(data = Low)
{
DAQmxErrChk (DAQmxWriteDigitalLines(taskHandle,1,1,10.0,DAQmx_Val_GroupByChannel,High,NULL,NULL));
sleep(1000);
DAQmxErrChk (DAQmxWriteDigitalLines(taskHandle,1,1,10.0,DAQmx_Val_GroupByChannel,Low,NULL,NULL));
sleep(1000);

DAQmxErrChk (DAQmxReadDigitalLines(taskHandle,1,10.0,DAQmx_Val_GroupByChannel,data,100,&read,&bytesPerSamp,NULL));
printf("Data acquired, channel %d: 0x%X\n",i,data);
}
}
else
{
while(data = High)
{
DAQmxErrChk (DAQmxWriteDigitalLines(taskHandle,1,1,10.0,DAQmx_Val_GroupByChannel,High,NULL,NULL));
sleep(1000);
DAQmxErrChk (DAQmxWriteDigitalLines(taskHandle,1,1,10.0,DAQmx_Val_GroupByChannel,Low,NULL,NULL));
sleep(1000);

DAQmxErrChk (DAQmxReadDigitalLines(taskHandle,1,10.0,DAQmx_Val_GroupByChannel,data,100,&read,&bytesPerSamp,NULL));
printf("Data acquired, channel %d: 0x%X\n",i,data);
}
}

Error:
if( DAQmxFailed(error) )
DAQmxGetExtendedErrorInfo(errBuff,2048);
if( taskHandle!=0 ) {
/*********************************************/
/*/ DAQmx Stop Code
/*********************************************/
DAQmxStopTask(taskHandle);
DAQmxClearTask(taskHandle);
}
if( DAQmxFailed(error) )
printf("DAQmx Error: %s\n",errBuff);
printf("End of program, press Enter key to quit\n");
getchar();
return 0;
}


Thank you~!
0 Kudos
Message 1 of 4
(3,616 Views)

Hi newspacekor-

The easiest way I can think of to perform this task in two steps.  First, create one task, read values from port 0 and assign a write buffer based on the states of pertinent lines, and then stop and clear that task.  Then create a second task and write the write buffer out to port 3.

I have combined two CVI example programs to include this functionality.  I tested in CVI with success and then removed all references to CVI-specific material, so this should give you an ANSI C example as a good starting point.  Please let us know if you have any additional questions.

Good luck!

Thanks-

Message Edited by Tom W. on 07-01-2005 03:43 PM

Tom W
National Instruments
0 Kudos
Message 2 of 4
(3,603 Views)

Thank you.

When I check this code....

but this is not Windows.... when I start then run to DOS...

how can I use windows.?

 

0 Kudos
Message 3 of 4
(3,577 Views)
Hi newspacekor-
 
The example I suggested contains the necessary functions to setup the tasks and control or read to the lines.  This functionality will be the same when you build your application whether you plan to develop your own GUI or not.  Development for Windows GUI use is left to the user, but the NI-DAQmx functionality will work as long as you use the C functions as shown in the example I suggested and also the NI-DAQmx C Reference help at Start>>Programs>>National Instruments>>NI-DAQ.
 
Thanks-
Tom W
National Instruments
0 Kudos
Message 4 of 4
(3,551 Views)