AOSP ~ 打印机
KERNEL
Linux内核默认运行打印机内核驱动,直接在配置上CONFIG_USB_PRINTER=y添加上去就好了。
插入打印机就可以看到/dev/usb/lp0设备节点了
插入打印机有如下打印,证明节点生成,识别设备
[ 8404.552206] usb 5-1: new high-speed USB device number 4 using xhci-hcd
[ 8404.693475] usb 5-1: New USB device found, idVendor=03f0, idProduct=3754, bcdDevice= 1.00
[ 8404.693580] usb 5-1: New USB device strings: Mfr=1, Product=2, SerialNumber=3
[ 8404.693608] usb 5-1: Product: DeskJet 1200 series
[ 8404.693633] usb 5-1: Manufacturer: HP
[ 8404.693657] usb 5-1: SerialNumber: CN24C3254J
[ 8404.703551] usblp 5-1:1.0: usblp0: USB Bidirectional printer dev 4 if 0 alt 0 proto 2 vid 0x03F0 pid 0x375
上层都是操作/dev/usb/lp0 或/dev/lp0这个节点,USB设备都是要自报家门的。usb协议中有专门的打印协议,内核是「不生产信息只是软硬件之间的搬运工」 使用内核的usblp.c只是因为它是个通道,不是目的,目的是将数据传输给打印机。使用libusb(应用层的usb通信库)直接传输也是一样的,参见hplip的实现;真到Android中使用usb host api也是一样的,参见Google play中 USB打印APP 的实现
LP 表示行式打印机
CUPS
OpenPrinting CUPS
The current standards-based, open source printing system developed by OpenPrinting for Linux® and other Unix®-like operating systems. CUPS uses IPP Everywhere™ to support printing to local and network printers.
Introduction
CUPS supports printing to:
- AirPrint™ and IPP Everywhere™ printers,
- Network and local (USB) printers with Printer Applications, and
- Network and local (USB) printers with (legacy) PPD-based printer drivers.
CUPS provides the System V (“lp”) and Berkeley (“lpr”) command-line interfaces, a configurable web interface, a C API, and common print filters, drivers, and backends for printing. The cups-filters project provides additional filters and drivers.
CUPS is licensed under the Apache License Version 2.0 with an exception to allow linking against GNU GPL2-only software.
cups 的全称是Common UNIX Printing System
它支持IPP服务,即Internet Printing Protoco
也就是通过Internet来提供打印服务,也就是可以通过http://xxx.xxx/printers的形式来访问打印机。这样 做的好处很多,因为http是标准的网络协议,稳定、可靠、透明
http://192.168.0.1:631/printers/hp2105
PPD
为了对各种打印机提供支持,打印系统可以使用 PostScript 打印机描述 (PostScript Printer Description, PPD) 文件
什么是 PPD 文件? PPD 文件用于说明 PostScript 打印机的字体、纸张尺寸、分辨率及其它标准特性。 PostScript 打印机驱动程序利用 PPD 文件来确定如何打印文档。 在打印过程中,如果您未使用正确的 PPD 文件,那么您的文档将无法正确打印,或者您将无法正常使用打印机的全部功能。 打印机可能不会执行任何打印操作,而显示关于文件格式或图形语言的系统错误或用户信息。
PrintService
Linux 平台
Linux 自动安装
CUPS
- 安装配置CUPS 首先安装必要的包cups、cups-pdf、cups-bsd
sudo apt-get install cups cups-pdf cups-bsd
- 确认是否运行
ps -ef | grep cups
- 给账户pi赋予修改权限
sudo usermod -a -G lpadmin pi
HPCUPS
apt install printer-driver-hpcups
Linux 手动编译
apt install libusb-1.0-0-dev pkgconf
./configure \
--prefix=/mnt/DATA/Github_OpenPrinting_cups/build \
--enable-libusb
Linux 运行
./build/sbin/cupsd -f
root@develop:~/DATA/Github_OpenPrinting_cups/build/sbin# ./lpinfo -v
network lpd
network ipp
network socket
network http
network https
direct usb://HP/DeskJet%201200%20series?serial=CN24C3254J
network ipps
network socket://192.168.160.100
添加打印机
lpadmin(选项)(参数)
-c:将打印机加入类;
-i:为打印机设置“system V”风格的接口脚本;
-m:从mode目录设置一个标准的“system V”接口脚本或“PPD”文件;
-o:为“PPD”或服务器设置选项;
-r:从类中删除打印机;
-u:设置打印机用户级的访问控制;
-D:为打印机提供一个文字描述;
-E:允许打印机接受打印任务;
-L:为打印机位置提供一个文字描述;
-P:为打印机指定一个ppd描述文件;
-p:指定要配置的打印机名称;
-d:设置默认打印机。
./build/sbin/lpadmin -p xxx -E -v usb://HP/DeskJet%201200%20series?serial=CN24C3254J \
-P /root/HP-DeskJet-1200-series.ppd
./build/bin/lp -d xxx /root/Baidu.pdf
cupsctl
root@develop:~/Github_OpenPrinting_cups# ./build/sbin/cupsctl -h
Usage: cupsctl [options] [param=value ... paramN=valueN]
Options:
-E Encrypt the connection to the server
-h server[:port] Connect to the named server and port
-U username Specify username to use for authentication
--[no-]debug-logging Turn debug logging on/off
--[no-]remote-admin Turn remote administration on/off
--[no-]remote-any Allow/prevent access from the Internet
--[no-]share-printers Turn printer sharing on/off
--[no-]user-cancel-any Allow/prevent users to cancel any job
- 打开debug日志
./build/sbin/cupsctl --debug-logging
cups-filters
apt install autopoint gettext
CUPS Web 配置
-
CUPS默认只监听localhost,修改配置文件,允许any监听TCP 631
把Listen localhost:631修改为Listen *:631
-
允许any访问CUPS WEB
vim /etc/cups/cupsd.conf
如下增加Allow all字段
# Restrict access to the server...
<Location />
Order allow,deny
Allow all
</Location>
# Restrict access to the admin pages...
<Location /admin>
Order allow,deny
Allow all
</Location>
# Restrict access to configuration files...
<Location /admin/conf>
AuthType Default
Require user @SYSTEM
Order allow,deny
Allow all
</Location>
重启服务 service cups restart```
问题
- PDF格式不支持
root@develop:~/Github_OpenPrinting_cups# ./build/bin/lp -d xxx /root/Baidu.pdf
./build/bin/lp: Unsupported document-format "application/pdf".
解决方案:?
参考
Android系统打印方案分析
在 Linux 上设置打印机的 12 个 CUPS lpadmin 命令示例
debian Printing
打印机命令参考手册
PPD FILE
CUPS
ArchLinux CUPS
Linux Build CUPS
Github CUPS DOC
HP Linux Imaging and Printing (hplip)