• 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 a Serial Port

 
Ranch Hand
Posts: 120
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Guys,

I had a look at other threads on serial ports but I still couldn't get mine to work.
Where do I put the port number?
Assume I'm trying to open comm 1. I want to make it really straightforward and do away with assigning variables for now.

I hope someone could help me here.




Karen
 
Ranch Hand
Posts: 808
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What problems are you having? Are you getting compile errors? (I ask because there's a typo in your code snippet, where the 'l' is left out of "serialPort".)

Also, your import statements must come before the class declarations, not inside the class declarations...
[ July 19, 2005: Message edited by: Jeff Bosch ]
 
Karen Baog
Ranch Hand
Posts: 120
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
They're just typo errors. In my test program the import is outside the class.
In the class SerialTest, when I did this:


An exception is thrown, and the error message is: "null". So, it seems it can't see a port.I havee the javax.comm.properties in my compiler's lib directory.
This is the structure of my JBuilder, and where the API comm files are placed:




Hope you can help.
 
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Instead of



use



That will print out the error message, if one is thrown.
 
Karen Baog
Ranch Hand
Posts: 120
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The error is :
java.lang.NullPointerException
 
Ranch Hand
Posts: 403
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You haven't initialised your "portId" variable (it's still null).
You'll need something along the lines of:

portId = CommPortIdentifier.getPortIdentifier("COM1");
 
What's that smell? I think this tiny ad may have stepped in something.
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic