STD_ERROR DLLEXPORT DRV_FunctionGenerator_ReleaseLock ( int Handle ) { STD_ERROR StdError = {0}; tsDriverInfo *pDriverInfo = NULL; CmtThreadLockHandle LockHandle = 0; int LockCounter = 0; int InstrumentType = 0; if ( Handle == 0 ) {STD_ERR (DRV_ERROR_PASSED_NULL);} if ( CmtGetTSVPtr ( Handle , &pDriverInfo ) < 0 ) {STD_ERR (DRV_ERROR_GET_TSV_POINTER);} InstrumentType = pDriverInfo->InstrumentType; LockHandle = pDriverInfo->InstrumentLockHandle; LockCounter = pDriverInfo->LockCounter; CmtReleaseTSVPtr ( Handle ); if ( InstrumentType != DRIVER_TYPE_FUNCTION_GENERATOR ) {STD_ERR (DRV_ERROR_INCORRECT_DRIVER_TYPE);} if ( LockHandle && LockCounter) { CmtReleaseLock (LockHandle); if ( CmtGetTSVPtr ( Handle , &pDriverInfo ) == 0 ) { pDriverInfo->LockCounter--; CmtReleaseTSVPtr ( Handle ); } } Error: return StdError; }
STD_ERROR DLLEXPORT DRV_FunctionGenerator_Signel_On ( int Handle , int Channel ) { STD_ERROR StdError = {0}; tsDriverInfo *pDriverInfo = NULL, tDriverInfo = {0}; CmtTSVHandle VariableHandle = 0; CmtThreadLockHandle LockHandle = 0; pfFunctionGenerator_Signel_On pWrapperFunction = NULL; int bLocked = 0; char *pTempString = NULL; if ( Handle == 0 ) {STD_ERR (DRV_ERROR_PASSED_NULL);} VariableHandle = Handle; if ( CmtGetTSVPtr ( VariableHandle , &pDriverInfo ) < 0 ) {STD_ERR (DRV_ERROR_GET_TSV_POINTER);} memcpy( &tDriverInfo , pDriverInfo , sizeof(tsDriverInfo)); CmtReleaseTSVPtr ( VariableHandle ); if ( tDriverInfo.InstrumentType != DRIVER_TYPE_FUNCTION_GENERATOR ) {STD_ERR (DRV_ERROR_INCORRECT_DRIVER_TYPE);} LockHandle = tDriverInfo.InstrumentLockHandle; pWrapperFunction = tDriverInfo.tInstrDB.functionGeneratorDriverFunctions.FunctionGenerator_Signel_On; CHK_PROCCESS_GET_LOCK ( LockHandle ); if ( pWrapperFunction && ( pDriverInfo->bDemoMode == 0 )) FREE_STDERR_COPY_ERR( pWrapperFunction( tDriverInfo.InstrumentHandle , Channel )); if ( pWrapperFunction == NULL ) { char szMessage[LOW_STRING] = {0}; sprintf( szMessage , "Method \"%s\"\nis not implemented in driver:\n%s" , "FunctionGenerator_Signel_On" , tDriverInfo.pDriverFileName ); ShowMessage ( INSTR_TYPE_CONTINUE , "Implementation Error . . ." , szMessage , NULL ); } Error: if ( LockHandle && bLocked ) CmtReleaseLock (LockHandle); if ( StdError.error ) { DRV_FunctionGenerator_GetErrorTextMessage ( VariableHandle , StdError.error , &pTempString ); if ( pTempString && ( strlen(pTempString))) { SET_DESCRIPTION(pTempString); } FREE(pTempString); } return StdError; }
STD_ERROR DLLEXPORT DRV_FunctionGenerator_Close ( int *pHandle ) { STD_ERROR StdError = {0}; tsDriverInfo *pDriverInfo = NULL, tDriverInfo = {0}; CmtTSVHandle VariableHandle = 0; CmtThreadLockHandle LockHandle = 0; pfFunctionGenerator_Close pWrapperFunction = NULL; int bHandleExists = 0; int bLocked = 0; if ( pHandle == NULL ) {STD_ERR (DRV_ERROR_PASSED_NULL);} VariableHandle = *pHandle; *pHandle = 0; if ( VariableHandle == 0 ) {STD_ERR (DRV_ERROR_PASSED_NULL);} if ( CmtGetTSVPtr ( VariableHandle , &pDriverInfo ) < 0 ) {STD_ERR (DRV_ERROR_GET_TSV_POINTER);} memcpy( &tDriverInfo , pDriverInfo , sizeof(tsDriverInfo)); FREE( pDriverInfo->pLastStateFileName ); CmtReleaseTSVPtr ( VariableHandle ); if ( tDriverInfo.InstrumentType != DRIVER_TYPE_FUNCTION_GENERATOR ) {STD_ERR (DRV_ERROR_INCORRECT_DRIVER_TYPE);} LockHandle = tDriverInfo.InstrumentLockHandle; pWrapperFunction = tDriverInfo.tInstrDB.functionGeneratorDriverFunctions.FunctionGenerator_Close; bHandleExists = DRIVER_MANAGER_IsConnectionExists( tDriverInfo.pInstrumentAddress , NULL , NULL ); if ( pWrapperFunction && bHandleExists ) { CHK_PROCCESS_GET_LOCK ( LockHandle ); if ( pDriverInfo->bDemoMode == 0 ) { FREE_STDERR_COPY( pWrapperFunction( &tDriverInfo.InstrumentHandle )); } CmtReleaseLock ( LockHandle ); LockHandle=0; bLocked=0; DRIVER_MANAGER_RemoveConnectionExists( tDriverInfo.pInstrumentAddress , tDriverInfo.InstrumentHandle ); } if ( pWrapperFunction == NULL ) { char szMessage[LOW_STRING] = {0}; sprintf( szMessage , "Method \"%s\"\nis not implemented in driver:\n%s" , "FunctionGenerator_Close" , tDriverInfo.pDriverFileName ); ShowMessage ( INSTR_TYPE_CONTINUE , "Implementation Error . . ." , szMessage , NULL ); } FREE(tDriverInfo.pInstrumentAddress); FREE(tDriverInfo.pDriverFileName); if ( tDriverInfo.pCalibration ) { FREE(tDriverInfo.pCalibration->pStateFileName); FREE(tDriverInfo.pCalibration->pCalibrationRefName); FREE(tDriverInfo.pCalibration->pConnectionDescription); FREE(tDriverInfo.pCalibration->pConnectionImage); FREE(tDriverInfo.pCalibration->vlfFrequency); FREE(tDriverInfo.pCalibration->vlfLoss); FREE(tDriverInfo.pCalibration->vlfPowerList); FREE_LIST(tDriverInfo.pCalibration->vlfLossList,tDriverInfo.pCalibration->iNumberOfPowers); FREE(tDriverInfo.pCalibration); } FREE( tDriverInfo.ptCallbacks ); Error: if ( LockHandle && bLocked ) CmtReleaseLock ( LockHandle ); if ( VariableHandle ) CmtDiscardTSV ( VariableHandle ); if ( DRIVER_MANAGER_IsConnectionExistsByType( DRIVER_TYPE_FUNCTION_GENERATOR ) == 0 ) FreeLibrary( tDriverInfo.LibraryHandle ); *pHandle = 0; if ( StdError.error ) {FREE_CALLOC_COPY_STRING (StdError.pszErrorDescription, "Error while closing instrument driver.");} return StdError; }
int DLLEXPORT DRV_FunctionGenerator_GetErrorTextMessage ( int Handle , int iError , char **pErrorMessage ) { tsDriverInfo *pDriverInfo = NULL, tDriverInfo = {0}; CmtTSVHandle VariableHandle = 0; CmtThreadLockHandle LockHandle = 0; pfFunctionGenerator_GetErrorTextMessage pWrapperFunction = NULL; STD_ERROR StdError = {0}; int bLocked = 0; if ((pErrorMessage == NULL) || (Handle == 0)) return DRV_ERROR_PASSED_NULL; CALLOC_ERR( *pErrorMessage , 256 , sizeof(char)); VariableHandle = Handle; if ( CmtGetTSVPtr ( VariableHandle , &pDriverInfo ) < 0 ) return DRV_ERROR_GET_TSV_POINTER; memcpy( &tDriverInfo , pDriverInfo , sizeof(tsDriverInfo)); CmtReleaseTSVPtr ( VariableHandle ); if ( tDriverInfo.InstrumentType != DRIVER_TYPE_FUNCTION_GENERATOR ) return DRV_ERROR_INCORRECT_DRIVER_TYPE; switch (iError) { case NO_ERROR: strcpy (*pErrorMessage, "OK."); break; case DRV_ERROR_PASSED_NULL: strcpy (*pErrorMessage, "Function parameter passed NULL."); break; case DRV_ERROR_INCORRECT_DRIVER_TYPE: strcpy (*pErrorMessage, "Unknown driver type."); break; case DRV_ERROR_CONNECTION: strcpy (*pErrorMessage, "Can't connect to the instrument."); break; case DRV_ERROR_CREATE_TSV_HANDLE: strcpy (*pErrorMessage, "Can't create new Thread Safe Variable."); break; case DRV_ERROR_GET_TSV_POINTER: strcpy (*pErrorMessage, "Can't get pointer to the Thread Safe Variable."); break; case DRV_ERROR_CREATE_LOCK_HANDLE: strcpy (*pErrorMessage, "Can't create new Lock."); break; case DRV_ERROR_DLL_FILE_NOT_FOUND: strcpy (*pErrorMessage, "The dll file not found."); break; case DRV_ERROR_DLL_FILE_NOT_OPENED: strcpy (*pErrorMessage, "Can't open the dll."); break; default: LockHandle = tDriverInfo.InstrumentLockHandle; pWrapperFunction = tDriverInfo.tInstrDB.functionGeneratorDriverFunctions.FunctionGenerator_GetErrorTextMessage; CHK_PROCCESS_GET_LOCK ( LockHandle ); if ( pWrapperFunction && ( pDriverInfo->bDemoMode == 0 )) { FREE_STDERR_COPY( pWrapperFunction ( tDriverInfo.InstrumentHandle , iError , (*pErrorMessage) )); } if ( pWrapperFunction == NULL ) { char szMessage[LOW_STRING] = {0}; sprintf( szMessage , "Method \"%s\"\nis not implemented in driver:\n%s" , "FunctionGenerator_GetErrorTextMessage" , tDriverInfo.pDriverFileName ); ShowMessage ( INSTR_TYPE_CONTINUE , "Implementation Error . . ." , szMessage , NULL ); } break; } Error: if ( LockHandle && bLocked ) CmtReleaseLock (LockHandle); RETURN_ERROR_VALUE; }
STD_ERROR DLLEXPORT DRV_FunctionGenerator_Init ( char *pszDriverLocation , char *pszAddressString , int *pHandle ) { STD_ERROR StdError = {0}; tsDriverInfo *pDriverInfo = NULL; CmtTSVHandle VariableHandle = 0; CmtThreadLockHandle LockHandle = 0; pfFunctionGenerator_Init pWrapperFunction = NULL; char szCurrentDirectory[STD_STRING] = {0}, szDriverLocation[STD_STRING] = {0}, szMessage[STD_STRING] = {0}, *pTemp = NULL; int iTry = 0, bHandleExists = 0; int bLocked = 0; char *pTempString = NULL; pfSTD_Config_Install_CommentCallback pConfig_Install_CommentCallback = NULL; pfSTD_Config_Install_ConfigValueCallback pConfig_Install_ConfigValueCallback = NULL; pfSTD_Config_Install_CheckForBreakCallback pConfig_Install_CheckForBreakCallback = NULL; pfSTD_Config_Copy_STD_CallBackSet pConfig_Copy_STD_CallBackSet = NULL; HINSTANCE LibraryHandle = NULL; if (( pszDriverLocation == NULL ) || ( pszAddressString == NULL )) {STD_ERR (DRV_ERROR_PASSED_NULL);} strcpy( szDriverLocation , pszDriverLocation ); do { pTemp = strstr( pszDriverLocation , ":\\" ); if ( pTemp ) break; pTemp = strchr( pszDriverLocation , '\\' ); if ( pTemp == NULL ) break; GetModuleDir( __CVIUserHInst , szCurrentDirectory ); if ( pTemp == pszDriverLocation ) sprintf( szDriverLocation , "%s%s" , szCurrentDirectory , pszDriverLocation ); else sprintf( szDriverLocation , "%s\\%s" , szCurrentDirectory , pszDriverLocation ); } while(0); if ( FileExists(szDriverLocation,NULL) == 0 ) { sprintf( szMessage , "Loading Function Generator Driver\n\"%s\"\n\nFailed, File has not found." , szDriverLocation ); ShowMessage ( INSTR_TYPE_CONTINUE , "Equipment driver file error..." , szMessage , NULL ); FORCE_ERR(-5,szMessage); } if ( pHandle ) { if ( CmtNewTSV ( sizeof(tsDriverInfo) , &VariableHandle ) != 0 ) {STD_ERR (DRV_ERROR_CREATE_TSV_HANDLE);} if ( VariableHandle == 0 ) {STD_ERR (DRV_ERROR_CREATE_TSV_HANDLE);} do { *pHandle = VariableHandle; if ( CmtGetTSVPtr ( VariableHandle , &pDriverInfo ) < 0 ) { {STD_ERR (DRV_ERROR_GET_TSV_POINTER);} break; } pDriverInfo->InstrumentType = DRIVER_TYPE_FUNCTION_GENERATOR; CALLOC_COPY_STRING( pDriverInfo->pInstrumentAddress , pszAddressString ); bHandleExists = DRIVER_MANAGER_IsConnectionExists( pszAddressString , &(pDriverInfo->InstrumentHandle) , &(pDriverInfo->InstrumentLockHandle) ); //--------- Load Library ---------------------// pDriverInfo->LibraryHandle = LoadLibrary(szDriverLocation); CALLOC_COPY_STRING( pDriverInfo->pDriverFileName,szDriverLocation); if ( pDriverInfo->LibraryHandle == 0 ) { {STD_ERR (DRV_ERROR_DLL_FILE_NOT_OPENED);} break; } //--------------- Load functions ------------------// pDriverInfo->tInstrDB.functionGeneratorDriverFunctions.Config_Install_CommentCallback = (pfSTD_Config_Install_CommentCallback) GetProcAddress( pDriverInfo->LibraryHandle , "Config_Install_CommentCallback"); pDriverInfo->tInstrDB.functionGeneratorDriverFunctions.Config_Install_ConfigValueCallback = (pfSTD_Config_Install_ConfigValueCallback) GetProcAddress( pDriverInfo->LibraryHandle , "Config_Install_ConfigValueCallback"); pDriverInfo->tInstrDB.functionGeneratorDriverFunctions.Config_Install_CheckForBreakCallback = (pfSTD_Config_Install_CheckForBreakCallback) GetProcAddress( pDriverInfo->LibraryHandle , "Config_Install_CheckForBreakCallback"); pDriverInfo->tInstrDB.functionGeneratorDriverFunctions.Config_LOG_SetAllowState = (pfSTD_Config_LOG_SetAllowState) GetProcAddress( pDriverInfo->LibraryHandle , "Config_LOG_SetAllowState"); pDriverInfo->tInstrDB.functionGeneratorDriverFunctions.Config_Copy_STD_CallBackSet = (pfSTD_Config_Copy_STD_CallBackSet) GetProcAddress( pDriverInfo->LibraryHandle , "Config_Copy_STD_CallBackSet"); pDriverInfo->tInstrDB.functionGeneratorDriverFunctions.FunctionGenerator_GetErrorTextMessage = (pfFunctionGenerator_GetErrorTextMessage) GetProcAddress( pDriverInfo->LibraryHandle , "FunctionGenerator_GetErrorTextMessage"); pDriverInfo->tInstrDB.functionGeneratorDriverFunctions.FunctionGenerator_Init = (pfFunctionGenerator_Init) GetProcAddress( pDriverInfo->LibraryHandle , "FunctionGenerator_Init"); pDriverInfo->tInstrDB.functionGeneratorDriverFunctions.FunctionGenerator_Close = (pfFunctionGenerator_Close) GetProcAddress( pDriverInfo->LibraryHandle , "FunctionGenerator_Close"); pDriverInfo->tInstrDB.functionGeneratorDriverFunctions.FunctionGenerator_Reset = (pfFunctionGenerator_Reset) GetProcAddress( pDriverInfo->LibraryHandle , "FunctionGenerator_Reset"); pDriverInfo->tInstrDB.functionGeneratorDriverFunctions.FunctionGenerator_Initiate = (pfFunctionGenerator_Initiate) GetProcAddress( pDriverInfo->LibraryHandle , "FunctionGenerator_Initiate"); pDriverInfo->tInstrDB.functionGeneratorDriverFunctions.FunctionGenerator_Signel_Off = (pfFunctionGenerator_Signel_Off) GetProcAddress( pDriverInfo->LibraryHandle , "FunctionGenerator_Signel_Off"); pDriverInfo->tInstrDB.functionGeneratorDriverFunctions.FunctionGenerator_Signel_On = (pfFunctionGenerator_Signel_On) GetProcAddress( pDriverInfo->LibraryHandle , "FunctionGenerator_Signel_On"); pDriverInfo->tInstrDB.functionGeneratorDriverFunctions.FunctionGenerator_Save_State = (pfFunctionGenerator_Save_State) GetProcAddress( pDriverInfo->LibraryHandle , "FunctionGenerator_Save_State"); pDriverInfo->tInstrDB.functionGeneratorDriverFunctions.FunctionGenerator_Load_State = (pfFunctionGenerator_Load_State) GetProcAddress( pDriverInfo->LibraryHandle , "FunctionGenerator_Load_State"); pDriverInfo->tInstrDB.Equipment_Info = (pfSTD_Equipment_Info) GetProcAddress( pDriverInfo->LibraryHandle , "Equipment_Info"); pDriverInfo->tInstrDB.Equipment_IsSupported = (pfSTD_Equipment_IsSupported) GetProcAddress( pDriverInfo->LibraryHandle , "Equipment_IsSupported"); pDriverInfo->tInstrDB.Equipment_SendStateFile = (pfSTD_Equipment_SendStateFile) GetProcAddress( pDriverInfo->LibraryHandle , "Equipment_SendStateFile"); pDriverInfo->tInstrDB.Equipment_ReceiveStateFile = (pfSTD_Equipment_ReceiveStateFile) GetProcAddress( pDriverInfo->LibraryHandle , "Equipment_ReceiveStateFile"); pDriverInfo->tInstrDB.Equipment_GetFileCatalog = (pfSTD_Equipment_GetFileCatalog) GetProcAddress( pDriverInfo->LibraryHandle , "Equipment_GetFileCatalog"); pDriverInfo->tInstrDB.Equipment_MakeFileCatalog = (pfSTD_Equipment_MakeFileCatalog) GetProcAddress( pDriverInfo->LibraryHandle , "Equipment_MakeFileCatalog"); pDriverInfo->tInstrDB.Equipment_DeleteFileCatalog = (pfSTD_Equipment_DeleteFileCatalog) GetProcAddress( pDriverInfo->LibraryHandle , "Equipment_DeleteFileCatalog"); pDriverInfo->tInstrDB.Equipment_DeleteStateFile = (pfSTD_Equipment_DeleteStateFile) GetProcAddress( pDriverInfo->LibraryHandle , "Equipment_DeleteStateFile"); pDriverInfo->tInstrDB.Config_SetAttribute = (pfSTD_Config_SetAttribute) GetProcAddress( pDriverInfo->LibraryHandle , "Config_SetAttribute"); pWrapperFunction = pDriverInfo->tInstrDB.functionGeneratorDriverFunctions.FunctionGenerator_Init; if ( pWrapperFunction == NULL ) { char szMessage[LOW_STRING] = {0}; sprintf( szMessage , "Method \"%s\"\nis not implemented in driver:\n%s" , "FunctionGenerator_Init" , pDriverInfo->pDriverFileName ); ShowMessage ( INSTR_TYPE_CONTINUE , "Implementation Error . . ." , szMessage , NULL ); {STD_ERR (DRV_ERROR_WRONG_WRAPPER);} } if ( !bHandleExists ) DRIVER_MANAGER_AddConnection( pszAddressString , &(pDriverInfo->InstrumentHandle) , DRIVER_TYPE_FUNCTION_GENERATOR , &(pDriverInfo->InstrumentLockHandle) ); LockHandle = pDriverInfo->InstrumentLockHandle; if ( LockHandle == 0 ) {STD_ERR (DRV_ERROR_CREATE_LOCK_HANDLE);} CHK_PROCCESS_GET_LOCK ( LockHandle ); DRIVER_MANAGER_IsConnectionExists( pszAddressString, &(pDriverInfo->InstrumentHandle) , NULL ); //===================== Install Calbacks ==========================================================================================// pConfig_Install_CommentCallback = pDriverInfo->tInstrDB.functionGeneratorDriverFunctions.Config_Install_CommentCallback; pConfig_Install_ConfigValueCallback = pDriverInfo->tInstrDB.functionGeneratorDriverFunctions.Config_Install_ConfigValueCallback; pConfig_Install_CheckForBreakCallback = pDriverInfo->tInstrDB.functionGeneratorDriverFunctions.Config_Install_CheckForBreakCallback; pConfig_Copy_STD_CallBackSet = pDriverInfo->tInstrDB.functionGeneratorDriverFunctions.Config_Copy_STD_CallBackSet; DRIVER_MANAGER_GetCopyCallbacksStructure( VariableHandle , &(pDriverInfo->ptCallbacks) , 1 , pszAddressString ); if ( pConfig_Copy_STD_CallBackSet && ( pDriverInfo->ptCallbacks )) { FREE_STDERR_COPY_ERR( pConfig_Copy_STD_CallBackSet( &pDriverInfo->InstrumentHandle , pDriverInfo->ptCallbacks )); pDriverInfo->ptCallbacks = NULL; } else { if ( pConfig_Install_CommentCallback && ( pDriverInfo->ptCallbacks )) { FREE_STDERR_COPY_ERR( pConfig_Install_CommentCallback( &pDriverInfo->InstrumentHandle , (pDriverInfo->ptCallbacks)->fCommentCallback , (pDriverInfo->ptCallbacks)->pCommentCallbackData , (pDriverInfo->ptCallbacks)->commentType )); } if ( pConfig_Install_ConfigValueCallback && ( pDriverInfo->ptCallbacks )) { FREE_STDERR_COPY_ERR( pConfig_Install_ConfigValueCallback( &pDriverInfo->InstrumentHandle , (pDriverInfo->ptCallbacks)->fConfigValueCallback , (pDriverInfo->ptCallbacks)->pConfigValueCallbackData , (pDriverInfo->ptCallbacks)->configType )); } if ( pConfig_Install_CheckForBreakCallback && ( pDriverInfo->ptCallbacks )) { FREE_STDERR_COPY_ERR( pConfig_Install_CheckForBreakCallback( &pDriverInfo->InstrumentHandle , (pDriverInfo->ptCallbacks)->fCheckForBreakCallback , (pDriverInfo->ptCallbacks)->pCheckForBreakCallbackData , (pDriverInfo->ptCallbacks)->breakType )); } } if (pDriverInfo->ptCallbacks) pDriverInfo->bDemoMode = (pDriverInfo->ptCallbacks)->bDemoMode; //=================================================================================================================================// for ( iTry = 0 ; iTry < 3 ; iTry++ ) { if ( pDriverInfo->bDemoMode == 1 ) { pDriverInfo->bConnected = 1; break; } if ( pWrapperFunction ) { FREE_STDERR_COPY( pWrapperFunction( pDriverInfo->InstrumentHandle , pszAddressString , &pDriverInfo->InstrumentHandle , &pDriverInfo->bConnected , &pDriverInfo->ChannelQuantity )); } else break; if ( StdError.error ) if ( ShowMessage ( INSTR_TYPE_YES_NO , "Function Genrator Error !!!", "Check connection and Power On the Device." , NULL ) ) continue; break; } CHK_STDERR(StdError); if (pDriverInfo->bConnected == 0) {STD_ERR (DRV_ERROR_CONNECTION);} if ( !bHandleExists ) DRIVER_MANAGER_UpdateConnection( pszAddressString , pDriverInfo->InstrumentHandle , NULL ); } while (0); } else { pfSTD_Equipment_IsSupported pWrapperFunction = NULL; int iCount = 0, status = 0, bSupport = 0, defaultRM = 0, hConnectionHandle = 0; char szReadBuffer[LOW_STRING] = {0}; //------------------ Checking for driver supporting ------------------------// viOpenDefaultRM (&defaultRM); SetBreakOnLibraryErrors (0); status = viOpen ( defaultRM , pszAddressString , NULL, NULL, &hConnectionHandle ); if ( status == 0 ) { status = viPrintf ( hConnectionHandle , "*IDN?\n" ); if ( status == 0 ) { viRead ( hConnectionHandle , szReadBuffer , (LOW_STRING-1) , &iCount ); } } if ( hConnectionHandle ) viClose(hConnectionHandle); SetBreakOnLibraryErrors (1); LibraryHandle = LoadLibrary(szDriverLocation); if ( LibraryHandle == 0 ) { sprintf( szMessage , "Loading Driver File\n\"%s\"\n\nFailed, File corrupted." , szDriverLocation ); ShowMessage ( INSTR_TYPE_CONTINUE , "Equipment driver file error..." , szMessage , NULL ); FORCE_ERR(-6,szMessage); } pWrapperFunction = (pfSTD_Equipment_IsSupported) GetProcAddress( LibraryHandle , "Equipment_IsSupported"); if ( pWrapperFunction ) { FREE_STDERR_COPY_ERR( pWrapperFunction( 0, pszAddressString , NULL , szReadBuffer , &bSupport , NULL )); IF (( bSupport == 0 ) , "This driver is not support the current Equipment." ); } else { char szMessage[LOW_STRING] = {0}; sprintf( szMessage , "Method \"%s\"\nis not implemented in driver:\n%s" , "Equipment_IsSupported" , szDriverLocation ); ShowMessage ( INSTR_TYPE_CONTINUE , "Implementation Error . . ." , szMessage , NULL ); } } Error: if ( LibraryHandle ) FreeLibrary(LibraryHandle); if ( LockHandle && bLocked ) CmtReleaseLock (LockHandle); if ( VariableHandle ) CmtReleaseTSVPtr ( VariableHandle ); if ( StdError.error ) { DRV_FunctionGenerator_GetErrorTextMessage ( VariableHandle , StdError.error , &pTempString ); if ( pTempString && ( strlen(pTempString))) { SET_DESCRIPTION(pTempString); } FREE(pTempString); DRV_FunctionGenerator_Close( &VariableHandle ); if ( pHandle ) *pHandle = 0; } return StdError; }
int CVICALLBACK DataThread (void *functionData) { char fileNameA[32]; char fileNameB[32]; char filePathA[MAX_PATHNAME_LEN]; // for data from channel A char filePathB[MAX_PATHNAME_LEN]; // for data from channel B U16 *data; FILE *outA, *outB; unsigned int numberOfElements = 0; // wait for tread lock CmtGetLock (dataThreadLock); // release the lock CmtReleaseLock (dataThreadLock); status = 3; // DataThread() is started SetCtrlVal (panelHandle, PANEL_STATUS, status); SetCtrlVal (panelHandle, PANEL_ERRORMSG, "Nice! DataThread() has been started!\n"); // get the total number of elements to write numberOfElements = rawBscanSize * rawAlineSize; // init the values dataLoop = 0; // run until button STOP pressed while (stop == 0) { // wait for event from AlazarAcquire() WaitForSingleObject (eventData, INFINITE); // remove buffer from FIFO buffer and free memory space while (FIFOBuff->f_head != FIFOBuff->f_tail) { data = FIFO_Remove (FIFOBuff); // remove buffer from FIFO queue // update counters SetCtrlAttribute (panelHandle, PANEL_TIMEVALUE, ATTR_CTRL_VAL, timerValue * 1000.0); // draw plot DeleteGraphPlot (panelHandle, PANEL_ALINEGRAPH, -1, VAL_DELAYED_DRAW); PlotY (panelHandle, PANEL_ALINEGRAPH, data + numberOfElements * channel + rawAlineSize * aLineIndex, rawAlineSize, VAL_UNSIGNED_SHORT_INTEGER, VAL_FAT_LINE, VAL_EMPTY_SQUARE, VAL_SOLID, 1, VAL_CYAN); // record files only if we have directory name in pathName variable if ((save == 2) || (dataLoop < alazarLoop)) { // set number of buffers which were saved SetCtrlAttribute (panelHandle, PANEL_DATALOOPS, ATTR_CTRL_VAL, dataLoop++); SetCtrlAttribute (panelHandle, PANEL_ALAZARLOOPS, ATTR_CTRL_VAL, alazarLoop); // set the name of output files and notify sprintf (fileNameA, "%09lli.mzi.raw.dat", dataLoop); sprintf (fileNameB, "%09lli.sample.raw.dat", dataLoop); MakePathname (pathName, fileNameA, filePathA); MakePathname (pathName, fileNameB, filePathB); SetCtrlAttribute (panelHandle, PANEL_DIRPATH, ATTR_CTRL_VAL, filePathB); // open output files for recording outA = fopen (filePathA, "wb"); outB = fopen (filePathB, "wb"); // error handling if ((outA == NULL) || (outB == NULL)) { SetCtrlVal (panelHandle, PANEL_ERRORMSG, "Ooops! We could not open files for recording!\n"); save = 0; SetCtrlVal (panelHandle, PANEL_SAVESWITCH, save); break; } // record buffer from channel A if (numberOfElements != fwrite (data, bytesPerSample, numberOfElements, outA)) { SetCtrlVal (panelHandle, PANEL_ERRORMSG, "Ooops! We could not write the file!\n"); save = 0; SetCtrlVal (panelHandle, PANEL_SAVESWITCH, save); fclose (outA); break; } // record buffer from channel B if (numberOfElements != fwrite (data + numberOfElements, bytesPerSample, numberOfElements, outB)) { SetCtrlVal (panelHandle, PANEL_ERRORMSG, "Ooops! We could not write the file!\n"); save = 0; SetCtrlVal (panelHandle, PANEL_SAVESWITCH, save); fclose (outB); break; } // close output files fclose (outA); fclose (outB); } free (data); // free buffer obtained from FIFO queue } } SetCtrlVal (panelHandle, PANEL_ERRORMSG, "Nice! DataThread() has been stopped!\n"); return 0; }
int CVICALLBACK threadFunc (void *functionData) { char textline[1024]; volatile int stop = 0, loop = 0; double value = 0.0; CNVBufferedWriter bufferedWriter; CNVData data = 0; int error; char buffer[MAX_PATHNAME_LEN]; // wait for tread lock CmtGetLock (lock); // release the lock CmtReleaseLock (lock); status = 2; // run while loop SetCtrlVal (panelHandle, PANEL_STATUS, status); SetCtrlVal(panelHandle, PANEL_TEXTSTRING, "Nice! thread() has been started!"); Delay (1.0); error = NetworkVariablePopup (buffer); if (error < 0) { MessagePopup ("Error", GetGeneralErrorString(error)); return 0; } else if (error > 0) { SetCtrlVal (panelHandle, PANEL_NAME, buffer); SetWaitCursor (1); error = CNVCreateBufferedWriter (buffer, DataTransferredCallback, StatusCallback, 0, 10, 10000, 0, &bufferedWriter); SetWaitCursor (0); if (error < 0) { MessagePopup ("Error", CNVGetErrorDescription(error)); return 0; } else { SetCtrlVal (panelHandle, PANEL_CNVSTATUS, "Connected"); } } CNVCreateScalarDataValue (&data, CNVDouble, value); while (stop == 0) { SetCtrlVal (panelHandle, PANEL_LED, 0); GetCtrlVal (panelHandle, PANEL_STOPBUTTON, &stop); Delay (0.2); sprintf (textline, "%i, %i", loop++, stop); SetCtrlVal (panelHandle, PANEL_TEXTSTRING, textline); value = loop; CNVSetScalarDataValue (data, CNVDouble, value); CNVPutDataInBuffer (bufferedWriter, data, CNVDoNotWait); } SetCtrlVal(panelHandle, PANEL_TEXTSTRING, "Nice! thread() has been stopped!"); Delay (1.0); CNVDisposeData (data); CNVDispose (bufferedWriter); CNVFinish (); status = 3; // exit threadFunc() SetCtrlVal (panelHandle, PANEL_STATUS, status); return 0; }