27if platform.system() ==
'Windows':
28 if '64 bit' in platform.python_compiler():
29 WinDLL(os.environ[
"GCLIB_ROOT"] +
'/dll/x64/libcrypto-1_1-x64.dll')
30 WinDLL(os.environ[
"GCLIB_ROOT"] +
'/dll/x64/libssl-1_1-x64.dll')
31 _gclib = WinDLL(os.environ[
"GCLIB_ROOT"] +
'/dll/x64/gclib.dll')
32 _gclibo = WinDLL(os.environ[
"GCLIB_ROOT"] +
'/dll/x64/gclibo.dll')
34 WinDLL(os.environ[
"GCLIB_ROOT"] +
'/dll/x86/libcrypto-1_1.dll')
35 WinDLL(os.environ[
"GCLIB_ROOT"] +
'/dll/x86/libssl-1_1.dll')
36 _gclib = WinDLL(os.environ[
"GCLIB_ROOT"] +
'/dll/x86/gclib.dll')
37 _gclibo = WinDLL(os.environ[
"GCLIB_ROOT"] +
'/dll/x86/gclibo.dll')
40 setattr(_gclib,
'GArrayDownload', getattr(_gclib,
'_GArrayDownload@20'))
41 setattr(_gclib,
'GArrayUpload', getattr(_gclib,
'_GArrayUpload@28'))
42 setattr(_gclib,
'GClose', getattr(_gclib,
'_GClose@4'))
43 setattr(_gclib,
'GCommand', getattr(_gclib,
'_GCommand@20'))
44 setattr(_gclib,
'GFirmwareDownload', getattr(_gclib,
'_GFirmwareDownload@8'))
45 setattr(_gclib,
'GInterrupt', getattr(_gclib,
'_GInterrupt@8'))
46 setattr(_gclib,
'GMessage', getattr(_gclib,
'_GMessage@12'))
47 setattr(_gclib,
'GOpen', getattr(_gclib,
'_GOpen@8'))
48 setattr(_gclib,
'GProgramDownload', getattr(_gclib,
'_GProgramDownload@12'))
49 setattr(_gclib,
'GProgramUpload', getattr(_gclib,
'_GProgramUpload@12'))
51 setattr(_gclibo,
'GAddresses', getattr(_gclibo,
'_GAddresses@8'))
52 setattr(_gclibo,
'GArrayDownloadFile', getattr(_gclibo,
'_GArrayDownloadFile@8'))
53 setattr(_gclibo,
'GArrayUploadFile', getattr(_gclibo,
'_GArrayUploadFile@12'))
54 setattr(_gclibo,
'GAssign', getattr(_gclibo,
'_GAssign@8'))
55 setattr(_gclibo,
'GError', getattr(_gclibo,
'_GError@12'))
56 setattr(_gclibo,
'GInfo', getattr(_gclibo,
'_GInfo@12'))
57 setattr(_gclibo,
'GIpRequests', getattr(_gclibo,
'_GIpRequests@8'))
58 setattr(_gclibo,
'GMotionComplete', getattr(_gclibo,
'_GMotionComplete@8'))
59 setattr(_gclibo,
'GProgramDownloadFile', getattr(_gclibo,
'_GProgramDownloadFile@12'))
60 setattr(_gclibo,
'GSleep', getattr(_gclibo,
'_GSleep@4'))
61 setattr(_gclibo,
'GProgramUploadFile', getattr(_gclibo,
'_GProgramUploadFile@8'))
62 setattr(_gclibo,
'GTimeout', getattr(_gclibo,
'_GTimeout@8'))
63 setattr(_gclibo,
'GVersion', getattr(_gclibo,
'_GVersion@8'))
64 setattr(_gclibo,
'GSetupDownloadFile', getattr(_gclibo,
'_GSetupDownloadFile@20'))
65 setattr(_gclibo,
'GServerStatus', getattr(_gclibo,
'_GServerStatus@8'))
66 setattr(_gclibo,
'GSetServer', getattr(_gclibo,
'_GSetServer@4'))
67 setattr(_gclibo,
'GListServers', getattr(_gclibo,
'_GListServers@8'))
68 setattr(_gclibo,
'GPublishServer', getattr(_gclibo,
'_GPublishServer@12'))
69 setattr(_gclibo,
'GRemoteConnections', getattr(_gclibo,
'_GRemoteConnections@8'))
71elif platform.system() ==
'Linux':
72 cdll.LoadLibrary(
"libgclib.so.2")
73 _gclib = CDLL(
"libgclib.so.2")
74 cdll.LoadLibrary(
"libgclibo.so.2")
75 _gclibo = CDLL(
"libgclibo.so.2")
77elif platform.system() ==
'Darwin':
78 _gclib_path =
'/Applications/gclib/dylib/gclib.0.dylib'
79 _gclibo_path =
'/Applications/gclib/dylib/gclibo.0.dylib'
80 cdll.LoadLibrary(_gclib_path)
81 _gclib = CDLL(_gclib_path)
82 cdll.LoadLibrary(_gclibo_path)
83 _gclibo = CDLL(_gclibo_path)
90_GCon_ptr = POINTER(_GCon)
92_GSize_ptr = POINTER(_GSize)
94_GCStringOut = c_char_p
97_GStatus_ptr = POINTER(_GStatus)
101_gclib.GArrayDownload.argtypes = [_GCon, _GCStringIn, _GOption, _GOption, _GCStringIn]
102_gclib.GArrayUpload.argtypes = [_GCon, _GCStringIn, _GOption, _GOption, _GOption, _GCStringOut, _GSize]
103_gclib.GClose.argtypes = [_GCon]
104_gclib.GCommand.argtypes = [_GCon, _GCStringIn, _GCStringOut, _GSize, _GSize_ptr]
105_gclib.GFirmwareDownload.argtypes = [_GCon, _GCStringIn]
106_gclib.GInterrupt.argtypes = [_GCon, _GStatus_ptr]
107_gclib.GMessage.argtypes = [_GCon, _GCStringOut, _GSize]
108_gclib.GOpen.argtypes = [_GCStringIn, _GCon_ptr]
109_gclib.GProgramDownload.argtypes = [_GCon, _GCStringIn, _GCStringIn]
110_gclib.GProgramUpload.argtypes = [_GCon, _GCStringOut, _GSize]
112_gclibo.GAddresses.argtypes = [_GCStringOut, _GSize]
113_gclibo.GArrayDownloadFile.argtypes = [_GCon, _GCStringIn]
114_gclibo.GArrayUploadFile.argtypes = [_GCon, _GCStringIn, _GCStringIn]
115_gclibo.GAssign.argtypes = [_GCStringIn, _GCStringIn]
116_gclibo.GError.argtypes = [_GReturn, _GCStringOut, _GSize]
117_gclibo.GError.restype =
None
118_gclibo.GError.argtypes = [_GCon, _GCStringOut, _GSize]
119_gclibo.GIpRequests.argtypes = [_GCStringOut, _GSize]
120_gclibo.GMotionComplete.argtypes = [_GCon, _GCStringIn]
121_gclibo.GProgramDownloadFile.argtypes = [_GCon, _GCStringIn, _GCStringIn]
122_gclibo.GSleep.argtypes = [c_uint]
123_gclibo.GSleep.restype =
None
124_gclibo.GProgramUploadFile.argtypes = [_GCon, _GCStringIn]
125_gclibo.GTimeout.argtypes = [_GCon, c_int]
126_gclibo.GVersion.argtypes = [_GCStringOut, _GSize]
127_gclibo.GServerStatus.argtypes = [_GCStringOut, _GSize]
128_gclibo.GSetServer.argtypes = [_GCStringIn]
129_gclibo.GListServers.argtypes = [_GCStringOut, _GSize]
130_gclibo.GPublishServer.argtypes = [_GCStringIn, _GOption, _GOption]
131_gclibo.GRemoteConnections.argtypes = [_GCStringOut, _GSize]
132_gclibo.GSetupDownloadFile.argtypes = [_GCon, _GCStringIn, _GOption, _GCStringOut, _GSize]
137_error_buf = create_string_buffer(128)
140 """Checks return codes from gclib and raises a python error if result is exceptional."""
142 _gclibo.GError(return_code, _error_buf, 128)
143 raise GclibError(str(_error_buf.value.decode(_enc)))
148 Error class for non-zero gclib return codes.
154 Represents a single Python connection to a Galil Controller or PLC.
158 """Constructor for the Connection class. Initializes gclib's handle and read buffer."""
159 self.
_gcon = _GCon(0)
160 self.
_buf = create_string_buffer(_buf_size)
165 """Destructor for the Connection class. Ensures close gets called to release Galil resource (Sockets, Kernel Driver, Com Port, etc)."""
170 """Checks if connection is established, throws error if not."""
171 if self.
_gcon.value ==
None:
175 """@ingroup py_connection
176 Opens a connection a galil controller.
177 See the gclib docs for address string formatting.
179 c_address = _GCStringIn(address.encode(_enc))
180 _rc(_gclib.GOpen(c_address, byref(self.
_gcon)))
185 """@ingroup py_connection
186 Closes a connection to a Galil Controller.
188 if self.
_gcon.value !=
None:
189 _rc(_gclib.GClose(self.
_gcon))
190 self.
_gcon = _GCon(0)
195 """@ingroup py_controller
196 Performs a command-and-response transaction on the connection.
200 c_command = _GCStringIn(command.encode(_enc))
201 _rc(_gclib.GCommand(self.
_gcon, c_command, self.
_buf, _buf_size,
None))
202 response = str(self.
_buf.value.decode(_enc))
203 return response[:-3].strip()
208 Provides a blocking sleep call which can be useful for timing-based chores.
216 Provides the gclib version number. Please include the output of this function on all support cases.
218 _rc(_gclibo.GVersion(self.
_buf, _buf_size))
219 return "py." + str(self.
_buf.value.decode(_enc))
222 """@ingroup py_remote
223 Provides the local server name and whether it is published to the local network.
225 _rc(_gclibo.GServerStatus(self.
_buf, _buf_size))
226 return str(self.
_buf.value.decode(_enc))
229 """@ingroup py_remote
230 Set the new active server.
232 c_server_name = _GCStringIn(server_name.encode(_enc))
233 _rc(_gclibo.GSetServer(c_server_name))
237 """@ingroup py_remote
238 Provide a list of all available gcaps servers on the local network.
240 _rc(_gclibo.GListServers(self.
_buf, _buf_size))
241 return str(self.
_buf.value.decode(_enc))
244 """@ingroup py_remote
245 Publish local gcaps server to the network.
247 c_server_name = _GCStringIn(server_name.encode(_enc))
248 _rc(_gclibo.GPublishServer(c_server_name, publish, save))
252 """@ingroup py_remote
253 Shows all remote addresses that are connected to the local server.
255 _rc(_gclibo.GRemoteConnections(self.
_buf, _buf_size))
256 return str(self.
_buf.value.decode(_enc))
259 """@ingroup py_connection
260 Provides a useful connection string. Please include the output of this function on all support cases.
262 _rc(_gclibo.GInfo(self.
_gcon, self.
_buf, _buf_size))
263 return str(self.
_buf.value.decode(_enc))
267 """@ingroup py_connection
268 Provides a dictionary of all Galil controllers requesting IP addresses via BOOT-P or DHCP.
270 Returns a dictionary mapping 'model-serial' --> 'mac address'
271 e.g. {'DMC4000-783': '00:50:4c:20:03:0f', 'DMC4103-9998': '00:50:4c:38:27:0e'}
273 Linux/OS X users must be root to use GIpRequests() and have UDP access to bind and listen on port 67.
275 _rc(_gclibo.GIpRequests(self.
_buf, _buf_size))
277 for line
in str(self.
_buf.value.decode(_enc)).splitlines():
278 line = line.replace(
' ',
'')
279 if (line ==
""):
continue
280 fields = line.split(
',')
282 ip_req_dict[fields[0] +
'-' + fields[1]] = fields[2]
287 """@ingroup py_connection
288 Assigns IP address over the Ethernet to a controller at a given MAC address.
289 Linux/OS X users must be root to use GAssign() and have UDP access to send on port 68.
291 c_ip = _GCStringIn(ip.encode(_enc))
292 c_mac = _GCStringIn(mac.encode(_enc))
293 _rc(_gclibo.GAssign(c_ip, c_mac))
298 """@ingroup py_connection
299 Provides a dictionary of all available connection addresses.
301 Returns a dictionary mapping 'address' -> 'revision reports', where possible
304 _rc(_gclibo.GAddresses(self.
_buf, _buf_size))
306 for line
in str(self.
_buf.value.decode(_enc)).splitlines():
307 fields = line.split(
',')
309 addr_dict[fields[0]] = fields[1]
311 addr_dict[fields[0]] =
''
317 """@ingroup py_memory
318 Downloads a program to the controller's program buffer.
319 See the gclib docs for preprocessor options.
322 c_prog = _GCStringIn(program.encode(_enc))
323 c_pre = _GCStringIn(preprocessor.encode(_enc))
324 _rc(_gclib.GProgramDownload(self.
_gcon, c_prog, c_pre))
329 """@ingroup py_memory
330 Uploads a program from the controller's program buffer.
333 _rc(_gclib.GProgramUpload(self.
_gcon, self.
_buf, _buf_size))
334 return str(self.
_buf.value.decode(_enc))
338 """@ingroup py_memory
339 Program download from file.
340 See the gclib docs for preprocessor options.
343 c_path = _GCStringIn(file_path.encode(_enc))
344 c_pre = _GCStringIn(preprocessor.encode(_enc))
345 _rc(_gclibo.GProgramDownloadFile(self.
_gcon, c_path, c_pre))
349 """@ingroup py_memory
350 Program upload to file.
353 c_path = _GCStringIn(file_path.encode(_enc))
354 _rc(_gclibo.GProgramUploadFile(self.
_gcon, c_path))
358 """@ingroup py_memory
359 Downloads array data to a pre-dimensioned array in the controller's array table.
360 array_data should be a list of values (e.g. int or float)
363 c_name = _GCStringIn(name.encode(_enc))
365 for val
in array_data:
366 array_string += str(val) +
","
367 c_data = _GCStringIn(array_string[:-1].encode(_enc))
368 _rc(_gclib.GArrayDownload(self.
_gcon, c_name, first, last, c_data))
373 """@ingroup py_memory
374 Uploads the entire controller array table or a subset and saves the data as a csv file specified by file_path.
375 names is optional and should be a list of array names on the controller.
378 c_path = _GCStringIn(file_path.encode(_enc))
380 c_names = _GCStringIn(
''.encode(_enc))
382 names_string += name +
' '
384 c_names = _GCStringIn(names_string[:-1].encode(_enc))
385 _rc(_gclibo.GArrayUploadFile(self.
_gcon, c_path, c_names))
390 """@ingroup py_memory
391 Downloads a csv file containing array data at file_path.
394 c_path = _GCStringIn(file_path.encode(_enc))
395 _rc(_gclibo.GArrayDownloadFile(self.
_gcon, c_path))
400 """@ingroup py_memory
401 Uploads array data from the controller's array table.
404 c_name = _GCStringIn(name.encode(_enc))
405 _rc(_gclib.GArrayUpload(self.
_gcon, c_name, first, last, 1, self.
_buf, _buf_size))
406 string_list = str(self.
_buf.value.decode(_enc)).split(
',')
408 for s
in string_list:
409 float_list.append(float(s))
414 """@ingroup py_connection
415 Set the library timeout. Set to -1 to use the initial library timeout, as specified in GOpen.
418 _rc(_gclibo.GTimeout(self.
_gcon, timeout))
425 """@ingroup py_connection
426 Convenience property read access to timeout value. If -1, gclib uses the initial library timeout, as specified in GOpen.
432 """@ingroup py_connection
433 Convenience property write access to timeout value. Set to -1 to use the initial library timeout, as specified in GOpen.
440 """@ingroup py_memory
444 c_path = _GCStringIn(file_path.encode(_enc))
445 _rc(_gclib.GFirmwareDownload(self.
_gcon, c_path))
450 """@ingroup py_unsolicited
451 Provides access to unsolicited messages from the controller.
454 _rc(_gclib.GMessage(self.
_gcon, self.
_buf, _buf_size))
455 return str(self.
_buf.value.decode(_enc))
459 """@ingroup py_controller
460 Blocking call that returns once all axes specified have completed their motion.
463 c_axes = _GCStringIn(axes.encode(_enc))
464 _rc(_gclibo.GMotionComplete(self.
_gcon, c_axes))
468 """@ingroup py_unsolicited
469 Provides access to PCI and UDP interrupts from the controller.
473 _rc(_gclib.GInterrupt(self.
_gcon, byref(status)))
477 """@ingroup py_memory
478 Downloads specified sectors from a Galil compressed backup (gcb) file to a controller.
480 Returns a dictionary with the controller information stored in the gcb file.
481 If options is specified as 0, an additional "options" key will be in the dictionary indicating the info sectors available in the gcb
484 c_path = _GCStringIn(file_path.encode(_enc))
486 rc = _gclibo.GSetupDownloadFile(self.
_gcon, c_path, options, self.
_buf, _buf_size)
491 for line
in str(self.
_buf.value.decode(_enc)).split(
"\"\n"):
492 fields = line.split(
',',1)
494 if (fields[0] ==
""):
continue
495 elif len(fields) >= 2:
496 info_dict[fields[0].strip(
"\"\'")] = fields[1].strip(
"\"\'")
498 info_dict[fields[0].strip(
"\"\'")] =
''
501 info_dict[
"options"] = rc
Error class for non-zero gclib return codes.
_cc(self)
Checks if connection is established, throws error if not.
__del__(self)
Destructor for the Connection class.
__init__(self)
Constructor for the Connection class.
GOpen(self, address)
Opens a connection a galil controller.
GTimeout(self, timeout)
Set the library timeout.
GInfo(self)
Provides a useful connection string.
GAddresses(self)
Provides a dictionary of all available connection addresses.
timeout(self)
Convenience property read access to timeout value.
GClose(self)
Closes a connection to a Galil Controller.
GAssign(self, ip, mac)
Assigns IP address over the Ethernet to a controller at a given MAC address.
GIpRequests(self)
Provides a dictionary of all Galil controllers requesting IP addresses via BOOT-P or DHCP.
GCommand(self, command)
Performs a command-and-response transaction on the connection.
GMotionComplete(self, axes)
Blocking call that returns once all axes specified have completed their motion.
GArrayUploadFile(self, file_path, names=[])
Uploads the entire controller array table or a subset and saves the data as a csv file specified by f...
GFirmwareDownload(self, file_path)
Upgrade firmware.
GSetupDownloadFile(self, file_path, options)
Downloads specified sectors from a Galil compressed backup (gcb) file to a controller.
GProgramDownloadFile(self, file_path, preprocessor="")
Program download from file.
GArrayDownload(self, name, first, last, array_data)
Downloads array data to a pre-dimensioned array in the controller's array table.
GProgramUpload(self)
Uploads a program from the controller's program buffer.
GArrayUpload(self, name, first, last)
Uploads array data from the controller's array table.
GProgramUploadFile(self, file_path)
Program upload to file.
GProgramDownload(self, program, preprocessor="")
Downloads a program to the controller's program buffer.
GArrayDownloadFile(self, file_path)
Downloads a csv file containing array data at file_path.
GRemoteConnections(self)
Shows all remote addresses that are connected to the local server.
GPublishServer(self, server_name, publish, save)
Publish local gcaps server to the network.
GListServers(self)
Provide a list of all available gcaps servers on the local network.
GSetServer(self, server_name)
Set the new active server.
GServerStatus(self)
Provides the local server name and whether it is published to the local network.
GInterrupt(self)
Provides access to PCI and UDP interrupts from the controller.
GMessage(self)
Provides access to unsolicited messages from the controller.
GVersion(self)
Provides the gclib version number.
GSleep(self, val)
Provides a blocking sleep call which can be useful for timing-based chores.