• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

opening serial port

 
Ranch Hand
Posts: 183
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 342
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Mike,

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?
 
Mike Southgate
Ranch Hand
Posts: 183
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ben;
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...

ms
reply
    Bookmark Topic Watch Topic
  • New Topic