Measurement Studio for VB6

cancel
Showing results for 
Search instead for 
Did you mean: 

How to call NI-DAQmx functions from Visual Basic 6?

I have a VB6 application which needs to interface to new NI hardware, e.g. PCI-6515. However the NI hardware is ONLY supported with the new NI-DAQmx driver.
0 Kudos
Message 1 of 9
(10,855 Views)
To my knowledge this is not directly supported by NI-DAQmx. That said, there's a potential workaround. You should be able to call into the C API by creating some "Declare" declarations for the functions in DAQmx much like you would if you were calling into the Windows API. If you know details about which functions you are going use, post them and I may be able to help with this conversion.
Message 2 of 9
(10,852 Views)
I'm pursuing exactly what you suggested and so far so good. I obtained some C to VB6 conversions elsewhere and I'm questioning the correctness (byVal vs. byRef) for some of the parameters.

For this application I will only need to read/write digital channels, bit by bit. The attached file has both C and VB6 procedure definitions needed for this application. Any feedback you have would be greatly appreciated. Thanks in advance...
0 Kudos
Message 3 of 9
(10,853 Views)
These look pretty close to me. I haven't run the code but it looks like you are on the right track. Be sure that when you pass your arrays to the read/write functions that you pass the first element of the array. In essence what you are doing is causing VB to pass a pointer to the first element of the array which emulates the way that you pass arrays in C. Good luck!
0 Kudos
Message 4 of 9
(10,852 Views)
Hello Ksholly,

I am in a similiar boat. I have purchased ( without checking out details first - foolishly) PCI - 6229 and am stuck to complete the project with VB6.

I want to do the following with NiDAQmx :

1. Acquire the data from 6 analog channels and store the result in a VB array @ 100 smaples / sec.

2. Acquire the status of 27 digital inputs and save the status in a image buffer for use by differnt parts of program.

3. Control the state of 8 digital outputs programatically based on the states of digital and analog inputs.

4. Control two analog outputs programmatically.

Actually to do the above with VB6 and traditional Ni-DAQ was a breeze. And I am sure it must be even more easy with LabView - but I am new to LV and have just got the full development system. No time for the learning curve.

I am quite desparate to get support on the API declarations for the above jobs.

Thanks for your help.

Regards

Raghunathan
Raghunathan
LabVIEW to Automate Hydraulic Test rigs.
0 Kudos
Message 5 of 9
(10,771 Views)
Hello

To get started, I would recommend going thru the DAQmx C examples that are installed as part of the driver. You can find them under ..\NI-DAQ\Examples\DAQmx ANSI C. Once you have an idea of the functions you would need to call, check out this post here to see how to setup the API calls. The functions reference manual for the DAQmx API will provide more information about the functions.

Hope this helps
Bilal Durrani
NI
0 Kudos
Message 6 of 9
(10,763 Views)
Hello Mr Bilal,

Thanks for your posting and the link where I could get all the written declarations of the NI-DAQmx for use in VB6.0. Actually writing the declarations based on the C-Functions is something which I had completed and the reference served to confirm the approach. Fine upto this and I have succeeded in using the following functions within VB :

DAQmxStartTask, DAQmxStopTask, DAQmxClearTask, DAQmxCreateTask, DAQmxCreateDIChan. All these return a "0" Status and thus are executing fine.

But I am tripped by the following functions :

DAQmxReadDigitalLines, DAQmxReadAnalogF64, DAQmxWriteDigitalScalarU32.

Actaully in all of the above there is one argument which is of type bool32 pointer called Reserved. I do not know what to provide for this argument - I have tried VBNull and "0". In all cases I get an error of -200492.

Understandably ( or so I believe) I am just one step short of the final solution and would like help on what to provide in place where the function expects a pointer.

Thanks

Raghunathan
Raghunathan
LabVIEW to Automate Hydraulic Test rigs.
0 Kudos
Message 7 of 9
(10,757 Views)
Change the declaration of the last parameter to ByVal instead of ByRef


int32 DAQmxReadDigitalLines (TaskHandle taskHandle, int32 numSampsPerChan, float64 timeout, bool32 fillMode, uInt8 readArray[], uInt32 arraySizeInBytes, int32 *sampsPerChanRead, int32 *numBytesPerSamp, bool32 *reserved);
Public Declare Function DAQmxReadDigitalLines Lib "nicaiu.dll" (ByVal taskHandle As Long, ByVal numSampsPerChan As Long, ByVal timeout As Double, ByVal fillmode As Long, ByRef readArray As Byte, ByVal arraySizeInBytes As Long, ByRef SampsPerChanRead As Long, ByRef numBytesPerSamp As Long, ByVal reserved As Long) As Long

And then you should be able to pass it 0&

See this MSDN article for more information.

Hope this helps
Bilal Durrani
NI
0 Kudos
Message 8 of 9
(10,752 Views)
NI-DAQmx support for Visual Basic 6.0 has improved with the release of NI-DAQmx 7.4. Please refer to KB: 39BF3M1E for more information.
0 Kudos
Message 9 of 9
(9,910 Views)