Measurement Studio for VB6

cancel
Showing results for 
Search instead for 
Did you mean: 

DAQmxWriteDigitalLines - Single Channel

I have been using the following code to write digital out to an NI board to switch relays.
 
'******************************************************************************
Dim writeArray() As Byte
Dim arraySizeInBytes as Long
 
    arraySizeInBytes = 8
    ReDim writeArray(arraySizeInBytes)
    For i = 0 To arraySizeInBytes - 1 :     writeArray(i) = 0 :   Next
    
 
Private Sub OpenValveChannel(ByVal channo As Integer)
Dim sampsPerChanWritten As Long
Dim taskHandle As Long
    DeviceAddr = "Dev1/port0/line0:7"
    writeArray(channo) = 1
    DAQmxErrChk DAQmxCreateTask("", taskHandle)
    DAQmxErrChk DAQmxCreateDOChan(taskHandle, DeviceAddr, "", DAQmx_Val_ChanForAllLines)
    DAQmxErrChk DAQmxStartTask(taskHandle)
    DAQmxErrChk DAQmxWriteDigitalLines(taskHandle, 1, True, 10#, DAQmx_Val_GroupByChannel, writeArray(0), sampsPerChanWritten, ByVal 0&)
    DAQmxErrChk DAQmxStopTask(taskHandle)
    DAQmxErrChk DAQmxClearTask(taskHandle)
 
I have realised that I should be only setting one channel not 0-7.... how exactly would I do this..
 
for example.. is this correct ?
 
Private Sub OpenValveChannel(ByVal channo As Integer)
Dim sampsPerChanWritten As Long
Dim taskHandle As Long
    DeviceAddr = "Dev1/port0/line0"
    DAQmxErrChk DAQmxCreateTask("", taskHandle)
    DAQmxErrChk DAQmxCreateDOChan(taskHandle, DeviceAddr, "", DAQmx_Val_ChanPerLine)
    DAQmxErrChk DAQmxStartTask(taskHandle)
    DAQmxErrChk DAQmxWriteDigitalLines(taskHandle, 1, True, 10#, DAQmx_Val_GroupByChannel, 1, sampsPerChanWritten, ByVal 0&)
    DAQmxErrChk DAQmxStopTask(taskHandle)
    DAQmxErrChk DAQmxClearTask(taskHandle)
 
Thanks
0 Kudos
Message 1 of 3
(10,799 Views)

Hi,

Yes you've got the right idea, take a look at the C Reference for DAQmx to show you the various correct methods, and parameters to pass to them, this is installed with DAQmx and can be found from the Start menu, from 'All Programs>>National Instruments>>NI-DAQ>>NI-DAQmx C Reference Help'

I've attached a VB 6.0 example program which should do what you need, if you have any questions, let me know

Regards

Hannah
NIUK & Ireland

0 Kudos
Message 2 of 3
(10,777 Views)
Thanks for that. I'm not sure that is quite what I want but it could be..

We have 8 relays attached to the 8 lines.

When I used the port0/line0:7 address I would setup a global array of 8 bytes and then to turn line 3 on..

    DeviceAddr = "Dev1/port0/line0:7"
    writeArray(3) = 1
    ..CreateTask
    ..CreateDOChan
    ..StartTask
     DAQmxWriteDigitalLines(taskHandle, 1, True, 10#,
                            DAQmx_Val_GroupByChannel, writeArray(0),
                            sampsPerChanWritten, ByVal 0&)

This would mean the global array WriteArray would be '0001000'

If I then wanted to turn on chan4..

    DeviceAddr = "Dev1/port0/line0:7"
    writeArray(4) = 1
    ..CreateTask
    ..CreateDOChan
    ..StartTask
     DAQmxWriteDigitalLines(taskHandle, 1, True, 10#,
                            DAQmx_Val_GroupByChannel, writeArray(0),
                            sampsPerChanWritten, ByVal 0&)


This would mean the global array WriteArray would now be '0001100'

This is what causes the problem as it tries to turn on valve 3 which is already turned on...



Are you saying that when you use your technique the digout function would be as follows..

Turn on line 3

    Redim i(8)
    i(3)=1

      DAQmxErrChk DAQmxWriteDigitalLines(taskHandle, 1, True, 10#,
            DAQmx_Val_GroupByChannel, i(3),
            sampsPerChanWritten, ByVal 0&



Turn on line 4

    Redim i(8)
    i(4)=1

      DAQmxErrChk DAQmxWriteDigitalLines(taskHandle, 1, True, 10#,
            DAQmx_Val_GroupByChannel, i(4),
            sampsPerChanWritten, ByVal 0&


Would the second write routine not turn 'OFF' line 3 ?

Regards

Peter

0 Kudos
Message 3 of 3
(10,775 Views)