Accueil > > > ENVOIE DES SMS VIA LES COMMANDES AT
ENVOIE DES SMS VIA LES COMMANDES AT
Information sur la source
Description
Cette application vous permet d'envoyer des SMS via le protocole de communication pc/GSM "AT Commands". Il vous suffit un modem GSM liè à votre pc avec un cable USB. Allez Les amis j'attends vos commentaires . Bon courage,
Source
- //Classe frame.java
- package essai1;
-
- import java.awt.event.ActionEvent;
-
- import java.awt.event.ActionListener;
-
- import java.awt.BorderLayout;
-
- import java.awt.Color;
-
- import java.awt.Dimension;
-
- import java.io.BufferedReader;
-
- import java.io.IOException;
-
- import java.io.PrintWriter;
-
- import java.util.Enumeration;
-
- import java.util.logging.Level;
-
- import java.util.logging.Logger;
-
-
-
- import javax.comm.CommPortIdentifier;
-
- import javax.comm.NoSuchPortException;
-
- import javax.comm.SerialPort;
-
- import javax.swing.*;
-
-
-
-
-
- public class frame extends JFrame{
-
-
-
- private static final long serialVersionUID = 1L;
-
- private JButton bouton = new JButton("Go");
-
- private JButton bouton2 = new JButton("START");
-
- String reponse="";
-
- private JPanel container = new JPanel();
-
- private JComboBox combo = new JComboBox();
-
- private JLabel label = new JLabel("les ports");
-
- CommPortIdentifier portId;
-
- BufferedReader in;
-
- PrintWriter out;
-
- SerialPort serialPort;
-
-
-
-
-
- private static ClassePort1 port1;
-
- static final private char cntrlZ=(char)26;
-
-
-
- public frame (){
-
- this.setTitle(" Choix");
-
- this.setSize(200, 100);
-
- this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
-
- this.setLocationRelativeTo(null);
-
-
-
- container.setBackground(Color.white);
-
- container.setLayout(new BorderLayout());
-
- combo.addActionListener(new FormeListener());
-
- bouton2.addActionListener(new Bouton2Listener());
-
- bouton.addActionListener(new BoutonListener());
-
- combo.setPreferredSize(new Dimension(100,20));
-
- listePortsDispo();
-
- JPanel south = new JPanel();
-
- south.add(bouton);
-
- south.add(bouton2);
-
- container.add(south, BorderLayout.SOUTH);
-
-
-
- JPanel top = new JPanel();
-
- top.add(label);
-
- top.add(combo);
-
-
-
- container.add(top, BorderLayout.NORTH);
-
- this.setContentPane(container);
-
- this.setVisible(true);
-
- }
-
-
-
-
-
- public void listePortsDispo(){
-
- System.err.println("recherche..." );
-
- Enumeration portList=CommPortIdentifier.getPortIdentifiers();
-
- if (portList==null)
-
- {
-
- System.err.println("Aucun port de communication détecté" );
-
- return;
-
- }
-
- while (portList.hasMoreElements()){
-
- portId=(CommPortIdentifier)portList.nextElement();
-
- combo.addItem(portId.getName());
-
-
-
- System.out.println("* "+portId.getName());
-
- } //fin while
-
- } //fin de la methode listePortsDispo()
-
-
-
- public class BoutonListener implements ActionListener{
-
-
-
- public void actionPerformed(ActionEvent arg0) {
-
- port1.openPort(reponse);
-
-
-
- }
-
-
-
- }
-
- class FormeListener implements ActionListener{
-
-
-
- public void actionPerformed(ActionEvent e) {
-
- reponse=combo.getSelectedItem().toString();
-
-
-
- }
-
- }
-
- public static void envoie_sms(String sms, String phn)throws IOException
-
- {
-
- try
-
- {
-
- port1.envoyer("AT+CMGF=1"+"\r");
-
- port1.envoyer("at+cmgs=\""+phn+"\"\r");
-
- port1.envoyer(sms+cntrlZ+"\r");
-
- Thread.sleep(1500);
-
-
-
- }
-
- catch (Exception ex)
-
- {
-
- Logger.getLogger(ClassePort1.class.getName()).log(Level.SEVERE, null, ex);
-
- }
-
-
-
-
-
- }
-
- class Bouton2Listener implements ActionListener{
-
-
-
- /**
-
- * Redéfinitions de la méthode actionPerformed
-
- */
-
- public void actionPerformed(ActionEvent e) {
-
-
-
- String[] a = {le numéro de GSM (exple:0021699000000)};
-
- try
-
- {
-
- for(int i=0;i<a.length;i++)
-
- {
-
-
-
- envoie_sms("Si tu recois ce message fais moi un bip pour tester mon programme , c rahma",a[i]);
-
- }
-
- }
-
- catch (Exception ex)
-
- {
-
- Logger.getLogger(ClassePort1.class.getName()).log(Level.SEVERE, null, ex);
-
- }
-
-
-
- }
-
-
-
- }
-
-
-
- public static void main(String args[]) throws NoSuchPortException{
-
- port1=new ClassePort1();
-
- new frame ();
-
- port1.closePort();
-
-
-
-
-
- }
-
-
-
- }
-
-
-
-
-
-
-
-
-
-
- //Classe ClassePort1.java
-
- package essai1;
-
- import java.util.TooManyListenersException;
- import java.util.logging.Level;
- import java.util.logging.Logger;
- import javax.comm.CommPortIdentifier;
- import javax.comm.PortInUseException;
- import javax.comm.SerialPort;
- import javax.comm.SerialPortEvent;
- import javax.comm.SerialPortEventListener;
- import javax.comm.UnsupportedCommOperationException;
- import javax.swing.JOptionPane;
- import java.io.*;
- import com.sun.comm.Win32Driver;
-
- public class ClassePort1 implements SerialPortEventListener{
-
- static String TimeStamp;
-
- SerialPort comPort;
- CommPortIdentifier portId;
- OutputStream os;
- static InputStream is;
- static PrintWriter sortie;
- Thread readThread;
- private static BufferedReader bufRead;
-
-
- public ClassePort1()
- {
-
- Win32Driver w32Driver = new Win32Driver();
- w32Driver.initialize();
- }
-
-
- public void openPort(String Portname)
- {
- try{
- portId=CommPortIdentifier.getPortIdentifier(Portname);
- ComControl();
-
- }
-
- catch
- (Exception e) {
- TimeStamp = new java.util.Date().toString();
- System.out.println(TimeStamp + ": ERROR " + portId);
- System.out.println(TimeStamp + ": msg1 - " + e);
- }
- }
- public void ComControl() {
-
- try {
- TimeStamp = new java.util.Date().toString();
-
-
- comPort = (SerialPort) portId.open("essai1", 10000);
- System.out.println("Le port : " + portId.getName() + " est ouvert");
-
-
- } catch (PortInUseException e) {}
- try {
-
- os = comPort.getOutputStream();
-
- bufRead = new BufferedReader(new InputStreamReader(comPort.getInputStream()));
-
- sortie = new PrintWriter(os, true);
- System.out.println("c bon");
-
- } catch (IOException e) {System.out.println("Yaraab");}
-
- try {
- comPort.addEventListener(this);
- } catch (TooManyListenersException e) {}
- comPort.notifyOnDataAvailable(true);
- try {
-
- comPort.setSerialPortParams(4800,
- SerialPort.DATABITS_8,
- SerialPort.STOPBITS_1,
- SerialPort.PARITY_NONE);
- comPort.setFlowControlMode(comPort.FLOWCONTROL_NONE) ;
-
- comPort.setDTR(false);
- comPort.setRTS(false);
-
-
-
- } catch (UnsupportedCommOperationException e) {}
-
- readThread = new Thread();
- readThread.start();
-
- }
-
-
- public void closePort()
- {
- comPort.close();
- }
-
-
- public static void ModeText(String str)
- {String reponse="";
- try
- { int c;
-
- System.out.println("nom");
- sortie.println(str);
- reponse= (String) bufRead.readLine().trim();
- System.out.println( "hhh"+reponse);
- Thread.sleep(3000);
-
- }
- catch (Exception e)
- {
- JOptionPane.showMessageDialog(null,"Exeption dans envoyer()2. "+e.getMessage(),"Envoi...",JOptionPane.ERROR_MESSAGE);
-
- }
-
- }
-
- public void envoyer(String str) throws IOException
- {
- os.write( (byte[]) str.getBytes());
- os.flush();
- os.close();
-
- System.out.println("Le port : est ouvert");
-
- try
- {
- Thread.sleep(3000);
-
- }
- catch (InterruptedException ex)
- {
- Logger.getLogger(ClassePort1.class.getName()).log(Level.SEVERE, null, ex);
- }
-
- }
-
- public void serialEvent(SerialPortEvent arg0)
- {
- throw new UnsupportedOperationException("Not supported yet.");
- }
-
-
-
-
- }
-
-
-
-
//Classe frame.java
package essai1;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Enumeration;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.comm.CommPortIdentifier;
import javax.comm.NoSuchPortException;
import javax.comm.SerialPort;
import javax.swing.*;
public class frame extends JFrame{
private static final long serialVersionUID = 1L;
private JButton bouton = new JButton("Go");
private JButton bouton2 = new JButton("START");
String reponse="";
private JPanel container = new JPanel();
private JComboBox combo = new JComboBox();
private JLabel label = new JLabel("les ports");
CommPortIdentifier portId;
BufferedReader in;
PrintWriter out;
SerialPort serialPort;
private static ClassePort1 port1;
static final private char cntrlZ=(char)26;
public frame (){
this.setTitle(" Choix");
this.setSize(200, 100);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setLocationRelativeTo(null);
container.setBackground(Color.white);
container.setLayout(new BorderLayout());
combo.addActionListener(new FormeListener());
bouton2.addActionListener(new Bouton2Listener());
bouton.addActionListener(new BoutonListener());
combo.setPreferredSize(new Dimension(100,20));
listePortsDispo();
JPanel south = new JPanel();
south.add(bouton);
south.add(bouton2);
container.add(south, BorderLayout.SOUTH);
JPanel top = new JPanel();
top.add(label);
top.add(combo);
container.add(top, BorderLayout.NORTH);
this.setContentPane(container);
this.setVisible(true);
}
public void listePortsDispo(){
System.err.println("recherche..." );
Enumeration portList=CommPortIdentifier.getPortIdentifiers();
if (portList==null)
{
System.err.println("Aucun port de communication détecté" );
return;
}
while (portList.hasMoreElements()){
portId=(CommPortIdentifier)portList.nextElement();
combo.addItem(portId.getName());
System.out.println("* "+portId.getName());
} //fin while
} //fin de la methode listePortsDispo()
public class BoutonListener implements ActionListener{
public void actionPerformed(ActionEvent arg0) {
port1.openPort(reponse);
}
}
class FormeListener implements ActionListener{
public void actionPerformed(ActionEvent e) {
reponse=combo.getSelectedItem().toString();
}
}
public static void envoie_sms(String sms, String phn)throws IOException
{
try
{
port1.envoyer("AT+CMGF=1"+"\r");
port1.envoyer("at+cmgs=\""+phn+"\"\r");
port1.envoyer(sms+cntrlZ+"\r");
Thread.sleep(1500);
}
catch (Exception ex)
{
Logger.getLogger(ClassePort1.class.getName()).log(Level.SEVERE, null, ex);
}
}
class Bouton2Listener implements ActionListener{
/**
* Redéfinitions de la méthode actionPerformed
*/
public void actionPerformed(ActionEvent e) {
String[] a = {le numéro de GSM (exple:0021699000000)};
try
{
for(int i=0;i<a.length;i++)
{
envoie_sms("Si tu recois ce message fais moi un bip pour tester mon programme , c rahma",a[i]);
}
}
catch (Exception ex)
{
Logger.getLogger(ClassePort1.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
public static void main(String args[]) throws NoSuchPortException{
port1=new ClassePort1();
new frame ();
port1.closePort();
}
}
//Classe ClassePort1.java
package essai1;
import java.util.TooManyListenersException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.comm.CommPortIdentifier;
import javax.comm.PortInUseException;
import javax.comm.SerialPort;
import javax.comm.SerialPortEvent;
import javax.comm.SerialPortEventListener;
import javax.comm.UnsupportedCommOperationException;
import javax.swing.JOptionPane;
import java.io.*;
import com.sun.comm.Win32Driver;
public class ClassePort1 implements SerialPortEventListener{
static String TimeStamp;
SerialPort comPort;
CommPortIdentifier portId;
OutputStream os;
static InputStream is;
static PrintWriter sortie;
Thread readThread;
private static BufferedReader bufRead;
public ClassePort1()
{
Win32Driver w32Driver = new Win32Driver();
w32Driver.initialize();
}
public void openPort(String Portname)
{
try{
portId=CommPortIdentifier.getPortIdentifier(Portname);
ComControl();
}
catch
(Exception e) {
TimeStamp = new java.util.Date().toString();
System.out.println(TimeStamp + ": ERROR " + portId);
System.out.println(TimeStamp + ": msg1 - " + e);
}
}
public void ComControl() {
try {
TimeStamp = new java.util.Date().toString();
comPort = (SerialPort) portId.open("essai1", 10000);
System.out.println("Le port : " + portId.getName() + " est ouvert");
} catch (PortInUseException e) {}
try {
os = comPort.getOutputStream();
bufRead = new BufferedReader(new InputStreamReader(comPort.getInputStream()));
sortie = new PrintWriter(os, true);
System.out.println("c bon");
} catch (IOException e) {System.out.println("Yaraab");}
try {
comPort.addEventListener(this);
} catch (TooManyListenersException e) {}
comPort.notifyOnDataAvailable(true);
try {
comPort.setSerialPortParams(4800,
SerialPort.DATABITS_8,
SerialPort.STOPBITS_1,
SerialPort.PARITY_NONE);
comPort.setFlowControlMode(comPort.FLOWCONTROL_NONE) ;
comPort.setDTR(false);
comPort.setRTS(false);
} catch (UnsupportedCommOperationException e) {}
readThread = new Thread();
readThread.start();
}
public void closePort()
{
comPort.close();
}
public static void ModeText(String str)
{String reponse="";
try
{ int c;
System.out.println("nom");
sortie.println(str);
reponse= (String) bufRead.readLine().trim();
System.out.println( "hhh"+reponse);
Thread.sleep(3000);
}
catch (Exception e)
{
JOptionPane.showMessageDialog(null,"Exeption dans envoyer()2. "+e.getMessage(),"Envoi...",JOptionPane.ERROR_MESSAGE);
}
}
public void envoyer(String str) throws IOException
{
os.write( (byte[]) str.getBytes());
os.flush();
os.close();
System.out.println("Le port : est ouvert");
try
{
Thread.sleep(3000);
}
catch (InterruptedException ex)
{
Logger.getLogger(ClassePort1.class.getName()).log(Level.SEVERE, null, ex);
}
}
public void serialEvent(SerialPortEvent arg0)
{
throw new UnsupportedOperationException("Not supported yet.");
}
}
Conclusion
Si quelqu'un a besoin d'aide je serais à votre service.
Historique
- 11 février 2010 16:01:38 :
- Je me suis trompée dans l'ajout des mots clés car ca ma première application que j'ai mis dans ce forum
- 11 février 2010 20:57:25 :
- ajout de l'image
Sources de la même categorie
Commentaires et avis
|
Derniers Blogs
GESTION D'EXCEPTION AVEC LES TASKSGESTION D'EXCEPTION AVEC LES TASKS par richardc
Nous avons vu dans un précédent article comment utiliser Task pour effectuer des opérations dans un autre thread.
Malheureusement, comme tout le monde n'est pas parfait, il se peut que cette exécution se passe mal et qu'une exception se produise.
La...
Cliquez pour lire la suite de l'article par richardc DéMARRONS AVEC LES TASKSDéMARRONS AVEC LES TASKS par richardc
Que vous le vouliez ou non, le développement multi-tâche est maintenant une obligation pour toute nouvelle application. Il est donc vital d'en comprendre les mécanismes et de s'y mettre le plus tôt possible.
En attendant le .NET Framework 4.5 avec le...
Cliquez pour lire la suite de l'article par richardc SLIDE & DéMO TECHDAYS 2012 - FAST & FURIOUS XAML APPSSLIDE & DéMO TECHDAYS 2012 - FAST & FURIOUS XAML APPS par Vko
Retrouvez les slides et les démo de ma session Fast & Furious XAML Apps. A ceux qui se posent la question : "est-ce que le code de la DataGrid est disponible?", je vous répondrais "pas encore". Je vais mettre en place un projet codeplex pour part...
Cliquez pour lire la suite de l'article par Vko XNA IS DEAD!XNA IS DEAD! par richardc
Depuis la semaine dernière (et grâce aux TechDays 2012), je me penche activement sur la nouvelle version de Windows, aka Windows 8. Vous me direz, il était temps puisque la première preview date de Septembre dernier.
OK. Remarquez, on n'en est qu'aux...
Cliquez pour lire la suite de l'article par richardc TECHDAYS PARIS 2012 : WINDOWS SERVER "8" QUOI DE 9 !TECHDAYS PARIS 2012 : WINDOWS SERVER "8" QUOI DE 9 ! par ROMELARD Fabrice
Speakers: Fabrice Meillon et Stanislas Quastana Cette session est basée entièrement sur celle donnée lors de la BUILD cet hiver. Il n'y a pas d'ajout d'information en rapport avec cet évènement passé. Windows 8 Server sera intégralem...
Cliquez pour lire la suite de l'article par ROMELARD Fabrice
Forum
J2EEJ2EE par barhoum1111
Cliquez pour lire la suite par barhoum1111
Logiciels
DocTranslate (V3.1.0.0)DOCTRANSLATE (V3.1.0.0)DocTranslate est un traducteur de document Microsoft Word, PowerPoint et Excel. Il permet d'autom... Cliquez pour télécharger DocTranslate Tribler (2012)TRIBLER (2012)Tribler est un client pair à pair (P2P/Peer-to-Peer) open source avec la capacité de regarder des... Cliquez pour télécharger Tribler OneSwarm (2012)ONESWARM (2012)Le peer-to-peer qui protège votre vie privée, c'est OneSwarm.
Ce logiciel de peer-to-peer crypté... Cliquez pour télécharger OneSwarm PONAMEDIA PREMIUM - HELLLOOO FLASH DEMO (V8.4)PONAMEDIA PREMIUM - HELLLOOO FLASH DEMO (V8.4)PONAMEDIA TV DEVIENS HELLLOOO FLASH
LA TV SUR VOTRE ORDINATEUR.
Toute une plateforme Multi... Cliquez pour télécharger PONAMEDIA PREMIUM - HELLLOOO FLASH DEMO Academy System (17.2.1.0)ACADEMY SYSTEM (17.2.1.0)Logiciel de gestion des établissements.
- élèves/étudiants (inscription, dossier, absence...)
-... Cliquez pour télécharger Academy System
|