Packet.ReadByte Method

Reads a byte from the Packet object and points the internal iterator to the next data object in the packet.

Namespace:  Microsoft.SmartDevice.Connectivity
Assembly:  Microsoft.SmartDevice.Connectivity (in Microsoft.SmartDevice.Connectivity.dll)

Syntax

'Declaration
Public Function ReadByte As Byte
'Usage
Dim instance As Packet 
Dim returnValue As Byte 

returnValue = instance.ReadByte()
public byte ReadByte()
public:
unsigned char ReadByte()
public function ReadByte() : byte

Return Value

Type: System.Byte
The byte read from the packet.

Exceptions

Exception Condition
InvalidOperationException

Thrown when one or more of the following conditions are true:

  • The packet's current data object is not of type Byte.

  • A read operation is tried after reaching end of packet.

Remarks

When the last data object in the packet is read, the method sets the packet's end-of-packet (EOP) flag to true and increments the iterator. The next call to the Read method throws an InvalidOperationException. Users should always check for EOP before calling Read.

Examples

' While stream is connected, try to read a packet. 
While ps.IsConnected()
    If ps.IsPacketAvailable() Then
        packet = ps.Read()
        While Not packet.IsEndOfPacket()
            Select Case packet.ReadDataType()
                Case DataType.BoolType
                    Dim boolValue As Boolean = packet.ReadBool()
                Case DataType.ByteArrayType
                    Dim buffer As Byte() = packet.ReadBytes()
                Case DataType.ByteType
                    Dim byteValue As Byte = packet.ReadByte()
                Case DataType.CharType
                    Dim charValue As Char = packet.ReadChar()
                Case DataType.Int32Type
                    Console.WriteLine("Int32Type:  " + packet.ReadInt32().ToString())
                Case DataType.StringType
                    Console.WriteLine("String:  " + packet.ReadString())
                Case Else 
            End Select 
        End While 
        Exit While 
    End If
    System.Threading.Thread.Sleep(1000)
End While
ps.Close()
device.Disconnect()
// While stream is connected, try to read a packet. 
while (ps.IsConnected())
{
    if (ps.IsPacketAvailable())
    {
        packet = ps.Read();
        while (!packet.IsEndOfPacket())
        {
            switch (packet.ReadDataType())
            {
                case DataType.BoolType:
                    bool boolValue = packet.ReadBool();
                    break;
                case DataType.ByteArrayType:
                    byte[] buffer = packet.ReadBytes();
                    break;
                case DataType.ByteType:
                    byte byteValue = packet.ReadByte();
                    break;
                case DataType.CharType:
                    char charValue = packet.ReadChar();
                    break;
                case DataType.Int32Type:
                    Console.WriteLine("Int32Type:  " + packet.ReadInt32().ToString());
                    break;
                case DataType.StringType:
                    Console.WriteLine("String:  " + packet.ReadString());
                    break;
                default:
                    break;
            }
        }
        break;
    }
    System.Threading.Thread.Sleep(1000);
}
ps.Close();
device.Disconnect();

.NET Framework Security

See Also

Reference

Packet Class

Packet Members

Microsoft.SmartDevice.Connectivity Namespace