You can find it in the following package
http://www.cs.uml.edu/~fredm/courses/91.305/software/JDK118-javaxcomm.zip
and if you succeed in detecting the serial port with javax.comm just tell me about your advancement
more information there
http://java.sun.com/developer/JDCTechTips/2002/tt0122.html
http://www.cs.uml.edu/~fredm/courses/91.305-fall04/javasetup.shtml
all the best
I got it to work =). Thank god.
I had to put the .dll in the system32 directory. I put the properties file in the jre/lib (I also put the dll here, but it did not work on its own). I added the .jar file as an additional archived source (I'm using eclipse). And then was able to run a GPS connectionTest without fail.
Here is that source code which you may want to use as reference in terms of detecting the serial port.
http://gpslib4j.sourceforge.net/
hey guys.....plzzz help me out....
1st of all i don't hv the properties file.....
secondly....i need to know how can i get modem inputs in my PC....
I m doin a project on takin alphanumeric input from modem which will b typed by the phone user and performing a search in my database and on that searched tuple i need to take that and convert to speech which again i need to read back to the phone via modem.
its a bit type of IVR project....
PLzzzzz help me out guys....
Some things I've found out about using javax.comm (using JDK118-javaxcomm.zip; link in posting 2 by Yanos):
- comm.jar has to be on the classpath (for sure ;-))
- win32com.dll is allowed to be in any dir but you have to point to that dir using the system property java.library.path: e.g.
java -Djava.library.path=<the dir that contains win32com.dll> -classpath ...
The search strategy used to find javax.comm.properties:
- first: searching for: System.getProperty("java.home") + File.separator + "lib" + File.separator + "javax.comm.properties"
- if not found: javax.comm.properties is searched in the same dir comm.jar is stored; that's done by tokenizing System.getProperty("java.class.path") using a StreamTokenizer using File.pathSeparatorChar (";" on Win32) as token delimiter;
Because "_" and ":" are not defined for that StreamTokenizer as "normal" characters that are allowed inside a filename it won't work if you have a "_" inside the path to your comm.jar and it won't work if comm.jar is located on another drive than the current!!!!! ;-(((
Remember that for parsing / tokenizing any path always the system dependend File.pathSeparatorChar / File.separatorChar is used
Initialization of CommPortIdentifier is really bad. The attached class does (for me) a better job. It removes the restrictions (no "_", ":" in classpath) as described in my previous posting. See JavaDoc on how to use. Please reply if it works for you too.
import java.io.File;
import java.io.IOException;
import java.io.StreamTokenizer;
import java.io.StringReader;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import javax.comm.CommPortIdentifier;
/**
* This class tries to do a better initialization of javax.comm than
* javax.comm.CommPortIdentifier (date: 15th Nov 1998) does because
* the original implementation does not tokenize the classpath on Win32 systems
* in a correct way.
* <P/>
* Just force the loading of that class does the job:
* <pre>
* Class.forName( "JavaXCommInitializer" );
* </pre>
* or
* <pre>
* Class c = JavaXCommInitializer.class;
* </pre>
* If not already done this class first forces the initialization of the original
* javax.comm.CommPortIdentifier (by calling getPortIdentifiers()) and runs the own initialization
* only if no ports were returned.
* <P/>
* Therefore access to private methods of javax.comm.CommPortIdentifier using the reflection
* API is necessary ;-). This will not be possible if you have a SecurityManager installed and not granted
* the necessary permissions.
* <P/>
* Most of the code is based on a decompiled version of javax.comm.CommPortIdentifier downloaded from
* http://www.cs.uml.edu/~fredm/courses/91.305/software/JDK118-javaxcomm.zip
*/
public class JavaXCommInitializer {
private JavaXCommInitializer() {}
private static String findPropFile() {
String s = System.getProperty("java.class.path");
StreamTokenizer streamtokenizer = new StreamTokenizer(((java.io.Reader) (new StringReader(s))));
streamtokenizer.whitespaceChars(((int) (File.pathSeparatorChar)), ((int) (File.pathSeparatorChar)));
streamtokenizer.wordChars(((int) (File.separatorChar)), ((int) (File.separatorChar)));
// characters allowed in a path (as long as they're not conflicting with File.pathSeparatorChar
char[] normalChars = { '.', ':', '_' };
for( int i = 0; i < normalChars.length; i++ ) {
char c = normalChars[i];
if( c != File.pathSeparatorChar ) {
streamtokenizer.ordinaryChar(c);
streamtokenizer.wordChars(c, c);
}
}
try {
while(streamtokenizer.nextToken() != -1) {
int i = -1;
if(streamtokenizer.ttype == -3 && (i = streamtokenizer.sval.indexOf("comm.jar")) != -1) {
String s1 = streamtokenizer.sval;
File file = new File(s1);
if(file.exists()) {
String s2 = s1.substring(0, i);
if(s2 != null)
s2 = s2 + "." + File.separator + "javax.comm.properties";
else
s2 = "." + File.separator + "javax.comm.properties";
File file1 = new File(s2);
if(file1.exists())
return file1.getCanonicalPath();
else
return null;
}
}
}
}
catch(IOException _ex) { }
return null;
}
private static void callPrivateMethod( Class clazz, String methodName, Class[] argTypes, Object[] args )
throws
Exception {
Method m = clazz.getDeclaredMethod( methodName, argTypes );
m.setAccessible( true );
m.invoke( null, args );
}
private static void setPrivateAttribute( Class clazz, String attrName, Object value )
throws
Exception {
Field f = clazz.getDeclaredField( attrName );
f.setAccessible( true );
f.set( null, value );
}
static {
// call the default initialization of javax.comm ...
if( !CommPortIdentifier.getPortIdentifiers().hasMoreElements() ) {
// ... if no ports found try to do it better ;-)
// no need for loading javax.comm.properties from <JAVA_HOME>/lib/javax.comm.properties
// as this is done very well by default init in CommPortIdentifier
// search propFile
String myPropfilename = findPropFile();
try {
if( myPropfilename != null ) {
// loadDriver(propfilename);
callPrivateMethod( CommPortIdentifier.class, "loadDriver", new Class[]{ String.class }, new Object[]{ myPropfilename } );
// propfilename = myPropfilename;
setPrivateAttribute( CommPortIdentifier.class, "propfilename", myPropfilename );
}
}
catch(Exception e) {
System.err.println(((Object) e));
}
}
}
}