'#Uses "..\classes\FunctionClass.cls
'#Uses "..\classes\ParameterClass.cls
'#Uses "..\include\Const.inc"
'#Uses "..\include\Format.inc"
'#Uses "..\include\Global.inc"
'#Uses "..\include\Pages.inc"
'#Uses "Include.inc"

Option Explicit
'*****************************************************************************
' Module:
'        CAN
'-----------------------------------------------------------------------------
' Description:
'        This file contains functions which are create controls for the
'        module 'CAN'.
'        Furthermore it contains functions for the event handling of
'        these controls.
'
'-----------------------------------------------------------------------------
' History:
'                 
'        Rev. Author         Date        Description
'        ---------------------------------------------------------------------
'        1.0  ste            25.05.00    final version for TC1775A
'        1.1  ste            20.07.00    the TC1775B has a new Loop-Back mode;
'                                        4 new function added
'        1.2  ste            02.11.00    1 new function added
'                                        
'        ---------------------------------------------------------------------
'        3.0  ahe            05.11.01    final version for Pegasus
'
'        3.1  ahe            08.08.02    - neu interrupt pages
'        3.2  ste            24.02.03    caption for module clock changed
'                            06.03.03    frmHint on page SRNs added
'
'*****************************************************************************


'*****************************************************************************
'Description:
'        This function is called from DAvE just before the Peripherals
'        window is shown.
'-----------------------------------------------------------------------------
'Parameters:
'        ps              reference to the Peripherals object
'-----------------------------------------------------------------------------
'Returns:
'        True            on successfull operation
'        False           else
'*****************************************************************************
Function OnLoad(ps As Peripherals) As Boolean
    On Error GoTo OnLoadError

    OnLoad = False

    '-------------------------------------------------------------------------
    ' page: Module Clock
    '-------------------------------------------------------------------------
    If (Not OnLoadPageModuleClock(ps)) Then Exit Function

    '-------------------------------------------------------------------------
    ' page: Control
    '-------------------------------------------------------------------------
    If (Not OnLoadPageControl(ps)) Then Exit Function

    '-------------------------------------------------------------------------
    ' page: SRNs
    '-------------------------------------------------------------------------
    If (Not OnLoadPageSRNs(ps)) Then Exit Function

    '-------------------------------------------------------------------------
    ' page: Interrupts
    '-------------------------------------------------------------------------
    If (Not OnLoadPageInterrupts_32(ps, 0)) Then Exit Function

    '-------------------------------------------------------------------------
    ' page: Interrupts
    '-------------------------------------------------------------------------
    If (Not OnLoadPageInterrupts_32(ps, 1)) Then Exit Function

    '-------------------------------------------------------------------------
    ' page: PEC
    '-------------------------------------------------------------------------
    If (Not OnLoadPagePEC(ps)) Then Exit Function

    '-------------------------------------------------------------------------
    ' page: Functions
    '-------------------------------------------------------------------------
    If (Not OnLoadPageFunctions(ps)) Then Exit Function

    '-------------------------------------------------------------------------
    ' page: Parameters
    '-------------------------------------------------------------------------
    If (Not OnLoadPageParameters(ps)) Then Exit Function

    '-------------------------------------------------------------------------
    ' page: Notes
    '-------------------------------------------------------------------------
    If (Not OnLoadPageNotes(ps)) Then Exit Function

    '-------------------------------------------------------------------------
    ' End of pages
    '-------------------------------------------------------------------------
    
    ' call function to initialize the menu
    If (Not InitMenu(ps, "CAN\Dialog")) Then Exit Function

    OnLoad = True
    Exit Function

OnLoadError:
    Exit Function
End Function


'*****************************************************************************
'Description:
'        This function is called from DAvE just before a page
'        is shown.
'-----------------------------------------------------------------------------
'Parameters:
'        ps              reference to the Peripherals object
'        Page            no. of the page (starts with 1)
'        Pagename        name of the page
'-----------------------------------------------------------------------------
'Returns:
'        True            on successfull operation
'        False           else
'*****************************************************************************
Function OnChangingPage(ps As Peripherals, Page As Integer, Pagename As String) As Boolean
    On Error Goto OnChangingPageError

    Dim vIndex As Variant
    Dim sVarPre As String 

    vIndex = ps.Parameters.v("x")   
    sVarPre = "CAN" & vIndex

    OnChangingPage = False

    '-------------------------------------------------------------------------
    'page: Module Clock
    '-------------------------------------------------------------------------
    If (Not OnChangingPageModuleClock (ps, Pagename)) Then Exit Function

    '-------------------------------------------------------------------------
    'page: Control
    '-------------------------------------------------------------------------
    If (Not OnChangingPageControl(ps, Pagename)) Then Exit Function

    '-------------------------------------------------------------------------
    'page: SRNs
    '-------------------------------------------------------------------------
    If (Not OnChangingPageSRNs(ps, Pagename)) Then Exit Function

    '-------------------------------------------------------------------------
    'page: Interrupts
    '-------------------------------------------------------------------------
    If (Not OnChangingPageInterrupts_32 (ps, Pagename, 0)) Then Exit Function

    '-------------------------------------------------------------------------
    'page: Interrupts
    '-------------------------------------------------------------------------
    If (Not OnChangingPageInterrupts_32 (ps, Pagename, 1)) Then Exit Function

    '-------------------------------------------------------------------------
    'page: PEC
    '-------------------------------------------------------------------------
    If (Not OnChangingPagePEC (ps, Pagename)) Then Exit Function

    '-------------------------------------------------------------------------
    'page: Functions
    '-------------------------------------------------------------------------
    If (Not OnChangingPageFunctions (ps, Pagename)) Then Exit Function

    '-------------------------------------------------------------------------
    'page: Parameters
    '-------------------------------------------------------------------------
    If (Not OnChangingPageParameters (ps, Pagename)) Then Exit Function

    '-------------------------------------------------------------------------
    'page: Notes
    '-------------------------------------------------------------------------
    If (Not OnChangingPageNotes (ps, Pagename, sVarPre)) Then Exit Function


    OnChangingPage = True
    Exit Function

OnChangingPageError:
    Exit Function
End Function


'*****************************************************************************
'Description:
'        This function is called from DAvE in two cases:
'
'        1.
'            The contents of the peripherals window must be refreshed.
'            In this case the 'Controlname' parameter is a empty string
'            and the values array 'v()' contains nothing.
'
'        2.
'            A control on the peripherals has been changed.
'            In this case the 'Controlname' parameter contains the name
'            of the changed control and the values array 'v()' contains the
'            changed value(s).
'
'-----------------------------------------------------------------------------
'Parameters:
'        ps              reference to the Peripherals object
'        Controlname     name of the changed control (for case 2)
'        v()             array with the changed values (for case 2)
'        Page            no. of the page (starts with 1)
'        Pagename        name of the page
'-----------------------------------------------------------------------------
'Returns:
'        True            on successfull operation
'        False           else
'*****************************************************************************
Function OnShow(ps As Peripherals, Controlname As String, v() As Variant, Page As Integer, Pagename As String) As Boolean
    On Error GoTo OnShowError

    Dim vIndex As Variant
    Dim sVarPre As String 

    vIndex = ps.Parameters.v("x")   
    sVarPre = "CAN" & vIndex

    OnShow = False

    '-------------------------------------------------------------------------
    ' page: Module Clock
    '-------------------------------------------------------------------------
    If (Not OnShowPageModuleClock(ps, Controlname, Pagename, v)) Then Exit Function

    '-------------------------------------------------------------------------
    ' page: Control
    '-------------------------------------------------------------------------
    If (Not OnShowPageControl(ps, Controlname, Pagename, v)) Then Exit Function

    '-------------------------------------------------------------------------
    ' page: SRNs
    '-------------------------------------------------------------------------
    If (Not OnShowPageSRNs(ps, Controlname, Pagename, v)) Then Exit Function

    '-------------------------------------------------------------------------
    ' page: Interrupts
    '-------------------------------------------------------------------------
    If (Not OnShowPageInterrupts_32(ps, Controlname, v, sVarPre, Pagename, 0)) Then Exit Function

    '-------------------------------------------------------------------------
    ' page: Interrupts
    '-------------------------------------------------------------------------
    If (Not OnShowPageInterrupts_32(ps, Controlname, v, sVarPre, Pagename, 1)) Then Exit Function

    '-------------------------------------------------------------------------
    ' page: PEC
    '-------------------------------------------------------------------------
    If (Not OnShowPagePEC(ps, Controlname, v, Pagename)) Then Exit Function

    '-------------------------------------------------------------------------
    ' page: Functions
    '-------------------------------------------------------------------------
    If (Not OnShowPageFunctions(ps, Controlname, Pagename, v)) Then Exit Function

    '-------------------------------------------------------------------------
    ' page: Parameters
    '-------------------------------------------------------------------------
    If (Not OnShowPageParameters(ps, Controlname, Pagename, v)) Then Exit Function 
       
    '-------------------------------------------------------------------------
    ' page: Notes
    '-------------------------------------------------------------------------
    If (Not OnShowPageNotes(ps, Controlname, Pagename, sVarPre, v)) Then Exit Function


    OnShow = True
    Exit Function

OnShowError:
    Exit Function
End Function


'*****************************************************************************
'Description:
'        This function is called from DAvE if the user clicks on a button.
'-----------------------------------------------------------------------------
'Parameters:
'        ps              reference to the Peripherals object
'        Controlname     name of the button
'-----------------------------------------------------------------------------
'Returns:
'        True            on successfull operation
'        False           else
'*****************************************************************************
Function OnClick(ps As Peripherals, Controlname As String) As Boolean
    On Error GoTo OnClickError

    OnClick = False

    '-------------------------------------------------------------------------
    ' buttons: PEC
    '-------------------------------------------------------------------------
    If (Not OnClickPagePEC(ps, Controlname)) Then Exit Function

    '-------------------------------------------------------------------------
    ' Page : Control
    '-------------------------------------------------------------------------
    If (Not OnButtonClickOnPageControl(ps, Controlname)) Then Exit Function 

    OnClick = True
    Exit Function

OnClickError:
    Errorbox "Can not process the click", Err.Description
    Exit Function
End Function


'*****************************************************************************
'Description:
'        This function is called from DAvE if the user clicks on a menu entry.
'-----------------------------------------------------------------------------
'Parameters:
'        ps              reference to the Peripherals object
'        Toolname        name of the entry
'        ToolId          id of the entry
'        Tooltext        additional text of the entry
'-----------------------------------------------------------------------------
'Returns:
'        True            on successfull operation
'        False           else
'*****************************************************************************
Function OnMenuClick(ps As Peripherals, Toolname As String, ToolId As Long, Tooltext As String) As Boolean
    On Error GoTo OnMenuClickError

    OnMenuClick = False

    If (Not MenuClick(ps, Toolname, ToolId, Tooltext, "CAN\Dialog")) Then Exit Function

    OnMenuClick = True
    Exit Function

OnMenuClickError:
    Exit Function
End Function


'-----------------------------------------------------------------------------
' local functions
'-----------------------------------------------------------------------------

'*****************************************************************************
'Description:
'        This function is called from the OnLoad function of the associated
'        module in order to add the page 'ModuleClock'.
'-----------------------------------------------------------------------------
'Parameters:
'        ps               reference to the Peripherals object
'-----------------------------------------------------------------------------
'Returns:
'        True            on successfull operation
'        False           else
'*****************************************************************************
Public Function OnLoadPageModuleClock(ps As Object) As Boolean
  On Error Resume Next

  OnLoadPageModuleClock = False

  If (Not ps.AddPage("Module Clock")) Then Exit Function

  OnLoadPageModuleClock = True
End Function



'*****************************************************************************
'Description:
'        This function is called from the OnChangingPage function of the
'        associated module in order load all controls for the requested page
'        if they are not already loaded.
'-----------------------------------------------------------------------------
'Parameters:
'        ps               reference to the Peripherals object
'        Pagename         requested page name
'-----------------------------------------------------------------------------
'Returns:
'        True            on successfull operation
'        False           else
'*****************************************************************************
Function OnChangingPageModuleClock(ps As Object, Pagename As String) As Boolean
  On Error Resume Next

  OnChangingPageModuleClock = False
  Dim sVarPre As String
  Dim vIndex  As Variant
  Dim r       As ProjectData

  vIndex = ps.Parameters.v("x")
  sVarPre = "CAN" & vIndex
  
  Set r = ps.ProjectData

  If (Not ps.ExtenderCollection("Module Clock").Loaded) And (Pagename = "Module Clock") Then
    ps.ExtenderCollection("Module Clock").Loaded = True
  

    '-------------------------------
    ' frame: frmDISx
    '-------------------------------
    If (Not ps.AddFrame("frmDISx",100,100, 5400, 1375, sVarPre & " Disabled Flag (CANDIS)")) Then Exit Function
        If (Not ps.AddOption("optDISx_0", 200, 350, 4800, 300, "Enable module; the peripheral is supplied with the clock signal")) Then Exit Function
        If (Not ps.AddOption("optDISx_1", 200, 825, 4800, 300, "Disable module; the clock input of peripheral is disabled")) Then Exit Function

    '-------------------------------
    ' frame: frmInputClock
    '-------------------------------
    If (Not ps.AddFrame("frmInputClock",100,1600, 5400, 1000, "Input Clock")) Then Exit Function
        If (Not ps.AddLabel("lbl_txt_InputClock", 0, 200, 450, 3225, 300, "Input clock of the " & sVarPre & " module [MHz]")) Then Exit Function
        If (Not ps.AddLabel("lbl_box_InputClock", 1, 3550, 400, 1000, 300, "")) Then Exit Function

  End If
  OnChangingPageModuleClock = True
End Function



'*****************************************************************************
'Description:
'        This function is called from the OnShow function of the associated
'        module. See the description for the OnShow function of the
'        associated module for details.
'-----------------------------------------------------------------------------
'Parameters:
'        ps              reference to the Peripherals object
'        Controlname     control name
'        Pagename        current page name
'        v()             value array
'-----------------------------------------------------------------------------
'Returns:
'        True            on successfull operation
'        False           else
'*****************************************************************************
Public Function OnShowPageModuleClock(ps As Object, Controlname As String, Pagename As String, v() As Variant) As Boolean
  On Error GoTo OnShowPageModuleClockError

  OnShowPageModuleClock = False

  Dim r         As ProjectData
  Dim c         As Object
  Dim e         As Object
  Dim bDisabled As Boolean
  Dim sVarPre   As String
  Dim vIndex    As Variant
  Dim sRegPre   As String
  Dim i         As Integer

  vIndex = ps.Parameters.v("x")
  sVarPre = "CAN" & vIndex
  sRegPre = sVarPre & "_"

  Set r = ps.ProjectData
  Set c = ps.ControlCollection
  Set e = ps.ExtenderCollection

  If (Pagename = "Module Clock") Then
    '-------------------------------------------------------------------------
    ' page: ModuleClock (action)
    '-------------------------------------------------------------------------
    Select Case (Controlname)
        '---------------------------------------------------------------------
        ' control: optDISx_0 (action)
        '---------------------------------------------------------------------
        Case "optDISx_0"
             r.v("SYSCON3_CANDIS") = 0

        '---------------------------------------------------------------------
        ' control: optDISx_1 (action)
        '---------------------------------------------------------------------
        Case "optDISx_1"
             r.v("SYSCON3_CANDIS") = 1
             Call SelectPinInterface(r, vindex, "A", "Tx", 7)
             Call SelectPinInterface(r, vindex, "A", "Rx", 7)
             Call SelectPinInterface(r, vindex, "B", "Tx", 7)
             Call SelectPinInterface(r, vindex, "B", "Rx", 7)
             Call DisableNodex(r, vIndex, "A")
             Call DisableNodex(r, vIndex, "B")
             Call UpdateCAN(r, vIndex, "A")
             Call UpdateCAN(r, vIndex, "B")
             Call DisableSRNs(r, vIndex)
             r.v(sVarPre & "_USE_Init") = 0


      Case Else
    End Select

    '-------------------------------------------------------------------------
    ' page: ModuleClock (show)
    '-------------------------------------------------------------------------

    '-------------------------------------------------------------------------
    ' control: optDISx_0 (show)
    '-------------------------------------------------------------------------
    With c("optDISx_0")
      bDisabled = False
      .Enabled = Not(bDisabled)
      .Value = -CInt(r.v("SYSCON3_CANDIS") = 0)
    End With

    With e("optDISx_0")
      If (bDisabled) Then
        .DisabledTooltipText = TOOLTIP_DISABLED_IF
        .DisabledTooltipText = .DisabledTooltipText & FormatDisabledTooltip("")
      End If
    End With

    '-------------------------------------------------------------------------
    ' control: optDISx_1 (show)
    '-------------------------------------------------------------------------
    With c("optDISx_1")
      bDisabled = False
      .Enabled = Not(bDisabled)
      .Value = -CInt(r.v("SYSCON3_CANDIS") = 1)
    End With

    With e("optDISx_1")
      If (bDisabled) Then
        .DisabledTooltipText = TOOLTIP_DISABLED_IF
        .DisabledTooltipText = .DisabledTooltipText & FormatDisabledTooltip("")
      End If
    End With

    '-------------------------------------------------------------------------
    ' control: lbl_txt_InputClock (show)
    '-------------------------------------------------------------------------
    With c("lbl_txt_InputClock")
      bDisabled = (IsModuleClockDisabled(r, vIndex))
      .Enabled = Not(bDisabled)
    End With

    With e("lbl_txt_InputClock")
      If (bDisabled) Then
        .DisabledTooltipText = TOOLTIP_DISABLED_IF
        If (IsModuleClockDisabled(r, vIndex)) Then
          .DisabledTooltipText = .DisabledTooltipText & GetTooltipModuleClockDisabled(r, vIndex)
        End If
      End If
    End With

    '-------------------------------------------------------------------------
    ' control: lbl_box_InputClock (show)
    '-------------------------------------------------------------------------
    With c("lbl_box_InputClock")
      bDisabled = (IsModuleClockDisabled(r, vIndex))
      .Enabled = Not(bDisabled)
      If (GetCANModuleClock(r, vIndex) > GetMaxSystemClock(r)) Then
          .Caption = TO_HIGH
      Else
          .Caption = GetCANModuleClock(r, vIndex)
      End If
    End With

    With e("lbl_box_InputClock")
      If (bDisabled) Then
        .DisabledTooltipText = TOOLTIP_DISABLED_IF
        If (IsModuleClockDisabled(r, vIndex)) Then
          .DisabledTooltipText = .DisabledTooltipText & GetTooltipModuleClockDisabled(r, vIndex)
        End If
      End If
    End With


  End If

  OnShowPageModuleClock = True
  Exit Function

OnShowPageModuleClockError:
  Errorbox "Can not show page", Err.Description
  Exit Function
End Function


'*****************************************************************************
'Description:
'        This function is called from the OnLoad function of the associated
'        module in order to add the page 'Control'.
'-----------------------------------------------------------------------------
'Parameters:
'        ps               reference to the Peripherals object
'-----------------------------------------------------------------------------
'Returns:
'        True            on successfull operation
'        False           else
'*****************************************************************************
Public Function OnLoadPageControl(ps As Object) As Boolean
  On Error Resume Next

  OnLoadPageControl = False

  If (Not ps.AddPage("Control")) Then Exit Function

  OnLoadPageControl = True
End Function



'*****************************************************************************
'Description:
'        This function is called from the OnChangingPage function of the
'        associated module in order load all controls for the requested page
'        if they are not already loaded.
'-----------------------------------------------------------------------------
'Parameters:
'        ps               reference to the Peripherals object
'        Pagename         requested page name
'-----------------------------------------------------------------------------
'Returns:
'        True            on successfull operation
'        False           else
'*****************************************************************************
Function OnChangingPageControl(ps As Object, Pagename As String) As Boolean
  On Error Resume Next

  Dim i As Integer

  OnChangingPageControl = False
  
  If (Not ps.ExtenderCollection("Control").Loaded) And (Pagename = "Control") Then
    ps.ExtenderCollection("Control").Loaded = True
  
    '-------------------------------
    ' frame: frmNode
    '-------------------------------
    If (Not ps.AddFrame("frmNode",100,100, 8400, 1000, "CAN Nodes")) Then Exit Function
        If (Not ps.AddButton("btnNode0", 3300, 400, 900, 380, "Node A")) Then Exit Function
        If (Not ps.AddButton("btnNode1", 4300, 400, 900, 380, "Node B")) Then Exit Function

    '-------------------------------
    ' frame: frmLBM
    '-------------------------------
    If (Not ps.AddFrame("frmLBM",100,1250, 8400, 1000, "Loop-Back Mode")) Then Exit Function
        If (Not ps.AddCheck("chkLBM", 200, 400, 4350, 300, "Enable the Loop-Back mode for node A and B (LBM)")) Then Exit Function

    '-------------------------------
    ' frame: frmOBJ
    '-------------------------------
    If (Not ps.AddFrame("frmOBJ",100,2400, 8400, 2500, "CAN Message Objects (OBJ)")) Then Exit Function
      For i = 0 To 31
        If (Not ps.AddButton("btnObj" & i, 300 + (i Mod 8) * 1000, 400 + (i\8) * 500, 900, 380, "OBJ " & i)) Then Exit Function
      Next i

  End If
  OnChangingPageControl = True
End Function



'*****************************************************************************
'Description:
'        This function is called from the OnShow function of the associated
'        module. See the description for the OnShow function of the
'        associated module for details.
'-----------------------------------------------------------------------------
'Parameters:
'        ps              reference to the Peripherals object
'        Controlname     control name
'        Pagename        current page name
'        v()             value array
'-----------------------------------------------------------------------------
'Returns:
'        True            on successfull operation
'        False           else
'*****************************************************************************
Public Function OnShowPageControl(ps As Object, Controlname As String, Pagename As String, v() As Variant) As Boolean
  On Error GoTo OnShowPageControlError

  OnShowPageControl = False

  Dim r As ProjectData
  Dim c As Object
  Dim e As Object
  Dim bDisabled As Boolean
  Dim vIndex As Variant
  Dim sVarPre As String
  Dim sRegPre As String
  Dim i As Integer
  Dim d As String

  vIndex = ps.Parameters.v("x")   
  sVarPre = "CAN" & vIndex
  sRegPre = sVarPre & "_"

  Set r = ps.ProjectData
  Set c = ps.ControlCollection
  Set e = ps.ExtenderCollection

  If (Pagename = "Control") Then
    '-------------------------------------------------------------------------
    ' page: Control (action)
    '-------------------------------------------------------------------------
    Select Case (Controlname)

        '---------------------------------------------------------------------
        ' control: chkLBM (action)
        '---------------------------------------------------------------------
        Case "chkLBM"
             r.v(sRegPre & "ABTRH_LBM") = v(1)
             r.v(sRegPre & "BBTRH_LBM") = v(1)

    Case Else
    End Select

    '-------------------------------------------------------------------------
    ' page: Control (show)
    '-------------------------------------------------------------------------

    '-------------------------------------------------------------------------
    ' frame: frmNode (show)
    '-------------------------------------------------------------------------
    bDisabled = IsModuleClockDisabled(r, vIndex)
    ' tooltip if control is disabled 
    d = TOOLTIP_DISABLED_IF
    d = d & GetTooltipModuleClockDisabled(r, vIndex)
    Call SetDefaultPropertiesForAllControlsOnFrame(c("frmNode").Caption, c, e, bDisabled, d, "")

    '-------------------------------------------------------------------------
    ' control: btnNode0 (show)
    '-------------------------------------------------------------------------
    With c("btnNode0")
    End With

    '-------------------------------------------------------------------------
    ' control: btnNode1 (show)
    '-------------------------------------------------------------------------
    With c("btnNode1")
    End With

    '-------------------------------------------------------------------------
    ' control: chkLBM (show)
    '-------------------------------------------------------------------------
    With c("chkLBM")
      bDisabled = IsModuleClockDisabled(r, vIndex) Or _
                  (r.v(sRegPre & "ACR_INIT") = 1 Or r.v(sRegPre & "BCR_INIT") = 1)
      .Enabled = Not(bDisabled)
      ' show condition
      .Value = -CInt((r.v(sRegPre & "ABTRH_LBM") = 1) And (r.v(sRegPre & "BBTRH_LBM") = 1))
    End With

    With e("chkLBM")
      If (bDisabled) Then
        ' tooltip if control is disabled 
        .DisabledTooltipText = TOOLTIP_DISABLED_IF
        .DisabledToolTipText = .DisabledToolTipText & GetTooltipModuleClockDisabled(r, vIndex)
        If (r.v(sRegPre & "ACR_INIT") = 1) Then
          .DisabledToolTipText = .DisabledToolTipText & FormatDisabledTooltip("the " & sVarPre & " node A is deselected")
        End If
        If (r.v(sRegPre & "BCR_INIT") = 1) Then
          .DisabledToolTipText = .DisabledToolTipText & FormatDisabledTooltip("the " & sVarPre & " node B is deselected")
        End If
      Else
        ' tooltip if control is enabled 
      End If
    End With


    '-------------------------------------------------------------------------
    ' frame: frmOBJ (show)
    '-------------------------------------------------------------------------
    bDisabled = IsModuleClockDisabled(r, vIndex) Or _
                (r.v(sRegPre & "ACR_INIT") = 1 And r.v(sRegPre & "BCR_INIT") = 1)
    ' tooltip if control is disabled 
    d = TOOLTIP_DISABLED_IF
    d = d & GetTooltipModuleClockDisabled(r, vIndex)
    If (r.v(sRegPre & "ACR_INIT") = 1 And r.v(sRegPre & "BCR_INIT") = 1) Then
      d = d & FormatDisabledTooltip("both " & sVarPre & " nodes (A and B) are deselected")
    End If
    Call SetDefaultPropertiesForAllControlsOnFrame(c("frmOBJ").Caption, c, e, bDisabled, d, "")


    '-------------------------------------------------------------------------
    ' control: btnObj0 (show)
    '-------------------------------------------------------------------------
    With c("btnObj0")
    End With


  End If

  OnShowPageControl = True
  Exit Function

OnShowPageControlError:
  Errorbox "Can not show page", Err.Description
  Exit Function
End Function


'*****************************************************************************
'Description:
'        This function is called from the OnClick function of the associated
'        module if a button on the page 'Control' will be clicked.
'-----------------------------------------------------------------------------
'Parameters:
'        ps              reference to the Peripherals object
'        Controlname     control name of the button
'-----------------------------------------------------------------------------
'Returns:
'        True            on successfull operation
'        False           else
'*****************************************************************************
Public Function OnButtonClickOnPageControl(ps As Object, Controlname As String) As Boolean
  On Error GoTo OnButtonClickOnPageControlError

  OnButtonClickOnPageControl = False

  Dim np As Peripherals
  Dim vIndex As Variant
  Dim sVarPre As String
  Dim sRegPre As String
  Dim j As Integer
  Dim s As String

  vIndex = ps.Parameters.v("x")   
  sVarPre = "CAN" & vIndex
  sRegPre = sVarPre & "_"

  '------------------------------------------------------------------------------------
  ' btnNodex (click)   (x = 0-1)
  '------------------------------------------------------------------------------------
  s = "A"
  For j = 0 To 1
    If (Controlname = "btnNode" & j) Then
      Set np = New Peripherals
      np.Parameters.Add ("x")
      np.Parameters.v("x") = vIndex
      np.Parameters.Add ("Number")
      np.Parameters.v("Number") = s
      Set np.ProjectData = ps.ProjectData
      np.Caption = "Configure " & sVarPre & " Node " & s
      np.Scriptfile = DefGetPath("Scripts") & "\CAN\Nodex.DAVE"
      np.Show

  		' only for the test scripts
      On Error Resume Next
   		' STE ObjectCollection.Add np, sVarPre & "_NODE" & j
      On Error GoTo OnButtonClickOnPageControlError
    End If
    s = "B"
  Next j

  '------------------------------------------------------------------------------------
  ' btnObjx (click)   (x = 0-31)
  '------------------------------------------------------------------------------------
  For j = 0 To 31
    If (Controlname = "btnObj" & j) Then
      Set np = New Peripherals
      np.Parameters.Add ("x")
      np.Parameters.v("x") = vIndex
      np.Parameters.Add ("Number")
      np.Parameters.v("Number") = j
      Set np.ProjectData = ps.ProjectData
      np.Caption = "Configure " & sVarPre & " Message Object (OBJ" & j & ")"
      np.Scriptfile = DefGetPath("Scripts") & "\CAN\Objx.DAVE"
      np.Show

  		' only for the test scripts
      On Error Resume Next
   		' STE ObjectCollection.Add np, sVarPre & "_OBJ" & j
      On Error GoTo OnButtonClickOnPageControlError

      Exit For
    End If
  Next j

  OnButtonClickOnPageControl = True
  Exit Function

OnButtonClickOnPageControlError:
  Errorbox "Can not process the click", Err.Description
  Exit Function
End Function


'*****************************************************************************
'Description:
'        This function is called from the OnLoad function of the associated
'        module in order to add the page 'SRNs'.
'-----------------------------------------------------------------------------
'Parameters:
'        ps               reference to the Peripherals object
'-----------------------------------------------------------------------------
'Returns:
'        True            on successfull operation
'        False           else
'*****************************************************************************
Public Function OnLoadPageSRNs(ps As Object) As Boolean
  On Error Resume Next

  OnLoadPageSRNs = False

  If (Not ps.AddPage("SRNs")) Then Exit Function

  OnLoadPageSRNs = True
End Function


'*****************************************************************************
'Description:
'        This function is called from the OnChangingPage function of the
'        associated module in order load all controls for the requested page
'        if they are not already loaded.
'-----------------------------------------------------------------------------
'Parameters:
'        ps               reference to the Peripherals object
'        Pagename         requested page name
'-----------------------------------------------------------------------------
'Returns:
'        True            on successfull operation
'        False           else
'*****************************************************************************
Function OnChangingPageSRNs(ps As Object, Pagename As String) As Boolean
  On Error Resume Next
  Dim i As Integer

  OnChangingPageSRNs = False
  
  If (Not ps.ExtenderCollection("SRNs").Loaded) And (Pagename = "SRNs") Then
    ps.ExtenderCollection("SRNs").Loaded = True
  
    '-------------------------------
    ' frame: frmSRN
    '-------------------------------
    If (Not ps.AddFrame("frmSRN",100,100, 8400, 3200, "TwinCAN Service Request Node Enable Control")) Then Exit Function
      For i = 0 To 7
        If (Not ps.AddCheck("chkSRC" & i, 200, 250 + i * 350, 4500, 380, "Enable the TwinCAN service request node " & i & " (SRE)")) Then Exit Function
      Next i
    '-------------------------------
    ' frame: frmHint
    '-------------------------------
    If (Not ps.AddFrame("frmHint",100,3400, 8400, 850, "Note:")) Then Exit Function
        If (Not ps.AddLabel("txtHint", 0, 200, 350, 8000, 300, CAPTION_LBL_PEC_HINT)) Then Exit Function

  End If
  OnChangingPageSRNs = True
End Function


'*****************************************************************************
'Description:
'        This function is called from the OnShow function of the associated
'        module. See the description for the OnShow function of the
'        associated module for details.
'-----------------------------------------------------------------------------
'Parameters:
'        ps              reference to the Peripherals object
'        Controlname     control name
'        Pagename        current page name
'        v()             value array
'-----------------------------------------------------------------------------
'Returns:
'        True            on successfull operation
'        False           else
'*****************************************************************************
Public Function OnShowPageSRNs(ps As Object, Controlname As String, Pagename As String, v() As Variant) As Boolean
  On Error GoTo OnShowPageSRNsError

  OnShowPageSRNs = False

  Dim r As ProjectData
  Dim c As Object
  Dim e As Object
  Dim bDisabled As Boolean
  Dim vIndex As Variant
  Dim sVarPre As String
  Dim sRegPre As String
  Dim i As Integer
  Dim d As String

  vIndex = ps.Parameters.v("x")   
  sVarPre = "CAN" & vIndex
  sRegPre = sVarPre & "_"

  Set r = ps.ProjectData
  Set c = ps.ControlCollection
  Set e = ps.ExtenderCollection

  If (Pagename = "SRNs") Then
    '-------------------------------------------------------------------------
    ' page: SRNs (action)
    '-------------------------------------------------------------------------
    For i = 0 To 7
        If (Controlname = "chkSRC" & i) Then
            If (v(1) = 1) Then
                If (i = 7) Then
                    r.v("CAN_IntEN") = 1
                    Call EnableSRN(r, sVarPre, sRegPre & i & "IC", "SRN" & i)
                Else
                    Call EnableSRN(r, sVarPre, sRegPre & i & "IC", "SRN" & i)
                End If
            Else
                If (i = 7) Then
                    r.v("CAN_IntEN") = 0
                    
                    If (r.Exist("SDLM_PISEL_I1SEL") = True) Then
                        If (r.v("SDLM_PISEL_I1SEL") = 0) Then
                            Call DisableSRN(r, sVarPre, sRegPre & i & "IC", "SRN" & i)
                        End If
                    Else
                        Call DisableSRN(r, sVarPre, sRegPre & i & "IC", "SRN" & i)
                    End If

                Else
                    Call DisableSRN(r, sVarPre, sRegPre & i & "IC", "SRN" & i)
                End If
            End If
            Exit For
        End If
    Next i

    '-------------------------------------------------------------------------
    ' page: SRNs (show)
    '-------------------------------------------------------------------------
    For i = 0 To 7
      With c("chkSRC" & i)
        bDisabled = IsModuleClockDisabled(r, vIndex) Or (r.v(sRegPre & "ACR_INIT") = 1 And r.v(sRegPre & "BCR_INIT") = 1)
        .Enabled = Not(bDisabled)
        ' show condition
        If (i = 7) Then
          .Value = -CInt(r.v(sRegPre & i & "IC_IE") = 1 And r.v("CAN_IntEN") = 1)
        Else
          .Value = -CInt(r.v(sRegPre & i & "IC_IE") = 1)
        End If
      End With

      With e("chkSRC" & i)
        If (bDisabled) Then
          ' tooltip if control is disabled 
          .DisabledTooltipText = TOOLTIP_DISABLED_IF
          .DisabledToolTipText = .DisabledToolTipText & GetTooltipModuleClockDisabled(r, vIndex)
          If (r.v(sRegPre & "ACR_INIT") = 1 And r.v(sRegPre & "BCR_INIT") = 1) Then
            .DisabledToolTipText = .DisabledToolTipText & FormatDisabledTooltip("both " & sVarPre & " nodes (A and B) are deselected")
          End If
        Else
          ' tooltip if control is enabled 
        End If
      End With
    Next i

  End If

  OnShowPageSRNs = True
  Exit Function

OnShowPageSRNsError:
  Errorbox "Can not show page", Err.Description
  Exit Function
End Function


'*****************************************************************************
'Description:
'        This function is called from the OnLoad function of the associated
'        module in order to add a page.
'-----------------------------------------------------------------------------
'Parameters:
'        ps               reference to the Peripherals object
'-----------------------------------------------------------------------------
'Returns:
'        True            on successfull operation
'        False           else
'*****************************************************************************
Public Function OnLoadPageFunctions(ps As Peripherals) As Boolean
  On Error Resume Next
  OnLoadPageFunctions = False

  If (Not ps.AddPage("Functions")) Then Exit Function

  OnLoadPageFunctions = True
End Function


'*****************************************************************************
'Description:
'        This function is called from the OnChangingPage function of the
'        associated module in order load all controls for the requested page
'        if they are not already loaded.
'-----------------------------------------------------------------------------
'Parameters:
'        ps               reference to the Peripherals object
'        Pagename         requested page name
'-----------------------------------------------------------------------------
'Returns:
'        True            on successfull operation
'        False           else
'*****************************************************************************
Public Function OnChangingPageFunctions(ps As Peripherals, Pagename As String) As Boolean
  On Error Resume Next
  OnChangingPageFunctions = False

  Dim vIndex As Variant
  Dim sVarPre As String
  Dim n As String
  Dim i As Integer
  Dim aFunctions(1 To 16) As String

  vIndex = ps.Parameters.v("x")   
  sVarPre = "CAN" & vIndex


  If (Not ps.ExtenderCollection("Functions").Loaded) And (Pagename = "Functions") Then
    ps.ExtenderCollection("Functions").Loaded = True

    '-------------------------------
    ' frame: fra_Init
    '-------------------------------
    If (Not ps.AddFrame("fra_Init", 100 , 100, 4150, 700, CAPTION_FRA_USE_INIT)) Then Exit Function
      If (Not ps.AddCheck("chk_Init", 150, 275, 200, 275, "")) Then Exit Function
      If (Not ps.AddText("txt_Init", 400, 250, 3600, 325)) Then Exit Function

    '-------------------------------
    ' frame: fra_CFile
    '-------------------------------
    If (Not ps.AddFrame("fra_CFile", 4400 , 100, 4150, 700, CAPTION_FRA_CFILE)) Then Exit Function
      If (Not ps.AddText("txt_CFile", 1475, 250, 2500, 325)) Then Exit Function
      If (Not ps.AddLabel("lbl_CFile", 0, 200, 275, 1250, 275, CAPTION_LBL_CFILE)) Then Exit Function

    '-------------------------------
    ' frame: fraLibrary1
    '-------------------------------
    ' initialize the array
    For i = Lbound(aFunctions) To Ubound(aFunctions)
      aFunctions(i) = ""
    Next i

    ' Functions and Macros
    i = Lbound(aFunctions)
    aFunctions(i) = "GetMsgObj"
    i = i + 1
    aFunctions(i) = "RequestMsgObj"
    i = i + 1
    aFunctions(i) = "NewData"
    i = i + 1
    aFunctions(i) = "Transmit"
    i = i + 1
    aFunctions(i) = "ConfigMsgObj"
    i = i + 1
    aFunctions(i) = "LoadData"
    i = i + 1
    aFunctions(i) = "DelMsgObj"
    i = i + 1
    aFunctions(i) = "MsgLost"
    i = i + 1
    aFunctions(i) = "ReleaseObj"
    i = i + 1
    aFunctions(i) = "SetMSGVAL"
    i = i + 1
    aFunctions(i) = "WriteFIFO"
    i = i + 1
    aFunctions(i) = "ReadFIFO"
    i = i + 1
    aFunctions(i) = "FlushReadFIFO"

    If (Not ps.AddFrame("fraLibrary1", 100 , 900, 4150, 4400, CAPTION_FRA_LIBRARY1)) Then Exit Function
      For i = Lbound(aFunctions) To Ubound(aFunctions)
        If Not(aFunctions(i) = "") Then
          If (Not ps.AddCheck("chk_" & aFunctions(i), 150, 325 + (300 * (i - 1)), 200, 275, "")) Then Exit Function
          If (Not ps.AddText("txt_" & aFunctions(i), 400, 300 + (300 * (i - 1)), 3600, 325)) Then Exit Function
        End If
      Next i

    '-------------------------------
    ' frame: fraLibrary2
    '-------------------------------
    ' initialize the array
    For i = Lbound(aFunctions) To Ubound(aFunctions)
      aFunctions(i) = ""
    Next i

    ' Functions and Macros
    i = Lbound(aFunctions)
    aFunctions(i) = "SRN0"
    i = i + 1
    aFunctions(i) = "SRN1"
    i = i + 1
    aFunctions(i) = "SRN2"
    i = i + 1
    aFunctions(i) = "SRN3"
    i = i + 1
    aFunctions(i) = "SRN4"
    i = i + 1
    aFunctions(i) = "SRN5"
    i = i + 1
    aFunctions(i) = "SRN6"
    i = i + 1
    aFunctions(i) = "SRN7"
    i = i + 1
    i = i + 1
    aFunctions(i) = "GetTxErrorCounter"
    i = i + 1
    aFunctions(i) = "GetRxErrorCounter"
    i = i + 1
    aFunctions(i) = "GetErrorTransferDirection"
    i = i + 1
    aFunctions(i) = "GetErrorIncrement"

    If (Not ps.AddFrame("fraLibrary2", 4400 , 900, 4150, 4400, CAPTION_FRA_LIBRARY2)) Then Exit Function
      For i = Lbound(aFunctions) To Ubound(aFunctions)
        If Not(aFunctions(i) = "") Then
          If (Not ps.AddCheck("chk_" & aFunctions(i), 150, 325 + (300 * (i - 1)), 200, 275, "")) Then Exit Function
          If (Not ps.AddText("txt_" & aFunctions(i), 400, 300 + (300 * (i - 1)), 3600, 325)) Then Exit Function
        End If
      Next i

  End If

  OnChangingPageFunctions = True
End Function


'*****************************************************************************
'Description:
'        This function is called from the OnShow function of the associated
'        module. See the description for the OnShow function of the
'        associated module for details.
'-----------------------------------------------------------------------------
'Parameters:
'        ps              reference to the Peripherals object
'        Controlname     control name
'        Pagename        current page name
'        v()             value array
'-----------------------------------------------------------------------------
'Returns:
'        True            on successfull operation
'        False           else
'*****************************************************************************
Public Function OnShowPageFunctions(ps As Peripherals, Controlname As String, Pagename As String, v() As Variant) As Boolean
  On Error Goto OnShowPageFunctionsError
  OnShowPageFunctions = False
    
  Dim r As ProjectData
  Dim c As Collection
  Dim e As Collection
  Dim bDisabled As Boolean
  Dim func As FunctionClass
  Dim sName As String
  Dim vIndex As Variant
  Dim sVarPre As String
  Dim sRegPre As String
  Dim d As String
  Dim i As Integer
  Dim sFctName As String

  vIndex = ps.Parameters.v("x")   
  sVarPre = "CAN" & vIndex
  sRegPre = sVarPre & "_"

  Set r = ps.ProjectData
  Set c = ps.ControlCollection
  Set e = ps.ExtenderCollection
  Set func = New FunctionClass

  If (Pagename = "Functions") Then

    '-------------------------------------------------------------------------
    ' page: Functions (action)
    '-------------------------------------------------------------------------
    RefreshFunctionDescriptions(vIndex, func, r)

    If (Not UpdateFunction(sVarPre, ps, func , Controlname, v)) Then Exit Function

    '-------------------------------------------------------------------------
    ' page: Functions (show)
    '-------------------------------------------------------------------------
    Set func = New FunctionClass
    RefreshFunctionDescriptions(vIndex, func, r)

    sName = sVarPre & "_NAME_Init" 
    ' disable condition
    func.Disabled(sName) = IsModuleClockDisabled(r, vIndex) Or (r.v(sRegPre & "ACR_INIT") = 1 And r.v(sRegPre & "BCR_INIT") = 1)
    ' tooltip if control is disabled
    d = GetDisabledFunctionToolTipEntry(func, sName)
    d = d & GetTooltipModuleClockDisabled(r, vIndex)
    If (r.v(sRegPre & "ACR_INIT") = 1 And r.v(sRegPre & "BCR_INIT") = 1) Then
      d = d & FormatDisabledToolTip("both " & sVarPre & " nodes are disabled")
    End If
    func.DisabledToolTip(sName) = d

    For i = 0 To 7
      sFctName = "SRN" & i
      sName = sVarPre & "_NAME_" & sFctName
      ' disable condition
      func.Disabled(sName) = True
      ' tooltip if control is disabled
      d = TOOLTIP_DISABLED_ISR32
      func.DisabledToolTip(sName) = d
      ' value for the control
      func.Value(sName) = IsISRSelected(r, sVarPre, sRegPre & i & "IC", "SRN" & i)
    Next i

    sFctName = "GetMsgObj"
    sName = sVarPre & "_NAME_" & sFctName
    ' disable condition
    func.Disabled(sName) = (r.v(sVarPre & "_USE_Init") = 0)
    ' tooltip if control is disabled
    d = GetDisabledFunctionToolTipEntry(func, sName)
    If (r.v(sVarPre & "_USE_Init") = 0) Then 
      d = d & FormatDisabledToolTip(TOOLTIP_DESELECTED_INIT)
    End If
    func.DisabledToolTip(sName) = d

    sFctName = "RequestMsgObj"
    sName = sVarPre & "_NAME_" & sFctName
    ' disable condition
    func.Disabled(sName) = (r.v(sVarPre & "_USE_Init") = 0)
    ' tooltip if control is disabled
    d = GetDisabledFunctionToolTipEntry(func, sName)
    If (r.v(sVarPre & "_USE_Init") = 0) Then 
      d = d & FormatDisabledToolTip(TOOLTIP_DESELECTED_INIT)
    End If
    func.DisabledToolTip(sName) = d

    sFctName = "NewData"
    sName = sVarPre & "_NAME_" & sFctName
    ' disable condition
    func.Disabled(sName) = (r.v(sVarPre & "_USE_Init") = 0)
    ' tooltip if control is disabled
    d = GetDisabledFunctionToolTipEntry(func, sName)
    If (r.v(sVarPre & "_USE_Init") = 0) Then 
      d = d & FormatDisabledToolTip(TOOLTIP_DESELECTED_INIT)
    End If
    func.DisabledToolTip(sName) = d

    sFctName = "Transmit"
    sName = sVarPre & "_NAME_" & sFctName
    ' disable condition
    func.Disabled(sName) = (r.v(sVarPre & "_USE_Init") = 0)
    ' tooltip if control is disabled
    d = GetDisabledFunctionToolTipEntry(func, sName)
    If (r.v(sVarPre & "_USE_Init") = 0) Then 
      d = d & FormatDisabledToolTip(TOOLTIP_DESELECTED_INIT)
    End If
    func.DisabledToolTip(sName) = d

    sFctName = "ConfigMsgObj"
    sName = sVarPre & "_NAME_" & sFctName
    ' disable condition
    func.Disabled(sName) = (r.v(sVarPre & "_USE_Init") = 0)
    ' tooltip if control is disabled
    d = GetDisabledFunctionToolTipEntry(func, sName)
    If (r.v(sVarPre & "_USE_Init") = 0) Then 
      d = d & FormatDisabledToolTip(TOOLTIP_DESELECTED_INIT)
    End If
    func.DisabledToolTip(sName) = d

    sFctName = "LoadData"
    sName = sVarPre & "_NAME_" & sFctName
    ' disable condition
    func.Disabled(sName) = (r.v(sVarPre & "_USE_Init") = 0)
    ' tooltip if control is disabled
    d = GetDisabledFunctionToolTipEntry(func, sName)
    If (r.v(sVarPre & "_USE_Init") = 0) Then 
      d = d & FormatDisabledToolTip(TOOLTIP_DESELECTED_INIT)
    End If
    func.DisabledToolTip(sName) = d

    sFctName = "DelMsgObj"
    sName = sVarPre & "_NAME_" & sFctName
    ' disable condition
    func.Disabled(sName) = (r.v(sVarPre & "_USE_Init") = 0)
    ' tooltip if control is disabled
    d = GetDisabledFunctionToolTipEntry(func, sName)
    If (r.v(sVarPre & "_USE_Init") = 0) Then 
      d = d & FormatDisabledToolTip(TOOLTIP_DESELECTED_INIT)
    End If
    func.DisabledToolTip(sName) = d

    sFctName = "MsgLost"
    sName = sVarPre & "_NAME_" & sFctName
    ' disable condition
    func.Disabled(sName) = (r.v(sVarPre & "_USE_Init") = 0)
    ' tooltip if control is disabled
    d = GetDisabledFunctionToolTipEntry(func, sName)
    If (r.v(sVarPre & "_USE_Init") = 0) Then 
      d = d & FormatDisabledToolTip(TOOLTIP_DESELECTED_INIT)
    End If
    func.DisabledToolTip(sName) = d

    sFctName = "ReleaseObj"
    sName = sVarPre & "_NAME_" & sFctName
    ' disable condition
    func.Disabled(sName) = (r.v(sVarPre & "_USE_Init") = 0)
    ' tooltip if control is disabled
    d = GetDisabledFunctionToolTipEntry(func, sName)
    If (r.v(sVarPre & "_USE_Init") = 0) Then 
      d = d & FormatDisabledToolTip(TOOLTIP_DESELECTED_INIT)
    End If
    func.DisabledToolTip(sName) = d

    sFctName = "SetMSGVAL"
    sName = sVarPre & "_NAME_" & sFctName
    ' disable condition
    func.Disabled(sName) = (r.v(sVarPre & "_USE_Init") = 0)
    ' tooltip if control is disabled
    d = GetDisabledFunctionToolTipEntry(func, sName)
    If (r.v(sVarPre & "_USE_Init") = 0) Then 
      d = d & FormatDisabledToolTip(TOOLTIP_DESELECTED_INIT)
    End If
    func.DisabledToolTip(sName) = d


    sFctName = "WriteFIFO"
    sName = sVarPre & "_NAME_" & sFctName
'    If (CAN_WORKAROUND_2) Then
'      func.Disabled(sName) = True
'      d = FormatNormalTooltip("This function is not implemented")
'    Else
      ' disable condition
      func.Disabled(sName) = (r.v(sVarPre & "_USE_Init") = 0)
      ' tooltip if control is disabled
      d = GetDisabledFunctionToolTipEntry(func, sName)
      If (r.v(sVarPre & "_USE_Init") = 0) Then 
        d = d & FormatDisabledToolTip(TOOLTIP_DESELECTED_INIT)
      End If
'    End If
    func.DisabledToolTip(sName) = d

    sFctName = "ReadFIFO"
    sName = sVarPre & "_NAME_" & sFctName
 '   If (CAN_WORKAROUND_2) Then
 '     func.Disabled(sName) = True
 '     d = FormatNormalTooltip("This function is not implemented")
 '   Else
      ' disable condition
      func.Disabled(sName) = (r.v(sVarPre & "_USE_Init") = 0)
      ' tooltip if control is disabled
      d = GetDisabledFunctionToolTipEntry(func, sName)
      If (r.v(sVarPre & "_USE_Init") = 0) Then 
        d = d & FormatDisabledToolTip(TOOLTIP_DESELECTED_INIT)
      End If
 '   End If
    func.DisabledToolTip(sName) = d

    sFctName = "FlushReadFIFO"
    sName = sVarPre & "_NAME_" & sFctName
'    If (CAN_WORKAROUND_2) Then
'      func.Disabled(sName) = True
'      d = FormatNormalTooltip("This function is not implemented")
'    Else
      ' disable condition
      func.Disabled(sName) = (r.v(sVarPre & "_USE_Init") = 0)
      ' tooltip if control is disabled
      d = GetDisabledFunctionToolTipEntry(func, sName)
      If (r.v(sVarPre & "_USE_Init") = 0) Then 
        d = d & FormatDisabledToolTip(TOOLTIP_DESELECTED_INIT)
      End If
'    End If
    func.DisabledToolTip(sName) = d


    sFctName = "GetTxErrorCounter"
    sName = sVarPre & "_NAME_" & sFctName
    ' disable condition
    func.Disabled(sName) = (r.v(sVarPre & "_USE_Init") = 0)
    ' tooltip if control is disabled
    d = GetDisabledFunctionToolTipEntry(func, sName)
    If (r.v(sVarPre & "_USE_Init") = 0) Then 
      d = d & FormatDisabledToolTip(TOOLTIP_DESELECTED_INIT)
    End If
    func.DisabledToolTip(sName) = d

    sFctName = "GetRxErrorCounter"
    sName = sVarPre & "_NAME_" & sFctName
    ' disable condition
    func.Disabled(sName) = (r.v(sVarPre & "_USE_Init") = 0)
    ' tooltip if control is disabled
    d = GetDisabledFunctionToolTipEntry(func, sName)
    If (r.v(sVarPre & "_USE_Init") = 0) Then 
      d = d & FormatDisabledToolTip(TOOLTIP_DESELECTED_INIT)
    End If
    func.DisabledToolTip(sName) = d

    sFctName = "GetErrorTransferDirection"
    sName = sVarPre & "_NAME_" & sFctName
    ' disable condition
    func.Disabled(sName) = (r.v(sVarPre & "_USE_Init") = 0)
    ' tooltip if control is disabled
    d = GetDisabledFunctionToolTipEntry(func, sName)
    If (r.v(sVarPre & "_USE_Init") = 0) Then 
      d = d & FormatDisabledToolTip(TOOLTIP_DESELECTED_INIT)
    End If
    func.DisabledToolTip(sName) = d

    sFctName = "GetErrorIncrement"
    sName = sVarPre & "_NAME_" & sFctName
    ' disable condition
    func.Disabled(sName) = (r.v(sVarPre & "_USE_Init") = 0)
    ' tooltip if control is disabled
    d = GetDisabledFunctionToolTipEntry(func, sName)
    If (r.v(sVarPre & "_USE_Init") = 0) Then 
      d = d & FormatDisabledToolTip(TOOLTIP_DESELECTED_INIT)
    End If
    func.DisabledToolTip(sName) = d


    If (Not ShowFunction(sVarPre, ps, func , v)) Then Exit Function

  End If         ' if Pagename

  OnShowPageFunctions = True
  Exit Function

OnShowPageFunctionsError:
    Errorbox "Can not show page", Err.Description
    Exit Function
End Function


'*****************************************************************************
'Description:
'        This function is called from the OnLoad function of the associated
'        module in order to add a page.
'-----------------------------------------------------------------------------
'Parameters:
'        ps               reference to the Peripherals object
'-----------------------------------------------------------------------------
'Returns:
'        True            on successfull operation
'        False           else
'*****************************************************************************
Public Function OnLoadPageParameters(ps As Peripherals) As Boolean
  On Error Resume Next
  OnLoadPageParameters = False

  If (Not ps.AddPage("Parameters")) Then Exit Function

  OnLoadPageParameters = True
End Function


'*****************************************************************************
'Description:
'        This function is called from the OnChangingPage function of the
'        associated module in order load all controls for the requested page
'        if they are not already loaded.
'-----------------------------------------------------------------------------
'Parameters:
'        ps               reference to the Peripherals object
'        Pagename         requested page name
'-----------------------------------------------------------------------------
'Returns:
'        True            on successfull operation
'        False           else
'*****************************************************************************
Public Function OnChangingPageParameters(ps As Peripherals, Pagename As String) As Boolean
  On Error Resume Next
  OnChangingPageParameters = False

  Dim vIndex As Variant
  Dim sVarPre As String
  Dim i As Integer
  Dim aParameters(1 To 16) As String

  vIndex = ps.Parameters.v("x")   
  sVarPre = "CAN" & vIndex


  If (Not ps.ExtenderCollection("Parameters").Loaded) And (Pagename = "Parameters") Then
    ps.ExtenderCollection("Parameters").Loaded = True

    '-------------------------------
    ' frame: fra_HFile
    '-------------------------------
    If (Not ps.AddFrame("fra_HFile", 100 , 100, 4150, 700, CAPTION_FRA_HFILE)) Then Exit Function
      If (Not ps.AddText("txt_HFile", 1475, 250, 2500, 325)) Then Exit Function
      If (Not ps.AddLabel("lbl_HFile",0 , 200 , 275, 1250, 275, CAPTION_LBL_HFILE)) Then Exit Function   

    '-------------------------------
    ' frame: fraParameters1
    '-------------------------------
    ' initialize the array
'    For i = Lbound(aParameters) To Ubound(aParameters)
'      aParameters(i) = ""
'    Next i

'    i = Lbound(aParameters)
'    aParameters(i) = "Para1"
'    i = i + 1
'    aParameters(i) = "Para2"

'    If (Not ps.AddFrame("fraParameters1", 100 , 900, 4150, 4400, CAPTION_FRA_PARAMETERS1)) Then Exit Function
'      For i = Lbound(aParameters) To Ubound(aParameters)
'        If Not(aParameters(i) = "") Then
'          If (Not ps.AddText("txt_" & aParameters(i), 200, 300 * i, 3800, 325)) Then Exit Function
'        End If
'      Next i

  End If

  OnChangingPageParameters = True
End Function


'*****************************************************************************
'Description:
'        This function is called from the OnShow function of the associated
'        module. See the description for the OnShow function of the
'        associated module for details.
'-----------------------------------------------------------------------------
'Parameters:
'        ps              reference to the Peripherals object
'        Controlname     control name
'        Pagename        current page name
'        v()             value array
'-----------------------------------------------------------------------------
'Returns:
'        True            on successfull operation
'        False           else
'*****************************************************************************
Public Function OnShowPageParameters(ps As Peripherals, Controlname As String, Pagename As String, v() As Variant) As Boolean
  On Error Goto OnShowPageParametersError
  OnShowPageParameters = False
    
  Dim r As ProjectData
  Dim c As Collection
  Dim e As Collection
  Dim para As ParameterClass
  Dim vIndex As Variant
  Dim sVarPre As String
  Dim sRegPre As String
  Dim sName As String
  Dim d As String
  Dim i As Integer

  vIndex = ps.Parameters.v("x")   
  sVarPre = "CAN" & vIndex
  sRegPre = sVarPre & "_"

  Set r = ps.ProjectData
  Set c = ps.ControlCollection
  Set e = ps.ExtenderCollection
  Set para = New ParameterClass


  If (Pagename = "Parameters") Then

    '-------------------------------------------------------------------------
    ' page: Parameters (action)
    '-------------------------------------------------------------------------
    RefreshParameterDescriptions(vIndex, para, r)

    If (Not UpdateParameter(sVarPre, ps, para , Controlname, v)) Then Exit Function


    '-------------------------------------------------------------------------
    ' page: Parameters (show)
    '-------------------------------------------------------------------------

    Set para = New ParameterClass
    RefreshParameterDescriptions(vIndex, para, r)

'    sName = sIndex & "_PARA_T2" 
'    ' disable condition
'    para.Disabled(sName) = True
'    ' tooltip if control is disabled
'    d = FormatDisabledTooltip("Fred ...")
'    para.DisabledToolTip(sName) = d

    If (Not ShowParameter(sVarPre, ps, para, v)) Then Exit Function

  End If         ' if Pagename

  OnShowPageParameters = True
  Exit Function

OnShowPageParametersError:
    Errorbox "Can not show page", Err.Description
    Exit Function
End Function


