没有合适的资源?快使用搜索试试~ 我知道了~
首页Windows系统中使用C#编写蓝牙通信程序的简单实例
资源详情
资源评论
资源推荐

Windows系统中使用系统中使用C#编写蓝牙通信程序的简单实例编写蓝牙通信程序的简单实例
主要介绍了Windows系统中使用C#编写蓝牙通信程序的简单实例,文中的例子使用到了32feet.NET中的
InTheHand.Net.Personal类库,需要的朋友可以参考下
现在很多电脑提供了蓝牙支持,很多笔记本网卡也集成了蓝牙功能,也可以采用USB蓝牙方便的连接手机等蓝牙设备进行通
信。
操作蓝牙要使用类库InTheHand.Net.Personal
首先在项目中引用该类库;
static void Main(string[] args)
{
BluetoothRadio bluetoothRadio = BluetoothRadio.PrimaryRadio;
if (bluetoothRadio == null)
{
Console.WriteLine("没有找到本机蓝牙设备!");
}
else
{
Console.WriteLine("ClassOfDevice: " + bluetoothRadio.ClassOfDevice);
Console.WriteLine("HardwareStatus: " + bluetoothRadio.HardwareStatus);
Console.WriteLine("HciRevision: " + bluetoothRadio.HciRevision);
Console.WriteLine("HciVersion: " + bluetoothRadio.HciVersion);
Console.WriteLine("LmpSubversion: " + bluetoothRadio.LmpSubversion);
Console.WriteLine("LmpVersion: " + bluetoothRadio.LmpVersion);
Console.WriteLine("LocalAddress: " + bluetoothRadio.LocalAddress);
Console.WriteLine("Manufacturer: " + bluetoothRadio.Manufacturer);
Console.WriteLine("Mode: " + bluetoothRadio.Mode);
Console.WriteLine("Name: " + bluetoothRadio.Name);
Console.WriteLine("Remote:" + bluetoothRadio.Remote);
Console.WriteLine("SoftwareManufacturer: " + bluetoothRadio.SoftwareManufacturer);
Console.WriteLine("StackFactory: " + bluetoothRadio.StackFactory);
}
Console.ReadKey();
}
如果PC插入了蓝牙适配器,便会显示蓝牙相关信息:
然后我们就要利用蓝牙收发文件了:
前提是蓝牙设备(如手机)已经和PC配对了
public partial class Form1 : Form
{
BluetoothRadio radio = null;//蓝牙适配器
string sendFileName = null;//发送文件名
BluetoothAddress sendAddress = null;//发送目的地址
ObexListener listener = null;//监听器
string recDir = null;//接受文件存放目录
Thread listenThread, sendThread;//发送/接收线程
public Form1()
{
InitializeComponent();
radio = BluetoothRadio.PrimaryRadio;//获取当前PC的蓝牙适配器
CheckForIllegalCrossThreadCalls = false;//不检查跨线程调用
if (radio == null)//检查该电脑蓝牙是否可用
{
MessageBox.Show("这个电脑蓝牙不可用!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
recDir = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);













安全验证
文档复制为VIP权益,开通VIP直接复制

评论0