This article was reproduced from: http://blog.csdn.net/u013686019/article/details/50165059
[HTML]View PlainCopy
- 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
- [178931.515572] USB 1-1: New Full-speed USB device number, using XHCI_HCD
- [178931.644906] USB 1-1: New USB device found, idvendor=0483, idproduct=5720
- [178931.644909] USB 1-1: New USB Device strings: mfr=1, product=2, serialnumber=3
- [178931.644911] USB 1-1: Product:sprt Printer
- [178931.644912] USB 1-1: Manufacturer:spirit
- [178931.644913] USB 1-1: serialnumber:11101800002
- [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
- ls/sys/class/
You can see that there is information about the printer device in the system:
[HTML]View PlainCopy
- /sys/class/usbmisc
Then you can perform the following:
[HTML]View PlainCopy
- 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
- Echo/system/bin/mdev >/proc/sys/kernel/hotplug
- /system/bin/mdev-s
However, in Android, it is associated with the device node creation in the file:
[CPP]View PlainCopy
- SYSTEM/CORE/INIT/DEVICES.C  
- static void handle_generic_device_event ( struct uevent *uevent)
- {
- if (!strncmp (Uevent->subsystem,
- if (!strcmp (Uevent->subsystem, "USB") {
- ....
- }
- }
- }  
By adding the following print information to the devices.c file:
We found that the USB printer information is as follows:
[HTML]View PlainCopy
- uevent->subsystem = "Usbmisc"
- 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
- echo "111" >/dev/usb/lp0
Android cannot automatically create a USB printer node/dev/usb/lp0 "Go"