binhui
2007-08-07 20:10:13 UTC
I am new in using LabWindows with DAQmx. ( I program a lot using Labwindows with GPIB.)
I read through examples in Labwindows 7.1. All of them have NIDAQmx_NewPhysChanDO* in main(). I just don't know how it works.
It is straight forward to create task, channel, start the task, do some work, stop the task, and clear the task. But this mysterious NewPhysChanDO* makes me unconfortable. There is no use later. Obviously we can use Dev1/line0 to directly access the line. Why we need it?
And I googled it, but nothing returns.
Please shine some light on it.
Here is the simple example from Labwindows 7.1 examples.
/********************************************************************** * CVI Example program:* WriteDigChan.c* * Example Category:* DO* * Description:* This example demonstrates how to write values to a digital* output channel.* * Instructions for Running:* 1. Select the digital lines on the DAQ device to be written.* 2. Select a value to write.* Note: The array is sized for 8 lines, if using a different* amount of lines, change the number of elements in the* array to equal the number of lines chosen.* * Steps:* 1. Create a task.* 2. Create a Digital Output channel. Use one channel for all* lines.* 3. Call the Start function to start the task.* 4. Write the digital Boolean array data. This write function* writes a single sample of digital data on demand, so no* timeout is necessary.* 5. Call the Clear Task function to clear the Task.* 6. Display an error if any.* * I/O Connections Overview:* Make sure your signal output terminals match the Lines I/O* Control. In this case wire the item to receive the signal to the* first eight digital lines on your DAQ Device.* *********************************************************************/
#include <cvirte.h>#include <userint.h>#include <NIDAQmx.h>#include <DAQmxIOctrl.h>#include "WriteDigChan.h"
#define DAQmxErrChk(functionCall) if( DAQmxFailed(error=(functionCall)) ) goto Error; else
static int panelHandle;
int main(int argc, char *argv[]){ if( InitCVIRTE(0,argv,0)==0 ) return -1; /* out of memory */ if( (panelHandle=LoadPanel(0,"WriteDigChan.uir",PANEL))<0 ) return -1; SetCtrlAttribute(panelHandle,PANEL_DECORATION_BLUE,ATTR_FRAME_COLOR,VAL_BLUE); NIDAQmx_NewPhysChanDOLineCtrl(panelHandle,PANEL_CHANNEL,1); //what hell is this for? DisplayPanel(panelHandle); RunUserInterface(); DiscardPanel(panelHandle); return 0;}
int CVICALLBACK PanelCallback(int panel, int event, void *callbackData, int eventData1, int eventData2){ if( event==EVENT_CLOSE ) QuitUserInterface(0); return 0;}
int CVICALLBACK WriteCallback(int panel, int control, int event, void *callbackData, int eventData1, int eventData2){ int error=0; TaskHandle taskHandle=0; char chan[256]; uInt8 data[8]; char errBuff[2048]={'\0'};
if( event==EVENT_COMMIT ) { GetCtrlVal(panel,PANEL_CHANNEL,chan); GetCtrlVal(panel,PANEL_BINARYSWITCH_0,&data[0]); GetCtrlVal(panel,PANEL_BINARYSWITCH_1,&data[1]); GetCtrlVal(panel,PANEL_BINARYSWITCH_2,&data[2]
I read through examples in Labwindows 7.1. All of them have NIDAQmx_NewPhysChanDO* in main(). I just don't know how it works.
It is straight forward to create task, channel, start the task, do some work, stop the task, and clear the task. But this mysterious NewPhysChanDO* makes me unconfortable. There is no use later. Obviously we can use Dev1/line0 to directly access the line. Why we need it?
And I googled it, but nothing returns.
Please shine some light on it.
Here is the simple example from Labwindows 7.1 examples.
/********************************************************************** * CVI Example program:* WriteDigChan.c* * Example Category:* DO* * Description:* This example demonstrates how to write values to a digital* output channel.* * Instructions for Running:* 1. Select the digital lines on the DAQ device to be written.* 2. Select a value to write.* Note: The array is sized for 8 lines, if using a different* amount of lines, change the number of elements in the* array to equal the number of lines chosen.* * Steps:* 1. Create a task.* 2. Create a Digital Output channel. Use one channel for all* lines.* 3. Call the Start function to start the task.* 4. Write the digital Boolean array data. This write function* writes a single sample of digital data on demand, so no* timeout is necessary.* 5. Call the Clear Task function to clear the Task.* 6. Display an error if any.* * I/O Connections Overview:* Make sure your signal output terminals match the Lines I/O* Control. In this case wire the item to receive the signal to the* first eight digital lines on your DAQ Device.* *********************************************************************/
#include <cvirte.h>#include <userint.h>#include <NIDAQmx.h>#include <DAQmxIOctrl.h>#include "WriteDigChan.h"
#define DAQmxErrChk(functionCall) if( DAQmxFailed(error=(functionCall)) ) goto Error; else
static int panelHandle;
int main(int argc, char *argv[]){ if( InitCVIRTE(0,argv,0)==0 ) return -1; /* out of memory */ if( (panelHandle=LoadPanel(0,"WriteDigChan.uir",PANEL))<0 ) return -1; SetCtrlAttribute(panelHandle,PANEL_DECORATION_BLUE,ATTR_FRAME_COLOR,VAL_BLUE); NIDAQmx_NewPhysChanDOLineCtrl(panelHandle,PANEL_CHANNEL,1); //what hell is this for? DisplayPanel(panelHandle); RunUserInterface(); DiscardPanel(panelHandle); return 0;}
int CVICALLBACK PanelCallback(int panel, int event, void *callbackData, int eventData1, int eventData2){ if( event==EVENT_CLOSE ) QuitUserInterface(0); return 0;}
int CVICALLBACK WriteCallback(int panel, int control, int event, void *callbackData, int eventData1, int eventData2){ int error=0; TaskHandle taskHandle=0; char chan[256]; uInt8 data[8]; char errBuff[2048]={'\0'};
if( event==EVENT_COMMIT ) { GetCtrlVal(panel,PANEL_CHANNEL,chan); GetCtrlVal(panel,PANEL_BINARYSWITCH_0,&data[0]); GetCtrlVal(panel,PANEL_BINARYSWITCH_1,&data[1]); GetCtrlVal(panel,PANEL_BINARYSWITCH_2,&data[2]