1
3
4
5
6
7from ctypes import CDLL, create_string_buffer, c_uint, c_int, \
8 byref, py_object, CFUNCTYPE, c_void_p, \
9 POINTER, c_ushort
10
11
12
13class AxErr(Exception):
14 pass
15
16
17
18device_t = {0: "unknown",
19 40: "laser ",
20 41: "CLDAQ ",
21 42: "EDAQ "
22 }
23
24
25connection_t = {0: "none",
26 1: "USB",
27 2: "RS232_PASSTHRU",
28 3: "RS232",
29 4: "ETHERNET"
30 }
31
32
33class AOCLW_wrapper_class:
34
35 def __init__(self, interfaces):
36
37
38 self.AOCLW = CDLL("../x64/Release/AxsunOCTControl_LW.dll")
41 if retval:
42 raise AxErr(self.GetAPIErrorString(retval))
43
44 def __del__(self):
46
47
48 def GetAPIErrorString(self, errorno):
49 the_string = create_string_buffer(512)
51 return ("*** AxErr " + str(errorno) + ": "
52 + str(the_string.value.decode()) + " ***")
53
54
55 def LibraryVersion(self):
56
57 major = c_uint(0)
58 minor = c_uint(0)
59 build = c_uint(0)
60 patch = c_uint(0)
61
62
64 byref(build), byref(patch))
65 if retval:
66 raise AxErr(self.GetAPIErrorString(retval))
67 return (str(major.value) + "." + str(minor.value) + "."
68 + str(build.value) + "." + str(patch.value))
69
70
71 def GetDeviceType(self, which):
72 this_device = c_int(0)
73 retval = self.AOCLW.
axDeviceType(byref(this_device), c_uint(which))
74 if retval:
75 raise AxErr(self.GetAPIErrorString(retval))
76 return device_t[this_device.value]
77
78
79 def GetSerialNum(self, which):
80 serialnum = create_string_buffer(40)
82 if retval:
83 raise AxErr(self.GetAPIErrorString(retval))
84 return str(serialnum.value.decode())
85
86
87 def GetFirmwareVersion(self, which):
88
89 major = c_uint(0)
90 minor = c_uint(0)
91 patch = c_uint(0)
92
93
95 byref(patch), c_uint(which))
96 if retval:
97 raise AxErr(self.GetAPIErrorString(retval))
98 return (str(major.value) + "."
99 + str(minor.value) + "."
100 + str(patch.value))
101
102
103 def GetConnectionType(self, which):
104 this_device = c_int(0)
106 if retval:
107 raise AxErr(self.GetAPIErrorString(retval))
108 return connection_t[this_device.value]
109
110
111 def CountDevices(self):
113
114 def RegisterCallback(self, func, obj):
115
116 CALLBACK_TYPE = CFUNCTYPE(None, c_void_p)
117
118
119 obj.callback_fn = CALLBACK_TYPE(func)
120
121
122 RegisterConnectCallback = self.AOCLW.axRegisterConnectCallback
123
124
125 RegisterConnectCallback.argtypes = [CALLBACK_TYPE, c_void_p]
126 RegisterConnectCallback.restype = c_int
127
128
129 retval = RegisterConnectCallback(obj.callback_fn,
130 c_void_p.from_buffer(py_object(obj)))
131 if retval:
132 raise AxErr(self.GetAPIErrorString(retval))
133
134 def OpenUSBInterface(self, open):
136 if retval:
137 raise AxErr(self.GetAPIErrorString(retval))
138
139 def OpenNetworkInterface(self, open):
141 if retval:
142 raise AxErr(self.GetAPIErrorString(retval))
143
144 def LaserEmission(self, state, which):
146 if retval:
147 raise AxErr(self.GetAPIErrorString(retval))
148
149 def GetFPGARegisterRange(self, start_reg, end_reg, which):
150 allocatedwords = end_reg - start_reg + 1
151 regvals_t = c_ushort * allocatedwords
152 regvals = regvals_t()
153 ReadRegs = self.AOCLW.axGetFPGARegisterRange
154 ReadRegs.argtypes = [c_uint, c_uint, POINTER(c_ushort), c_uint, c_uint]
155 ReadRegs.restype = c_int
156 retval = ReadRegs(start_reg,
157 end_reg,
158 regvals,
159 allocatedwords * 2,
160 which)
161 if retval:
162 raise AxErr(self.GetAPIErrorString(retval))
163
164
165 this_reg = start_reg
166 regnums_vals = {}
167 for x in regvals:
168 regnums_vals[this_reg] = x
169 this_reg += 1
170
171
172 return regnums_vals
173
174 def SetFPGARegister(self, reg, value, which):
175 retval = self.AOCLW.
axSetFPGARegister(c_uint(reg), c_ushort(value), c_uint(which))
176 if retval:
177 raise AxErr(self.GetAPIErrorString(retval))
178
179 def GetFPGARegister(self, reg, which):
180 regvalue = c_ushort(0)
182 if retval:
183 raise AxErr(self.GetAPIErrorString(retval))
184 return regvalue.value
AxErr __cdecl axGetFPGARegister(const uint32_t regnum, uint16_t *regval, uint32_t which_DAQ)
Gets (i.e. reads) the current value in a FPGA register.
AxErr __cdecl axSetFPGARegister(uint32_t regnum, uint16_t regval, uint32_t which_DAQ)
Sets (i.e. writes) a FPGA register with a single value.
AxErr __cdecl axOpenAxsunOCTControl(uint32_t open_all_interfaces)
Opens the AxsunOCTControl_LW session.
AxErr __cdecl axDeviceType(AxDevType *device_type, uint32_t which_device)
Gets the device type (e.g. Laser, EDAQ).
uint32_t __cdecl axCountConnectedDevices()
Counts the number of devices successfully connected and enumerated by AxsunOCTControl_LW.
void __cdecl axGetErrorExplained(AxErr errornum, char *error_string)
Gets a string which explains an error code in a more verbose fashion.
AxErr __cdecl axNetworkInterfaceOpen(uint32_t interface_status)
Opens, resets, or closes the Ethernet network interface.
AxErr __cdecl axCloseAxsunOCTControl()
Closes an AxsunOCTControl_LW session previously opened with axOpenAxsunOCTControl().
AxErr __cdecl axSerialNumber(char *serial_number, uint32_t which_device)
Gets the device serial number string.
AxErr __cdecl axSetLaserEmission(uint32_t emission_state, uint32_t which_laser)
Enables or disables swept laser emission.
AxErr __cdecl axUSBInterfaceOpen(uint32_t interface_status)
Opens, resets, or closes the USB interface.
AxErr __cdecl axConnectionType(AxConnectionType *connection_type, uint32_t which_device)
Gets the device connection interface (e.g. USB, Ethernet, RS-232).
AxErr __cdecl axLibraryVersion(uint32_t *major, uint32_t *minor, uint32_t *patch, uint32_t *build)
Gets the AxsunOCTControl_LW library version.
AxErr __cdecl axFirmwareVersion(uint32_t *major, uint32_t *minor, uint32_t *patch, uint32_t which_device)
Gets the device firmware version.