Skocz do zawartości

przemo199980

Członkowie
  • Postów

    2
  • Dołączył

  • Ostatnio

przemo199980's Achievements

Newbie

Newbie (1/14)

0

Reputacja

  1. To działający kod może się komuś przyda. Powodem nie działanie było błędne wprowadzenie bądź brak enter i CTRL+z import java.io.*; import java.util.*; import gnu.io.*; public class SMSsender { static Enumeration portList; static CommPortIdentifier portId; static String messageString1 = "AT"; // komenda do sprawdzenia poprawnosci modulu gsm static String messageString2 = "AT+CPIN=\"7078\""; // podanie kodu pin jesli jest static String messageString3 = "AT+CMGF=1"; // ustawienia trybu tekstowego wiadomosci static String messageString4 = "AT+CMGS=\"+4866467xxxx\""; // podanie numeru adresata wiadomosci static String messageString5 = "TESTY2"; // tresc wysylanej wiadomosci 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")) {// poszukiwanie portu COM try { serialPort = (SerialPort)// otwarcie portu COM do ktorego przylaczony jest modul gsm portId.open("COM3", 2000); } catch (PortInUseException e) {System.out.println("err");} try { outputStream = serialPort.getOutputStream();//tworzenie wyjsciowego kanalu przesylowego inputStream = serialPort.getInputStream(); } catch (IOException e) {e.printStackTrace();} try { serialPort.setSerialPortParams(9600, SerialPort.DATABITS_8, SerialPort.STOPBITS_1, SerialPort.PARITY_NONE); // ustawienia parametrów portu COM (musza one się zgadzac z tymi w Windows } catch (UnsupportedCommOperationException e) {e.printStackTrace();} try { outputStream.write((messageString1 + enter).getBytes());//Podanie komendy at do sprawdzenie czy modul dziala Thread.sleep(100); outputStream.flush(); outputStream.write((messageString2 + enter).getBytes()); // podanie kodu pin do modulu Thread.sleep(100); outputStream.flush(); outputStream.write((messageString3 + enter).getBytes()); // ustwienie trybu tekstowego wiedomosci Thread.sleep(100); outputStream.flush(); outputStream.write((messageString4 + enter).getBytes()); // podanie numeru telefony adresata wiadomosci Thread.sleep(100); outputStream.flush(); outputStream.write((messageString5 + CTRLZ).getBytes()); // podanie tresci wiadomosci i jej wyslanie outputStream.flush(); Thread.sleep(300); System.out.println("Wyslano wiadomosc"); Thread.sleep(3000); outputStream.close(); serialPort.close(); System.out.println("Port COM zamkniety"); } catch (IOException e) {e.printStackTrace();} } } } } }
  2. Witam mam od kilku dni próbuje napisać program do wysyłanie sms poprzez moduł GSM. Udało mi się za pomocą programu wysłać odpowiednia komendy na port Com komputera jednak bez reakcji modułu. Dodam ze gdy te same komendy wysalem programem tera temp pro moduł bezproblemu wysyła SMS. Jednak gdy uzywam mojego programu juz nie. Wiem że pewnie bład jest gdzieś w sposobie wprowadzania przeze mnie komend ale nie mam juz pojecią jaki to problem. Przeczesałem większą cześć internetu i juz nie mam pojecia co robie zle. Z góry dzięki za pomoc. import java.io.*; import java.util.*; import gnu.io.*; public class prawiefinal { static Enumeration portList; static CommPortIdentifier portId; static String messageString4 = "AT \r"; static String messageString = "AT+CMGF=1 \r"; static String messageString2 = "AT+CMGS=\"+4866467xxxx\"\r"; static String messageString3 = "> TESTY \u001A\r"; static SerialPort serialPort; static OutputStream outputStream; 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(); } 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.getBytes()); // outputStream.write(13); Thread.sleep(3000); outputStream.flush(); outputStream.write(messageString.getBytes()); //outputStream.write(13); Thread.sleep(3000); outputStream.flush(); outputStream.write(messageString2.getBytes()); //outputStream.write(13); Thread.sleep(3000); outputStream.flush(); outputStream.write(messageString3.getBytes()); // Thread.sleep(1000); outputStream.write(26); outputStream.flush(); System.out.println(messageString); Thread.sleep(3000); outputStream.close(); serialPort.close(); } catch (IOException e) {e.printStackTrace();} } } } } }
×
×
  • Utwórz nowe...