Imports System.Collections.ObjectModel

Public MustInherit Class CN_generico

#Region " Constants"

   Public Const MAX_AXES As Short = 10
   Public Const MAX_VAR As Short = 100
   Public Const MAX_VALUES As Short = 9           ' Max. index to read the data from the FXServer array
   Public Const MAX_TOOLS As Short = 100
   Public Const NUM_DATA = 55                     ' Numero di dati del CN (Speed,Feed,...)

   Public m_NewVariable As Boolean = False        ' per scrittura delle vairbaili Apllication del PLC

   Public Enum CnData
      Mode = 0
      JogIncr = 1
      Feed = 2
      FeedOvr = 3
      Speed = 4
      SpeedOvr = 5
      Power = 6
      Spindle = 7
      Coolant = 8
      Laser = 9
      PowerOvr = 10
      Comm = 11
      Refresh = 12
      InternalCoolant = 13
      ExternCoolant = 14
      CBAxes = 15
      AirBlow = 16
      Home = 17
      TableUp = 18
      TableDown = 19
      DoorClosed = 20
      LimitZ = 21
      VacuumUp = 22
      VacuumDown = 23
      Vacuum2Up = 24
      Vacuum2Down = 25
      Vacuum1State = 26
      Vacuum2State = 27
      Vacuum3State = 28
      Vacuum4State = 29
      Vacuum5State = 30
      Vacuum6State = 31
      Vacuum135State = 32
      Vacuum246State = 33
      OpenAllState = 34
      CloseAllState = 35
      Open123State = 36
      Open456State = 37
      Close123State = 38
      Close456State = 39
      BlowState = 40
      VacuumOn = 41
      BypassState = 42
      Vacuum0 = 43
      Vacuum90 = 44
      VacuumOff = 45
      LaserTrac = 46

      XYJog = 47
      ZCJog = 48
      ZBJog = 49
      PowerON = 50
      Remote = 51

      Parking = 52
      EnableZone = 53
      EnablePC = 54
   End Enum

#End Region

#Region " Struct"

   Public Structure ToolStructure
      Public type As Char
      Public lenght As Double
      Public radius As Double
      Public tip As Double
      Public D_lenght As Double
      Public D_radius As Double
      Public nose_dir As String
      Public comp_num As Short
   End Structure

#End Region

#Region " Interface"

   Friend m_IsSiemensOne As Boolean = False
   Friend m_IsActiveModeSubscription As Boolean = False

   Friend m_DbVarPath As String = ""

   Public IsFlexiumPlus As Boolean = False
   Public sz_CncFxIdentifier As String = ""

   Public d_LinearAxisPrecision As Double
   Public d_RotaryAxisPrecision As Double

   Public sz_ServerInitStatus As String
   Public sz_ServerReinitStatus As String
   Public sz_ManualDataInput As String

   Public sz_versionRTS As String
   Public sz_ConnectionAddress As String
   Public sz_AffaireNumber As String

   Public n_state As Short = 0
   Public n_validaxes As Short

   Public b_axis_events_enable As Boolean = False
   Public d_axis_position(MAX_AXES) As Double
   Public d_axis_delta(MAX_AXES) As Double
   Public b_axis_valid(MAX_AXES) As Boolean

   Public d_DReadELS_value As Double
   Public n_DReadELS_handle As Short

   ' variabili lettura e scrittura generiche
   Public sz_interf_error_message As String     ' eventuale messaggio di errore
   Public n_param1 As Integer
   Public l_param1 As Long
   Public d_param1 As Double
   Public sz_string As String                 ' ( MAX 200 caratteri )

   Public b_data(14) As Boolean
   Public n_data(14) As Int16
   Public l_data(14) As Long
   Public d_data(14) As Double
   Public sz_spare_data As String

   Public d_Dvariable_values(MAX_VAR) As Double
   Public b_Dvariable_changed As Boolean = False

   Public d_DInterpo_values(MAX_AXES) As Double
   Public d_DInterpo_Prog_Feed As Double
   Public d_DInterpo_Feed_override As Double
   Public l_channel_override(MAX_VALUES) As Long
   Public b_feed_changed As Boolean = False

   Public n_activate_error_code As Short

   Public d_spindle_prog(MAX_VALUES) As Double
   Public d_spindle_eff(MAX_VALUES) As Double
   Public n_spindle_override(MAX_VALUES) As Short
   Public b_spindle_data_changed As Boolean = False

   Public d_spindle_power As Double
   Public b_spindle_power_changed As Boolean = False

   Public Tools(MAX_TOOLS) As ToolStructure
   Public b_Tool_data_changed As Boolean = False

   Public sz_PLC_error_messages As String
   Public sz_NC_error_messages As List(Of String)
   Public b_PLC_error As Boolean
   Public b_NC_error As Boolean
   Public bIsErrorMessage As Boolean = True

   Public bSpindleState As Boolean
   Public bLaserState As Boolean
   Public bLaserTracState As Boolean
   Public bCoolantState As Boolean
   Public bInternalCoolantState As Boolean
   Public bExternCoolantState As Boolean
   Public bCBAxesState As Boolean
   Public b5AxesState As Boolean
   Public bAirBlowState As Boolean
   Public bHomeState As Boolean
   Public bTableUpState As Boolean
   Public bTableDownState As Boolean
   Public nDoorClosedState As Integer
   Public bLimitZState As Boolean
   Public bPowerOvr As Double
   Public bParkingState As Boolean
   Public nEnableZone As Integer
   Public nEnablePc As Integer
   Public bHsm As Double
   Public bVacuumUp As Boolean
   Public bVacuumDown As Boolean
   Public bVacuum2Up As Boolean
   Public bVacuum2Down As Boolean
   Public bVacuum0 As Boolean
   Public bVacuum90 As Boolean
   Public bVacuum1State As Boolean
   Public bVacuum2State As Boolean
   Public bVacuum3State As Boolean
   Public bVacuum4State As Boolean
   Public bVacuum5State As Boolean
   Public bVacuum6State As Boolean
   Public bVacuum135State As Boolean
   Public bVacuum246State As Boolean
   Public bOpenAllState As Boolean
   Public bCloseAllState As Boolean
   Public bOpen123State As Boolean
   Public bOpen456State As Boolean
   Public bClose123State As Boolean
   Public bClose456State As Boolean
   Public bBlowState As Boolean
   Public bVacuumOn As Boolean
   Public bVacuumOff As Boolean
   Public bBypassState As Boolean
   Public bResetState As Boolean
   Public bFeedHold As Boolean
   Public bSpeedHold As Boolean

   ' Nuovi di bottoni -------------------------------------------
   Public bXYJog As Boolean
   Public bZCJog As Boolean
   Public bZBCJog As Boolean

   Public bPowerON As Boolean
   Public bRemote As Boolean
   ' Nuovi di bottoni -------------------------------------------

   Public nMachineMode As Integer

   Public m_szCnDataVar(NUM_DATA - 1) As String

   Public Event NewPositionData(ByVal sender As Object)
   Public Event NewPosDeltaData(ByVal sender As Object)
   Public Event NewVarChanged(ByVal sender As Object)

   Protected Overridable Sub OnNewPositionData()
      RaiseEvent NewPositionData(0)
   End Sub
   Protected Overridable Sub OnNewPosDeltaData()
      RaiseEvent NewPosDeltaData(0)
   End Sub
   Protected Overridable Sub OnNewVarChanged()
      RaiseEvent NewVarChanged(0)
   End Sub

#End Region

#Region " Metodi pubblici"

   Public MustOverride Function Init() As Boolean

   Public MustOverride Function Stop_Connection() As Boolean

   Public MustOverride Sub ReadEls_Add_Parameter(sz_var As String, n_par As Short)

   Public MustOverride Sub DVariables_WriteVariables(sz_parameters As String, sz_values As String)

   Public MustOverride Sub DVariables_WriteVariables2(sz_parameters As String, sz_values As String)

   Public Overridable Sub DVariables_WriteVariables3(VarAddr As String, ParType As Short, nVarValue As Integer, lVarValue As Long, dVarValue As Double, sVarValue As String)
   End Sub

   Public Overridable Sub DPlcVariables_WriteVariables(sz_parameters As String, sz_values As String)
   End Sub

   Public Overridable Sub Read_Variable(VarAddr As String, ParType As Integer, ByRef nVarValue As Integer, ByRef lVarValue As Long, ByRef dVarValue As Double, ByRef sVarValue As String)

   End Sub

   Public Overridable Sub DVariables_Read_Subscription(VarAddr As String, ParType As Short, Index As Integer)

   End Sub

   Public MustOverride Function MDI_command() As Short

   Public Overridable Function New_MDI_command(nChannel As Integer) As Short
      Return 0
   End Function

   Public MustOverride Function ActivateProgram(n_part_program As Integer) As Int16

   Public MustOverride Sub set_OP_OM(n As Short)

   Public MustOverride Function DPOsition_ReadOnce() As Short

   Public MustOverride Function DGeneralFunctions_CycleStart() As Int16

   Public MustOverride Function DGeneralFunctions_FeedHold() As Int16

   Public MustOverride Function DGeneralFunctions_Reset() As Int16

   Public MustOverride Function DGeneralFunctions_WriteCncMode(nmode As Short) As Int16

   Public MustOverride Function Write_var_1(sz_par As String, lvalue As Long) As Int16

   Public MustOverride Function Download_NC_prog(sz_PC_filename As String, sz_NC_filename As String) As Int16

   Public MustOverride Function Upload_NC_prog(sz_PC_filename As String, sz_NC_filename As String) As Int16

   Public MustOverride Function Delete_NC_prog(sz_NC_filename As String) As Int16

   Public MustOverride Function DTool_set_read_range(n_start As Short, n_stop As Short) As Short

   Public MustOverride Function DTool_write_tool(n_tool_number As Short, Length_X As Double, Radius As Double, TipRadius_Z As Double, _
                                    DLength_X As Double, DTipRadius_Z As Double, _
                                    nDirection As Short, nType As Short, nH As Integer) As Short

   Public Overridable Function SetProgramMainOrSub(bMain As Boolean) As Boolean
      Return True
   End Function

   Public Overridable Function get_free_memory(n_zone As Int16) As Long
      Return 0
   End Function

   Public Overridable Function read_active_mode() As Int16
      Return 0
   End Function

   Public Overridable Function get_program_status() As Int16
      Return 0
   End Function

   Public Overridable Function get_plc_messages() As Int16
      Return 0
   End Function

   Public Overridable Function Is_G24_active() As Boolean
      Return False
   End Function

   Public Overridable Function Is_G26_active() As Boolean
      Return False
   End Function

   Public Overridable Function Is_G71_active() As Boolean
      Return False
   End Function

   Public Overridable Function VerifyAxis(ByRef nAx As Integer) As Boolean
      Return (nAx >= 0 And nAx <= MAX_AXES)
   End Function

   Public Function SetCnDataVar(nId As CnData, sVal As String) As Boolean
      m_szCnDataVar(nId) = sVal
      Return True
   End Function

#End Region

End Class
