WriteDouble() public méthode

public WriteDouble ( double value ) : void
value double
Résultat void
        public async void StoreData()
        {
            var stream = await _dataFile.OpenAsync(FileAccessMode.ReadWrite, StorageOpenOptions.AllowReadersAndWriters);

            using (var outputStream = stream.GetOutputStreamAt(0))
            {
                using (var dataWriter = new Windows.Storage.Streams.DataWriter(outputStream))
                {
                    const string delinieater = ";";
                    foreach (double[] data in _data)
                    {
                        foreach (double d in data)
                        {
                            dataWriter.WriteDouble(d);
                            dataWriter.WriteString(delinieater);
                        }
                    }
                    await dataWriter.FlushAsync();
                }
            }
            stream.Dispose();

            _dataLineCount += _data.Count();

            if (_dataLineCount >= LINE_LIMIT)
            {
                await CreateDataFile();
            }
            _data = new List <double[]>();
        }
Exemple #2
0
        private async void ButtonAction5_Click(object sender, RoutedEventArgs e)
        {
            DevicesInformation = string.Empty;
            try
            {
                var motors = _dicCharacteristics["Parrot_PowerMotors"].Characteristic;
                await motors.WriteClientCharacteristicConfigurationDescriptorAsync(GattClientCharacteristicConfigurationDescriptorValue.Indicate);
                byte[] arr1 = { 02, 40, 20, 09, 00, 05, 00, 04, 00, 12, 0xC0, 00, 01, 00 };


                var buffer = new DataWriter();
                buffer.WriteInt16(2);
                buffer.WriteInt16(1);
                buffer.WriteInt16(2);
                buffer.WriteInt16(0);
                buffer.WriteInt16(2);
                buffer.WriteInt16(0);
                buffer.WriteInt16(1);
                buffer.WriteInt16(1);
                buffer.WriteInt16(1);
                buffer.WriteInt16(1);
                buffer.WriteInt16(1);
                buffer.WriteDouble(0);

                await motors.WriteValueAsync(buffer.DetachBuffer(), GattWriteOption.WriteWithoutResponse);
                DevicesInformation += $"  - 1 OK{Environment.NewLine}";
            }
            catch (Exception exception)
            {
                DevicesInformation += $"  - ERROR {exception.Message}{Environment.NewLine}";
            }


        }
Exemple #3
0
        public async Task<bool> SendMotorCmd(bool on, int tilt, int forward, int turn, int up, float scale)
        {
            var packet = new DataWriter();
            try
            {
                packet.WriteByte(2);
                packet.WriteByte((byte)_motorCounter);
                packet.WriteByte(2);
                packet.WriteByte(0);
                packet.WriteByte(2);
                packet.WriteByte(0);
                if (on)
                {
                    packet.WriteByte(1);
                }
                else
                {
                    packet.WriteByte(0);
                }
                // is byte casting necessary???
                packet.WriteByte((byte)(tilt & 0xFF));
                packet.WriteByte((byte)(forward & 0xFF));
                packet.WriteByte((byte)(turn & 0xFF));
                packet.WriteByte((byte)(up & 0xFF));
                packet.WriteDouble(scale); // well, but I need different endian :(
                                           //byte[] tmpArr = stream.toByteArray();
                                           //byte tmp;
                                           //tmp = tmpArr[11]; // temporary hack - swapping float ordering
                                           //tmpArr[11] = tmpArr[14];
                                           //tmpArr[14] = tmp;
                                           //tmp = tmpArr[12];
                                           //tmpArr[12] = tmpArr[13];
                                           //tmpArr[13] = tmp;
                                           //characteristics.setValue(tmpArr);
                await _motorChar.WriteValueAsync(packet.DetachBuffer(), GattWriteOption.WriteWithoutResponse);
            }
            catch (Exception exception)
            {
                AddException(exception);
            }

            await Sleep(50);
            _motorCounter++;
            return true;
        }
Exemple #4
0
        public async Task<bool> SendMotorCommand(bool @on, int tilt, int forward, int turn, int up, float scale, IReadOnlyList<GattCharacteristic> characteristics)
        {
            var res = false;
            var characteristic = characteristics[0];
            try
            {
                Debug.WriteLine("    Send Motor Command");
                Debug.WriteLine("    Try to write to " + CharacteristicUuidsResolver.GetNameFromUuid(characteristic.Uuid));
                Debug.WriteLine("    Char props" + characteristic.CharacteristicProperties);

                var writer = new DataWriter();
                writer.WriteByte(2);
                writer.WriteByte((byte)_motorCounter);
                writer.WriteByte(2);
                writer.WriteByte(0);
                writer.WriteByte(2);
                writer.WriteByte(0);
                if (on)
                {
                    writer.WriteByte(1);
                }
                else
                {
                    writer.WriteByte(0);
                }
                // is byte casting necessary???
                writer.WriteByte((byte)(tilt & 0xFF));
                writer.WriteByte((byte)(forward & 0xFF));
                writer.WriteByte((byte)(turn & 0xFF));
                writer.WriteByte((byte)(up & 0xFF));
                writer.WriteDouble(scale); // well, but I need different endian :(

                await characteristic.WriteValueAsync(writer.DetachBuffer());
                Debug.WriteLine("      Write sucessfull");
                res = true;
            }
            catch (Exception exception)
            {
                Debug.WriteLine("      Write error");
            }
            return res;
        }