Android cannot automatically create a USB printer node/dev/usb/lp0 "Go"

Source: Internet
Author: User
Tags echo command

This article was reproduced from: http://blog.csdn.net/u013686019/article/details/50165059

[HTML]View PlainCopy
    1. android:4.4.4
First, the problem analysis

When the USB printer is plugged into an Android device, there is no printer node (/DEV/USB/LP0) generated in the System/dev directory.

The first reaction is to check the printer device and access the Ubuntu-equipped PC, normal: /dev/usb/lp0

The second reaction is to view the printer driver information:

[HTML]View PlainCopy
  1. [178931.515572] USB 1-1: New Full-speed USB device number, using XHCI_HCD
  2. [178931.644906] USB 1-1: New USB device found, idvendor=0483, idproduct=5720
  3. [178931.644909] USB 1-1: New USB Device strings: mfr=1, product=2, serialnumber=3
  4. [178931.644911] USB 1-1: Product:sprt Printer
  5. [178931.644912] USB 1-1: Manufacturer:spirit
  6. [178931.644913] USB 1-1: serialnumber:11101800002
  7. [178931.645918] usblp 1-1:1.0:usblp0:usb bidirectional printer dev 0 alt 0 Proto 2 vid 0x0483 pid 0x5720

also normal. and PC display the information is the key part of the same.

The problem is that the system cannot create the node . Then create it manually!

Second, the problem of a preliminary solution

Under embedded Linux systems, device nodes can be created through Mdev. Mdev is to obtain the device information by scanning the system/sys/class/directory, and then create the node under/dev/ . Pass:

[HTML]View PlainCopy
    1. ls/sys/class/

You can see that there is information about the printer device in the system:

[HTML]View PlainCopy
    1. /sys/class/usbmisc

Then you can perform the following:

[HTML]View PlainCopy
    1. BusyBox mdev-s

See/dev/again, surprise discovery:/dev/usb/lp0, there!

Third, the problem is fundamentally solved

After the above detection, we know:

1, Drive Normal

2, the system has printer equipment information

So the question is: The system cannot automatically create a printer node for us/dev/usb/lp0

Under Linux, hot plug-related can be added as follows in the/etc/init.d/rcs script:

[HTML]View PlainCopy
    1. Echo/system/bin/mdev >/proc/sys/kernel/hotplug
    2. /system/bin/mdev-s

However, in Android, it is associated with the device node creation in the file:

[CPP]View PlainCopy
    1. SYSTEM/CORE/INIT/DEVICES.C  
    2. static void handle_generic_device_event ( struct uevent *uevent)   
    3. {   
    4.     if  (!strncmp (Uevent->subsystem,  
    5.          if  (!strcmp (Uevent->subsystem,  "USB")  {  
    6.              ....  
    7.          }  
    8.     }  
    9. }  

By adding the following print information to the devices.c file:

We found that the USB printer information is as follows:

[HTML]View PlainCopy
    1. uevent->subsystem = "Usbmisc"
    2. uevent->device_name = "Usb/lp0"

The code simply return after the "Usbmisc" processing logic is not found.

At this point, the solution comes out:

Add the code that handles Uevent->subsystem = "Usbmisc":

Compile, burn write, restart, insert, ok!

Iv. Testing

Node/dev/usb/lp0 is there, can not use, but also to test ah, we are using the printer, not watching the node fun.

output characters to/dev/usb/lp0 via the echo command to print:

[HTML]View PlainCopy
    1. echo "111" >/dev/usb/lp0

Android cannot automatically create a USB printer node/dev/usb/lp0 "Go"

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.