|
@@ -72,6 +72,20 @@ class Device(object): |
|
|
""" |
|
|
""" |
|
|
self._read_thread.stop() |
|
|
self._read_thread.stop() |
|
|
|
|
|
|
|
|
|
|
|
def close(self): |
|
|
|
|
|
""" |
|
|
|
|
|
Closes the device. |
|
|
|
|
|
""" |
|
|
|
|
|
try: |
|
|
|
|
|
self._running = False |
|
|
|
|
|
self._read_thread.stop() |
|
|
|
|
|
self._device.close() |
|
|
|
|
|
|
|
|
|
|
|
except: |
|
|
|
|
|
pass |
|
|
|
|
|
|
|
|
|
|
|
self.on_close() |
|
|
|
|
|
|
|
|
class ReadThread(threading.Thread): |
|
|
class ReadThread(threading.Thread): |
|
|
""" |
|
|
""" |
|
|
Reader thread which processes messages from the device. |
|
|
Reader thread which processes messages from the device. |
|
@@ -113,7 +127,7 @@ class Device(object): |
|
|
except Exception, err: |
|
|
except Exception, err: |
|
|
self._running = False |
|
|
self._running = False |
|
|
|
|
|
|
|
|
raise err |
|
|
|
|
|
|
|
|
#raise err |
|
|
|
|
|
|
|
|
time.sleep(0.01) |
|
|
time.sleep(0.01) |
|
|
|
|
|
|
|
@@ -226,19 +240,14 @@ class USBDevice(Device): |
|
|
Closes the device. |
|
|
Closes the device. |
|
|
""" |
|
|
""" |
|
|
try: |
|
|
try: |
|
|
self._running = False |
|
|
|
|
|
self._read_thread.stop() |
|
|
|
|
|
|
|
|
|
|
|
self._device.close() |
|
|
|
|
|
|
|
|
|
|
|
# HACK: Probably should fork pyftdi and make this call in .close(). |
|
|
# HACK: Probably should fork pyftdi and make this call in .close(). |
|
|
self._device.usb_dev.attach_kernel_driver(self._interface) |
|
|
self._device.usb_dev.attach_kernel_driver(self._interface) |
|
|
|
|
|
|
|
|
|
|
|
super(USBDevice, self).close() |
|
|
|
|
|
|
|
|
except: |
|
|
except: |
|
|
pass |
|
|
pass |
|
|
|
|
|
|
|
|
self.on_close() |
|
|
|
|
|
|
|
|
|
|
|
def write(self, data): |
|
|
def write(self, data): |
|
|
""" |
|
|
""" |
|
|
Writes data to the device. |
|
|
Writes data to the device. |
|
@@ -439,16 +448,11 @@ class SerialDevice(Device): |
|
|
Closes the device. |
|
|
Closes the device. |
|
|
""" |
|
|
""" |
|
|
try: |
|
|
try: |
|
|
self._running = False |
|
|
|
|
|
self._read_thread.stop() |
|
|
|
|
|
|
|
|
|
|
|
self._device.close() |
|
|
|
|
|
|
|
|
super(SerialDevice, self).close() |
|
|
|
|
|
|
|
|
except: |
|
|
except: |
|
|
pass |
|
|
pass |
|
|
|
|
|
|
|
|
self.on_close() |
|
|
|
|
|
|
|
|
|
|
|
def write(self, data): |
|
|
def write(self, data): |
|
|
""" |
|
|
""" |
|
|
Writes data to the device. |
|
|
Writes data to the device. |
|
@@ -557,6 +561,15 @@ class SocketDevice(Device): |
|
|
Serial to IP interface. |
|
|
Serial to IP interface. |
|
|
""" |
|
|
""" |
|
|
|
|
|
|
|
|
|
|
|
@property |
|
|
|
|
|
def ssl(self): |
|
|
|
|
|
""" |
|
|
|
|
|
Retrieves whether or not the device is using SSL. |
|
|
|
|
|
|
|
|
|
|
|
:returns: Whether or not the device is using SSL. |
|
|
|
|
|
""" |
|
|
|
|
|
return self._use_ssl |
|
|
|
|
|
|
|
|
@property |
|
|
@property |
|
|
def ssl_certificate(self): |
|
|
def ssl_certificate(self): |
|
|
""" |
|
|
""" |
|
@@ -681,17 +694,16 @@ class SocketDevice(Device): |
|
|
""" |
|
|
""" |
|
|
Closes the device. |
|
|
Closes the device. |
|
|
""" |
|
|
""" |
|
|
self._running = False |
|
|
|
|
|
|
|
|
|
|
|
try: |
|
|
try: |
|
|
self._read_thread.stop() |
|
|
|
|
|
self._device.shutdown(socket.SHUT_RDWR) # Make sure that it closes immediately. |
|
|
|
|
|
self._device.close() |
|
|
|
|
|
|
|
|
if self.ssl: |
|
|
|
|
|
self._device.shutdown() |
|
|
|
|
|
else: |
|
|
|
|
|
self._device.shutdown(socket.SHUT_RDWR) # Make sure that it closes immediately. |
|
|
|
|
|
|
|
|
except: |
|
|
|
|
|
pass |
|
|
|
|
|
|
|
|
super(SocketDevice, self).close() |
|
|
|
|
|
|
|
|
self.on_close() |
|
|
|
|
|
|
|
|
except Exception, ex: |
|
|
|
|
|
pass |
|
|
|
|
|
|
|
|
def write(self, data): |
|
|
def write(self, data): |
|
|
""" |
|
|
""" |
|
|