示例#1
0
        private void Listener()
        {
            byte[] read = new byte[1];

            List <byte> buffer = new List <byte>();

            while (true)
            {
                try
                {
                    if (socket.InputStream.Read(read, 0, read.Length) > 0)
                    {
                        if (read.Count() == 1 && read[0] != 0xFF)
                        {
                            buffer.AddRange(read);
                        }
                    }

                    if (read[0] == 0xFF)
                    {
                        socket.InputStream.Close();
                        ResultEvent?.Invoke(buffer);
                    }
                }
                catch (Exception exception) { Log.Debug(TAG, exception.ToString()); }
            }
        }
示例#2
0
        private void worker()
        {
            string name;

            while (filenames.TryDequeue(out name))
            {
                if (_stopSignal.WaitOne(0))
                {
                    return;
                }
                ResultEvent?.Invoke(Predict_with_db(ImageToTensor(name), name));
            }
        }
示例#3
0
    public async void MultiplicationTable(int number) //ST
    {
        for (int i = 0; true; i++)                    //ST
        {
            int result = number * i;                  //ST
                                                      //Should make a callback with all the data that is required by caller.

            ResultEvent?.Invoke(number, i, result);   // notification. ? is to check if resultevent is null if it is not null
            // then we will call back

            await Task.Delay(1000); //5 seconds delay
        } //ST
    } //ST
示例#4
0
        private void worker()
        {
            string name;

            while (filenames.TryDequeue(out name))
            {
                if (_stopSignal.WaitOne(0))
                {
                    ErrMessage?.Invoke("Stopping Thread by signal");
                    return;
                }
                ResultEvent?.Invoke(Predict(ImageToTensor(name), name));
            }
            InfoMessage?.Invoke("Stopping thread normally");
        }
示例#5
0
        //public void Stop() => _ct.Cancel();
        private void worker()
        {
            string name;

            while (filenames.TryDequeue(out name))
            {
                //Console.WriteLine("here working");
                if (_ct.IsCancellationRequested || _stopSignal.WaitOne(0))
                {
                    Console.WriteLine("sssss");
                    ErrMessage?.Invoke("Stopping Thread by signal");
                    return;
                }
                //Console.WriteLine("here after");
                var current_res = Predict_with_db(ImageToTensor(name), name);
                ResultEvent?.Invoke(current_res);
            }
            InfoMessage?.Invoke("Stopping thread normally");
        }
        /// <summary>
        /// Sets up the notifications;
        /// Will call Status
        /// </summary>
        /// <param name="notifyType"></param>
        /// <returns>true if the notify was set up. </returns>

        public async Task <bool> NotifyResultAsync(GattClientCharacteristicConfigurationDescriptorValue notifyType = GattClientCharacteristicConfigurationDescriptorValue.Notify)
        {
            if (!await EnsureCharacteristicAsync())
            {
                return(false);
            }
            var ch = Characteristics[0];

            if (ch == null)
            {
                return(false);
            }
            GattCommunicationStatus result = GattCommunicationStatus.ProtocolError;

            try
            {
                result = await ch.WriteClientCharacteristicConfigurationDescriptorAsync(notifyType);

                if (!NotifyResult_ValueChanged_Set)
                {
                    // Only set the event callback once
                    NotifyResult_ValueChanged_Set = true;
                    ch.ValueChanged += (sender, args) =>
                    {
                        var datameaning = "STRING|ASCII|Result";
                        var parseResult = BluetoothDeviceController.BleEditor.ValueParser.Parse(args.CharacteristicValue, datameaning);

                        Result = parseResult.ValueList.GetValue("Result").AsString;

                        ResultEvent?.Invoke(parseResult);
                    };
                }
            }
            catch (Exception e)
            {
                Status.ReportStatus($"NotifyResult: {e.Message}", result);
                return(false);
            }
            Status.ReportStatus($"NotifyResult: set notification", result);

            return(true);
        }
示例#7
0
 public virtual void OnResultEvent()
 {
     ResultEvent?.Invoke(this, EventArgs.Empty);
 }