Chronogps Posted March 20, 2011 Share Posted March 20, 2011 Je rencontre un problème de Socket sur un périphérique bluetooth (il s'agit d'un dongle bluetooth qui se branche sur une voiture pour récupérer des données du calculateur). Ce périphérique fonctionne bien (j'ai testé un soft dédié à ce matériel sur le market qui fonctionne). Sous Windows (pc ou mobile), j'apairais le dongle en lui associant un port COM. Le dialogue ensuite s'opère comme avec un modem (avec des séquences AT XXX). J'utilise le code ci dessous qui fonctionne parfaitement avec un autre périphérique bluetooth (une antenne gps externe). Avec la clé j'ai systématiquement une erreur sur le Socket.connect() (service discovery failed). J'avoues que je sèche un peu. J'ai testé le programme d'exemple Bluetooth chat : même erreur. Une idée ? une piste ? J'ai l'impression de ne pas attaquer le problème dans le bon sens... class OBDListener implements Runnable { private TextView textView; private Handler handler; private OBD Obd; BluetoothAdapter bluetooth; BluetoothDevice device; BluetoothSocket Socket; InputStream instream=null; OutputStream outstream=null; public OBDListener(String Id,Handler handler, TextView textView,OBD Obd) { String debug=""; this.textView = textView; this.handler = handler; this.Obd = Obd; bluetooth = BluetoothAdapter.getDefaultAdapter(); try { debug="bluetooth OK"; device = bluetooth.getRemoteDevice(Id); if (device!=null) { //Socket = device.createRfcommSocketToServiceRecord(uuid); Method m=null; try { m = device.getClass().getMethod("createRfcommSocket", new Class[] {int.class}); } catch (SecurityException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (NoSuchMethodException e) { // TODO Auto-generated catch block e.printStackTrace(); } try { if (m!=null) Socket = (BluetoothSocket) m.invoke(device, 1); } catch (IllegalArgumentException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IllegalAccessException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (InvocationTargetException e) { // TODO Auto-generated catch block e.printStackTrace(); } debug+="/device OK"; } if (Socket != null) { debug+="/socket OK"; Socket.connect(); } } catch (IOException e) { handler.post(new MessagePoster(textView, debug+"/"+e.getMessage(),null,null,0)); } } public void run() { try { instream=null; instream = Socket.getInputStream(); outstream=null; outstream= Socket.getOutputStream(); (...) } catch (IOException e) { handler.post(new MessagePoster(textView, "get/input/outputstream/"+e.getMessage(),null,null,0)); } } } Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.