-
Notifications
You must be signed in to change notification settings - Fork 39
/
ConectorDriverComando.py
36 lines (27 loc) · 1.23 KB
/
ConectorDriverComando.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# -*- coding: iso-8859-1 -*-
import importlib
import logging
class ConectorError(Exception):
pass
class ConectorDriverComando:
driver = None
def __init__(self, comando, driver, *args, **kwargs):
self.logger = logging.getLogger("ConectorDriverComando")
self.logger.info(f"Inicializando ConectorDriverComando driver de '${driver}'")
self._comando = comando
self.driver_name = driver
# instanciar el driver dinamicamente segun el driver pasado como parametro
libraryName = "Drivers." + driver + "Driver"
driverModule = importlib.import_module(libraryName)
driverClass = getattr(driverModule, driver + "Driver")
self.driver = driverClass(**kwargs)
def sendCommand(self, *args):
self.logger.info(f"Enviando comando '${args}'")
return self.driver.sendCommand(*args)
def close(self):
# Si el driver es Receipt, se cierra desde la misma clase del driver, sino, tira error de Bad File Descriptor por querer cerrarlo dos veces.
if self.driver_name == "ReceiptDirectJet":
if self.driver.connected is False:
return None
self.driver.close()
self.driver = None