03-14-2019 09:13 AM
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
03-15-2019 05:16 PM
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,
03-18-2019 04:20 PM
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?
03-19-2019 05:34 PM
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,
03-22-2019 04:02 PM
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.
03-25-2019 02:54 PM
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,
03-25-2019 04:48 PM
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
03-29-2019 01:19 PM
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)
...