예제 #1
0
        async void SwitchToggled(object sender, ToggledEventArgs e)
        {
            Debug.WriteLine("Switching: " + characteristic.ID.PartialFromUuid());
            if (e.Value)
            {
                if (characteristic.ID.PartialFromUuid() == "0xaa52")                // gyroscope on/off
                {
                    characteristic.Write(new byte[] { 0x07 });                      // enable XYZ axes
                }
                else if (characteristic.ID.PartialFromUuid() == "0xaa23")           // humidity period
                {
                    characteristic.Write(new byte[] { 0x02 });                      //
                }
                else
                {
                    characteristic.Write(new byte[] { 0x01 });
                }
            }
            else
            {
                // OFF
                characteristic.Write(new byte[] { 0x00 });
            }
            var c = await characteristic.ReadAsync();

            UpdateDisplay(c);
        }
예제 #2
0
        /// <summary>
        ///     Updates the BLE settings.
        /// </summary>
        public async void UpdateBLESettings(BLEChar blechar)
        {
            try {
                if (Settings != null && _temperatureService != null && _measurementScaleChar != null &&
                    _measurementTimeChar != null && _autooffIntervalChar != null && _sleepTimeChar != null)
                {
                    switch (blechar)
                    {
                    case BLEChar.Scale:
                        _measurementScaleChar.Write(Settings.Scale == 0 ? new byte[] { 0x43 } : new byte[] { 0x46 });
                        break;

                    case BLEChar.Time:
                        StopTemperatureReading = true;
                        _measurementTimeChar.Write(new[] { Convert.ToByte(Settings.MeasurementLevel) });
                        break;

                    case BLEChar.AutoOff:
                        _autooffIntervalChar.Write(new[] { Convert.ToByte(Settings.AutoOff) });
                        break;

                    case BLEChar.Sleep:
                        _sleepTimeChar.Write(new[] { Convert.ToByte(Settings.Sleep) });
                        break;

                    case BLEChar.Prob:
                        var bytes = HACCPUtil.GetBytesFromString(Settings.Prob);
                        _probeNameChar.Write(bytes);
                        break;
                    }
                }
            } catch (Exception) {
                Debug.WriteLine("Error on updating BLE settings");
            }
        }
예제 #3
0
        void HandleReceiveValueUpdated(object sender, CharacteristicReadEventArgs e)
        {
            var bytes = e.Characteristic.Value;

            if (bytes == null || bytes.Length == 0)
            {
                return;
            }

//			Debug.WriteLine ("Receive.Value: " + string.Join (" ", bytes.Select (x => x.ToString ("X2"))));

            lock (readBuffer)
            {
                if (readBuffer.Count + bytes.Length > ReadBufferSize)
                {
                    readBuffer.RemoveRange(0, ReadBufferSize / 2);
                }

                readBuffer.AddRange(bytes);
            }

            reset.Write(new byte[] { 1 });

            dataReceived.Set();
        }
예제 #4
0
 /// <summary>
 ///     Resets the blue2 auto off.
 /// </summary>
 public void ResetBlue2AutoOff()
 {
     if (_resetAutoOffChar != null)
     {
         _resetAutoOffChar.Write(new byte[] { Convert.ToByte(0) });
     }
     IsSleeping = false;
 }
예제 #5
0
        void BtnSendClicked(object sender, System.EventArgs e)
        {
            var data = System.Text.Encoding.UTF8.GetBytes(entryMessage.Text);

            if (characteristic.CanWrite)
            {
                characteristic.Write(data);
            }
        }
예제 #6
0
        public void SendCommand(ICharacteristic handle, byte[] command)
        {
            handle.ValueUpdated += Handle_ValueUpdated;

            if (handle.CanWrite)
            {
                handle.Write(command);
            }
        }
예제 #7
0
 /// <summary>
 ///     Dises the connect from wand.
 /// </summary>
 public void DisConnectFromWand()
 {
     try {
         if (_disConnectPeripheralChar != null)
         {
             _disConnectPeripheralChar.Write(new byte[] { Convert.ToByte(0) });
         }
     } catch (Exception ex) {
         Debug.WriteLine("Error on DisConnectFromWand : {0}", ex.Message);
     }
 }
예제 #8
0
 public void SetEnabled(bool value)
 {
     if (value)
     {
         if (!IsOn)
         {
             //Enable sensor
             switchCharacteristic.Write(new byte[] { 0x01 });
             IsOn = true;
         }
     }
     else
     {
         if (IsOn)
         {
             //Disable sensor
             switchCharacteristic.Write(new byte[] { 0x00 });
             IsOn = false;
         }
     }
 }
예제 #9
0
 //Turn the service on and off
 void SwitchToggled(ICharacteristic characteristic, Boolean e)
 {
     if (e)
     {
         if (characteristic.ID.PartialFromUuid() == "0xaa52")      // gyroscope on/off
         {
             characteristic.Write(new byte[] { 0x07 });            // enable XYZ axes
         }
         else if (characteristic.ID.PartialFromUuid() == "0xaa23") // humidity period
         {
             characteristic.Write(new byte[] { 0x02 });            //
         }
         else
         {
             characteristic.Write(new byte[] { 0x01 });
         }
     }
     else
     {
         // OFF
         characteristic.Write(new byte[] { 0x00 }); // off
     }
 }
        // <summary>
        // Enable all the sensors for a device
        // </summary>
        // <param name="device">The device we want to enable all sensors</param>
        async Task EnabelSensors(IDevice device)
        {
            foreach (Sensor sensor in _sensorList)
            {
                IService service = await device.GetServiceAsync(sensor.sensorService);

                ICharacteristic characteristic = await service.GetCharacteristicAsync(sensor.sensorConfig);

                if (characteristic.CanWrite)
                {
                    characteristic.Write(new byte[] { 0x01 });
                }
            }
        }
예제 #11
0
        public override async Task WriteAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken)
        {
            if (count > 20)
            {
                throw new ArgumentOutOfRangeException("count", "This function is limited to buffers of 20 bytes and less.");
            }
            await initTask;
            var   b = buffer;

            if (offset != 0 || count != b.Length)
            {
                b = new byte[count];
                Array.Copy(buffer, offset, b, 0, count);
            }
            // Write the data
            transmit.Write(b);
            // Throttle
            await Task.Delay(TimeSpan.FromMilliseconds(b.Length)); // 1 ms/byte is slow but reliable
        }
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();
            Title = "CharacteristicDetail";
            View.BackgroundColor = UIColor.White;


            _characteristicNameText = new UILabel(new RectangleF(10, 70, 300, 60));
            _characteristicIDText   = new UILabel(new RectangleF(10, 100, 300, 60));
            _rawValueText           = new UILabel(new RectangleF(10, 130, 300, 60));
            _stringValueText        = new UILabel(new RectangleF(10, 160, 300, 120));
            _stringValueText.Lines  = 2;
            //_valueUdpatedDateTime = new UILabel (new RectangleF (10, 190, 300, 60));


            _rawValueText.Text    = "raw";
            _stringValueText.Text = "string";
            //_valueUdpatedDateTime.Text = "-";

            // populate our page
            this._characteristicNameText.Text = _characteristic.Name;
            this._characteristicIDText.Text   = _characteristic.ID.ToString();



            Add(_characteristicNameText);
            Add(_characteristicIDText);
            Add(_rawValueText);
            Add(_stringValueText);
            //Add (_valueUdpatedDateTime);

            // NOTIFY-UPDATE
            this._valueUpdatedHandler = (s, e) => {
                Console.WriteLine("-- _valueUpdatedHandler: " + e.Characteristic.Value);
                this.InvokeOnMainThread(() => {
                    this.PopulateValueInfo();
                });
            };


            // request the value to be read
            _characteristic.StartUpdates();

            // READ
            var @type = new UILabel(new RectangleF(150, 250, 300, 60));
            var read  = UIButton.FromType(UIButtonType.System);

            read.Frame = new RectangleF(10, 250, 50, 30);
            read.SetTitle("Read", UIControlState.Normal);
            read.TouchUpInside += async(sender, e) => {
                @type.Text = "before";
                var c = await _characteristic.ReadAsync();

                @type.Text = "value:" + c.StringValue;
            };
            if (_characteristic.CanRead)
            {
                Add(@type);
                Add(read);
            }

            // WRITE
            var write = UIButton.FromType(UIButtonType.System);

            write.Frame = new RectangleF(10, 300, 100, 30);
            write.SetTitle("Write On", UIControlState.Normal);
            write.TouchUpInside += (sender, e) => {
                Console.WriteLine("turning on: " + _characteristic.ID.PartialFromUuid());
                if (_characteristic.ID.PartialFromUuid() == "0xaa52")             // gyroscope on/off
                {
                    _characteristic.Write(new byte[] { 0x07 });                   // enable XYZ axes
                }
                else if (_characteristic.ID.PartialFromUuid() == "0xaa23")        // humidity period
                {
                    _characteristic.Write(new byte[] { 0x02 });                   //
                }
                else
                {
                    _characteristic.Write(new byte[] { 0x01 });
                }
            };

            var writeoff = UIButton.FromType(UIButtonType.System);

            writeoff.Frame = new RectangleF(120, 300, 100, 30);
            writeoff.SetTitle("Write Off", UIControlState.Normal);
            writeoff.TouchUpInside += (sender, e) => {
                _characteristic.Write(new byte[] { 0x00 });
            };
            if (_characteristic.CanWrite)
            {
                Add(write);
                Add(writeoff);
            }
        }
예제 #13
0
		public void SendCommand (ICharacteristic handle, byte[] command)
		{
			Debug.WriteLine("Subscribers: " + handle.ValueUpdatedSubscribers);
			if (handle.ValueUpdatedSubscribers <= 1)
			{
				handle.ValueUpdated += Handle_ValueUpdated;
			}

			if (handle.CanWrite)
			{
				Console.WriteLine("Adapter: Sending Command");
				handle.Write(command);
			}
			else {
				Console.WriteLine("Unable to write handle");
			}
		}
예제 #14
0
 public void Write(byte[] data) => _characteristic.Write(data);
예제 #15
0
		public void SendCommand (ICharacteristic handle, byte[] command)
		{
			handle.ValueUpdated += Handle_ValueUpdated;

			if (handle.CanWrite)
				handle.Write (command);
		}
예제 #16
0
 public void WriteByte(byte ToWrite)
 {
     SerialTX.Write(new byte[1] {
         ToWrite
     });
 }
예제 #17
0
		public void SendCommand (ICharacteristic handle, byte[] command)
		{
			//handle.ValueUpdated += Handle_ValueUpdated;

			if (handle.CanWrite)
			{
				Console.WriteLine("Adapter: Sending Command");
				handle.Write(command);
			}
			else {
				Console.WriteLine("Unable to write to handle");
			}
		}