class Connection: def __init__(self, address, device_id): self.address = address self.device_id = device_id self.dev = MettlerToledoDevice(port=self.address) def get_weight(self): weight = self.dev.get_weight() return { 'value': weight[0], 'unit': weight[1], 'stable': True if weight[2] is 'S' else False } def get_info(self): data = self.dev.get_balance_data() sn = self.dev.get_serial_number() sw = self.dev.get_software_version() if len(data) > 3: info = { 'model': data[0], 'model-type': data[1], 'sn': sn, 'sw-version': sw[0], 'sw-type': sw[1], 'capacity': data[1], 'unit': data[2] } else: info = { 'model': data[0], 'sn': sn, 'sw-version': sw[0], 'sw-type': sw[1], 'capacity': data[1], 'unit': data[2] } return info def get_address(self): return self.dev.get_port() def close(self): self.dev.close()
from mettler_toledo_device import MettlerToledoDevice dev = MettlerToledoDevice() # Might automatically find device if one available # if it is not found automatically, specify port directly #dev = MettlerToledoDevice(port='/dev/ttyUSB0') # Linux specific port dev = MettlerToledoDevice(port='/dev/ttyACM0') # Linux specific port for abstract control model dev = MettlerToledoDevice(port='/dev/tty.usbmodem262471') # Mac OS X specific port #dev = MettlerToledoDevice(port='COM3') # Windows specific port dev.get_serial_number() #1126493049 dev.get_balance_data() #['XS204', 'Excellence', '220.0090', 'g'] dev.get_weight_stable() #[-0.0082, 'g'] #if weight is stable #None #if weight is dynamic dev.get_weight() #[-0.6800, 'g', 'S'] #if weight is stable #[-0.6800, 'g', 'D'] #if weight is dynamic dev.zero_stable() #True #zeros if weight is stable #False #does not zero if weight is not stable dev.zero() #'S' #zeros if weight is stable #'D' #zeros if weight is dynamic
from mettler_toledo_device import MettlerToledoDevice dev = MettlerToledoDevice() # Might automatically find device if one available # if it is not found automatically, specify port directly #dev = MettlerToledoDevice(port='/dev/ttyUSB0') # Linux specific port dev = MettlerToledoDevice( port='/dev/ttyACM0') # Linux specific port for abstract control model dev = MettlerToledoDevice( port='/dev/tty.usbmodem262471') # Mac OS X specific port #dev = MettlerToledoDevice(port='COM3') # Windows specific port dev.get_serial_number() #1126493049 dev.get_balance_data() #['XS204', 'Excellence', '220.0090', 'g'] dev.get_weight_stable() #[-0.0082, 'g'] #if weight is stable #None #if weight is dynamic dev.get_weight() #[-0.6800, 'g', 'S'] #if weight is stable #[-0.6800, 'g', 'D'] #if weight is dynamic dev.zero_stable() #True #zeros if weight is stable #False #does not zero if weight is not stable dev.zero() #'S' #zeros if weight is stable #'D' #zeros if weight is dynamic