📄 commtest.java
字号:
package misc;//import gnu.io.*;import javax.comm.*;import java.util.*;import java.io.*;import org.smslib.*;public class CommTest{ static CommPortIdentifier portId; static Enumeration portList; static int bauds[] = { 19200, 38400, 115200 }; public static void main(String[] args) { portList = CommPortIdentifier.getPortIdentifiers(); while (portList.hasMoreElements()) { portId = (CommPortIdentifier) portList.nextElement(); if (portId.getPortType() == CommPortIdentifier.PORT_SERIAL) { System.out.println("Found port: " + portId.getName()); for (int i = 0; i < bauds.length; i++) { System.out.print(" Trying at " + bauds[i] + "..."); try { SerialPort serialPort; InputStream inStream; OutputStream outStream; int c; String response; serialPort = (SerialPort) portId.open("SMSLibCommTester", 1971); serialPort.setFlowControlMode(SerialPort.FLOWCONTROL_RTSCTS_IN); serialPort.enableReceiveTimeout(2000); inStream = serialPort.getInputStream(); outStream = serialPort.getOutputStream(); c = inStream.read(); while (c != -1) c = inStream.read(); outStream.write('A'); outStream.write('T'); outStream.write('\r'); outStream.write('A'); outStream.write('T'); outStream.write('\r'); outStream.write('A'); outStream.write('T'); outStream.write('\r'); try { Thread.sleep(1000); } catch (Exception e) { } response = ""; c = inStream.read(); while (c != -1) { response += (char) c; c = inStream.read(); } serialPort.close(); if (response.indexOf("OK") >= 0) { System.out.print(" Getting Info..."); CService srv = new CService(portId.getName(), bauds[i], "", ""); try { srv.connect(); System.out.println(" Found: " + srv.getDeviceInfo().getModel()); srv.disconnect(); } catch (Exception e) { System.out.println(" Nobody here!"); } srv = null; } else System.out.println(" Nobody here!"); } catch (Exception e) { System.out.println(" Nobody here!"); } } } } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -