Pipelining COM ports

H

hr.org.fer

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?
 
T

Thomas Fritsch

hr.org.fer said:
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]
 
H

hr.org.fer

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

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.
 
T

Thomas Fritsch

hr.org.fer said:
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");
 
H

hr.org.fer

Thomas said:
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.
 
K

Knute Johnson

hr.org.fer said:
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());
}
}
}
 
H

hr.org.fer

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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,743
Messages
2,569,478
Members
44,898
Latest member
BlairH7607

Latest Threads

Top