ahmedmahdibenjemaa
Messages postés18Date d'inscriptionjeudi 27 mars 2008StatutMembreDernière intervention14 mai 2013
-
7 janv. 2013 à 13:02
ahmedmahdibenjemaa
Messages postés18Date d'inscriptionjeudi 27 mars 2008StatutMembreDernière intervention14 mai 2013
-
30 janv. 2013 à 09:36
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??
ahmedmahdibenjemaa
Messages postés18Date d'inscriptionjeudi 27 mars 2008StatutMembreDernière intervention14 mai 2013 30 janv. 2013 à 09:35
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:
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:
set obj = createObject("PSLauncher.PSLauncher") obj.launch()
télécharger le "InTheHand.Net.Personal.dll" sur ce site :
site
ahmedmahdibenjemaa
Messages postés18Date d'inscriptionjeudi 27 mars 2008StatutMembreDernière intervention14 mai 2013 30 janv. 2013 à 09:36
voici mon code de DLL :
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;
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 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.