Measurement Studio for VB6

cancel
Showing results for 
Search instead for 
Did you mean: 

DAQmxRegisterEveryNSamplesEvent with AI & DI in VB6

(Also posted in Multifunction daq, but this forum may be more appropriate)

I have a large software program written in VB6 that works with an E Series device and the legacy drivers.  I'm trying to upgrade the hardware to daqmx (PCI-6251).  I don't want to rewrite all the UI, so I'm trying to see if I can use the C-runtime library in VB6.  I am stuck with VB6.0 because of the massive interface, otherwise, I'd use VC++.

I'm running into a problem wtih DAQmxRegisterEveryNSamplesEvent, that sometimes events don't get called, so i went back to some sample NI code to demonstrate these issues:

I started with the example from
Continuous Analog Acquisition with NI-DAQmx Events in Visual Basic 6.0

I added code to verify that the events were being called.  It crashed.  (Version A below) I changed it to startup from sub main and it stopped crashing (Version B below), but I have no idea why....does anybody have any idea why it stopped crashing when I changed the startup object?

I added some code for a DI task, and the events only seem to get called the first time I make the task (version C below).

Ultimately, I tried to never clear the old task, so that the old threads stuck around, and a brand new thread was created each time, and that seems to work (version D below), but this is unsatisfactory becasue its a terrible waste of resources---the application needs to create new tasks often based on user input that can have completely different sampling rates, etc and channels to sample....

Does anybody know what's going on with versions A & versions C--if I'm not doing something correctly?

Thanks in advance for your help,
Steve

summary:
I started with the example at
NI-DAQmx: Continuous Analog Acquisition with NI-DAQmx Events in Visual Basic 6.0

Versions of software attached:
A)modified to count the number of times each event gets triggered--crashes
B)modified to startup from "subMain"--miracolously stops the crashing
C)added new digital acquisition task--events not executed when the task is called a second time
D)modified so that old tasks are never cleared--events are always executed, but threads & resources build up
0 Kudos
Message 1 of 7
(7,653 Views)
I didn't attach the code in the last email.
 
Steve
0 Kudos
Message 2 of 7
(7,639 Views)
Hi Steve,
 
I'll take a look at the code and the post back.
 
Ed W.
 
0 Kudos
Message 3 of 7
(7,617 Views)
Hi Ed,

Thanks for looking into it.

Steve
0 Kudos
Message 4 of 7
(7,603 Views)

Hi Steve,

 

I’ve started looking into the code, and I wanted to give you an update about these crashes. 

 

So far, I was able to verify the behavior that you’re seeing, but I’ve only found a workaround for version A of your code. 

 

The source of the problem with version A is the extra form that you’re creating and updating.  I tried removing the code that updates that form, and the program doesn’t crash anymore.  Then, I added code to show the number of events on the MainForm, and this displayed fine, again, with no crashes. 

 

I’ve attached the code below.  I’ll be looking into the other versions in the near future.  Thank you for your patience.

 

Ed W.

Applications Engineer

National Instruments

0 Kudos
Message 5 of 7
(7,591 Views)
Hi Ed,

That's an interesting workaround.  I like that better than mine.  I wonder if the crashing has anything to do with the options (eg DAQmx_Val_SynchronousEventCallbacks) parameter of DAQmxRegisterDoneEvent...if there's something strange going on with threads.

Thanks for looking into it.

Steve
0 Kudos
Message 6 of 7
(7,589 Views)
Hi Steve,

It may be that the separate threads aren't handled very well, like you said.  But the source of these crashes (at least in version A) is definitely due to the idiosyncrasies of Visual Basic 6.0, not DAQmx.

Ed W.
Applications Engineer
National Instruments
0 Kudos
Message 7 of 7
(7,567 Views)