Windows / .NetのBluetooth API?
-
02-07-2019 - |
質問
私は、近くのモバイルデバイスを見つけて識別するBluetoothスキャナーを作成中です。これはC#を使用して達成できるものですか、それともC / C ++ APIにドロップダウンする必要がありますか?私のアプリケーションはWindows XPおよびVistaを対象としています。ポインターは大歓迎です。
ありがとう!
解決
PCのBluetoothの問題の1つは、使用中のBTスタックがいくつかあり、特定のマシンでどのBTスタックが利用可能かをまったくわからないことです。最も一般的なものは、Widcomm(現在のBroadcom)とMicrosoft(XPで登場、おそらくサービスパックの1つ)です。ただし、一部のBTハードウェアベンダーはBlueSoleilをパッケージ化し、一部は東芝を使用しています。ほとんどのドングルはMSスタックで動作するため、私が見た.NETライブラリはそれを使用する傾向があります。
各スタックは、近くのデバイスを参照してサービスを問い合わせるディスカバリー部分を実行するまったく異なる方法を持っています。
今日、1つのアプローチを選択する必要がある場合は、おそらくC ++で検出を行い、.NETのインターフェイスを追加します。
32feet.netを試してみたところ、かなりうまくいきましたが、Widcommスタックをサポートしていませんでした。
他のヒント
マイクペトリチェンコには素晴らしいBTフレームワークがあります。 BlueSoleil、Widcomm、Toshiba、Microsoftで動作します。
現在はワイヤレス通信ライブラリと呼ばれ、Bluetooth 802.11および赤外線で動作します。 Mikeは会社をSoft Service Companyに指名し、100ドルから2050ドルの範囲の価格でソースコードの有無にかかわらず非商用および商用ライセンスを販売しています。
Bluetoothデバイスを知り、PCからBluetoothデバイスにファイルを送信する最良の方法は、そのコードを使用することです。
public void ExecuteCommandSync(object command)
{
try
{
// create the ProcessStartInfo using "cmd" as the program to be run,
// and "/c " as the parameters.
// Incidentally, /c tells cmd that we want it to execute the command that follows,
// and then exit.
System.Diagnostics.ProcessStartInfo procStartInfo =
new System.Diagnostics.ProcessStartInfo("cmd", "/c " + command);
// The following commands are needed to redirect the standard output.
// This means that it will be redirected to the Process.StandardOutput StreamReader.
procStartInfo.RedirectStandardOutput = true;
procStartInfo.UseShellExecute = false;
// Do not create the black window.
procStartInfo.CreateNoWindow = true;
// Now we create a process, assign its ProcessStartInfo and start it
System.Diagnostics.Process proc = new System.Diagnostics.Process();
proc.StartInfo = procStartInfo;
proc.Start();
// Get the output into a string
string result = proc.StandardOutput.ReadToEnd();
// Display the command output.
Console.WriteLine(result);
}
catch (Exception objException)
{
// Log the exception
MessageBox.Show(objException.Message);
}
}
このメソッドは次のように呼び出すことができます
string command = "fsquirt";
ExecuteCommandSync(command);
したがって、BluetoothFileTransferWizardが表示され、使用可能なデバイスを選択して、そのデバイスを送信するためのファイルを送信できます。この方法を使用したくない場合は、32feet.net.ukを試してください。これは、C#およびVB.NETのBluetooth開発に最適でした。