本文整理汇总了C#中InTheHand.Net.Sockets.BluetoothClient.DiscoverDevices方法的典型用法代码示例。如果您正苦于以下问题:C# BluetoothClient.DiscoverDevices方法的具体用法?C# BluetoothClient.DiscoverDevices怎么用?C# BluetoothClient.DiscoverDevices使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类InTheHand.Net.Sockets.BluetoothClient
的用法示例。
在下文中一共展示了BluetoothClient.DiscoverDevices方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: MakeConnection
public static void MakeConnection(BluetoothAddress btAddress)
{
var serviceClass = BluetoothService.SerialPort;
if (_cli != null)
{
_cli.Close();
}
_cli = new BluetoothClient();
var bluetoothDeviceInfos = _cli.DiscoverDevices();
var deviceInfos = bluetoothDeviceInfos.ToList();
BluetoothDeviceInfo device = null;
foreach (var bluetoothDeviceInfo in deviceInfos)
{
var scannedDeviceAddress = bluetoothDeviceInfo.DeviceAddress;
if (scannedDeviceAddress == btAddress)
{
device = bluetoothDeviceInfo;
}
}
if (device == null)
{
return;
}
var ep = new BluetoothEndPoint(device.DeviceAddress, serviceClass);
try
{
if (!device.Connected)
{
_cli.Connect(ep);
}
}
catch(System.Net.Sockets.SocketException e)
{
_cli.Close();
_isConnected = false;
return;
}
_isConnected = true;
}
示例2: search
private void search()
{
try
{
Guid uuid = BluetoothService.L2CapProtocol;
BluetoothDeviceInfo bdi;
BluetoothAddress ba;
byte tmp;
bool found = false;
int discarded;
bc = new BluetoothClient();
bc.InquiryLength = new TimeSpan(0, 0, 0, Int32.Parse(osae.GetObjectPropertyValue(pName, "Discover Length").Value), 0);
nearosaeDevices = bc.DiscoverDevices(10, false, false, true);
for (int j = 0; j < nearosaeDevices.Length; j++)
{
string addr = nearosaeDevices[j].DeviceAddress.ToString();
Object obj = osae.GetObjectByAddress(addr);
if (obj == null)
{
if (osae.GetObjectPropertyValue(pName, "Learning Mode").Value == "TRUE")
{
osae.ObjectAdd(nearosaeDevices[j].DeviceName, nearosaeDevices[j].DeviceName, "BLUETOOTH DEVICE", nearosaeDevices[j].DeviceAddress.ToString(), "", true);
osae.ObjectPropertySet(nearosaeDevices[j].DeviceName, "Discover Type", "0");
logging.AddToLog(addr + " - " + nearosaeDevices[j].DeviceName + ": added to OSA", true);
}
}
}
List<OSAEObject> objects = osae.GetObjectsByType("BLUETOOTH DEVICE");
foreach (OSAEObject obj in objects)
{
found = false;
string address = obj.Address;
byte[] byteArray = HexEncoding.GetBytes(address, out discarded);
tmp = byteArray[0];
byteArray[0] = byteArray[5];
byteArray[5] = tmp;
tmp = byteArray[1];
byteArray[1] = byteArray[4];
byteArray[4] = tmp;
tmp = byteArray[2];
byteArray[2] = byteArray[3];
byteArray[3] = tmp;
ba = new BluetoothAddress(byteArray);
bdi = new BluetoothDeviceInfo(ba);
logging.AddToLog("begin search for " + address, false);
for (int j = 0; j < nearosaeDevices.Length; j++)
{
if (nearosaeDevices[j].DeviceAddress.ToString() == address)
{
found = true;
logging.AddToLog(address + " - " + obj.Name + ": found with DiscoverDevices", false);
}
}
if (!found)
{
logging.AddToLog(address + " - " + obj.Name + ": failed with DiscoverDevices", false);
}
try
{
if (!found && (Int32.Parse(osae.GetObjectPropertyValue(obj.Name, "Discover Type").Value) == 2 || Int32.Parse(osae.GetObjectPropertyValue(obj.Name, "Discover Type").Value) == 0))
{
logging.AddToLog(address + " - " + obj.Name + ": attempting GetServiceRecords", false);
bdi.GetServiceRecords(uuid);
found = true;
logging.AddToLog(address + " - " + obj.Name + " found with GetServiceRecords", false);
}
}
catch (Exception ex)
{
logging.AddToLog(address + " - " + obj.Name + " failed GetServiceRecords. exception: " + ex.Message, false);
}
try
{
if (!found && (Int32.Parse(osae.GetObjectPropertyValue(obj.Name, "Discover Type").Value) == 3 || Int32.Parse(osae.GetObjectPropertyValue(obj.Name, "Discover Type").Value) == 0))
{
logging.AddToLog(address + " - " + obj.Name + ": attempting Connection", false);
//attempt a connect
BluetoothEndPoint ep;
ep = new BluetoothEndPoint(bdi.DeviceAddress, BluetoothService.Handsfree);
//MessageBox.Show("attempt connect: " + pairedDevices[i].DeviceAddress);
bc.Connect(ep);
logging.AddToLog(address + " - " + obj.Name + " found with Connect attempt", false);
bc.Close();
found = true;
}
}
//.........这里部分代码省略.........
示例3: GetNearbyRemoteAddresses
public static List<string> GetNearbyRemoteAddresses(TimeSpan timeout)
{
List<string> result = new List<string>();
try
{
BluetoothClient cli = new BluetoothClient();
if (timeout != TimeSpan.Zero) cli.InquiryLength = timeout;
BluetoothDeviceInfo[] devs = cli.DiscoverDevices();
foreach (BluetoothDeviceInfo dev in devs)
{
if (dev.DeviceName.ToLower().Contains("bd remote control"))
{
if (RemoteBtState(null, dev) == RemoteBtStates.Awake)
{
string candidate = FormatBtAddress(null, dev.DeviceAddress, "N");
if (!result.Contains(candidate)) result.Add(candidate);
}
}
}
}
catch
{
DebugLog.write("BTUtils.GetNearbyRemoteAddresses Failed");
}
return result;
}
示例4: findBluetoothTolist
public void findBluetoothTolist()
{
BluetoothRadio.PrimaryRadio.Mode = RadioMode.Discoverable;
BluetoothClient bluetoothClient = new BluetoothClient();
BluetoothDeviceInfo[] bluetoothDeviceInfo = bluetoothClient.DiscoverDevices(10);
ArrayList deviceCollection = new ArrayList();
foreach (BluetoothDeviceInfo device_info in bluetoothDeviceInfo)
{
string device_name = device_info.DeviceName;
string device_address = device_info.DeviceAddress.ToString();
BluetoothDeviceManager manager = new BluetoothDeviceManager(device_name,device_address);
deviceCollection.Add(manager);
}
System.Management.ManagementObjectSearcher Searcher = new System.Management.ManagementObjectSearcher("Select * from WIN32_SerialPort");
foreach (System.Management.ManagementObject Port in Searcher.Get())
{
string PNPDeviceID = Port.GetPropertyValue("PNPDeviceID").ToString();
string DeviceID = Port.GetPropertyValue("DeviceID").ToString();
for (int i = 0; i < deviceCollection.Count; i++)
{
BluetoothDeviceManager manager = (BluetoothDeviceManager)deviceCollection[i];
string device_address = manager.getDeviceAddress();
int index = PNPDeviceID.IndexOf(device_address);
if (index > 0)
{
manager.addCOM(DeviceID);
bluetoothList.Add(manager);
}
}
}
}
示例5: GetAvailableSpheroNames
public string[] GetAvailableSpheroNames()
{
Reset();
_client = new BluetoothClient();
_peers = _client.DiscoverDevices();
var spheros = _peers.Where(x => x.DeviceName.StartsWith("Sphero")).Select(x => x.DeviceName).ToArray();
return spheros;
}
示例6: Initialize
private void Initialize()
{
client = new BluetoothClient();
devices = client.DiscoverDevices(10, true, true, false);
deviceList.Items.Clear();
foreach (BluetoothDeviceInfo device in devices)
{
deviceList.Items.Add(device.DeviceName);
}
}
示例7: DetectPebbles
public static IList<Pebble> DetectPebbles()
{
var client = new BluetoothClient();
// A list of all BT devices that are paired, in range, and named "Pebble *"
var bluetoothDevices = client.DiscoverDevices( 20, true, false, false ).
Where( bdi => bdi.DeviceName.StartsWith( "Pebble " ) ).ToList();
return ( from device in bluetoothDevices
select (Pebble)new PebbleNet45( new PebbleBluetoothConnection( device ),
device.DeviceName.Substring( 7 ) ) ).ToList();
}
示例8: bg_DoWork
private void bg_DoWork(object sender, DoWorkEventArgs e)
{
List<Device> devices = new List<Device>();
InTheHand.Net.Sockets.BluetoothClient bc = new InTheHand.Net.Sockets.BluetoothClient();
InTheHand.Net.Sockets.BluetoothDeviceInfo[] array = bc.DiscoverDevices();
int count = array.Length;
for (int i = 0; i < count; i++)
{
Device device = new Device(array[i]);
devices.Add(device);
}
e.Result = devices;
}
示例9: Main
static void Main(string[] args)
{
//Runs Method
InitDeviceList();
//Drops known user table
sqlClient.Drop("tblknown");
//Creates known user table
sqlClient.Create("tblknown", "id int NOT NULL AUTO_INCREMENT, name varchar(255),counting int NOT NULL ,address int,PRIMARY KEY (id)");
BluetoothClient bc = new BluetoothClient();
BluetoothDeviceInfo[] devices = bc.DiscoverDevices();
string a = "dadasd";
int number = 0;
if (devices.Length == 0)
{
Console.WriteLine("Empty set");
}
else
for (int i = 0; i < devices.Length; i++)
{
a = number + ") " + devices[i].DeviceName + "/" + "Address: " + devices[i].DeviceAddress + "\r\n";
for (int j = 0; j < userDevices.Count; j++)
{
if (devices[i].DeviceAddress.ToString() == userDevices[j].Address)
{
//convert list items to string
string username = (userDevices[j].UserName.ToString().ToUpper());
string address = (userDevices[j].Address.ToString().ToUpper());
//adds '' to string,so sql can accept as a char
string knownuser = "'" + username.Replace(",", "','") + "'";
string knownaddress = "'" + address.Replace(",", "','") + "'";
// listBox1.Items.Add(userDevices[j].UserName);
sqlClient.Insert("tblknown", "name", knownuser);
sqlClient.Update("tblknown", "counting =counting+1", "id=1");
}
}
number++;
Console.WriteLine(a);
}
Console.ReadLine();
}
示例10: GetDevicesinRange
//private static BlueToothWorker _worker = new BlueToothWorker();
public static string[] GetDevicesinRange()
{
var result = new List<string>();
var cli = new InTheHand.Net.Sockets.BluetoothClient();
//cli.BeginDiscoverDevices(10, true, true, false, false, DeviceDiscovered, null);
var peers = cli.DiscoverDevices();
foreach (var device in peers)
{
result.Add(device.DeviceName);
}
return result.ToArray();
}
示例11: deviceIsRuning
public bool? deviceIsRuning()
{
bool? result = null;
try
{
BluetoothClient searcher = new BluetoothClient();
searcher.DiscoverDevices();
return true;
}
catch (Exception ex)
{
result = false;
}
return result;
}
示例12: button1_Click
private void button1_Click(object sender, EventArgs e)
{
this.listBox1.Items.Clear();
this.label2.Text = "Searching... please wait";
this.label2.Update();
try
{
BluetoothRadio.PrimaryRadio.Mode = RadioMode.Connectable;
BluetoothClient btc = new BluetoothClient();
devices = btc.DiscoverDevices(60, false, true, true);
for (int i = 0; (i < devices.Length); i++)
{
//if the device is a wocket
if (((devices[i].DeviceName.IndexOf("Wocket") >= 0)
|| (devices[i].DeviceName.IndexOf("WKT") >= 0)
|| (devices[i].DeviceName.IndexOf("FireFly") >= 0)
|| (devices[i].DeviceName.IndexOf("0006660") >= 0)
&& (wocketCount < 100)))
{
string hex = "";
hex = devices[i].DeviceAddress.ToString();
#region Commented
// if (this.WocketsList_Box.Items.IndexOf(hex) < 0)
//{
// this.WocketsList_Box.Items.Add(devices[i].DeviceName + " (" + hex + ")");
//macaddresses.Add(hex);
//}
#endregion Commented
this.listBox1.Items.Add(hex);
bluetoothlist.Add(hex, devices[i]);
wocketCount++;
}
}
btc.Dispose();
btc.Close();
}
catch
{
MessageBox.Show("Cannot connect: please check your Bluetooth radio is plugged in and active");
Environment.Exit(0);
}
}
示例13: DoFind
private async void DoFind(Action<IList<IAvailableSphero>> onSuccess, Action<Exception> onError)
{
try
{
// what?!
var client = new BluetoothClient();
var peers = client.DiscoverDevices();
var spheroPeers = peers
.Where(x => x.DeviceName.StartsWith("Sphero"))
.Select(x => new AvailableSphero(x))
.ToArray();
onSuccess(spheroPeers);
}
catch (Exception exception)
{
onError(exception);
}
}
示例14: GetDevices
/// <summary>
/// Gets the devices.
/// </summary>
/// <returns>The list of the devices.</returns>
public async Task<IList<Device>> GetDevices()
{
// for not block the UI it will run in a different threat
var task = Task.Run(() =>
{
var devices = new List<Device>();
using (var bluetoothClient = new BluetoothClient())
{
var array = bluetoothClient.DiscoverDevices();
var count = array.Length;
for (var i = 0; i < count; i++)
{
devices.Add(new Device(array[i]));
}
}
return devices;
});
return await task;
}
示例15: DetectPebbles
/// <summary>
/// Detect all Pebble bluetooth connections that have been paired with this system.
/// </summary>
/// <returns></returns>
public static List<Flint.Core.Pebble> DetectPebbles()
{
var client = new BluetoothClient();
// A list of all BT devices that are paired, in range, and named "Pebble *"
var bluetoothDevices = client.DiscoverDevices(20, true, false, false).
Where(bdi => bdi.DeviceName.StartsWith("Pebble "));
// A list of all available serial ports with some metadata including the PnP device ID,
// which in turn contains a BT device address we can search for.
var portListCollection = (new ManagementObjectSearcher("SELECT * FROM Win32_SerialPort")).Get();
var portList = new ManagementBaseObject[portListCollection.Count];
portListCollection.CopyTo(portList, 0);
return (from device in bluetoothDevices
from port in portList
where ((string)port["PNPDeviceID"]).Contains(device.DeviceAddress.ToString())
select new Flint.Core.Pebble(new PebbleBluetoothConnection((string)port["DeviceID"]), device.DeviceName.Substring(7))).ToList();
}