private void ConnectSocket() { _socket = new TcpClient(_ip, Communication_Port); _socket.Client.ReceiveTimeout = 500; IsConnected = true; DeviceConnected?.Invoke(); }
public bool Open() { CheckDisposed(); bool result = false; try { if (!Busy) { DeviceConnectingEventArgs args = new DeviceConnectingEventArgs { IPAddress = Settings.IPAddress, AcceptConnection = true }; DeviceConnecting?.Invoke(args); if (args.AcceptConnection) { OpenClient(); result = StartListen(); Connect(); DeviceConnected?.Invoke(this); } } } catch (Exception ex) { DeviceError?.Invoke(this, new DeviceErrorEventArgs { Ex = ex }); } return(result); }
/// <summary> /// Invokes the <see cref="DeviceConnected"/> event. /// </summary> /// <param name="device"></param> protected void OnDeviceConnected(Device device) { if (DeviceConnected != null) { DeviceConnected.Invoke(device); } }
public override void OnReceive(Context context, Intent intent) { string action = intent.Action; if (action.Equals(BluetoothDevice.ActionBondStateChanged)) { var device = (BluetoothDevice)intent.GetParcelableExtra(BluetoothDevice.ExtraDevice); switch (device.BondState) { case Bond.Bonded: Toast.MakeText(context, "Gerät gekoppelt", ToastLength.Long).Show(); DeviceConnected?.Invoke(device, new EventArgs()); break; case Bond.Bonding: Toast.MakeText(context, "Gerät wird gekoppelt", ToastLength.Long).Show(); break; case Bond.None: break; default: break; } } }
private async Task Connect(DeviceInformation deviceInformation) { // Perform device access checks before trying to get the device. // First, we check if consent has been explicitly denied by the user. var accessStatus = DeviceAccessInformation.CreateFromId(deviceInformation.Id).CurrentStatus; if (accessStatus == DeviceAccessStatus.DeniedByUser) { throw new UnauthorizedAccessException("This app does not have access to connect to the remote device (please grant access in Settings > Privacy > Other Devices"); } var bluetoothDevice = await BluetoothDevice.FromIdAsync(deviceInformation.Id); // This should return a list of uncached Bluetooth services (so if the server was not active when paired, it will still be detected by this call) var rfcommServices = await bluetoothDevice.GetRfcommServicesAsync(); RfcommDeviceService bluetoothService = null; foreach (var service in rfcommServices.Services) { System.Diagnostics.Debug.WriteLine("Service {0}: {1}", service.ConnectionHostName, service.ConnectionServiceName); if (service.ServiceId.Uuid == RfcommServiceId.SerialPort.Uuid) { bluetoothService = service; break; } } if (bluetoothService != null) { bluetoothDevice.ConnectionStatusChanged += BluetoothDevice_ConnectionStatusChanged; var device = new UwpRfcommDevice(deviceInformation, bluetoothService); connectedDevices.Add(device.deviceInfo.Id, device); DeviceConnected?.Invoke(device); } }
public void StartScan(BleDevice device) { _CentralManager = new CBCentralManager(this, null); if (device == null) { throw new Exception("Could not start client without a service type to scan for."); } _CentralManager.DiscoveredPeripheral += (o, e) => { DeviceFound?.Invoke(this, new DeviceEventArgs { Device = new BleDevice { Guid = e.Peripheral.UUID.Uuid } }); }; _CentralManager.ConnectedPeripheral += (o, e) => { DeviceConnected?.Invoke(this, new DeviceEventArgs { Device = new BleDevice { Guid = e.Peripheral.UUID.Uuid } }); }; //_CentralManager.ScanForPeripherals(CBUUID.FromPartial(device.GuidValue)); _CentralManager.ScanForPeripherals(CBUUID.FromString(device.Guid)); }
private void ConnectArrived(object sender, EventArrivedEventArgs e) { if (!IsConnected) { IsConnected = true; DeviceConnected?.Invoke(); } }
public void ConnectToDevice(IDevice device) { connectedDevices.Add(device); var args = new DeviceConnectionEventArgs(); args.Device = device; DeviceConnected?.Invoke(this, args); }
private void DeviceOnConnected(DeviceEventArgs args) { lock (_connectedDevices) { _connectedDevices.Add(args.Device); } DeviceConnected?.Invoke(args.Device); }
private void OnDeviceConnected(object sender, DeviceDataEventArgs args) { var dev = args.Device; CacheDeviceList(); Debug.WriteLine($"Device connected {dev.Name}[{dev.Model}/{dev.Serial}]"); DeviceConnected?.Invoke(this, args); //EchoTest(args.Device.Serial); }
/// <summary> /// Immediately locks the device update capability and invokes the <see cref="DeviceConnected"/> event. /// </summary> /// <param name="device"></param> private void OnDeviceConnected(Device device) { // When a device has been connected, immediately clear any locks and then re-lock // so that we update the state of the device at the end of this frame or the next. UnlockDeviceStateUpdate(); LockDeviceStateUpdate(); if (DeviceConnected != null) { DeviceConnected.Invoke(device); } }
internal void Start() { // For logcat arguments and more details check https://developer.android.com/studio/command-line/logcat m_Runtime.OnUpdate += OnUpdate; m_MessageProvider = m_Runtime.CreateMessageProvider(adb, Filter, MessagePriority, m_Device.SupportsFilteringByPid ? PackagePid : 0, LogPrintFormat, m_Device != null ? m_Device.Id : null, OnDataReceived); m_MessageProvider.Start(); if (DeviceConnected != null) { DeviceConnected.Invoke(Device.Id); } }
public BleAdapter(IAdapter adapter) { _adapter = adapter; _adapter.DeviceDiscovered += (sender, args) => DeviceDiscovered?.Invoke(sender, BleDevice.Wrap(args.Device)); _adapter.DeviceConnected += (sender, args) => DeviceConnected?.Invoke(sender, args.Adapt <DeviceConnectionEventArgs>()); _adapter.DeviceDisconnected += (sender, args) => DeviceDisconnected?.Invoke(sender, args.Adapt <DeviceConnectionEventArgs>()); _adapter.ScanTimeoutElapsed += (sender, args) => ScanTimeoutElapsed?.Invoke(sender, args); }
public void TriggerDeviceConnected(IDeviceBLE pInput) { RunMainThread(() => { Debug.WriteLine("Finished connecting to : " + pInput.Id); if (mConnectedDevices != null) { mConnectedDevices.Add(pInput); } DeviceConnected?.Invoke(pInput); RemoveDevice(pInput); }); }
public async Task Connect(DeviceInfo deviceInfo) { Disconnect(); ConnectedDevice = await BluetoothLEDevice.FromIdAsync(deviceInfo.DeviceId); if (ConnectedDevice == null) { return; } deviceInfo.MacAddress = ConnectedDevice.BluetoothAddress.ToMacAddressString(); deviceInfo.Name = ConnectedDevice.Name; _infoManager.SaveDevice(deviceInfo); DeviceConnected?.Invoke(this, EventArgs.Empty); }
private void Watcher_EventArrived(object sender, EventArrivedEventArgs e) { bool connected = IsDeviceConnected(); if (!Connected && connected) { Trace.WriteLine("Device Connected: " + DeviceName); Connected = true; DeviceConnected?.Invoke(this, null); } else if (Connected && !connected) { Trace.WriteLine("Device Disconnected: " + DeviceName); Connected = false; DeviceDisconnected?.Invoke(this, null); } }
private void Heartbeat(object state) { if (!_socket.Connected && IsConnected) { DeviceDisconnected?.Invoke(); IsConnected = false; } if (!IsConnected) { // Try reconnect try { ConnectSocket(); DeviceConnected?.Invoke(); } catch (Exception e) { IsConnected = false; } } try { var response = Ping(); Span<byte> statusSpan = Serialize<DacStatusDto>(response.DacStatus); var dacStatus = DacStatus.ParseDacStatus(statusSpan); var ack = DacResponse.ParseAckCode(response.Response); StatusUpdated?.Invoke(ack, dacStatus.BufferFullness); } catch (Exception e) { } }
private void UpdateByConnectionStatusAndPublishEvent(BluetoothLEDevice sender, object args) { if (sender.ConnectionStatus == BluetoothConnectionStatus.Connected) { if (!_devices.ContainsKey(sender.DeviceId)) { _devices[sender.DeviceId] = sender; } DeviceConnected?.Invoke(this, new BleDeviceEventArgs(sender.ToDomainModel())); return; } if (sender.ConnectionStatus == BluetoothConnectionStatus.Disconnected) { if (_devices.ContainsKey(sender.DeviceId)) { var t = ClearDevice(sender.DeviceId).Result; } OnDeviceDisconnected(new BleDeviceEventArgs(sender.ToDomainModel())); } }
private static void EnumerationThreadProc() { var oldDevices = new PIEDevice[0]; while (true) { try { var devices = PIEDevice.EnumeratePIE(); foreach (var pieDevice in devices.Where(d => d.HidUsagePage == 0xC && !oldDevices.Any(od => DeviceEquals(od, d)))) { var device = new XKeysDevice(pieDevice); lock (((IList)Devices).SyncRoot) Devices.Add(device); DeviceConnected?.Invoke(null, device); Logger.Info("New device connected {0}:{1}", pieDevice.Pid, pieDevice.Vid); } foreach (var pieDevice in oldDevices.Where(d => d.HidUsagePage == 0xC && !devices.Any(od => DeviceEquals(od, d)))) { var device = Devices.FirstOrDefault(d => DeviceEquals(d.PieDevice, pieDevice)); if (device == null) { continue; } device.Dispose(); lock (((IList)Devices).SyncRoot) Devices.Remove(device); Logger.Info("Device disconnected {0}:{1}", pieDevice.Pid, pieDevice.Vid); } oldDevices = devices; Thread.Sleep(1000); } catch (Exception e) { Logger.Error(e); } } }
/// <summary> /// Accept new connections /// </summary> /// <param name="ar">Async Result</param> private void AcceptCallback(IAsyncResult ar) { Socket client = null; try { client = serverSocket.EndAccept(ar); } catch (Exception ex) { ServerError?.Invoke(ex); return; } DeviceConnected?.Invoke((IPEndPoint)client.RemoteEndPoint); ReadObject readObject = new ReadObject() { client = client, buffer = new byte[1024], isFirstMessage = true, session = new SessionCrypto() }; client.BeginReceive(readObject.buffer, 0, readObject.buffer.Length, SocketFlags.None, new AsyncCallback(ReadCallback), readObject); serverSocket.BeginAccept(new AsyncCallback(AcceptCallback), null); }
private void DealCallbackInThread(Tuple <int, IntPtr> arg) { int state = arg.Item1; IntPtr devicePtr = arg.Item2; if (state == 1) //设备连接 { var devInfo = (UsbDeviceInfo)Marshal.PtrToStructure(devicePtr, typeof(UsbDeviceInfo)); DeviceConnected?.Invoke(new UsbDevice() { VID = devInfo.VID, PID = devInfo.PID }); LoggerManagerSingle.Instance.Info($"设备连接:vid={devInfo.VID:X}, pid={devInfo.PID:X}, isPhone={devInfo.IsPhone}, desc={devInfo.GetDeviceDesc()}, type={devInfo.GetDeviceType()}"); } else //设备断开 { var devInfoStr = Marshal.PtrToStringAnsi(devicePtr); var infoStr = devInfoStr.Split('#'); UsbDeviceInfo devInfo = new UsbDeviceInfo(); if (infoStr.Length > 2) { string[] vpID; if (GetVIDPID(infoStr[1], out vpID)) { devInfo.VID = Convert.ToUInt32(vpID[0], 16); devInfo.PID = Convert.ToUInt32(vpID[1], 16); } DeviceDisconnected?.Invoke(new UsbDevice() { VID = devInfo.VID, PID = devInfo.PID }); LoggerManagerSingle.Instance.Info($"断开设备:vid={devInfo.VID:X}, pid={devInfo.PID:X}, str={devInfoStr}"); } } }
/// <summary> /// Callback method that MdsLib calls when a device connects or disconnects /// </summary> /// <param name="mdsevent">details of device connection/disconnection</param> public void OnDeviceConnectionEvent(MDSEvent mdsevent) { var method = ((NSString)mdsevent.BodyDictionary.ValueForKey(new NSString("Method"))); if (method == new NSString("POST")) { // Device connected var bodyDict = (NSDictionary)mdsevent.BodyDictionary.ValueForKey(new NSString("Body")); var serial = ((NSString)bodyDict.ValueForKey(new NSString("Serial"))).ToString(); var connDict = (NSDictionary)bodyDict.ValueForKey(new NSString("Connection")); var uuid = ((NSString)connDict.ValueForKey(new NSString("UUID"))).ToString(); var uniqueIDGuid = new Guid(uuid); this.UuidToSerialMapper.TryAdd(uniqueIDGuid, serial); Debug.WriteLine($"MdsConnectionListener OnDeviceConnectionEvent CONNECTED: Serial {serial}"); DeviceConnected?.Invoke(this, new MdsConnectionListenerBLEConnectedEventArgs(uuid)); DeviceConnectionComplete?.Invoke(this, new MdsConnectionListenerEventArgs(serial, uniqueIDGuid)); } else if (method == new NSString("DEL")) { // Device disconnected var bodyDict = (NSDictionary)mdsevent.BodyDictionary.ValueForKey(new NSString("Body")); var serial = ((NSString)bodyDict.ValueForKey(new NSString("Serial"))).ToString(); // Get the matching Uuid var uniqueIDGuid = this.UuidToSerialMapper.First(kv => kv.Value == serial).Key; Debug.WriteLine($"MdsConnectionListener OnDeviceConnectionEvent DISCONNECTED: Serial {serial}"); DeviceDisconnected?.Invoke(this, new MdsConnectionListenerEventArgs(serial, uniqueIDGuid)); } else { throw new MdsException($"OnDeviceConnectionEvent unexpected method: {method}"); } }
void hidDevice_Inserted() { DeviceConnected?.Invoke(); }
private void OnDeviceConnected(IDevice device) { CurConnectDeves.Add(device); DeviceConnected?.Invoke(device); }
/// <summary> /// Callback method that MdsLib calls when a device connects /// </summary> /// <param name="MACaddress"></param> public void OnConnect(string MACaddress) { Debug.WriteLine($"SUCCESS MdsConnectionListener OnConnect callback called: MACaddress {MACaddress}"); DeviceConnected?.Invoke(this, new MdsConnectionListenerBLEConnectedEventArgs(MACaddress)); }
private void OnDeviceConnectedEvent(ConnectionEventArgs args) { DeviceConnected?.Invoke(this, args); }
public override void OnDeviceConnected() => DeviceConnected?.Invoke();
/// <summary>Raises the <see cref="E:RAPISink.DeviceConnected"/> event.</summary> public void OnDeviceConnected(IRAPIDevice pIDevice) { DeviceConnected?.Invoke(this, new DeviceConnectEventArgs(pIDevice)); }
protected virtual void OnDeviceConnected(IDeviceService device) { DeviceConnected?.Invoke(device); }
private void DoDeviceConnected() { System.Diagnostics.Debug.WriteLine("device connected"); DeviceConnected?.Invoke(this, new EventArgs()); }