aspose file tools*
The moose likes Beginning Java and the fly likes Opening a Serial Port Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Opening a Serial Port" Watch "Opening a Serial Port" New topic
Author

Opening a Serial Port

Karen Baog
Ranch Hand

Joined: Mar 02, 2005
Posts: 120
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


amerzil co-ed student<br />"Praise be the Code"
Jeff Bosch
Ranch Hand

Joined: Jul 30, 2003
Posts: 805
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 ]

Give a man a fish, he'll eat for one day. Teach a man to fish, he'll drink all your beer.
Cheers, Jeff (SCJP 1.4, SCJD in progress, if you can call that progress...)
Karen Baog
Ranch Hand

Joined: Mar 02, 2005
Posts: 120
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

Joined: May 20, 2005
Posts: 61
Instead of



use



That will print out the error message, if one is thrown.


-Rich, SCJP 1.4
Karen Baog
Ranch Hand

Joined: Mar 02, 2005
Posts: 120
The error is :
java.lang.NullPointerException
James Swan
Ranch Hand

Joined: Jun 26, 2001
Posts: 403
You haven't initialised your "portId" variable (it's still null).
You'll need something along the lines of:

portId = CommPortIdentifier.getPortIdentifier("COM1");
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Opening a Serial Port