28.12.2013 Views

Serial Programming - upload.wikimedia....

Serial Programming - upload.wikimedia....

Serial Programming - upload.wikimedia....

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Using Java for <strong>Serial</strong> Communication<br />

• one as part of the private JRE which comes with the JDK to run JDK tools, and<br />

• one as part of the public JRE which comes with the JDK to run applications<br />

Some even claim to have a fourth JRE somewhere in the \Windows directory hierarchy.<br />

JavaComm should at least be installed as extension in the JDK and in all public JREs.<br />

Webstart<br />

JavaComm<br />

A general problem, both for JavaComm and RxTx is, that they resist installation via Java<br />

WebStart 4 :<br />

JavaComm is notorious, because it requires a file called javax.comm.properties to be placed in<br />

the JDK lib directory, something which can't be done with Java WebStart. This is particularly<br />

sad, because the need for that file is the result of some unnecessary design/decision in<br />

JavaComm and could have easily been avoided by the JavaComm designers. Sun constantly<br />

refuses to correct this error, citing the mechanism is essential. Which is, they are lying<br />

through their teeth when it comes to JavaComm, particular, because Java for a long time<br />

has a service provider architecture exactly intended for such purposes.<br />

The contents of the properties file is typically just one line, the name of the java class with<br />

the native driver, e.g.:<br />

driver=com.sun.comm.Win32Driver<br />

The following is a hack which allows to deploy JavaComm via Web Start ignoring that<br />

brain-dead properties file. It has serious drawbacks, and might fail with newer JavaComm<br />

releases - should Sun ever come around and make a new version.<br />

First, turn off the security manager. Some doofus programmer at Sun decided that it would<br />

be cool to again and again check for the existence of the dreaded javax.comm.properties file,<br />

even after it has been loaded initially, for no other apparent reason than checking for the file.<br />

System.setSecurityManager(null);<br />

Then, when initializing the JavaComm API, initialize the driver manually:<br />

String driverName = "com.sun.comm.Win32Driver"; // or get as a JNLP<br />

property<br />

CommDriver commDriver =<br />

(CommDriver)Class.forName(driverName).newInstance();<br />

commDriver.initialize();<br />

RxTx<br />

4 http://java.sun.com/products/javawebstart/<br />

89

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!