mirror of
https://github.com/Ircama/epson_print_conf.git
synced 2025-06-06 01:21:37 -04:00
Refinements
This commit is contained in:
parent
3571c365d9
commit
f77584307d
2 changed files with 69 additions and 37 deletions
74
README.md
74
README.md
|
@ -18,6 +18,7 @@ The software also provides a configurable printer dictionary, which can be easil
|
||||||
|
|
||||||
```
|
```
|
||||||
git clone https://github.com/Ircama/epson_print_conf
|
git clone https://github.com/Ircama/epson_print_conf
|
||||||
|
pip3 install pyyaml
|
||||||
pip3 install pyasn1==0.4.8
|
pip3 install pyasn1==0.4.8
|
||||||
pip3 install git+https://github.com/etingof/pysnmp.git
|
pip3 install git+https://github.com/etingof/pysnmp.git
|
||||||
cd epson_print_conf
|
cd epson_print_conf
|
||||||
|
@ -35,11 +36,12 @@ It is tested with Ubuntu / Windows Subsystem for Linux, Windows.
|
||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
```
|
```
|
||||||
usage: epson_print_conf.py [-h] -m MODEL -a HOSTNAME [-i] [-q QUERY] [--reset_waste_ink]
|
usage: epson_print_conf.py [-h] -m MODEL -a HOSTNAME [-p PORT] [-i] [-q QUERY_NAME]
|
||||||
[--detect-key] [-d] [-e DUMP_EEPROM DUMP_EEPROM] [--dry-run]
|
[--reset_waste_ink] [-d]
|
||||||
[--write-first-ti-received-time YEAR MONTH DAY] [-R READ_EEPROM]
|
[--write-first-ti-received-time YEAR MONTH DAY] [--dry-run]
|
||||||
[-W WRITE_EEPROM] [-S WS_TO_STRING] [-t TIMEOUT] [-r RETRIES]
|
[-R ADDRESS_SET] [-W ADDRESS_VALUE_SET] [-e FIRST_ADDRESS LAST_ADDRESS]
|
||||||
[-c CONFIG_FILE]
|
[--detect-key] [-S SEQUENCE_STRING] [-t TIMEOUT] [-r RETRIES]
|
||||||
|
[-c CONFIG_FILE] [--simdata SIMDATA_FILE]
|
||||||
|
|
||||||
optional arguments:
|
optional arguments:
|
||||||
-h, --help show this help message and exit
|
-h, --help show this help message and exit
|
||||||
|
@ -47,32 +49,35 @@ optional arguments:
|
||||||
Printer model. Example: -m XP-205 (use ? to print all supported models)
|
Printer model. Example: -m XP-205 (use ? to print all supported models)
|
||||||
-a HOSTNAME, --address HOSTNAME
|
-a HOSTNAME, --address HOSTNAME
|
||||||
Printer host name or IP address. (Example: -m 192.168.1.87)
|
Printer host name or IP address. (Example: -m 192.168.1.87)
|
||||||
|
-p PORT, --port PORT Printer port (default is 161)
|
||||||
-i, --info Print all available information and statistics (default option)
|
-i, --info Print all available information and statistics (default option)
|
||||||
-q QUERY, --query QUERY
|
-q QUERY_NAME, --query QUERY_NAME
|
||||||
Print specific information. (Use ? to list all available queries)
|
Print specific information. (Use ? to list all available queries)
|
||||||
--reset_waste_ink Reset all waste ink levels to 0
|
--reset_waste_ink Reset all waste ink levels to 0
|
||||||
--detect-key Detect the read_key via brute force
|
|
||||||
-d, --debug Print debug information
|
-d, --debug Print debug information
|
||||||
-e DUMP_EEPROM DUMP_EEPROM, --eeprom-dump DUMP_EEPROM DUMP_EEPROM
|
|
||||||
Dump EEPROM (arguments: start, stop)
|
|
||||||
--dry-run Dry-run change operations
|
|
||||||
--write-first-ti-received-time YEAR MONTH DAY
|
--write-first-ti-received-time YEAR MONTH DAY
|
||||||
Change the first TI received time
|
Change the first TI received time
|
||||||
-R READ_EEPROM, --read-eeprom READ_EEPROM
|
--dry-run Dry-run change operations
|
||||||
Read the values of a list of printer EEPROM addreses. Format is: address [,
|
-R ADDRESS_SET, --read-eeprom ADDRESS_SET
|
||||||
...]
|
Read the values of a list of printer EEPROM addreses. Format is: address
|
||||||
-W WRITE_EEPROM, --write-eeprom WRITE_EEPROM
|
[, ...]
|
||||||
|
-W ADDRESS_VALUE_SET, --write-eeprom ADDRESS_VALUE_SET
|
||||||
Write related values to a list of printer EEPROM addresses. Format is:
|
Write related values to a list of printer EEPROM addresses. Format is:
|
||||||
address: value [, ...]
|
address: value [, ...]
|
||||||
-S WS_TO_STRING, --write-sequence-to-string WS_TO_STRING
|
-e FIRST_ADDRESS LAST_ADDRESS, --eeprom-dump FIRST_ADDRESS LAST_ADDRESS
|
||||||
|
Dump EEPROM
|
||||||
|
--detect-key Detect the read_key via brute force
|
||||||
|
-S SEQUENCE_STRING, --write-sequence-to-string SEQUENCE_STRING
|
||||||
Convert write sequence of numbers to string.
|
Convert write sequence of numbers to string.
|
||||||
-t TIMEOUT, --timeout TIMEOUT
|
-t TIMEOUT, --timeout TIMEOUT
|
||||||
SNMP GET timeout (floating point argument)
|
SNMP GET timeout (floating point argument)
|
||||||
-r RETRIES, --retries RETRIES
|
-r RETRIES, --retries RETRIES
|
||||||
SNMP GET retries (floating point argument)
|
SNMP GET retries (floating point argument)
|
||||||
-c CONFIG_FILE, --config CONFIG_FILE
|
-c CONFIG_FILE, --config CONFIG_FILE
|
||||||
read a configuration file including the full log dump of a previous operation
|
read a configuration file including the full log dump of a previous
|
||||||
with '-d' flag (instead of accessing the printer via SNMP)
|
operation with '-d' flag (instead of accessing the printer via SNMP)
|
||||||
|
--simdata SIMDATA_FILE
|
||||||
|
write SNMP dictionary map to simdata file
|
||||||
|
|
||||||
Epson Printer Configuration via SNMP (TCP/IP)
|
Epson Printer Configuration via SNMP (TCP/IP)
|
||||||
```
|
```
|
||||||
|
@ -110,6 +115,30 @@ python3 epson_print_conf.py -m XP-205 -a 192.168.1.87 -R 173,172
|
||||||
|
|
||||||
## API Interface
|
## API Interface
|
||||||
|
|
||||||
|
### Specification
|
||||||
|
|
||||||
|
```python
|
||||||
|
EpsonPrinter(model, hostname, port, timeout, retries, dry_run)
|
||||||
|
```
|
||||||
|
|
||||||
|
- `model`: printer model
|
||||||
|
- `hostname`: IP address or network name of the printer
|
||||||
|
- `port`: SNMP port number (default is 161)
|
||||||
|
- `timeout`: printer connection timeout in seconds (float)
|
||||||
|
- `retries`: connection retries if error or timeout occurred
|
||||||
|
- `dry_run`: boolean (True if write dry-run mode is enabled)
|
||||||
|
|
||||||
|
### Exceptions
|
||||||
|
|
||||||
|
```
|
||||||
|
TimeoutError
|
||||||
|
ValueError
|
||||||
|
```
|
||||||
|
|
||||||
|
(And *pysnmp* exceptions.)
|
||||||
|
|
||||||
|
### Sample
|
||||||
|
|
||||||
```python
|
```python
|
||||||
import epson_print_conf
|
import epson_print_conf
|
||||||
import logging
|
import logging
|
||||||
|
@ -117,7 +146,7 @@ import logging
|
||||||
logging.basicConfig(level=logging.DEBUG, format="%(message)s") # if logging is needed
|
logging.basicConfig(level=logging.DEBUG, format="%(message)s") # if logging is needed
|
||||||
|
|
||||||
printer = epson_print_conf.EpsonPrinter(
|
printer = epson_print_conf.EpsonPrinter(
|
||||||
printer_model="XP-205", hostname="192.168.1.87")
|
model="XP-205", hostname="192.168.1.87")
|
||||||
|
|
||||||
if not printer.parm:
|
if not printer.parm:
|
||||||
print("Unknown printer")
|
print("Unknown printer")
|
||||||
|
@ -152,15 +181,6 @@ printer.brute_force_read_key()
|
||||||
printer.write_first_ti_received_time(2000, 1, 2)
|
printer.write_first_ti_received_time(2000, 1, 2)
|
||||||
```
|
```
|
||||||
|
|
||||||
### Exceptions
|
|
||||||
|
|
||||||
```
|
|
||||||
TimeoutError
|
|
||||||
ValueError
|
|
||||||
```
|
|
||||||
|
|
||||||
(And *pysnmp* exceptions.)
|
|
||||||
|
|
||||||
## Output example
|
## Output example
|
||||||
Example of advanced printer status with an XP-205 printer:
|
Example of advanced printer status with an XP-205 printer:
|
||||||
|
|
||||||
|
|
|
@ -301,7 +301,7 @@ class EpsonPrinter:
|
||||||
eeprom_link: str = f'{SNMP_OID_ENTERPRISE}.{SNMP_EPSON}.{OID_PRV_CTRL}.1'
|
eeprom_link: str = f'{SNMP_OID_ENTERPRISE}.{SNMP_EPSON}.{OID_PRV_CTRL}.1'
|
||||||
|
|
||||||
session: object
|
session: object
|
||||||
printer_model: str
|
model: str
|
||||||
hostname: str
|
hostname: str
|
||||||
parm: dict
|
parm: dict
|
||||||
mib_dict: dict = {}
|
mib_dict: dict = {}
|
||||||
|
@ -317,11 +317,13 @@ class EpsonPrinter:
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
printer_model: str = None,
|
model: str = None,
|
||||||
hostname: str = None,
|
hostname: str = None,
|
||||||
|
port: int = 161,
|
||||||
timeout: (None, float) = None,
|
timeout: (None, float) = None,
|
||||||
retries: (None, float) = None,
|
retries: (None, float) = None,
|
||||||
dry_run: bool = False) -> None:
|
dry_run: bool = False
|
||||||
|
) -> None:
|
||||||
"""Initialise printer model."""
|
"""Initialise printer model."""
|
||||||
# process "alias" definintion
|
# process "alias" definintion
|
||||||
for printer_name, printer_data in self.PRINTER_CONFIG.copy().items():
|
for printer_name, printer_data in self.PRINTER_CONFIG.copy().items():
|
||||||
|
@ -360,13 +362,14 @@ class EpsonPrinter:
|
||||||
"in '%s' configuration.",
|
"in '%s' configuration.",
|
||||||
sameas, printer_name
|
sameas, printer_name
|
||||||
)
|
)
|
||||||
self.printer_model = printer_model
|
self.model = model
|
||||||
self.hostname = hostname
|
self.hostname = hostname
|
||||||
|
self.port = port
|
||||||
self.timeout = timeout
|
self.timeout = timeout
|
||||||
self.retries = retries
|
self.retries = retries
|
||||||
self.dry_run = dry_run
|
self.dry_run = dry_run
|
||||||
if self.printer_model in self.valid_printers:
|
if self.model in self.valid_printers:
|
||||||
self.parm = self.PRINTER_CONFIG[self.printer_model]
|
self.parm = self.PRINTER_CONFIG[self.model]
|
||||||
else:
|
else:
|
||||||
self.parm = None
|
self.parm = None
|
||||||
|
|
||||||
|
@ -470,7 +473,7 @@ class EpsonPrinter:
|
||||||
else:
|
else:
|
||||||
return write_op
|
return write_op
|
||||||
|
|
||||||
def snmp_mib(self, mib, label="unknown"):
|
def snmp_mib(self, mib: str, label: str = "unknown") -> (str, Any):
|
||||||
"""Generic SNMP query, returning value of a MIB."""
|
"""Generic SNMP query, returning value of a MIB."""
|
||||||
if self.mib_dict:
|
if self.mib_dict:
|
||||||
if mib not in self.mib_dict:
|
if mib not in self.mib_dict:
|
||||||
|
@ -485,7 +488,7 @@ class EpsonPrinter:
|
||||||
if not self.hostname:
|
if not self.hostname:
|
||||||
return None, False
|
return None, False
|
||||||
utt = UdpTransportTarget(
|
utt = UdpTransportTarget(
|
||||||
(self.hostname, 161),
|
(self.hostname, self.port),
|
||||||
)
|
)
|
||||||
if self.timeout is not None:
|
if self.timeout is not None:
|
||||||
utt.timeout = self.timeout
|
utt.timeout = self.timeout
|
||||||
|
@ -1557,6 +1560,14 @@ if __name__ == "__main__":
|
||||||
action="store",
|
action="store",
|
||||||
help='Printer host name or IP address. (Example: -m 192.168.1.87)',
|
help='Printer host name or IP address. (Example: -m 192.168.1.87)',
|
||||||
required=True)
|
required=True)
|
||||||
|
parser.add_argument(
|
||||||
|
'-p',
|
||||||
|
'--port',
|
||||||
|
dest='port',
|
||||||
|
type=int,
|
||||||
|
default=161,
|
||||||
|
action="store",
|
||||||
|
help='Printer port (default is 161)')
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
'-i',
|
'-i',
|
||||||
'--info',
|
'--info',
|
||||||
|
@ -1701,8 +1712,9 @@ if __name__ == "__main__":
|
||||||
logging.getLogger().setLevel(logging.DEBUG)
|
logging.getLogger().setLevel(logging.DEBUG)
|
||||||
|
|
||||||
printer = EpsonPrinter(
|
printer = EpsonPrinter(
|
||||||
args.model,
|
model=args.model,
|
||||||
args.hostname,
|
hostname=args.hostname,
|
||||||
|
port=args.port,
|
||||||
timeout=args.timeout,
|
timeout=args.timeout,
|
||||||
retries=args.retries,
|
retries=args.retries,
|
||||||
dry_run=args.dry_run)
|
dry_run=args.dry_run)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue