Newer
Older
Martin Drechsler
committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Fri Mar 22 16:29:22 2019
@author: liaf-ankylosaurus-admin
"""
from uldaq import (get_daq_device_inventory, DaqDevice, InterfaceType,
DigitalDirection, DigitalPortIoType, AOutFlag, Range)
#empty some variables and defining interface type
daq_device = None
dio_device = None
port_to_write = None
port_info = None
interface_type = InterfaceType.USB
descriptor_index = 0
port_types_index = 0
# Get descriptors for all of the available DAQ devices.
devices = get_daq_device_inventory(interface_type)
number_of_devices = len(devices)
if number_of_devices == 0:
raise Exception('Error: No DAQ devices found')
print('Found', number_of_devices, 'DAQ device(s):')
for i in range(number_of_devices):
print(' ', devices[i].product_name, ' (', devices[i].unique_id, ')', sep='')
# Create the DAQ device object associated with the specified descriptor index.
daq_device = DaqDevice(devices[descriptor_index])
# Get the DioDevice object and verify that it is valid.
dio_device = daq_device.get_dio_device()
if dio_device is None:
raise Exception('Error: The device does not support digital output')
# Create a aoDevice object from the first descriptor.
ao_device = daq_device.get_ao_device()
# Verify the specified DAQ device supports analog output.
if ao_device is None:
raise Exception('Error: The DAQ device does not support analog output')
ao_info = ao_device.get_info()
# Establish a connection to the DAQ device.
descriptor = daq_device.get_descriptor()
if not daq_device.is_connected():
print('\nConnecting to', descriptor.dev_string, '- please wait...')
daq_device.connect()
print('\n', descriptor.dev_string, 'ready')
def _configure_digital_outs():
global port_types_index
# Get the port types for the device(AUXPORT, FIRSTPORTA, ...)
dio_info = dio_device.get_info()
port_types = dio_info.get_port_types()
if port_types_index >= len(port_types):
port_types_index = len(port_types) - 1
port_to_write = port_types[port_types_index]
# Get the port I/O type and the number of bits for the first port.
port_info = dio_info.get_port_info(port_to_write)
# If the port is bit configurable, then configure the individual bits
# for output; otherwise, configure the entire port for output.
if port_info.port_io_type == DigitalPortIoType.BITIO:
# Configure all of the bits for output for the first port.
for bit_number in range(port_info.number_of_bits):
dio_device.d_config_bit(port_to_write, bit_number,
DigitalDirection.OUTPUT)
elif port_info.port_io_type == DigitalPortIoType.IO:
# Configure the entire port for output.
dio_device.d_config_port(port_to_write, DigitalDirection.OUTPUT)
_configure_digital_outs()
class daq_AO(object):
def __init__(self, out_num, min_value = -10, max_value = 10, output_range = Range.BIP10VOLTS):
self.out_num = out_num
self.output_range = output_range
self.max = max_value
self.min = min_value
self.current_value = 0
#methods
def set_out(self, value):
try:
ao_device.a_out(self.out_num, self.output_range, AOutFlag.DEFAULT, float(value))
self.current_value = value
except:
raise("Failing to set analog output %i", self.out_num)
# 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):
global port_types_index, dio_device
def __init__(self, out_num):
self.out_num = out_num
self.dio_info = dio_device.get_info()
self.port_types = self.dio_info.get_port_types()
self.port_to_write = self.port_types[port_types_index]
def set_out(self, bit_value):
try:
# Output the value to the board
dio_device.d_bit_out(self.port_to_write, self.out_num, bit_value)
except:
raise("Failing to set digital output %i", self.out_num)
# def set_out(self, bit_value):
# print('Digital out %i set to %s' % (self.out_num, bit_value) )
# return bit_value, self.out_num
#