-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlaser_control.py
More file actions
63 lines (45 loc) · 1.85 KB
/
laser_control.py
File metadata and controls
63 lines (45 loc) · 1.85 KB
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
######################################################################################################
# @author Mehrdad Zarei <mzarei@umk.pl>
# @date 2021.08.10
# @version 0
#
# @brief control lasre's parameters with NI_USB_6229
#
######################################################################################################
from inspect import Attribute
import nidaqmx
from nidaqmx.constants import TerminalConfiguration
class LaserControl:
# def __init__(self):
# self.chPzt = {'1': '', '2': '', '3': '', '4': '',\
# '5': 'Dev2/ao2', '6': 'Dev2/ao0', '7': '', '8': ''}
# self.chI = {'1': '', '2': '', '3': '', '4': '',\
# '5': 'Dev2/ao3', '6': 'Dev2/ao1', '7': '', '8': ''}
# self.set_I('6', 0)
# self.set_Pzt('6', 0)
# self.RSE = 10083
def setOutput(self, port, val, min_val_ni=-10.0, max_val_ni=10.0):
with nidaqmx.Task() as task:
try:
# min_val and max_val must be set to avoid error. some NIs have min 0 and max 5
task.ao_channels.add_ao_voltage_chan(port, min_val=min_val_ni, max_val=max_val_ni)
except nidaqmx.DaqError:
return False
try:
task.write([round(val, 3)], auto_start=True, timeout=0.0)
except :
pass
def getInput(self, port, noSmp = 1):
with nidaqmx.Task() as task:
try:
task.ai_channels.add_ai_voltage_chan(port, terminal_config=TerminalConfiguration.RSE)
except nidaqmx.DaqError:
return -11
try:
return task.read(noSmp)
except :
return -12
# a = LaserControl()
# print(a.getInput('Dev1/ai1', 10))
# a.setOutput('Dev2/ao2', 0.0)
# a.setOutput('Dev2/ao0', 0.0)