AT指令发送短信问题,在线等待!!急急急急
下面是一段用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错误!!!!
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错误!!!!
...全文
相关推荐
c + + 计 时 器 急 急 急急 急 急急 急 急急 急 急急 急 急急 急 急急 急 急急 急 急急 急 急急 急 急
c + + 计 时 器 急 急 急急 急 急急 急 急急 急 急急 急 急急 急 急急 急 急急 急 急急 急 急急 急 急
这是sdk调用源文件,急急急急急急
这是sdk调用源文件,急急急急急急
急急急平面波matlab仿真中如何用颜色表示声压级的大小-Doc1.doc
急急急平面波matlab仿真中如何用颜色表示声压级的大小-Doc1.doc 原程序是: f=125; c0=344; k=2*f*pi./c0; r=0:0.001:0.5; p=exp; P=abs; plot; xlabel'); ylabel'); 不知程序对不对 请问怎么在平面波matlab仿真中如何用颜色表示声压级的大小,能不能帮忙把程序完整的表示出来
苏少版五年级音乐下册(简谱)第3单元《听:急急风》教学设计.pdf
苏少版五年级音乐下册(简谱)第3单元《听:急急风》教学设计.pdf
(51页PPT)急急脚咖啡品牌手册.pptx
(51页PPT)急急脚咖啡品牌手册.pptx


Java SE
