IPacket.ReadByte-Methode
Aktualisiert: November 2007
Liest ein Byte aus dem Objekt und verweist den internen Iterator auf das nächste Datenobjekt im Paket.
Namespace: Microsoft.SmartDevice.DeviceAgentTransport
Assembly: Microsoft.SmartDevice.DeviceAgentTransport (in Microsoft.SmartDevice.DeviceAgentTransport.dll)
Syntax
Function ReadByte As Byte
Dim instance As IPacket
Dim returnValue As Byte
returnValue = instance.ReadByte()
byte ReadByte()
unsigned char ReadByte()
function ReadByte() : byte
Rückgabewert
Typ: System.Byte
Das aus dem Paket gelesene Byte.
Beispiele
' Check for a packet while communication stream is connected.
While packetStream.IsConnected()
' If a packet is found, display the string and integer data.
If packetStream.IsPacketAvailable() Then
packetStream.Read(packet)
Dim sb As New StringBuilder()
While Not packet.IsEndOfPacket()
Select Case packet.ReadDataType()
Case DataType.BoolType
Dim boolValue As Boolean = packet.ReadBool()
Case DataType.ByteArrayType
' Read bytes and convert IntPtr to byte[]
Dim ptr As IntPtr
Dim size As System.UInt32 = 0
packet.ReadBytes(ptr, size)
Dim buffer As Byte() = InteropUtils.ConvertIntPtrToByteArray(ptr, _
Convert.ToInt32(size))
Case DataType.ByteType
Dim byteValue As Byte = packet.ReadByte()
Case DataType.CharType
Dim charValue As Char = packet.ReadChar()
Case DataType.Int32Type
sb.Append("Int32Type: " + packet.ReadInt32().ToString() + _
vbCr + vbLf)
Case DataType.StringType
sb.Append("String: " + packet.ReadString() + vbCr + vbLf)
Case Else
End Select
End While
MessageBox.Show(sb.ToString())
Exit While
End If
System.Threading.Thread.Sleep(1000)
End While
// Check for a packet while communication stream is connected.
while (packetStream.IsConnected())
{
// If a packet is found, display the string and integer data.
if (packetStream.IsPacketAvailable())
{
packetStream.Read(out packet);
StringBuilder sb = new StringBuilder();
while (!packet.IsEndOfPacket())
{
switch (packet.ReadDataType())
{
case DataType.BoolType:
bool boolValue = packet.ReadBool();
break;
case DataType.ByteArrayType:
// Read bytes and convert IntPtr to byte[]
IntPtr ptr;
uint size = 0;
packet.ReadBytes(out ptr, out size);
byte[] buffer = InteropUtils.ConvertIntPtrToByteArray(ptr,
Convert.ToInt32(size));
break;
case DataType.ByteType:
byte byteValue = packet.ReadByte();
break;
case DataType.CharType:
char charValue = packet.ReadChar();
break;
case DataType.Int32Type:
sb.Append("Int32Type: " + packet.ReadInt32().ToString() + "\r\n");
break;
case DataType.StringType:
sb.Append("String: " + packet.ReadString() + "\r\n");
break;
default:
break;
}
}
MessageBox.Show(sb.ToString());
break;
}
System.Threading.Thread.Sleep(1000);
}
Berechtigungen
- Volle Vertrauenswürdigkeit für den unmittelbaren Aufrufer. Dieser Member kann von nur teilweise vertrauenswürdigem Code nicht verwendet werden. Weitere Informationen finden Sie unter Verwenden von Bibliotheken aus teilweise vertrauenswürdigem Code.