JavaRush /Java Blog /Random EN /SMS from 3g modem
Izhak
Level 22
Москва

SMS from 3g modem

Published in the Random EN group
In continuation of yesterday's story, I did a little research on the topic of sending messages from a 3g modem. I tried it with an MTS modem. SMS from 3g modem - 1 After connecting and installing the program, two com ports were detected MobileConnect - Application Interface (COM34) MobileConnect - PC UI Interface (COM33) To send messages, you had to connect to the COM33 port. Code I received package ComKEB; import jssc.*; import java.util.Scanner; /** * Created by ipolma on 8/15/2014. */ public class ComKEB { public static void main(String[] args) { String[] retPorts = SerialPortList.getPortNames(); //for (String port: retPorts){System.out.println(port);} SerialPort serialPort = new SerialPort(retPorts[3]);//"COM4"); указываем второй порт System.out.println(serialPort.getPortName()); if (openSerialPort(serialPort)) { System.out.println("Open"); System.out.println("For close type: \nclose"); } else System.out.println("Not open"); try { Scanner scanner = new Scanner(System.in); String in; serialPort.writeBytes("AT+cmgf=1\r".getBytes()); serialPort.writeBytes("at+cmgs=\"+7926*******\"\r".getBytes()); serialPort.writeBytes("qwweqwe\032".getBytes());//calling ctrl+z while (true) { Thread.sleep(1000); if (scanner.hasNext()) { if ("close".equals((in=scanner.nextLine()))) { if (serialPort.closePort()) System.out.println(serialPort.getPortName() +" close successfull;"); System.exit(0); }else{ } } } }catch(Exception e){e.printStackTrace();} } private static boolean openSerialPort(SerialPort serialPort) { try { //Открываем порт if (serialPort.isOpened()) serialPort.closePort(); //Здесь бывает ситуация Busy, которую не обработаешь - только если ожидать serialPort.openPort(); //Выставляем параметры serialPort.setParams(SerialPort.BAUDRATE_9600, SerialPort.DATABITS_8, SerialPort.STOPBITS_1, SerialPort.PARITY_NONE); //Включаем аппаратное управление потоком serialPort.setFlowControlMode(SerialPort.FLOWCONTROL_NONE); PortReader portReader = new PortReader(serialPort); serialPort.addEventListener(portReader, SerialPort.MASK_RXCHAR); return true; }catch(Exception e){ e.printStackTrace(); return false; } } private static class PortReader implements SerialPortEventListener { SerialPort serialPort; public PortReader(SerialPort serialPort) { this.serialPort = serialPort; } public void serialEvent(SerialPortEvent event) { if (event.isRXCHAR() && event.getEventValue() > 0) { try { //Получаем ответ от устройства, обрабатываем данные и т.д. byte[] data = serialPort.readBytes(event.getEventValue()); for (byte b:data) { System.out.println(b); } } catch (SerialPortException ex) { System.out.println(ex); } } } } } an COM33 Open For close type: close OK > +CMGS: 6 OK ^RSSI: 17 close COM33 close successfull; SMS with the text qwweqwe . True, I haven’t been able to read anything yet. But so far so good :) http://stackoverflow.com/questions/9393097/receiving-and-sending-sms-through-gsm-modem http://stackoverflow.com/questions/9257302/sending-sms-at- commands-to-3g-modem-using-php http://habrahabr.ru/post/133085/ http://serj.kz/content/3
Comments
TO VIEW ALL COMMENTS OR TO MAKE A COMMENT,
GO TO FULL VERSION