Represents a Loconet packet of an unknown type.

Namespace: RRAutoLib.Loconet
Assembly: RRAutoLib (in RRAutoLib.dll) Version: 1.4.4420.16901

Syntax

C#
[SerializableAttribute]
public class PkUnknown : Packet
Visual Basic
<SerializableAttribute> _
Public Class PkUnknown _
	Inherits Packet

Remarks

Incoming Loconet packets that are either not natively supported by this API or are corrupt will return this type. To create you own packet classes you must inherit from this class.

Examples

The following is an example of a custom packet class:
CopyVB.NET
Imports RRAutoLib.Loconet

Public Class PkCustom
    Inherits PkUnknown

    Public Sub New()
        'initialize an n byte packet;
        'in this example it is a 4 byte OPS_LOCO_ADR
        _bytaBytes = New Byte(3) {&HBF, 0, 0, 0}
    End Sub

    Public Sub New(ByVal srtAddress As UShort)
        'simplify class construction
        Me.New()
        Me.Address = srtAddress
    End Sub

    Public Property Address() As UShort
        Get
            'decode parameter from packet bytes
            Return (CType(_bytaBytes(1), UShort) << 7) Or _bytaBytes(2)
        End Get
        Set(ByVal Value As UShort)
            'encode parameter to packet bytes
            _bytaBytes(1) = (Value >> 7) And 127
            _bytaBytes(2) = Value And 127
        End Set
    End Property

    Public Overrides ReadOnly Property NeedsPacketResponse() As Boolean
        Get
            'indicates that this packet expects a response
            Return True
        End Get
    End Property

    Public Overrides Function ValidPacketResponse(ByVal objResponsePacket As RRAutoLib.Loconet.Packet) As Boolean
        'indicates that this packet expects either a slot read or a long aknoledge as a response packet    
        Return objResponsePacket.OpCode = OpCodes.SL_RD_DATA Or _
               objResponsePacket.OpCode = OpCodes.LONG_ACK
    End Function

    Public Overrides ReadOnly Property Description() As String
        Get
            'brief description of packet
            Return "My custom packet"
        End Get
    End Property

    Public Overrides ReadOnly Property ParmsDesc() As String
        Get
            'description of decoded packet parameters
            Return "Adr=" & Me.Address
        End Get
    End Property

End Class

Inheritance Hierarchy

System..::..Object
  RRAutoLib.Loconet..::..Packet
    RRAutoLib.Loconet..::..PkUnknown

See Also