File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes I/O and Streams and the fly likes opening serial port Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "opening serial port" Watch "opening serial port" New topic

opening serial port

Mike Southgate
Ranch Hand

Joined: Jul 18, 2003
Posts: 183
I can't open my serial port in Java. I know it's ok because other programs can communicate over COM1, but I can't.

and my output is:

So I'm getting a PortInUseException. But as you may have noticed, I've inserted code right before to check for that, and it says everythings fine.

Any suggestions?


ms<br />SCJP, SCJD
Ben Wood
Ranch Hand

Joined: Aug 14, 2001
Posts: 342

Does a basic port list test work, e.g...

I must admit I haven't used the isCurrentlyOwned() method, so maybe there is an issue with it? One problem I have noticed is that if you leave something running that has been used to communicate over the port then Java cannot subsequently get hold of it. For example if I run a QBASIC program and then exit QBASIC but leave the command prompt open that can cause Java problems. Are you sure everything else that might have had access to the port is completely shut down?

SCJP 1.4,
Mike Southgate
Ranch Hand

Joined: Jul 18, 2003
Posts: 183
thanks for your reply. Yes, listing the ports works fine. That's waht the getPorts() method in the first line of code does. It returns COM1 and COM2 as serial ports.

I was thinking about other processes not letting go of the port too, to test it I did two things: 1) insert the code to check for port in use, and 2) rebooted and tried it first thing.

I'm really not sure how to proceed on this. Perhaps I should take this code out into an independent class and run it on another machine. Can't think of many more approaches...

I agree. Here's the link:
subject: opening serial port
jQuery in Action, 3rd edition