Newer
Older
import nidaqmx
import logging
log = logging.getLogger(__name__)
log.addHandler(logging.NullHandler())
class DAC():
def __init__(self, addr):
self.type = addr[:2]
self.setup = False
if self.type=="ao":
try:
nidaqmx.Task().ao_channels.add_ao_voltage_chan("Dev1/"+addr)
self.setup = True
except:
log.info("Seems like the DAC is inaccessible")
elif self.type=="ai":
try:
nidaqmx.Task().ai_channels.add_ai_voltage_chan("Dev1/"+addr)
self.setup = True
except:
log.info("Seems like the DAC is inaccessible")
def read(self):
with nidaqmx.Task() as task:
task.ai_channels.add_ai_voltage_chan("Dev1/"+self.addr)
output = task.read()
else:
print("Cannot read from a analog output")
def write(self, value):
if self.setup:
if self.type=="ao":
with nidaqmx.Task() as task:
task.ao_channels.add_ao_voltage_chan("Dev1/"+self.addr)
task.write(value)
else:
print("Cannot write to a analog input")