Problème Socket Bluetooth

Problème Socket Bluetooth - C - Programmation

Marsh Posté le 01-07-2008 à 18:31:35    

Bonjour à tous,
 
depuis un petit moment j'essaie de faire un programme qui puisse communiquer avec mon téléphone portable.
Je me confronte cependant à un problème au moment de la création d'un socket bluetooth.
 
Je débute en tout ce qui concerne la communication via socket, mais là ça bloque avant :
Le début de la fonction correspond à du code à microsoft, utilisé pour les fonctions WSA*
 
 
int  main(int ac, char **av)
{
 
 int  s; /*mon socket*/
 
/*les trucs à crosoft*/
    WORD wVersionRequested;
    WSADATA wsaData;
    int err;
 
    wVersionRequested = MAKEWORD(2, 2);
    err = WSAStartup(wVersionRequested, &wsaData);
    if (err != 0) {
        printf("WSAStartup failed with error: %d\n", err);
        return 1;
    }
 
    if (LOBYTE(wsaData.wVersion) != 2 || HIBYTE(wsaData.wVersion) != 2) {
        printf("Could not find a useable version of Winsock.dll\n" );
        WSACleanup();
        return 1;
    }
    else
        printf("The Winsock 2.2 dll was found okay\n" );
         
 
/*là c'est moi qui prend le relai*/
 printf("debut\n" );
 s = socket(AF_BTH, SOCK_STREAM, BTHPROTO_RFCOMM);
 if (s == INVALID_SOCKET)
  printf("non %d\n", WSAGetLastError());
 else
  printf("oui\n" );
 
 printf("fin\n" );
 WSACleanup();
 return (0);
}
 
Ce qu'il se passe :
Le programme trouve le socket invalide, et m'écrit, tel que je lui demande, "non" suivi du numéro d'erreur, en l'occurence 10047
 
d'après Microsoft :
http://msdn.microsoft.com/en-us/li [...] S.85).aspx
WSAEAFNOSUPPORT
10047
 
Address family not supported by protocol family.
 
    An address incompatible with the requested protocol was used. All sockets are created with an associated address family (that is, AF_INET for Internet Protocols) and a generic protocol type (that is, SOCK_STREAM). This error is returned if an incorrect protocol is explicitly requested in the socket call, or if an address of the wrong family is used for a socket, for example, in sendto.
 
OR :
http://msdn.microsoft.com/en-us/li [...] S.85).aspx
AF_BTM (il y a un define AF_BTM AF_BTH)
32
 
The Bluetooth address family. This address family is supported on Windows XP SP2 or later if the computer has a Bluetooth adapter and driver installed.
 
Je suis bien sous Windows XP SP2 (je suis passé au SP3 mais ça marche pas non plus, j'ai bien un adaptateur bluetooth (intégré) qui fonctionne avec les logiciels de base)
 
POUR FINIR :
toujours d'après le man socket() de crosoft :
BTHPROTO_RFCOMM
3
 
The Bluetooth Radio Frequency Communications (Bluetooth RFCOMM) protocol. This is a possible value when the af parameter is AF_BTH and the type parameter is SOCK_STREAM. This protocol is supported on Windows XP SP2 or later.
 
Les paramètres que je donne à ma fonction socket sont bien AF_BTH, SOCK_STREAM et BTHPROTO_RFCOMM
Malgré cela WSAGetLastError me dis que l'address family n'est pas supporté, je ne comprends pas pourquoi.
 
les includes que j'ai sont, dans l'ordre,  
#include <stdlib.h>
#include <stdio.h>
#include <Winsock2.h>
#include <Ws2bth.h>
#include <Bthsdpdef.h>
#include <BluetoothAPIs.h>
 
Si vous pouviez m'aider en me disant d'où ça vient, je vous en serai reconnaissant.
Vous devriez pouvoir facilement compiler ce code sous windows.
 
Merci, n'hésitez pas à poser des questions.

Reply

Marsh Posté le 01-07-2008 à 18:31:35   

Reply

Marsh Posté le 11-03-2009 à 23:35:43    

Quand tu dit tout les logiciel, ton dongle blutooth utilise bien le driver generic de crosoft, tu as le petit icone bt dans la barre des taches et ton téléphone est ds la list de ses perif ?

Reply

Sujets relatifs:

Leave a Replay

Make sure you enter the(*)required information where indicate.HTML code is not allowed