public void Update(BluetoothDevice nativeDevice, BluetoothGatt gatt, IGattCallback gattCallback) { _nativeDevice = nativeDevice; _gatt = gatt; _gattCallback = gattCallback; }
public void OnLeScan(Android.Bluetooth.BluetoothDevice device, int rssi, byte[] scanRecord) { if (_devices.All(x => x.Address != device.Address)) { _devices.Add(ConvertDevice(device)); } }
public Device (BluetoothDevice nativeDevice, BluetoothGatt gatt, GattCallback gattCallback, int rssi) : base () { this._nativeDevice = nativeDevice; this._gatt = gatt; this._gattCallback = gattCallback; this._rssi = rssi; // when the services are discovered on the gatt callback, cache them here if (this._gattCallback != null) { this._gattCallback.ServicesDiscovered += (s, e) => { this._services = new List<IService> (); try{ var services = this._gatt.Services; foreach (var item in services) { this._services.Add (new Service (item, this._gatt, this._gattCallback)); } this.ServicesDiscovered (this, e); } catch { } }; } }
public Device (BluetoothDevice nativeDevice, BluetoothGatt gatt, GattCallback gattCallback, int rssi) : base () { this._nativeDevice = nativeDevice; this._gatt = gatt; this._gattCallback = gattCallback; this._rssi = rssi; // when the services are discovered on the gatt callback, cache them here if (this._gattCallback != null) { this._gattCallback.ServicesDiscovered += (s, e) => { var services = this._gatt.Services; this._services = new List<IService> (); foreach (var item in services) { this._services.Add (new Service (item, this._gatt, this._gattCallback)); foreach (var itm in item.Characteristics) { Console.WriteLine("Characteristic: " + itm.Uuid.ToString()); } } this.ServicesDiscovered (this, e); }; } }
public IBluetoothSocket Connect(RoomVoiceControl.Bluetooth.BluetoothDevice device) { IBluetoothSocket socket = null; Android.Bluetooth.BluetoothDevice bluetoothDevice = mBluetoothAdapter.GetRemoteDevice(device.Address); UserDialogs.Instance.Toast("Connecting to " + bluetoothDevice); try { btSocket = bluetoothDevice.CreateRfcommSocketToServiceRecord(UUID.FromString(MY_UUID)); btSocket.Connect(); socket = new AndroidBluetoothSocket() { BTSocket = btSocket }; UserDialogs.Instance.Toast("Connected to Bluetooth!"); } catch (System.Exception e) { Console.WriteLine(e.Message); try { btSocket.Close(); } catch (System.Exception) { UserDialogs.Instance.Alert("Connection Error!"); } } return(socket); }
public ConnectedSphero(BluetoothDevice bluetoothDevice, BluetoothSocket socket) : base(bluetoothDevice) { _spheroSocketWrapper = new StreamSocketWrapper(socket); _runner = new NonAwaitingConnectedSpheroRunner(_spheroSocketWrapper); _runner.Disconnected += (sender, args) => RaiseDisconnected(); _runner.Start(); }
public Device(BluetoothDevice nativeDevice, BluetoothGatt gatt, IGattCallback gattCallback, int rssi, byte[] advertisementData = null) : base() { Update(nativeDevice, gatt, gattCallback); this._rssi = rssi; _advertisementData = advertisementData ?? new byte[0]; }
internal Device (BluetoothDevice nativeDevice, BluetoothGatt gatt, GattCallback gattCallback, int rssi) : base () { this._nativeDevice = nativeDevice; _gatt = gatt; SetGattCallback(gattCallback); this._rssi = rssi; }
private Device ConvertDevice(Android.Bluetooth.BluetoothDevice device) { return(new Device { Address = device.Address, Name = device.Name, NativeDevice = device }); }
public void Update(BluetoothDevice nativeDevice, BluetoothGatt gatt, IGattCallback gattCallback) { _nativeDevice = nativeDevice; _gatt = gatt; _gattCallback = gattCallback; Id = ParseDeviceId(); Name = _nativeDevice.Name; }
public static Device Find(this IList<IDevice> list, BluetoothDevice device) { foreach (var d in list) { // TODO: verify that address is unique if (device.Address == ((BluetoothDevice)d.NativeDevice).Address) return d as Device; } return null; }
public static ButtonStroked CreateDeviceButton(BluetoothConnectionActivity activity, BluetoothDevice device, TetrisColor color, int minHeight, int defaultText) { if(device == null) { return CreateDeviceButton(activity, device, color, minHeight, activity.Resources.GetString(defaultText)); } return CreateDeviceButton(activity, device, color, minHeight, device.Name); }
public override void OnNotificationSent(BluetoothDevice device, GattStatus status) { base.OnNotificationSent(device, status); if (NotificationSent != null) { NotificationSent(this, new BleEventArgs() { Device = device }); } }
public void AddFriendDevice(BluetoothDevice device, string name) { if(device != null) { _friendsDevices.Add(device); } ButtonStroked friendsDeviceButton = UtilsUI.CreateDeviceButton(this, device, FriendsDeviceColor, (int)(_devicesLayout.Height*1f/NbDevicesDisplayed), name); LinearLayout.LayoutParams lp = UtilsUI.CreateDeviceLayoutParams(this, 5); _friendsDevicesLayout.AddView(friendsDeviceButton, lp); }
public override void OnCharacteristicWriteRequest(BluetoothDevice device, int requestId, BluetoothGattCharacteristic characteristic, bool preparedWrite, bool responseNeeded, int offset, byte[] value) { base.OnCharacteristicWriteRequest(device, requestId, characteristic, preparedWrite, responseNeeded, offset, value); if (CharacteristicWriteRequest != null) { CharacteristicWriteRequest(this, new BleEventArgs() { Device = device, Characteristic = characteristic, Value = value, RequestId = requestId, Offset = offset }); } }
public override void OnConnectionStateChange(BluetoothDevice device, ProfileState status, ProfileState newState) { var message = "Bluetooth Server connection state: {0} Device: " + device.Address; Debug.WriteLineIf(newState == ProfileState.Connected, string.Format(message, "Connected")); Debug.WriteLineIf(newState == ProfileState.Disconnected, string.Format(message, "Disconnected")); var handler = ConnectionStateChanged; if (handler != null) handler(device, status, newState); }
void Buttestprint_Click(object sender, EventArgs e) { mmDevice = null; findBTPrinter (); if (mmDevice != null) { string userid = ((GlobalvarsApp)this.Application).USERID_CODE; PrintInvHelper prnHelp = new PrintInvHelper (pathToDatabase, userid); string msg =prnHelp.OpenBTAndPrintTest(mmSocket, mmDevice); Toast.MakeText (this, msg, ToastLength.Long).Show (); } }
private static bool TrySetPin(Android.Bluetooth.BluetoothDevice device, string pin) { try { return(device.SetPin(PinToByteArray(pin))); } catch { return(false); } }
public override void OnCharacteristicReadRequest(BluetoothDevice device, int requestId, int offset, BluetoothGattCharacteristic characteristic) { base.OnCharacteristicReadRequest(device, requestId, offset, characteristic); Console.WriteLine("Read request from {0}", device.Name); if (CharacteristicReadRequest != null) { CharacteristicReadRequest(this, new BleEventArgs() { Device = device, Characteristic = characteristic, RequestId = requestId, Offset = offset }); } }
public void OnLeScan (BluetoothDevice device, int rssi, byte[] scanRecord) { if (scanRecord[8] == 141 && scanRecord[9] == 2) { var broodDevice = new BroodtoothDevice () { AdvertisementData = scanRecord, UUID = device.Address }; BroodSubject.OnNext (broodDevice); } }
private void openDeviceConnection(BluetoothDevice btDevice) { try { mSocket = btDevice.CreateRfcommSocketToServiceRecord(getUUIDFromString()); mSocket.Connect(); mStream = mSocket.InputStream; mReader = new InputStreamReader(mStream); } catch (IOException e) { throw e; } }
public bool StartPrint(string text,int noofcopy,ref string errmsg) { bool isPrinted = false; mBluetoothAdapter=null; mmSocket=null; mmDevice = null; FindBTPrinter (); if (mmDevice != null) { isPrinted =PrintToDevice (text, noofcopy); } errmsg = msg; return isPrinted; }
/// <summary> /// Initializes a new instance of the <see cref="BluetoothLE.Droid.Device"/> class. /// </summary> /// <param name="nativeDevice">Native device.</param> /// <param name="gatt">Native Gatt.</param> /// <param name="callback">Callback.</param> /// <param name="rssi">Rssi.</param> /// <param name="scanRecord">scanRecord.</param> public Device(BluetoothDevice nativeDevice, BluetoothGatt gatt, GattCallback callback, int rssi, byte[] scanRecord) { _nativeDevice = nativeDevice; _gatt = gatt; _callback = callback; _scanRecord = scanRecord; _rssi = rssi; _id = DeviceIdFromAddress(_nativeDevice.Address); if (_callback != null) { _callback.ServicesDiscovered += ServicesDiscovered; } Services = new List<IService>(); }
//private static final String TAG = "SBeaconParser"; public override Beacon FromScanData(byte[] scanData, int rssi, Android.Bluetooth.BluetoothDevice device, long timestampMs) { int startByte = 2; while (startByte <= 5) { // "m:2-3=0203,i:2-2,i:7-8,i:14-19,d:10-13,p:9-9" if (((int)scanData[startByte + 3] & 0xff) == 0x03 && ((int)scanData[startByte + 4] & 0xff) == 0x15) { //BeaconManager.logDebug(TAG, "This is a SBeacon beacon advertisement"); // startByte+0 company id (2 bytes) // startByte+2 = 02 (1) byte header // startByte+3 = 0315 (2 bytes) header // startByte+5 = Beacon Type 0x01 // startByte+6 = Reserved (1 bytes) // startByte+7 = Security Code (2 bytes) => Major little endian // startByte+9 = Tx Power => Tx Power // startByte+10 = Timestamp (4 bytes) => Minor (2 LSBs) little endian // startByte+14 = Beacon ID (6 bytes) -> UUID little endian int grouping = (scanData[startByte + 8] & 0xff) * 0x100 + (scanData[startByte + 7] & 0xff); int clock = (scanData[startByte + 13] & 0xff) * 0x1000000 + (scanData[startByte + 12] & 0xff) * 0x10000 + (scanData[startByte + 11] & 0xff) * 0x100 + (scanData[startByte + 10] & 0xff); int txPower = (int)(sbyte)scanData[startByte + 9]; // this one is signed byte[] beaconId = new byte[6]; //Java.Lang.JavaSystem.Arraycopy(scanData, startByte+14, beaconId, 0, 6); Array.Copy(scanData, startByte + 14, beaconId, 0, 6); String hexString = BytesToHex(beaconId); StringBuilder sb = new StringBuilder(); sb.Append(hexString.Substring(0, 12)); String id = "0x" + sb.ToString(); int beaconTypeCode = (scanData[startByte + 3] & 0xff) * 0x100 + (scanData[startByte + 2] & 0xff); String mac = null; if (device != null) { mac = device.Address; } Beacon beacon = new SBeacon(grouping, id, clock, txPower, rssi, beaconTypeCode, mac); return(beacon); } startByte++; } return(null); }
//-------------------------------------------------------------- // CONSTRUCTORS //-------------------------------------------------------------- public ConnectThread(BluetoothDevice device, BluetoothManager service) { _device = device; _service = service; BluetoothSocket tmp = null; // Get a BluetoothSocket for a connection with the // given BluetoothDevice try { tmp = device.CreateRfcommSocketToServiceRecord(BluetoothManager.MyUUID); } catch(Java.IO.IOException e) { Log.Error(BluetoothManager.Tag, "create() failed", e); } _socket = tmp; }
private void ScanCallback_ScanResultEvent(BluetoothDevice device, int rssi, ScanRecord record) { // 同じアイテムならListに追加しない。 if (bleDevices.Count == 0) bleDevices.Add(new BleDeviceData { Name = device.Name, Id = device.Address }); else { foreach (var item in bleDevices) { if (!item.Id.Contains(device.Address)) bleDevices.Add(new BleDeviceData { Name = device.Name ?? "Unknown", Id = device.Address }); } } // MainThreadで処理する。 RunOnUiThread(() => { listView.Adapter = new SimpleListItem2_Adapter(this, bleDevices); }); }
public void connected(BluetoothSocket socket, BluetoothDevice device, String socketType) { lock (mutex) { if (_connectThread != null) { _connectThread.cancel (); _connectThread = null; } if (_connectedThread != null) { _connectedThread.cancel (); _connectedThread = null; } if (_secureAcceptThread != null) { _secureAcceptThread.cancel (); _secureAcceptThread = null; } if (_insecureAcceptThread != null) { _insecureAcceptThread.cancel (); _insecureAcceptThread = null; } _connectedThread = new ConnectedThread (socket, socketType); //_connectThread.start (); Message msg = _handler.ObtainMessage (Utility.MESSAGE_DEVICE_NAME); Bundle bundle = new Bundle (); bundle.PutString (Utility.DEVICE_NAME, device.Name); msg.Data = bundle; _handler.SendMessage (msg); setState (STATE_CONNECTED); } }
public static ButtonStroked CreateDeviceButton(BluetoothConnectionActivity activity, BluetoothDevice device, TetrisColor color, int minHeight, string text) { ButtonStroked button = new ButtonStroked(activity); button.Settings = DeviceButtonUI.Clone(); button.Settings.StrokeColor = Utils.getAndroidColor(color, button.Settings.StrokeShade); button.Settings.FillColor = Utils.getAndroidColor(color, button.Settings.FillShade); button.SetMinimumHeight(minHeight); int padding = Utils.GetPixelsFromDP(activity, button.Settings.Padding); button.SetPadding(padding, padding, padding, padding); button.Text = text; if(device != null) { button.Tag = device.Address; button.Click += delegate { activity.DeviceListClick(button); }; } else { button.Enabled = false; } return button; }
public void connect(BluetoothDevice device, bool secure) { lock (mutex) { if (_state == STATE_CONNECTING) { if (_connectThread != null) { _connectThread.cancel (); _connectThread = null; } } if (_connectedThread != null) { _connectedThread.cancel (); _connectedThread = null; } _connectThread = new ConnectThread (device, secure); //_connectThread.Start (); setState (STATE_CONNECTING); } }
public override void OnCharacteristicWriteRequest(BluetoothDevice device, int requestId, BluetoothGattCharacteristic characteristic, bool preparedWrite, bool responseNeeded, int offset, byte[] value) { var handler = CharasteristicWriteRequested; if (handler != null) handler(device, requestId, characteristic, preparedWrite, responseNeeded, offset, value); }
public void AddDevice (BluetoothDevice device) { if (!mLeDevices.Contains (device)) { mLeDevices.Add (device); } }
// Device scan callback. public void OnLeScan (BluetoothDevice device, int rssi, byte[] scanRecord) { RunOnUiThread (new Action (delegate { mLeDeviceListAdapter.AddDevice (device); mLeDeviceListAdapter.NotifyDataSetChanged(); })); }
/// <summary> /// Initializes a new instance of the <see cref="BluetoothDevice"/> class. /// </summary> /// <param name="device">The Android Bluetooth Device.</param> public BluetoothDevice(Android.Bluetooth.BluetoothDevice device) { m_device = device ?? throw new ArgumentNullException(nameof(device)); }
internal BluetoothDevice(ABluetooth.BluetoothDevice device) { _device = device; }
public ConnectThread(BluetoothChatService chatService, BluetoothDevice device, bool secure) { this.chatService = chatService; mmDevice = device; BluetoothSocket tmp = null; mSocketType = secure ? "Secure" : "Insecure"; // Get a BluetoothSocket for a connection with the // given BluetoothDevice try { if (secure) { tmp = device.CreateRfcommSocketToServiceRecord(MY_UUID_SECURE); } else { tmp = device.CreateInsecureRfcommSocketToServiceRecord(MY_UUID_INSECURE); } } catch (IOException e) { Log.E(TAG, "Socket Type: " + mSocketType + "create() failed", e); } mmSocket = tmp; }
/// <summary> /// Initializes a new instance of the <see cref="BluetoothDevice"/> class. /// </summary> /// <param name="device">The Android Bluetooth Device.</param> public BluetoothDevice(Android.Bluetooth.BluetoothDevice device) { m_device = device; }
internal BluetoothRemoteGATTServer(BluetoothDevice device, ABluetooth.BluetoothDevice bluetoothDevice) : this(device) { _gattCallback = new GattCallback(this); NativeGatt = bluetoothDevice.ConnectGatt(Android.App.Application.Context, false, _gattCallback); }
private DeviceInformation(Android.Bluetooth.BluetoothDevice device) { _device = device; }
private BluetoothLEDevice(Android.Bluetooth.BluetoothDevice device) { _device = device; }
/// <summary> /// Initializes a new instance of the <see cref="BluetoothDevice"/> class. /// </summary> /// <param name="device">The Android Bluetooth Device.</param> /// <param name="parser">Parser used for incoming messages</param> public BluetoothDevice(IIncomingMessageParser parser, Android.Bluetooth.BluetoothDevice device) : base(parser) { m_device = device; }
public BluetoothDevice(Android.Bluetooth.BluetoothDevice device) { PlatformDevice = device; }
/// <summary> /// Start the ConnectedThread to begin managing a Bluetooth connection </summary> /// <param name="socket"> The BluetoothSocket on which the connection was made </param> /// <param name="device"> The BluetoothDevice that has been connected </param> public void Connected(BluetoothSocket socket, BluetoothDevice device, string socketType) { lock (this) { if (D) { Log.D(TAG, "connected, Socket Type:" + socketType); } // Cancel the thread that completed the connection if (mConnectThread != null) { mConnectThread.Cancel(); mConnectThread = null; } // Cancel any thread currently running a connection if (mConnectedThread != null) { mConnectedThread.Cancel(); mConnectedThread = null; } // Cancel the accept thread because we only want to connect to one device if (mSecureAcceptThread != null) { mSecureAcceptThread.Cancel(); mSecureAcceptThread = null; } if (mInsecureAcceptThread != null) { mInsecureAcceptThread.Cancel(); mInsecureAcceptThread = null; } // Start the thread to manage the connection and perform transmissions mConnectedThread = new ConnectedThread(this, socket, socketType); mConnectedThread.Start(); // Send the name of the connected device back to the UI Activity Message msg = mHandler.ObtainMessage(global::BluetoothChat.BluetoothChat.MESSAGE_DEVICE_NAME); Bundle bundle = new Bundle(); bundle.PutString(global::BluetoothChat.BluetoothChat.DEVICE_NAME, device.GetName()); msg.SetData(bundle); mHandler.SendMessage(msg); State = STATE_CONNECTED; } }
public async Task<bool> Init(bool simulatormode = false) { running = true; //initialize _data data = new Dictionary<string, string> {{"vin", DefValue}}; //VIN piDs = ObdShare.ObdUtil.GetPIDs(); foreach (var v in piDs.Values) { data.Add(v, DefValue); } this.simulatormode = simulatormode; if (simulatormode) { return true; } bluetoothAdapter = BluetoothAdapter.DefaultAdapter; if (bluetoothAdapter == null) { System.Diagnostics.Debug.WriteLine("Bluetooth is not available"); return false; } try { var ba = bluetoothAdapter.BondedDevices; foreach (var bd in ba) { if (bd.Name.ToLower().Contains("obd")) bluetoothDevice = bd; } if (bluetoothDevice == null) { return false; } bluetoothSocket = bluetoothDevice.CreateRfcommSocketToServiceRecord(SppUuid); await bluetoothSocket.ConnectAsync(); connected = true; } catch (Java.IO.IOException) { // Close the socket try { connected = false; bluetoothSocket.Close(); } catch (Java.IO.IOException) { } catch (Exception) { } return false; } catch (Exception) { } if (connected) { reader = bluetoothSocket.InputStream; writer = bluetoothSocket.OutputStream; string s; s = await SendAndReceive("ATZ\r"); s = await SendAndReceive("ATE0\r"); s = await SendAndReceive("ATL1\r"); s = await SendAndReceive("ATSP00\r"); PollObd(); return true; } else return false; }
private BluetoothDevice(ABluetooth.BluetoothDevice device) { _device = device; }