IPacket.IsEndOfPacket 方法

更新:2007 年 11 月

检查内部迭代器是否已到达数据包的末尾。

命名空间:  Microsoft.SmartDevice.DeviceAgentTransport
程序集:  Microsoft.SmartDevice.DeviceAgentTransport(在 Microsoft.SmartDevice.DeviceAgentTransport.dll 中)

语法

声明
Function IsEndOfPacket As Boolean
用法
Dim instance As IPacket
Dim returnValue As Boolean

returnValue = instance.IsEndOfPacket()
bool IsEndOfPacket()
bool IsEndOfPacket()
function IsEndOfPacket() : boolean

返回值

类型:System.Boolean

如果已到达数据包的末尾,则为 true;如果仍然有剩余的数据包,则为 false。

示例

' 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);
}

权限

另请参见

参考

IPacket 接口

IPacket 成员

Microsoft.SmartDevice.DeviceAgentTransport 命名空间