mux/main.c

This is an example of how to use the ASX multiplexer control.

00001 /* $Header: /Repository/apps/asx/examples/mux/main.c,v 1.5 2004/08/11 14:13:36 as-age Exp $ */
00002 #include "stdio.h"
00003 #include "stdlib.h"
00004 #include "asx.h"
00005 #include "asxstring.h"
00006 
00007 int CheckError(ASX_HANDLE hObj, int nLine);
00008 void PrintControlName(ASX_HANDLE hControl);
00009 
00010 ASX_HANDLE hSystem=0;
00011 
00012 int main(int argc, char* argv[])
00013 {
00014     char *pszName;
00015     ASX_HANDLE hAdapter;
00016     ASX_HANDLE hMixer;
00017     ASX_HANDLE hMux;
00018     ASX_ERROR asxError;
00019     int nAdapterToUse=0;
00020     enum asxNODE eNode;
00021     int nNodeIndex;
00022     char szName[64];
00023     int nRequiredLength;
00024     int nCount;
00025     int i,nLen;
00026 
00027     // create the system
00028     ASX_System_Create(ASX_SYSTEM_TYPE_HPI,&hSystem);
00029     CheckError(hSystem, __LINE__);
00030 
00031     // get the adapter
00032     asxError = ASX_System_GetAdapter(hSystem,nAdapterToUse,&hAdapter);
00033     CheckError(hSystem, __LINE__);
00034 
00035     ASX_Adapter_GetName(hAdapter,0,0,&nLen);
00036     CheckError(hAdapter, __LINE__);
00037     pszName = (char *)malloc(nLen);
00038     ASX_Adapter_GetName(hAdapter,pszName,nLen,&nLen);
00039     CheckError(hAdapter, __LINE__);
00040     printf("Adapter [%d] is %s \n", nAdapterToUse,pszName);
00041 
00042     // get the mixer handle
00043     asxError = ASX_Adapter_GetMixer( hAdapter, &hMixer );
00044     CheckError(hAdapter, __LINE__);
00045 
00046     // get a multiplexer object
00047     asxError = ASX_Mixer_GetControlByNodeTypeAndIndex(
00048         hMixer,
00049         0,0,
00050         asxNODE_RECORDER,0,
00051         asxCONTROL_MULTIPLEXER,
00052         &hMux);
00053     CheckError(hMixer, __LINE__);
00054     // print out some control details
00055     PrintControlName(hMux);
00056 
00057     // Get the selector and print out available selections,
00058     asxError=0;
00059     i=0;
00060     while(!asxError)
00061     {
00062 
00063         asxError=ASX_Multiplexer_Enumerate( hMux, i,&eNode, &nNodeIndex, &nCount);
00064         if(i==0)
00065             printf("Multiplexer has total of %d options\n",nCount);
00066         
00067         if(!asxError)
00068         {
00069             ASXSTRING_EnumToString(eNode, szName, 64, &nRequiredLength);
00070             printf("Option[%d] is %s %d\n",i,szName,nNodeIndex);
00071             i++;
00072         }
00073     }
00074 
00075 
00076     // Get the current setting.
00077     asxError = ASX_Multiplexer_Get(hMux,&eNode,&nNodeIndex);
00078     ASXSTRING_EnumToString(eNode, szName, 64, &nRequiredLength);
00079     printf("Multiplexer currently set to enum %d, index %d, %s %d\n",eNode,nNodeIndex,szName,nNodeIndex);
00080 
00081     printf("Press ENTER to exit\n");
00082     getchar();
00083     ASX_System_Delete(hSystem);
00084     return 0;
00085 }
00086 
00087 void PrintControlName(ASX_HANDLE hControl)
00088 {
00089     char *pszName;
00090     int nLen;
00091     enum asxCONTROL eControl;
00092 
00093     ASX_Control_GetType(hControl, &eControl);
00094     ASXSTRING_EnumToString(eControl,0,0,&nLen);
00095     pszName=(char *)malloc(nLen);
00096     ASXSTRING_EnumToString(eControl,pszName,nLen,&nLen);
00097     printf("Control : %s\n",pszName);
00098 
00099     free(pszName);
00100 }
00101 
00102 int CheckError(ASX_HANDLE hObj, int nLine)
00103 {
00104     int nError;
00105     int asxSubSystemErrorCode=0;
00106     char *pszAsxErrorString;
00107     char *pszAsxSubSystemErrorString;
00108     int nLen1,nLen2;
00109 
00110     ASX_Error_GetLast( hObj, &nError, &asxSubSystemErrorCode);
00111     if(!nError)
00112         return 0;
00113     ASX_Error_GetLastString( hObj, 0,0,&nLen1,0,0,&nLen2);
00114     pszAsxErrorString = (char *)malloc(nLen1);
00115     pszAsxSubSystemErrorString = (char *)malloc(nLen2);
00116     ASX_Error_GetLastString( hObj, pszAsxErrorString,nLen1,&nLen1,pszAsxSubSystemErrorString,nLen2,&nLen2);
00117     printf("Error: #%d, %s - Subsystem Error: #%ld, %s \n",
00118         nError,
00119         pszAsxErrorString,
00120         asxSubSystemErrorCode,
00121         pszAsxSubSystemErrorString );
00122     printf("When called from source %s line %d\n",__FILE__,nLine);
00123 
00124     printf("Press ENTER to exit\n");
00125     getchar();
00126     free(pszAsxErrorString);
00127     free(pszAsxSubSystemErrorString);
00128     ASX_System_Delete(hSystem);
00129     exit(1);
00130     return 1;
00131 }

Generated on Tue Nov 18 13:03:40 2008 for ASX by  doxygen 1.4.6-NO