Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / November 2006

Tip: Looking for answers? Try searching our database.

Pipelining COM ports

Thread view: 
hr.org.fer - 13 Nov 2006 13:40 GMT
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 - 13 Nov 2006 16:41 GMT
> Is it possible to create a pipeline to virtual COM port (MS Windows)?
>
[quoted text clipped - 4 lines]
> 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?

Signature

Thomas

hr.org.fer - 13 Nov 2006 22:07 GMT
> 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 - 13 Nov 2006 23:26 GMT
> I tried that. :-) You can't open the same port twice. The following
> code:
[quoted text clipped - 10 lines]
> 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");

Signature

Thomas

hr.org.fer - 14 Nov 2006 13:24 GMT
> 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 - 15 Nov 2006 00:02 GMT
>> May be that works:
>>    RandomAccessFile raf = new RandomAccessFile("COM10", "rw");
[quoted text clipped - 9 lines]
> 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());
        }
    }
}

Signature

Knute Johnson
email s/nospam/knute/

hr.org.fer - 15 Nov 2006 11:29 GMT
On Nov 15, 1:02 am, Knute Johnson <nos...@rabbitbrush.frazmtn.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.*;
[quoted text clipped - 12 lines]
>
> }

Yes, this compiles and runs OK now. Thanks for the assistance.


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.