Measurement Studio for VB6

cancel
Showing results for 
Search instead for 
Did you mean: 

Using Declare statements instead of the NIDAQmx Type Library

I originally wrote my ActiveX control using the NIDAQmx type library supplied, and it worked well. However I found that it tries to pull in the nicaui.dll library (and that then depends on a host of other libraries) or it will not install.
I need to install my application not only on systems with NIDAQmx installed, but also on systems with  only traditional NIDAQ installed, and others with no NIDAQ at all installed on them.
There may be a way to do this using the typelib, but I don't know what it is, and I ended up replacing all the  NIDAQmx calls with  Declare statements. I couldn't find these documented  anywhere, and it took some trial and error to get the parameter types working correctly, especially the 64-bit integer stuff!

Anyway I have it all working now, and on startup my application will check to see if NIDAQmx is installed and use it if it is, if not it will fall back to trying the traditional NIDAQ, and if that fails it uses its other input methods.

My questions are:

1. Is there a way to do this while still having the safety of a typelib, or does early-binding preclude this?
2. If Declare statements are required, are they documented  somewhere to save all the trial-and-error I had to go through?

Thanks

David
 
 
0 Kudos
Message 1 of 7
(10,332 Views)
David,

Impressive work! Smiley HappyUnfortunately, I don't think you will be able to do what you originally wanted to. I think that the ActiveX installer requires the presence of dlls which are early bound... though you may want to dig around MSDN for more info on this.

I do have one suggestion, however. Perhaps you could build a dll (using the type library) which performs all of your DAQmx functions. You could then dynamically call this dll (or not) from your ActiveX control, depending on whether or not you detect that the DAQmx driver is installed. In order to make your code more modular, you could even do this for each driver you plan to access. Does this sound like a viable option?

Ryan Verret
Product Marketing Engineer
Signal Generators
National Instruments
0 Kudos
Message 2 of 7
(10,313 Views)

I've hit the same problem that David did - has NI published anywhere the equivalent Declare statements or do I, like David, have to figure them out by trial and error?

 

For apps that support multiple hardware devices, including traditional and mx based systems, being able to use Declare statements is important.

 

Thanks,


Van

0 Kudos
Message 3 of 7
(9,299 Views)

G'Day Van,

 

I don't know whether NI has done anything about the declarations, but here are the ones I put together, to save you the trouble of rediscovering them!

 

Cheers,

 

David

 

Declare Function DAQmxReadDigitalScalarU32 Lib "nicaiu.dll" (ByVal taskHandle As Long, ByVal timeout As Double, ByRef Value As Long, ByRef reserved As Any) As Long
Declare Function DAQmxWriteDigitalScalarU32 Lib "nicaiu.dll" (ByVal taskHandle As Long, ByVal AutoStart As Boolean, ByVal timeout As Double, ByVal Value As Long, ByRef reserved As Any) As Long

Declare Function DAQmxAddGlobalChansToTask Lib "nicaiu.dll" (ByVal taskHandle As Long, ByVal ChannelNames As String) As Long
Declare Function DAQmxGetTaskNumChans Lib "nicaiu.dll" (ByVal taskHandle As Long, ByRef data As Long) As Long

'Declare Function DAQmxCfgSampClkTiming Lib "nicaiu.dll" (ByVal taskHandle As Long, ByVal source As String, ByVal rate As Double, ByVal activeEdge As Long, ByVal samplemode As Long, ByVal sampsperchan As Currency) As Long
Declare Function DAQmxCfgSampClkTiming_VB6 Lib "nicaiu.dll" (ByVal taskHandle As Long, ByVal source As String, ByVal rate As Double, ByVal activeEdge As Long, ByVal samplemode As Long, ByVal sampsperchan As Long) As Long

Declare Function DAQmxCfgInputBuffer Lib "nicaiu.dll" (ByVal taskHandle As Long, ByVal arraySizeInSamps As Long) As Long

'Declare Function DAQmxRegisterEveryNSamplesEvent Lib "nicaiu.dll" (ByVal taskHandle As Long, ByVal everyNSamplesEventType As Long, ByVal nSamples As Long, ByVal options As Long, ByVal callbackfunction As Long, ByVal callbackdata As Any) As Long
Declare Function DAQmxRegisterEveryNSamplesEvent_VB6 Lib "nicaiu.dll" (ByVal taskHandle As Long, ByVal everyNSamplesEventType As Long, ByVal nSamples As Long, ByVal options As Long, ByVal callbackfunction As Long, ByRef callbackdata As Long) As Long

Declare Function DAQmxGetTaskDevices Lib "nicaiu.dll" (ByVal taskHandle As Long, ByVal data As String, ByVal buffersize As Long) As Long
Declare Function DAQmxGetDevIsSimulated Lib "nicaiu.dll" (ByVal device As String, ByRef data As Boolean) As Long
Declare Function DAQmxCreateTask Lib "nicaiu.dll" (ByVal taskname As String, ByRef taskHandle As Long) As Long
Declare Function DAQmxStartTask Lib "nicaiu.dll" (ByVal taskHandle As Long) As Long
Declare Function DAQmxStopTask Lib "nicaiu.dll" (ByVal taskHandle As Long) As Long
Declare Function DAQmxClearTask Lib "nicaiu.dll" (ByVal taskHandle As Long) As Long
Declare Function DAQmxGetErrorString Lib "nicaiu.dll" (ByVal errorCode As Long, ByVal errorString As String, ByVal buffersize As Long) As Long

Declare Function DAQmxCreateDIChan Lib "nicaiu.dll" (ByVal taskHandle As Long, ByVal lines As String, ByVal name As String, ByVal linegrouping As Long) As Long
Declare Function DAQmxCreateDOChan Lib "nicaiu.dll" (ByVal taskHandle As Long, ByVal lines As String, ByVal name As String, ByVal linegrouping As Long) As Long
Declare Function DAQmxReadAnalogF64 Lib "nicaiu.dll" (ByVal taskHandle As Long, ByVal numSampsPerChan As Long, ByVal timeout As Double, ByVal fillmode As Long, ByRef readArray As Double, ByVal arraySizeInSamps As Long, ByRef sampsPerChanRead As Long, ByRef reserved As Any) As Long

Declare Function DAQmxGetSysNIDAQMajorVersion Lib "nicaiu.dll" (ByRef data As Long) As Long

 

Message 4 of 7
(9,291 Views)
Thanks David, this has most of what I need!  Still, would have been nice if NI could save us a little time and just publish a list.  OTOH, that would be a pretty long list if they did every function.  
0 Kudos
Message 5 of 7
(9,287 Views)

Indeed great work, but I'm missing the DAQmxWriteAnalogF64 declaration here. I'd figured it should be done like:

 

Declare Function DAQmxWriteAnalogF64 Lib "nicaiu.dll" (ByVal taskHandle As Long, ByVal numSampsPerChan As Long, ByVal autoStart As Boolean, ByVal timeout As Double, ByVal dataLayout As Boolean, ByRef writeArray As Double, ByRef sampsPerChanWritten As Long, ByVal reserved As Any) As Long

 

but when I call this function by using

 

DAQmx_ErrChk DAQmxWriteAnalogF64(taskhandle, 1000&, True, 10.0#, DAQmx_Val_GroupByScanNumber, writeArray(0), sampsPerChanWritten, byVal 0&)

 

my system crashes. So what went wrong? 

 

Regards,

 

Charlie

0 Kudos
Message 6 of 7
(9,097 Views)

I've hit another snag in trying to avoid the problems Dave outlined early (need to support users who use Trad NIDAQ and do not have NIDAQmx installed for a start, and even users who have no NIDAQ at all) - I've run into a function that I cannot determine the correct Declare statement for.

 

DAQmxCfgDigEdgeStartTrig has a definition in the c library as:

   int32 DAQmxCfgDigEdgeStartTrig (TaskHandle taskHandle, const char triggerSource[], int32 triggerEdge);

So, it would seem that the VB6 declare statements would look like this:

   Private Declare Function DAQmxCfgDigEdgeStartTrig Lib "nicaiu.dll" (ByVal taskHandle&, ByVal trigsource$, _
                        ByVal trigEdge As Long)

However, this gives me a VB "Bad DLL calling convention error" when I execute it in code, with what I believe are valid parameters.

 

If anyone else has successfully used this function in VB6, please let me know what the trick is!

 

Thanks,

 

Van

0 Kudos
Message 7 of 7
(8,264 Views)