WriteInt16() публичный Метод

public WriteInt16 ( short value ) : void
value short
Результат void
Пример #1
0
        IBuffer getBuffer(short i)
        {
            var writer = new Windows.Storage.Streams.DataWriter();

            writer.WriteInt16(i);
            return(writer.DetachBuffer());
        }
Пример #2
0
        public async Task SetAcquisitionRateAsync(UInt16 rate)
        {
            var acqusitionCharacteristic = service.GetCharacteristics(new Guid("00000EE2-0000-1000-8000-00805f9b34fb"))[0];
            DataWriter writer = new DataWriter();
            //Endianess of reciever data inverted
            writer.WriteInt16((Int16) SwapUInt16(rate));
            var status = await acqusitionCharacteristic.WriteValueAsync(writer.DetachBuffer());

        }
Пример #3
0
        private async Task <bool> SendPowerOffCommand()
        {
            var   writer = new Windows.Storage.Streams.DataWriter();
            short val    = CMD_OFF;

            writer.WriteInt16(val);
            GattCommunicationStatus writeResult = await _writeCharacteristic.WriteValueAsync(writer.DetachBuffer());

            bool success = writeResult == GattCommunicationStatus.Success;

            return(success);
        }
Пример #4
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}";
            }


        }
Пример #5
0
 public async void ToggleMediaState(MessageType type)
 {
     try
     {
         if (Speakers != null && Speakers.Count > 0)
         {
             foreach (Speaker speaker in Speakers)
             {
                 StreamSocket socket = speaker.Socket;
                 if (socket != null)
                 {
                     IOutputStream outStream = socket.OutputStream;
                     using (DataWriter dataWriter = new DataWriter(outStream))
                     {
                         dataWriter.WriteInt16((Int16)type);
                         await dataWriter.StoreAsync();
                         dataWriter.DetachStream();
                     }
                 }
             }
         }
     }
     catch (Exception ex)
     {
         Debug.WriteLine("Error playing: " + ex);
     }
 }
Пример #6
0
        public async void Send(byte[] fileBytes)
        {
            try
            {
                if (Speakers != null && Speakers.Count > 0 && fileBytes != null)
                {
                    //iterate through the speakers and send out the media file to each speaker
                    foreach (Speaker speaker in Speakers)
                    {
                        StreamSocket socket = speaker.Socket;

                        if (socket != null)
                        {
                            IOutputStream outStream = socket.OutputStream;
                            using (DataWriter dataWriter = new DataWriter(outStream))
                            {
                                //write header bytes to indicate to the subscriber 
                                //information about the file to be sent
                                dataWriter.WriteInt16((short)MessageType.Media);
                                dataWriter.WriteInt32(fileBytes.Length);
                                await dataWriter.StoreAsync();
                                //start from 0 and increase by packet size
                                int partNumber = 0;
                                int sourceIndex = 0;
                                int bytesToWrite = fileBytes.Length;
                                while (bytesToWrite > 0)
                                {
                                    dataWriter.WriteInt32(partNumber);
                                    int packetSize = bytesToWrite;
                                    if (packetSize > MAX_PACKET_SIZE)
                                    {
                                        packetSize = MAX_PACKET_SIZE;
                                    }
                                    byte[] fragmentedPixels = new byte[packetSize];
                                    Array.Copy(fileBytes, sourceIndex, fragmentedPixels, 0, packetSize);
                                    dataWriter.WriteBytes(fragmentedPixels);
                                    Debug.WriteLine("sent byte packet length " + packetSize);
                                    await dataWriter.StoreAsync();
                                    sourceIndex += packetSize;
                                    bytesToWrite -= packetSize;
                                    partNumber++;
                                    Debug.WriteLine("sent total bytes " + (fileBytes.Length - bytesToWrite));
                                }
                                //Finally DetachStream
                                dataWriter.DetachStream();
                            }
                        }
                    }


                    //check the speakers have all received the file
                    foreach (Speaker speaker in Speakers)
                    {
                        StreamSocket socket = speaker.Socket;
                        if (socket != null)
                        {
                            //wait for the 'I got it' message
                            DataReader reader = new DataReader(socket.InputStream);
                            uint x = await reader.LoadAsync(sizeof(short));
                            MessageType t = (MessageType)reader.ReadInt16();
                            if (MessageType.Ready == t)
                            {
                                await Windows.ApplicationModel.Core.CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal,
                                () =>
                                {
                                    Speakers.Remove(speaker);
                                    speaker.Status = "Ready";
                                    Speakers.Add(speaker);
                                });
                            }
                            reader.DetachStream();
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.ToString());
            }
        }
		public async Task<IRandomAccessStream> BeepBeep(int Amplitude, int Frequency, int Duration)
		{
			double A = ((Amplitude * (System.Math.Pow(2, 15))) / 1000) - 1;
			double DeltaFT = 2 * Math.PI * Frequency / 44100.0;

			int Samples = 441 * Duration / 10;
			int Bytes = Samples * 4;
			int[] Hdr = { 0X46464952, 36 + Bytes, 0X45564157, 0X20746D66, 16, 0X20001, 44100, 176400, 0X100004, 0X61746164, Bytes };

			InMemoryRandomAccessStream ims = new InMemoryRandomAccessStream();
			IOutputStream outStream = ims.GetOutputStreamAt(0);
			DataWriter dw = new DataWriter(outStream);
			dw.ByteOrder = ByteOrder.LittleEndian;

			for (int I = 0; I < Hdr.Length; I++)
			{
				dw.WriteInt32(Hdr[I]);
			}
			for (int T = 0; T < Samples; T++)
			{
				short Sample = System.Convert.ToInt16(A * Math.Sin(DeltaFT * T));
				dw.WriteInt16(Sample);
				dw.WriteInt16(Sample);
			}
			await dw.StoreAsync();
			await outStream.FlushAsync();
			return ims;
		}
Пример #8
0
        private async void OnPerformAction()
        {
            var stream = socket.OutputStream;
            using (var writer = new DataWriter(stream))
            {
                writer.ByteOrder = ByteOrder.LittleEndian;
                //writer.WriteInt16(6);
                //writer.WriteByte(0x00);
                //writer.WriteByte(3);
                //writer.WriteUInt16(1500);
                //writer.WriteUInt16(1000);

                //var bytes = new byte[] { 6, 0, 0, 3, 220, 5, 232, 3 };
                //writer.WriteBytes(bytes);

                writer.WriteInt16(12);
                writer.WriteByte(Byte0);
                writer.WriteByte(Byte1);
                writer.WriteByte(Byte2);
                writer.WriteByte(Byte3);
                writer.WriteByte(Byte4);
                writer.WriteByte(Byte5);
                writer.WriteByte(Byte6);
                writer.WriteByte(Byte7);
                writer.WriteUInt32(FourBytes);

                await writer.StoreAsync();
                writer.DetachStream();
            }
            using (var reader = new DataReader(socket.InputStream))
            {
                reader.ByteOrder = ByteOrder.LittleEndian;
                await reader.LoadAsync(5);
                var length = reader.ReadUInt16();
                var byte1 = reader.ReadByte();
                var byte2 = reader.ReadByte();
                var status = reader.ReadByte();

                reader.DetachStream();
            }
        }