Namespace Frame
    ''' <summary>
    ''' Trame de requête 0x10 (16) : Ecriture de N mots
    ''' </summary>
    ''' <remarks></remarks>
    Public NotInheritable Class ClsFrameModbus16Req
        Inherits ClsFrameModbusWrittingWord

        ''' <summary>
        ''' Mémoride l'offset
        ''' </summary>
        ''' <remarks></remarks>
        Private mOffset As UShort = 0

#Region "Constructeurs"
        ''' <summary>
        ''' Constructeur de la classe
        ''' </summary>
        ''' <param name="pSlaveId">Numéro d'esclave</param>
        ''' <param name="pOffset">Offset des données</param>
        ''' <param name="pData">Données</param>
        ''' <remarks></remarks>
        Public Sub New(ByVal pSlaveId As Byte, ByVal pOffset As UShort, ByVal pData As UShort())
            MyBase.New(pSlaveId, 16, pData)
            mOffset = pOffset
        End Sub
        ''' <summary>
        ''' Constructeur de la classe
        ''' </summary>
        ''' <param name="pSlaveId">Numéro d'esclave</param>
        ''' <param name="pOffset">Offset des données</param>
        ''' <remarks></remarks>
        Public Sub New(ByVal pSlaveId As Byte, ByVal pOffset As UShort)
            MyClass.New(pSlaveId)
            mOffset = pOffset
        End Sub
        ''' <summary>
        ''' Constructeur de la classe
        ''' </summary>
        ''' <param name="pSlaveId">Numéro d'esclave</param>
        ''' <remarks></remarks>
        Public Sub New(ByVal pSlaveId As Byte)
            MyBase.New(pSlaveId, 16)
        End Sub
        ''' <summary>
        ''' Constructeur de la classe
        ''' </summary>
        ''' <param name="pFrame1">Trame à traiter</param>
        ''' <param name="pFrame2">Trame à traiter (copie)</param>
        ''' <remarks></remarks>
        Public Sub New(ByVal pFrame1 As Byte(), ByVal pFrame2 As Byte())
            MyBase.New(pFrame1, pFrame2)
            mOffset = CUShort((CInt(pFrame1(0)) << 8) + pFrame1(1))
        End Sub
#End Region

        ''' <summary>
        ''' Retourne ou définit l'offset des données
        ''' </summary>
        ''' <value></value>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Public Property Offset() As UShort
            Get
                Return mOffset
            End Get
            Set(ByVal value As UShort)
                mOffset = value
            End Set
        End Property

        ''' <summary>
        ''' Retourne la trame Modbus
        ''' </summary>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Friend Overloads Overrides Function GetFrame() As Byte()
            Return MyBase.GetFrame(New Byte() {CByte((mOffset And &HFF00) >> 8), CByte(mOffset And &HFF), CByte((Count And &HFF00) >> 8), CByte(Count And &HFF)}, New Byte() {})
        End Function

        ''' <summary>
        ''' Héritée, retourne l'offset de la longueur des données (1 octet, en octets)
        ''' </summary>
        ''' <value></value>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Protected Overrides ReadOnly Property LengthOffset() As Integer
            Get
                Return 4
            End Get
        End Property

        ''' <summary>
        ''' Retourne le type de trame
        ''' </summary>
        ''' <value></value>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Public Overrides ReadOnly Property FrameType() As ClsFrameModbusBase.EFrameType
            Get
                Return EFrameType.Request
            End Get
        End Property
    End Class
End Namespace
