Pipelining COM ports

Discussion in 'Java' started by hr.org.fer, Nov 13, 2006.

  1. hr.org.fer

    hr.org.fer Guest

    Is it possible to create a pipeline to virtual COM port (MS Windows)?

    I connect a mobile phone to PC over Bluetooth and
    [CommPortIdentifier.getPortIdentifiers();] does not enumerate any port,
    neither COM1 nor virtual port for mobile phone.

    If I use [new FileOutputStream("COM10");] then I can send data to
    mobile phone but I can't read the response.

    Basically, I need to open a pipeline to file. Where can I find more
    information on this topic?
    hr.org.fer, Nov 13, 2006
    #1
    1. Advertising

  2. hr.org.fer wrote:
    > Is it possible to create a pipeline to virtual COM port (MS Windows)?
    >
    > I connect a mobile phone to PC over Bluetooth and
    > [CommPortIdentifier.getPortIdentifiers();] does not enumerate any port,
    > neither COM1 nor virtual port for mobile phone.
    >
    > If I use [new FileOutputStream("COM10");] then I can send data to
    > mobile phone but I can't read the response.

    And what happens if you also use [new FileInputStream("COM10");] for
    reading?
    [May be this approach too naive, because I don't have any experience
    with COM ports]
    >
    > Basically, I need to open a pipeline to file. Where can I find more
    > information on this topic?
    >


    --
    Thomas
    Thomas Fritsch, Nov 13, 2006
    #2
    1. Advertising

  3. hr.org.fer

    hr.org.fer Guest

    > And what happens if you also use [new FileInputStream("COM10");] for
    > reading?


    I tried that. :) You can't open the same port twice. The following
    code:
    try {
    FileInputStream fis = new FileInputStream("COM10");
    FileOutputStream fos = new FileOutputStream("COM10");
    } catch (Exception e) {
    System.err.println(e);
    }

    produces the following output:
    java.io.FileNotFoundException: COM10 (Access is denied)


    In C I can achieve the goal by calling port = open("COM10", O_RDWR);
    but I don't know the equivalent in Java.

    I guess I'll have to look up another solution to my problem. Anyway,
    thanks for trying to help.
    hr.org.fer, Nov 13, 2006
    #3
  4. "hr.org.fer" <> wrote
    > I tried that. :) You can't open the same port twice. The following
    > code:
    > try {
    > FileInputStream fis = new FileInputStream("COM10");
    > FileOutputStream fos = new FileOutputStream("COM10");
    > } catch (Exception e) {
    > System.err.println(e);
    > }
    >
    > produces the following output:
    > java.io.FileNotFoundException: COM10 (Access is denied)
    >
    >
    > In C I can achieve the goal by calling port = open("COM10", O_RDWR);
    > but I don't know the equivalent in Java.

    May be that works:
    RandomAccessFile raf = new RandomAccessFile("COM10", "rw");

    --
    Thomas
    Thomas Fritsch, Nov 13, 2006
    #4
  5. hr.org.fer

    hr.org.fer Guest

    Thomas Fritsch wrote:
    > May be that works:
    > RandomAccessFile raf = new RandomAccessFile("COM10", "rw");


    I had tried that as well. :) The problem is that I can't read the
    response from the other side (mobile phone in my particular case). I
    can read only data that I sent to that port. The same problem was in C,
    I could not use the ordinary files there as well.

    I found the solution: Java Communications API can be downloaded from
    Sun's pages and it provides classes for communication with serial ports
    (RS-232). I have problems configuring it because it does not display
    any port on my computer, but I hope I'll solve that problem in next few
    days.
    hr.org.fer, Nov 14, 2006
    #5
  6. hr.org.fer wrote:
    > Thomas Fritsch wrote:
    >> May be that works:
    >> RandomAccessFile raf = new RandomAccessFile("COM10", "rw");

    >
    > I had tried that as well. :) The problem is that I can't read the
    > response from the other side (mobile phone in my particular case). I
    > can read only data that I sent to that port. The same problem was in C,
    > I could not use the ordinary files there as well.
    >
    > I found the solution: Java Communications API can be downloaded from
    > Sun's pages and it provides classes for communication with serial ports
    > (RS-232). I have problems configuring it because it does not display
    > any port on my computer, but I hope I'll solve that problem in next few
    > days.
    >


    If you are using Winblows, put your files here and run the test code below.

    JDK/jre/lib/ext comm.jar

    JRE/lib/ext comm.jar
    JRE/lib javax.comm.properties
    JRE/bin win32com.dll

    import java.io.*;
    import java.util.*;
    import javax.comm.*;

    public class Ports {
    public static void main(String[] args) {
    Enumeration e = CommPortIdentifier.getPortIdentifiers();

    while (e.hasMoreElements()) {
    CommPortIdentifier cpi =
    (CommPortIdentifier) e.nextElement();
    System.out.println(cpi.getName());
    }
    }
    }

    --

    Knute Johnson
    email s/nospam/knute/
    Knute Johnson, Nov 15, 2006
    #6
  7. hr.org.fer

    hr.org.fer Guest

    On Nov 15, 1:02 am, Knute Johnson <>
    wrote:
    > JDK/jre/lib/ext comm.jar
    >
    > JRE/lib/ext comm.jar
    > JRE/lib javax.comm.properties
    > JRE/bin win32com.dll


    This was the problem. I did not put files in JRE folder, but instead I
    had put them all in JDK (lib and bin) directory. The result was that I
    was able to compile source code (I had put comm.jar as project
    dependency) but at runtime non of the ports were accessible. Now
    everything works fine and I can access all of my ports.


    > import java.io.*;
    > import java.util.*;
    > import javax.comm.*;
    >
    > public class Ports {
    > public static void main(String[] args) {
    > Enumeration e = CommPortIdentifier.getPortIdentifiers();
    >
    > while (e.hasMoreElements()) {
    > CommPortIdentifier cpi =
    > (CommPortIdentifier) e.nextElement();
    > System.out.println(cpi.getName());
    > }
    > }
    >
    > }


    Yes, this compiles and runs OK now. Thanks for the assistance.
    hr.org.fer, Nov 15, 2006
    #7
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. koko

    Pipelining in VHDL

    koko, Apr 29, 2004, in forum: VHDL
    Replies:
    2
    Views:
    5,629
    mizocom
    Apr 29, 2004
  2. Peggy
    Replies:
    0
    Views:
    624
    Peggy
    Sep 8, 2004
  3. tulip

    pipelining

    tulip, Nov 5, 2004, in forum: VHDL
    Replies:
    0
    Views:
    618
    tulip
    Nov 5, 2004
  4. Andrea Campi

    Pipelining tutorial wanted

    Andrea Campi, Nov 14, 2004, in forum: VHDL
    Replies:
    9
    Views:
    2,182
    Mike Treseler
    Nov 19, 2004
  5. mreister
    Replies:
    1
    Views:
    3,152
    mreister
    May 25, 2010
Loading...

Share This Page