Results 1 to 9 of 9
  1. #1
    Z.K. is offline Member
    Join Date
    Apr 2011
    Posts
    10
    Rep Power
    0

    Question C IO port function equivalent in Java

    I was wondering if anyone could tell me the equivalent of inp() and outp() C functions in Java. I need to use Digital outputs on a board I have and all their examples are in C and I need to do this in Java.

    :?

  2. #2
    Toll's Avatar
    Toll is offline Senior Member
    Join Date
    May 2011
    Location
    Sweden
    Posts
    392
    Rep Power
    4

    Default

    And what does inp and outp do in C for those of us that don't know?

  3. #3
    Z.K. is offline Member
    Join Date
    Apr 2011
    Posts
    10
    Rep Power
    0

    Default

    Quote Originally Posted by Toll View Post
    And what does inp and outp do in C for those of us that don't know?
    inp() Reads a byte from a port and outp() writes a byte to a port. Useful for activating relays, LEDs, etc. You send a hex value representing whether the device you are send it to will be turned off or on. Usually a high (or 1) is 5V and a low (or 0) is 0V. This is used for interfacing with devices using either the serial or parallel ports though it can be used with USB if there is a driver for it like the various USB Data Acquisition devices like this one iUSBDAQ, lowest price USB data acquisition module, free software. In my case, I am using Linux and I need to use Java and there is not a lot of documentation about how to do this. I am not using a serial port, it is a digital I/O on a small board computer.

  4. #4
    Toll's Avatar
    Toll is offline Senior Member
    Join Date
    May 2011
    Location
    Sweden
    Posts
    392
    Rep Power
    4

    Default

    I don't use Linux very regularly, but I believe it treats all ports as files, yes? So if you can access the output-port in Linux, you might be able to use a simple FileOutputStream to connect to the port. Otherwise, have a look at http://java.sun.com/developer/Books/...ookbook/11.pdf. It deals with serial and parallell ports, but you might be able to adapt it to whatever port you have available to you.

  5. #5
    Z.K. is offline Member
    Join Date
    Apr 2011
    Posts
    10
    Rep Power
    0

    Default

    Quote Originally Posted by Toll View Post
    I don't use Linux very regularly, but I believe it treats all ports as files, yes? So if you can access the output-port in Linux, you might be able to use a simple FileOutputStream to connect to the port. Otherwise, have a look at http://java.sun.com/developer/Books/...ookbook/11.pdf. It deals with serial and parallell ports, but you might be able to adapt it to whatever port you have available to you.
    Except I don't know how to open a port based on a memory address. I am not using either serial or parallel ports. Also, my attempt at using serial ports did not succeed. I spent 4 weeks trying to get a program to work and never could get it to function properly. The port would open, but I could not get any data and I could not seem to write anything to the port either. In any case I am using a special digital I/O port and not serial or parallel.

  6. #6
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,526
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by Z.K. View Post
    Except I don't know how to open a port based on a memory address. I am not using either serial or parallel ports. Also, my attempt at using serial ports did not succeed. I spent 4 weeks trying to get a program to work and never could get it to function properly. The port would open, but I could not get any data and I could not seem to write anything to the port either. In any case I am using a special digital I/O port and not serial or parallel.
    )

    There are a couple of implementations that can handle serial and parallel ports (javax.comm and rxtx) but their parallel port handling wants a full centronics implementation to be available (strobe and handshake etc.) They can't handle arbitrary ports. Java is not the most suitable language for this purpose (as far as I know). Maybe you can play a bit with JNI or JNA (native language interfaces).

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  7. #7
    Z.K. is offline Member
    Join Date
    Apr 2011
    Posts
    10
    Rep Power
    0

    Default

    Quote Originally Posted by JosAH View Post
    )

    There are a couple of implementations that can handle serial and parallel ports (javax.comm and rxtx) but their parallel port handling wants a full centronics implementation to be available (strobe and handshake etc.) They can't handle arbitrary ports. Java is not the most suitable language for this purpose (as far as I know). Maybe you can play a bit with JNI or JNA (native language interfaces).

    kind regards,

    Jos
    Yes, I am finding out that Java is not the best way to go, but I have no choice as the main part of this code is not mine though I would not have used Java in the first place. I am more used to C, C++, and C#. Serial ports especially are much easier in C#. I did find this link though How To Write Directly to a Memory Locations In Java - Java Wiki. I was wondering what you think about it. It looks like it might be what I am looking for.

  8. #8
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,526
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by Z.K. View Post
    Yes, I am finding out that Java is not the best way to go, but I have no choice as the main part of this code is not mine though I would not have used Java in the first place. I am more used to C, C++, and C#. Serial ports especially are much easier in C#. I did find this link though How To Write Directly to a Memory Locations In Java - Java Wiki. I was wondering what you think about it. It looks like it might be what I am looking for.
    Note that writing to and reading from a port is something totally different that writing/reading memory (those ports aren't memory mapped). But you can follow the same scenario: write two C functions that read or write from/to a port and bind them using JNI to Java.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  9. #9
    Z.K. is offline Member
    Join Date
    Apr 2011
    Posts
    10
    Rep Power
    0

    Default

    Quote Originally Posted by JosAH View Post
    Note that writing to and reading from a port is something totally different that writing/reading memory (those ports aren't memory mapped). But you can follow the same scenario: write two C functions that read or write from/to a port and bind them using JNI to Java.

    kind regards,

    Jos
    Okay thanks, I will give that a try. Someone else mentioned JNI to me as well. So, maybe I will go that route.

Similar Threads

  1. Equivalent of PHP isset in JAVA
    By africanhacker in forum New To Java
    Replies: 11
    Last Post: 03-24-2011, 02:41 PM
  2. Java equivalent of PHP's variable-variables?
    By XmisterIS in forum New To Java
    Replies: 7
    Last Post: 09-01-2010, 11:05 AM
  3. Java equivalent of Linux 'find' function
    By porchrat in forum New To Java
    Replies: 5
    Last Post: 08-25-2010, 11:31 AM
  4. [SOLVED] Java equivalent to X11 Work Procedure
    By LongHitter in forum New To Java
    Replies: 0
    Last Post: 01-12-2009, 11:36 AM
  5. Php explode function, equivalent java
    By fernando in forum Advanced Java
    Replies: 1
    Last Post: 07-31-2007, 05:44 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •