|
ASX Version4.37.03
|
This is an example of how to use the ASX multiplexer control.
/* $Header: /home/eliot/asi/repo/cvsrepo/Repository/apps/asx/examples/mux/main.c,v 1.5 2004/08/11 14:13:36 as-age Exp $ */ #include "stdio.h" #include "stdlib.h" #include "asx.h" #include "asxstring.h" int CheckError(ASX_HANDLE hObj, int nLine); void PrintControlName(ASX_HANDLE hControl); ASX_HANDLE hSystem=0; int main(int argc, char* argv[]) { char *pszName; ASX_HANDLE hAdapter; ASX_HANDLE hMixer; ASX_HANDLE hMux; ASX_ERROR asxError; int nAdapterToUse=0; enum asxNODE eNode; int nNodeIndex; char szName[64]; int nRequiredLength; int nCount; int i,nLen; // create the system ASX_System_Create(ASX_SYSTEM_TYPE_HPI,&hSystem); CheckError(hSystem, __LINE__); // get the adapter asxError = ASX_System_GetAdapter(hSystem,nAdapterToUse,&hAdapter); CheckError(hSystem, __LINE__); ASX_Adapter_GetName(hAdapter,0,0,&nLen); CheckError(hAdapter, __LINE__); pszName = (char *)malloc(nLen); ASX_Adapter_GetName(hAdapter,pszName,nLen,&nLen); CheckError(hAdapter, __LINE__); printf("Adapter [%d] is %s \n", nAdapterToUse,pszName); // get the mixer handle asxError = ASX_Adapter_GetMixer( hAdapter, &hMixer ); CheckError(hAdapter, __LINE__); // get a multiplexer object asxError = ASX_Mixer_GetControlByNodeTypeAndIndex( hMixer, 0,0, asxNODE_RECORDER,0, asxCONTROL_MULTIPLEXER, &hMux); CheckError(hMixer, __LINE__); // print out some control details PrintControlName(hMux); // Get the selector and print out available selections, asxError=0; i=0; while(!asxError) { asxError=ASX_Multiplexer_Enumerate( hMux, i,&eNode, &nNodeIndex, &nCount); if(i==0) printf("Multiplexer has total of %d options\n",nCount); if(!asxError) { ASXSTRING_EnumToString(eNode, szName, 64, &nRequiredLength); printf("Option[%d] is %s %d\n",i,szName,nNodeIndex); i++; } } // Get the current setting. asxError = ASX_Multiplexer_Get(hMux,&eNode,&nNodeIndex); ASXSTRING_EnumToString(eNode, szName, 64, &nRequiredLength); printf("Multiplexer currently set to enum %d, index %d, %s %d\n",eNode,nNodeIndex,szName,nNodeIndex); printf("Press ENTER to exit\n"); getchar(); ASX_System_Delete(hSystem); return 0; } void PrintControlName(ASX_HANDLE hControl) { char *pszName; int nLen; enum asxCONTROL eControl; ASX_Control_GetType(hControl, &eControl); ASXSTRING_EnumToString(eControl,0,0,&nLen); pszName=(char *)malloc(nLen); ASXSTRING_EnumToString(eControl,pszName,nLen,&nLen); printf("Control : %s\n",pszName); free(pszName); } int CheckError(ASX_HANDLE hObj, int nLine) { int nError; int asxSubSystemErrorCode=0; char *pszAsxErrorString; char *pszAsxSubSystemErrorString; int nLen1,nLen2; ASX_Error_GetLast( hObj, &nError, &asxSubSystemErrorCode); if(!nError) return 0; ASX_Error_GetLastString( hObj, 0,0,&nLen1,0,0,&nLen2); pszAsxErrorString = (char *)malloc(nLen1); pszAsxSubSystemErrorString = (char *)malloc(nLen2); ASX_Error_GetLastString( hObj, pszAsxErrorString,nLen1,&nLen1,pszAsxSubSystemErrorString,nLen2,&nLen2); printf("Error: #%d, %s - Subsystem Error: #%ld, %s \n", nError, pszAsxErrorString, asxSubSystemErrorCode, pszAsxSubSystemErrorString ); printf("When called from source %s line %d\n",__FILE__,nLine); printf("Press ENTER to exit\n"); getchar(); free(pszAsxErrorString); free(pszAsxSubSystemErrorString); ASX_System_Delete(hSystem); exit(1); return 1; }
1.7.3