05-11-2018 09:43 AM
I'm new here and need some help please. I am using Excel VBA and NI USB-6008 to read in some analog voltages. I have been through the VB6 examples and have come across the example using Excel for digital IO. Can't seem to get my code to work and I'm sure it's to my lack of understanding the syntax.
I tried DAQmxReadAnalogScalarF64 and DAQmxReadAnalogF64, with adjusting things in the config_port_click() sub.
Not sure if it is configuration or in the read subs. Thank you in advance for any help.
Dim taskHandle0 As Long
Dim Status0 As Double
Dim data(0) As Double
Sub Configure_Port_Click()
Status0 = DAQmxCreateTask("", taskHandle0)
Status0 = DAQmxCreateAIVoltageChan(taskHandle0, "Dev1/ai0:7", "", _
DAQmx_Val_InputTermCfg_RSE, 0, 10, _
DAQmx_Val_VoltageUnits2_Volts, "")
Status0 = DAQmxCfgSampClkTiming(taskHandle0, "OnboardClock", 50, DAQmx_Val_Rising, _
DAQmx_Val_AcquisitionType_ContSamps, 50)
Status0 = DAQmxStartTask(taskHandle0)
End Sub
Private Sub Image1_Click()
Stat0 = DAQmxReadAnalogF64(taskHandle0, 1000, 10#, _
DAQmx_Val_GroupByChannel, data(0), 8, 10, ByVal 0&)
'Status0 = DAQmxReadAnalogScalarF64(taskHandle0, 10#, data(0), ByVal 0&)
Range(Cells(3, 1).Address) = data(0)
End Sub
Sub Stop_Task_Click()
Status0 = DAQmxStopTask(taskHandle0)
Status0 = DAQmxClearTask(taskHandle0)
05-14-2018 10:51 AM
There is an example for using VBA with digital lines:
http://www.ni.com/example/25305/en/
But overall NI does not support VBA programming. I would recommend using a different software to take your data (I.e. LabVIEW, Visual Studio, LabWindows/CVI, etc.) and then exporting it to excel.
05-14-2018 12:34 PM
Thank you for your input Dane,
The example shows DIO, and from it I figured out how to use the Analog Out from Excel. I was hoping to do the same for Analog Input. Your point is well taken regarding NI not supporting VB and your recommendations to use LabView. I still would enjoy either figuring this out or having my error/s pointed out so it could be a learning experience for me.
Love LabView and NI products.