Multifunction DAQ

cancel
Showing results for 
Search instead for 
Did you mean: 

DAQmx with Excel 64 bit VBA

Hello,

I was using Windows 10 64 bit PC with 32 bit excel VBA7.0 and the following code works great for controlling my DAQ USb6501.

Public Sub DAQmxErrChk(errorCode As Long)
'
' Utility function to handle errors by recording the DAQmx error code
' and message.
'
Dim errorString As String
Dim bufferSize As Long
Dim status As Long
If (errorCode < 0) Then
' Find out the error message length.
bufferSize = DAQmxGetErrorString(errorCode, 0, 0)
' Allocate enough space in the string.
errorString = String$(bufferSize, 0)
' Get the actual error message.
status = DAQmxGetErrorString(errorCode, errorString, bufferSize)
' Trim it to the actual length, and display the message
errorString = Left(errorString, InStr(errorString, Chr$(0)))
Err.Raise errorCode, , errorString
End If


End Sub

Below code is used to enable all controls in my board.

Sub Enable_all()
DAQmxErrChk DAQmxCreateTask(" ", taskHandle)
DAQmxErrChk DAQmxCreateDOChan(taskHandle, "dev1/port0/line0:7", "Hulu", DAQmx_Val_ChanForAllLines)
Dim i As Integer
Dim writeArray(0 To 7) As Byte
For i = 0 To 7
' Reverse Logic
writeArray(i) = 1
Next

'writeArray(0) = 0
DAQmxErrChk DAQmxStartTask(taskHandle)


DAQmxErrChk DAQmxWriteDigitalLines(taskHandle, 1, True, 10#, DAQmx_Val_GroupByChannel, writeArray(0), sampsPerChanWritten, ByVal 0&)
DAQmxErrChk DAQmxStopTask(taskHandle)
DAQmxErrChk DAQmxClearTask(taskHandle)
End Sub

 

Now I have Windows 10  64 bit PC with  64 bit Excel and VBA7.1 (The only difference between new PC and old PC is 64 bit Excel vs 32 bit Excel) and the above code is not working. As per some internet search, changed "Long" declarations to "LongPtr" and is not helping. Please help me on this. I have DAQmx driver version21.0.

Thanks,

Leyo

0 Kudos
Message 1 of 5
(2,399 Views)

Hello,

 

we have a very similar problem.

An application which was running well on a system with Windows 10 (64-bit) and Excel 2013 (32-bit) is making trouble on a the same system, when Excel was updated to Excel for Microsoft 365 (64-bit).

We are using the DAQ USB6216. Our application uses VBA 7.1.

 

It seems like we are able to create a task with:

 

Dim lTaskhandle As Long

DAQmxErrChk DAQmxCreateTask("", lTaskhandle)

 

When debugging the code, we find that we get a value assigned to lTaskhandle.

But when we continue and (in the next command) try to create a channel with

 

DAQmxErrChk DAQmxCreateAOVoltageChan(lTaskhandle, sChannelText, "", 0, 10, DAQmx_Val_VoltageUnits2_Volts, "")

 

we get the Error Code 200088 ("Task specified is invalid or does not exist.")

 

The function DAQmxCreateTask requires a type Long variable lTaskhandle. And we also tried to work with LongPtr, but without success.

 

It seems that there is a wrong conversion of a 32-bit value to the value of our Long variable.

 

We also updated our DAQmx driver to the newest available version 21.3, but without success.

The references in VBA show the file C:\windows\SysWOW64\nidaqmx.tlb for the NI DAQmx C API. We noticed, that this file nidaqmx.tlb in the system folder was not updated since 2012.

 

Can you give advice for a workaround? Hopefully, I don't have to wait as long as LeyoJoseph in this thread for an answer to  my questions...

 

Thanks in advance!

Stefan

 

0 Kudos
Message 2 of 5
(2,259 Views)

Leider haben wir praktisch dasselbe Problem beim USB6232.

 

Excel 64bit, welches in unserem Unternehmen nun standardmäßig eingeführt werden soll, kommt bei VBA-Einsatz nicht mit der der Datei nidaqmx.tlb (Datum vom 06.02.2012) in C:\Windows\SysWOW64 (verbunden über Extras-Verweise-Liste "NI DAQmx C API") zurecht . Der taskhandle, der bei Aufruf von:

 

DAQmxErrChk DAQmxCreateTask("", lTaskhandle) 

 

von NI zurückgegeben wird (z.B. hexF338B6D0) und dann nachfolgend wieder benutzt wird:

 

DAQmxErrChk DAQmxStartTask(lTaskhandle)

 

wird mit Fehlermeldung:  "Task specified is invalid or does not exist".  abgelehnt.

 

Excel 64bit besteht darauf, dass die Variable Taskhandle as Long definiert sein muss, was auch der Hilfetext, der aus der o.g. nidaqmx.tlb kommen muss, als Schema so angibt. Ich vermute, dass das ein Pointer ist, was aber Excel-VBA egal sein könnte, wenn es ihn richtig bekommt und unverändert wieder weitergibt.

 

Im Rahmen der Verbreitung von Office365 wird Excel 64bit sicher häufig installiert und damit sollte das Problem bei vielen in Zukunft akut werden. Daher bitte ich die NI-Administratoren sich dieses Themas dringend anzunehmen.

 

 

 

 

 

 

Message 3 of 5
(2,233 Views)

Hello,

The way I fixed this issue is like this.

I wrote the control code in python.

Talk to Python from Excel using "xlwings". Use xlwings UDF option and is very fast.

0 Kudos
Message 4 of 5
(2,222 Views)

Hello Joseph

that sounds fascinating. Thank you for being able to help me. I've heard of Python, but not yet of xlwings. Since I assume that more people will get this problem in the future, it would be very grateful if you could send me more details, explanation and preferably some code for your solution.

Thank you in advance.

 

Best regards

Stefan

0 Kudos
Message 5 of 5
(2,217 Views)