Measurement Studio for VB6

cancel
Showing results for 
Search instead for 
Did you mean: 

how to unrigister the call back function,in vb6 with DAQmx 8.5

I use daqmx api which named DAQmxRegisterEveryNSamplesEvent to register my call back function,When I invoke the function  DAQmxErrChk (DAQmxStopTask(taskHandleAnalog)) to stop my Task.then i call the procedure AD_OPEN  again,it raise an error ,tell me that i need to unregister the event,the data has transfer into the buffer.how can i unregister the event,please look at the following code.

Spoiler
 

 

Private Sub create()

 

   Dim channel As String
    Dim minVoltage, maxVoltage As Double
    Dim samplesPerChannelPerRead As Double
    Dim sampleMode As Long
    Dim boolVal As Boolean
    On Error GoTo AdErrorHandler:
    ' Get values from UI controls
    channel = "Dev2/ai1:2"
    minVoltage = -10
    maxVoltage = 10
    samplesPerChannelPerRead = 100
     If (taskHandleAnalog <> 0) Then
         DAQmxErrChk (DAQmxStopTask(taskHandleAnalog))
        DAQmxErrChk (DAQmxClearTask(taskHandleAnalog))
        taskhandle = 0
    End If
    ' Configure the task
    DAQmxErrChk (DAQmxCreateTask("", taskHandleAnalog))
     DAQmxErrChk (DAQmxCreateAIVoltageChan(taskHandleAnalog, "Dev2/ai0", "", DAQmx_Val_InputTermCfg_RSE, minVoltage, maxVoltage, DAQmx_Val_VoltageUnits2_Volts, vbNullString))

    DAQmxErrChk (DAQmxCreateAIVoltageChan(taskHandleAnalog, channel, "", DAQmx_Val_InputTermCfg_Diff, minVoltage, maxVoltage, DAQmx_Val_VoltageUnits2_Volts, vbNullString))

End Sub

 

Private Sub AD_Open()

    DAQmxErrChk (DAQmxCfgSampClkTiming(taskHandleAnalog, "", 200, DAQmx_Val_Rising, DAQmx_Val_AcquisitionType_ContSamps, samplesPerChannelPerRead))
    'Find number of samples specified
    DAQmxErrChk (DAQmxGetTaskNumChans(taskHandleAnalog, numChannels))
    'Configure Event Callbacks
    DAQmxErrChk (DAQmxRegisterEveryNSamplesEvent(taskHandleAnalog, 1, 4, 0, AddressOf EveryNSamplesEventHandler1, Nothing))

 ReDim dataBuffer(numChannels * samplesPerChannelPerRead - 1)
    ' Start the DAQmx Task
'    DAQmxErrChk (DAQmxCfgDigEdgeStartTrig(taskHandleAnalog, "/Dev1/PFI2", DAQmx_Val_Edge1_Falling))
    DAQmxErrChk (DAQmxStartTask(taskHandleAnalog))
    ' Update UI
    Exit Sub
AdErrorHandler:
    MsgBox Err.Description
End Sub

0 Kudos
Message 1 of 2
(6,186 Views)

This may be a bit late, so hopefully you found this on your own. But in order to unregister the event pass a null value for the callback function parameter in the DAQmxRegisterEveryNSamplesEvent function (Nothing in VB).

National Instruments
0 Kudos
Message 2 of 2
(6,160 Views)