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, c_char_p
10import platform, os
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 = 0):
36
37 if platform.system() == "Windows":
38 self.AOCLW = CDLL("../x64/Release/AxsunOCTControl_LW.dll")
39 if platform.system() == "Darwin" or platform.system() == "Linux":
40 lib_path = os.path.join(os.getcwd(), "build/lib/libaxsunoctcontrol_lw.dylib")
41 self.AOCLW = CDLL(lib_path)
43 if retval:
44 raise AxErr(self.GetAPIErrorString(retval))
45
46 def __del__(self):
48
49
50 def GetAPIErrorString(self, errorno):
51 the_string = create_string_buffer(512)
53 return ("*** AxErr " + str(errorno) + ": "
54 + the_string.value.decode() + " ***")
55
56
57 def LibraryVersion(self):
58
59 major = c_uint(0)
60 minor = c_uint(0)
61 build = c_uint(0)
62 patch = c_uint(0)
64 byref(build), byref(patch))
65 return (major.value, minor.value, build.value, patch.value)
66
67
68 def LWLibVersion(self):
69 ReadStr = self.AOCLW.axLWLibVersion
70 ReadStr.restype = c_char_p
71 return str(ReadStr(), 'UTF-8')
72
73
75 ReadStr = self.AOCLW.axLWBuildDateTime
76 ReadStr.restype = c_char_p
77 return ReadStr().decode()
78
79
80 def GetDeviceType(self, which_dev):
81 this_device = c_int(0)
82 retval = self.AOCLW.
axDeviceType(byref(this_device), c_uint(which_dev))
83 if retval:
84 raise AxErr(self.GetAPIErrorString(retval))
85 return device_t[this_device.value]
86
87
88 def GetSerialNum(self, which_dev):
89 serialnum = create_string_buffer(40)
91 if retval:
92 raise AxErr(self.GetAPIErrorString(retval))
93 return serialnum.value.decode()
94
95
96 def GetFirmwareVersion(self, which_dev):
97
98 major = c_uint(0)
99 minor = c_uint(0)
100 patch = c_uint(0)
101
102
104 byref(patch), c_uint(which_dev))
105 if retval:
106 raise AxErr(self.GetAPIErrorString(retval))
107 return (str(major.value) + "."
108 + str(minor.value) + "."
109 + str(patch.value))
110
111
112 def GetConnectionType(self, which_dev):
113 this_device = c_int(0)
115 if retval:
116 raise AxErr(self.GetAPIErrorString(retval))
117 return connection_t[this_device.value]
118
119
120 def CountDevices(self):
122
123 def RegisterCallback(self, func, obj):
124
125 CALLBACK_TYPE = CFUNCTYPE(None, c_void_p)
126
127
128 obj.callback_fn = CALLBACK_TYPE(func)
129
130
131 RegisterConnectCallback = self.AOCLW.axRegisterConnectCallback
132
133
134 RegisterConnectCallback.argtypes = [CALLBACK_TYPE, c_void_p]
135 RegisterConnectCallback.restype = c_int
136
137
138 retval = RegisterConnectCallback(obj.callback_fn, c_void_p.from_buffer(py_object(obj)))
139 if retval:
140 raise AxErr(self.GetAPIErrorString(retval))
141
142 def OpenUSBInterface(self, open):
144 if retval:
145 raise AxErr(self.GetAPIErrorString(retval))
146
147 def OpenNetworkInterface(self, open):
149 if retval:
150 raise AxErr(self.GetAPIErrorString(retval))
151
152 def LaserEmission(self, state, which_laser = 0):
154 if retval:
155 raise AxErr(self.GetAPIErrorString(retval))
156
157 def GetFPGARegisterRange(self, start_reg, end_reg, which_daq = 0):
158 allocatedwords = end_reg - start_reg + 1
159 regvals_t = c_ushort * allocatedwords
160 regvals = regvals_t()
161 ReadRegs = self.AOCLW.axGetFPGARegisterRange
162 ReadRegs.argtypes = [c_uint, c_uint, POINTER(c_ushort), c_uint, c_uint]
163 ReadRegs.restype = c_int
164 retval = ReadRegs(start_reg,
165 end_reg,
166 regvals,
167 allocatedwords * 2,
168 which_daq)
169 if retval:
170 raise AxErr(self.GetAPIErrorString(retval))
171
172
173 this_reg = start_reg
174 regnums_vals = {}
175 for x in regvals:
176 regnums_vals[this_reg] = x
177 this_reg += 1
178
179
180 return regnums_vals
181
182 def SetFPGARegister(self, reg, value, which_daq = 0):
183 retval = self.AOCLW.
axSetFPGARegister(c_uint(reg), c_ushort(value), c_uint(which_daq))
184 if retval:
185 raise AxErr(self.GetAPIErrorString(retval))
186
187 def GetFPGARegister(self, reg, which_daq = 0):
188 regvalue = c_ushort(0)
190 if retval:
191 raise AxErr(self.GetAPIErrorString(retval))
192 return regvalue.value
const char * axLWBuildDateTime()
Get a string describing the time and date that the AxsunOCTControl_LW library was built.
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 as numeric elements.
AxErr __cdecl axFirmwareVersion(uint32_t *major, uint32_t *minor, uint32_t *patch, uint32_t which_device)
Gets the device firmware version.