Skip to content

Commit

Permalink
modified connectToPort to prevent crash in Windows and OSX
Browse files Browse the repository at this point in the history
  • Loading branch information
viveksb007 committed Apr 18, 2017
1 parent e86be68 commit ee92d0d
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions PSL/packet_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,16 @@ def listPorts(self):
return glob.glob('/dev/ttyACM*') + glob.glob('/dev/ttyUSB*')

def connectToPort(self, portname):
import socket
try:
self.blockingSocket = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
self.blockingSocket.bind('\0PSghhhLab%s' % portname)
self.blockingSocket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
except socket.error as e:
self.occupiedPorts.add(portname)
raise RuntimeError("Another program is using %s (%d)" % (portname))
import platform
if platform.system() not in ["Windows", "Darwin"]:
import socket
try:
self.blockingSocket = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
self.blockingSocket.bind('\0PSghhhLab%s' % portname)
self.blockingSocket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
except socket.error as e:
self.occupiedPorts.add(portname)
raise RuntimeError("Another program is using %s (%d)" % (portname))

fd = serial.Serial(portname, 9600, stopbits=1, timeout=0.02)
fd.read(100)
Expand Down

0 comments on commit ee92d0d

Please sign in to comment.