关于蓝牙连接PC和PPC失败的问题
我使用的一个蓝牙程序可以正常的搜索到可用设备的ID,但是在连接的时候,只要是连接PC和PPC(windows mobile 6)就会失败,不过如果是连接S40或者linux系统的手机却成功。不知道是哪里出问题了。代码本身并不长---用的inthehand的dll。 难道微软自己的系统兼容性还有问题? 另外说的是我用的SDK5.0生成的程序,安装在6.0系统的机子里,这个是不是也有什么影响
主要代码如下:
private void button1_Click(object sender, EventArgs e)
{
BluetoothRadio.PrimaryRadio.Mode = RadioMode.Connectable;
bluetoothClient = new BluetoothClient();
Cursor.Current = Cursors.WaitCursor;
BluetoothDeviceInfo[] bluetoothDeviceInfo = { };
bluetoothDeviceInfo = bluetoothClient.DiscoverDevices(10);
comboBox1.DataSource = bluetoothDeviceInfo;
comboBox1.DisplayMember = "DeviceName";
comboBox1.ValueMember = "DeviceAddress";
comboBox1.Focus();
Cursor.Current = Cursors.Default;
}
private void button2_Click(object sender, EventArgs e)
{
if (comboBox1.SelectedValue != null)
{
try
{
bluetoothClient.Connect(new BluetoothEndPoint((BluetoothAddress)comboBox1.SelectedValue, service));
MessageBox.Show("Connected");
NetworkStream stream = bluetoothClient.GetStream();
string message = "Hello Server!";
Byte[] data = System.Text.Encoding.ASCII.GetBytes(message);
stream.Write(data, 0, data.Length);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
}
[解决办法]
这是codeproject上的例子吧
我用了也遇到过这种问题
后来修改service值为BluetoothService.SerialPort就OK了
private Guid service = BluetoothService.SerialPort;