LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Detect hardware capabilities of a DAQmx device

Solved!
Go to solution

When dealing with data acquisition devices it is sometime useful to programmatically detect hardware capabilities of them. I presently need to deal with AO channels of several USB devices and would like to limit user ability to set the output value to the actual range of device channels (which can be for example 0-5V or 0-10V or -10-10V) in order to prevent getting errors. How can I do this?

 

I cannot use DAQmxGetChanAttribute since this function requires the channel to be added to a task but in that step you state min/max limits and DAQmxGetChanAttribute reflects those limits even if lower than max possible values.

I have been digging into NI System Configuration but could not find an appropriate function.

 

Suggestions are welcome!



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 1 of 5
(1,125 Views)

Hi Roberto,

I'm not sure I understand.

You want to set limits on the user interface that correspond to the channel capabilities ? Or you want to change the software limits of the channels ?

And you want to do either of those without defining a task ?

0 Kudos
Message 2 of 5
(1,105 Views)
Solution
Accepted by topic author RobertoBozzolo

Hi Roberto

 

This code snip is a part of mach larger program that i can not share.

Hope it will help you.

 

int SetupAnalogIn(int board_index)
{
int size , i , no_channels , *types = NULL ;
char *channels = NULL , str[128] ;
double rate , *ranges ;


size = DAQmxGetDeviceAttribute (DevInfo[board_index].DevName,DAQmx_Dev_AI_VoltageRngs, 0, 0);
ranges = (double *)malloc(size* sizeof(double)) ;
DAQmxGetDeviceAttribute (DevInfo[board_index].DevName,DAQmx_Dev_AI_VoltageRngs, ranges, size);

free(ranges) ;

size = DAQmxGetDeviceAttribute (DevInfo[board_index].DevName, DAQmx_Dev_AI_PhysicalChans, 0, 0);
if(size <= 0)
return 0 ;

channels = malloc(size) ;
if(channels == NULL)
{
MessageBox(HWND_DESKTOP,"Unable to allocate memory","NiPanels", MB_ICONERROR | MB_OK | MB_SYSTEMMODAL);
return 0 ;
}
DAQmxGetDeviceAttribute (DevInfo[board_index].DevName, DAQmx_Dev_AI_PhysicalChans, channels, size);

DevInfo[board_index].hWnd_AnlgIn = LoadPanel(0 , "NiPanels.uir" , ANLG_IN) ;
if(DevInfo[board_index].hWnd_AnlgIn <= 0)
return 0 ;

sprintf(str , "%s:%s Analog In",DevInfo[board_index].Type,DevInfo[board_index].DevName) ;
SetPanelAttribute(DevInfo[board_index].hWnd_AnlgIn ,ATTR_TITLE , str) ;
SetCtrlVal(DevInfo[board_index].hWnd_AnlgIn , ANLG_IN_DEV_NO , board_index) ;

//get all channels
for(i = 0 , no_channels = 0 ; i < size ; )
{
if(!CopyUntilComma(&channels[i] , str , 64))
break ;
no_channels++ ; i += strlen(str) + 1 ;

InsertTableRows(DevInfo[board_index].hWnd_AnlgIn ,ANLG_IN_TABLE , -1 , 1 , VAL_USE_MASTER_CELL_TYPE) ;
SetTableCellAttribute(DevInfo[board_index].hWnd_AnlgIn , ANLG_IN_TABLE , MakePoint(1,no_channels) , ATTR_CTRL_VAL , str) ;
}

InsertTableCellRangeRingItem (DevInfo[board_index].hWnd_AnlgIn, ANLG_IN_TABLE, MakeRect(1,2,no_channels,1) , -1, "RSE");
InsertTableCellRangeRingItem (DevInfo[board_index].hWnd_AnlgIn, ANLG_IN_TABLE, MakeRect(1,2,no_channels,1) , -1, "NRSE");
InsertTableCellRangeRingItem (DevInfo[board_index].hWnd_AnlgIn, ANLG_IN_TABLE, MakeRect(1,2,no_channels,1) , -1, "Diff");

//check for TC capable channels
size = DAQmxGetDeviceAttribute (DevInfo[board_index].DevName,DAQmx_Dev_AI_SupportedMeasTypes, NULL,0);
types = malloc(size * sizeof(int)) ;
if(types == NULL)
{
MessageBox(HWND_DESKTOP,"Unable to allocate memory","NiPanels", MB_ICONERROR | MB_OK | MB_SYSTEMMODAL);
return 0 ;
}
DAQmxGetDeviceAttribute (DevInfo[board_index].DevName,DAQmx_Dev_AI_SupportedMeasTypes, types,size);
for(i = 0 ; i < size ; i++)
{
if(types[i] == DAQmx_Val_Temp_TC)
{
InsertTableCellRangeRingItem (DevInfo[board_index].hWnd_AnlgIn, ANLG_IN_TABLE, MakeRect(1,2,no_channels,1) , -1, "Temp");
InsertListItem(DevInfo[board_index].hWnd_AnlgIn , ANLG_IN_ALL_CHAN_CFG , -1 , "Temp","Temp") ;
InsertTableCellRangeRingItem (DevInfo[board_index].hWnd_AnlgIn, ANLG_IN_TABLE, MakeRect(1,6,no_channels,1) , -1, "");
InsertTableCellRangeRingItem (DevInfo[board_index].hWnd_AnlgIn, ANLG_IN_TABLE, MakeRect(1,6,no_channels,1) , -1, "J");
InsertTableCellRangeRingItem (DevInfo[board_index].hWnd_AnlgIn, ANLG_IN_TABLE, MakeRect(1,6,no_channels,1) , -1, "K");
SetTableColumnAttribute(DevInfo[board_index].hWnd_AnlgIn, ANLG_IN_TABLE, 6 , ATTR_COLUMN_VISIBLE , 1) ;
SetTableCellRangeAttribute (DevInfo[board_index].hWnd_AnlgIn,ANLG_IN_TABLE, VAL_TABLE_COLUMN_RANGE(6), ATTR_CELL_DIMMED, 1);
break ;
}
}
free(types) ;
DAQmxGetDeviceAttribute (DevInfo[board_index].DevName,DAQmx_Dev_AI_MaxSingleChanRate, &rate,1);
SetCtrlAttribute(DevInfo[board_index].hWnd_AnlgIn, ANLG_IN_SAMP_RATE , ATTR_MAX_VALUE , rate) ;

DisplayPanel(DevInfo[board_index].hWnd_AnlgIn) ;

free(channels) ;

return 1 ;
}
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/

Message 3 of 5
(1,093 Views)

@gdargaud  ha scritto:

Hi Roberto,

I'm not sure I understand.

You want to set limits on the user interface that correspond to the channel capabilities ? Or you want to change the software limits of the channels ?

And you want to do either of those without defining a task ?


Yes, I want to st user limits the same as hardware capabilities, so that the system is not likely to get an error due to invalid values attempted.

 

AFAIK this cannot be done safely by defining a task, since you add a channel to it with a call to 

 

DAQmxCreateAOVoltageChan (taskHandle, "channel", "", -10.0, 10.0, DAQmx_Val_Volts, "");

 

in which you  must set min/max limits. Supposing you don't get an error in this function by setting incorrect values, the limits you set here are reflected in DAQmxGetChanAttribute (..., ..., DAQmx_AO_Max, ...), so you don't get board capabilities but your settings instead.



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 4 of 5
(1,083 Views)

@GabelDaniel  ha scritto:

...

 

size = DAQmxGetDeviceAttribute (DevName, DAQmx_Dev_AI_VoltageRngs, 0, 0);

 

 

...

 

return 1 ;

}


That was the solution (in my case with DAQmx_Dev_AO_VoltageRngs attribute) ! It didn't occurred to me to query for device attributes!

Thanks Daniel



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 5 of 5
(1,077 Views)