Commit 2bbc80ef authored by Guillaume Seguin's avatar Guillaume Seguin

Cleanup serial port detection

parent 040b89f2
...@@ -462,7 +462,7 @@ class pronsole(cmd.Cmd): ...@@ -462,7 +462,7 @@ class pronsole(cmd.Cmd):
pass pass
for g in ['/dev/ttyUSB*', '/dev/ttyACM*', "/dev/tty.*", "/dev/cu.*", "/dev/rfcomm*"]: for g in ['/dev/ttyUSB*', '/dev/ttyACM*', "/dev/tty.*", "/dev/cu.*", "/dev/rfcomm*"]:
baselist+=glob.glob(g) baselist += glob.glob(g)
return filter(self._bluetoothSerialFilter, baselist) return filter(self._bluetoothSerialFilter, baselist)
def _bluetoothSerialFilter(self, serial): def _bluetoothSerialFilter(self, serial):
......
...@@ -534,20 +534,6 @@ class PronterWindow(MainWindow, pronsole.pronsole): ...@@ -534,20 +534,6 @@ class PronterWindow(MainWindow, pronsole.pronsole):
return return
wx.CallAfter(self.addtexttolog,l); wx.CallAfter(self.addtexttolog,l);
def scanserial(self):
"""scan for available ports. return a list of device names."""
baselist = []
if os.name == "nt":
try:
key = _winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE, "HARDWARE\\DEVICEMAP\\SERIALCOMM")
i = 0
while True:
baselist += [_winreg.EnumValue(key, i)[1]]
i += 1
except:
pass
return baselist+glob.glob('/dev/ttyUSB*') + glob.glob('/dev/ttyACM*') + glob.glob("/dev/tty.*") + glob.glob("/dev/cu.*") + glob.glob("/dev/rfcomm*")
def project(self,event): def project(self,event):
from printrun import projectlayer from printrun import projectlayer
projectlayer.SettingsFrame(self, self.p).Show() projectlayer.SettingsFrame(self, self.p).Show()
...@@ -651,19 +637,16 @@ class PronterWindow(MainWindow, pronsole.pronsole): ...@@ -651,19 +637,16 @@ class PronterWindow(MainWindow, pronsole.pronsole):
self.Close() self.Close()
def rescanports(self, event = None): def rescanports(self, event = None):
scan = self.scanserial() scanned = self.scanserial()
portslist = list(scan) portslist = list(scanned)
if self.settings.port != "" and self.settings.port not in portslist: if self.settings.port != "" and self.settings.port not in portslist:
portslist += [self.settings.port] portslist.append(self.settings.port)
self.serialport.Clear() self.serialport.Clear()
self.serialport.AppendItems(portslist) self.serialport.AppendItems(portslist)
try: if os.path.exists(self.settings.port) or self.settings.port in scanned:
if os.path.exists(self.settings.port) or self.settings.port in scan: self.serialport.SetValue(self.settings.port)
self.serialport.SetValue(self.settings.port) elif portslist:
elif len(portslist) > 0: self.serialport.SetValue(portslist[0])
self.serialport.SetValue(portslist[0])
except:
pass
def cbkey(self, e): def cbkey(self, e):
if e.GetKeyCode() == wx.WXK_UP: if e.GetKeyCode() == wx.WXK_UP:
...@@ -1591,17 +1574,18 @@ class PronterWindow(MainWindow, pronsole.pronsole): ...@@ -1591,17 +1574,18 @@ class PronterWindow(MainWindow, pronsole.pronsole):
def connect(self, event = None): def connect(self, event = None):
print _("Connecting...") print _("Connecting...")
port = None port = None
try: if self.serialport.GetValue():
port = self.scanserial()[0]
except:
pass
if self.serialport.GetValue()!="":
port = str(self.serialport.GetValue()) port = str(self.serialport.GetValue())
else:
scanned = self.scanserial()
if scanned:
port = scanned[0]
baud = 115200 baud = 115200
try: try:
baud = int(self.baud.GetValue()) baud = int(self.baud.GetValue())
except: except:
pass print _("Could not parse baud rate: ")
traceback.print_exc(file = sys.stdout)
if self.paused: if self.paused:
self.p.paused = 0 self.p.paused = 0
self.p.printing = 0 self.p.printing = 0
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment