本文整理汇总了C#中InTheHand.Net.Sockets.BluetoothClient类的典型用法代码示例。如果您正苦于以下问题:C# BluetoothClient类的具体用法?C# BluetoothClient怎么用?C# BluetoothClient使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
BluetoothClient类属于InTheHand.Net.Sockets命名空间,在下文中一共展示了BluetoothClient类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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;
}
}
开发者ID:donnaknew,项目名称:programmingProject,代码行数:32,代码来源:Bluetooth.cs
示例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.
}
开发者ID:ugurcicekfidan,项目名称:VisualStudioWorks,代码行数:7,代码来源:Arastirma.cs
示例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();
}
开发者ID:lucasmlima08,项目名称:ConnectionBluetoothDesktop,代码行数:26,代码来源:Server.cs
示例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();
}
}
}
开发者ID:CGHill,项目名称:Random-Projects,代码行数:33,代码来源:Form1.cs
示例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);
}
开发者ID:Deremius,项目名称:Uraban-Phase-Space,代码行数:27,代码来源:WinBluetoothConnection.cs
示例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);
}
}
开发者ID:EmilBechMadsen,项目名称:AEBM-ITU-PSCT-2013,代码行数:25,代码来源:BluetoothHandler.cs
示例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;
}
开发者ID:ArmyOfPirates,项目名称:PS3BluMote,代码行数:26,代码来源:BTUtils.cs
示例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);
}
}
}
}
开发者ID:sh932111,项目名称:BrainProject,代码行数:31,代码来源:BlueController.cs
示例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];
}
开发者ID:MarcFletcher,项目名称:NetworkComms.Net,代码行数:11,代码来源:BluetoothConnection.cs
示例10: Disconnect
public void Disconnect()
{
_client.Close();
_client = new BluetoothClient();
_readerThread = null;
_reader = null;
_writer = null;
}
开发者ID:Grodien,项目名称:HsluRobot,代码行数:9,代码来源:BluetoothConnector.cs
示例11: WinBluetoothConnection
public WinBluetoothConnection()
{
connectedDeviceInfo = null;
connection = new BluetoothClient();
bluetoothAddress = 0;
socketIsReadyToNewRecive = true;
socketIsReadyToNewSend = true;
}
开发者ID:Deremius,项目名称:Uraban-Phase-Space,代码行数:9,代码来源:WinBluetoothConnection.cs
示例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;
}
开发者ID:slodge,项目名称:BallControl,代码行数:9,代码来源:Singleton.cs
示例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);
}
}
开发者ID:tewarid,项目名称:NetTools,代码行数:11,代码来源:MainForm.cs
示例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();
}
开发者ID:mubold,项目名称:PebbleSharp,代码行数:12,代码来源:PebbleNet45.cs
示例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();
}
开发者ID:EmilBechMadsen,项目名称:AEBM-ITU-PSCT-2013,代码行数:12,代码来源:BluetoothHandler.cs
示例16: OpenAsync
public Task OpenAsync()
{
return Task.Run( () =>
{
_tokenSource = new CancellationTokenSource();
_client = new BluetoothClient();
_client.Connect( _deviceInfo.DeviceAddress, BluetoothService.SerialPort );
_networkStream = _client.GetStream();
Task.Factory.StartNew( CheckForData, _tokenSource.Token, TaskCreationOptions.LongRunning,
TaskScheduler.Default );
} );
}
开发者ID:mubold,项目名称:PebbleSharp,代码行数:12,代码来源:PebbleNet45.cs
示例17: 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;
}
开发者ID:pinkuyt,项目名称:a-pod-project-team-3,代码行数:13,代码来源:Bluetooth_Window.xaml.cs
示例18: IstemciDinleyici
public IstemciDinleyici(BluetoothClient istemci, AnaPencere pencere)
{
this.istemci = istemci;
this.anaPencere = pencere;
istemciAdi = this.istemci.RemoteMachineName;
istemciAdresi = ((BluetoothEndPoint)(this.istemci.Client.RemoteEndPoint)).Address; // :D
anaPencere.SunucuUyariGoster("Ýstemci baðlandý: " + istemciAdi);
istemciKanali = new Thread(new ThreadStart(Kanal));
istemciKanali.Start();
}
开发者ID:ugurcicekfidan,项目名称:VisualStudioWorks,代码行数:13,代码来源:IstemciDinleyici.cs
示例19: GetConnection
/// <summary>
/// Internal <see cref="BluetoothConnection"/> creation which hides the necessary internal calls
/// </summary>
/// <param name="connectionInfo">ConnectionInfo to be used to create connection</param>
/// <param name="defaultSendReceiveOptions">Connection default SendReceiveOptions</param>
/// <param name="btClient">If this is an incoming connection we will already have access to the btClient, otherwise use null</param>
/// <param name="establishIfRequired">Establish during create if true</param>
/// <returns>An existing connection or a new one</returns>
internal static BluetoothConnection GetConnection(ConnectionInfo connectionInfo, SendReceiveOptions defaultSendReceiveOptions, BluetoothClient btClient, bool establishIfRequired = true)
{
connectionInfo.ConnectionType = ConnectionType.Bluetooth;
//If we have a tcpClient at this stage we must be server side
if (btClient != null) connectionInfo.ServerSide = true;
bool newConnection = false;
BluetoothConnection connection;
lock (NetworkComms.globalDictAndDelegateLocker)
{
List<Connection> existingConnections = NetworkComms.GetExistingConnection(connectionInfo.RemoteEndPoint, connectionInfo.LocalEndPoint, connectionInfo.ConnectionType, connectionInfo.ApplicationLayerProtocol);
//Check to see if a connection already exists, if it does return that connection, if not return a new one
if (existingConnections.Count > 0)
{
if (NetworkComms.LoggingEnabled)
NetworkComms.Logger.Trace("Attempted to create new BluetoothConnection to connectionInfo='" + connectionInfo + "' but there is an existing connection. Existing connection will be returned instead.");
establishIfRequired = false;
connection = (BluetoothConnection)existingConnections[0];
}
else
{
if (NetworkComms.LoggingEnabled)
NetworkComms.Logger.Trace("Creating new BluetoothConnection to connectionInfo='" + connectionInfo + "'." + (establishIfRequired ? " Connection will be established." : " Connection will not be established."));
if (connectionInfo.ConnectionState == ConnectionState.Establishing)
throw new ConnectionSetupException("Connection state for connection " + connectionInfo + " is marked as establishing. This should only be the case here due to a bug.");
//If an existing connection does not exist but the info we are using suggests it should we need to reset the info
//so that it can be reused correctly. This case generally happens when using NetworkComms.Net in the format
//TCPConnection.GetConnection(info).SendObject(packetType, objToSend);
if (connectionInfo.ConnectionState == ConnectionState.Established || connectionInfo.ConnectionState == ConnectionState.Shutdown)
connectionInfo.ResetConnectionInfo();
//We add a reference to networkComms for this connection within the constructor
connection = new BluetoothConnection(connectionInfo, defaultSendReceiveOptions, btClient);
newConnection = true;
}
}
if (newConnection && establishIfRequired) connection.EstablishConnection();
else if (!newConnection) connection.WaitForConnectionEstablish(NetworkComms.ConnectionEstablishTimeoutMS);
if (!NetworkComms.commsShutdown) TriggerConnectionKeepAliveThread();
return connection;
}
开发者ID:MarcFletcher,项目名称:NetworkComms.Net,代码行数:59,代码来源:BluetoothConnectionStatic.cs
示例20: 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();
}
开发者ID:kakkr1,项目名称:ProjectOneLan,代码行数:51,代码来源:Program.cs
注:本文中的InTheHand.Net.Sockets.BluetoothClient类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论