如何打开/关闭并行端口上的数据引脚?
我想简单地打开和关闭某些数据引脚,以便它们可以控制一组继电器。我不是在问硬件位(应该很容易),但我不知道从哪里开始编写软件。我不想要一个可以向设备发送字节的高级库 - 我真的想打开/关闭某些引脚。
我正在运行 Linux,并且想在 Java 中执行此操作,那么我只需要一个库吗?如果该库有良好的文档并且易于使用,那就太好了,但如果没有,那么简短的示例代码将帮助我入门。
I want to simply switch certain data pins on and off, so that they can control a set of relays. I'm not asking about the hardware bit (should be easy), but I don't know where to begin writing the software. I don't want a high level library that can send bytes to a device - I literally want to switch on/off certain pins.
I'm running Linux and I want to do this in Java, so would I just need a library? It would be nice if the library has good documentation and is easy to use, but if not then a short example code will help me get started.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
有一个非常易于使用的 API,称为 ParalPort:
http://www.oocities .com/Juanga69/parport/index.html?20112
这很简单,你可以使用“write(int oneByte)”,在“oneByte”中你发送一个8位字,打开和关闭引脚你想要的,根据这个图:
There's a pretty easy-to-use API called ParalelPort:
http://www.oocities.com/Juanga69/parport/index.html?20112
Its very easy, you could use "write(int oneByte)", where in the "oneByte" you send a 8 bit word, turning on and off the pins you want, according to this diagram:
转至 https://cds.sun.com/is-bin/INTERSHOP.enfinity/WFS/CDS-CDS_SMI-Site/en_US/-/USD/ViewProductDetail -Start?ProductRef=JAVACOMM-3.0.1-LX-SP-GF@CDS-CDS_SMI 并下载 Linux 版本。
JavaComm 用户指南位于:http://java.sun.com/products /javacomm/reference/docs/API_users_guide_3.html
当然,您需要一些外部电子设备来从 PPort 输出进行转换,然后触发继电器。根据这些继电器将要触发的内容(有问题的负载),您将烧毁您的电脑。
如果我是你,我会考虑像 Arduino 板 这样的东西,它允许你写入输出并提供你的电脑和你想要控制的东西之间有一些电气隔离。
Go to https://cds.sun.com/is-bin/INTERSHOP.enfinity/WFS/CDS-CDS_SMI-Site/en_US/-/USD/ViewProductDetail-Start?ProductRef=JAVACOMM-3.0.1-LX-SP-G-F@CDS-CDS_SMI and download the version for Linux.
JavaComm user guide is here: http://java.sun.com/products/javacomm/reference/docs/API_users_guide_3.html
Of course you will need to have some external electronics to convert from the PPort output to then trigger the relays. Depending on what these relays are going to trigger (The load in question) you will blow your PC.
If I were you I would consider something like an Arduino board that will allow you to write to outputs as well as provide you some electrical isolation between your PC and what you are trying to control.
请先将光耦合器之类的东西连接到并行端口引脚。然后从那里连接一个晶体管或 MOSFET 来驱动继电器。确保继电器上有反向电流保护二极管。
please attach something like an opto-coupler to the parallel port pins first. then from there, attach a transistor or mosfet to drive the relays. make sure the relays have reverse current protection diodes on them.
来自 http://www.ti.com/product/ULN2803A:
您必须将 com 引脚连接到输出 + 电压引脚才能正常工作。预计电压下降 1.3V。这可以直接连接到并行端口(如果需要,可以使用串联电阻)。必须连接计算机、电磁阀电源和 ULN2803A 接地。还有许多其他器件可用,但该器件采用 DIP 封装,使原型设计变得更加容易。
吉尔
From http://www.ti.com/product/ULN2803A:
You must connect the com pin to your output + voltage pin for it to work. Expect a 1.3V drop. This can be directly connected to the parallel port (you may use a series resistor if you want). The computer, solenoid power, and the ULN2803A grounds must be connected. There are many other devices available but this is in a DIP package making prototyping an easier task.
Gil