Measurement Studio for VB6

cancel
Showing results for 
Search instead for 
Did you mean: 

Starting/Stopping tasks in VB6 using Daqmx

I am using VB6 with the NI-DAQmx reference and a compactDAQ module with the following modules:
9205 Analog in
9205 Analog in
9263 Analog out
9481 Relay out
In the examples, they usually start the task, read the data, then stop the task. If I want to constantly read all of the analog channels (every iteration of my while loop), and I want to send a digital output (to turn relays on/off) as needed, what is the best way to handle starting and stopping tasks? Do I have to create a task each time I read the analog or each time I want to set one relay on or off?

Do I create a different task for every operation?

My current system uses a plug in data logging card that simply requires a call to a DLL to read channel X, another call to a DLL to turn on a relay bit, etc... I'm converting over to this compactDAQ and I'm hoping there is some easy "drop in" code to replace what I do now.
 
Any help is greatly appreciated.
0 Kudos
Message 1 of 2
(7,032 Views)
Hi,

It is actually recommended not to start and stop tasks inside your loop.  The opening and closing of tasks is only opening the communication to your device.  Once you have done that you can write/read (based on what kind of task it is), as many times as you want. 

So, in your while loop you do not need to start and stop your task.  You can set up your task to be continuous.  You can do this in the configuration using the DAQmxCfgSampClkTiming (TaskHandle taskHandle, const char source[], float64 rate, int32 activeEdge, int32 sampleMode, uInt64 sampsPerChanToAcquire); function.

The sampleMode parameter can be set to DAQmx_Val_ContSamps for continuous sampling.  In this mode, you can acquire or generate samples inside your loop till you stop the task.

You can find more information on all the different DAQmx functions by selecting Start >> Programs >> National Instruments >> NI-DAQ >> NI-DAQmx C Reference Help.  Most of these C functions are similar to what are used in VB6 as well.

If you are looking for examples you can actually refer to the ANSI C examples that will be installed with DAQmx.  They are very similar to programming in VB6.  Please look at this knowledge base article for more help on this.

NI-DAQmx Support in Visual Basic 6.0
NI-DAQmx Examples for Visual Basic 6.0

You will have to create seperate tasks for different operations.  For example, you will have one task for analog input and one task for digital IO.

Hope all of this helps.

Regards,
Raajit L
National Instruments
0 Kudos
Message 2 of 2
(7,015 Views)