資源簡介
C# wince 藍(lán)牙控制、搜索設(shè)備、文件發(fā)送

代碼片段和文件信息
using?System;
using?System.Collections.Generic;
using?System.ComponentModel;
using?System.Data;
using?System.Drawing;
using?System.Text;
using?System.Windows.Forms;
using?InTheHand.Net;
using?InTheHand.Net.Bluetooth;
using?InTheHand.Net.Ports;
using?InTheHand.Net.Sockets;
using?System.Threading;
namespace?NewHMIBth
{
????public?partial?class?MainFrm?:?Form
????{
????????private?BluetoothListener?Listener;
????????private?List?clientList?=?new?List();
???????
????????private?bool?listening?=?true;
????????public?MainFrm()
????????{
????????????InitializeComponent();
????????????btnSend.Enabled?=?false;
????????????btnStop.Enabled?=false;
????????}
???????private??delegate?void?SafeWinFormsThreadDelegate(string?msg);
????????private?void?WriteMsg(string?msg)
????????{
????????????SafeWinFormsThreadDelegate?d?=?new?SafeWinFormsThreadDelegate(UpdateUI);
????????????Invoke(d?new?object[]?{?msg?});
????????}
????????private?void?UpdateUI(string?msg)
????????{
????????????this.listBoxMsg.Items.Add(msg);
????????}
????????private?void?btnStart_Click(object?sender?EventArgs?e)
????????{
????????????BluetoothRadio?radio?=?BluetoothRadio.PrimaryRadio;
????????????if?(radio?==?null)
????????????{
????????????????UpdateUI(“沒有發(fā)現(xiàn)藍(lán)牙設(shè)備或者不支持藍(lán)牙協(xié)議棧!“);
????????????????return;
????????????}
????????????radio.Mode?=?RadioMode.Discoverable;
????????????Listener?=?new?BluetoothListener(BluetoothService.SerialPort);
????????????Listener.Start();
????????????listening?=?true;
????????????Thread?ListenerThread?=?new?Thread(ListenLoop);
????????????ListenerThread.Start();
????????????btnStop.Enabled?=?true;
????????????btnStart.Enabled?=?false;
????????????btnSend.Enabled?=?true;
????????????UpdateUI(“藍(lán)牙服務(wù)開始!“);
???????
????????}
????????private?void?ListenLoop()
????????{?
??????????????string?dataToSend?=?“感謝您的藍(lán)牙信息訂閱\r\n“;
??????????????byte[]?dataBuffer?=?System.Text.Encoding.Unicode.GetBytes(dataToSend);
??????????while(listening)
??????????{
?????????????
??????????????try
??????????????{
??????????????????BluetoothClient?Client?=?Listener.AcceptBluetoothClient();
??????????????????WriteMsg(“獲得從“+Client.RemoteMachineName+“藍(lán)牙信息訂閱“);
??????????????????clientList.Add(Client);
??????????????????System.IO.Stream?ns?=?Client.GetStream();
??????????????????ns.Write(dataBuffer?0?dataBuffer.Length);
??????????????}
??????????????catch
??????????????{
??????????????????break;
??????????????}
??????????}
??????????Listener.Stop();
????????}
????????private?void?btnSend_Click(object?sender?EventArgs?e)
????????{
????????????BroadLoop(this.txtMsg.Text);
????????}
????????private?void?BroadLoop(string?Msg)
????????{
????????????List?tempClientList?=?new?List();
????????????string??dataSend=“藍(lán)牙發(fā)送的信息內(nèi)容:“+Msg+“\r\n“;
????????????Byte[]??dataBuffer=System.Text.Encoding.Unicode.GetBytes(dataSend);
????????????foreach
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件????????346??2010-02-13?10:24??Bluetooth\NewHMIBth\NewBthDeviceCab\Debug\CabWiz.log
?????文件?????245542??2010-02-13?10:24??Bluetooth\NewHMIBth\NewBthDeviceCab\Debug\NewBthDeviceCab.CAB
?????文件???????1826??2010-02-13?10:24??Bluetooth\NewHMIBth\NewBthDeviceCab\Debug\NewBthDeviceCab.inf
?????文件??????15960??2010-02-13?10:24??Bluetooth\NewHMIBth\NewBthDeviceCab\NewBthDeviceCab.vddproj
?????文件?????229888??2009-09-09?08:40??Bluetooth\NewHMIBth\NewHMIBth\bin\Debug\InTheHand.Net.Personal.dll
?????文件??????13824??2010-03-28?19:28??Bluetooth\NewHMIBth\NewHMIBth\bin\Debug\NewHMIBth.exe
?????文件??????28160??2010-03-28?19:28??Bluetooth\NewHMIBth\NewHMIBth\bin\Debug\NewHMIBth.pdb
?????文件???????6392??2010-02-13?10:24??Bluetooth\NewHMIBth\NewHMIBth\MainFrm.cs
?????文件??????11170??2010-02-13?10:24??Bluetooth\NewHMIBth\NewHMIBth\MainFrm.Designer.cs
?????文件???????6298??2010-02-13?10:24??Bluetooth\NewHMIBth\NewHMIBth\MainFrm.resx
?????文件???????4196??2009-12-05?14:21??Bluetooth\NewHMIBth\NewHMIBth\NewHMIBth.csproj
?????文件????????198??2010-03-28?19:28??Bluetooth\NewHMIBth\NewHMIBth\NewHMIBth.csproj.user
?????文件????????844??2010-02-13?10:24??Bluetooth\NewHMIBth\NewHMIBth\obj\Debug\NewHMIBth.csproj.GenerateResource.Cache
?????文件??????13824??2010-03-28?19:28??Bluetooth\NewHMIBth\NewHMIBth\obj\Debug\NewHMIBth.exe
?????文件????????180??2010-02-13?10:24??Bluetooth\NewHMIBth\NewHMIBth\obj\Debug\NewHMIBth.MainFrm.resources
?????文件??????28160??2010-03-28?19:28??Bluetooth\NewHMIBth\NewHMIBth\obj\Debug\NewHMIBth.pdb
?????文件????????180??2009-12-05?21:48??Bluetooth\NewHMIBth\NewHMIBth\obj\Debug\NewHMIBth.Properties.Resources.resources
?????文件??????13609??2010-04-07?11:04??Bluetooth\NewHMIBth\NewHMIBth\obj\Debug\ResolveAssemblyReference.cache
?????文件????????284??2010-02-13?10:24??Bluetooth\NewHMIBth\NewHMIBth\obj\NewHMIBth.csproj.FileList.txt
?????文件????????796??2010-03-28?19:28??Bluetooth\NewHMIBth\NewHMIBth\obj\NewHMIBth.csproj.FileListAbsolute.txt
?????文件????????356??2009-12-05?13:17??Bluetooth\NewHMIBth\NewHMIBth\Program.cs
?????文件???????1147??2009-12-05?13:15??Bluetooth\NewHMIBth\NewHMIBth\Properties\AssemblyInfo.cs
?????文件???????2355??2009-12-05?13:15??Bluetooth\NewHMIBth\NewHMIBth\Properties\Resources.Designer.cs
?????文件???????5618??2009-12-05?13:15??Bluetooth\NewHMIBth\NewHMIBth\Properties\Resources.resx
?????文件???????1402??2009-12-05?15:30??Bluetooth\NewHMIBth\NewHMIBth.sln
????..A..H.?????20480??2010-06-17?09:28??Bluetooth\NewHMIBth\NewHMIBth.suo
?????文件?????139264??2009-10-01?22:40??Bluetooth\NewPCBth\NewPCBth\bin\Debug\InTheHand.Net.Personal.dll
?????文件???????5632??2005-12-08?14:51??Bluetooth\NewPCBth\NewPCBth\bin\Debug\NewPCBth.vshost.exe
????..A.SH.??????9728??2010-03-28?19:34??Bluetooth\NewPCBth\NewPCBth\bin\Debug\Thumbs.db
?????文件???????7313??2010-02-13?10:31??Bluetooth\NewPCBth\NewPCBth\Form1.cs
............此處省略43個文件信息
評論
共有 條評論