import serial import time from tkinter import * import serial.tools.list_ports from tkinter import filedialog as fd import os import threading from gerbil.gerbil import Gerbil class touchCNC: def __init__(self, root): self.root = root # GUI Main self.buttonsize_x = 5 self.buttonsize_y = 3 self.increments = 0 self.BORDER = 2 self.states = {'M3': '0', 'M8': '0', 'M6': '0', 'G10': '0'} # self.spindle, Coolant, Toolchange self.dict_GCODE = {'G': '0', 'X': '0', 'Y': '0', 'Z': '0', 'I': '0', 'J': '0', 'F': '0' } # GUI Color Scheme self.attention = 'red' self.loaded = 'green' self.cooling = 'blue' self.toolchange = 'yellow' self.standard = '#17223B' self.feed = '#283B67' self.increments = IntVar() self.movement = Frame(root, relief='ridge', bd=self.BORDER) self.left = Button(root, text="-X", width=self.buttonsize_x, height=self.buttonsize_y, command=lambda: self.jogWrite('X', '-1', self.increments), bd=self.BORDER, bg=self.standard) self.right = Button(root, text="+X", width=self.buttonsize_x, height=self.buttonsize_y, command=lambda: self.jogWrite('X', '1', self.increments), bd=self.BORDER, bg=self.standard) self.up = Button(root, text="+Y", width=self.buttonsize_x, height=self.buttonsize_y, command=lambda: self.jogWrite('Y', '1', self.increments), bd=self.BORDER, bg=self.standard) self.down = Button(root, text="-Y", width=self.buttonsize_x, height=self.buttonsize_y, command=lambda: self.jogWrite('Y', '-1', self.increments), bd=self.BORDER, bg=self.standard) self.z_up = Button(root, text="+Z", width=self.buttonsize_x, height=self.buttonsize_y, command=lambda: self.jogWrite('Z', '1', self.increments), bd=self.BORDER, bg=self.standard) self.z_down = Button(root, text="-Z", width=self.buttonsize_x, height=self.buttonsize_y, command=lambda: self.jogWrite('Z', '-1', self.increments), bd=self.BORDER, bg=self.standard) self.zero_x = Button(root, text="zero X", width=self.buttonsize_x, height=1, command=lambda: self.directWrite('G10 P0 L20 X0'), bd=self.BORDER) self.zero_y = Button(root, text="zero Y", width=self.buttonsize_x, height=1, command=lambda: self.directWrite('G10 P0 L20 Y0'), bd=self.BORDER) self.zero_z = Button(root, text="zero Z", width=self.buttonsize_x, height=1, command=lambda: self.directWrite('G10 P0 L20 Z0'), bd=self.BORDER) self.zero_all = Button(root, text="zeroAll", width=self.buttonsize_x, height=3, command=lambda: self.latchWrite('G10'), bd=self.BORDER, bg='magenta') self.setzero = Button(root, text="SetPOS", width=self.buttonsize_x, height=self.buttonsize_y, command=lambda: self.directWrite('G28.1'), bd=self.BORDER) self.gozero = Button(root, text="GoPOS", width=self.buttonsize_x, height=self.buttonsize_y, command=lambda: self.directWrite('G28'), bd=self.BORDER) self.connect_ser = Button(root, text="Cnnct", width=self.buttonsize_x, height=self.buttonsize_y, command=self.grblConnect2, bg='grey', bd=self.BORDER) self.discon_ser = Button(root, text="Dsconct", width=self.buttonsize_x, height=self.buttonsize_y, command= self.grblClose, bd=self.BORDER) self.unlock = Button(root, text="Unlock", width=self.buttonsize_x, height=self.buttonsize_y, command=lambda: self.directWrite('$X'), bd=self.BORDER) self.start = Button(root, text="START", width=self.buttonsize_x, height=self.buttonsize_y, bg=self.attention, command=self.grblWrite, bd=self.BORDER) self.stop = Button(root, text="STOP", width=self.buttonsize_x, height=self.buttonsize_y, bd=self.BORDER, command=self.grblStop) self.pause = Button(root, text="PAUSE", width=self.buttonsize_x, height=self.buttonsize_y, bg=self.cooling, bd=self.BORDER, command=self.grblPause) self.resume = Button(root, text="RESUME", width=self.buttonsize_x, height=self.buttonsize_y, bd=self.BORDER, command=lambda: self.directWrite('~')) self.fopen = Button(root, text="GCODE", width=self.buttonsize_x, height=self.buttonsize_y, bg='grey', fg='black', command=self.openGCODE, bd=self.BORDER) self.spindle = Button(root, text="Spindle", width=self.buttonsize_x, height=self.buttonsize_y, command=lambda: self.latchWrite('M3')) self.coolant = Button(root, text="Coolant", width=self.buttonsize_x, height=self.buttonsize_y, command=lambda: self.latchWrite('M8')) self.tool = Button(root, text="Tool", width=self.buttonsize_x, height=self.buttonsize_y, command=lambda: self.latchWrite('M6')) self.macro = Button(root, text="Macro1", width=self.buttonsize_x, height=self.buttonsize_y, command=lambda: self.directWrite(' G91 G0 X10 Y10 Z50 F1000')) self.inc1 = Button(root, text="Inc 1%", width=self.buttonsize_x, height=self.buttonsize_y, command=lambda: self.directWrite('‘'), bg=self.feed) self.inc10 = Button(root, text="Inc 10%", width=self.buttonsize_x, height=self.buttonsize_y, command=lambda: self.directWrite('“'), bg=self.feed) self.dec1 = Button(root, text="Dec 1%", width=self.buttonsize_x, height=self.buttonsize_y, command=lambda: self.directWrite('”'), bg=self.feed) self.dec10 = Button(root, text="Dec 10%", width=self.buttonsize_x, height=self.buttonsize_y, command=lambda: self.directWrite('’'), bg=self.feed) self.reset = Button(root, text="