public string fnConnectResult(string sNetIP, int iPORT_NUM, IDataReceivedCallback callback) { try { client = new TcpClient(sNetIP, iPORT_NUM); cb = callback; client.GetStream().BeginRead(readBuffer, 0, READ_BUFFER_SIZE, new AsyncCallback(DoRead), null); return("Connection Succeeded"); } catch (Exception ex) { return("Server is not active. Please start server and try again." + ex.ToString()); } }
/// <summary> /// Enable notifications on a characteristic, enqueueing the request /// </summary> /// <param name="iCharacteristic"></param> /// <param name="iDataReceivedCallback">Callback class with which to return the notification read results</param> /// <param name="iDataSentCallback">Callback class with which to return the set notification results</param> /// <returns>True if requested characteristic has been loaded</returns> public bool EnableCharacteristicNotification(Guid iCharacteristic, IDataReceivedCallback iDataReceivedCallback, DeviceDataSentCallBack iDataSentCallback) { if (_characteristics.TryGetValue(iCharacteristic, out BluetoothGattCharacteristic characteristic)) { // Set up notification callback for receiving data from the gateway SetNotificationCallback(characteristic).With(iDataReceivedCallback); // Enable the notifications and enqueue the request EnableNotifications(characteristic).With(iDataSentCallback).Fail(iDataSentCallback).Enqueue(); return(true); } return(false); }