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

Entrée/Sortie Java Discussion :

Librairie Bluetooth introuvable


Sujet :

Entrée/Sortie Java

  1. #1
    Invité
    Invité(e)
    Par défaut Librairie Bluetooth introuvable
    Bonjour à tous,

    Je voudrais réaliser une application Natel -> PC en Java et Bluetooth (oui je sais c'est un projet de fou...)

    J'ai trouvé plusieurs codes sur le net. Celui-la a retenu mon attention :

    http://today.java.net/pub/a/today/20...bluetooth.html

    Le seul souci c'est que je ne trouve absolument pas la librairie :

    J'ai pu trouver les autres en installant le "j2me_wireless_toolkit-2_2-windows.exe"

    Le site officiel de la librairie est mort. Donc comment je la trouve ? Ou peut etre auriez-vous une idée pour faire autrement mon projet ?

    Merci.

    P.S : Je ne sais pas si c'est le bon forum.

  2. #2
    Membre éclairé
    Inscrit en
    Décembre 2005
    Messages
    50
    Détails du profil
    Informations forums :
    Inscription : Décembre 2005
    Messages : 50
    Par défaut
    Pour utliser le bluetooth avec javaSE je te conseille cette librairie libre :
    bluecove

    qui marche tres bien mais seulement sur windows et mac, linux n'est pas encore compatible avec la partie native.

    Pour windows tu as aussi cet autre projet : bluesock mais il a l'air arrete.

    Pour utiliser ces libraires utilisent les exewmples qui sont donnees avec ca marche tres bien

  3. #3
    Invité
    Invité(e)
    Par défaut
    Salut,

    Tout d'abord je te remerci pour le lien de la librairie BlueCove. J'ai ajouté le .jar a eclipse.

    Mais quand je veux lancer SimpleDiscovery.java j'ai une erreur : Cannot get local device: javax.bluetooth.BluetoothStateException

    Saurais-tu d'ou viens cette erreur ? Je ne sais pas si ca vient de cela mais j'ai aussi une erreur ici : import net.sf.jour.signature.SignatureTestCase; dans les les packages javax.

  4. #4
    Membre éclairé
    Inscrit en
    Décembre 2005
    Messages
    50
    Détails du profil
    Informations forums :
    Inscription : Décembre 2005
    Messages : 50
    Par défaut
    As tu regarder sur le site de bluecove si ton OS (windows ou mac os je le rapelle) implémentait bien la bonne pile bluetooth.

    Si oui que ton peripherique bluetooth est bine branche et actif quand tu lance le programme.

    J'interpreterais ton erreur rapidement comme cela mais je suis loin d'etre un specialiste de cette librairie je sais juste que dans le cas de mon projet ca a marcher assez vite sans trop de probleme.

  5. #5
    Invité
    Invité(e)
    Par défaut
    ok je regarde tout ça. Mais pourrais tu me dire plus au niveau de ton projet ?

  6. #6
    Membre éclairé
    Inscrit en
    Décembre 2005
    Messages
    50
    Détails du profil
    Informations forums :
    Inscription : Décembre 2005
    Messages : 50
    Par défaut
    Mon projet est le développement d'une application de délégation de paiement en utilisant les téléphones portables.

    Pour cela je dois utiliser plusieurs connections bluetooth :

    entre téléphone/téléphone
    et entre téléphone/PC

    La liaison téléphone/téléphone se fait très bien car la jsr 82 est implémente sur la plus part des téléphone récents.

    Par contre le liaison téléphone/PC est plus difficile car il faut utiliser la libraire bluecove mais une fois que la librairie est installée c'est exactement la même utilisation qu'avec java ME.

    Si tu veux des bouts de codes avec les actions a réaliser pour faire les connections je peux en poster certain mais avant il faut que je les nettoie de 2/3 choses.

  7. #7
    Membre éclairé
    Inscrit en
    Décembre 2005
    Messages
    50
    Détails du profil
    Informations forums :
    Inscription : Décembre 2005
    Messages : 50
    Par défaut
    c'est aller un peu plus vite que prevu alors je met ici un bout de code pour faire un serveur bluettoh sur un pc.

    Il suffit de rajouter le jar de bluecove dans eclipse et ca marche tres bien si tu respecte les critere de bluetoohstack de bluecove.

    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
     
    package monPackage;
     
    import java.io.DataInputStream;
    import java.io.DataOutputStream;
    import java.io.InputStream;
    import java.io.OutputStream;
     
     
    import javax.bluetooth.UUID;
    import javax.microedition.io.StreamConnection;
    import javax.microedition.io.StreamConnectionNotifier;
     
     
     
    public class MonAppli{
     
    	private StreamConnectionNotifier connector;
    	private Thread threadClient;
    	protected String uuidPC = new UUID("1101", true).toString();
     
     
    	public MonAppli() {
    		try {
    			String url = "btspp://localhost:" + uuidPC + ";name=DeviceServerCOMM";
    			connector = (StreamConnectionNotifier)javax.microedition.io.Connector.open(url);
     
    			System.out.println("Waiting for connection...");
    			while (true) { 
    				handleConnection(connector.acceptAndOpen());
    				System.out.println("Waiting for connection...");
    			}
    		}
    		catch (Exception e)
    		{
    			e.printStackTrace();
    			System.exit(1);
    		}
     
    	}
     
    	private void handleConnection(final StreamConnection client){
    		threadClient = new Thread(new Runnable()
    		{
    			public void run()
    			{
    				OutputStream out = null;
    				DataOutputStream writer = null;
    				InputStream in = null;
    				DataInputStream reader = null;
     
    				try {
    					// TODO Echange avec le telephone
    				} 
    				catch (Exception e)
    				{
    					System.out.println("erreur");
    					System.out.println(e.toString());
    				}
    				finally
    				{
    					// TODO finaliser la connection
    					try {
    						client.close();
    					} catch (Exception g) {}
    				}
    			}
    		});
     
    		threadClient.start();
    	}
     
    	public static void main(String args[]) {
    		new MonAppli();
    	}
    }
    Et voila la partie client qui tourne sur un téléphone mobile. Si tu ne dois pas utiliser java me pour ton coté client il faut changer 2/3 truc notamment au niveau des extends et méthodes des midlets mais c'est pas grand chose et l'important y est c'est a dire les méthodes de recherches des devices puis de connections.

    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
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
     
     
    import java.io.*;
    import java.util.*;
     
    import javax.bluetooth.*;
    import javax.microedition.io.*;
    import javax.microedition.lcdui.*;
    import javax.microedition.midlet.*;
     
     
    public class MonClient extends MIDlet implements DiscoveryListener, CommandListener{
     
    	protected Command commandExit;
    	protected Command commandConnect;
    	protected Command commandBrowse;
    	protected Form infoArea = new Form("Mon client");
     
    	// For the connection with the other phone
    	protected UUID uuidPhone = new UUID(0x1101);
    	protected int inquiryMode = DiscoveryAgent.GIAC;
    	protected int connectionOptions = ServiceRecord.NOAUTHENTICATE_NOENCRYPT;
    	protected Vector deviceList = new Vector();
     
     
    	protected void destroyApp(boolean arg0) throws MIDletStateChangeException {
    	}
     
    	protected void pauseApp() {
    	}
     
    	protected void startApp() throws MIDletStateChangeException {
     
    		Display.getDisplay(this).setCurrent(infoArea);
    		commandExit = new Command("Exit", Command.SCREEN,1);
    		commandConnect = new Command("Send", Command.SCREEN,1);
    		commandBrowse = new Command("Open",Command.SCREEN,1);
     
    		infoArea.addCommand(commandBrowse);
    		infoArea.addCommand(commandConnect);
    		infoArea.addCommand(commandExit);
     
    		infoArea.setCommandListener(this);
     
    	}
     
    	private void startDeviceInquiry() {
    		try {
    			deviceList.removeAllElements();
    			log("Searching for devices..");
    			DiscoveryAgent agent = getAgent();
    			agent.startInquiry(inquiryMode, this);
    		} catch (Exception e) {
    			log("Error : "+e);
    		}
    	}
     
    	public void deviceDiscovered(RemoteDevice btDevice, DeviceClass cod) {
    		deviceList.addElement(btDevice);
    	}
     
    	public void inquiryCompleted(int discType) {
    		if(deviceList.size() !=0)
    			makeDeviceSelectionGUI();
    		else
    			log("No device founded");
    	}
     
    	/*-
    	 *   -------  Service search section -------
    	 */
     
    	private void startServiceSearch(RemoteDevice device) {
    		try {
    			UUID uuids[] = new UUID[] { uuidPhone };
    			getAgent().searchServices(null, uuids, device, this);
    		} catch (Exception e) {
    			log(e);
    		}
    	}
     
    	/**
             * This method is called when a service(s) are discovered.This method starts
             * a thread that handles the data exchange with the server.
             */
    	public void servicesDiscovered(int transId, ServiceRecord[] records) {
    		for (int i = 0; i < records.length; i++) {
    			ServiceRecord rec = records[i];
    			String url = rec.getConnectionURL(connectionOptions, false);
    			handleConnection(url);
    		}
    	}
     
    	public void serviceSearchCompleted(int transID, int respCode) {
    		String msg = null;
    		switch (respCode) {
    		case SERVICE_SEARCH_COMPLETED:
    			msg = "the service search completed normally";
    			break;
    		case SERVICE_SEARCH_TERMINATED:
    			msg = "the service search request was cancelled by a call to DiscoveryAgent.cancelServiceSearch()";
    			break;
    		case SERVICE_SEARCH_ERROR:
    			msg = "an error occurred while processing the request";
    			break;
    		case SERVICE_SEARCH_NO_RECORDS:
    			msg = "no records were found during the service search";
    			break;
    		case SERVICE_SEARCH_DEVICE_NOT_REACHABLE:
    			msg = "the device specified in the search request could not be reached or the local device could not establish a connection to the remote device";
    			break;
    		}
    		log("Service search completed - " + msg);
    	}
     
    	/*-
    	 *   -------  The actual connection handling. -------
    	 */
     
    	private void handleConnection(final String url) {
    		Thread writer = new Thread() {
    			public void run() {
    				StreamConnection stream = null;
    				try {
    					stream = (StreamConnection) Connector.open(url);
     
    					log("Bluetooth stream open.");
    					InputStream in = stream.openInputStream();
    					DataInputStream reader = new DataInputStream(in);
    					OutputStream out = stream.openOutputStream();
    					DataOutputStream writer = new DataOutputStream(out);
    					log("Start the exchange.");
    					while (true) {
    						// TODO Ecrire ici les echanges avec le serveur bluetooth
    					}
    				} catch (IOException e) {
    					log(e);
    				}catch(Exception e){
    					log("Error");
    					log(e);
    				}
    				finally {
    					log("Bluetooth stream closed.");
    					if (stream != null) {
    						try {
    							stream.close();
    						} catch (IOException e) {
    							log(e);
    						}
    					}
    				}
    			}
    		};
    		writer.start();
    	}
     
    	/*-
    	 *   -------  Graphic User Interface section -------
    	 */
     
    	private void makeInformationAreaGUI() {
    		infoArea.deleteAll();
    		Display.getDisplay(this).setCurrent(infoArea);
    	}
     
    	private void makeDeviceSelectionGUI() {
    		final List devices = new List("Select a device", List.IMPLICIT);
    		for (int i = 0; i < deviceList.size(); i++)
    			devices.append(
    					getDeviceStr((RemoteDevice) deviceList.elementAt(i)), null);
    		devices.setCommandListener(new CommandListener() {
    			public void commandAction(Command arg0, Displayable arg1) {
    				makeInformationAreaGUI();
    				startServiceSearch((RemoteDevice) deviceList.elementAt(devices
    						.getSelectedIndex()));
    			}
    		});
    		Display.getDisplay(this).setCurrent(devices);
    	}
     
     
    	synchronized public void log(String msg) {
    		infoArea.append(msg);
    		infoArea.append("\n\n");
    	}
     
    	public void log(Throwable e) {
    		log(e.getMessage());
    		log(e.toString());
    	}
     
    	public void commandAction(Command c, Displayable s)
    	{
    		if (c == commandExit){
    			try{
    				destroyApp(false);
    				notifyDestroyed();
    			}catch(MIDletStateChangeException e){
    				log(e);
    			}
    		}
    		if(c == commandConnect){
    			try {
    				startDeviceInquiry();
    			} catch (Throwable t) {
    				log(t);
    			}
    		}
     
    		if(c == commandBrowse){
     
     
    		}
     
    	}
     
    	/*
    	 *  Utils section
    	 */
    	public String hashToString(byte[] hash) {  
    		StringBuffer sb = new StringBuffer(); 
    		for (int i = 0; i < hash.length; i++) {  
    			int v = hash[i] & 0xFF; 
    			if(v < 16) {
    				sb.append("0"); 
    			}
    			sb.append(Integer.toString(v, 16)); 
    		}  
    		return sb.toString(); 
    	}
     
    	private DiscoveryAgent getAgent() {
    		try {
    			return LocalDevice.getLocalDevice().getDiscoveryAgent();
    		} catch (BluetoothStateException e) {
    			throw new Error(e.getMessage());
    		}
    	}
     
    	private String getDeviceStr(RemoteDevice btDevice) {
    		return getFriendlyName(btDevice) + " - 0x"
    		+ btDevice.getBluetoothAddress();
    	}
     
    	private String getFriendlyName(RemoteDevice btDevice) {
    		try {
    			return btDevice.getFriendlyName(false);
    		} catch (IOException e) {
    			return "no name available";
    		}
    	}
    }

Discussions similaires

  1. Une librairie bluetooth ?
    Par kmedghaith dans le forum C++
    Réponses: 2
    Dernier message: 25/01/2010, 10h44
  2. [JAVA CLIENT] Librairie Javacomm introuvable
    Par miupom dans le forum Débuter avec Java
    Réponses: 2
    Dernier message: 15/07/2009, 13h56
  3. [php-4-src.rpm]Librairie dynamique introuvable par rpm
    Par SYL666 dans le forum Administration système
    Réponses: 1
    Dernier message: 03/07/2007, 15h20
  4. Librairie Bluetooth pour Windows
    Par Janitrix dans le forum Windows
    Réponses: 2
    Dernier message: 03/07/2007, 12h04
  5. Librairie BDE introuvable
    Par jld66 dans le forum Bases de données
    Réponses: 2
    Dernier message: 08/09/2006, 09h48

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