def __init__(self): for myport in comports(): if myport.vid == VID_CP210X: self.hdr = Serial(port=myport.name, baudrate=115200, timeout=1) log.info('connected to %s', myport.name) break else: raise Exception('COM port not found')
def updateSpeed(self, mmpm): mmps = mmpm / 60 log.info(mmps) if mmps < setting.get('speed').get('min'): self.cur_speed = setting.get('speed').get('min') elif mmps > setting.get('speed').get('max'): self.cur_speed = setting.get('speed').get('max') else: self.cur_speed = mmps log.info('updated speed: %d', self.cur_speed)
def exeGcode(self, gcodePath): """ To execute gcode command in the gcodePath file line by line """ try: with open(gcodePath, 'r') as gcodeHdr: #--- whole logic inside --- line_num = 0 for line in gcodeHdr: # loop through line in file line_num += 1 # strip out space, \n characters line = line.strip() if not line or line.startswith('#'): # ignore on empty or comment lines continue log.info(str(line_num) + ' ' + line) gc_box = gcode_parse(line) # update speed if F is available if 'F' in gc_box: self.updateSpeed(gc_box.get('F')) gc_cmd = gc_box.get('cmd') if gc_cmd == 'G0': pass elif gc_cmd == 'G1': pass elif gc_cmd == 'G2': pass elif gc_cmd == 'G3': pass elif gc_cmd == 'G90': self.is_absolute = True elif gc_cmd == 'G91': self.is_absolute = False elif gc_cmd == 'M03': pass elif gc_cmd == 'M05': pass except Exception as e: log.error(e) finally: log.info('execute gcode terminated')
def app(): initLog("./output/") intro() args = sys.argv[1:] if len(args) == 0: log.error('no command') else: d = draw() createUart() command, args = args[0], args[1:] if command == 'help': showHelp() elif command == 'gcode': try: d.exeGcode(args[0]) except: log.error('gcode: missing file path') elif command == 'test': com.send('abcd') else: log.info("unknown command!")
def showHelp(): log.info("cmd: Description")
def intro(): log.info(" ------------------------------------ ") log.info(" -------------- PYDRAW -------------- ") log.info(" ------------------------------------ ")
def loadSetting(jsonPath): global setting with open(jsonPath, 'r') as js: setting = json.load(js) log.info('Drawing setting %s', setting)
def showProperties(self): log.info('cur_x %f cur_y %f cur_speed %f', self.cur_x, self.cur_y, self.cur_speed)