使用smslib包详解
1.配置comm.jar包
win32com.dll
to your <JDK>\bin
directory. C:\>copy c:\commapi\win32com.dll to c:\jdk1.1.6\bin
2) Copy comm.jar
to your <JDK>\lib
directory. C:\>copy c:\commapi\comm.jar c:\jdk1.1.6\lib
3) Copy javax.comm.properties
to your <JDK>\lib
directory.
4) C:\>copy c:\commapi\javax.comm.properties c:\jdk1.1.6\lib
The javax.comm.properties
file must be installed. If it is not, no ports will be found by the system.
Add comm.jar
to your classpath (do not do this step for a JRE installation).
If you don't have a classpath defined: C:\>set CLASSPATH=c:\jdk1.1.6\lib\comm.jar
If you already have a classpath defined: C:\>set CLASSPATH=c:\jdk1.1.6\lib\comm.jar;%classpath%
5)特别注意在myeclipse建立工程时,jre选择java的 不要使用myeclipse的否则报端口没找到错误 javax.comm.NoSuchPortException
2.建立工程导入lib包 comm.jar log4j-1.2.13.jar smslib3.2.2.jar
3.查看端口是否配置成功
Enumeration en = CommPortIdentifier.getPortIdentifiers();
CommPortIdentifier portId;
while (en.hasMoreElements())
{
portId = (CommPortIdentifier) en.nextElement();
if (portId.getPortType() == CommPortIdentifier.PORT_SERIAL){
System.out.println(portId.getName());
}
}
成功打印你机器的端口
不成功不显示
4.使用