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错误!!!!
...全文
195 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
qyluo 2004-08-02
  • 打赏
  • 举报
回复
大哥们帮帮忙啊,急急急。。。
lightsword 2004-07-30
  • 打赏
  • 举报
回复
关注...
qyluo 2004-07-30
  • 打赏
  • 举报
回复
有人知道吗!?????
qyluo 2004-07-30
  • 打赏
  • 举报
回复
使用pdu模式,在outputStream.write(pdu.getBytes());出错,估计是pdu.getBytes()的问题,但是不知道怎么改!!!!!!
shadou 2004-07-30
  • 打赏
  • 举报
回复
我一般不等“>”返回就发后面的“0891683108100005F011000D91683186419156F7000800100063006D006300630074006500730074”的。

最多发完后读串口 有没有 ‘error’串。

一起发试试
AT+CMGS=31+char(13)+pdu+char(26);
qyluo 2004-07-30
  • 打赏
  • 举报
回复
有人吗?????

62,614

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧