Click or drag to resize

PkUnknown Class

Represents a Loconet packet of an unknown type.
Inheritance Hierarchy

Namespace:  RRAutoLib.Loconet
Assembly:  RRAutoLib (in RRAutoLib.dll) Version: 4.0.8678.28884
Syntax
<SerializableAttribute>
Public Class PkUnknown
	Inherits Packet

The PkUnknown type exposes the following members.

Constructors
  NameDescription
Public methodPkUnknown
Permits instantiation of user derived classes.
Protected methodPkUnknown(SerializationInfo, StreamingContext)
Used to inherit custom serialization from Packet because constructors are not inherited.
Top
Properties
  NameDescription
Public propertyBytes
Gets the bytes that makes up a Loconet packet message.
(Inherited from Packet.)
Public propertyDescription
User friendly description of the packet.
(Overrides PacketDescription.)
Public propertyID
Gets the unique identifier of the packet.
(Inherited from Packet.)
Public propertyIsEchoe
Gets value indicating if the packet is an echoe.
(Inherited from Packet.)
Public propertyNeedsPacketResponse
Gets value indicating if this packet expects a response packet.
(Inherited from Packet.)
Public propertyOpCode
Gets the Loconet operation code associated with the packet.
(Overrides PacketOpCode.)
Public propertyParmsDesc
User friendly description of the most significant packet parameters.
(Overrides PacketParmsDesc.)
Public propertyPostTxWait
Gets or sets the time in milliseconds to wait after sending this packet before performing the next step.
(Inherited from Packet.)
Public propertyRxPacket
Gets the received response packet post transmit.
(Inherited from Packet.)
Public propertyTag
Gets or sets an arbitrary object that is associated with the packet.
(Inherited from Packet.)
Public propertyTimeStamp
Gets an event time stamp of the packet's echo or arrival.
(Inherited from Packet.)
Top
Methods
  NameDescription
Public methodBytesToString
Converts the Bytes into a readable string.
(Inherited from Packet.)
Public methodCode exampleClone
Creates a copy of the packet.
(Inherited from Packet.)
Protected methodGetObjectData (Inherited from Packet.)
Public methodValidPacketResponse
Gets value indicating if given packet is a valid response for this packet.
(Inherited from Packet.)
Top
Fields
  NameDescription
Protected field_blnIsEchoe
Exposed through IsEchoe property.
(Inherited from Packet.)
Protected field_bytaBytes
Exposed through Bytes property.
(Inherited from Packet.)
Protected field_dblTimeStamp
Exposed through TimeStamp property.
(Inherited from Packet.)
Protected field_objRxPacket
Exposed through RxPacket property.
(Inherited from Packet.)
Protected field_objTag
Exposed through Tag property.
(Inherited from Packet.)
Protected field_sctID
Exposed through ID property.
(Inherited from Packet.)
Protected field_srtPostTxWait
Exposed through PostTxWait property.
(Inherited from Packet.)
Top
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:
VB
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(address As UShort)
        'simplify class construction
        Me.New()
        Me.Address = address
    End Sub

    Public Property Address() As UShort
        Get
            'decode parameter from packet bytes
            Dim bits = BitWise.CopyBits(_bytaBytes(3), 0, 7, 0, 0)  'least significant 7 bits
            Return BitWise.CopyBits(_bytaBytes(2), 0, 7, bits, 7)   'most significant 7 bits
        End Get
        Set(value As UShort)
            'encode parameter to packet bytes
            BitWise.CopyBits(value, 0, 7, _bytaBytes(3), 0)     'least significant 7 bits
            BitWise.CopyBits(value, 7, 7, _bytaBytes(2), 0)     'most significant 7 bits
        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(responsePacket As RRAutoLib.Loconet.Packet) As Boolean
        'indicates that this packet expects either a slot read or a long aknoledge as a response packet    
        Return responsePacket.OpCode = OpCodes.SL_RD_DATA OrElse _
               responsePacket.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
See Also