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

VB 6 et antérieur Discussion :

Couplage automatique avec le bluetooth en VB6


Sujet :

VB 6 et antérieur

  1. #1
    Membre à l'essai
    Homme Profil pro
    Étudiant
    Inscrit en
    Janvier 2012
    Messages
    41
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Janvier 2012
    Messages : 41
    Points : 22
    Points
    22
    Par défaut Couplage automatique avec le bluetooth en VB6
    bonjour,
    je suis entrain de modifier une communication entre mon programme sur mon PC et un appareil.
    Il était connecté directement par USB, mais maintenant je change pour une connexion Bluetooth .
    le programme arrive à se connecter sur l’appareil sauf que l'utilisateur doit saisir le code PIN à chaque fois (sachant qu'il peut l'utiliser plusieurs fois par heure ).
    j'ai essayé d'automatiser cette étape, mais sans succès .
    Est ce qu'il y a un moyen pour que celle-ci soit transparente pour l'utilisateur??

    merci d'avance

  2. #2
    Membre à l'essai
    Homme Profil pro
    Étudiant
    Inscrit en
    Janvier 2012
    Messages
    41
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Janvier 2012
    Messages : 41
    Points : 22
    Points
    22
    Par défaut
    il ya une solution, mais ce n'est pas complètement opérationnel. Créer une dll ActiveX en suivant ces étapes avec "InTheHand.Net.Personal.dll":
    - Ouvrer VS2010 en tant qu'administrateur.
    - Creer un projet bibliothèque de classes (exmaple - MyProject).
    - Ajouter une nouvelle interface pour le projet (voir l'exemple ci-dessous).
    - Ajouter un using System.Runtime.InteropServices; au fichier
    - Ajouter la InterfaceType attributs, Guid à l'interface.
    - Vous pouvez générer un GUID en utilisant Outils-> Générer GUID(Create GUID) (option 4).
    - Ajouter une classe qui implémente cette interface.
    - Ajouter la ClassInterface attributs, Guid, ProgId à l'interface.
    - ProgId convention est {namespace} {classe}.
    Sous le dossier Propriétés dans le projet dans le fichier AssemblyInfo mis ComVisible à true.
    - Dans le menu des propriétés du projet, dans l'onglet build marque "Inscrire pour COM Interop"
    Générez le projet

    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
    29
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
     
    using System.Runtime.InteropServices;
     
    namespace Launcher
    {
     
        [InterfaceType(ComInterfaceType.InterfaceIsDual), Guid("XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX")]
        public interface ILauncher
        {
            void launch();
        }
     
        [ClassInterface(ClassInterfaceType.None), Guid("YYYYYYYY-YYYY-YYYY-YYYY-YYYYYYYYYYY"), ProgId("Launcher.Launcher")]
        public class Launcher : ILauncher
        {
            private string path = null;
     
            public void launch()
            {
                Console.WriteLine("I launch scripts for a living.");
     
            }
     
        }
    }
    - et en VB6 en utilisant le COM:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    set obj = createObject("PSLauncher.PSLauncher") obj.launch()
    télécharger le "InTheHand.Net.Personal.dll" sur ce site :
    site

  3. #3
    Membre à l'essai
    Homme Profil pro
    Étudiant
    Inscrit en
    Janvier 2012
    Messages
    41
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Janvier 2012
    Messages : 41
    Points : 22
    Points
    22
    Par défaut
    voici mon code de DLL :
    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
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using InTheHand.Net.Sockets;
    using InTheHand.Net.Bluetooth;
    using System.Windows.Forms;
    using InTheHand.Net;
    using System.Runtime.InteropServices;
     
    namespace LibrairieDeConnexionBluetoothAvecDLL
    {
     
        [InterfaceType(ComInterfaceType.InterfaceIsDual), Guid("220081A3-4B8F-4834-A47D-0531877D483E"), ComVisible(true)]
        public interface IBluetooth
        {
            bool connection();
            void initialisation();
            void detecterLesDispositifs();
            void choisirUnDispositif();
            void ajouterLesControleALaFentreDeConnexion(Form fenetreDeSelectionDuBluetooth, ListBox listeDesAdresseDesPériphérique, ListBox listeDesNomDesPériphérique, Button Connexion, Button refresh);
            void confgurerFenetreDeConnexion(Form fenetreDeSelectionDuBluetooth);
            void configurerLeBouton(Button Connexion, int marginGauche, int marginHaut, string nom, bool etat);
            void configurerLaListe(ListBox liste, int with, int height, int marginGauche, int marginHaut, bool enable);
            void seConnecter();
            void Win32AuthCallbackHandler(object sender, InTheHand.Net.Bluetooth.BluetoothWin32AuthenticationEventArgs e);
            void listeDesNomDesPériphérique_SelectedIndexChanged(object sender, EventArgs e);
            void Refresh_Click(object sender, EventArgs e);
            void Connexion_Click(object sender, EventArgs e);
        }
     
        [ClassInterface(ClassInterfaceType.None), Guid("90A2335C-0310-49C1-AF57-E9BF993647D5"), ProgId("LibrairieDeConnexionBluetoothAvecDLL.Bluetooth"), ComVisible(true)]
        public class Bluetooth : UserControl, IBluetooth
        {
            private BluetoothClient listeDePeripheriqueBluetooth;
            private BluetoothClient SerialPort;
            private BluetoothDeviceInfo optifive;
            private Guid service;
            private BluetoothDeviceInfo[] bdi;
            private BluetoothRadio radio;
            private Form fenetreDeSelectionDuBluetooth;
            private ListBox listeDesNomDesPériphériques;
            private ListBox listeDesAdresseDesPériphériques;
            private Button Connexion;
            private Button Refresh;
     
            public bool connection()
            {
                initialisation();
                detecterLesDispositifs();
                listeDesNomDesPériphériques.SelectedIndexChanged += new System.EventHandler(
                    listeDesNomDesPériphérique_SelectedIndexChanged);
                Refresh.Click += new System.EventHandler(Refresh_Click);
                Connexion.Click += new System.EventHandler(Connexion_Click);
     
                return optifive.Connected;
            }
     
            public void initialisation()
            {
                radio = BluetoothRadio.PrimaryRadio;
                if (radio != null && radio.Mode == RadioMode.PowerOff)
                {
                    BluetoothRadio.PrimaryRadio.Mode = RadioMode.Connectable;
                }
                listeDePeripheriqueBluetooth = new BluetoothClient();
                service = BluetoothService.SerialPort;
     
                fenetreDeSelectionDuBluetooth = new Form();
                confgurerFenetreDeConnexion(fenetreDeSelectionDuBluetooth);
                listeDesNomDesPériphériques = new ListBox();
                listeDesAdresseDesPériphériques = new ListBox();
                Connexion = new Button();
                Refresh = new Button();
                configurerLaListe(listeDesNomDesPériphériques, 200, 300, 5, 5, true);
                configurerLaListe(listeDesAdresseDesPériphériques, 200, 300, 220, 5, false);
                configurerLeBouton(Connexion, 220, 310, "Connexion", false);
                configurerLeBouton(Refresh, 5, 310, "Refresh", true);
                ajouterLesControleALaFentreDeConnexion(fenetreDeSelectionDuBluetooth, listeDesAdresseDesPériphériques, listeDesNomDesPériphériques, Connexion, Refresh);
                fenetreDeSelectionDuBluetooth.Show();
            }
     
            public void detecterLesDispositifs()
            {
                //this will take a while...
                Cursor.Current = Cursors.WaitCursor;
                bdi = listeDePeripheriqueBluetooth.DiscoverDevices();
                //bind the combo
                if (listeDesAdresseDesPériphériques.Items.Count>0)
                    listeDesAdresseDesPériphériques.Items.Clear();
                if(listeDesNomDesPériphériques.Items.Count>0)
                    listeDesNomDesPériphériques.Items.Clear();
                bdi.ToList().ForEach(delegate(BluetoothDeviceInfo Device)
                {
                    listeDesNomDesPériphériques.Items.Add(Device.DeviceName);
                    listeDesAdresseDesPériphériques.Items.Add(Device.DeviceAddress.ToString().Insert(10, ":").Insert(8, ":").Insert(6, ":").Insert(4, ":").Insert(2, ":"));
                });
                Cursor.Current = Cursors.Default;
     
            }
     
     
            public void choisirUnDispositif()
            {
                bdi.ToList().ForEach(delegate(BluetoothDeviceInfo device)
                {
                    if (device.DeviceName == listeDesNomDesPériphériques.SelectedItem.ToString().Replace(":", ""))
                        optifive = device;
                });
            }
     
            public void ajouterLesControleALaFentreDeConnexion(Form fenetreDeSelectionDuBluetooth, ListBox listeDesAdresseDesPériphérique, ListBox listeDesNomDesPériphérique, Button Connexion, Button refresh)
            {
                fenetreDeSelectionDuBluetooth.Controls.Add(listeDesNomDesPériphérique);
                fenetreDeSelectionDuBluetooth.Controls.Add(listeDesAdresseDesPériphérique);
                fenetreDeSelectionDuBluetooth.Controls.Add(Connexion);
                fenetreDeSelectionDuBluetooth.Controls.Add(refresh);
            }
     
            public void confgurerFenetreDeConnexion(Form fenetreDeSelectionDuBluetooth)
            {
                fenetreDeSelectionDuBluetooth.StartPosition = FormStartPosition.CenterScreen;
                fenetreDeSelectionDuBluetooth.Height = 378;
                fenetreDeSelectionDuBluetooth.Width = 445;
                fenetreDeSelectionDuBluetooth.Text = "Connexion Bluetooth";
            }
     
            public void configurerLeBouton(Button Connexion, int marginGauche, int marginHaut, string nom, bool etat)
            {
                Connexion.Left = marginGauche;
                Connexion.Top = marginHaut;
                Connexion.Width = 100;//height==23
                Connexion.Text = nom;
                Connexion.Enabled = etat;
            }
     
            public void configurerLaListe(ListBox liste, int with, int height, int marginGauche, int marginHaut, bool enable)
            {
                liste.Height = height;
                liste.Width = with;
                liste.Left = marginGauche;
                liste.Top = marginHaut;
                liste.Enabled = enable;
                if (liste == null)
                    MessageBox.Show("n'éxiste pas");
                else
                    MessageBox.Show("éxiste");
            }
     
     
            public void seConnecter()
            {
                try
                {
                    BluetoothWin32Authentication authetification = new BluetoothWin32Authentication(Win32AuthCallbackHandler);
                    SerialPort = new BluetoothClient();
                    SerialPort.Connect(new BluetoothEndPoint(optifive.DeviceAddress, service));
                }
                catch (Exception ex)
                {
                    MessageBox.Show("n'arrive pas a se connecter : " + ex.Message);
                }
     
            }
     
     
     
     
     
            public void Win32AuthCallbackHandler(object sender, InTheHand.Net.Bluetooth.BluetoothWin32AuthenticationEventArgs e)
            {
                // Note we assume here that 'Legacy' pairing is being used,
                // and thus we only set the Pin property!
                string address = e.Device.DeviceAddress.ToString();
                Console.WriteLine("Received an authentication request from address " + address);
                //
                // compare the first 8 hex numbers, this is just a special case because in the
                // used scenario the model of the devices can be identified by the first 8 hex
                // numbers, the last 4 numbers being the device specific part.
     
                // send authentication response
                e.Pin = "0000";
     
                e.Confirm = true;
            }
     
     
            public void listeDesNomDesPériphérique_SelectedIndexChanged(object sender, EventArgs e)
            {
                choisirUnDispositif();
                listeDesAdresseDesPériphériques.SelectedIndex = listeDesNomDesPériphériques.SelectedIndex;
                Connexion.Enabled = true;
            }
     
     
            public void Refresh_Click(object sender, EventArgs e)
            {
                detecterLesDispositifs();
            }
     
     
            public void Connexion_Click(object sender, EventArgs e)
            {
                seConnecter();
            }
     
     
        }
    }

Discussions similaires

  1. Pairing automatique de devices Bluetooth avec mot de passe
    Par H3bus dans le forum API standards et tierces
    Réponses: 1
    Dernier message: 16/10/2012, 13h04
  2. pb avec un ocx en vb6
    Par arsa dans le forum VB 6 et antérieur
    Réponses: 4
    Dernier message: 26/11/2005, 12h37
  3. Numéro automatique avec PostgreSql
    Par BRAUKRIS dans le forum PostgreSQL
    Réponses: 3
    Dernier message: 09/09/2005, 22h55
  4. Envoi de mail automatique avec Visual C++
    Par cza dans le forum MFC
    Réponses: 2
    Dernier message: 22/02/2005, 15h59
  5. Démarrage automatique avec xfce
    Par lunatix dans le forum Applications et environnements graphiques
    Réponses: 4
    Dernier message: 21/09/2004, 22h50

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