/// <summary> /// Writes a specified number of bytes to the serial port using data from a buffer. /// </summary> /// <param name="buffer">The byte array that contains the data to write to the port.</param> /// <param name="offset">The zero-based byte offset in the buffer parameter at which to begin copying bytes to the port.</param> /// <param name="count">The number of bytes to write.</param> /// <remarks> /// ArgumentException: offset plus count is greater than the length of the buffer. /// </remarks> public Windows.Foundation.IAsyncAction Write( Windows.Storage.Streams.IBuffer buffer, uint offset, uint count ) { var outputStream = this.cdcData.BulkOutPipes[0].OutputStream; var writer = new Windows.Storage.Streams.DataWriter(outputStream); return(Task.Run(async() => { // Overflow check. if ((int)buffer.Length < (offset + count)) { throw new System.ArgumentException("Capacity of buffer is not enough."); } writer.WriteBuffer(buffer, offset, count); var written = await writer.StoreAsync(); return; } ).AsAsyncAction()); }
/// <summary> /// Writes a specified number of bytes to the serial port using data from a buffer. /// </summary> /// <param name="buffer">The byte array that contains the data to write to the port.</param> /// <param name="offset">The zero-based byte offset in the buffer parameter at which to begin copying bytes to the port.</param> /// <param name="count">The number of bytes to write.</param> /// <remarks> /// ArgumentException: offset plus count is greater than the length of the buffer. /// </remarks> public Windows.Foundation.IAsyncAction Write( Windows.Storage.Streams.IBuffer buffer, uint offset, uint count ) { var outputStream = this.cdcData.BulkOutPipes[0].OutputStream; var writer = new Windows.Storage.Streams.DataWriter(outputStream); return Task.Run(async () => { // Overflow check. if ((int)buffer.Length < (offset + count)) { throw new System.ArgumentException("Capacity of buffer is not enough."); } writer.WriteBuffer(buffer, offset, count); var written = await writer.StoreAsync(); return; } ).AsAsyncAction(); }