Napisałem program który jest w stanie wysłać SMS wszystko działa bez najmniejszego problemu. Jednak potrzebuje uzyskać potwierdzenia wysłania wiadomości i tu jest problem nie jestem w stanie odczytać odpowiedzi modułu na komendy AT. Dodam ze moduł połączony do USB. Do komunikcja z modułem wykorzystują biblioteke rxtx. Aha korzystam również z programu do nasłuchu portu COM z którego korzysta moduł Advanced Serial Port MOnitor" pokazuje on że komendy AT zostaly wyslane na port COM i ok jednak nie pokazuje odpowiedzi modułu. Prosiłbym o pomoc. Co najwyzej udało mi sie dostać bełkot typu [B@355da254" .
import java.io.*;
import java.util.*;
import gnu.io.*;
public class SMSsender {
static Enumeration portList;
static CommPortIdentifier portId;
static String messageString4 = "AT";
//static String messageString5 = "AT+CPIN=\"7078\"";
static String messageString = "AT+CMGF=1";
static String messageString2 = "AT+CMGS=\"+4866467xxxx\"";
static String messageString3 = "TESTY";
static SerialPort serialPort;
static OutputStream outputStream;
static InputStream inputStream;
static char enter = 13;
static char CTRLZ = 26;
public static void main(String[] args) throws InterruptedException {
portList = CommPortIdentifier.getPortIdentifiers();
while (portList.hasMoreElements()) {
portId = (CommPortIdentifier) portList.nextElement();
if (portId.getPortType() == CommPortIdentifier.PORT_SERIAL) {
if (portId.getName().equals("COM3")) {
try {
serialPort = (SerialPort)
portId.open("COM3", 2000);
} catch (PortInUseException e) {System.out.println("err");}
try {
outputStream = serialPort.getOutputStream();
inputStream = serialPort.getInputStream();
} catch (IOException e) {e.printStackTrace();}
try {
serialPort.setSerialPortParams(9600,
SerialPort.DATABITS_8,
SerialPort.STOPBITS_1,
SerialPort.PARITY_NONE);
} catch (UnsupportedCommOperationException e) {e.printStackTrace();}
try {
outputStream.write((messageString4 + enter).getBytes());
Thread.sleep(100);
outputStream.flush();
byte buffer[] = new byte[10000];
inputStream.read(buffer);
System.out.println("Odpowiedz po komendzie \"At\": "+buffer.toString());
//outputStream.write((messageString5 + enter).getBytes());
//Thread.sleep(100);
//outputStream.flush();
outputStream.write((messageString + enter).getBytes());
Thread.sleep(100);
outputStream.flush();
outputStream.write((messageString2 + enter).getBytes());
Thread.sleep(100);
outputStream.flush();
outputStream.write((messageString3 + CTRLZ).getBytes());
outputStream.flush();
byte buffer1[] = new byte[100000];
// read the response from mobile phone
inputStream.read(buffer1);
System.out.println("Odpowiedz po komendzie \"Testy2\": "+buffer.toString());
System.out.println("Wiadomosc wyslana");
Thread.sleep(3000);
outputStream.close();
serialPort.close();
System.out.println("Port Com Zamkniety");
} catch (IOException e) {e.printStackTrace();}
}
}
}
}
}