public LightPage(TelitDevice device) { InitializeComponent(); _viewModel = new LightViewModel(); BindingContext = _viewModel; _device = device; }
public async Task <bool> Connect(TelitDevice device) { bool isSuccess = false; try { var light = LightPeripherals?.FirstOrDefault(x => x.Name == device.Name && x.Address == device.Address); if (light != null) { CancellationTokenSource tokenSource = new CancellationTokenSource(); Action <bool> status = (isConnected) => { isSuccess = isConnected; tokenSource.Cancel(); }; TIOConnectionCallback callback = new TIOConnectionCallback(status); var connection = light.Connect(callback); await Task.Delay(20000, tokenSource.Token); } } catch { } return(isSuccess); }
public void SendData(byte[] buffer, TelitDevice device) { try { var light = LightPeripherals?.FirstOrDefault(x => x.Name == device.Name && x.Address == device.Address); if (light != null) { var connection = light.Connection; if (connection != null && buffer != null && buffer.Length > 0) { connection.Transmit(buffer); //connection.Dispose(); } } } catch { } }
public void OnPeripheralUpdate(ITIOPeripheral peripheral) { var lightExists = TelitServiceAndroid.LightPeripherals? .FirstOrDefault(x => x.Name == peripheral.Name && x.Address == peripheral.Address); if (lightExists == null) { TelitServiceAndroid.LightPeripherals.Add(peripheral); } //Application.Current.MainPage.DisplayAlert("", "Device updated", "Ok"); TelitDevice device = new TelitDevice { Name = peripheral.Name, Address = peripheral.Address }; _onDevicesFound?.Invoke(device); }
//[Register("STATE_CONNECTED")] //public const int StateConnected = 2; //[Register("STATE_CONNECTING")] //public const int StateConnecting = 1; //[Register("STATE_DISCONNECTED")] //public const int StateDisconnected = 0; //[Register("STATE_DISCONNECTING")] //public const int StateDisconnecting = 3; public bool Disconnect(TelitDevice device) { bool isSuccess = false; try { var light = LightPeripherals?.FirstOrDefault(x => x.Name == device.Name && x.Address == device.Address); if (light != null) { var connection = light.Connection; if (connection != null) { connection.Disconnect(); //connection.Dispose(); } } } catch { } return(isSuccess); }