def get_description(self): # Quick workaround to avoid calling FiscalPrinter.setup(), since that # may send commands to the ECF, and we just need the description. # TODO: Improve stoqdrivers so we can get this easyer port = VirtualPort() port.setTimeout = lambda x: True port.setParity = lambda x: True port.setWriteTimeout = lambda x: True driver = BasePrinter(brand=self.brand, model=self.model, port=port) return driver.get_model_name()
def get_interface(self): """ Based on the column values instantiate the stoqdrivers interface for the device itself. """ if self.device_name == '/dev/null': interface = 'serial' port = VirtualPort() product_id = vendor_id = None elif self.device_name.startswith('usb:'): # USB device interface, vendor_id, product_id = self.device_name.split(':') vendor_id = int(vendor_id, 16) product_id = int(product_id, 16) port = None else: # Serial device interface = 'serial' port = self._get_serial_port() product_id = vendor_id = None if self.type == DeviceSettings.CHEQUE_PRINTER_DEVICE: return ChequePrinter(brand=self.brand, model=self.model, port=port) elif self.type == DeviceSettings.NON_FISCAL_PRINTER_DEVICE: return NonFiscalPrinter(brand=self.brand, model=self.model, port=port, interface=interface, product_id=product_id, vendor_id=vendor_id) elif self.type == DeviceSettings.SCALE_DEVICE: return Scale(brand=self.brand, model=self.model, device=self.device_name, port=port) raise DatabaseInconsistency("The device type referred by this " "record (%r) is invalid, given %r." % (self, self.type))
def _create_port(self, baudrate): if self._device_name == '/dev/null': return VirtualPort() port = SerialPort(device=self._device_name, baudrate=baudrate) port.writeTimeout = 5 if platform.system() != 'Windows': port.nonblocking() return port
def get_fiscal_driver(self): if self.brand == 'virtual': port = VirtualPort() else: port = SerialPort(device=self.device_name, baudrate=self.baudrate) return FiscalPrinter(brand=self.brand, model=self.model, port=port)