本文整理匯總了C#中Windows.Storage.Streams.DataWriter.WriteByte方法的典型用法代碼示例。如果您正苦於以下問題:C# DataWriter.WriteByte方法的具體用法?C# DataWriter.WriteByte怎麽用?C# DataWriter.WriteByte使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Windows.Storage.Streams.DataWriter
的用法示例。
在下文中一共展示了DataWriter.WriteByte方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: 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;
}
示例2: 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();
}
示例3: Start
public override async void Start()
{
if (_Started)
return;
_SequenceNumber = 1;
try
{
// Connect to the Drone
udpClient = new DatagramSocket();
await udpClient.BindServiceNameAsync(_ServiceName);
await udpClient.ConnectAsync(new HostName(DroneClient.Host), _ServiceName);
udpWriter = new DataWriter(udpClient.OutputStream);
udpWriter.WriteByte(1);
await udpWriter.StoreAsync();
_Timer = ThreadPoolTimer.CreatePeriodicTimer(new TimerElapsedHandler(timerElapsedHandler), TimeSpan.FromMilliseconds(25));
_Started = true;
}
catch (Exception)
{
Stop();
}
}
示例4: onewireReset
async Task<bool> onewireReset(string deviceId)
{
try
{
if (serialPort != null)
serialPort.Dispose();
serialPort = await SerialDevice.FromIdAsync(deviceId);
// Configure serial settings
serialPort.WriteTimeout = TimeSpan.FromMilliseconds(1000);
serialPort.ReadTimeout = TimeSpan.FromMilliseconds(1000);
serialPort.BaudRate = 9600;
serialPort.Parity = SerialParity.None;
serialPort.StopBits = SerialStopBitCount.One;
serialPort.DataBits = 8;
serialPort.Handshake = SerialHandshake.None;
dataWriteObject = new DataWriter(serialPort.OutputStream);
dataWriteObject.WriteByte(0xF0);
await dataWriteObject.StoreAsync();
dataReaderObject = new DataReader(serialPort.InputStream);
await dataReaderObject.LoadAsync(1);
byte resp = dataReaderObject.ReadByte();
if (resp == 0xFF)
{
System.Diagnostics.Debug.WriteLine("Nothing connected to UART");
return false;
}
else if (resp == 0xF0)
{
System.Diagnostics.Debug.WriteLine("No 1-wire devices are present");
return false;
}
else
{
System.Diagnostics.Debug.WriteLine("Response: " + resp);
serialPort.Dispose();
serialPort = await SerialDevice.FromIdAsync(deviceId);
// Configure serial settings
serialPort.WriteTimeout = TimeSpan.FromMilliseconds(1000);
serialPort.ReadTimeout = TimeSpan.FromMilliseconds(1000);
serialPort.BaudRate = 115200;
serialPort.Parity = SerialParity.None;
serialPort.StopBits = SerialStopBitCount.One;
serialPort.DataBits = 8;
serialPort.Handshake = SerialHandshake.None;
dataWriteObject = new DataWriter(serialPort.OutputStream);
dataReaderObject = new DataReader(serialPort.InputStream);
return true;
}
}
catch (Exception ex)
{
System.Diagnostics.Debug.WriteLine("Exception: " + ex.Message);
return false;
}
}
示例5: InitializeServiceSdpAttributes
/// <summary>
/// Creates the SDP record that will be revealed to the Client device when pairing occurs.
/// </summary>
/// <param name="rfcommProvider">The RfcommServiceProvider that is being used to initialize the server</param>
private void InitializeServiceSdpAttributes(RfcommServiceProvider rfcommProvider)
{
var sdpWriter = new DataWriter();
// Write the Service Name Attribute.
sdpWriter.WriteByte(Constants.SdpServiceNameAttributeType);
// The length of the UTF-8 encoded Service Name SDP Attribute.
sdpWriter.WriteByte((byte)Constants.SdpServiceName.Length);
// The UTF-8 encoded Service Name value.
sdpWriter.UnicodeEncoding = Windows.Storage.Streams.UnicodeEncoding.Utf8;
sdpWriter.WriteString(Constants.SdpServiceName);
// Set the SDP Attribute on the RFCOMM Service Provider.
rfcommProvider.SdpRawAttributes.Add(Constants.SdpServiceNameAttributeId, sdpWriter.DetachBuffer());
}
示例6: GetFilledReport
public HidOutputReport GetFilledReport()
{
var dataWriter = new DataWriter();
dataWriter.WriteByte(Id);
dataWriter.WriteBytes(Data.Array);
report.Data = dataWriter.DetachBuffer();
return report;
}
示例7: Send
public async Task Send(byte[] data, int length, IPEndPoint iPEndPoint)
{
var stream = await socket.GetOutputStreamAsync(new Windows.Networking.HostName(iPEndPoint.Address.ToString()), iPEndPoint.Port.ToString());
DataWriter writer = new DataWriter(stream);
for (int i = 0; i < length; i++)
writer.WriteByte(data[i]);
await writer.StoreAsync();
}
示例8: SendMotorCommand
public async void SendMotorCommand(Boolean on, int tilt, int forward, int turn, int up, float scale)
{
var characteristics = _service.GetCharacteristics(RollingSpiderCharacteristicUuids.Parrot_PowerMotors);
var characteristic = characteristics[0];
var writer = new DataWriter();
try
{
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());
}
catch (IOException e)
{
Debug.WriteLine(e);
}
//var gattTransaction = new GattReliableWriteTransaction();
//gattTransaction.WriteValue(characteristic, writer.DetachBuffer());
//var status = await gattTransaction.CommitAsync();
//switch (status)
//{
// case GattCommunicationStatus.Success:
// AddLogAction("Writing to your device OK !");
// break;
// case GattCommunicationStatus.Unreachable:
// AddLogAction("Writing to your device Failed !");
// break;
//}
}
示例9: GetBuffer
/// <summary>
/// Packs the current command into contiguous buffer bytes
/// </summary>
/// <returns>
/// buffer holds the current wire/air format of the command
/// </returns>
public IBuffer GetBuffer()
{
using (DataWriter writer = new DataWriter())
{
writer.WriteByte(CLA);
writer.WriteByte(INS);
writer.WriteByte(P1);
writer.WriteByte(P2);
if (CommandData != null && CommandData.Length > 0)
{
writer.WriteByte((byte)CommandData.Length);
writer.WriteBytes(CommandData);
}
if (Le != null)
{
writer.WriteByte((byte)Le);
}
return writer.DetachBuffer();
}
}
示例10: Init
public override async System.Threading.Tasks.Task<SensorBase.InitResult> Init()
{
var r = await base.Init();
if (r == InitResult.Ok)
{
// Lecture des données de calibration
GattCommunicationStatus s;
using (var writer = new DataWriter())
{
writer.WriteByte(2);
s = await pConfigurationCharacteristic.WriteValueAsync(writer.DetachBuffer());
}
if (s == GattCommunicationStatus.Success)
{
var calib = GetCharacteristic(pDeviceService, BAROMETER_CALIBRATION_UUID);
if (calib != null)
{
var result = await calib.ReadValueAsync(BluetoothCacheMode.Uncached);
if (result.Status == GattCommunicationStatus.Success && result.Value.Length == 16)
{
byte[] b = new byte[16];
DataReader wReader = DataReader.FromBuffer(result.Value);
using (wReader)
{
wReader.ReadBytes(b);
}
pBarometerCalibrationData[0] = BitConverter.ToUInt16(b, 0);
pBarometerCalibrationData[1] = BitConverter.ToUInt16(b, 2);
pBarometerCalibrationData[2] = BitConverter.ToUInt16(b, 4);
pBarometerCalibrationData[3] = BitConverter.ToUInt16(b, 6);
pBarometerCalibrationData[4] = BitConverter.ToInt16(b, 8);
pBarometerCalibrationData[5] = BitConverter.ToInt16(b, 10);
pBarometerCalibrationData[6] = BitConverter.ToInt16(b, 12);
pBarometerCalibrationData[7] = BitConverter.ToInt16(b, 14);
}
}
}
}
return r;
}
示例11: Reboot
public async void Reboot(string HostName)
{
HostName remoteHostName = new HostName(HostName);
using (StreamSocket socket = new StreamSocket())
{
socket.Control.KeepAlive = false;
await socket.ConnectAsync(remoteHostName, "6");
using (DataWriter writer = new DataWriter(socket.OutputStream))
{
// set payload length
writer.ByteOrder = ByteOrder.LittleEndian;
writer.WriteUInt32(2);
// set payload type
writer.WriteByte((byte)PayloadType.Byte);
// set payload
writer.WriteByte(0x01);
// transmit
await writer.StoreAsync();
writer.DetachStream();
}
}
}
示例12: button_Click
private async void button_Click(object sender, RoutedEventArgs e)
{
// Find all paired instances of the Rfcomm chat service
try {
using (chatSocket = new StreamSocket())
{
await chatSocket.ConnectAsync(new HostName(textBoxIp.Text), "5000");
var stream = chatSocket.OutputStream;
chatWriter = new DataWriter(stream);
chatWriter.WriteByte(1);
await chatWriter.StoreAsync();
}
}catch(Exception ex)
{
var dialog = new MessageDialog(ex.Message);
await dialog.ShowAsync();
}
}
示例13: SendDataAync
private async Task SendDataAync(byte data)
{
try
{
var ip = ApplicationData.Current.LocalSettings.Values["address"].ToString();
using (chatSocket = new StreamSocket())
{
await chatSocket.ConnectAsync(new HostName(ip), "5000");
var stream = chatSocket.OutputStream;
chatWriter = new DataWriter(stream);
chatWriter.WriteByte(data);
await chatWriter.StoreAsync();
}
}
catch (Exception ex)
{
var dialog = new MessageDialog(ex.Message);
await dialog.ShowAsync();
}
}
示例14: WriteString
public async void WriteString(string HostName, string Message)
{
HostName remoteHostName = new HostName(HostName);
using (StreamSocket socket = new StreamSocket())
{
socket.Control.KeepAlive = false;
await socket.ConnectAsync(remoteHostName, "6");
using (DataWriter writer = new DataWriter(socket.OutputStream))
{
// set payload length
writer.ByteOrder = ByteOrder.LittleEndian;
writer.WriteUInt32(writer.MeasureString(Message));
// set payload type
writer.WriteByte((byte)PayloadType.String);
// set payload
writer.WriteString(Message);
// transmit
await writer.StoreAsync();
writer.DetachStream();
}
using (DataReader reader = new DataReader(socket.InputStream))
{
int length;
string response;
// receive payload length
reader.ByteOrder = ByteOrder.LittleEndian;
await reader.LoadAsync(4);
length = reader.ReadInt32();
// receive payload
await reader.LoadAsync((uint)length);
response = reader.ReadString((uint)length);
Debug.WriteLine(string.Format("response: {0}", response));
reader.DetachStream();
}
}
}
示例15: Start
public override async void Start()
{
if (_Started)
return;
_SequenceNumber = 1;
// Connect To Drone
udpClient = new DatagramSocket();
await udpClient.BindServiceNameAsync(_ServiceName);
await udpClient.ConnectAsync(new HostName(DroneClient.Host), _ServiceName);
udpWriter = new DataWriter(udpClient.OutputStream);
//string path = string.Format("AR.Drone-CommandHistory_{0:yyyy-MM-dd-HH-mm}.txt", DateTime.Now);
//commandHistoryFile = await ApplicationData.Current.TemporaryFolder.CreateFileAsync(path, CreationCollisionOption.ReplaceExisting);
// Write first message
//byte[] firstMessage = BitConverter.GetBytes(1);
//WriteString(firstMessage.ToString());
udpWriter.WriteByte(1);
await udpWriter.StoreAsync();
_Timer = ThreadPoolTimer.CreatePeriodicTimer(new TimerElapsedHandler(timerElapsedHandler), TimeSpan.FromMilliseconds(25));
_Started = true;
}