蓝牙串行端口与 Obex 文件传输
Bluetooth SerialPort vs ObexFileTransfer
下午好。
我正在开发一个应用程序,它可以通过蓝牙将文件从计算机传输到智能手机,但配对不符合我的预期。
与 32feets 库配对:
BluetoothEndPoint remoteEndPoint = new BluetoothEndPoint(selecteddevice.DeviceAddress,BluetoothService.ObexFileTransfer);
最后一个参数假定为蓝牙适配器 GUID。如果我用
喂它
BluetoothService.SerialPort。我只能连接到 Iphone SE
BluetoothService.ObexFileTransfer。我只能连接 Allview Soul Xtream Mini。
我还有一个 galaxy tab 2,我无法通过任何一种方式连接它。
我使用了一个 catch,错误如下:
- ex {"The requested address is not valid in its context 4CBCA5CAA8A0:0000110600001000800000805f9b34fb"} System.Net.Sockets.SocketException
我做了一些研究,这是我发现的:
https://32feet.codeplex.com/wikipage?title=Errors
配对码:
private void Connect()
{
SelectBluetoothDeviceDialog bldialog = new SelectBluetoothDeviceDialog();
serviceClass = BluetoothService.SerialPort;
bldialog.ShowAuthenticated = true;
bldialog.ShowRemembered = true;
bldialog.ShowUnknown = true;
if (bldialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
if (bldialog.SelectedDevice == null)
{
System.Windows.Forms.MessageBox.Show("No device selected", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
BluetoothDeviceInfo selecteddevice = bldialog.SelectedDevice;
BluetoothEndPoint remoteEndPoint = new BluetoothEndPoint(selecteddevice.DeviceAddress, BluetoothService.ObexFileTransfer);
client = new BluetoothClient();
try
{
client.Connect(remoteEndPoint);
}
catch (SocketException ex)
{
return;
}
catch (ObjectDisposedException ex)
{
return;
}
catch (IOException ex)
{
return;
}
textBox.Text += string.Format("Connected to: {0}", selecteddevice.DeviceName);
textBox.Text += string.Format("Bluetooth Device Browser. Current Device: {0}", selecteddevice.DeviceName);
}
}
作为蓝牙,我使用的是 ASUS USB-BT400。
我该怎么做才能解决我的连接问题?
我这样解决了问题
BluetoothDeviceInfo selecteddevice = bldialog.SelectedDevice;
if (selecteddevice.DeviceName.ToLower().Contains("iphone"))
serviceClass = BluetoothService.SerialPort;
else if (selecteddevice.DeviceName.ToLower().Contains("allview"))
serviceClass = new Guid("00001103-0000-1000-8000-00805f9b34fb");
else serviceClass = BluetoothService.ObexFileTransfer;
此外,如果其他人知道我如何连接到我正在收听的 galaxy 选项卡,我也无法与之配对。
下午好。 我正在开发一个应用程序,它可以通过蓝牙将文件从计算机传输到智能手机,但配对不符合我的预期。
与 32feets 库配对:
BluetoothEndPoint remoteEndPoint = new BluetoothEndPoint(selecteddevice.DeviceAddress,BluetoothService.ObexFileTransfer);
最后一个参数假定为蓝牙适配器 GUID。如果我用
喂它BluetoothService.SerialPort。我只能连接到 Iphone SE
BluetoothService.ObexFileTransfer。我只能连接 Allview Soul Xtream Mini。 我还有一个 galaxy tab 2,我无法通过任何一种方式连接它。 我使用了一个 catch,错误如下:
- ex {"The requested address is not valid in its context 4CBCA5CAA8A0:0000110600001000800000805f9b34fb"} System.Net.Sockets.SocketException
我做了一些研究,这是我发现的: https://32feet.codeplex.com/wikipage?title=Errors
配对码:
private void Connect()
{
SelectBluetoothDeviceDialog bldialog = new SelectBluetoothDeviceDialog();
serviceClass = BluetoothService.SerialPort;
bldialog.ShowAuthenticated = true;
bldialog.ShowRemembered = true;
bldialog.ShowUnknown = true;
if (bldialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
if (bldialog.SelectedDevice == null)
{
System.Windows.Forms.MessageBox.Show("No device selected", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
BluetoothDeviceInfo selecteddevice = bldialog.SelectedDevice;
BluetoothEndPoint remoteEndPoint = new BluetoothEndPoint(selecteddevice.DeviceAddress, BluetoothService.ObexFileTransfer);
client = new BluetoothClient();
try
{
client.Connect(remoteEndPoint);
}
catch (SocketException ex)
{
return;
}
catch (ObjectDisposedException ex)
{
return;
}
catch (IOException ex)
{
return;
}
textBox.Text += string.Format("Connected to: {0}", selecteddevice.DeviceName);
textBox.Text += string.Format("Bluetooth Device Browser. Current Device: {0}", selecteddevice.DeviceName);
}
}
作为蓝牙,我使用的是 ASUS USB-BT400。 我该怎么做才能解决我的连接问题?
我这样解决了问题
BluetoothDeviceInfo selecteddevice = bldialog.SelectedDevice;
if (selecteddevice.DeviceName.ToLower().Contains("iphone"))
serviceClass = BluetoothService.SerialPort;
else if (selecteddevice.DeviceName.ToLower().Contains("allview"))
serviceClass = new Guid("00001103-0000-1000-8000-00805f9b34fb");
else serviceClass = BluetoothService.ObexFileTransfer;
此外,如果其他人知道我如何连接到我正在收听的 galaxy 选项卡,我也无法与之配对。