Pipelining COM ports  
Author Message
hr.org.fer





PostPosted: 2006-11-13 21:41:00 Top

java-programmer, Pipelining COM ports 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?

 
Thomas Fritsch





PostPosted: 2006-11-14 0:41:00 Top

java-programmer >> Pipelining COM ports 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
 
hr.org.fer





PostPosted: 2006-11-14 6:07:00 Top

java-programmer >> Pipelining COM ports > 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.

 
 
Thomas Fritsch





PostPosted: 2006-11-14 7:27:00 Top

java-programmer >> Pipelining COM ports "hr.org.fer" <email***@***.com> 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


 
 
hr.org.fer





PostPosted: 2006-11-14 21:25:00 Top

java-programmer >> Pipelining COM ports 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.

 
 
Knute Johnson





PostPosted: 2006-11-15 8:02:00 Top

java-programmer >> Pipelining COM ports 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/
 
 
hr.org.fer





PostPosted: 2006-11-15 19:30:00 Top

java-programmer >> Pipelining COM ports On Nov 15, 1:02 am, Knute Johnson <email***@***.com>
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.