LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

What is NIDAQmx_NewPhysChanDOLineCtrl( ) for?

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]);
  GetCtrlVal(panel,PANEL_BINARYSWITCH_3,&data[3]);
  GetCtrlVal(panel,PANEL_BINARYSWITCH_4,&data[4]);
  GetCtrlVal(panel,PANEL_BINARYSWITCH_5,&data[5]);
  GetCtrlVal(panel,PANEL_BINARYSWITCH_6,&data[6]);
  GetCtrlVal(panel,PANEL_BINARYSWITCH_7,&data[7]);
  /*********************************************/
  // DAQmx Configure Code
  /*********************************************/
  DAQmxErrChk (DAQmxCreateTask("",&taskHandle));
  DAQmxErrChk (DAQmxCreateDOChan(taskHandle,chan,"",DAQmx_Val_ChanForAllLines));
  /*********************************************/
  // DAQmx Start Code
  /*********************************************/
  DAQmxErrChk (DAQmxStartTask(taskHandle));
  /*********************************************/
  // DAQmx Write Code
  /*********************************************/
  DAQmxErrChk (DAQmxWriteDigitalLines(taskHandle,1,1,10.0,DAQmx_Val_GroupByChannel,data,NULL,NULL));
 }
Error:
 if( DAQmxFailed(error) )
  DAQmxGetExtendedErrorInfo(errBuff,2048);
 if( taskHandle!=0 ) {
  /*********************************************/
  // DAQmx Stop Code
  /*********************************************/
  DAQmxStopTask(taskHandle);
  DAQmxClearTask(taskHandle);
 }
 if( DAQmxFailed(error) )
  MessagePopup("DAQmx Error",errBuff);
 return 0;
}

Message Edited by binhui on 08-07-2007 02:47 PM

0 Kudos
Message 1 of 5
(4,121 Views)
Hi,
    "NIDAQmx_NewPhysChanDO" is part of daqmxioctrl.fp instrument library.
    This function creates a new "DAQmx IO" control for selecting physical digital output channels,
    so it create a Ring control(with callback) before existing String control.
    This ring can be used for dynamic selecting DigitalOut Line, depend on your HW.
    Selected line adress(text format) is set to assigned string control.

Message Edited by ovrabek/CZ on 08-08-2007 08:37 AM

0 Kudos
Message 2 of 5
(4,108 Views)
I haven't get the idea about it.
 
But as far as dynamically selecting DigitalOut Line,
GetCtrlVal(panel,PANEL_CHANNEL,chan);
DAQmxErrChk (DAQmxCreateDOChan(taskHandle,chan,"",DAQmx_Val_ChanForAllLines));
will do the job, if I change the selected line adress(text format) in the string control:PANEL_CHANNEL.
 
I have tested it with or without "NIDAQmx_NewPhysChanDO" in this example. The program behaves same at least at Labwindows 7.1.
 
Is there any function which requires calling "NIDAQmx_NewPhysChanDO" first?
 
The thing is that I cannot see any relation between this "NIDAQmx_NewPhysChanDO" and other part of the program.  It looks a total junk code.
 
And for this simple program, it does have no effect. I am using pci 6509.
 
Btw, how to acess this ring control except changing the selected line adress(text format) in the string control, which obviously doesn't need this "NIDAQmx_NewPhysChanDO"?

Message Edited by binhui on 08-08-2007 09:01 AM

0 Kudos
Message 3 of 5
(4,098 Views)
I use word "dynamically selecting", but i mean user friendly select of digital output at runtime.

NIDAQmx_NewPhysChanDO can by used or not as you want.
It is independent on other part of program.


"NIDAQmx_NewPhysChanDO" only add new way to select "Digital Line" by user from dialog(created after click on the ring).
   if you d`not need change addres, or you set adress directly to string control,You not need use this function.

I attach some image from WriteDigChan example:
    WithoutDAQmxCreateDOChan.JPG   where DAQmxCreateDOChan is disabled(comment)
    WithDAQmxCreateDOChan.JPG        where
DAQmxCreateDOChan is used. - ring control is visible on panel(at runtime)

when click on the Ring control
(at runtime):
    RingSelection.JPG                                dialog box for selection DO (list of available DO, depend upon instaled NIDAQmx cards)
                                                                   after select "DigitalOutput line", adress is copy to string control.


I hope this help to clarify this function.

P.S. Im sorry about my bad English.

Message 4 of 5
(4,088 Views)
Thanks for your explanation.
It makes everything clear.
 
0 Kudos
Message 5 of 5
(4,079 Views)