Raspberry Pi escpos python打印机USB连接

时间:2018-09-16 13:10:47

标签: python python-3.x raspberry-pi raspberry-pi3 raspbian

我在通过USB与热敏打印机连接时遇到问题,这是我插入热敏打印机时得到的输出。

这是我输入lsusb -v

时的输出
Bus 001 Device 004: ID 0456:0808 Analog Devices, Inc.
Device Descriptor:
  bLength                18
  bDescriptorType         1
  bcdUSB               2.00
  bDeviceClass            0 (Defined at Interface level)
  bDeviceSubClass         0
  bDeviceProtocol         0
  bMaxPacketSize0        64
  idVendor           0x0456 Analog Devices, Inc.
  idProduct          0x0808
  bcdDevice            2.00
  iManufacturer           1 Thermal Printer
  iProduct                2 H58 Printer USB
  iSerial                 3 Printer
  bNumConfigurations      1
  Configuration Descriptor:
    bLength                 9
    bDescriptorType         2
    wTotalLength           32
    bNumInterfaces          1
    bConfigurationValue     1
    iConfiguration          5 (error)
    bmAttributes         0xc0
      Self Powered
    MaxPower              100mA
    Interface Descriptor:
      bLength                 9
      bDescriptorType         4
      bInterfaceNumber        0
      bAlternateSetting       0
      bNumEndpoints           2
      bInterfaceClass         7 Printer
      bInterfaceSubClass      1 Printer
      bInterfaceProtocol      2 Bidirectional
      iInterface              4 (error)
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x81  EP 1 IN
        bmAttributes            2
          Transfer Type            Bulk
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x0040  1x 64 bytes
        bInterval               0
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x03  EP 3 OUT
        bmAttributes            2
          Transfer Type            Bulk
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x0040  1x 64 bytes
        bInterval               0
Device Status:     0x0001
  Self Powered

这是我使用escpos python库连接到打印机的python脚本。

#!/usr/bin/python
from escpos.printer import Usb
p = Usb(0x0456,0x0808, 0x03)
p.text("Mini")

这是我尝试运行脚本时遇到的错误。

Traceback (most recent call last):
  File "/usr/local/lib/python3.5/dist-packages/usb/core.py", line 223, in get_interface_and_endpoint
    return self._ep_info[endpoint_address]
KeyError: 1

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "print.py", line 4, in <module>
    p.text("Mini")
  File "/usr/local/lib/python3.5/dist-packages/escpos/escpos.py", line 513, in text
    self.magic.write(txt)
  File "/usr/local/lib/python3.5/dist-packages/escpos/magicencode.py", line 272, in write
    self.write_with_encoding(encoding, to_write)
  File "/usr/local/lib/python3.5/dist-packages/escpos/magicencode.py", line 293, in write_with_encoding
    six.int2byte(self.encoder.get_sequence(encoding)))
  File "/usr/local/lib/python3.5/dist-packages/escpos/printer.py", line 85, in _raw
    self.device.write(self.out_ep, msg, self.timeout)
  File "/usr/local/lib/python3.5/dist-packages/usb/core.py", line 940, in write
    intf, ep = self._ctx.setup_request(self, endpoint)
  File "/usr/local/lib/python3.5/dist-packages/usb/core.py", line 102, in wrapper
    return f(self, *args, **kwargs)
  File "/usr/local/lib/python3.5/dist-packages/usb/core.py", line 215, in setup_request
    intf, ep = self.get_interface_and_endpoint(device, endpoint_address)
  File "/usr/local/lib/python3.5/dist-packages/usb/core.py", line 102, in wrapper
    return f(self, *args, **kwargs)
  File "/usr/local/lib/python3.5/dist-packages/usb/core.py", line 231, in get_interface_and_endpoint
    raise ValueError('Invalid endpoint address ' + hex(endpoint_address))
ValueError: Invalid endpoint address 0x1

我也尝试在第3个参数中使用0x81,但是它仍然出现错误我已经看过很多教程,但是我仍然遇到错误,我可以使用GUI测试打印,但是不能使用python脚本进行打印

0 个答案:

没有答案