Ok, solved.
Just a skeleton, here we go:
Dim sampsPerChanWritten As Long
Dim test As Long
Dim taskHandle As Long
Dim delay As Double
'OBS Long, fel i exempel
Dim status As Long
Public Sub DAQmxErrChk(errorCode As Long)
' Utility function to handle errors by recording the DAQmx error code
' and message. This sub, (c) NI
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
Private Sub Configure_Port_Click()
Dim numChannels As Long
Dim errorCode As Long
Dim errorString As String
DAQmxErrChk DAQmxCreateTask("", taskHandle)
DAQmxErrChk DAQmxCreateAOVoltageChan(taskHandle, "Dev1/ao0", "aoChannel", -10, 10, DAQmx_Val_VoltageUnits2_Volts, "")
DAQmxErrChk DAQmxGetTaskNumChans(taskHandle, numChannels)
If numChannels > 1 Then
errorCode = -1
errorString = "Please spec. only one channel."
Err.Raise errorCode, , errorString
End If
End Sub
Private Sub Stop_Task_Click()
DAQmxErrChk DAQmxStopTask(taskHandle)
DAQmxErrChk DAQmxClearTask(taskHandle)
End Sub
Private Sub Write_Logic_0_Click()
'Set the DA to -4V. The # is equiv to cdbl(-4)
DAQmxErrChk DAQmxWriteAnalogScalarF64(taskHandle, True, 10#, -4#, ByVal 0&)
End Sub
Private Sub Write_Logic_1_Click()
'Set it to +7.
DAQmxErrChk DAQmxWriteAnalogScalarF64(taskHandle, True, 10#, 7#, ByVal 0&)
End Sub