Friend NotInheritable Class FrmPrinc

    Private Structure sInjecteur
        Public Command As Boolean
        Public NbTranche As Integer
        Public Taux As Double
        Public Totalisateur As UInteger
    End Structure

    Private Structure sReading
        Public Debit As Integer
        Public TempDef As Boolean
        Public TempInst As Double
        Public TempMoy As Double
        Public PressionInst As Double
        Public PressionMoy As Double
        Public VolumeLoad As UInteger
        Public Volume15 As UInteger
        Public VolumeFuite As UInteger
        Public TotalisateurPrinc As UInteger
        Public Predetermination As UInteger
        Public MV15 As Double

        Public BlendTotalisateur As UInteger
        Public BlendVolume As UInteger
        Public BlendTempInst As Double
        Public BlendTempMoy As Double
        Public BlendTauxReal As Double
        Public BlendTauxSatis As Double

        Public ReleveReq As Boolean
        Public ReleveRep As Boolean

        Public MiscAff As String
        Public MiscIdAutor As Integer
        Public MiscDefaut As Integer
        Public MiscPhaseAutom As Integer
        Public MiscTV As Double
        Public MiscPurge As Boolean
        Public MiscVARC As Boolean
        Public MiscIdBE As UInteger
        Public MiscSim As Integer
        Public MiscEtatMetro As Integer
        Public MiscIdOperation As Integer

        Public QuaisAPI As Boolean
        Public QuaisTerreG As Boolean
        Public QuaisBrasVapeur As Boolean
        Public QuaisDmdLoad As Boolean
        Public QuaisPasserelleG As Boolean
        Public QuaisOrientationG_AntiDebord As Boolean
        Public QuaisBrasBaisseConnecte As Boolean
        Public QuaisDmdProduit As Boolean
        Public QuaisTerreD As Boolean
        Public QuaisDmdLoadD As Boolean
        Public QuaisPasserelleD_BrasRange As Boolean
        Public QuaisOrientationD As Boolean

        Public PlusAutonome As Boolean
        Public PlusEntree1 As Boolean
        Public PlusEntree2 As Boolean
        Public PlusPSL As Boolean
        Public PlusDemandeAck As Boolean
        Public PlusChangementBE As Boolean
        Public PlusRecopieGD As Boolean
        Public PlusRecopiePD As Boolean
        Public PlusPresenceTicket As Boolean

        Public Injecteurs() As sInjecteur
        Public InjVolAdd As UInteger
        Public InjVolCol As UInteger
        Public InjInjAdd As Integer
        Public InjInjCol As Integer

        Public ReadOnly Property GetProp(ByVal pName As String) As String
            Get
                Select Case pName
                    Case "Debit"
                        Return CStr(Debit)
                    Case "TempDef"
                        Return IIf(TempDef, "Vrai", "Faux")
                    Case "TempInst"
                        Return TempInst.ToString("#,##0.0")
                    Case "TempMoy"
                        Return TempMoy.ToString("#,##0.0")
                    Case "PressionInst"
                        Return PressionInst.ToString("#,##0.0")
                    Case "PressionMoy"
                        Return PressionMoy.ToString("#,##0.0")
                    Case "VolumeLoad"
                        Return CStr(VolumeLoad)
                    Case "Volume15"
                        Return CStr(Volume15)
                    Case "VolumeFuite"
                        Return CStr(VolumeFuite)
                    Case "TotalisateurPrinc"
                        Return CStr(TotalisateurPrinc)
                    Case "Predetermination"
                        Return CStr(Predetermination)
                    Case "MV15"
                        Return MV15.ToString("#,##0.0")
                    Case "BlendTotalisateur"
                        Return CStr(BlendTotalisateur)
                    Case "BlendVolume"
                        Return CStr(BlendVolume)
                    Case "BlendTempInst"
                        Return BlendTempInst.ToString("#,##0.0")
                    Case "BlendTempMoy"
                        Return BlendTempMoy.ToString("#,##0.0")
                    Case "BlendTauxReal"
                        Return BlendTauxReal.ToString("#,##0.0")
                    Case "BlendTauxSatis"
                        Return BlendTauxSatis.ToString("#,##0.0")
                    Case "ReleveReq"
                        Return IIF(ReleveReq, "Vrai", "Faux")
                    Case "ReleveRep"
                        Return IIf(ReleveRep, "Vrai", "Faux")
                    Case "MiscAff"
                        Return MiscAff
                    Case "MiscIdAutor"
                        Return CStr(MiscIdAutor)
                    Case "MiscDefaut"
                        Return CStr(MiscDefaut)
                    Case "MiscPhaseAutom"
                        Return CStr(MiscPhaseAutom)
                    Case "MiscTV"
                        Return MiscTV.ToString("#,##0.0")
                    Case "MiscPurge"
                        Return IIF(MiscPurge, "Vrai", "Faux")
                    Case "MiscVARC"
                        Return IIf(MiscVARC, "Vrai", "Faux")
                    Case "MiscIdBE"
                        Return CStr(MiscIdBE)
                    Case "MiscSim"
                        Return CStr(MiscSim)
                    Case "MiscEtatMetro"
                        Return CStr(MiscEtatMetro)
                    Case "MiscIdOperation"
                        Return CStr(MiscIdOperation)
                    Case "QuaisAPI"
                        Return IIF(QuaisAPI, "Vrai", "Faux")
                    Case "QuaisTerreG"
                        Return IIf(QuaisTerreG, "Vrai", "Faux")
                    Case "QuaisBrasVapeur"
                        Return IIf(QuaisBrasVapeur, "Vrai", "Faux")
                    Case "QuaisDmdLoad"
                        Return IIf(QuaisDmdLoad, "Vrai", "Faux")
                    Case "QuaisPasserelleG"
                        Return IIf(QuaisPasserelleG, "Vrai", "Faux")
                    Case "QuaisOrientationG_AntiDebord"
                        Return IIf(QuaisOrientationG_AntiDebord, "Vrai", "Faux")
                    Case "QuaisBrasBaisseConnecte"
                        Return IIf(QuaisBrasBaisseConnecte, "Vrai", "Faux")
                    Case "QuaisDmdProduit"
                        Return IIf(QuaisDmdProduit, "Vrai", "Faux")
                    Case "QuaisTerreD"
                        Return IIf(QuaisTerreD, "Vrai", "Faux")
                    Case "QuaisDmdLoadD"
                        Return IIf(QuaisDmdLoadD, "Vrai", "Faux")
                    Case "QuaisPasserelleD_BrasRange"
                        Return IIf(QuaisPasserelleD_BrasRange, "Vrai", "Faux")
                    Case "QuaisOrientationD"
                        Return IIf(QuaisOrientationD, "Vrai", "Faux")
                    Case "PlusAutonome"
                        Return IIf(PlusAutonome, "Vrai", "Faux")
                    Case "PlusEntree1"
                        Return IIf(PlusEntree1, "Vrai", "Faux")
                    Case "PlusEntree2"
                        Return IIf(PlusEntree2, "Vrai", "Faux")
                    Case "PlusPSL"
                        Return IIf(PlusPSL, "Vrai", "Faux")
                    Case "PlusDemandeAck"
                        Return IIf(PlusDemandeAck, "Vrai", "Faux")
                    Case "PlusChangementBE"
                        Return IIf(PlusChangementBE, "Vrai", "Faux")
                    Case "PlusRecopieGD"
                        Return IIf(PlusRecopieGD, "Vrai", "Faux")
                    Case "PlusRecopiePD"
                        Return IIf(PlusRecopiePD, "Vrai", "Faux")
                    Case "PlusPresenceTicket"
                        Return IIf(PlusPresenceTicket, "Vrai", "Faux")
                    Case "InjVolAdd"
                        Return CStr(InjVolAdd)
                    Case "InjVolCol"
                        Return CStr(InjVolCol)
                    Case "InjInjAdd"
                        Return CStr(InjInjAdd)
                    Case "InjInjCol"
                        Return CStr(InjInjCol)
                    Case "Injecteurs(0)", "Injecteurs(1)", "Injecteurs(2)", "Injecteurs(3)", "Injecteurs(4)", "Injecteurs(5)", "Injecteurs(6)", "Injecteurs(7)"
                        Dim lInject As Integer = CInt(pName.Substring(11, 1))
                        Return String.Format("{0}, NbTranche : {1}, Taux : {2}%, Totalisateur : {3} l", IIF(Injecteurs(lInject).Command, "Cmd", "NCmd"), Injecteurs(lInject).NbTranche, Injecteurs(lInject).Taux, Injecteurs(lInject).Totalisateur)
                    Case Else
#If DEBUG Then
                        Stop
#End If
                        Return "NonDef"
                End Select
            End Get
        End Property

        Public ReadOnly Property IsBoolean(ByVal pName As String) As Boolean
            Get
                Dim lLstFalse As New List(Of String)
                Dim lLstTrue As New List(Of String)

                lLstFalse.AddRange(New String() {"Debit", "TempMoy", "TempInst", "PressionInst", "PressionMoy", "VolumeLoad", "Volume15", "VolumeFuite", "TotalisateurPrinc", "Predetermination", "MV15", "BlendTotalisateur", "BlendVolume", "BlendTempInst", "BlendTempMoy", "BlendTauxReal", "BlendTauxSatis", "MiscAff", "MiscIdAutor", "MiscDefaut", "MiscPhaseAutom", "MiscTV", "MiscIdBE", "MiscSim", "MiscEtatMetro", "MiscIdOperation", "InjVolAdd", "InjVolCol", "InjInjAdd", "InjInjCol", "Injecteurs(0)", "Injecteurs(1)", "Injecteurs(2)", "Injecteurs(3)", "Injecteurs(4)", "Injecteurs(5)", "Injecteurs(6)", "Injecteurs(7)"})

                lLstTrue.AddRange(New String() {"TempDef", "ReleveReq", "ReleveRep", "MiscPurge", "MiscVARC", "QuaisAPI", "QuaisTerreG", "QuaisBrasVapeur", "QuaisDmdLoad", "QuaisPasserelleG", "QuaisOrientationG_AntiDebord", "QuaisBrasBaisseConnecte", "QuaisDmdProduit", "QuaisTerreD", "QuaisDmdLoadD", "QuaisPasserelleD_BrasRange", "QuaisOrientationD", "PlusAutonome", "PlusEntree1", "PlusEntree2", "PlusPSL", "PlusDemandeAck", "PlusChangementBE", "PlusRecopieGD", "PlusRecopiePD", "PlusPresenceTicket"})

                If lLstFalse.Contains(pName) Then
                    Return False
                ElseIf lLstTrue.Contains(pName) Then
                    Return True
                Else
#If DEBUG Then
                    Stop
#End If
                    Return False
                End If
            End Get
        End Property
    End Structure

    Private Structure sWriting
        Public Autorisation As Boolean
    End Structure

    Private Structure sGrid
        Public Fields As String(,)
        Public Group As String

        Public Sub New(ByVal pGroup As String, ByVal pFields As String(,))
            Fields = pFields
            Group = pGroup
        End Sub
    End Structure


    Private mReading As sReading

    Private mWriting As sWriting

    Private mFrameWrite As Modbus.SendingFrame

    'Private WithEvents mCom As New Modbus.Serie.MonitorMaster(4, 9600, IO.Ports.Parity.None, 8, IO.Ports.StopBits.One, "127.0.0.1", 200, 1000, False)
    Private WithEvents mCom As New Modbus.Serie.MonitorMaster(4, 9600, IO.Ports.Parity.None, 8, IO.Ports.StopBits.One, 200, 1000, False)


    Private Sub FrmPrinc_FormClosed(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosedEventArgs) Handles Me.FormClosed
        mCom.Close(True)
    End Sub

    Private Sub FrmPrinc_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        mCom.Open()

        With mWriting
            .Autorisation = False
        End With

        ReDim mReading.Injecteurs(7)

        InitRead()

        TRefresh.Enabled = True
    End Sub

    Private Sub TRefresh_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles TRefresh.Tick
        With DGRead
            For i As Integer = 0 To .RowsCount - 1
                If .Cell(i, 2).Text = "" Then Continue For
                .Cell(i, 3).Text = MiseEnForme(.Cell(i, 1).Text, .Cell(i, 2).Text)
                If mReading.IsBoolean(.Cell(i, 2).Text.Split(","c)(0)) Then
                    .Cell(i, 3).BackColor = IIF(mReading.GetProp(.Cell(i, 2).Text.Split(","c)(0)) = "Vrai", Color.Green, Color.Red)
                End If
            Next
            'TODO : Gestion écriture
        End With
    End Sub

    Private Function MiseEnForme(ByVal pFormat As String, ByVal pFields As String) As String
        Dim ltStr As String() = pFields.Split(","c)

        For i As Integer = 0 To ltStr.GetUpperBound(0)
            ltStr(i) = mReading.GetProp(ltStr(i))
        Next

        Return String.Format(pFormat, ltStr)
    End Function


    Private Function GestRecept(ByVal pSender As Modbus.IAnimCom, ByVal pFrameSend As Modbus.Frame.ClsFrameModbusBase, ByVal pFrameReceive As Modbus.Frame.ClsFrameModbusBase, ByVal pId As Integer) As Modbus.SendingFrame
        Select Case pId
            Case 1
                If pFrameReceive Is Nothing Then Return Nothing

                If pFrameReceive.Function <> 3 Then Return Nothing
                Dim lFrame As Modbus.Frame.ClsFrameModbus03Rep = DirectCast(pFrameReceive, Modbus.Frame.ClsFrameModbus03Rep)

                Dim lQ32 As Boolean

                With mReading
                    'Mot 0
                    .TempDef = Not lFrame.Boolean(0, 0)
                    .QuaisBrasBaisseConnecte = lFrame.Boolean(0, 1)
                    .QuaisPasserelleD_BrasRange = lFrame.Boolean(0, 2)
                    .QuaisPasserelleG = lFrame.Boolean(0, 3)
                    .QuaisOrientationD = lFrame.Boolean(0, 4)
                    .QuaisOrientationG_AntiDebord = lFrame.Boolean(0, 5)
                    .QuaisTerreD = lFrame.Boolean(0, 6)
                    .QuaisTerreG = lFrame.Boolean(0, 7)
                    .QuaisBrasVapeur = lFrame.Boolean(0, 8)
                    .PlusChangementBE = lFrame.Boolean(0, 10)
                    .QuaisDmdProduit = lFrame.Boolean(0, 11)
                    .ReleveReq = lFrame.Boolean(0, 13)
                    .ReleveRep = lFrame.Boolean(0, 14)

                    'Mot 1
                    .MiscDefaut = lFrame.UInt8(1, True)
                    .QuaisDmdLoadD = lFrame.Boolean(1, 8)
                    .QuaisDmdLoad = lFrame.Boolean(1, 9)
                    lQ32 = lFrame.Boolean(1, 14)
                    If Not lQ32 Then
                        If lFrame.Boolean(1, 10) Then
                            .VolumeLoad = &H10000
                        Else
                            .VolumeLoad = 0
                        End If
                        If lFrame.Boolean(1, 11) Then
                            .VolumeFuite = &H10000
                        Else
                            .VolumeFuite = 0
                        End If
                    End If
                    .PlusAutonome = lFrame.Boolean(1, 12)

                    'Mot 2
                    .VolumeLoad = .VolumeLoad Or lFrame.UInt16(2)

                    'Mot 3
                    .VolumeFuite = .VolumeFuite Or lFrame.UInt16(3)

                    'Mot 4
                    .Debit = lFrame.UInt16(4)

                    'Mot 5
                    'If .TempInst >= 0 Then
                    .TempInst = lFrame.UInt16(5) / 10

                    'Mot 6
                    'If .TempMoy >= 0 Then 
                    .TempMoy = lFrame.UInt16(6) / 10

                    'Mots 7-11
                    .MiscAff = lFrame.String(7, 10)

                    'Mot 12
                    .PressionInst = lFrame.UInt16(12) / 10

                    'Mot 13
                    .MV15 = lFrame.UInt16(13) / 10

                    'Mot 14-21
                    For i As Integer = 0 To 7
                        .Injecteurs(i).Taux = lFrame.UInt8(14 + i, True)
                        .Injecteurs(i).NbTranche = lFrame.UInt8(14 + i, False)
                    Next

                    'Mot 22-37
                    For i As Integer = 0 To 7
                        .Injecteurs(i).Totalisateur = lFrame.UInt32(22 + i)
                    Next

                    'Mot 38
                    .MiscPhaseAutom = lFrame.UInt16(38)

                    'Mot 39-40
                    .TotalisateurPrinc = lFrame.UInt32(39)

                    'Mot 42
                    .MiscTV = lFrame.Int16(42) / 10

                    'Mot 43
                    .PlusEntree1 = lFrame.Boolean(43, 0)
                    .PlusEntree2 = lFrame.Boolean(43, 1)
                    .PlusRecopiePD = lFrame.Boolean(43, 2)
                    .PlusRecopieGD = lFrame.Boolean(43, 3)
                    .PlusPSL = lFrame.Boolean(43, 4)
                    .PlusDemandeAck = lFrame.Boolean(43, 5)
                    .MiscPurge = lFrame.Boolean(43, 6)
                    .MiscVARC = lFrame.Boolean(43, 7)
                    .Injecteurs(0).Command = lFrame.Boolean(43, 8)
                    .Injecteurs(1).Command = lFrame.Boolean(43, 9)
                    .Injecteurs(2).Command = lFrame.Boolean(43, 10)
                    .Injecteurs(3).Command = lFrame.Boolean(43, 11)
                    .Injecteurs(4).Command = lFrame.Boolean(43, 12)
                    .Injecteurs(5).Command = lFrame.Boolean(43, 13)
                    .Injecteurs(6).Command = lFrame.Boolean(43, 14)
                    .Injecteurs(7).Command = lFrame.Boolean(43, 15)

                    'Mot 44
                    .Predetermination = lFrame.UInt16(44)

                    'Mot 45
                    If lQ32 Then
                        .VolumeLoad += CUInt(lFrame.UInt16(45)) << 16
                    End If

                    'Mot 46
                    If lQ32 Then
                        .VolumeFuite += CUInt(lFrame.UInt16(46)) << 16
                    End If

                    'Mot 47
                    If lQ32 Then
                        .Predetermination += CUInt(lFrame.UInt16(47)) << 16
                    End If

                    'Mot 48
                    .InjInjAdd = lFrame.UInt8(48, True)
                    .InjInjCol = lFrame.UInt8(48, False)

                    'Mot 49-50
                    .MiscIdBE = lFrame.UInt32(49)

                    'Mot 51-52
                    .InjVolAdd = lFrame.UInt32(51)

                    'Mot 53-54
                    .InjVolCol = lFrame.UInt32(53)

                    'Mot 55
                    .MiscSim = lFrame.UInt16(55)

                    'Mot 56-57
                    If lQ32 Then
                        .Volume15 = lFrame.UInt32(56)
                    Else
                        .Volume15 = lFrame.UInt16(57)
                    End If

                    'Mot 58
                    .PressionMoy = lFrame.UInt16(58) / 10

                    'Mot 59
                    .MiscEtatMetro = lFrame.UInt8(59, True)

                    'Mot 60-61
                    .MiscIdOperation = lFrame.Int32(60)

                    'Mot 62-63
                    .BlendTotalisateur = lFrame.UInt32(62)

                    'Mot 64-65
                    .BlendVolume = lFrame.UInt32(64)

                    'Mot 66
                    .BlendTauxReal = lFrame.UInt16(66) / 100

                    'Mot 67
                    .BlendTauxSatis = lFrame.UInt16(67) / 100

                    'Mot 68
                    .BlendTempInst = lFrame.UInt16(68) / 10

                    'Mot 69
                    .BlendTempMoy = lFrame.UInt16(69) / 10
                End With

                Return Nothing
            Case 2
                'TODO
                Return Nothing
            Case Else
#If DEBUG Then
                Stop
#End If
                Return Nothing
        End Select
    End Function

    Private Sub CmdMaj_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CmdMaj.Click
        With DirectCast(mFrameWrite.FrameSend, Modbus.Frame.ClsFrameModbus16Req)
            'TODO : Envoi
        End With
        mCom.NonCyclicAdd(mFrameWrite, 0)
    End Sub



    Private Sub InitRead()

        Dim lLst As New List(Of sGrid)

        lLst.Add(New sGrid("Standard", New String(,) {{"Debit", "{0} m3/h", "Debit"}, {"TempInst", "{1} °C", "TempDef,TempInst"}, {"TempMoy", "{1} °C", "TempDef,TempMoy"}, {"PressionInst", "{0} bars", "PressionInst"}, {"PressionMoy", "{0} bars", "PressionMoy"}, {"VolumeLoad", "{0} l", "VolumeLoad"}, {"Volume15", "{0} l", "Volume15"}, {"VolumeFuite", "{0} l", "VolumeFuite"}, {"TotalisateurPrinc", "{0} l", "TotalisateurPrinc"}, {"Predetermination", "{0} l", "Predetermination"}, {"MV15", "{0} kg/m3", "MV15"}}))

        lLst.Add(New sGrid("Blending", New String(,) {{"BlendTotalisateur", "{0} l", "BlendTotalisateur"}, {"BlendVolume", "{0} l", "BlendVolume"}, {"BlendTempInst", "{0} °C", "BlendTempInst"}, {"BlendTempMoy", "{0} °C", "BlendTempMoy"}, {"BlendTauxReal", "{0}%", "BlendTauxReal"}, {"BlendTauxSatis", "{0}%", "BlendTauxSatis"}}))

        lLst.Add(New sGrid("Relevé", New String(,) {{"ReleveReq", "{0}", "ReleveReq"}, {"ReleveRep", "{0}", "ReleveRep"}}))

        lLst.Add(New sGrid("Divers", New String(,) {{"MiscAff", "{0}", "MiscAff"}, {"MiscIdAutor", "{0}", "MiscIdAutor"}, {"MiscDefaut", "{0}", "MiscDefaut"}, {"MiscPhaseAutom", "{0}", "MiscPhaseAutom"}, {"MiscTV", "{0} bars", "MiscTV"}, {"MiscPurge", "{0}", "MiscPurge"}, {"MiscVARC", "{0}", "MiscVARC"}, {"MiscIdBE", "{0}", "MiscIdBE"}, {"MiscSim", "{0}", "MiscSim"}, {"MiscEtatMetro", "{0}", "MiscEtatMetro"}, {"MiscIdOperation", "{0}", "MiscIdOperation"}}))

        lLst.Add(New sGrid("Quais", New String(,) {{"QuaisAPI", "{0}", "QuaisAPI"}, {"QuaisTerreG", "{0}", "QuaisTerreG"}, {"QuaisBrasVapeur", "{0}", "QuaisBrasVapeur"}, {"QuaisDmdLoad", "{0}", "QuaisDmdLoad"}, {"QuaisPasserelleG", "{0}", "QuaisPasserelleG"}, {"QuaisOrientationG_AntiDebord", "{0}", "QuaisOrientationG_AntiDebord"}, {"QuaisBrasBaisseConnecte", "{0}", "QuaisBrasBaisseConnecte"}, {"QuaisDmdProduit", "{0}", "QuaisDmdProduit"}, {"QuaisTerreD", "{0}", "QuaisTerreD"}, {"QuaisDmdLoadD", "{0}", "QuaisDmdLoadD"}, {"QuaisPasserelleD_BrasRange", "{0}", "QuaisPasserelleD_BrasRange"}, {"QuaisOrientationD", "{0}", "QuaisOrientationD"}}))

        lLst.Add(New sGrid("Plus", New String(,) {{"PlusAutonome", "{0}", "PlusAutonome"}, {"PlusEntree1", "{0}", "PlusEntree1"}, {"PlusEntree2", "{0}", "PlusEntree2"}, {"PlusPSL", "{0}", "PlusPSL"}, {"PlusDemandeAck", "{0}", "PlusDemandeAck"}, {"PlusChangementBE", "{0}", "PlusChangementBE"}, {"PlusRecopieGD", "{0}", "PlusRecopieGD"}, {"PlusRecopiePD", "{0}", "PlusRecopiePD"}, {"PlusPresenceTicket", "{0}", "PlusPresenceTicket"}}))

        lLst.Add(New sGrid("Injecteurs", New String(,) {{"InjVolAdd", "{0} l", "InjVolAdd"}, {"InjVolCol", "{0} l", "InjVolCol"}, {"InjInjAdd", "{0} l", "InjInjAdd"}, {"InjInjCol", "{0} l", "InjInjCol"}, {"Injecteur 1", "", "Injecteurs(0)"}, {"Injecteur 2", "", "Injecteurs(1)"}, {"Injecteur 3", "", "Injecteurs(2)"}, {"Injecteur 4", "", "Injecteurs(3)"}, {"Injecteur 5", "", "Injecteurs(4)"}, {"Injecteur 6", "", "Injecteurs(5)"}, {"Injecteur 7", "", "Injecteurs(6)"}, {"Injecteur 8", "", "Injecteurs(7)"}}))

        Dim lCount As Integer = 0

        For Each lGroup As sGrid In lLst
            lCount += 1
            lCount += lGroup.Fields.GetLength(0)
        Next

        DGRead.ColsCount = 4
        DGRead.RowsCount = lCount
        DGRead.Col(0).Width = 180
        DGRead.Col(1).Width = 0
        DGRead.Col(2).Width = 0
        DGRead.Col(3).Width = 500

        lCount = 0

        For Each lGroup As sGrid In lLst
            DGRead.Cell(lCount, 0).Text = lGroup.Group
            For i As Integer = 0 To 3
                DGRead.Cell(lCount, i).BackColor = Color.Gray
            Next
            lCount += 1

            For i As Integer = 0 To lGroup.Fields.GetLength(0) - 1
                DGRead.Cell(lCount, 0).Text = lGroup.Fields(i, 0)
                DGRead.Cell(lCount, 1).Text = lGroup.Fields(i, 1)
                DGRead.Cell(lCount, 2).Text = lGroup.Fields(i, 2)
                lCount += 1
            Next
        Next

    End Sub

    Private Sub mCom_StartConnexion(ByVal pSender As Modbus.IAnimCom) Handles mCom.StartConnexion

        Dim lReadFrame As New Modbus.Frame.ClsFrameModbus03Req(1, 0, 70)

        pSender.CyclicAdd(New Modbus.SendingFrame(lReadFrame, New Modbus.SendingFrame.DgtSent(AddressOf GestRecept), Modbus.SendingFrame.ESlaveLock.NoLock, 1, 1))
        pSender.NonCyclicAdd(New Modbus.SendingFrame(New Modbus.Frame.ClsFrameModbus03Req(1, 0, 100), New Modbus.SendingFrame.DgtSent(AddressOf GestRecept), Modbus.SendingFrame.ESlaveLock.NoLock, 1, 2), 0)

        mFrameWrite = New Modbus.SendingFrame(New Modbus.Frame.ClsFrameModbus16Req(1, 0), New Modbus.SendingFrame.DgtSent(AddressOf GestRecept), Modbus.SendingFrame.ESlaveLock.NoLock, 1, 2)
    End Sub
End Class
