def initSerial(self, device, br=250000): self.port = device self.baudrate = br self.timeout = 0.05 self.writeTimeout = 10 self.open() if not self.usbId: print "Initial bootloader wait..." time.sleep(1) # Store usb information for later re-connection even if device # name has changed: comports = list_ports.comports() # ('/dev/ttyACM0', 'ttyACM0', 'USB VID:PID=2341:0042 SNR=75237333536351815111')] for (dev, name, usbid) in comports: if dev == device or name == device: self.gui.log("Found usbid %s for device %s" % (usbid, dev)) self.usbId = usbid break # Read left over garbage recvLine = self.safeReadline() while recvLine: self.gui.logRecv("Initial read: '%s'" % recvLine) self.gui.logRecv(recvLine.encode("hex"), "\n") recvLine = self.safeReadline()
def reconnect(self): # XXX add timeout, or otherwise prevent re-connection to power-cycled printer?! comports = list_ports.comports() # ('/dev/ttyACM0', 'ttyACM0', 'USB VID:PID=2341:0042 SNR=75237333536351815111')] for (dev, name, usbid) in comports: if usbid == self.usbId: print "reconnect(): found device %s, previous device: %s" % (dev, self.port) self.close() self.initSerial(dev, br=self.baudrate) return time.sleep(0.1)
def reconnect(self): # XXX add timeout, or otherwise prevent re-connection to power-cycled printer?! comports = list_ports.comports() # ('/dev/ttyACM0', 'ttyACM0', 'USB VID:PID=2341:0042 SNR=75237333536351815111')] for (dev, name, usbid) in comports: if usbid == self.usbId: print "reconnect(): found device %s, previous device: %s" % ( dev, self.port) self.close() self.initSerial(dev, br=self.baudrate) return time.sleep(0.1)
def initSerial(self, device, br=115200): self.port = device self.baudrate = br self.timeout = 0.05 self.writeTimeout = 10 self.open() # Store usb information for later re-connection even if device # name has changed: comports = list_ports.comports() # ('/dev/ttyACM0', 'ttyACM0', 'USB VID:PID=2341:0042 SNR=75237333536351815111')] for (dev, name, usbid) in comports: if dev == device or name == device: print "Found usbid %s for device %s" % (usbid, dev) self.usbId = usbid break
count = 1 seq = 0 save = list(range(1, 60)) print( "This is TermCIC's datalogger for ML-T Precision Balances and Scales (Mettler Toledo)." ) print( "Why making this program? Simple, the software provided by Mettler Toledo doesn't make sense." ) # Setting serial port print("Detecting serial ports...") t.sleep(1) ports = list_ports.comports() for p in ports: print(p.device) print(len(ports), 'ports found') portName = input("Select a serial port (e.g. type COM3): ") print("Connecting to {}...".format(portName)) t.sleep(1) ser = serial.Serial('{}'.format(portName), baudrate=9600, timeout=1) currentData = ser.readline() print("The current read from ML-T is {}".format(currentData)) print() # Select path to save data print("Detecting current directory...") t.sleep(1) root = tkinter.Tk()