Add Reference InTheHand.Net.Personal.dll
First create a Bluetooth class
1 classLanya {2 Public stringBluename {Get;Set; }//L Bluetooth Name3 PublicBluetoothaddress blueaddress {Get;Set; }//Unique identifier for Bluetooth4 PublicClassofdevice Blueclassofdevice {Get;Set; }//What type of Bluetooth is it?5 Public BOOLIsblueauth {Get;Set; }//specify that the device passes validation6 Public BOOLisblueremembered {Get;Set; }//Remember device7 PublicDateTime Bluelastseen {Get;Set; }8 PublicDateTime bluelastused {Get;Set; }9}
Then it's the search device.
1List<lanya> lanyalist =NewList<lanya> ();//search for a collection of Bluetooth2Bluetoothclient client =Newbluetoothclient (); 3Bluetoothradio radio = Bluetoothradio.primaryradio;//get the Bluetooth adapter4Radio. Mode =radiomode.connectable; 5Bluetoothdeviceinfo[] devices = client. Discoverdevices ();//Search for Bluetooth for 10 seconds6 foreach(varIteminchdevices) {7Lanyalist.add (NewLanya {bluename = Item. DeviceName, blueaddress = Item. DeviceAddress, Blueclassofdevice = Item. Classofdevice, Isblueauth = Item. Authenticated, isblueremembered = Item. Remembered, Bluelastseen = Item. Lastseen, bluelastused = Item. lastused});//Add the search Bluetooth to the collection8}
Pairing of Bluetooth
1 New bluetoothclient (); 2 Guid mGUID1 = bluetoothservice.handsfree; // UUID for Bluetooth service 3 4 Blueclient. Connect (s.blueaddress, Mguid) // start pairing Bluetooth 4.0 does not require Setpin
Client
1bluetoothclient BL =NewBluetoothclient ();//2Guid mGUID2 = Guid.parse ("00001101-0000-1000-8000-00805F9B34FB");//UUIID of Bluetooth serial port service3 4 Try5 {6 Bl. Connect (s.blue_address, mguid);7 //"Successful connection";8 }9 Catch(Exception x)Ten { One //Exception A } - - varv =Bl. GetStream (); the byte[] SendData =Encoding.Default.GetBytes ("Life is short, I use Python"); -V.write (SendData,0, senddata.length);//Send
Server-side
1Bluetoothlistener =NewBluetoothlistener (mGUID2);2Bluetoothlistener.start ();//Start listening .3 4BL = Bluetoothlistener.acceptbluetoothclient ();//Receive5 6 7 while(true)8 {9 byte[] buffer =New byte[ -];TenStream Peerstream =Bl. GetStream (); One APeerstream.read (Buffer,0, buffer. Length); - - stringData= Encoding.UTF8.GetString (buffer). ToString (). Replace (" /","");//Remove the bytes from the back the}
This is basically it!
Bluetooth communication above the PC (C #)