Commit 54ac5cf2 authored by Martin Drechsler's avatar Martin Drechsler

Adoutputs file changed completely to do things cleaner. Now it is independent...

Adoutputs file changed completely to do things cleaner. Now it is independent of instacal configuration.
parent 5901d2c5
# -*- coding: utf-8 -*-
"""
Created on Wed May 30 15:27:17 2018
Created on Thu Oct 25 15:35:49 2018
@author: martindrech
@author: Usuario
For now, this will work with one measruement computing daq. It is expected to be the USB-3105 and
the board number will be 0.
If the daq is not found, whenever trying to send signals, the command will be printed in the console.
"""
#from __future__ import absolute_import, division, print_function
import warnings
from messages import show_warning
import warnings
daqfound = True
from mcculw import ul
from mcculw.enums import InterfaceType, ULRange, InfoType, BoardInfo, DigitalIODirection
from mcculw.ul import ULError
try:
from mcculw import ul
from mcculw.enums import DigitalIODirection, ULRange, InterfaceType
from examples.props.digital import DigitalProps
from examples.props.ao import AnalogOutputProps
from props.digital import DigitalProps
from props.ao import AnalogOutputProps
from mcculw.ul import ULError
ao_range = ULRange.BIP10VOLTS
ul.ignore_instacal() #instacal will be ignored
except:
warnings.warn('There was some error with the mcculw drivers. ')
# First of all, I check which daqs are available and print it.
devices = ul.get_daq_device_inventory(interface_type=InterfaceType.USB)
device = devices[0]
if len(devices)>0:
print('daq %s is connected' % device.product_name)
else:
print('No daq connected')
def discover_device(board_num, board_name):
"""
Checks if daq is found.
"""
devices = ul.get_daq_device_inventory(InterfaceType.USB) #get device inventory
device = next((device for device in devices
if board_name in device.product_name), None)
devices = ul.get_daq_device_inventory(interface_type=InterfaceType.USB)
if len(devices)==0:
daqfound = False
warnings.warn('daq not found')
if device != None: #if it is found,
try:
ul.create_daq_device(board_num, device) #create an instance
except ULError:
ul.release_daq_device(board_num)
ul.create_daq_device(board_num, device)
warnings.warn('The board number %i was already in use, and it was released and redefined ' % board_num);
finally:
return True
return False
daqfound = discover_device(0, 'USB-3105')
class daq_AO(object):
def __init__(self, out_num, board_num = 0, output_range = ULRange.BIP10VOLTS):
global daqfound
self.out_num = out_num
self.board_num = board_num
self.output_range = output_range
if daqfound:
ul.set_config(InfoType.BOARDINFO, self.board_num, self.out_num, BoardInfo.DACRANGE, self.output_range)
self.ao_props = AnalogOutputProps(self.board_num)
else:
device = devices[0]
print('The daq %s was found succesfully :)' % device.product_name)
daqfound = True
#methods
if daqfound:
def set_out(self, value):
try:
ul.v_out(self.board_num, self.out_num, self.output_range, value)
except ULError as e:
self.show_ul_error(e)
else:
def set_out(self, value):
print('Analog out %i set to %f' % (self.out_num, value) )
return value, self.out_num
#%%
class daq_DO(object):
def __init__(self, out_num):
global daqfound
#ul.ignore_instacal()
self.board_num = 0
self.out_num = out_num
if daqfound:
......@@ -62,8 +104,7 @@ class daq_DO(object):
self.board_num, self.port.type, DigitalIODirection.OUT)
except ULError as e:
self.show_ul_error(e)
print('puerto: ', self.port)
print(self.port.type)
if daqfound:
def set_out(self, bit_value):
......@@ -77,33 +118,4 @@ class daq_DO(object):
print('Digital out %i set to %s' % (self.out_num, bit_value) )
return bit_value, self.out_num
class daq_AO(object):
def __init__(self, out_num):
global daqfound
#ul.ignore_instacal()
self.board_num = 0
self.out_num = out_num
if daqfound:
self.ao_props = AnalogOutputProps(self.board_num)
if daqfound:
def set_out(self, value):
try:
ul.v_out(self.board_num, self.out_num, ao_range, value)
except ULError as e:
self.show_ul_error(e)
def get_analog_out(self):
#ao_range = self.ao_props.available_ranges[0]
try:
state = ul.a_in(self.board_num, self.out_num, ao_range)
print(state)
except ValueError:
return 0
else:
def set_out(self, value):
print('Analog out %i set to %f' % (self.out_num, value) )
return value, self.out_num
######################################################################################
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment