IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

API standards et tierces Java Discussion :

SMSLib et lecture sur modem


Sujet :

API standards et tierces Java

  1. #1
    Membre régulier Avatar de yashiro
    Inscrit en
    Mars 2004
    Messages
    214
    Détails du profil
    Informations forums :
    Inscription : Mars 2004
    Messages : 214
    Points : 82
    Points
    82
    Par défaut SMSLib et lecture sur modem
    Bonjour à tous!!! Je suis actuellement en train de développer un module d'envoie de sms, qui pourra aussi servir à recevoir les sms.
    Actuellement j'utilise smslib et je réussi à envoyer correctement les sms mais j'arrive pas à lire les sms reçus.

    Je m'inspire pourtant du code donné en exemple

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
     
    // Liste des message
    LinkedList msgList = new LinkedList();
     
    // Initialisation du service
    CService srv = new CService("COM1", 57600, "Nokia", "");
     
    // Code PIN
    srv.setSimPin("0000");
     
    // Code PIN2
    srv.setSimPin2("0000");
     
    // Connexion
    srv.connect();
     
    // Lecture de messages
    srv.readMessages(msgList, CIncomingMessage.MessageClass.All);
     
    // Parcour et affichage
    for (int i = 0; i < msgList.size(); i++)
     {
        CIncomingMessage msg = (CIncomingMessage) msgList.get(i);
        System.out.println(msg);
     }
     
    // Déconnexion
    srv.disconnect();
    Le fait est que il n'ya pas d'exception mais au finish, aucun message n'est affiché, alors que lorsque j'entre dans le téléphone, je trouve plein de messages (lu et non lus).
    J'utilise la version 2 de smslib.

    Si kelkun sait comment faire... Merci de m'aider
    passionné de développement

  2. #2
    Candidat au Club
    Inscrit en
    Février 2009
    Messages
    7
    Détails du profil
    Informations forums :
    Inscription : Février 2009
    Messages : 7
    Points : 4
    Points
    4
    Par défaut
    bonjour,
    pouvez vous nous aider nous sommes en train de réaliser la meme application que vous mais on n'arrive pas à envoyer le message une erreur s'affiche:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
     
    SendMessage(): sample application.
      Using jSMSEngine API 1.2.4
     
    13 avr. 2009 11:59:06 org.jsmsengine.CSerialDriver open
    INFO: Connecting...
    salut: 0
    salut: 0
    Mobile Device Information: 
    	Manufacturer  : SAMSUNG
    	Model         : SAMSUNG SGH-D820
    	Serial No     : 358225 00 173476 0
    	IMSI          : 605030205124468
    	S/W Version   : 01/07/2005
    	Battery Level : 75%
    	Signal Level  : 54%
    java.lang.StringIndexOutOfBoundsException: String index out of range: 0
    tatou -11
    	at java.lang.StringBuffer.charAt(Unknown Source)
    	at org.jsmsengine.CSerialDriver.getResponse(CSerialDriver.java:219)
    	at org.jsmsengine.CService.sendMessage(CService.java:967)
    	at org.jsmsengine.CService.sendMessage(CService.java:857)
    	at ReadMessages.main(ReadMessages.java:91)
    13 avr. 2009 11:59:41 org.jsmsengine.CSerialDriver close
    INFO: Disconnecting...
    Message Failed!
    et le code qu'on utilise est:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    //
    //	jSMSEngine API.
    //	An open-source API package for sending and receiving SMS via a GSM device.
    //	Copyright (C) 2002,2004, Thanasis Delenikas, Athens/GREECE
    //		Web Site: <a href="http://www.jsmsengine.org" target="_blank">http://www.jsmsengine.org</a>
    //
    //	jSMSEngine is a package which can be used in order to add SMS processing
    //		capabilities in an application. jSMSEngine is written in Java. It allows you
    //		to communicate with a compatible mobile phone or GSM Modem, and
    //		send / receive SMS messages.
    //
    //	jSMSEngine is distributed under the LGPL license.
    //
    //	This library is free software; you can redistribute it and/or
    //		modify it under the terms of the GNU Lesser General Public
    //		License as published by the Free Software Foundation; either
    //		version 2.1 of the License, or (at your option) any later version.
    //	This library is distributed in the hope that it will be useful,
    //		but WITHOUT ANY WARRANTY; without even the implied warranty of
    //		MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    //		Lesser General Public License for more details.
    //	You should have received a copy of the GNU Lesser General Public
    //		License along with this library; if not, write to the Free Software
    //		Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    //
     
    //
    //	SendMessage.java - Sample application.
    //
    //		This application shows you the basic procedure needed for sending
    //		an SMS messages from your GSM device.
    //
     
    //	Include the necessary package.
    import org.jsmsengine.*;
     
    class ReadMessages
    {
    	public static void main(String[] args)
    	{
    		int status;
    		// Create jSMSEngine service.
    		CService srv = new CService("com4", 9600);
     
    		System.out.println();
    		System.out.println("SendMessage(): sample application.");
    		System.out.println("  Using " + srv._name + " " + srv._version);
    		System.out.println();
    		try
    		{
    			//	Initialize service.	
    			srv.initialize();
    			//	Set the cache directory.
    			srv.setCacheDir(".\\");
     
    			//	Set the phonebook.
    			//	srv.setPhoneBook("../misc/phonebook.xml");
    			//	Connect to GSM device.
    			status = srv.connect();
     
    			System.out.println("salut: "+CService.ERR_OK);
     
    			System.out.println("salut: "+status);
    			//	Did we connect ok?
    			if (status == CService.ERR_OK)
    			{
    				//	Set the operation mode to PDU - default is ASCII.
    				srv.setOperationMode(CService.MODE_PDU);
     
    				// Set the SMSC number (set to default).
    			srv.setSmscNumber("");
     
    				//	Print out GSM device info...
    				System.out.println("Mobile Device Information: ");
    				System.out.println("	Manufacturer  : " + srv.getDeviceInfo().getManufacturer());
    				System.out.println("	Model         : " + srv.getDeviceInfo().getModel());
    				System.out.println("	Serial No     : " + srv.getDeviceInfo().getSerialNo());
    				System.out.println("	IMSI          : " + srv.getDeviceInfo().getImsi());
    				System.out.println("	S/W Version   : " + srv.getDeviceInfo().getSwVersion());
    				System.out.println("	Battery Level : " + srv.getDeviceInfo().getBatteryLevel() + "%");
    				System.out.println("	Signal Level  : " + srv.getDeviceInfo().getSignalLevel() + "%");
     
    				//	Create a COutgoingMessage object and dispatch it.
    				//	*** Please update the phone number with one of your choice ***
    				COutgoingMessage msg = new COutgoingMessage("+21694149864", "");
     
    				//	Character set is 7bit by default - lets make it UNICODE :)
    				//	We can do this, because we are in PDU mode (look at line 63). When in ASCII mode,
    				//		this does not make ANY difference...
    				msg.setMessageEncoding(CMessage.MESSAGE_ENCODING_UNICODE);
    				System.out.println("tatou "+srv.sendMessage(msg));
    				if (srv.sendMessage(msg) == CService.ERR_OK) System.out.println("Message Sent!");
    				else System.out.println("Message Failed!");
     
    				// Disconnect from GSM device.
    				srv.disconnect();
    			}
    			else System.out.println("Connection to mobile failed, error: " + status);
    		}
    		catch (Exception e)
    		{
    			e.printStackTrace();
    		}
    		System.exit(0);
    	}
    }

  3. #3
    Futur Membre du Club
    Inscrit en
    Avril 2009
    Messages
    6
    Détails du profil
    Informations forums :
    Inscription : Avril 2009
    Messages : 6
    Points : 7
    Points
    7
    Par défaut PFE J2ME
    bonjour je suis entrain moi aussi de penser a une application de ce genre pour mon PFE mais j'arrive vraiment pas a avancer ( je suis ingenieur telecom).
    est ce que vous pouvez m'aider car je dois remplir un questionnaire puis le transformer et l'envoyer par sms ...
    merci de votre comprehension et merci .

  4. #4
    Nouveau Candidat au Club
    Inscrit en
    Janvier 2010
    Messages
    2
    Détails du profil
    Informations forums :
    Inscription : Janvier 2010
    Messages : 2
    Points : 0
    Points
    0
    Par défaut smslib
    salut,
    moi j'ai un problème avec smslib.
    Lorsque je lance mon application il y a une exception qui est générée.
    J'avais pensé que c'était mon nokia 6230 le problème.
    J'ai donc choisi d'utiliser un nokia 6230i à la place.
    Mais le résultat est toujours négatif.
    Aidez moi svp.
    Merci

  5. #5
    Futur Membre du Club
    Inscrit en
    Décembre 2009
    Messages
    10
    Détails du profil
    Informations forums :
    Inscription : Décembre 2009
    Messages : 10
    Points : 5
    Points
    5
    Par défaut Recevoir des sms via un modem
    Bonjour:
    je suis entrain de réaliser une application en java qui permet d'envoyer et de recevoir des sms via un modem.

    jusqu'à maintenant j'ai réussi d'envoyer les message;

    mais comment faire pour recevoir les message entrant dans le modem connecté.

    merci de m'aider c'est urgent. email : amostapha@live.fr

  6. #6
    Nouveau membre du Club
    Inscrit en
    Septembre 2009
    Messages
    26
    Détails du profil
    Informations forums :
    Inscription : Septembre 2009
    Messages : 26
    Points : 26
    Points
    26
    Par défaut
    Bonjour,
    Après avoir téléchargé la librairie smslib, quelques exemple y sont proposés pour l'envoi et la réception de sms.

    Toutefois, voici quelques exemples (à customiser)
    Pour l'envoi:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
     
     
    import common.Fichier;
    import org.smslib.GatewayException;
    import org.smslib.OutboundMessage;
    import org.smslib.Service;
    import org.smslib.TimeoutException;
    import org.smslib.modem.SerialModemGateway;
     
    public class SendMessage {
     
        private SerialModemGateway gateway = null;
        private OutboundMessage msg = null;
        private String tel_dest = null;
        private String content = null;
        private Service srv;
     
        public SendMessage(String portName, String cpin, String tel_dest, String content) {
            this.gateway = new SerialModemGateway(portName, portName, 115200, "not set", "not set");
            this.gateway.setSimPin(cpin);
            this.tel_dest = tel_dest;
            this.content = content;
        }
     
        public boolean doIt() throws Exception {
            boolean sent = false;
            this.srv = new Service();
            gateway.setInbound(true);
            gateway.setOutbound(true);
            srv.addGateway(gateway);
            srv.startService();
            System.out.println("Envoi du Message En cours....");
            msg = new OutboundMessage(tel_dest, content);
            try {
                srv.sendMessage(msg, gateway.getGatewayId());
                System.out.println("Message Envoyé !");
                sent = true;
            }
            catch (GatewayException e) {
                e.printStackTrace();
                Fichier.getInstance().ecrireFichier(Fichier.fichierError, e.getMessage());
                System.out.println("Message non envoye pour GatewayException");
                System.out.println(e.getMessage());
            } catch (InterruptedException e) {
                e.printStackTrace();
                Fichier.getInstance().ecrireFichier(Fichier.fichierError, e.getMessage());
                System.out.println("Message non envoye pour InterruptedException: APPEL interrompu");
                System.out.println(e.getMessage());
            } catch (TimeoutException e) {
                e.printStackTrace();
                Fichier.getInstance().ecrireFichier(Fichier.fichierError, e.getMessage());
                System.out.println("Message non envoye pour TimeoutException: gateway n'a pas repondu a temps");
                System.out.println(e.getMessage());
            }
            catch (Exception e){
                e.printStackTrace();
                Fichier.getInstance().ecrireFichier(Fichier.fichierError, e.getMessage());
                System.out.println(e.getMessage());
            }
            srv.stopService();
            return sent;
        }
    }
    Pour la réception:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
     
    /*
     * To change this template, choose Tools | Templates
     * and open the template in the editor.
     */
     
    package messages;
     
    import common.Fichier;
    import java.util.*;
    import java.util.List;
    import org.smslib.ICallNotification;
    import org.smslib.IGatewayStatusNotification;
    import org.smslib.IInboundMessageNotification;
    import org.smslib.IOrphanedMessageNotification;
    import org.smslib.InboundMessage;
    import org.smslib.Service;
    import org.smslib.AGateway.GatewayStatuses;
    import org.smslib.AGateway.Protocols;
    import org.smslib.InboundMessage.MessageClasses;
    import org.smslib.Message.MessageTypes;
    import org.smslib.modem.SerialModemGateway;
     
    public class ReadMessages
    {
        public SerialModemGateway gateway=null;
        public List<InboundMessage> AllMessageList=null;
        private List<InboundMessage> msgList=null;
        Service srv;
     
        public List<InboundMessage> getMsgList() {
            return msgList; 
        }
     
        public void setMsgList(List<InboundMessage> msgList) {
            this.msgList = msgList;
        }
     
        public List<InboundMessage> getAllMessageList() {
            return AllMessageList;
        }
     
        public ReadMessages(){
            this.gateway=new SerialModemGateway("COM8","COM8",115200,"","");
            this.gateway.setSimPin("0000");
        }
     
        public ReadMessages(String portName,String cpin){
            this.gateway=new SerialModemGateway(portName,portName,115200,"not set","not set");
            this.gateway.setSimPin(cpin);
        }
     
        public Vector doIt(String messageClass) throws Exception
        {
            Vector expediteurList = new Vector();
            // Define a list which will hold the read messages.
            InboundNotification inboundNotification = new InboundNotification();
            // Create the notification callback method for inbound voice calls.
            CallNotification callNotification = new CallNotification();
            //Create the notification callback method for gateway statuses.
            GatewayStatusNotification statusNotification = new GatewayStatusNotification();
            OrphanedMessageNotification orphanedMessageNotification = new OrphanedMessageNotification();
            try
            {
                System.out.println("Read messages from a serial gsm modem.");
                this.srv = new Service();
                // Create the Gateway representing the serial GSM modem.
                //SerialModemGateway gateway = new SerialModemGateway("modem.com1", "COM1", 57600, "Nokia", "");
                // Set the modem protocol to PDU (alternative is TEXT). PDU is the default, anyway...
                gateway.setProtocol(Protocols.PDU);
                // Do we want the Gateway to be used for Inbound messages?
                gateway.setInbound(true);
                // Do we want the Gateway to be used for Outbound messages?
                gateway.setOutbound(true);
                // Let SMSLib know which is the SIM PIN.
                //gateway.setSimPin("0000");
                // Set up the notification methods.
                this.srv.setInboundMessageNotification(inboundNotification);
                this.srv.setCallNotification(callNotification);
                this.srv.setGatewayStatusNotification(statusNotification);
                this.srv.setOrphanedMessageNotification(orphanedMessageNotification);
                // Add the Gateway to the Service object.
                this.srv.addGateway(gateway);
                // Similarly, you may define as many Gateway objects, representing
                // various GSM modems, add them in the Service object and control all of them.
                // Start! (i.e. connect to all defined Gateways)
                this.srv.startService();
                // Printout some general information about the modem.
                System.out.println();
                System.out.println("Modem Information:");
                System.out.println("  Manufacturer: " + gateway.getManufacturer());
                System.out.println("  Model: " + gateway.getModel());
                System.out.println("  Serial No: " + gateway.getSerialNo());
                System.out.println("  Code pin: " + gateway.getSimPin());
                System.out.println("  Signal Level: " + gateway.getSignalLevel() + "%");
                System.out.println("  Battery Level: " + gateway.getBatteryLevel() + "%");
                System.out.println("  GatewayId: " + gateway.getGatewayId() + "%");
                System.out.println();
                if (messageClass.contentEquals("ALL")){
                    AllMessageList=new ArrayList<InboundMessage>();
                    this.srv.readMessages( AllMessageList, MessageClasses.ALL);
                    for (InboundMessage msg : AllMessageList){
                        //hash.put(msg.getMemIndex(),msg);
                        System.out.println(msg);
                        /*expediteur = msg.getOriginator();
                        if ((expediteur.length() == 11) ){
                            listExpediteur.add(expediteur.substring(3));
                        }*/
                        //srv.deleteMessage(msg);
                        //System.out.println("Message supprimé!");
                    }
               }
           }
            catch (Exception e)
            {
                e.printStackTrace();
                System.out.println(e.getMessage());
                Fichier.getInstance().ecrireFichier(Fichier.fichierError,e.getMessage());
    	}
            finally
            {
                this.srv.stopService();
            }
            return expediteurList;
        }
     
        public class InboundNotification implements IInboundMessageNotification
        {
            public void process(String gatewayId, MessageTypes msgType, InboundMessage msg)
            {
                if (msgType == MessageTypes.INBOUND)
                    System.out.println(">>> New Inbound message detected from Gateway: " + gatewayId);
                else if (msgType == MessageTypes.STATUSREPORT)
                    System.out.println(">>> New Inbound Status Report message detected from Gateway: " + gatewayId);
                System.out.println(msg);
            }
        }
     
        public class CallNotification implements ICallNotification
        {
            public void process(String gatewayId, String callerId)
            {
                System.out.println(">>> New call detected from Gateway: " + gatewayId + " : " + callerId);
            }
        }
     
        public class GatewayStatusNotification implements IGatewayStatusNotification
        {
            public void process(String gatewayId, GatewayStatuses oldStatus, GatewayStatuses newStatus)
            {
                System.out.println(">>> Gateway Status change for " + gatewayId + ", OLD: " + oldStatus + " -> NEW: " + newStatus);
            }
        }
     
        public class OrphanedMessageNotification implements IOrphanedMessageNotification
        {
            public boolean process(String gatewayId, InboundMessage msg)
            {
                System.out.println(">>> Orphaned message part detected from " + gatewayId);
                System.out.println(msg);
                // Since we are just testing, return FALSE and keep the orphaned message part.
                return false;
            }
        }
    }

  7. #7
    Futur Membre du Club
    Inscrit en
    Février 2005
    Messages
    4
    Détails du profil
    Informations forums :
    Inscription : Février 2005
    Messages : 4
    Points : 5
    Points
    5
    Par défaut Recevoir des sms via un modem avec SMSlib
    Bonjour,

    J'ai aussi des difficultés pour la réception des message avec SMSlib.
    Aidez moi svp.
    Merci.

  8. #8
    Membre à l'essai
    Femme Profil pro
    Inscrit en
    Juin 2012
    Messages
    12
    Détails du profil
    Informations personnelles :
    Sexe : Femme

    Informations forums :
    Inscription : Juin 2012
    Messages : 12
    Points : 13
    Points
    13
    Par défaut SMSLib sous Android Application
    Citation Envoyé par ilboudfr Voir le message
    Bonjour,

    J'ai aussi des difficultés pour la réception des message avec SMSlib.
    Aidez moi svp.
    Merci.
    Bonjour,

    STP,Comment je peux utiliser le lib SMSLib pour envoyer et recevoir des SMS puis les enregistrer en base de données?

    Merci

  9. #9
    Nouveau membre du Club
    Inscrit en
    Septembre 2009
    Messages
    26
    Détails du profil
    Informations forums :
    Inscription : Septembre 2009
    Messages : 26
    Points : 26
    Points
    26
    Par défaut
    Citation Envoyé par caddy Voir le message
    Bonjour,
    Après avoir téléchargé la librairie smslib, quelques exemple y sont proposés pour l'envoi et la réception de sms.

    Toutefois, voici quelques exemples (à customiser)
    Pour l'envoi:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
     
     
    import common.Fichier;
    import org.smslib.GatewayException;
    import org.smslib.OutboundMessage;
    import org.smslib.Service;
    import org.smslib.TimeoutException;
    import org.smslib.modem.SerialModemGateway;
     
    public class SendMessage {
     
        private SerialModemGateway gateway = null;
        private OutboundMessage msg = null;
        private String tel_dest = null;
        private String content = null;
        private Service srv;
     
        public SendMessage(String portName, String cpin, String tel_dest, String content) {
            this.gateway = new SerialModemGateway(portName, portName, 115200, "not set", "not set");
            this.gateway.setSimPin(cpin);
            this.tel_dest = tel_dest;
            this.content = content;
        }
     
        public boolean doIt() throws Exception {
            boolean sent = false;
            this.srv = new Service();
            gateway.setInbound(true);
            gateway.setOutbound(true);
            srv.addGateway(gateway);
            srv.startService();
            System.out.println("Envoi du Message En cours....");
            msg = new OutboundMessage(tel_dest, content);
            try {
                srv.sendMessage(msg, gateway.getGatewayId());
                System.out.println("Message Envoyé !");
                sent = true;
            }
            catch (GatewayException e) {
                e.printStackTrace();
                Fichier.getInstance().ecrireFichier(Fichier.fichierError, e.getMessage());
                System.out.println("Message non envoye pour GatewayException");
                System.out.println(e.getMessage());
            } catch (InterruptedException e) {
                e.printStackTrace();
                Fichier.getInstance().ecrireFichier(Fichier.fichierError, e.getMessage());
                System.out.println("Message non envoye pour InterruptedException: APPEL interrompu");
                System.out.println(e.getMessage());
            } catch (TimeoutException e) {
                e.printStackTrace();
                Fichier.getInstance().ecrireFichier(Fichier.fichierError, e.getMessage());
                System.out.println("Message non envoye pour TimeoutException: gateway n'a pas repondu a temps");
                System.out.println(e.getMessage());
            }
            catch (Exception e){
                e.printStackTrace();
                Fichier.getInstance().ecrireFichier(Fichier.fichierError, e.getMessage());
                System.out.println(e.getMessage());
            }
            srv.stopService();
            return sent;
        }
    }
    Pour la réception:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
     
    /*
     * To change this template, choose Tools | Templates
     * and open the template in the editor.
     */
     
    package messages;
     
    import common.Fichier;
    import java.util.*;
    import java.util.List;
    import org.smslib.ICallNotification;
    import org.smslib.IGatewayStatusNotification;
    import org.smslib.IInboundMessageNotification;
    import org.smslib.IOrphanedMessageNotification;
    import org.smslib.InboundMessage;
    import org.smslib.Service;
    import org.smslib.AGateway.GatewayStatuses;
    import org.smslib.AGateway.Protocols;
    import org.smslib.InboundMessage.MessageClasses;
    import org.smslib.Message.MessageTypes;
    import org.smslib.modem.SerialModemGateway;
     
    public class ReadMessages
    {
        public SerialModemGateway gateway=null;
        public List<InboundMessage> AllMessageList=null;
        private List<InboundMessage> msgList=null;
        Service srv;
     
        public List<InboundMessage> getMsgList() {
            return msgList; 
        }
     
        public void setMsgList(List<InboundMessage> msgList) {
            this.msgList = msgList;
        }
     
        public List<InboundMessage> getAllMessageList() {
            return AllMessageList;
        }
     
        public ReadMessages(){
            this.gateway=new SerialModemGateway("COM8","COM8",115200,"","");
            this.gateway.setSimPin("0000");
        }
     
        public ReadMessages(String portName,String cpin){
            this.gateway=new SerialModemGateway(portName,portName,115200,"not set","not set");
            this.gateway.setSimPin(cpin);
        }
     
        public Vector doIt(String messageClass) throws Exception
        {
            Vector expediteurList = new Vector();
            // Define a list which will hold the read messages.
            InboundNotification inboundNotification = new InboundNotification();
            // Create the notification callback method for inbound voice calls.
            CallNotification callNotification = new CallNotification();
            //Create the notification callback method for gateway statuses.
            GatewayStatusNotification statusNotification = new GatewayStatusNotification();
            OrphanedMessageNotification orphanedMessageNotification = new OrphanedMessageNotification();
            try
            {
                System.out.println("Read messages from a serial gsm modem.");
                this.srv = new Service();
                // Create the Gateway representing the serial GSM modem.
                //SerialModemGateway gateway = new SerialModemGateway("modem.com1", "COM1", 57600, "Nokia", "");
                // Set the modem protocol to PDU (alternative is TEXT). PDU is the default, anyway...
                gateway.setProtocol(Protocols.PDU);
                // Do we want the Gateway to be used for Inbound messages?
                gateway.setInbound(true);
                // Do we want the Gateway to be used for Outbound messages?
                gateway.setOutbound(true);
                // Let SMSLib know which is the SIM PIN.
                //gateway.setSimPin("0000");
                // Set up the notification methods.
                this.srv.setInboundMessageNotification(inboundNotification);
                this.srv.setCallNotification(callNotification);
                this.srv.setGatewayStatusNotification(statusNotification);
                this.srv.setOrphanedMessageNotification(orphanedMessageNotification);
                // Add the Gateway to the Service object.
                this.srv.addGateway(gateway);
                // Similarly, you may define as many Gateway objects, representing
                // various GSM modems, add them in the Service object and control all of them.
                // Start! (i.e. connect to all defined Gateways)
                this.srv.startService();
                // Printout some general information about the modem.
                System.out.println();
                System.out.println("Modem Information:");
                System.out.println("  Manufacturer: " + gateway.getManufacturer());
                System.out.println("  Model: " + gateway.getModel());
                System.out.println("  Serial No: " + gateway.getSerialNo());
                System.out.println("  Code pin: " + gateway.getSimPin());
                System.out.println("  Signal Level: " + gateway.getSignalLevel() + "%");
                System.out.println("  Battery Level: " + gateway.getBatteryLevel() + "%");
                System.out.println("  GatewayId: " + gateway.getGatewayId() + "%");
                System.out.println();
                if (messageClass.contentEquals("ALL")){
                    AllMessageList=new ArrayList<InboundMessage>();
                    this.srv.readMessages( AllMessageList, MessageClasses.ALL);
                    for (InboundMessage msg : AllMessageList){
                        //hash.put(msg.getMemIndex(),msg);
                        System.out.println(msg);
                        /*expediteur = msg.getOriginator();
                        if ((expediteur.length() == 11) ){
                            listExpediteur.add(expediteur.substring(3));
                        }*/
                        //srv.deleteMessage(msg);
                        //System.out.println("Message supprimé!");
                    }
               }
           }
            catch (Exception e)
            {
                e.printStackTrace();
                System.out.println(e.getMessage());
                Fichier.getInstance().ecrireFichier(Fichier.fichierError,e.getMessage());
    	}
            finally
            {
                this.srv.stopService();
            }
            return expediteurList;
        }
     
        public class InboundNotification implements IInboundMessageNotification
        {
            public void process(String gatewayId, MessageTypes msgType, InboundMessage msg)
            {
                if (msgType == MessageTypes.INBOUND)
                    System.out.println(">>> New Inbound message detected from Gateway: " + gatewayId);
                else if (msgType == MessageTypes.STATUSREPORT)
                    System.out.println(">>> New Inbound Status Report message detected from Gateway: " + gatewayId);
                System.out.println(msg);
            }
        }
     
        public class CallNotification implements ICallNotification
        {
            public void process(String gatewayId, String callerId)
            {
                System.out.println(">>> New call detected from Gateway: " + gatewayId + " : " + callerId);
            }
        }
     
        public class GatewayStatusNotification implements IGatewayStatusNotification
        {
            public void process(String gatewayId, GatewayStatuses oldStatus, GatewayStatuses newStatus)
            {
                System.out.println(">>> Gateway Status change for " + gatewayId + ", OLD: " + oldStatus + " -> NEW: " + newStatus);
            }
        }
     
        public class OrphanedMessageNotification implements IOrphanedMessageNotification
        {
            public boolean process(String gatewayId, InboundMessage msg)
            {
                System.out.println(">>> Orphaned message part detected from " + gatewayId);
                System.out.println(msg);
                // Since we are just testing, return FALSE and keep the orphaned message part.
                return false;
            }
        }
    }
    Je viens de recevoir un MP qui m'a fait réaliser qu'il y a des lignes inutiles dans ce code.
    Je vous prierais d'ignorer les lignes
    et toutes les
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    Fichier.getInstance().ecrireFichier(...,...);
    La vitesse du modem utilisé est 115200. A modifier si ce n'est pas celle de votre modem (il est préférable d'en tenir compte comme d'une variable dans le code).
    Le port utilisé est "COM8" - Mêmes instructions que pour la vitesse du modem.

  10. #10
    Nouveau membre du Club
    Profil pro
    Développeur D'Applications
    Inscrit en
    Décembre 2004
    Messages
    17
    Détails du profil
    Informations personnelles :
    Localisation : Togo

    Informations professionnelles :
    Activité : Développeur D'Applications

    Informations forums :
    Inscription : Décembre 2004
    Messages : 17
    Points : 33
    Points
    33
    Par défaut smslib
    Salut à tous,

    J'ai essayé récemment d'utiliser smslib mais j'ai eu aussi des soucis. En gros je me suis tourné vers C# avec la libraire GSMComm, qui est vraiment cool et assez complète.
    Par expérience, pour ceux qui utilisent des Nokia comme modem, j'ai constaté que la lecture des SMS de marche pas à cause de certains aspects de sécurité.
    Je ne sais pas s'il y a réellement un moyen de contourner cela.

    Cdlt.

Discussions similaires

  1. FTP & lecture sur le canal de controle
    Par Tex-Twil dans le forum Modules
    Réponses: 9
    Dernier message: 15/01/2006, 12h15
  2. prob connexion internet : priorité reseau sur modem
    Par sniperwolf dans le forum Administration
    Réponses: 1
    Dernier message: 21/10/2005, 10h11
  3. Erreur de lecture sur BD Access avec delphi
    Par e120650 dans le forum Bases de données
    Réponses: 1
    Dernier message: 10/06/2005, 10h17
  4. [C#] lecture sur port série
    Par Iokanaan dans le forum Windows Forms
    Réponses: 3
    Dernier message: 03/05/2005, 13h50
  5. [Kylix] Lecture sur le port série en C++
    Par MD Software dans le forum EDI
    Réponses: 1
    Dernier message: 08/05/2004, 12h52

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo