adafruit / Python-Thermal-Printer

217 stars 147 forks source link

When trying to run python3 printertest.py I get a termios.error: (25, 'Inappropriate ioctl for device') error #57

Open threalboss opened 2 years ago

threalboss commented 2 years ago

When trying to run python3 printertest.py (on my pi zero w) I get the error:

File "/home/pi/.local/lib/python3.9/site-packages/serial/serialposix.py", line 398, in _reconfigure_port
    orig_attr = termios.tcgetattr(self.fd)
termios.error: (25, 'Inappropriate ioctl for device')

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/pi/Python-Thermal-Printer/printertest.py", line 5, in <module>
    printer = Adafruit_Thermal("/dev/usb/lp0", 9600, timeout=5)
  File "/home/pi/Python-Thermal-Printer/Adafruit_Thermal.py", line 84, in __init__
    Serial.__init__(self, *args, **kwargs)
  File "/home/pi/.local/lib/python3.9/site-packages/serial/serialutil.py", line 244, in __init__
    self.open()
  File "/home/pi/.local/lib/python3.9/site-packages/serial/serialposix.py", line 332, in open
    self._reconfigure_port(force_update=True)
  File "/home/pi/.local/lib/python3.9/site-packages/serial/serialposix.py", line 401, in _reconfigure_port
    raise SerialException("Could not configure port: {}".format(msg))
serial.serialutil.SerialException: Could not configure port: (25, 'Inappropriate ioctl for device')

In printertest.py I change the printer setup line to: printer = Adafruit_Thermal("/dev/usb/lp0", 9600, timeout=5)

This is because I could only get the first test to work with /dev/usb/lp0 and my print test page said it is 9600.

aidyk commented 2 years ago

It seems that the library doesn't support a tiny thermal printer connected via USB. I instead found a solution using python-escpos (https://github.com/python-escpos/python-escpos).