2015-04-12 195 views
1

我知道有很多关于状态的打印机问题...状态热敏打印机

我有一个西铁城CT-S310 II,我设法写字符的所有代码在没有USB问题libusb_bulk_transfer(文字,加粗,居中,CR,CUT_PAPER等):

#define ENDPOINT_OUT 0x02 
#define ENDPOINT_IN  0x81 

struct libusb_device_handle *_handle; 

[detach kernel driver...] 
[claim interface...] 
[etc ...] 

r = libusb_bulk_transfer(device_handle, ENDPOINT_OUT, Mydata, out_len, &transferred, 1000); 

现在,我需要从打印机接收数据ckeck的状态,我的第一个想法是用相同的发送POS命令doc的“bulk_transfer”:

1D(hexa)72(hexa)n N => 1(发送PAPEL传感器状态)

和检索由“bulk_transfer”与结束点“ENDPOINT_IN”该文档说有8个字节以接收所述值:

bit 0,1 => paper found by paper near-end sensor 00H 
bit 0,1 => paper not found by paper near-end sensor 03H 
bit 1,2 => paper found by paper-end sensor 00H 
bit 1,2 => paper not found by paper-end sensor 0CH 
[...] 

于是两个“bulk_transfer”,一个用于发送命令状态(ENDPOINT_OUT),一个用于接收结果(ENDPOINT_IN),但我总是有一个USB错误(“bulk_transfer”in read = -1)

也许USB不工作喜欢这个 ?所以,我的第二个想法是用在PrinterClass USB实现的功能与命令“control_transfer”:

int r = 0; 
    int out_len = 1; 
    unsigned char* _udata = NULL; 

    uint8_t bmRequestType = LIBUSB_ENDPOINT_IN | LIBUSB_REQUEST_TYPE_CLASS | LIBUSB_RECIPIENT_INTERFACE; 
    uint8_t bRequest = LIBUSB_REQUEST_GET_STATUS; 
    uint16_t wValue = 0; // the value field for the setup packet (?????) 
    uint16_t wIndex = 0; // N° interface printer (the index field for the setup packet) 

    r = libusb_control_transfer(device_handle, bmRequestType,bRequest,wValue, wIndex,_udata,out_len, USB_TIMEOUT); 

我并不确切如何填补所有的参数,我知道这取决于我的设备,但DOC的libsub不是很明确。

什么是“wValue”?

什么是“wIndex”?接口号?

参数LIBUSB_ENDPOINT_IN默认为0x80,但是我的打印机使用0x81,我必须改变这个默认端点吗?

Bus 001 Device 004: ID 1d90:2060 
Device Descriptor: 
    bLength    18 
    bDescriptorType   1 
    bcdUSB    2.00 
    bDeviceClass   0 (Defined at Interface level) 
    bDeviceSubClass   0 
    bDeviceProtocol   0 
    bMaxPacketSize0  64 
    idVendor   0x1d90 
    idProduct   0x2060 
    bcdDevice   0.02 
    iManufacturer   1 CITIZEN 
    iProduct    2 Thermal Printer 
    iSerial     3 00000000 
    bNumConfigurations  1 
    Configuration Descriptor: 
    bLength     9 
    bDescriptorType   2 
    wTotalLength   32 
    bNumInterfaces   1 
    bConfigurationValue  1 
    iConfiguration   0 
    bmAttributes   0xc0 
     Self Powered 
    MaxPower    0mA 
    Interface Descriptor: 
     bLength     9 
     bDescriptorType   4 
     bInterfaceNumber  0 
     bAlternateSetting  0 
     bNumEndpoints   2 
     bInterfaceClass   7 Printer 
     bInterfaceSubClass  1 Printer 
     bInterfaceProtocol  2 Bidirectional 
     iInterface    0 
     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  0x02 EP 2 OUT 
     bmAttributes   2 
      Transfer Type   Bulk 
      Synch Type    None 
      Usage Type    Data 
     wMaxPacketSize  0x0040 1x 64 bytes 
     bInterval    0 
Device Status:  0x0001 
    Self Powered 

在我的情况“control_transfer”的回应是纸或without.How发好“control_transfer”的请求,我的打印机?

所有帮助的状态始终为0 :(解决我的问题是值得欢迎的!

回答

0

终于解决了!

LIBUSB_REQUEST_GET_STATUS的值为0x00,但对于一台打印机请求状态为0x01。

用于检查libusb-1.0打印机的状态:

uint8_t bmRequestType = LIBUSB_ENDPOINT_IN | LIBUSB_REQUEST_TYPE_CLASS | LIBUSB_RECIPIENT_INTERFACE; 
    uint8_t bRequest = 0x01; // Here not LIBUSB_REQUEST_GET_STATUS 
    uint16_t wValue = 0; 
    uint16_t wIndex = 0; 

    r = libusb_control_transfer(device_handle, bmRequestType,bRequest,wValue, wIndex,&_udata,out_len, USB_TIMEOUT);