void Update()
    {
        MainThreadWait.WaitOne();
        MainThreadWait.Reset();


        if (mainThreadCallback != null)
        {
            try
            {
                mainThreadCallback();
            } catch (Exception e) {
                Debug.Log(e);
            }
            mainThreadCallback = null;
        }



        if (useReceiveEvents)
        {
            lock (readQueue)
            {
                if (readQueue.Count > 0)
                {
                    ValueReceivedEvent.Invoke(readQueue.Dequeue());
                }
            }
        }

        ChildThreadWait.Set();
    }
Exemplo n.º 2
0
        public void Connect()
        {
            logger.LogInformation($"Connecting KEBA on {ip}:{port}");
            sender.Connect(IPAddress.Parse(ip), port);
            logger.LogInformation("Connected");

            connected = true;

            Task.Run(async() =>
            {
                while (connected)
                {
                    var receivedResults = await listener.ReceiveAsync();
                    var message         = Encoding.ASCII.GetString(receivedResults.Buffer);

                    logger.LogTrace($"Message received: {message}");

                    ValueReceived?.Invoke(this, message);
                }

                logger.LogInformation("Connection closed.");
            });

            Send(InformationCommand);

            Send(Report2Command);
            Send(Report3Command);

            report3Timer.Start();
            report2Timer.Start();
        }
Exemplo n.º 3
0
        public override void ProcessNetworkData(string id, string value)
        {
            BindingValue bound = new BindingValue(value);

            _value.SetValue(bound, false);
            _receivedTrigger.FireTrigger(bound);
            ValueReceived?.Invoke(this, new Value {
                Text = value
            });
        }
Exemplo n.º 4
0
 private void Characteristic_ValueChanged(GattCharacteristic sender, GattValueChangedEventArgs args)
 {
     if (!_valueReceived)
     {
         _valueReceived = true;
         var tet              = args.CharacteristicValue.ToString();
         var byteArray        = args.CharacteristicValue.ToArray();
         var strValue         = Encoding.UTF8.GetString(byteArray);
         var buttonId         = strValue.Split(";")[0];
         var buttonPressCount = strValue.Split(";")[1];
         ValueReceived?.Invoke(this, new ValueReceivedEventArgs(buttonId, ushort.Parse(buttonPressCount)));
         _signal.Set();
     }
 }
Exemplo n.º 5
0
 private void OnValueReceived(Reading value)
 {
     Console.WriteLine(value);
     ValueReceived?.Invoke(this, value);
 }