本文整理汇总了C#中Windows.Storage.Streams.DataWriter.WriteInt16方法的典型用法代码示例。如果您正苦于以下问题:C# DataWriter.WriteInt16方法的具体用法?C# DataWriter.WriteInt16怎么用?C# DataWriter.WriteInt16使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Windows.Storage.Streams.DataWriter
的用法示例。
在下文中一共展示了DataWriter.WriteInt16方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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());
}
示例2: ButtonAction5_Click
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}";
}
}
示例3: ToggleMediaState
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);
}
}
示例4: Send
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());
}
}
示例5: BeepBeep
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;
}
示例6: OnPerformAction
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();
}
}