当前位置: 首页>>代码示例>>C#>>正文


C# DataWriter.DetachBuffer方法代码示例

本文整理汇总了C#中Windows.Storage.Streams.DataWriter.DetachBuffer方法的典型用法代码示例。如果您正苦于以下问题:C# DataWriter.DetachBuffer方法的具体用法?C# DataWriter.DetachBuffer怎么用?C# DataWriter.DetachBuffer使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Windows.Storage.Streams.DataWriter的用法示例。


在下文中一共展示了DataWriter.DetachBuffer方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: OnWriteableTagArrived

       private void OnWriteableTagArrived(ProximityDevice sender, ProximityMessage message)
       {
    
           var dataWriter = new DataWriter();
           dataWriter.UnicodeEncoding = Windows.Storage.Streams.UnicodeEncoding.Utf16LE;
           string appLauncher = string.Format(@"mywaiter:MainPage?source=3");
 
           dataWriter.WriteString(appLauncher);
           pubId = sender.PublishBinaryMessage("WindowsUri:WriteTag", dataWriter.DetachBuffer());
   
       }
开发者ID:Hitchhikrr,项目名称:NokiaCompo_CampusParty13,代码行数:11,代码来源:writeTag.xaml.cs

示例2: Encrypt

        /// <summary>
        /// 加密
        /// </summary>
        /// <param name="toEncrypt"></param>
        /// <param name="bufferkey"></param>
        /// <returns></returns>
        public static string Encrypt(string toEncrypt)
        {
            SymmetricKeyAlgorithmProvider aesCbcPkcs7 =
SymmetricKeyAlgorithmProvider.OpenAlgorithm(SymmetricAlgorithmNames.AesCbcPkcs7);
            var dataWriter = new DataWriter();
            dataWriter.WriteBytes(new byte[] { 65, 69, 87, 65, 49, 50, 94, 64, 35, 77, 65, 87, 40, 0, 0, 0 });
            CryptographicKey key =
              aesCbcPkcs7.CreateSymmetricKey(dataWriter.DetachBuffer());
            byte[] plainText = Encoding.UTF8.GetBytes(toEncrypt);
            byte[] cipherText = CryptographicEngine.Encrypt(
                key, plainText.AsBuffer(), dataWriter.DetachBuffer()).ToArray();
            return Convert.ToBase64String(cipherText, 0, cipherText.Length);

        }
开发者ID:mshaal135,项目名称:DesktopAD-SDK-For-Windows-App,代码行数:20,代码来源:App.xaml.cs

示例3: OnNavigatedTo

        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            if (this.Frame.CanGoBack)
            {
                SystemNavigationManager.GetForCurrentView().AppViewBackButtonVisibility = AppViewBackButtonVisibility.Visible;
                SystemNavigationManager.GetForCurrentView().BackRequested += Publish_BackRequested;
            }

            this.publisher = new BluetoothLEAdvertisementPublisher();

            ushort id = 0x1234;
            var manufacturerDataWriter = new DataWriter();
            manufacturerDataWriter.WriteUInt16(id);

            var manufacturerData = new BluetoothLEManufacturerData
            {
                CompanyId = 0xFFFE,
                Data = manufacturerDataWriter.DetachBuffer()
            };

            publisher.Advertisement.ManufacturerData.Add(manufacturerData);

            this.Manufacturer = "12-34";

            publisher.Start();
        }
开发者ID:muneneevans,项目名称:blog,代码行数:26,代码来源:Publish.xaml.cs

示例4: WriteBlecOmmand

        private async Task WriteBlecOmmand(string command)
        {
            try
            {
                _commandExecuting = true;

                BluetoothLEDevice oygenBluetoothLeDevice = null;
                GattCharacteristic writeCharacteristics = null;

                oygenBluetoothLeDevice = await BluetoothLEDevice.FromBluetoothAddressAsync(0x000780067cf1);


                var srv =
                    oygenBluetoothLeDevice.GattServices.FirstOrDefault(
                        gs => gs.Uuid.ToString().Equals("2ac94b65-c8f4-48a4-804a-c03bc6960b80"));

                Debug.WriteLine(oygenBluetoothLeDevice.Name);

                writeCharacteristics =
                    srv
                        .GetAllCharacteristics()
                        .FirstOrDefault(ch => ch.Uuid.ToString().Equals("50e03f22-b496-4a73-9e85-335482ed4b12"));

                var writer = new DataWriter();

                writer.WriteString(command + "\n");

                await writeCharacteristics.WriteValueAsync(writer.DetachBuffer());
            }
            catch (Exception ex)
            {
                Debug.WriteLine("Bluetooth Problem.");
                Debug.WriteLine(ex.Message);
            }
        }
开发者ID:Injac,项目名称:NIteLIteCommander,代码行数:35,代码来源:MainPage.xaml.cs

示例5: TransparentExchangeAsync

        /// <summary>
        /// Extension method to SmartCardConnection class to perform a transparent exchange to the ICC
        /// </summary>
        /// <param name="connection">
        /// SmartCardConnection object
        /// </param>
        /// <param name="commandData">
        /// Command object to send to the ICC
        /// </param>
        /// <returns>Response received from the ICC</returns>
        public static async Task<byte[]> TransparentExchangeAsync(this SmartCardConnection connection, byte[] commandData)
        {
            byte[] responseData = null;
            ManageSessionResponse apduRes = await TransceiveAsync(connection, new ManageSession(new byte[2] { (byte)ManageSession.DataObjectType.StartTransparentSession, 0x00 })) as ManageSessionResponse;

            if (!apduRes.Succeeded)
            {
                throw new Exception("Failure to start transparent session, " + apduRes.ToString());
            }

            using (DataWriter dataWriter = new DataWriter())
            {
                dataWriter.WriteByte((byte)TransparentExchange.DataObjectType.Transceive);
                dataWriter.WriteByte((byte)commandData.Length);
                dataWriter.WriteBytes(commandData);

                TransparentExchangeResponse apduRes1 = await TransceiveAsync(connection, new TransparentExchange(dataWriter.DetachBuffer().ToArray())) as TransparentExchangeResponse;

                if (!apduRes1.Succeeded)
                {
                    throw new Exception("Failure transceive with card, " + apduRes1.ToString());
                }

                responseData = apduRes1.IccResponse;
            }

            ManageSessionResponse apduRes2 = await TransceiveAsync(connection, new ManageSession(new byte[2] { (byte)ManageSession.DataObjectType.EndTransparentSession, 0x00 })) as ManageSessionResponse;

            if (!apduRes2.Succeeded)
            {
                throw new Exception("Failure to end transparent session, " + apduRes2.ToString());
            }

            return responseData;
        }
开发者ID:mhdubose,项目名称:Windows-universal-samples,代码行数:45,代码来源:PcscUtils.cs

示例6: iBeaconSetAdvertisement

        public static void iBeaconSetAdvertisement(this BluetoothLEAdvertisement Advertisment, iBeaconData data)
        {
            BluetoothLEManufacturerData manufacturerData = new BluetoothLEManufacturerData();

            // Set Apple as the manufacturer data
            manufacturerData.CompanyId = 76;

            var writer = new DataWriter();
            writer.WriteUInt16(0x0215); //bytes 0 and 1 of the iBeacon advertisment indicator

            if (data!=null& data.UUID!= Guid.Empty)
            {
                //If UUID is null scanning for all iBeacons
                writer.WriteBytes( data.UUID.ToByteArray());
                if (data.Major!=0)
                {
                    //If Major not null searching with UUID and Major
                    writer.WriteBytes(BitConverter.GetBytes(data.Major).Reverse().ToArray());
                    if (data.Minor != 0)
                    {
                        //If Minor not null we are looking for a specific beacon not a class of beacons
                        writer.WriteBytes(BitConverter.GetBytes(data.Minor).Reverse().ToArray());
                        if (data.TxPower != 0)
                            writer.WriteBytes(BitConverter.GetBytes(data.TxPower));
                    }
                }
            }

            manufacturerData.Data = writer.DetachBuffer();

            Advertisment.ManufacturerData.Clear();
            Advertisment.ManufacturerData.Add(manufacturerData);
        }
开发者ID:danardelean,项目名称:Beacons.Universal,代码行数:33,代码来源:Beacons.cs

示例7: HandleSensorControlPoint

        // Write function for adding control points to a server
        private async Task HandleSensorControlPoint(string data)
        {
            if (!string.IsNullOrEmpty(data))
            {
                // Get current service from base class.
                var service = await GetService();
                // Get current characteristic from current service using the selected values from the base class.
                var characteristic = service.GetCharacteristics(this.SelectedService.Guid)[this.SelectedIndex];

                //Create an instance of a data writer which will write to the relevent buffer.
                DataWriter writer = new DataWriter();
                byte[] toWrite = System.Text.Encoding.UTF8.GetBytes(data);
                writer.WriteBytes(toWrite);

                // Attempt to write the data to the device, and whist doing so get the status.
                GattCommunicationStatus status = await characteristic.WriteValueAsync(writer.DetachBuffer());

                // Displays a message box to tell user if the write operation was successful or not.
                if (status == GattCommunicationStatus.Success)
                {
                    MessageHelper.DisplayBasicMessage("Sensor control point has been written.");
                }
                else
                {
                    MessageHelper.DisplayBasicMessage("There was a problem writing the sensor control value, Please try again later.");
                }
            }
        }
开发者ID:mwarren571,项目名称:GestureControlWristband,代码行数:29,代码来源:HeartRateMonitorDevice.cs

示例8: Init

 public async Task<bool> Init()
 {
     var res = true;
     ClearExceptions();
     for (int i = 0; i < 20; i++)
     {
         try
         {
             var value = new byte[3];
             value[0] = 0x1;
             value[1] = (byte)(i + 1);
             value[2] = (byte)(i + 1);
             var buffer = new DataWriter();
             buffer.WriteBytes(value);
             await _initCount1To20Char.WriteValueAsync(buffer.DetachBuffer(), GattWriteOption.WriteWithoutResponse);
             await Sleep(50);
         }
         catch (Exception exception)
         {
             res = false;
             AddException(exception);
         }
     }
     return res;
 }
开发者ID:modulexcite,项目名称:events,代码行数:25,代码来源:TourTheStairs.cs

示例9: ButtonAction2_Click

        private async void ButtonAction2_Click(object sender, RoutedEventArgs e)
        {
            DevicesInformation = string.Empty;
            foreach (var rsCharacteristic in _dicCharacteristics)
            {
                DevicesInformation += $"  Try to write to {rsCharacteristic.Value.CharName}{Environment.NewLine}";
                bool writeOk = true;
                try
                {
                    var charToTest = rsCharacteristic.Value.Characteristic;
                    byte[] arr = { 4, 1, 2, 0, 1, 0 };
                    var writer = new DataWriter();
                    writer.WriteBytes(arr);
                    await charToTest.WriteClientCharacteristicConfigurationDescriptorAsync(GattClientCharacteristicConfigurationDescriptorValue.Indicate);
                    await charToTest.WriteValueAsync(writer.DetachBuffer());
                    DevicesInformation += $"  - OK{Environment.NewLine}";
                }
                catch
                {
                    DevicesInformation += $"  - ERROR{Environment.NewLine}";
                    writeOk = false;
                }

                var msg = $"{rsCharacteristic.Value.CharName}, {writeOk}, {rsCharacteristic.Value.Characteristic.CharacteristicProperties}, {rsCharacteristic.Value.Characteristic.Uuid}";
                Debug.WriteLine(msg);

                await Task.Delay(TimeSpan.FromMilliseconds(100));
            }
        }
开发者ID:modulexcite,项目名称:events,代码行数:29,代码来源:MainPage.xaml.cs

示例10: Scenario3_BackgroundWatcher

        /// <summary>
        /// Initializes the singleton application object.  This is the first line of authored code
        /// executed, and as such is the logical equivalent of main() or WinMain().
        /// </summary>
        public Scenario3_BackgroundWatcher()
        {
            this.InitializeComponent();

            // Create and initialize a new trigger to configure it.
            trigger = new BluetoothLEAdvertisementWatcherTrigger();

            // Configure the advertisement filter to look for the data advertised by the publisher in Scenario 2 or 4.
            // You need to run Scenario 2 on another Windows platform within proximity of this one for Scenario 3 to 
            // take effect.

            // Unlike the APIs in Scenario 1 which operate in the foreground. This API allows the developer to register a background
            // task to process advertisement packets in the background. It has more restrictions on valid filter configuration.
            // For example, exactly one single matching filter condition is allowed (no more or less) and the sampling interval

            // For determining the filter restrictions programatically across APIs, use the following properties:
            //      MinSamplingInterval, MaxSamplingInterval, MinOutOfRangeTimeout, MaxOutOfRangeTimeout

            // Part 1A: Configuring the advertisement filter to watch for a particular advertisement payload

            // First, let create a manufacturer data section we wanted to match for. These are the same as the one 
            // created in Scenario 2 and 4. Note that in the background only a single filter pattern is allowed per trigger.
            var manufacturerData = new BluetoothLEManufacturerData();

            // Then, set the company ID for the manufacturer data. Here we picked an unused value: 0xFFFE
            manufacturerData.CompanyId = 0xFFFE;

            // Finally set the data payload within the manufacturer-specific section
            // Here, use a 16-bit UUID: 0x1234 -> {0x34, 0x12} (little-endian)
            DataWriter writer = new DataWriter();
            writer.WriteUInt16(0x1234);

            // Make sure that the buffer length can fit within an advertisement payload. Otherwise you will get an exception.
            manufacturerData.Data = writer.DetachBuffer();

            // Add the manufacturer data to the advertisement filter on the trigger:
            trigger.AdvertisementFilter.Advertisement.ManufacturerData.Add(manufacturerData);

            // Part 1B: Configuring the signal strength filter for proximity scenarios

            // Configure the signal strength filter to only propagate events when in-range
            // Please adjust these values if you cannot receive any advertisement 
            // Set the in-range threshold to -70dBm. This means advertisements with RSSI >= -70dBm 
            // will start to be considered "in-range".
            trigger.SignalStrengthFilter.InRangeThresholdInDBm = -70;

            // Set the out-of-range threshold to -75dBm (give some buffer). Used in conjunction with OutOfRangeTimeout
            // to determine when an advertisement is no longer considered "in-range"
            trigger.SignalStrengthFilter.OutOfRangeThresholdInDBm = -75;

            // Set the out-of-range timeout to be 2 seconds. Used in conjunction with OutOfRangeThresholdInDBm
            // to determine when an advertisement is no longer considered "in-range"
            trigger.SignalStrengthFilter.OutOfRangeTimeout = TimeSpan.FromMilliseconds(2000);

            // By default, the sampling interval is set to be disabled, or the maximum sampling interval supported.
            // The sampling interval set to MaxSamplingInterval indicates that the event will only trigger once after it comes into range.
            // Here, set the sampling period to 1 second, which is the minimum supported for background.
            trigger.SignalStrengthFilter.SamplingInterval = TimeSpan.FromMilliseconds(1000);
        }
开发者ID:RasmusTG,项目名称:Windows-universal-samples,代码行数:63,代码来源:Scenario3_BackgroundWatcher.xaml.cs

示例11: GetBufferFromByteArray

 public static IBuffer GetBufferFromByteArray(this byte[] payload)
 {
     using (var dw = new DataWriter())
     {
         dw.WriteBytes(payload);
         return dw.DetachBuffer();
     }
 }
开发者ID:slodge,项目名称:BallControl,代码行数:8,代码来源:BufferExtensionMethods.cs

示例12: GetFilledReport

        public HidOutputReport GetFilledReport()
        {
            var dataWriter = new DataWriter();
            dataWriter.WriteByte(Id);
            dataWriter.WriteBytes(Data.Array);
            report.Data = dataWriter.DetachBuffer();

            return report;
        }
开发者ID:vbfox,项目名称:U2FExperiments,代码行数:9,代码来源:UwpOutputReport.cs

示例13: SetAcquisitionRateAsync

        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());

        }
开发者ID:balalaikaproject,项目名称:AmbulatoryEEG,代码行数:9,代码来源:eegService.cs

示例14: GetBufferFromString

 private IBuffer GetBufferFromString(String str)
 {
     using (InMemoryRandomAccessStream memoryStream = new InMemoryRandomAccessStream())
     {
         using (DataWriter dataWriter = new DataWriter(memoryStream))
         {
             dataWriter.WriteString(str);
             return dataWriter.DetachBuffer();
         }
     }
 }
开发者ID:mbin,项目名称:Win81App,代码行数:11,代码来源:Scenario4.xaml.cs

示例15: GetDataIn

        private static byte[] GetDataIn(byte serviceCount, byte[] serviceCodeList, byte blockCount, byte[] blockList)
        {
            DataWriter dataWriter = new DataWriter();

            dataWriter.WriteByte(serviceCount);
            dataWriter.WriteBytes(serviceCodeList);
            dataWriter.WriteByte(blockCount);
            dataWriter.WriteBytes(blockList);

            return dataWriter.DetachBuffer().ToArray();
        }
开发者ID:RasmusTG,项目名称:Windows-universal-samples,代码行数:11,代码来源:FelicaCommands.cs


注:本文中的Windows.Storage.Streams.DataWriter.DetachBuffer方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。