⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 hp33120a.c

📁 CVI教程,用于信号采集系统的多任务开发软件.学习简单,功能实用.
💻 C
📖 第 1 页 / 共 5 页
字号:
    return error;}/***************************************************************************** * Function: hp33120a_GenerateStandardWaveform * Purpose:  This application function configures the attributes of the  *           function generator that affect standard waveform generation, *           enables an output channel, and initiates signal generation.  This *           behavior is identical to calling the *           hp33120a_ConfigureStandardWaveform function. *****************************************************************************/ViStatus _VI_FUNC  hp33120a_GenerateStandardWaveform (ViSession vi,                              ViConstString channelName,                              ViInt32 waveform,                              ViReal64 amplitude,                              ViReal64 dcOffset,                              ViReal64 frequency,                              ViReal64 startPhase){    ViStatus error = VI_SUCCESS;        checkErr( Ivi_LockSession (vi, VI_NULL));    /* Call functions */    checkErr( hp33120a_ConfigureStandardWaveform (vi, channelName, waveform,                          amplitude, dcOffset, frequency,                          startPhase));Error:    Ivi_UnlockSession (vi, VI_NULL);    return error;}/***************************************************************************** * Function: hp33120a_QueryArbWfmCapabilities * Purpose:  This function returns the attributes of the function generator *           that are related to creating arbitrary waveforms.  These *           attributes are the maximum number of waveforms, waveform *           quantum, minimum waveform size, and maximum waveform size. *****************************************************************************/ViStatus _VI_FUNC  hp33120a_QueryArbWfmCapabilities (ViSession vi,                          ViInt32 *maxNumWfms,                          ViInt32 *wfmQuantum,                          ViInt32 *minWfmSize,                          ViInt32 *maxWfmSize) {    ViStatus error = VI_SUCCESS;        checkErr( Ivi_LockSession (vi, VI_NULL));        /* Get attributes */    if (maxNumWfms)    viCheckParm( Ivi_GetAttributeViInt32 (vi, VI_NULL,                         HP33120A_ATTR_MAX_NUM_WAVEFORMS,                         0, maxNumWfms), 2,                         "Max Number of Waveforms");    if (wfmQuantum)    viCheckParm( Ivi_GetAttributeViInt32 (vi, VI_NULL,                         HP33120A_ATTR_WAVEFORM_QUANTUM,                         0, wfmQuantum), 3, "Waveform Quantum");    if (minWfmSize)    viCheckParm( Ivi_GetAttributeViInt32 (vi, VI_NULL,                         HP33120A_ATTR_MIN_WAVEFORM_SIZE,                         0, minWfmSize), 4, "Min Waveform Size");    if (maxWfmSize)    viCheckParm( Ivi_GetAttributeViInt32 (vi, VI_NULL,                         HP33120A_ATTR_MAX_WAVEFORM_SIZE,                         0, maxWfmSize), 5, "Max Waveform Size");    checkErr( hp33120a_CheckStatus (vi));    Error:    Ivi_UnlockSession (vi, VI_NULL);    return error;}/***************************************************************************** * Function: hp33120a_CreateArbWaveform * Purpose:  This function creates an arbitrary waveform and returns a handle *           that identifies that waveform.  You use the handles this *           function returns to specify a sequence of arbitrary waveforms *           with the hp33120a_CreateArbSequence function. *****************************************************************************/ViStatus _VI_FUNC hp33120a_CreateArbWaveform (ViSession vi, ViInt32 wfmSize,                         ViReal64 wfmData[],                         ViInt32 *wfmHandle){    ViStatus error = VI_SUCCESS;    ViInt32  newWfmHandle = VI_NULL;    ViChar   newWfmName[HP33120A_VAL_NAME_LENGTH];    ViChar  *writBuff = VI_NULL;    ViInt16 *binData = VI_NULL;        checkErr( Ivi_LockSession (vi, VI_NULL));        if (!wfmData)    viCheckParm( IVI_ERROR_INVALID_PARAMETER, 3, "NULL address for wfmData");    if (!wfmHandle)    viCheckParm( IVI_ERROR_INVALID_PARAMETER, 4, "NULL address for wfmHandle");        checkErr( hp33120a_VerifyOutputMode (vi, HP33120A_VAL_OUTPUT_ARB));    checkErr( hp33120a_VerifyWfmCreatable(vi, wfmSize, wfmData));     checkErr( hp33120a_GetNewWfmInfo (vi, &newWfmHandle, newWfmName));            if (!Ivi_Simulating(vi))                /* call only when locked */    {    ViSession   io = Ivi_IOSession(vi); /* call only when locked */    ViInt32     index, x;    checkErr( Ivi_SetNeedToCheckStatus (vi, VI_TRUE));        checkErr( Ivi_Alloc (vi, (sizeof(ViInt16)*wfmSize), (ViAddr *)(&binData)));    checkErr( Ivi_Alloc (vi, (sizeof(ViChar)*((wfmSize*2) + 28)), (ViAddr *)(&writBuff)));    /* convert to range -2047 to 2047 */    for (index = 0; index < wfmSize; index++)        {        binData[index] = (ViInt16)(floor (2047 * wfmData[index]));        }    /* put data in Big-Endian notation */    Fmt (binData, "%*d[b2o10]<%*d[b2]",wfmSize,wfmSize,binData);    /* build output buffer to write to instrument */    x = sprintf(writBuff, ":DATA:DAC VOLATILE, #5%05d", (2*wfmSize));    memcpy((writBuff + x), binData, (2*wfmSize));    viCheckErr( viBufWrite (io, writBuff, (x + 2*wfmSize), VI_NULL));    viCheckErr( viPrintf(io, ":DATA:COPY %s", newWfmName));        }        checkErr( hp33120a_CheckStatus (vi));    checkErr( hp33120a_UpdateDriverWfmRecord (vi, newWfmHandle, wfmSize, newWfmName));    Error:    if (binData)    Ivi_Free (vi, binData);    *wfmHandle = ((error < VI_SUCCESS) ? VI_NULL : newWfmHandle);    Ivi_UnlockSession (vi, VI_NULL);    return error;}/***************************************************************************** * Function: hp33120a_ConfigureSampleRate * Purpose:  This function configures the sample rate attribute, which *           determines the rate at which the function generator produces *           arbitrary waveforms. *****************************************************************************/ViStatus _VI_FUNC hp33120a_ConfigureSampleRate (ViSession vi, ViReal64 sampleRate){    ViStatus error = VI_SUCCESS;        checkErr( Ivi_LockSession (vi, VI_NULL));        /* Set attribute */    viCheckParm( Ivi_SetAttributeViReal64 (vi, VI_NULL,                       HP33120A_ATTR_ARB_SAMPLE_RATE,                       0, sampleRate), 4, "Sample Rate");        checkErr( hp33120a_CheckStatus (vi));    Error:    Ivi_UnlockSession (vi, VI_NULL);    return error;}/***************************************************************************** * Function: hp33120a_ConfigureArbWaveform * Purpose:  This function configures the attributes of the function *           generator that affect arbitrary waveform generation.  These *           attributes are the arbitrary waveform handle, gain, and offset. *****************************************************************************/ViStatus _VI_FUNC  hp33120a_ConfigureArbWaveform (ViSession vi,                          ViConstString channelName,                          ViInt32 wfmHandle,                          ViReal64 arbGain,                          ViReal64 arbOffset){    ViStatus error = VI_SUCCESS;        checkErr( Ivi_LockSession (vi, VI_NULL));        /* Set attributes */    viCheckParm( Ivi_SetAttributeViInt32 (vi, channelName,                      HP33120A_ATTR_ARB_WAVEFORM_HANDLE,                      0, wfmHandle), 3, "Waveform Handle");    viCheckParm( Ivi_SetAttributeViReal64 (vi, channelName,                       HP33120A_ATTR_ARB_GAIN,                       0, arbGain), 4, "Arbitrary Gain");    viCheckParm( Ivi_SetAttributeViReal64 (vi, channelName,                        HP33120A_ATTR_ARB_OFFSET,                       0, arbOffset), 5, "Arbitrary Offset");    checkErr( hp33120a_CheckStatus (vi));    Error:    Ivi_UnlockSession (vi, VI_NULL);    return error;}/***************************************************************************** * Function: hp33120a_GenerateArbWaveform * Purpose: This function configures the attributes of the function generator *          that affect arbitrary waveform generation, enables an output *          channel, and initiates signal generation.  This *          behavior is identical to calling the *          hp33120a_ConfigureArbitraryWaveform function. *****************************************************************************/ViStatus _VI_FUNC  hp33120a_GenerateArbWaveform (ViSession vi,                         ViConstString channelName,                         ViInt32 wfmHandle,                         ViReal64 arbGain,                         ViReal64 arbOffset){    ViStatus error = VI_SUCCESS;    ViBoolean outputActive = VI_FALSE;        checkErr( Ivi_LockSession (vi, VI_NULL));        /* Call functions */    checkErr( hp33120a_ConfigureArbWaveform (vi, channelName, wfmHandle,                         arbGain, arbOffset));Error:    Ivi_UnlockSession (vi, VI_NULL);    return error;}    /***************************************************************************** * Function: hp33120a_ClearArbWaveform * Purpose:  This function removes a previously created arbitrary waveform *           from the function generator's memory and invalidates the *           waveform's handle.  If the waveform handle's values is *           HP33120A_VAL_ALL_WAVEFORMS, this function  *           removes all user-specified arbitrary waveforms from memory. *****************************************************************************/ViStatus _VI_FUNC  hp33120a_ClearArbWaveform (ViSession vi, ViInt32 wfmHandle){    ViStatus  error = VI_SUCCESS;    ViBoolean wfmExists;    ViInt32   currentHandle;    ViChar    wfmName[HP33120A_VAL_NAME_LENGTH];    checkErr( Ivi_LockSession (vi, VI_NULL));        checkErr( hp33120a_VerifyOutputMode (vi, HP33120A_VAL_OUTPUT_ARB));        if (wfmHandle != HP33120A_VAL_ALL_WAVEFORMS)    {    checkErr( hp33120a_WfmExists (vi, wfmHandle, &wfmExists));    if (!wfmExists)        viCheckErrElab( HP33120A_ERROR_INVALID_WAVEFORM,                "The waveform does not exist.");    if (wfmHandle < (HP33120A_VAL_FIRST_WAVEFORM_HANDLE + 5) && (!Ivi_Simulating(vi)))        viCheckErrElab( HP33120A_ERROR_INVALID_WAVEFORM,                "The waveform is factory-installed and cannot be cleared.");            checkErr( Ivi_GetAttributeViInt32 (vi, "1", HP33120A_ATTR_ARB_WAVEFORM_HANDLE,                        0, &currentHandle));    if (currentHandle == wfmHandle)        viCheckErrElab( HP33120A_ERROR_WFM_IN_USE,                "Cannot clear waveform because it is configured for output");            if (!Ivi_Simulating(vi))                /* call only when locked */        {        ViSession   io = Ivi_IOSession(vi); /* call only when locked */                checkErr( Ivi_SetNeedToCheckStatus (vi, VI_TRUE));        checkErr( hp33120a_GetWfmNameFromHandleUtil (vi, wfmHandle,                              HP33120A_VAL_NAME_LENGTH, wfmName));        viCheckErr( viPrintf (io, "DATA:DEL %s;", wfmName));        }    }    else    {    if (!Ivi_Simulating(vi))                /* call only when locked */        {        ViSession   io = Ivi_IOSession(vi); /* call only when locked */                checkErr( Ivi_SetNeedToCheckStatus (vi, VI_TRUE));        viCheckErr( viPrintf (io, "FUNC:USER EXP_RISE;:DATA:DEL:ALL;"));        checkErr( Ivi_InvalidateAttribute (vi, IV

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -