开发者

How to switch data pins on/off on parallel port?

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 r开发者_JS百科unning 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.


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:

     Bit | Pin # | Printer DATA
    -----+-------+--------------
      7  |   9   |   DATA 7
      6  |   8   |   DATA 6
      5  |   7   |   DATA 5
      4  |   6   |   DATA 4
      3  |   5   |   DATA 3
      2  |   4   |   DATA 2
      1  |   3   |   DATA 1
      0  |   2   |   DATA 0


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.


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.


From http://www.ti.com/product/ULN2803A:

The ULN2803A device is a 50 V, 500 mA Darlington transistor array. The device consists of eight NPN Darlington pairs that feature high-voltage outputs with common-cathode clamp diodes for switching inductive loads. The collector-current rating of each Darlington pair is 500 mA. The Darlington pairs may be connected in parallel for higher current capability.

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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜