Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Opening a Serial Port

 
Karen Baog
Ranch Hand
Posts: 120
  • Mark post as helpful
  • send pies
  • 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
 
Jeff Bosch
Ranch Hand
Posts: 805
  • Mark post as helpful
  • send pies
  • 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
  • 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.
 
Richard Anderson
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator
The error is :
java.lang.NullPointerException
 
James Swan
Ranch Hand
Posts: 403
  • Mark post as helpful
  • send pies
  • 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");
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic