SIM900을 기반으로하는 셀 모뎀을 사용하여 Java/Netbeans에서 문자 메시지를 보내려고합니다. TeraTerm을 사용하여 기본 AT 명령을 사용하여 모뎀을 사용하여 메시지를 보낼 수 있는지 확인합니다. 다음 코드는 jssc
을 사용하여 메시지를 보내려고합니다.
오류가 발생하지 않고 데이터가 모뎀에 기록 된 것처럼 보였지만 문자 메시지는 수신되지 않습니다. 전화 번호는 +
과 함께 사용하지 않고 시도했습니다.
TeraTerm에서 숫자는 +
없이 작동해야합니다. 많은 변형이 시도되었고 많은 .println
이 사용되었습니다. 아직 진전이 없습니다.
누군가 내 방식의 오류를 볼 수 있기를 바랍니다.java jssc 모뎀이 메시지를 보냅니다
미리 감사드립니다. Doug
package jssc_test;
import jssc.SerialPort;
import jssc.SerialPortException;
import jssc.SerialPortList;
public class Jssc_test {
public static SerialPort serialPort=null;
public static void main(String[] args) throws InterruptedException {
try {
String[] portNames = SerialPortList.getPortNames();
for(int i = 0; i < portNames.length; i++){
System.out.println(portNames[i]);
}
if(portNames.length < 1){
System.out.println("No ports available");
System.exit(0);
}
else{
serialPort = new SerialPort(portNames[0]);
}
System.out.println("Port opened: " + serialPort.openPort());
System.out.println("Params set: " + serialPort.setParams(9600, 8, 1, 0));
System.out.println("\"Hello World!!!\" successfully writen to port: " + serialPort.writeBytes("Hello World!!!".getBytes()));
serialPort.writeBytes(" AT+CMGF=1".getBytes());
Thread.sleep(1000);
System.out.println("bytes back = " + serialPort.readString());
serialPort.writeBytes(" AT+CMGS=\"585*******\"".getBytes()); // \r = <CR>. Tried both with and without '+'. In TeraTerm, only works without +. error if use: \r\n
//Thread.sleep(1000);
//System.out.println("bytes back = " + serialPort.readString());
//serialPort.writeBytes("0x0D".getBytes()); // send <CR>
Thread.sleep(1000);
System.out.println("bytes back = " + serialPort.readString());
serialPort.writeBytes("THIS IS A TEST from DS.".getBytes()); // placing Cntr-Z string in text did not work: \u001A
//serialPort.writeBytes("0x0D".getBytes()); // send <CR>
serialPort.writeBytes("0x1A".getBytes()); // send <ctrl>Z
Thread.sleep(1000);
System.out.println("bytes back = " + serialPort.readString());
System.out.println("Port closed: " + serialPort.closePort());
}
catch (SerialPortException ex){
System.out.println(ex);
}
} // ******************* end main ***************
} // *********************** end main class ***********************