Thanks Jeff,
I tried your code in C and it worked as you said. First time around, no problems. I'm calling these functions with VBA (from within Excel,) and for some reason first time round I still get an error. It's curious, and I don't understand it. The problem is runtime error 6, "overflow." Interestingly enough if I step through the code, and pause for a second or so between making the channel and calling the write lines function I don't have a problem. I really dont understand since the C program works well. I've included the class I used to control the lines below, any ideas?
Best Regards,
Daniel
Option Explicit
Private m_sampsPerChanWritten As Long
Private m_TaskHandle As Long
Private m_writeArray(0 To 3) As Byte
Private m_bytesPerWriteDigitalLines As Long
Private Const c_digitalLineHIGH As Long = 1
Private Const c_digitalLineLOW As Long = 0
Private Const c_terminalAddress As String = "Dev1/port0/line0:1"
Private Sub Class_Initialize()
' Create the DAQmx task.
DAQmxErrChk DAQmxCreateTask("", m_TaskHandle)
' Add a digital output channel to the task.
DAQmxErrChk DAQmxCreateDOChan(m_TaskHandle, c_terminalAddress, "", DAQmx_Val_ChanForAllLines)
'Check the number of bytes per channel
DAQmxErrChk DAQmxGetWriteDigitalLinesBytesPerChan(m_TaskHandle, m_bytesPerWriteDigitalLines)
If m_bytesPerWriteDigitalLines <> 2 Then
MsgBox ("Error. Expecting 2 bytes per channel.")
End If
'Verify the task
'DAQmxErrChk DAQmxTaskControl(m_taskHandle, DAQmx_Val_Task_Verify)
'Reserve and Commit the resources for the task
'DAQmxErrChk DAQmxTaskControl(m_taskHandle, DAQmx_Val_Task_Commit)
'Start the task
DAQmxErrChk DAQmxStartTask(m_TaskHandle)
End Sub
Private Sub Class_Terminate()
'stop the task
DAQmxErrChk DAQmxStopTask(m_TaskHandle)
' terminate the task
DAQmxErrChk DAQmxClearTask(m_TaskHandle)
End Sub
Public Sub Inflate()
m_writeArray(0) = c_digitalLineLOW
m_writeArray(1) = c_digitalLineHIGH
'write the array to the digital lines
DAQmxErrChk DAQmxWriteDigitalLines(m_TaskHandle, 1, 1, -1#, DAQmx_Val_GroupByChannel, m_writeArray(0), m_sampsPerChanWritten, 0)
End Sub
Public Sub Deflate()
m_writeArray(0) = c_digitalLineHIGH
m_writeArray(1) = c_digitalLineLOW
'write the array to the digital lines
DAQmxErrChk DAQmxWriteDigitalLines(m_TaskHandle, 1, 1, -1#, DAQmx_Val_GroupByChannel, m_writeArray(0), m_sampsPerChanWritten, 0)
End Sub
Public Sub StopAir()
m_writeArray(0) = c_digitalLineLOW
m_writeArray(1) = c_digitalLineLOW
'write the array to the digital lines
DAQmxErrChk DAQmxWriteDigitalLines(m_TaskHandle, 1, 1, -1#, DAQmx_Val_GroupByChannel, m_writeArray(0), m_sampsPerChanWritten, 0)
End Sub