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.
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