作者kenlan (kenlan )
看板java
标题[问题] 关於使用java comm来寄sms的问题
时间Sun Dec 26 02:44:03 2010
小第算是java的新手 最近写了一个寄sms的程式
public class Main {
public static void main(String[] args) throws PortInUseException, IOException, NoSuchPortException, UnsupportedCommOperationException {
String port1="COM6";
OutputStream outputStream;
InputStream inputStream;
int msg;
try {
//建立com port连线
SerialPort serialPort1 = (SerialPort) CommPortIdentifier.getPortIdentifier(port1).open("Main", 2000);
try {
serialPort1.setSerialPortParams(9600, SerialPort.DATABITS_8, SerialPort.STOPBITS_1, SerialPort.PARITY_NONE);
inputStream = serialPort1.getInputStream();
outputStream = serialPort1.getOutputStream();
outputStream.write("at+cmgf=0\r\n".getBytes()); //进入PDU模式
outputStream.write("at+cmgs=18\r\n".getBytes());
outputStream.write("0011000c918896356712340004aa0441424344".getBytes());
outputStream.write(new byte[]{(byte)0x1a});
/*String aaa=Integer.toHexString(26);
System.out.println(aaa);
outputStream.write(aaa.getBytes());*/
int size = 0;
while(true)
{
while(( size = inputStream.available()) > 0 )
{
byte [] feedback= new byte [size];
msg=inputStream.read(feedback,0,feedback.length);
System.out.println(new String(feedback));
}
}
} catch (UnsupportedCommOperationException ex) {
Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
}
} catch (NoSuchPortException ex) {
Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
在ctrl+z的地方,也就是0x1A的地方,一直失败
无法完成寄信,使用过很多种ctrl+z的方式
回传值只有停在
at+cmgf=0
OK
这边
请问这边的问题是出在那里呢??
谢谢大家
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 118.171.99.142
1F:→ kenlan:发现问题是在AT COMMAND指令无法重覆下,但是还是没解决 12/26 14:35
3F:→ qrtt1:还是你很想要自己写!? 12/26 14:45
4F:→ kenlan:谢谢楼上,我成功了,是用原本的CODE加上sleep 3秒 12/26 15:13