おそらく、32feet.NETライブラリ(私がメンテナです)を使用して、ジョブを送信する前にプリンタが存在するかどうかを確認してください。プリンタのBluetoothアドレスを知っている必要があります。システムからそれを取得できますか、または多分あなたは常にそれを知っています。
MSFT Bluetoothスタックでの検出は、常に範囲内のすべての既知のデバイスを返します:-(ただし、他の手段を使用してデバイスの存在/不在を検出できます。おそらく、BeginGetServiceRecordsフォームでBluetoothDeviceInfo.GetServiceRecordsを使用します。編集済み):
bool IsPresent(BluetoothAddress addr) // address from config somehow
{
BluetoothDeviceInfo bdi = new BluetoothDeviceInfo(addr);
if (bdi.Connected) {
return true;
}
Guid arbitraryClass = BluetoothService.Headset;
AsyncResult<bool> ourAr = new AsyncResult<bool>(); // Jeffrey Richter's impl
IAsyncResult ar = bdi.BeginGetService(arbitraryClass, IsPresent_GsrCallback, ourAr);
bool signalled = ourAr.AsyncWaitHandle.WaitOne(Timeout);
if (!signalled) {
return false; // Taken too long, so not in range
} else {
return ourAr.Result;
}
}
void IsPresent_GsrCallback(IAsyncResult ar)
{
AsyncResult<bool> ourAr = (AsyncResult<bool>)ar.AsyncState;
const bool IsInRange = true;
const bool completedSyncFalse = true;
try {
bdi.EndGetServiceResult(ar);
ourAr.SetAsCompleted(IsInRange, completedSyncFalse);
} catch {
// If this returns quickly, then it is in range and
// if slowly then out of range but caller will have
// moved on by then... So set true in both cases...
// TODO check what error codes we get here. SocketException(10108) iirc
ourAr.SetAsCompleted(IsInrange, completedSyncFalse);
}
}