岁月联盟 · 中国技术网 本站主页 | 安全认证 | 用户服务 | 技术论坛
新闻快报 | 新手学堂 | 黑客特区 | 程序语言 | 数 据 库 | 防 火 墙 | 路由交换 | 系统集成 | 服 务 器 | 存储备份 | 考试认证
Windows | Linux | Java | 协议分析 | 问题解答 | 进程大全 | 网页设计 | 多 媒 体 | 图库资料 | 软件下载 | 站内下载
  您现在的位置: 岁月联盟 >> Linux频道 >> Linux编程 >> CC编程 >> Linux频道正文
解析Linux下的并口编程(英文版)
作者:未知 文章来源:本站整理 点击数: 更新时间:2007-7-10 16:26:01

  The printer is accessible through /dev/lp0; in the same way, the parallel port itself is accessible through /dev/parport0. The difference is in the level of control that you have over the wires in the parallel port cable.
  
  With the printer driver, a user-space program (such as the printer spooler) can send bytes in "printer protocol". Briefly, this means that for each byte, the eight data lines are set up, then a "strobe" line tells the printer to look at the data lines, and the printer sets an "acknowledgement" line to say that it got the byte. The printer driver also allows the user-space program to read bytes in "nibble mode", which is a way of transferring data from the peripheral to the computer half a byte at a time (and so it's quite slow).
  
  In contrast, the ppdev driver (accessed via /dev/parport0) allows you to:
  
  examine status lines,
  
  set control lines,
  
  set/examine data lines (and control the direction of the data lines),
  
  wait for an interrupt (triggered by one of the status lines),
  
  find out how many new interrupts have occurred,
  
  set up a response to an interrupt,
  
  use IEEE 1284 negotiation (for telling peripheral which transfer mode, to use)
  
  transfer data using a specified IEEE 1284 mode.
  
  Programming interface
  
  The ppdev interface is largely the same as that of other character special devices, in that it supports open, close, read, write, and ioctl. The constants for the ioctl commands are in include/linux/ppdev.h.
  
  Starting and stopping: open and close
  
  The device node /dev/parport0 represents any device that is connected to parport0, the first parallel port in the system. Each time the device node is opened, it represents (to the process doing the opening) a different device. It can be opened more than once, but only one instance can actually be in control of the parallel port at any time. A process that has opened /dev/parport0 shares the parallel port in the same way as any other device driver. A user-land driver may be sharing the parallel port with in-kernel device drivers as well as other user-land drivers.
  
  Control: ioctl
  
  Most of the control is done, naturally enough, via the ioctl call. Using ioctl, the user-land driver can control both the ppdev driver in the kernel and the physical parallel port itself. The ioctl call takes as parameters a file descriptor (the one returned from opening the device node), a command, and optionally (a pointer to) some data.
  
  PPCLAIM
  
  Claims access to the port. As a user-land device driver writer, you will need to do this before you are able to actually change the state of the parallel port in any way. Note that some operations only affect the ppdev driver and not the port, such as PPSETMODE; they can be performed while access to the port is not claimed.
  
  PPEXCL
  
  Instructs the kernel driver to forbid any sharing of the port with other drivers, i.e. it requests exclusivity. The PPEXCL command is only valid when the port is not already claimed for use, and it may mean that the next PPCLAIM ioctl will fail: some other driver may already have registered itself on that port.
  
  Most device drivers don't need exclusive access to the port. It's only provided in case it is really needed, for example for devices where access to the p

[1] [2] [3] 下一页


  • 上一个Linux频道:
  • 下一个Linux频道:
  •  
    热门文章
    推荐文章
    关于我们 | 发展历程 | 网站地图 | 广告服务 | 招贤纳士 | 战略合作 | 友情链接 | 著作声明 | 联系我们
    Copyright © 2002-2007 SYUE All rights reserved.
    E_mail:Admin@Syue.Com 皖ICP备05004589号
    未经授权禁止转载、摘编、复制或建立镜像.如有违反,追究法律责任.
    天龙八部私服 传世私服 传奇世界私服 传奇私服 bet365 天龙八部私服 热血江湖私服 英雄合击传奇私服 热血江湖私服 bet365 bet365