From f29b670361141957dd4c2e1a131f1ce06cac2a0b Mon Sep 17 00:00:00 2001 From: Vasilis Vlachoudis Date: Thu, 28 Jan 2016 20:56:32 +0100 Subject: [PATCH] - Added user selectable choice for other controllers - If smoothie is selected all g-code is converted to upper case Some commands are translated to Smoothie equivalent --- FilePage.py | 21 +++++++++++++++++++- Sender.py | 51 +++++++++++++++++++++++++++++++++++++---------- TerminalPage.py | 1 + Utils.py | 11 ++++++++++ bCNC.ini | 53 +++++++++++++++++++++++++------------------------ 5 files changed, 99 insertions(+), 38 deletions(-) diff --git a/FilePage.py b/FilePage.py index f25cfbe7b..9b9132e47 100644 --- a/FilePage.py +++ b/FilePage.py @@ -250,7 +250,21 @@ def __init__(self, master, app): # --- row += 1 - b= Checkbutton(self, text=_("Connect on startup"), + b = Label(self, text=_("Controller:"), background=Ribbon._BACKGROUND) + b.grid(row=row,column=col,sticky=E) + + self.ctrlCombo = tkExtra.Combobox(self, True, + background="White", + command=self.ctrlChange) + self.ctrlCombo.grid(row=row, column=col+1, sticky=EW) + tkExtra.Balloon.set(self.ctrlCombo, _("Select controller board")) + self.ctrlCombo.fill(sorted(Utils.CONTROLLER.keys())) + self.ctrlCombo.set(Utils.controllerName(app.controller)) + self.addWidget(self.ctrlCombo) + + # --- + row += 1 + b= Checkbutton(self, text=_("Connect on startup"), variable=self.autostart) b.grid(row=row, column=col, columnspan=2, sticky=W) tkExtra.Balloon.set(b, _("Connect to serial on startup of the program")) @@ -271,9 +285,14 @@ def __init__(self, master, app): tkExtra.Balloon.set(self.connectBtn, _("Open/Close serial port")) self.grid_columnconfigure(1, weight=1) + #----------------------------------------------------------------------- + def ctrlChange(self): + self.app.controller = Utils.CONTROLLER.get(self.ctrlCombo.get(), 0) + #----------------------------------------------------------------------- def saveConfig(self): # Connection + Utils.setStr("Connection", "controller", Utils.controllerName(self.app.controller)) Utils.setStr("Connection", "port", self.portCombo.get()) Utils.setStr("Connection", "baud", self.baudCombo.get()) Utils.setBool("Connection", "openserial", self.autostart.get()) diff --git a/Sender.py b/Sender.py index 0df0ea917..b3885beeb 100644 --- a/Sender.py +++ b/Sender.py @@ -114,6 +114,7 @@ def __init__(self): self.pendant = Queue() # Command queue to be executed from Pendant self.serial = None self.thread = None + self.controller = Utils.CONTROLLER["Grbl"] self._posUpdate = False # Update position self._probeUpdate= False # Update probe @@ -135,7 +136,8 @@ def quit(self, event=None): #---------------------------------------------------------------------- def loadConfig(self): - Pendant.port = Utils.getInt("Connection","pendantport",Pendant.port) + self.controller = Utils.CONTROLLER.get(Utils.getStr("Connection", "controller"), 0) + Pendant.port = Utils.getInt("Connection","pendantport",Pendant.port) GCode.LOOP_MERGE = Utils.getBool("File","dxfloopmerge") self.loadHistory() @@ -277,6 +279,17 @@ def executeCommand(self, line): elif rexx.abbrev("UNLOCK",cmd,3): self.unlock() + # Send commands to SMOOTHIE + elif self.controller == Utils.SMOOTHIE: + if line[0] in ( "help", "version", "mem", "ls", + "cd", "pwd", "cat", "rm", "mv", + "remount", "play", "progress", "abort", + "reset", "dfu", "break", "config-get", + "config-set", "get", "set_temp", "get", + "get", "net", "load", "save", "upload", + "calc_thermistor", "thermistors", "md5sum"): + self.serial.write(oline+"\n") + else: return _("unknown command"),_("Invalid command %s")%(oline) @@ -442,7 +455,10 @@ def hardReset(self): #---------------------------------------------------------------------- def softReset(self): if self.serial: - self.serial.write(b"\030") + if self.controller == Utils.GRBL: + self.serial.write(b"\030") + elif self.controller == Utils.SMOOTHIE: + self.serial.write("reset\n") self.stopProbe() self._alarm = False @@ -458,34 +474,46 @@ def home(self): #---------------------------------------------------------------------- def viewSettings(self): - self.sendGrbl("$$\n") + if self.controller == Utils.GRBL: + self.sendGrbl("$$\n") def viewParameters(self): - self.sendGrbl("$#\n$G\n") + self.sendGrbl("$#\n") def viewState(self): self.sendGrbl("$G\n") def viewBuild(self): - self.sendGrbl("$I\n") + if self.controller == Utils.GRBL: + self.sendGrbl("$I\n") + elif self.controller == Utils.SMOOTHIE: + self.serial.write("version\n") def viewStartup(self): - self.sendGrbl("$N\n") + if self.controller == Utils.GRBL: + self.sendGrbl("$N\n") def checkGcode(self): - self.sendGrbl("$C\n") + if self.controller == Utils.GRBL: + self.sendGrbl("$C\n") def grblHelp(self): - self.sendGrbl("$\n") + if self.controller == Utils.GRBL: + self.sendGrbl("$\n") + elif self.controller == Utils.SMOOTHIE: + self.serial.write("help\n") def grblRestoreSettings(self): - self.sendGrbl("$RST=$\n") + if self.controller == Utils.GRBL: + self.sendGrbl("$RST=$\n") def grblRestoreWCS(self): - self.sendGrbl("$RST=#\n") + if self.controller == Utils.GRBL: + self.sendGrbl("$RST=#\n") def grblRestoreAll(self): - self.sendGrbl("$RST=#\n") + if self.controller == Utils.GRBL: + self.sendGrbl("$RST=#\n") #---------------------------------------------------------------------- def goto(self, x=None, y=None, z=None): @@ -815,6 +843,7 @@ def serialIO(self): # if not tosend: tosend = None #print ">S>",repr(tosend),"stack=",sline,"sum=",sum(cline) + if self.controller==Utils.SMOOTHIE: tosend = tosend.upper() self.serial.write(bytes(tosend)) # self.serial.flush() diff --git a/TerminalPage.py b/TerminalPage.py index 57c5bb0b4..b327d7bb7 100644 --- a/TerminalPage.py +++ b/TerminalPage.py @@ -51,6 +51,7 @@ def __init__(self, master, app): text=_("Settings"), compound=LEFT, anchor=W, + #state=app.controller==Utils.GRBL and NORMAL or DISABLED, command=self.app.viewSettings, background=Ribbon._BACKGROUND) b.grid(row=row, column=col, padx=0, pady=0, sticky=NSEW) diff --git a/Utils.py b/Utils.py index c5c0147d3..448e3f3f1 100644 --- a/Utils.py +++ b/Utils.py @@ -65,6 +65,10 @@ _FONT_SECTION = "Font" +GRBL = 0 +SMOOTHIE = 1 +CONTROLLER = {"Grbl":0, "Smoothie":1} + #------------------------------------------------------------------------------ def loadIcons(): global icons @@ -236,6 +240,13 @@ def setUtf(section, name, value): setInt = setStr setFloat = setStr +#------------------------------------------------------------------------------- +def controllerName(idx): + for n,i in CONTROLLER.items(): + if i==idx: + return n + return "unknown" + #------------------------------------------------------------------------------- # Add Recent #------------------------------------------------------------------------------- diff --git a/bCNC.ini b/bCNC.ini index 21edd30ae..c9ef20888 100644 --- a/bCNC.ini +++ b/bCNC.ini @@ -23,30 +23,31 @@ terminal.ribbon = Commands Terminal terminal.page = DRO Terminal* [Connection] -baud = 115200 -port = -pendant = 1 +baud = 115200 +port = +pendant = 1 pendantport = 8080 -openserial = 0 +openserial = 0 errorreport = 1 +controller = Grbl [Control] -step = 1 -wcs = 54 +step = 1 +wcs = 54 ;zstep = 1 -step1=0.1 -step2=1 -step3=10 +step1 = 0.1 +step2 = 1 +step3 = 10 [Canvas] -view = X-Y +view = X-Y workarea = 1 -margin = 1 -grid = 1 -axes = 1 -probe = 1 -rapid = 1 -paths = 1 +margin = 1 +grid = 1 +axes = 1 +probe = 1 +rapid = 1 +paths = 1 [Error] @@ -54,16 +55,16 @@ paths = 1 x = y = z = -xmin = 0.0 -xmax = 100.0 -xn = 5 -ymin = 0.0 -ymax = 100.0 -yn = 5 -zmin = -10.0 -zmax = 5.0 -feed = 10.0 -tlo = 0.0 +xmin = 0.0 +xmax = 100.0 +xn = 5 +ymin = 0.0 +ymax = 100.0 +yn = 5 +zmin = -10.0 +zmax = 5.0 +feed = 10.0 +tlo = 0.0 center = 10.0 cmd = G38.2 toolpolicy = 1