日期:2014-05-17 浏览次数:20815 次
namespace serve
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
public bool OpenPort()
{
InTheHand.Net.Bluetooth.BluetoothRadio.PrimaryRadio.Mode = InTheHand.Net.Bluetooth.RadioMode.Connectable;
InTheHand.Net.Sockets.BluetoothClient cli = new InTheHand.Net.Sockets.BluetoothClient();
InTheHand.Net.Sockets.BluetoothDeviceInfo[] devices = cli.DiscoverDevices();
foreach (InTheHand.Net.Sockets.BluetoothDeviceInfo device in devices) //设备搜寻
{
device.Update();
device.Refresh();
MessageBox.Show("设备已找到");
break;
}
BluetoothDeviceInfo bd = new BluetoothDeviceInfo(devices[0].DeviceAddress);
bluetoothClient = new BluetoothClient();
Guid mGUID = Guid.Parse("fa87c0d0-afac-11de-8a39-0800200c9a66");
bluetoothClient.Connect(devices[0].DeviceAddress, mGUID);//客户端对地址实现连接,这是一个阻塞线程