Multifunction DAQ

cancel
Showing results for 
Search instead for 
Did you mean: 

Open-Drain Configuraiton for USB-6000 with Python

I'm using the USB-6000 and have been able to control the digital output port.  The default digital output configuration is push-pull.  How can I configure the digital output port to open-drain?  Here's the code I have that works fine for push-pull output:

 

import nidaqmx
import time

with nidaqmx.Task() as task:
    task.do_channels.add_do_chan("Dev2/port0/line0:3")
    task.write(3)    # Set port 0 lines 0 & 1 to logic high
    time.sleep(5)
    task.write(2)    # Set only line 1 to logic high
    time.sleep(5)
    task.write(0)    # Set all lines low

0 Kudos
Message 1 of 8
(1,596 Views)

Hi bobuuu,

 

The property you're looking for is do_output_drive_type.

 

This is a property of the channel object, and allows you to set each channel to either active-drive (the default) or open collector.


Thanks,

 

Michael B.
Product Support Engineer
National Instruments
0 Kudos
Message 2 of 8
(1,572 Views)

Michael, thanks for identifying the do_output_drive_type property.  The next thing I need is the line of Python code that uses this property.  I've tried many combinations of what I think should work with no luck.  Can you reply with this line of code to add to my example Python program?

0 Kudos
Message 3 of 8
(1,553 Views)

The property should just be an attribute of the do_channel object you create, so the line would be something like "do_channel.do_output_drive_type = DigitalDriveType.OPEN_COLLECTOR".  The DigitalDriveType class is part of the nidaqmx constants: https://nidaqmx-python.readthedocs.io/en/latest/constants.html

 

Thanks,

Michael B.
Product Support Engineer
National Instruments
0 Kudos
Message 4 of 8
(1,547 Views)

Michael, I have not been able to get this to work.  I tried a few variations of the assignment statement you provided (I think you omitted the "s" in channel, I tried with and without the "s" with no luck).  Here are the results:

 

import nidaqmx
import time
with nidaqmx.Task() as task:
    task.do_channels.add_do_chan("Dev2/port0/line0:3")
    do_channels.do_output_drive_type = DigitalDriveType.OPEN_COLLECTOR
    task.write(3)    # Set port 0 lines 0 & 1 to logic high
    time.sleep(5)
    task.write(2)    # Set only line 1 to logic high
    time.sleep(5)
    task.write(0)    # Set all lines low

 

Provides error:

Python 3.7.2 (tags/v3.7.2:9a3ffc0492, Dec 23 2018, 22:20:52) [MSC v.1916 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license()" for more information.
>>>
=== RESTART: U:\Python\Programs\NI USB-6212\USB-6000 - Forum Question5.py ===
Traceback (most recent call last):
  File "U:\Python\Programs\NI USB-6212\USB-6000 - Forum Question5.py", line 5, in <module>
    do_channels.do_output_drive_type = DigitalDriveType.OPEN_COLLECTOR
NameError: name 'DigitalDriveType' is not defined

 

import nidaqmx
import time
with nidaqmx.Task() as task:
    task.do_channels.add_do_chan("Dev2/port0/line0:3")
    taks.do_channels.do_output_drive_type = DigitalDriveType.OPEN_COLLECTOR
    task.write(3)    # Set port 0 lines 0 & 1 to logic high
    time.sleep(5)
    task.write(2)    # Set only line 1 to logic high
    time.sleep(5)
    task.write(0)    # Set all lines low

 

Provides error:

Python 3.7.2 (tags/v3.7.2:9a3ffc0492, Dec 23 2018, 22:20:52) [MSC v.1916 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license()" for more information.
>>>
=== RESTART: U:\Python\Programs\NI USB-6212\USB-6000 - Forum Question5.py ===
Traceback (most recent call last):
  File "U:\Python\Programs\NI USB-6212\USB-6000 - Forum Question5.py", line 5, in <module>
    taks.do_channels.do_output_drive_type = DigitalDriveType.OPEN_COLLECTOR
NameError: name 'DigitalDriveType' is not defined

 

Basically, anything I tried gives an error that 'DigitalDriveType' is not defined.

 

 

0 Kudos
Message 5 of 8
(1,527 Views)

Hi bobuuu,

 

DigitalDriveType is a class defined in nidaqmx.constants.  You may have to refer to it as nidaqmx.constants.DigitalDriveType, depending on how you import the package.  I'm not familiar with Python, so I can't give you the best guidance on how to structure your imports.

 

Thanks,

Michael B.
Product Support Engineer
National Instruments
0 Kudos
Message 6 of 8
(1,503 Views)

I tried adding the constant definition as you described (in two places).  There are no errors at this time but the output is still driven high with a 1K resistor load i.e. not acting as an open collector output.

 

import nidaqmx
import time

nidaqmx.do_output_drive_type = nidaqmx.constants.DigitalDriveType.OPEN_COLLECTOR
with nidaqmx.Task() as task:
    task.do_channels.add_do_chan("Dev2/port0/line0:3")
    task.do_output_drive_type = nidaqmx.constants.DigitalDriveType.OPEN_COLLECTOR
    task.write(3)    # Set port 0 lines 0 & 1 to logic high
    time.sleep(5)
    task.write(2)    # Set only line 1 to logic high
    time.sleep(5)
    task.write(0)    # Set all lines low

0 Kudos
Message 7 of 8
(1,497 Views)

task.do_channels is described in the documentation as a collection of channels.  To modify the settings of the contained channels, you want to iterate over the collection.  Try this:

 

import nidaqmx

...

with nidaqmx.Task() as task:

    task.do_channels.add_do_chan("Dev2/port0/line0:3")

    for chnl in task.do_channels:

        chnl.do_output_drive_type = nidaqmx.constants.DigitalDriveType.OPEN_COLLECTOR

    task.write(3)

    ...

0 Kudos
Message 8 of 8
(1,461 Views)