Multifunction DAQ

cancel
Showing results for 
Search instead for 
Did you mean: 

DAQmxRegisterDoneEvent

I am using the RIO-9215 with DAQmx and VB6.  I am attempting to digitize a second of data and would like to use DAQmxRegisterDoneEvent to catch the end of the digitizing process.  I am using the code below.  The code works with no errors when the comment is removed from the call to my DAQDone sub which contains .  But when it is in place the event sub never fires and DAQDone is never called.  All of this code is in a single .BAS module.
 
Anyone have an idea what I am doing wrong?
 
Sub DAQStart() 
    Dim n As Integer
    Dim NumChannels As Long
    Dim ChanNumberString As String
   
    'Create the DAQmx task.
    DAQmxErrChk DAQmxCreateTask("", TaskHandle)
    ChanNumberString = ""
    For n = 0 To DAQChnl - 1
        ChanNumberString = ChanNumberString & "Dev1/AI" & DAQMsg(1, n) & ","
    Next n
    ChanNumberString = left(ChanNumberString, Len(ChanNumberString) - 1)
    If KillIt Then Exit Sub
   
    'Add analog input channels to the task.
    DAQmxErrChk DAQmxCreateAIVoltageChan(TaskHandle, ChanNumberString, "", _
                DAQmx_Val_Cfg_Default, -10, 10, _
                DAQmx_Val_VoltageUnits1_Volts, "")
   
    'Configure task for sample acquisition and read in data
    'int32 DAQmxCfgSampClkTiming (TaskHandle, const char source[], float64 SampleRate, int32 activeEdge,
    '       int32 sampleMode, uInt64 sampsPerChanToAcquire);
    DAQmxErrChk DAQmxCfgSampClkTiming(TaskHandle, "OnboardClock", DAQSampleRate, DAQmx_Val_Rising, _
                DAQmx_Val_AcquisitionType_FiniteSamps, DAQSamples)
               
    DAQmxErrChk DAQmxGetTaskNumChans(TaskHandle, NumChannels)
    DAQArraySize = DAQSamples * NumChannels
    ReDim Data(DAQArraySize)
   
    DAQmxErrChk DAQmxRegisterDoneEvent(TaskHandle, 0, AddressOf DAQmxEvent, Null)
   
    DAQmxErrChk DAQmxStartTask(TaskHandle)
    'DAQDone
End Sub
 
Public Function DAQmxEvent(TaskHandle As Long, Status As Long, Data As Long) As Long  '#ErrLinesDone#
    Stop
    DAQDone
End Function
 
Public Sub DAQDone() 
    Dim VoltBuf() As Double
    ReDim VoltBuf(DAQArraySize)
   
    'Get the data from DAQ
    DAQmxErrChk DAQmxReadAnalogF64(TaskHandle, DAQmx_Val_Auto, 10#, _
                DAQmx_Val_GroupByScanNumber, VoltBuf(0), DAQArraySize, DAQSamples, ByVal 0&)
    'Task is done so clear it.
    DAQmxErrChk DAQmxClearTask(TaskHandle)
    'Format data into the DAQData(Chnl, Sample) array.
    '... more stuff here
   
    'Clear unused array.
    Erase VoltBuf
End Sub
0 Kudos
Message 1 of 3
(2,981 Views)

Hello Peek,

The problem may be with the way you are setting up the DAQmxEvent callback function.  The NI-DAQmx C Reference Help says that the callback function you pass as a parameter to DAQmxRegisterDoneEvent must have the following form:

int32 CVICALLBACK Callback (TaskHandle taskHandle, int32 status, void *callbackData);

Admittedly, I'm not super familiar with VB6 syntax, but it looks like your callback function takes in a long instead of a pointer for that third parameter.  This may be why it isn't getting called correctly.

Thanks,

Justin M.
National Instruments

0 Kudos
Message 2 of 3
(2,944 Views)

Hi again Peek,

I found a VB6 example on our website that is very similar to what you are trying to do.  Take a look at the following:

NI-DAQmx: Continuous Analog Acquisition with NI-DAQmx Events in Visual Basic 6.0

I hope this helps!

Thanks,

Justin M.
National Instruments

0 Kudos
Message 3 of 3
(2,924 Views)