本文整理汇总了C#中InTheHand.Net.Sockets.BluetoothClient类的典型用法代码示例。如果您正苦于以下问题:C# BluetoothClient类的具体用法?C# BluetoothClient怎么用?C# BluetoothClient使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
BluetoothClient类属于InTheHand.Net.Sockets命名空间,在下文中一共展示了BluetoothClient类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: connectToDeviceWithoutPairing
/// <summary>
/// Attempt to connect to the BluetoothDevice, without trying to pair first.
/// </summary>
/// <param name="device"></param>
/// <returns></returns>
public static async Task<Boolean> connectToDeviceWithoutPairing(BluetoothDevice device) {
BluetoothEndPoint endPoint = new BluetoothEndPoint(device.btDeviceInfo.DeviceAddress, BluetoothService.SerialPort);
BluetoothClient client = new BluetoothClient();
if (!device.Authenticated) {
return false;
}
else {
try {
client.Connect(endPoint);
if (devicesStreams.Keys.Contains(device)) {
devicesStreams.Remove(device);
}
devicesStreams.Add(device, client.GetStream());
if (devicesClients.Keys.Contains(device)) {
devicesClients.Remove(device);
}
devicesClients.Add(device, client);
}
catch (Exception ex) {
//System.Console.Write("Could not connect to device: " + device.DeviceName + " " + device.DeviceAddress);
return false;
}
return true;
}
}
示例2: Arastirma
public Arastirma(AnaPencere pencere)
{
anaPencere = pencere;
localAygit = new BluetoothClient(); // Local bluetooth aygýtýna eriþiyoruz.
aramaKanali = new Thread(new ThreadStart(AygitArama)); // Araþtýrma için iþ parçasý oluþtur.
aramaKanali.Start(); // Ýþ parçasýný baþlat.
}
示例3: readInfoClient
public void readInfoClient()
{
bluetoothClient = bluetoothListener.AcceptBluetoothClient();
Console.WriteLine("Cliente Conectado!");
Stream stream = bluetoothClient.GetStream();
while (bluetoothClient.Connected)
{
try
{
byte[] byteReceived = new byte[1024];
int read = stream.Read(byteReceived, 0, byteReceived.Length);
if (read > 0)
{
Console.WriteLine("Messagem Recebida: " + Encoding.ASCII.GetString(byteReceived) + System.Environment.NewLine);
}
stream.Flush();
}
catch (Exception e)
{
Console.WriteLine("Erro: " + e.ToString());
}
}
stream.Close();
}
示例4: ServerConnectThread
public void ServerConnectThread()
{
updateUI("Server started, waiting for client");
bluetoothListener = new BluetoothListener(mUUID);
bluetoothListener.Start();
conn = bluetoothListener.AcceptBluetoothClient();
updateUI("Client has connected");
connected = true;
//Stream mStream = conn.GetStream();
mStream = conn.GetStream();
while (connected)
{
try
{
byte[] received = new byte[1024];
mStream.Read(received, 0, received.Length);
string receivedString = Encoding.ASCII.GetString(received);
//updateUI("Received: " + receivedString);
handleBluetoothInput(receivedString);
//byte[] send = Encoding.ASCII.GetBytes("Hello world");
//mStream.Write(send, 0, send.Length);
}
catch (IOException e)
{
connected = false;
updateUI("Client disconnected");
disconnectBluetooth();
}
}
}
示例5: connect
public override void connect ()
{
if (connection == null)
{
connection = new BluetoothClient();
}
if (connection.Connected)
{
throw new Exception("Connection is already opened");
}
connection.Connect (new BluetoothAddress(bluetoothAddress), OtherData.upsBluetoothGuid);
connectedDeviceInfo = new BluetoothDeviceInfo(connection.RemoteEndPoint.Address);
bluetoothAddress = connection.RemoteEndPoint.Address.ToInt64();
socket = connection.Client;
socketReciveOperation = new SocketAsyncEventArgs();
socketReciveOperation.UserToken = socket;
socketReciveOperation.RemoteEndPoint = socket.RemoteEndPoint;
socketReciveOperation.Completed += new EventHandler<SocketAsyncEventArgs>(onReciveComplete);
socketSendOperation = new SocketAsyncEventArgs();
socketSendOperation.UserToken = socket;
socketSendOperation.RemoteEndPoint = socket.RemoteEndPoint;
socketSendOperation.Completed += new EventHandler<SocketAsyncEventArgs>(onSendComplete);
WinBluetoothFactory.getFactory().addConnectedDevice(this);
}
示例6: GetImages
public static void GetImages(BluetoothEndPoint endpoint, Color tagColor)
{
InTheHand.Net.Sockets.BluetoothClient btc = new InTheHand.Net.Sockets.BluetoothClient();
btc.Connect(endpoint);
var nws = btc.GetStream();
byte[] emptySize = BitConverter.GetBytes(0); //
if (BitConverter.IsLittleEndian) Array.Reverse(emptySize); // redundant but usefull in case the number changes later..
nws.Write(emptySize, 0, emptySize.Length); // write image size
int imgCount = GetImgSize(nws);
nws = btc.GetStream();
for (int i = 0; i < imgCount; i++)
{
MemoryStream ms = new MemoryStream();
int size = GetImgSize(nws);
if (size == 0) continue;
byte[] buffer = new byte[size];
int read = 0;
while ((read = nws.Read(buffer, 0, buffer.Length)) != 0)
{
ms.Write(buffer, 0, read);
}
SurfaceWindow1.AddImage(System.Drawing.Image.FromStream(ms), tagColor);
}
}
示例7: 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;
}
示例8: 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);
}
}
}
}
示例9: BluetoothConnection
/// <summary>
/// Bluetooth connection constructor
/// </summary>
private BluetoothConnection(ConnectionInfo connectionInfo, SendReceiveOptions defaultSendReceiveOptions, BluetoothClient btClient)
: base(connectionInfo, defaultSendReceiveOptions)
{
if (btClient != null)
this.btClient = btClient;
dataBuffer = new byte[NetworkComms.InitialReceiveBufferSizeBytes];
}
示例10: Disconnect
public void Disconnect()
{
_client.Close();
_client = new BluetoothClient();
_readerThread = null;
_reader = null;
_writer = null;
}
示例11: WinBluetoothConnection
public WinBluetoothConnection()
{
connectedDeviceInfo = null;
connection = new BluetoothClient();
bluetoothAddress = 0;
socketIsReadyToNewRecive = true;
socketIsReadyToNewSend = true;
}
示例12: 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;
}
示例13: 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);
}
}
示例14: 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();
}
示例15: SendBluetooth
public static void SendBluetooth(BluetoothEndPoint endpoint, BitmapSource bms)
{
InTheHand.Net.Sockets.BluetoothClient btc = new InTheHand.Net.Sockets.BluetoothClient();
btc.Connect(endpoint);
byte[] img = BmSourceToByteArr(bms);
var nws = btc.GetStream();
byte[] imgSize = BitConverter.GetBytes(img.Length);
if (BitConverter.IsLittleEndian) Array.Reverse(imgSize);
nws.Write(imgSize, 0, imgSize.Length); // write image size
nws.Write(img, 0, img.Length); // Write image
nws.Flush();
}