AT指令发送短信问题,在线等待!!急急急急
qyluo 2004-07-30 11:35:08 下面是一段用AT指令发送短信的代码,有点问题,高手帮忙啊!
public static void pduSend() throws Exception {
String str = "";
String resp = "";
String strSend = "cmcctest";
outputStream.write("AT\r".getBytes());
resp = getResponse(inStream);
System.out.println(resp);
outputStream.write("ATE0\r".getBytes());
resp = getResponse(inStream);
System.out.println(resp);
str = "AT+CMGF=0\r";
outputStream.write(str.getBytes());
resp = getResponse(inStream);
//cmcctest 的pdu串如下
pdu =
"0891683108100005F011000D91683186419156F7000800100063006D006300630074006500730074";
str = "AT+CMGS=" + 31 + "\r";
outputStream.write(str.getBytes());
int count = 0, c;
while (count < 4) {
c = inStream.read();
if (c != -1) {
count++;
}
System.out.println(c);
}
//执行下面这条语句出错(IOException)
outputStream.write(pdu.getBytes());
outputStream.write((char)26);
}
public static void main(String[] args) throws Exception {
portList = CommPortIdentifier.getPortIdentifiers();
while (portList.hasMoreElements()) {
portId = (CommPortIdentifier) portList.nextElement();
if (portId.getPortType() == CommPortIdentifier.PORT_SERIAL) {
// if (portId.getName().equals("COM1")) {
if (portId.getName().equals("COM5")) {
try {
serialPort = (SerialPort)
portId.open("SimpleWriteApp", 2000);
outputStream = serialPort.getOutputStream();
inStream = serialPort.getInputStream();
serialPort.setSerialPortParams(9600,
SerialPort.DATABITS_8,
SerialPort.STOPBITS_1,
SerialPort.PARITY_NONE);
pduSend();
}
catch (Exception e) {
e.printStackTrace();
}
finally {
serialPort.close();
}
}
}
}
}
前面的代码执行都没有问题,就是在outputStream.write(pdu.getBytes());时报io错误!!!!