Multifunction DAQ

cancel
Showing results for 
Search instead for 
Did you mean: 

Getting the contents of the text box list from NIDAQmx_NewPhysChanAICtrl(...) programatically

For some parameters such as for available gains, you can attempt to set the parameter when you attempt to create a channel such as by calling DAQmxCreateAIVoltageChan(...) and then check to see what the value of the parameter parameter was actually set. Unfortunately, if you try to set a non-existent channel, you get an error returned and the executable or, in my case, the dll crashes. At least, it does so in the shipping examples that I've tried and in my own dlls.

If your program uses a graphic interface and if it is intended for interactive use only, you can use NIDAQmx_NewPhysChanAICtrl(...) followed by setting filter properties using SetPhysChanCtrlAttrib(...) to limit the list displayed in the pull-down list in the special text box that the channel control uses to get the list of available channels. Unfortunately, I haven't found a way to programatically get the list or the number of items in the list. In my case, I mostly want my dll to return an error and perhaps display a message without crashing. Fortunately, getting a list of available devices ot checking to see if a particular device is real and/or active is simple but I haven't found a way to do the same thing for available channels.
0 Kudos
Message 1 of 6
(4,239 Views)
Hello Duncan

Instead of checking at the channel level, you can check at the task level using property functions like the ones listed below. This is assuming that you know which tasks your channels are in. You can find this information in the DAQmx C reference manual by going to Start->All Programs->National Instruments->NI-DAQ.

Get/Set/Reset Task_NumChans
int32 __CFUNC DAQmxGetTaskNumChans(TaskHandle taskHandle, uInt32 *data);
Purpose
DAQmxGetTaskNumChans indicates the number of virtual channels in the task..

Get/Set/Reset Task_Channels
int32 __CFUNC DAQmxGetTaskChannels(TaskHandle taskHandle, char *data, uInt32 bufferSize);
Purpose
DAQmxGetTaskChannels indicates the names of all virtual channels in the task.

Hope it helps...
0 Kudos
Message 2 of 6
(4,233 Views)
Thanks sergesl,
I think I was confused by the shipping example behavior and similar behavior in my dll. I changed the error handling so that a channel error could be corrected in a text box and it seems to work OK.

This part of the code tries to use the channel from the calling program:
error = 1;
while (error){
error = DAQmxCreateAIVoltageChan(taskHandle,ADHdwr.AIchans,"",DAQmx_Val_Cfg_Default,min,max,DAQmx_Val_Volts,NULL);
if(error){
DAQmxGetExtendedErrorInfo(errBuff,2048);
MessagePopup("DAQmx Error",errBuff);
PanelChan = BuildChanPANEL();
NIDAQmx_NewPhysChanAICtrl(PanelChan,PANEL_TACHOCHAN,1);
NIDAQmx_SetPhysChanCtrlAttribute (PanelChan,PANEL_TACHOCHAN, NIDAQmx_IOCtrl_ChanType, NIDAQmx_IOCtrl_Val_PhysChanIOTypeAI);
NIDAQmx_SetPhysChanCtrlAttribute (PanelChan,PANEL_TACHOCHAN, NIDAQmx_IOCtrl_Limit_Device, ADHdwr.AIchans);
NIDAQmx_SetPhysChanCtrlAttribute (PanelChan,PANEL_TACHOCHAN, NIDAQmx_IOCtrl_Limit_To_Device,1);
NIDAQmx_GetPhysChanCtrlAttribute (PanelChan,PANEL_TACHOCHAN, NIDAQmx_IOCtrl_PhysChanExternal, NULL);
SetCtrlVal (PanelChan,PANEL_TACHOCHAN, ADHdwr.AIchans);
DisplayPanel(PanelChan);
ui = RunUserInterface();
}
}
PanelChan is a panel that has the string control for NIDAQmx_NewPhysChanAICtrl and a QUIT button. The Quit button has the following callback:
int CVICALLBACK CloseTachoInterface (int panel, int control, int event,
void *callbackData, int eventData1, int eventData2)
{
switch (event)
{
case EVENT_COMMIT:
GetCtrlVal (PanelChan,PANEL_TACHOCHAN, ADHdwr.AIchans);
QuitUserInterface (ui);
DiscardPanel(PanelChan);
PanelChan = 0;
break;
}
return 0;
}

This works for now but I'll probably change it later.

Duncan
0 Kudos
Message 3 of 6
(4,222 Views)
Pleased to be of any help Duncan...
0 Kudos
Message 4 of 6
(4,215 Views)
hi, I have problem... I need to limit devices in devices in the text box list to "Dev1"....


NIDAQmx_NewPhysChanAICtrl (panelHandle, PANEL_AIPHYSICAL, 1);   
NIDAQmx_SetPhysChanCtrlAttribute (panelHandle, PANEL_AIPHYSICAL, NIDAQmx_IOCtrl_Limit_Device, "Dev1");
//NIDAQmx_SetPhysChanCtrlAttribute (panelHandle, PANEL_AIPHYSICAL, NIDAQmx_IOCtrl_Limit_To_Device, 1)


but, function SetPhysChanCtrlAttribute returns me fatal error:

 FATAL RUN-TIME ERROR:   "BP1.c", line 53, col 70, thread id 0x00000D80:   Missing argument to variable argument function.


thank you for your request



0 Kudos
Message 5 of 6
(3,795 Views)
This question has been addressed on this forum.
JaceD
Signal Sources Product Support Engineer
National Instruments
0 Kudos
Message 6 of 6
(3,774 Views)