Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Pipelining COM ports

Reply
Thread Tools

Pipelining COM ports

 
 
hr.org.fer
Guest
Posts: n/a
 
      11-13-2006
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?

 
Reply With Quote
 
 
 
 
Thomas Fritsch
Guest
Posts: n/a
 
      11-13-2006
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
 
Reply With Quote
 
 
 
 
hr.org.fer
Guest
Posts: n/a
 
      11-13-2006
> 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.

 
Reply With Quote
 
Thomas Fritsch
Guest
Posts: n/a
 
      11-13-2006
"hr.org.fer" <(E-Mail Removed)> 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


 
Reply With Quote
 
hr.org.fer
Guest
Posts: n/a
 
      11-14-2006
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.

 
Reply With Quote
 
Knute Johnson
Guest
Posts: n/a
 
      11-15-2006
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/
 
Reply With Quote
 
hr.org.fer
Guest
Posts: n/a
 
      11-15-2006
On Nov 15, 1:02 am, Knute Johnson <(E-Mail Removed)>
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.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Type of actual ports is not compatible with type of ports of entity. mreister VHDL 1 05-25-2010 11:30 AM
Recommendations Please for a PCI card w/ two USB 2 Ports and FireWaire Ports Mike Digital Photography 27 02-26-2006 12:54 AM
enable pipelining on Firefox D Cheung Firefox 1 02-07-2005 12:42 PM
How to purposely make pipelining in Handel-C? Peggy VHDL 0 09-08-2004 01:15 AM
Pipelining in VHDL koko VHDL 2 04-29-2004 06:51 PM



Advertisments