There are only two main libraries available for serial communication in Java -- The Java Communiations API Extension, which is apparently not well documented or supported, and RXTX, which is used by Arduino and is included in the folders included with the Arduino IDE. I opted to use the latter, since I already had copies on my harddrive and the Arduino website features a nice tutorial on interfacing with the Arduino and RXTX. Perfect! The tutorial goes into extensive detail on usage: The rxtxSerial.dll needs to be included in the PATH, and the RXTXcomm.jar needs to be included in the CLASSPATH.
The latter is not always so easy with Eclipse. JAR files, folders, and projects are all added to the CLASSPATH seperately, and there are seperate CLASSPATH setups for building and running. This is all detailed (for a slightly old but still followable version) here, but following these instructions wasn't enough for my purposes. The author of these instructions had similar qualms:
It seems to meI actually had no luck until I broke down and just made a batch file to run the SerialTest program (similar to that found in the Use Sample Code section of the interfacing tutorial, except I put the dll in my main jdk folder, and the jars in my source folder), and I think that's how I'll keep it. Instant success, after hours wasted trying to interface with Eclipse when I already had working code. So if I do ever end up teaching a Java course, I think I'd give the following advice: Sure, use Eclipse for the simple stuff, and use it as a write-time error checker to save time on compiling, but for anything complicated, don't let your code be a slave to your IDE; just use the command line.Add Variables, Add Libraries, andAdd JARSall add collections of classpath elements that are defined inside Eclipse, but I don't know their differences. When I specify classpath in any IDE, I like to explicitly spell out Jar files and directories, without using any IDE-specific artifacts. I suppose the whole purpose of having them is to reuse them in other projects, but I find it's pretty unrealistic due to various jar version differences.
I don't care about the difference between a jar file and a directory, both of them are just an element in the classpath. I like the fact that NetBeans combine them into one singleAdd JAR/Folderbutton.
No comments:
Post a Comment