Linux嵌入式树莓派CUPS驱动打印机

嘿,好久没写东西了,最近在研究如何实现远程打印机的功能,家里是有一台打印机的,型号是HP Deskjet 2132 ,可以实现打印、复印、扫描功能,买了好几年了,除了墨贵,没别的毛病,这次想着给他改成网络的,可以实现手机、电脑等各种设备远程打印,经历了无数的坑,在此简单记录下。

一、IMX6ULL驱动打印机

总结,不大行,交叉编译的问题比较多,还需要进一步搞,但是也不是没有任何意义的,最起码cups可以用了,然后就可以添加网络打印机了。

1)搜索资料

以前在我的Ubuntu 18.04上是用过打印机的,打印的时候我也不知道发生了什么反正可以打印,扫描的时候需要安装一个叫SANE - Scanner Access Now Easy (sane-project.org)的东西,所有在这方面我是小白。然后通过不断搜索,基本上确定了这么几个关键字:

关键字可能不是很准确的理解
hpliphp打印机驱动
cups打印机管理工具,并不包含驱动程序,是驱动的上一层

| guten-print | Gutenprint Printer Drivers 开源的打印机驱动程序,支持一系列的打印机,没有我的 |

2)搞起

编译cups

经过不断的努力终于编译成了cups这个东西

编译环境:

wsl2 Ubuntu 18.04 + imx6ull交叉编译环境

编译命令:

cd cups
# 设置交叉编译环境工具链
# 这个命令不全,可能还有一些disable的东西,需要根据具体的情况进行设置
./configure --prefix=/home/xx/cupsinstall --host=arm-linux CC=arm-linux-gnueabihf-gcc CXX=arm-linux-gnueabihf-g++

编译之后将文件上传到imx6ull就可以了

修改配置文件

#
# Configuration file for the CUPS scheduler.  See "man cupsd.conf" for a
# complete description of this file.
#
​
# Log general information in error_log - change "warn" to "debug"
# for troubleshooting...
LogLevel warn
PageLogFormat
​
# Deactivate CUPS' internal logrotating, as we provide a better one, especially
# LogLevel debug2 gets usable now
MaxLogSize 0
​
# Only listen for connections from the local machine.
Listen *:631            # 修改设置任何人都可以连接,本来是localhost,只有本地可以连接
Listen /run/cups/cups.sock
​
# Show shared printers on the local network.
Browsing On
BrowseLocalProtocols dnssd
​
# Default authentication type, when authentication is required...
DefaultAuthType Basic
​
# Web interface setting...
WebInterface Yes
​
# 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         # 添加所有人都能访问/admiin目录,没有的话是没法访问的
</Location>
​
# Restrict access to configuration files...
<Location /admin/conf>
  AuthType Default
  Require user @SYSTEM
  Order allow,deny
  Allow all         # 添加所有人都能访问/admin/conf目录,没有的话是没法访问的
</Location>
​
# Restrict access to log files...
<Location /admin/log>
  AuthType Default
  Require user @SYSTEM
  Order allow,deny
  Allow all         # 添加所有人都能访问/admin/log目录,没有的话是没法访问的
</Location>
​
# Set the default printer/job policies...
<Policy default>
  # Job/subscription privacy...
  JobPrivateAccess default
  JobPrivateValues default
  SubscriptionPrivateAccess default
  SubscriptionPrivateValues default
​
  # Job-related operations must be done by the owner or an administrator...
  <Limit Create-Job Print-Job Print-URI Validate-Job>
    Order deny,allow
  </Limit>
​
  <Limit Send-Document Send-URI Hold-Job Release-Job Restart-Job Purge-Jobs Set-Job-Attributes Create-Job-Subscription Renew-Subscription Cancel-Subscription Get-Notifications Reprocess-Job Cancel-Current-Job Suspend-Current-Job Resume-Job Cancel-My-Jobs Close-Job CUPS-Move-Job CUPS-Get-Document>
    Require user @OWNER @SYSTEM
    Order deny,allow
  </Limit>
​
  # All administration operations require an administrator to authenticate...
  <Limit CUPS-Add-Modify-Printer CUPS-Delete-Printer CUPS-Add-Modify-Class CUPS-Delete-Class CUPS-Set-Default CUPS-Get-Devices>
    AuthType Default
    Require user @SYSTEM
    Order deny,allow
  </Limit>
​
  # All printer operations require a printer operator to authenticate...
  <Limit Pause-Printer Resume-Printer Enable-Printer Disable-Printer Pause-Printer-After-Current-Job Hold-New-Jobs Release-Held-New-Jobs Deactivate-Printer Activate-Printer Restart-Printer Shutdown-Printer Startup-Printer Promote-Job Schedule-Job-After Cancel-Jobs CUPS-Accept-Jobs CUPS-Reject-Jobs>
    AuthType Default
    Require user @SYSTEM
    Order deny,allow
  </Limit>
​
  # Only the owner or an administrator can cancel or authenticate a job...
  <Limit Cancel-Job CUPS-Authenticate-Job>
    Require user @OWNER @SYSTEM
    Order deny,allow
  </Limit>
​
  <Limit All>
    Order deny,allow
  </Limit>
</Policy>
​
# Set the authenticated printer/job policies...
<Policy authenticated>
  # Job/subscription privacy...
  JobPrivateAccess default
  JobPrivateValues default
  SubscriptionPrivateAccess default
  SubscriptionPrivateValues default
​
  # Job-related operations must be done by the owner or an administrator...
  <Limit Create-Job Print-Job Print-URI Validate-Job>
    AuthType Default
    Order deny,allow
  </Limit>
​
  <Limit Send-Document Send-URI Hold-Job Release-Job Restart-Job Purge-Jobs Set-Job-Attributes Create-Job-Subscription Renew-Subscription Cancel-Subscription Get-Notifications Reprocess-Job Cancel-Current-Job Suspend-Current-Job Resume-Job Cancel-My-Jobs Close-Job CUPS-Move-Job CUPS-Get-Document>
    AuthType Default
    Require user @OWNER @SYSTEM
    Order deny,allow
  </Limit>
​
  # All administration operations require an administrator to authenticate...
  <Limit CUPS-Add-Modify-Printer CUPS-Delete-Printer CUPS-Add-Modify-Class CUPS-Delete-Class CUPS-Set-Default>
    AuthType Default
    Require user @SYSTEM
    Order deny,allow
  </Limit>
​
  # All printer operations require a printer operator to authenticate...
  <Limit Pause-Printer Resume-Printer Enable-Printer Disable-Printer Pause-Printer-After-Current-Job Hold-New-Jobs Release-Held-New-Jobs Deactivate-Printer Activate-Printer Restart-Printer Shutdown-Printer Startup-Printer Promote-Job Schedule-Job-After Cancel-Jobs CUPS-Accept-Jobs CUPS-Reject-Jobs>
    AuthType Default
    Require user @SYSTEM
    Order deny,allow
  </Limit>
​
  # Only the owner or an administrator can cancel or authenticate a job...
  <Limit Cancel-Job CUPS-Authenticate-Job>
    AuthType Default
    Require user @OWNER @SYSTEM
    Order deny,allow
  </Limit>
​
  <Limit All>
    Order deny,allow
  </Limit>
</Policy>
​
# Set the kerberized printer/job policies...
<Policy kerberos>
  # Job/subscription privacy...
  JobPrivateAccess default
  JobPrivateValues default
  SubscriptionPrivateAccess default
  SubscriptionPrivateValues default
​
  # Job-related operations must be done by the owner or an administrator...
  <Limit Create-Job Print-Job Print-URI Validate-Job>
    # AuthType Negotiate   所有的Negotiate都改成Default
    AuthType Default 
    Order deny,allow
  </Limit>
​
  # 这里要注意,下述配置项比较长,需要多行显示,但是要注意的是这里不能换行,只能放到一行,换句话说这里不能有换行符,如果配置文件是从别处复制过来的很有可能出现问题
  <Limit Send-Document Send-URI Hold-Job Release-Job Restart-Job Purge-Jobs Set-Job-Attributes Create-Job-Subscription Renew-Subscription Cancel-Subscription Get-Notifications Reprocess-Job Cancel-Current-Job Suspend-Current-Job Resume-Job Cancel-My-Jobs Close-Job CUPS-Move-Job CUPS-Get-Document>
    AuthType Default
    Require user @OWNER @SYSTEM
    Order deny,allow
  </Limit>
​
  # All administration operations require an administrator to authenticate...
  <Limit CUPS-Add-Modify-Printer CUPS-Delete-Printer CUPS-Add-Modify-Class CUPS-Delete-Class CUPS-Set-Default>
    AuthType Default
    Require user @SYSTEM
    Order deny,allow
  </Limit>
​
  # All printer operations require a printer operator to authenticate...
  <Limit Pause-Printer Resume-Printer Enable-Printer Disable-Printer Pause-Printer-After-Current-Job Hold-New-Jobs Release-Held-New-Jobs Deactivate-Printer Activate-Printer Restart-Printer Shutdown-Printer Startup-Printer Promote-Job Schedule-Job-After Cancel-Jobs CUPS-Accept-Jobs CUPS-Reject-Jobs>
    AuthType Default
    Require user @SYSTEM
    Order deny,allow
  </Limit>
​
  # Only the owner or an administrator can cancel or authenticate a job...
  <Limit Cancel-Job CUPS-Authenticate-Job>
    AuthType Default
    Require user @OWNER @SYSTEM
    Order deny,allow
  </Limit>
​
  <Limit All>
    Order deny,allow
  </Limit>
</Policy>

添加用户:

这一条好像相当重要,不加好像也是无法访问的,但是具体我也忘了,总之我的理解是需要将可以使用打印机的用户或者说imx6ull的用户(我这里是root)添加到lpadmin用户组中

# 添加root到用户组
usermod -a G lpadmin root
# 该用户需要有一个密码
passwd root

启动服务

# 执行以下命令就可以启动cupsd服务了
cupsd

远程登陆

在个人电脑上输入imx6ull设备的IP地址+631端口,如http://192.168.1.14:631即可进入到cups的web管理页面,到这里就结束了,没办法,打印机驱动并没有编译成功,所以暂时到这里。

二、树莓派安装hplip

安装hplip

imx6ull是证明失败了的,所以我将目光投向了我的树莓派4,一条命令搞定 image-20210723200257016.png

sudo apt install hplip
# 添加当前用户到lpadmin用户组
# 我这里是添加的pi用户
sudo usermod -a -G lpadmin pi

然后按照上边imx6ull那段更改配置文件,然后重新插拔打印机,然后也可以直接重启下树莓派

sudo reboot

进入配置添加打印机

image-20210723200548698.pngimage-20210723200615833.pngimage-20210723200704382.pngimage-20210723200828385.pngimage-20210723201017875.pngimage-20210723201101903.pngimage-20210723201101903.pngimage-20210723201210886.png

image-20210723201256965.png

image-20210723201312752.pngimage-20210723201338347.pngimage-20210723201406584.png到这里为止就可以打印了,第二部分结束

三、imx6ull再来一次

前边imx6ull这个东西主要是驱动编译有问题,后来看到cups支持一个叫IPP的东西,似乎是不需要知道打印机驱动的,因此重新搞了一下。直接使用ipp协议进行打印机的添加,效果也是不错的。

小总结

最近在网上也在学习如何驱动打印机,确实是比较麻烦的,目前看来惠普的是最简单的,其提供的hplip非常完善,也提供了源代码,可以交叉编译安装,其他的打印机如兄弟打印机提供了Linux x86-64的驱动,但是没有源码,在树莓派或其他嵌入式板子上没法用,也有其他人提供了一些开源的解决方案,这个还需要测试,功能可能也不够完善,同时打印机如果是同一个系列的,驱动程序基本也是可以通用的。都需要测试。

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值