Imports System.Collections.ObjectModel Imports System.Collections.Specialized Imports EgtBEAMWALL.Core.ConstMachComm Imports ISOCNC.Remoting Imports EgtUILib Imports EgtWPFLib5 Imports System.IO Imports EgtBEAMWALL.Core Imports EgtBEAMWALL.Supervisor.CommVar Public Class MachManaging ' lock per aggiunta elemento a lista MachGroup Private Shared Lock_CommandList As New Object Private m_bConnected As Boolean = False Public ReadOnly Property bConnected As Boolean Get Return m_bConnected End Get End Property Friend Sub SetConnected(value As Boolean) m_bConnected = value End Sub Private m_CN As Object = Nothing Public ReadOnly Property CN As Object Get Return m_CN End Get End Property Public ReadOnly Property Tpa As TPAComm Get Return m_CN End Get End Property Public ReadOnly Property Num_Flexium As NUMFlexiumComm Get Return m_CN End Get End Property Public ReadOnly Property Num_Axium_APServer As NUMAxiumComm Get Return m_CN End Get End Property Public ReadOnly Property Num_Axium_PCToolkit As NUMAxiumPcToolkitComm Get Return m_CN End Get End Property Public ReadOnly Property Siemens_Sharp7 As SIEMENSSharp7Comm Get Return m_CN End Get End Property Private Shared WithEvents m_CommandList As New ObservableCollection(Of ThreadCommand) Public Shared ReadOnly Property CommandList As ObservableCollection(Of ThreadCommand) Get Return m_CommandList End Get End Property Friend Shared Sub AddToCommandList(value As ThreadCommand) SyncLock Lock_CommandList For CommandIndex = m_CommandList.Count - 1 To 0 Step -1 Dim Command As ThreadCommand = m_CommandList(CommandIndex) If Command.ProcessingStatus = ThreadCommand.ProcessingStatuses.DONE Then m_CommandList.Remove(Command) End If Next CommandList.Add(value) End SyncLock End Sub Private m_bStartPending As Boolean = False Public ReadOnly Property StartPending As Boolean Get Return m_bStartPending End Get End Property Friend Sub ResetStartPending() m_bStartPending = False End Sub Friend Sub SetStartPending(value As Boolean) m_bStartPending = value End Sub ' prossima barra di cui mando i parametri di carico Private m_NextBarId As Integer ' indice di lavorazione della macchina (pareti NUM) Private m_nMachIndex As Integer Friend ReadOnly Property nMachIndex As Integer Get Return m_nMachIndex End Get End Property ' variabile che indica prima barra dopo start (Siemens) Private m_bFirstRaw As Boolean = True ' variabile che indica se emettere ii messaggi di debug Private m_Debug As Integer = 0 Public ReadOnly Property Debug As Integer Get Return m_Debug End Get End Property Sub New() ' leggo variabile debug da ini m_Debug = GetPrivateProfileInt(S_GENERAL, K_DEBUG, 0, CurrentMachine.sMachIniFile) ' imposto in Map Map.SetRefMachManaging(Me) AddHandler m_CommandList.CollectionChanged, AddressOf CommandList_CollectionChanged ' mi connetto alla macchina Connect() End Sub Private Sub OnDispose() RemoveHandler m_CommandList.CollectionChanged, AddressOf CommandList_CollectionChanged End Sub Friend Sub Timer_Tick() Select Case CurrentMachine.NCType Case NCTypes.NUM_FLEXIUM, NCTypes.TPA, NCTypes.NUM_AXIUM_APSERVER, NCTypes.NUM_AXIUM_PCTOOLKIT, NCTypes.SIEMENS_SHARP7 ' eseguo ciclo principale Dim nReset_State As Integer Dim nStart_State As Boolean Dim nStop_State As Boolean Dim nP_Prod As Integer Dim nP_Machgroup As Integer Dim nP_Part As Integer Dim nP_State As Integer Dim nISO_Num As Integer Dim nISO_Sent As Integer Dim nRunning As Integer Dim nCurrMachIndex As Integer Dim nDataWrite As Integer Dim nNCStatus As Integer Dim nNCMode As Integer Dim ResetVariable As Variable = Map.refMachCommandMessagePanelVM.MainVariablesList.FirstOrDefault(Function(x) x.sName = RESET_STATE) Dim StartVariable As Variable = Map.refMachCommandMessagePanelVM.MainVariablesList.FirstOrDefault(Function(x) x.sName = START_STATE) Dim StopVariable As Variable = Map.refMachCommandMessagePanelVM.MainVariablesList.FirstOrDefault(Function(x) x.sName = STOP_STATE) Dim ProdVariable As Variable = Map.refMachCommandMessagePanelVM.MainVariablesList.FirstOrDefault(Function(x) x.sName = P_PROD) Dim MachGroupVariable As Variable = Map.refMachCommandMessagePanelVM.MainVariablesList.FirstOrDefault(Function(x) x.sName = P_MACHGROUP) Dim PartVariable As Variable = Map.refMachCommandMessagePanelVM.MainVariablesList.FirstOrDefault(Function(x) x.sName = P_PART) Dim StateVariable As Variable = Map.refMachCommandMessagePanelVM.MainVariablesList.FirstOrDefault(Function(x) x.sName = P_STATE) Dim ISONumVariable As Variable = Map.refMachCommandMessagePanelVM.MainVariablesList.FirstOrDefault(Function(x) x.sName = ISO_NUM) Dim ISOSentVariable As Variable = Map.refMachCommandMessagePanelVM.MainVariablesList.FirstOrDefault(Function(x) x.sName = ISO_SENT) Dim RunningVariable As Variable = Map.refMachCommandMessagePanelVM.MainVariablesList.FirstOrDefault(Function(x) x.sName = RUNNING) Dim MachIndexVariable As Variable = Map.refMachCommandMessagePanelVM.MainVariablesList.FirstOrDefault(Function(x) x.sName = MACHINDEX) Dim DataReadedVariable As Variable = Map.refMachCommandMessagePanelVM.MainVariablesList.FirstOrDefault(Function(x) x.sName = DATAREADED) Dim ResetReadedVariable As Variable = Map.refMachCommandMessagePanelVM.MainVariablesList.FirstOrDefault(Function(x) x.sName = RESETREADED) Dim DataToReadVariable As Variable = Map.refMachCommandMessagePanelVM.MainVariablesList.FirstOrDefault(Function(x) x.sName = DATATOREAD) Dim NCStatusVariable As Variable = Map.refMachCommandMessagePanelVM.MainVariablesList.FirstOrDefault(Function(x) x.sName = NC_STATUS) Dim NCModeVariable As Variable = Map.refMachCommandMessagePanelVM.MainVariablesList.FirstOrDefault(Function(x) x.sName = NC_MODE) Select Case CurrentMachine.NCType Case NCTypes.TPA ' leggo tutte le variabili Tpa.RWVariableManager.RefreshAllVars() Tpa.RWVariableManager.ReadVar(P_PROD, nP_Prod) Tpa.RWVariableManager.ReadVar(P_MACHGROUP, nP_Machgroup) Tpa.RWVariableManager.ReadVar(P_PART, nP_Part) Tpa.RWVariableManager.ReadVar(P_STATE, nP_State) Tpa.RWVariableManager.ReadVar(RESET_STATE, nReset_State) Case NCTypes.NUM_FLEXIUM ResetVariable = Map.refMachCommandMessagePanelVM.MainVariablesList.FirstOrDefault(Function(x) x.sName = RESET_STATE) StartVariable = Map.refMachCommandMessagePanelVM.MainVariablesList.FirstOrDefault(Function(x) x.sName = START_STATE) StopVariable = Map.refMachCommandMessagePanelVM.MainVariablesList.FirstOrDefault(Function(x) x.sName = STOP_STATE) ProdVariable = Map.refMachCommandMessagePanelVM.MainVariablesList.FirstOrDefault(Function(x) x.sName = P_PROD) MachGroupVariable = Map.refMachCommandMessagePanelVM.MainVariablesList.FirstOrDefault(Function(x) x.sName = P_MACHGROUP) PartVariable = Map.refMachCommandMessagePanelVM.MainVariablesList.FirstOrDefault(Function(x) x.sName = P_PART) StateVariable = Map.refMachCommandMessagePanelVM.MainVariablesList.FirstOrDefault(Function(x) x.sName = P_STATE) ISONumVariable = Map.refMachCommandMessagePanelVM.MainVariablesList.FirstOrDefault(Function(x) x.sName = ISO_NUM) ISOSentVariable = Map.refMachCommandMessagePanelVM.MainVariablesList.FirstOrDefault(Function(x) x.sName = ISO_SENT) RunningVariable = Map.refMachCommandMessagePanelVM.MainVariablesList.FirstOrDefault(Function(x) x.sName = RUNNING) MachIndexVariable = Map.refMachCommandMessagePanelVM.MainVariablesList.FirstOrDefault(Function(x) x.sName = MACHINDEX) Integer.TryParse(ResetVariable.sValue, nReset_State) Boolean.TryParse(StartVariable.sValue, nStart_State) Boolean.TryParse(StopVariable.sValue, nStop_State) Integer.TryParse(ProdVariable.sValue, nP_Prod) Integer.TryParse(MachGroupVariable.sValue, nP_Machgroup) Integer.TryParse(PartVariable.sValue, nP_Part) Integer.TryParse(StateVariable.sValue, nP_State) Integer.TryParse(ISONumVariable.sValue, nISO_Num) Integer.TryParse(ISOSentVariable.sValue, nISO_Sent) Integer.TryParse(RunningVariable.sValue, nRunning) Integer.TryParse(MachIndexVariable.sValue, nCurrMachIndex) ' se indice lavorazione positivo, lo aggiorno If nCurrMachIndex > 0 AndAlso nReset_State = 0 Then m_nMachIndex = nCurrMachIndex End If Case NCTypes.NUM_AXIUM_APSERVER Dim dTemp As Double = 0 Dim nTemp As Integer = 0 If Not IsNothing(ResetVariable.sValue) Then Integer.TryParse(ResetVariable.sValue, nReset_State) Else nReset_State = 1 End If If Not IsNothing(StartVariable.sValue) Then Integer.TryParse(StartVariable.sValue, nTemp) nStart_State = (nTemp = 1) Else nStart_State = -1 End If If Not IsNothing(StopVariable.sValue) Then Integer.TryParse(StopVariable.sValue, nTemp) nStop_State = (nTemp = 1) Else nStop_State = -1 End If If Not IsNothing(ProdVariable.sValue) Then Integer.TryParse(ProdVariable.sValue, nP_Prod) Else nP_Prod = -1 End If If Not IsNothing(MachGroupVariable.sValue) Then Integer.TryParse(MachGroupVariable.sValue, nP_Machgroup) Else nP_Machgroup = -1 End If If Not IsNothing(PartVariable.sValue) Then Integer.TryParse(PartVariable.sValue, nP_Part) Else nP_Part = -1 End If If Not IsNothing(StateVariable.sValue) Then Integer.TryParse(StateVariable.sValue, nP_State) Else nP_State = -1 End If If Not IsNothing(ISONumVariable.sValue) Then Integer.TryParse(ISONumVariable.sValue, nISO_Num) Else nISO_Num = -1 End If If Not IsNothing(ISOSentVariable.sValue) Then Integer.TryParse(ISOSentVariable.sValue, nISO_Sent) Else nISO_Sent = -1 End If If Not IsNothing(RunningVariable.sValue) Then Integer.TryParse(RunningVariable.sValue, nRunning) Else nRunning = -1 End If If Not IsNothing(MachIndexVariable.sValue) Then Integer.TryParse(MachIndexVariable.sValue, nCurrMachIndex) Else nCurrMachIndex = -1 End If ' se indice lavorazione positivo, lo aggiorno If nCurrMachIndex > 0 AndAlso nReset_State = 0 Then m_nMachIndex = nCurrMachIndex End If ' leggo messaggi plc ReadPLCMessages() Case NCTypes.NUM_AXIUM_PCTOOLKIT ' leggo tutte le variabili Num_Axium_PCToolkit.RefreshAllVars() Dim dTemp As Double = 0 Dim nTemp As Integer = 0 If Not IsNothing(ResetVariable.sValue) Then Integer.TryParse(ResetVariable.sValue, nReset_State) Else nReset_State = 1 End If If Not IsNothing(StartVariable.sValue) Then Integer.TryParse(StartVariable.sValue, nTemp) nStart_State = (nTemp = 1) Else nStart_State = -1 End If If Not IsNothing(StopVariable.sValue) Then Integer.TryParse(StopVariable.sValue, nTemp) nStop_State = (nTemp = 1) Else nStop_State = -1 End If If Not IsNothing(ProdVariable.sValue) Then Integer.TryParse(ProdVariable.sValue, nP_Prod) Else nP_Prod = -1 End If If Not IsNothing(MachGroupVariable.sValue) Then Integer.TryParse(MachGroupVariable.sValue, nP_Machgroup) Else nP_Machgroup = -1 End If If Not IsNothing(PartVariable.sValue) Then Integer.TryParse(PartVariable.sValue, nP_Part) Else nP_Part = -1 End If If Not IsNothing(StateVariable.sValue) Then Integer.TryParse(StateVariable.sValue, nP_State) Else nP_State = -1 End If If Not IsNothing(ISONumVariable.sValue) Then Integer.TryParse(ISONumVariable.sValue, nISO_Num) Else nISO_Num = -1 End If If Not IsNothing(ISOSentVariable.sValue) Then Integer.TryParse(ISOSentVariable.sValue, nISO_Sent) Else nISO_Sent = -1 End If If Not IsNothing(RunningVariable.sValue) Then Integer.TryParse(RunningVariable.sValue, nRunning) Else nRunning = -1 End If If Not IsNothing(MachIndexVariable.sValue) Then Integer.TryParse(MachIndexVariable.sValue, nCurrMachIndex) Else nCurrMachIndex = -1 End If ' se indice lavorazione positivo, lo aggiorno If nCurrMachIndex > 0 AndAlso nReset_State = 0 Then m_nMachIndex = nCurrMachIndex End If ' leggo messaggi plc ReadPLCMessages() Num_Axium_PCToolkit.ReadCncMode() Num_Axium_PCToolkit.ReadPosition() Case NCTypes.SIEMENS_SHARP7 ' leggo tutte le variabili Map.refMachManaging.DebugMessage(1, "Leggo tutte le variabili") Siemens_Sharp7.RefreshAllVars() If Not IsNothing(ResetVariable.sValue) Then Integer.TryParse(ResetVariable.sValue, nReset_State) Else nReset_State = 1 End If If Not IsNothing(ProdVariable.sValue) Then Integer.TryParse(ProdVariable.sValue, nP_Prod) Else nP_Prod = -1 End If If Not IsNothing(MachGroupVariable.sValue) Then Integer.TryParse(MachGroupVariable.sValue, nP_Machgroup) Else nP_Machgroup = -1 End If If Not IsNothing(PartVariable.sValue) Then Integer.TryParse(PartVariable.sValue, nP_Part) Else nP_Part = -1 End If If Not IsNothing(StateVariable.sValue) Then Integer.TryParse(StateVariable.sValue, nP_State) Else nP_State = -1 End If If Not IsNothing(ISONumVariable.sValue) Then Integer.TryParse(ISONumVariable.sValue, nISO_Num) Else nISO_Num = -1 End If If Not IsNothing(RunningVariable.sValue) Then Integer.TryParse(RunningVariable.sValue, nRunning) Else nRunning = -1 End If If Not IsNothing(DataReadedVariable.sValue) Then Integer.TryParse(DataReadedVariable.sValue, nDataWrite) Else nDataWrite = -1 End If If Not IsNothing(NCStatusVariable.sValue) Then Integer.TryParse(NCStatusVariable.sValue, nNCStatus) Else nNCStatus = -1 End If If Not IsNothing(NCModeVariable.sValue) Then Integer.TryParse(NCModeVariable.sValue, nNCMode) Else nNCMode = -1 End If ' leggo messaggi plc Siemens_Sharp7.ReadPLCMessages() End Select ' se SiemensSharp7 e reset a 0, verifico che conferma lettura reset sia a zero If CurrentMachine.NCType = NCTypes.SIEMENS_SHARP7 And ResetReadedVariable.sValue = "1" And ResetVariable.sValue = "0" Then Map.refMachManaging.DebugMessage(1, "Azzero lettura reset") ResetReadedVariable.sValue = "0" End If ' se SiemensSharp7 e dati letti a 1 e dati scritti a 0, verifico che dati letti sia a zero If CurrentMachine.NCType = NCTypes.SIEMENS_SHARP7 And DataReadedVariable.sValue = "1" And DataToReadVariable.sValue = "0" Then Map.refMachManaging.DebugMessage(1, "Azzero lettura dati") DataReadedVariable.sValue = "0" End If ' se NUM aggiorno stato della macchina If CurrentMachine.NCType = NCTypes.NUM_FLEXIUM Then Dim OpState As OPStates If nStop_State Then OpState = OPStates.Stop ElseIf nStart_State Then OpState = OPStates.Start Else OpState = OPStates.End End If If OpState <> Map.refLeftPanelVM.SelOPState.Id Then m_OpStateCallbackDlg(OpState) End If ElseIf CurrentMachine.NCType = NCTypes.NUM_AXIUM_APSERVER OrElse CurrentMachine.NCType = NCTypes.NUM_AXIUM_PCTOOLKIT Then Dim OpState As OPStates If nReset_State = 1 Then OpState = OPStates.End ElseIf nStop_State Then OpState = OPStates.Stop ElseIf nStart_State Then OpState = OPStates.Start Else OpState = OPStates.End End If If IsNothing(Map.refLeftPanelVM.SelOPState) OrElse OpState <> Map.refLeftPanelVM.SelOPState.Id Then m_OpStateCallbackDlg(OpState) End If ElseIf CurrentMachine.NCType = NCTypes.SIEMENS_SHARP7 Then Dim OpState As OPStates If nNCStatus > 0 Then Select Case nNCStatus Case 1 OpState = OPStates.End Case 2 OpState = OPStates.Stop Case 3 OpState = OPStates.Start Case Else OpState = OPStates.Unspecified End Select End If If IsNothing(Map.refLeftPanelVM.SelOPState) OrElse OpState <> Map.refLeftPanelVM.SelOPState.Id Then Map.refMachManaging.DebugMessage(1, "Imposto stato CN: " & OpState) m_OpStateCallbackDlg(OpState) End If Dim OpMode As OPModes If nNCMode > 0 Then Select Case nNCMode Case 1 OpMode = OPModes.Manual Case 2 OpMode = OPModes.Auto Case 3 OpMode = OPModes.Mdi Case 4 ' Reference Point OpMode = OPModes.Home End Select End If If IsNothing(Map.refLeftPanelVM.SelOPMode) OrElse OpMode <> Map.refLeftPanelVM.SelOPMode.Id Then Map.refMachManaging.DebugMessage(1, "Imposto modo CN: " & OpMode) m_OpModeCallbackDlg(OpMode) End If End If ' se TPA e non ancora fatto, preparo variabili barra successiva If CurrentMachine.NCType = NCTypes.TPA AndAlso CurrentMachine.Flow = FlowTypes.CONTINUOUS AndAlso m_NextBarId = 0 Then SetNextBarVars(nRunning) ' se macchina NUM, non sto gia' spedendo e variabile spedizione me lo permette ElseIf (CurrentMachine.NCType = NCTypes.NUM_FLEXIUM AndAlso Not Num_Flexium.bIsTransferActive AndAlso nISO_Sent = 1) OrElse (CurrentMachine.NCType = NCTypes.NUM_AXIUM_APSERVER AndAlso Not Num_Axium_APServer.bIsTransferActive AndAlso nISO_Sent = 1) OrElse (CurrentMachine.NCType = NCTypes.NUM_AXIUM_PCTOOLKIT AndAlso Not Num_Axium_PCToolkit.bIsTransferActive AndAlso nISO_Sent = 1) OrElse (CurrentMachine.NCType = NCTypes.SIEMENS_SHARP7 AndAlso (nISO_Num = 0 OrElse nISO_Num = nRunning)) Then ' verifico se c'e' un programma da lanciare Map.refMachManaging.DebugMessage(1, "Entro in SendNextProgram") SendNextProgram() ElseIf CurrentMachine.NCType = NCTypes.SIEMENS_SHARP7 AndAlso m_NextBarId = 0 Then SetNextBarVars(nRunning) End If ' verifico se scattato stato reset If nReset_State <> 0 Then Map.refMachManaging.DebugMessage(1, "Scattato Reset") ' resetto tutti i programmi If Not IsNothing(Map.refProjectVM.SupervisorMachGroupPanelVM) Then Map.refProjectVM.SupervisorMachGroupPanelVM.ResetAllMachGroups() If CurrentMachine.NCType = NCTypes.SIEMENS_SHARP7 Then 'resetto programma corrente Map.refMachManaging.DebugMessage(1, "Resetto programma corrente") ISONumVariable.sValue = "0" m_bFirstRaw = True Else ' resetto variabili P ProdVariable.sValue = "0" MachGroupVariable.sValue = "0" PartVariable.sValue = "0" StateVariable.sValue = "0" If CurrentMachine.NCType = NCTypes.TPA Then RemoveAllProgram() ' rimuovo programma default per pending End If End If ' cancello tutti i programmi da memoria CN If CurrentMachine.NCType = NCTypes.TPA Then RemoveAllProgram() ' rimuovo programma default per pending End If ' azzero variabile reset If CurrentMachine.NCType = NCTypes.SIEMENS_SHARP7 Then Map.refMachManaging.DebugMessage(1, "Confermo lettura reset") ResetReadedVariable.sValue = "1" Else ResetVariable.sValue = "0" End If ' resetto prossima barra e variabili V If CurrentMachine.NCType = NCTypes.TPA AndAlso CurrentMachine.Flow = FlowTypes.CONTINUOUS Then m_NextBarId = 0 'For Index As Integer = 1 To 6 ' Tpa.RWVariableManager.WriteVarByName(VPAR & Index.ToString(), 0) 'Next ResetNextBarVars() End If Return ' se macchina TPA, e' in pending e non sta tagliando alcun pezzo ElseIf CurrentMachine.NCType = NCTypes.TPA AndAlso Tpa.opState = MachineOperatingState.Pending AndAlso Tpa.remObject.MachineOperativeStatus = MachineOperatingState.Pending AndAlso (nP_Prod = 0 AndAlso nP_Machgroup = 0 AndAlso nP_Part = 0 AndAlso nP_State = PartState.NULL) Then ' verifico se c'e' un programma da lanciare SendNextProgram() ' attesa per essere sicuro che abbia scritto e riletto variabili Threading.Thread.Sleep(300) ' verifico stati inizio e fine pezzi ElseIf (CurrentMachine.NCType <> NCTypes.SIEMENS_SHARP7 AndAlso nP_Prod <> 0 AndAlso nP_Machgroup <> 0 AndAlso nP_Part <> 0) OrElse (CurrentMachine.NCType = NCTypes.SIEMENS_SHARP7 AndAlso DataToReadVariable.sValue = "1" AndAlso nP_Prod <> 0 AndAlso nP_Machgroup <> 0 AndAlso nP_Part <> 0) Then If nP_State = PartState.START Then Map.refMachManaging.DebugMessage(1, "Leggo dati start") Dim dtStart As DateTime = DateTime.Now() ' recupero gruppo di lavorazione del pezzo Dim MachGroup As MyMachGroupVM = Map.refProjectVM.SupervisorMachGroupPanelVM.MachGroupVMList.FirstOrDefault(Function(x) x.Id = nP_Machgroup) ' se pezzo = -1 devo dare start a tutti i pezzi del MachGroup If nP_Part = -1 Then If Not IsNothing(MachGroup) Then For Each Part In MachGroup.PartVMList ' scrivo data start su Db pezzo DbControllers.m_PartController.UpdateStart(nP_Prod, nP_Machgroup, Part.nPartId, dtStart) DbControllers.m_PartController.UpdateStatus(nP_Prod, nP_Machgroup, Part.nPartId, ItemState.WIP) ' scrivo stato start Part.nProduction_State = ItemState.WIP Part.dtStartTime = dtStart Part.NotifyPropertyChanged(NameOf(Part.nProduction_State)) ' scrivo evento inizio pezzo su DB DbControllers.m_LogMachineController.Create(LogEvent.CreatePartStateLog(dtStart, nP_Prod, nP_Machgroup, Part.nPartId, nP_State, DbControllers.SupervisorId)) Next End If Else ' scrivo data start su Db pezzo DbControllers.m_PartController.UpdateStart(nP_Prod, nP_Machgroup, nP_Part, dtStart) DbControllers.m_PartController.UpdateStatus(nP_Prod, nP_Machgroup, nP_Part, ItemState.WIP) If Not IsNothing(MachGroup) Then ' recupero pezzo Dim Part As PartVM = MachGroup.PartVMList.FirstOrDefault(Function(x) x.nPartId = nP_Part) If Not IsNothing(Part) Then ' scrivo stato start Part.nProduction_State = ItemState.WIP Part.dtStartTime = dtStart Part.NotifyPropertyChanged(NameOf(Part.nProduction_State)) End If End If ' scrivo evento inizio pezzo su DB DbControllers.m_LogMachineController.Create(LogEvent.CreatePartStateLog(dtStart, nP_Prod, nP_Machgroup, nP_Part, nP_State, DbControllers.SupervisorId)) End If ' azzero variabile per far ripartire macchina Select Case CurrentMachine.NCType Case NCTypes.TPA Tpa.RWVariableManager.WriteVarByName(P_STATE, 0) Case NCTypes.NUM_FLEXIUM, NCTypes.NUM_AXIUM_APSERVER, NCTypes.NUM_AXIUM_PCTOOLKIT StateVariable.sValue = "0" Case NCTypes.SIEMENS_SHARP7 Map.refMachManaging.DebugMessage(1, "Confermo lettura dati start") DataReadedVariable.sValue = "1" End Select ' se nessun pezzo della barra diverso da quello corrente e' in start If Not MachGroup.PartVMList.Any(Function(x) x.nPartId <> nP_Part AndAlso x.nProduction_State = 1) Then ' scrivo data start su Db barra DbControllers.m_MachGroupController.UpdateStart(nP_Prod, nP_Machgroup, dtStart) DbControllers.m_MachGroupController.UpdateStatus(nP_Prod, nP_Machgroup, ItemState.WIP) ' scrivo stato start If Not IsNothing(MachGroup) Then MachGroup.MyMachGroupM.SetProductionState(ItemState.WIP) MachGroup.dtStartTime = dtStart MachGroup.NotifyPropertyChanged(NameOf(MachGroup.nProduction_State)) End If ' scrivo evento inizio MachGroup su DB DbControllers.m_LogMachineController.Create(LogEvent.CreateMachGroupStateLog(dtStart, nP_Prod, nP_Machgroup, nP_State, DbControllers.SupervisorId)) End If ' flag di aggiornamento log macchina Map.refMachineLogPageVM.UpdateMachineLogList(False) DebugMessage(1, "Fine lettura dati start") ' attesa per essere sicuro che abbia scritto e riletto variabili Threading.Thread.Sleep(300) ElseIf nP_State = PartState.END_ Then DebugMessage(1, "Leggo dati end") Dim dtEnd As DateTime = DateTime.Now() ' recupero gruppo di lavorazione del pezzo Dim MachGroup As MyMachGroupVM = Map.refProjectVM.SupervisorMachGroupPanelVM.MachGroupVMList.FirstOrDefault(Function(x) x.Id = nP_Machgroup) ' se pezzo = -1 devo dare end a tutti i pezzi del MachGroup If nP_Part = -1 Then If Not IsNothing(MachGroup) Then For Each Part In MachGroup.PartVMList ' scrivo data end su Db pezzo DbControllers.m_PartController.UpdateEnd(nP_Prod, nP_Machgroup, Part.nPartId, dtEnd) DbControllers.m_PartController.UpdateStatus(nP_Prod, nP_Machgroup, Part.nPartId, ItemState.Produced) ' scrivo stato end Part.nProduction_State = ItemState.Produced Part.dtEndTime = dtEnd Part.NotifyPropertyChanged(NameOf(Part.nProduction_State)) ' resetto stato redo Part.bRedo = False ' se non impostata data start If Part.dtStartTime = DateTime.MinValue Then ' scrivo data start su Db pezzo Dim dtStart As DateTime = Part.dtEndTime - TimeSpan.FromSeconds(60) DbControllers.m_PartController.UpdateStart(nP_Prod, nP_Machgroup, Part.nPartId, dtStart) Part.dtStartTime = dtStart End If ' scrivo evento fine pezzo su DB DbControllers.m_LogMachineController.Create(LogEvent.CreatePartStateLog(dtEnd, nP_Prod, nP_Machgroup, Part.nPartId, nP_State, DbControllers.SupervisorId)) Next End If Else ' scrivo data end su Db pezzo DbControllers.m_PartController.UpdateEnd(nP_Prod, nP_Machgroup, nP_Part, dtEnd) DbControllers.m_PartController.UpdateStatus(nP_Prod, nP_Machgroup, nP_Part, ItemState.Produced) If Not IsNothing(MachGroup) Then ' recupero pezzo Dim Part As PartVM = MachGroup.PartVMList.FirstOrDefault(Function(x) x.nPartId = nP_Part) If Not IsNothing(Part) Then ' scrivo stato end Part.nProduction_State = ItemState.Produced Part.dtEndTime = dtEnd Part.NotifyPropertyChanged(NameOf(Part.nProduction_State)) ' resetto stato redo Part.bRedo = False End If End If ' scrivo evento fine pezzo su DB DbControllers.m_LogMachineController.Create(LogEvent.CreatePartStateLog(dtEnd, nP_Prod, nP_Machgroup, nP_Part, nP_State, DbControllers.SupervisorId)) End If ' se tutti i pezzi della barra sono in end If Not IsNothing(MachGroup) AndAlso MachGroup.PartVMList.All(Function(x) x.nProduction_State >= 2) Then ' scrivo data end su Db barra DbControllers.m_MachGroupController.UpdateEnd(nP_Prod, nP_Machgroup, dtEnd) DbControllers.m_MachGroupController.UpdateStatus(nP_Prod, nP_Machgroup, ItemState.Produced) ' scrivo stato end MachGroup.MyMachGroupM.SetProductionState(ItemState.Produced) MachGroup.dtEndTime = dtEnd MachGroup.NotifyPropertyChanged(NameOf(MachGroup.nProduction_State)) ' scrivo evento fine MachGroup su DB DbControllers.m_LogMachineController.Create(LogEvent.CreateMachGroupStateLog(dtEnd, nP_Prod, nP_Machgroup, nP_State, DbControllers.SupervisorId)) ' azzero tutte le variabilli per iniziare barra successiva ' azzero variabile per far ripartire macchina If CurrentMachine.NCType = NCTypes.SIEMENS_SHARP7 Then DebugMessage(1, "Confermo lettura dati end") DataReadedVariable.sValue = "1" Else ProdVariable.sValue = "0" MachGroupVariable.sValue = "0" PartVariable.sValue = "0" StateVariable.sValue = "0" End If ' se non impostata data start If MachGroup.dtStartTime = DateTime.MinValue Then Dim dtStart As DateTime = MachGroup.dtEndTime - TimeSpan.FromSeconds(60) ' provo a recuperare tempo stimato If MachGroup.nCALC_TIME > 0 Then Dim MinPartStart As DateTime = MachGroup.PartVMList.Min(Function(x) x.dtStartTime) If MinPartStart > DateTime.MinValue Then dtStart = New DateTime(Math.Min((MachGroup.dtEndTime - TimeSpan.FromSeconds(MachGroup.nCALC_TIME)).Ticks, MinPartStart.Ticks)) Else dtStart = MachGroup.dtEndTime - TimeSpan.FromSeconds(MachGroup.nCALC_TIME) End If End If ' scrivo data start su Db barra DbControllers.m_MachGroupController.UpdateStart(nP_Prod, nP_Machgroup, dtStart) MachGroup.dtStartTime = dtStart End If ' resetto stati di produzione MachGroup.ResetProduce() ' se partenza pezzi uno a uno If CurrentMachine.Flow = FlowTypes.ONEBYONE Then ' riattivo bottone produzione per tutti gli altri MyMachGroupVM.UpdateProduceIsEnabledForAll() End If Else ' azzero variabile per far ripartire macchina If CurrentMachine.NCType = NCTypes.SIEMENS_SHARP7 Then DataReadedVariable.sValue = "1" Else StateVariable.sValue = "0" End If End If ' se pezzo = -1 stampo etichette di tutti i pezzi del MachGroup If nP_Part = -1 Then If Not IsNothing(MachGroup) Then For Each Part In MachGroup.PartVMList Map.refLeftPanelVM.PrintLabel(MachGroup, Part) Next End If Else ' recupero pezzo Dim Part As PartVM = MachGroup.PartVMList.FirstOrDefault(Function(x) x.nPartId = nP_Part) If Not IsNothing(Part) Then Map.refLeftPanelVM.PrintLabel(MachGroup, Part) End If End If ' flag di aggiornamento log macchina Map.refMachineLogPageVM.UpdateMachineLogList(False) DebugMessage(1, "Fine lettura dati end") ' attesa per essere sicuro che abbia scritto e riletto variabili Threading.Thread.Sleep(300) End If End If End Select ' funzione che riavvia comunicazione Siemens se necessario If CurrentMachine.NCType = NCTypes.SIEMENS_SHARP7 Then Siemens_Sharp7.RefreshConnection() End If End Sub Private m_Lock_SendProgram As New Object Private Function SetNextBarVars(nRunning As Integer) As Boolean ' verifico se c'e' un programma da lanciare If Not IsNothing(Map.refProjectVM.SupervisorMachGroupPanelVM) Then For Each MyMachGroup As MyMachGroupVM In Map.refProjectVM.SupervisorMachGroupPanelVM.MachGroupVMList If If(CurrentMachine.NCType = NCTypes.TPA, Not MyMachGroup.bSentToMachine, MyMachGroup.bSentToMachine AndAlso nRunning <> 0 AndAlso MyMachGroup.nName <> nRunning) AndAlso MyMachGroup.dtStartTime = DateTime.MinValue Then If MyMachGroup.bReadyForMachining Then ' leggo valori parametri V da file Dim dVPars(10) As Double Dim Lines() As String = File.ReadAllLines(MyMachGroup.CnFilePath()) Dim sVs() As String = Lines(0).Split(";"c) For VParIndex = 1 To sVs.Length - 1 Dim VPar() As String = sVs(VParIndex).Split("="c) VPar(1) = VPar(1).Trim StringToDoubleAdv(VPar(1), dVPars(VParIndex - 1)) Next ' li scrivo nel CN Select Case CurrentMachine.NCType Case NCTypes.TPA For Index As Integer = 1 To 10 Dim sValue As String = "" sValue = DoubleToString(dVPars(Index - 1), 2) Tpa.RWVariableManager.WriteVarByName(VPAR & Index.ToString(), sValue) Next Case NCTypes.SIEMENS_SHARP7 ' imposto larghezza barra Dim NextPartL As Variable = Map.refMachCommandMessagePanelVM.MainVariablesList.FirstOrDefault(Function(x) x.sName = NEXTPART_L) NextPartL.sValue = DoubleToString(Math.Ceiling(dVPars(0)), 2) Dim NextPartW As Variable = Map.refMachCommandMessagePanelVM.MainVariablesList.FirstOrDefault(Function(x) x.sName = NEXTPART_W) NextPartW.sValue = DoubleToString(dVPars(1), 2) Dim NextPartH As Variable = Map.refMachCommandMessagePanelVM.MainVariablesList.FirstOrDefault(Function(x) x.sName = NEXTPART_H) NextPartH.sValue = DoubleToString(dVPars(2), 2) Dim NextPartPressX1 As Variable = Map.refMachCommandMessagePanelVM.MainVariablesList.FirstOrDefault(Function(x) x.sName = NEXTPART_PRESSX1) NextPartPressX1.sValue = DoubleToString(dVPars(3), 2) Dim NextPartFeed As Variable = Map.refMachCommandMessagePanelVM.MainVariablesList.FirstOrDefault(Function(x) x.sName = NEXTPART_FEED) NextPartFeed.sValue = DoubleToString(dVPars(4), 2) Dim NextPartAcc As Variable = Map.refMachCommandMessagePanelVM.MainVariablesList.FirstOrDefault(Function(x) x.sName = NEXTPART_ACC) NextPartAcc.sValue = DoubleToString(dVPars(5), 2) Dim NextPartRef1 As Variable = Map.refMachCommandMessagePanelVM.MainVariablesList.FirstOrDefault(Function(x) x.sName = NEXTPART_REF1) NextPartRef1.sValue = DoubleToString(dVPars(6), 2) Dim NextPartRef2 As Variable = Map.refMachCommandMessagePanelVM.MainVariablesList.FirstOrDefault(Function(x) x.sName = NEXTPART_REF2) NextPartRef2.sValue = DoubleToString(dVPars(7), 2) 'DebugMessage(1, "Imposto larghezza: " & MyMachGroup.dW) End Select m_NextBarId = MyMachGroup.Id Return True Else If CurrentMachine.NCType = NCTypes.SIEMENS_SHARP7 Then ' metto tutti i valori a 0 ResetNextBarVars() End If Return False End If End If Next ' se ho passato tutte le barre della lista, resetto valori carico barra successiva If CurrentMachine.NCType = NCTypes.SIEMENS_SHARP7 Then ' metto tutti i valori a 0 ResetNextBarVars() End If End If Return False End Function Private Function ResetNextBarVars() As Boolean ' li scrivo nel CN Select Case CurrentMachine.NCType Case NCTypes.TPA For Index As Integer = 1 To 10 Dim sValue As String = "" sValue = DoubleToString(0, 2) Tpa.RWVariableManager.WriteVarByName(VPAR & Index.ToString(), sValue) Next Case NCTypes.SIEMENS_SHARP7 ' imposto larghezza barra Dim NextPartL As Variable = Map.refMachCommandMessagePanelVM.MainVariablesList.FirstOrDefault(Function(x) x.sName = NEXTPART_L) NextPartL.sValue = DoubleToString(0, 2) Dim NextPartW As Variable = Map.refMachCommandMessagePanelVM.MainVariablesList.FirstOrDefault(Function(x) x.sName = NEXTPART_W) NextPartW.sValue = DoubleToString(0, 2) Dim NextPartH As Variable = Map.refMachCommandMessagePanelVM.MainVariablesList.FirstOrDefault(Function(x) x.sName = NEXTPART_H) NextPartH.sValue = DoubleToString(0, 2) Dim NextPartPressX1 As Variable = Map.refMachCommandMessagePanelVM.MainVariablesList.FirstOrDefault(Function(x) x.sName = NEXTPART_PRESSX1) NextPartPressX1.sValue = DoubleToString(0, 2) Dim NextPartFeed As Variable = Map.refMachCommandMessagePanelVM.MainVariablesList.FirstOrDefault(Function(x) x.sName = NEXTPART_FEED) NextPartFeed.sValue = DoubleToString(0, 2) Dim NextPartAcc As Variable = Map.refMachCommandMessagePanelVM.MainVariablesList.FirstOrDefault(Function(x) x.sName = NEXTPART_ACC) NextPartAcc.sValue = DoubleToString(0, 2) Dim NextPartRef1 As Variable = Map.refMachCommandMessagePanelVM.MainVariablesList.FirstOrDefault(Function(x) x.sName = NEXTPART_REF1) NextPartRef1.sValue = DoubleToString(0, 2) Dim NextPartRef2 As Variable = Map.refMachCommandMessagePanelVM.MainVariablesList.FirstOrDefault(Function(x) x.sName = NEXTPART_REF2) NextPartRef2.sValue = DoubleToString(0, 2) 'DebugMessage(1, "Imposto larghezza: " & MyMachGroup.dW) End Select Return False End Function Private Function SendNextProgram() As Boolean Dim bSent As Boolean = False If (CurrentMachine.NCType = NCTypes.TPA AndAlso Not m_bStartPending AndAlso Tpa.opState = MachineOperatingState.Pending) OrElse (CurrentMachine.NCType = NCTypes.NUM_FLEXIUM AndAlso Not Num_Flexium.bIsTransferActive) OrElse (CurrentMachine.NCType = NCTypes.NUM_AXIUM_APSERVER AndAlso Not Num_Axium_APServer.bIsTransferActive) OrElse (CurrentMachine.NCType = NCTypes.NUM_AXIUM_PCTOOLKIT AndAlso Not Num_Axium_PCToolkit.bIsTransferActive) OrElse CurrentMachine.NCType = NCTypes.SIEMENS_SHARP7 Then ' Or Tpa.opState = MachineOperatingState.Start) Then ' verifico se c'e' un programma da lanciare If Not IsNothing(Map.refProjectVM.SupervisorMachGroupPanelVM) Then Dim bMachGroupNotReady As Boolean = False SyncLock m_Lock_SendProgram For Each MyMachGroup As MyMachGroupVM In Map.refProjectVM.SupervisorMachGroupPanelVM.MachGroupVMList DebugMessage(1, "Ciclo alla ricerca di un programma da mandare") ' EgtOutLog("Ciclo su name: " & MyMachGroup.Name & " id: " & MyMachGroup.Id) If Not MyMachGroup.bSentToMachine AndAlso (If(CurrentMachine.NCType <> NCTypes.SIEMENS_SHARP7, MyMachGroup.dtStartTime = DateTime.MinValue, MyMachGroup.dtEndTime = DateTime.MinValue) OrElse (Map.refSupervisorManagerVM.CurrProd.nType = BWType.WALL AndAlso MyMachGroup.bResetWhileCutting)) Then ' verifico se ricalcolo finito If MyMachGroup.bReadyForMachining AndAlso If(CurrentMachine.NCType = NCTypes.NUM_FLEXIUM Or CurrentMachine.NCType = NCTypes.NUM_AXIUM_APSERVER OrElse CurrentMachine.NCType = NCTypes.NUM_AXIUM_PCTOOLKIT, Not MyMachGroup.bSendingToMachine, True) Then ' lo lancio DebugMessage(1, "Eseguo SendProgram") bSent = SendProgram(MyMachGroup.CnFilePath(), MyMachGroup.Name, MyMachGroup) ' EgtOutLog(MyMachGroup.Name & " id: " & MyMachGroup.Id & " mandato " & DateTime.Now() & " " & MyMachGroup.Name & " " & bSent.ToString()) Select Case CurrentMachine.NCType Case NCTypes.TPA, NCTypes.SIEMENS_SHARP7 MyMachGroup.SetSentToMachine(bSent) Case NCTypes.NUM_FLEXIUM, NCTypes.NUM_AXIUM_APSERVER, NCTypes.NUM_AXIUM_PCTOOLKIT MyMachGroup.SetSendingToMachine(bSent) End Select m_NextBarId = 0 Exit For Else ' programma non ancora pronto, esco per attendere bMachGroupNotReady = True Exit For 'Return False End If End If Next End SyncLock If CurrentMachine.NCType = NCTypes.SIEMENS_SHARP7 AndAlso Not Map.refProjectVM.SupervisorMachGroupPanelVM.MachGroupVMList.Any(Function(x As MyMachGroupVM) x.nProduction_State < ItemState.WIP And x.bReadyForMachining) Then Dim ISONumVariable As Variable = Map.refMachCommandMessagePanelVM.MainVariablesList.FirstOrDefault(Function(x) x.sName = ISO_NUM) Dim nISONum As Integer = 0 If Not Integer.TryParse(ISONumVariable.sValue, nISONum) Or nISONum <> 0 Then DebugMessage(1, "Resetto programma da inviare") ISONumVariable.sValue = 0 ' resetto variabili per prossima barra ResetNextBarVars() ' do stop working Dim StopWorking As Variable = Map.refMachCommandMessagePanelVM.MainVariablesList.FirstOrDefault(Function(x) x.sName = STOP_WORKING) StopWorking.sValue = "1" End If End If 'If CurrentMachine.NCType = NCTypes.SIEMENS_SHARP7 Then ' SetNextBarVars() 'End If If bMachGroupNotReady Then Return False End If End If Return bSent End Function Private Sub CommandList_CollectionChanged(sender As Object, e As NotifyCollectionChangedEventArgs) If Not IsNothing(e.NewItems) Then Dim nCommandCount As Integer = e.NewItems.Count For CommandIndex = 0 To nCommandCount - 1 Dim Command As ThreadCommand = e.NewItems(CommandIndex) If Command.ProcessingStatus = ThreadCommand.ProcessingStatuses.WAITING Then Command.SetProcessingStatus(ThreadCommand.ProcessingStatuses.PROCESSING) ExecuteCommand(DirectCast(Command, ThreadCommand)) Command.SetProcessingStatus(ThreadCommand.ProcessingStatuses.DONE) End If Next End If End Sub Private Sub ExecuteCommand(Command As ThreadCommand) Select Case Command.CommandType Case CommandTypes.CONNECT Connect() Case CommandTypes.DISCONNECT Disconnect() Case CommandTypes.START Start() Case CommandTypes.STOP_ [Stop]() Case CommandTypes.RESET Reset() Case CommandTypes.STEP_ Step_() Case CommandTypes.SETPOINT SetPoint() Case CommandTypes.SENDPROG SendProgram(Command.sVariable, Command.sVariables(1)) Case CommandTypes.REMOVEPROG RemoveProgram(Command.nVariable, Command.sVariable, Command.sVariables(1)) Case CommandTypes.REMOVEALLPROG RemoveAllProgram() Case CommandTypes.READ_TPA Tpa.RWVariableManager.RefreshVar(Command.sVariable) Case CommandTypes.WRITE WriteVar(Command.sVariable, Command.sVariables(1), Command.nVariable) Case CommandTypes.DELETEALARMS DeleteAlarms() Case CommandTypes.SETOPMODE SetOPState(Command.nVariable) Case CommandTypes.READ_NUMFLEXIUM Num_Flexium.StartReadList() Num_Flexium.StartReadELS() Case CommandTypes.STOPREAD_NUMFLEXIUM Num_Flexium.CloseReadList() Num_Flexium.CloseReadELS() Case CommandTypes.MDI SendMDI(Command.sVariable) Case CommandTypes.SETCHANNEL SetChannel(Command.nVariable) End Select End Sub Public Sub Connect() Select Case CurrentMachine.NCType Case NCTypes.TPA Try m_CN = New TPAComm(Me) m_bConnected = Tpa.remObject.OnConnect() m_ResultCallbackDlg(CommandTypes.CONNECT, CommandStates.OK, ResultTypes.EXECUTED, "") ' imposto stato manuale Dim ManualMode As OPState = Map.refLeftPanelVM.OPModeList.FirstOrDefault(Function(x) x.Id = OPModes.Manual) Map.refLeftPanelVM.SetOPMode(ManualMode) ' creo classe di gestione variabili Catch ex As Exception m_ResultCallbackDlg(CommandTypes.CONNECT, CommandStates.ERROR_, ResultTypes.EXECUTED, "Errore: impossibile connettersi!") Return End Try Case NCTypes.NUM_FLEXIUM Try m_CN = New NUMFlexiumComm(Me) Num_Flexium.InitFxServer() m_ResultCallbackDlg(CommandTypes.CONNECT, CommandStates.OK, ResultTypes.EXECUTED, "") ' creo classe di gestione variabili Catch ex As Exception m_ResultCallbackDlg(CommandTypes.CONNECT, CommandStates.ERROR_, ResultTypes.EXECUTED, "Errore: impossibile connettersi!") Return End Try Case NCTypes.NUM_AXIUM_APSERVER Try m_CN = New NUMAxiumComm(Me) Num_Axium_APServer.InitFxObjects() m_ResultCallbackDlg(CommandTypes.CONNECT, CommandStates.OK, ResultTypes.EXECUTED, "") ' creo classe di gestione variabili Catch ex As Exception m_ResultCallbackDlg(CommandTypes.CONNECT, CommandStates.ERROR_, ResultTypes.EXECUTED, "Errore: impossibile connettersi!") Return End Try Case NCTypes.NUM_AXIUM_PCTOOLKIT Try m_CN = New NUMAxiumPcToolkitComm(Me) If Num_Axium_PCToolkit.InitConnection() Then Num_Axium_PCToolkit.GetGeneralFunctions() m_ResultCallbackDlg(CommandTypes.CONNECT, CommandStates.OK, ResultTypes.EXECUTED, "") Else m_ResultCallbackDlg(CommandTypes.CONNECT, CommandStates.ERROR_, ResultTypes.EXECUTED, "Errore: impossibile connettersi!") Return End If ' creo classe di gestione variabili Catch ex As Exception m_ResultCallbackDlg(CommandTypes.CONNECT, CommandStates.ERROR_, ResultTypes.EXECUTED, "Errore: impossibile connettersi!") Return End Try Case NCTypes.SIEMENS_SHARP7 Try m_CN = New SIEMENSSharp7Comm(Me) If Siemens_Sharp7.InitConnection() Then m_bConnected = True ' imposto stato manuale Dim ManualMode As OPState = Map.refLeftPanelVM.OPModeList.FirstOrDefault(Function(x) x.Id = OPModes.Manual) Map.refLeftPanelVM.SetOPMode(ManualMode) m_ResultCallbackDlg(CommandTypes.CONNECT, CommandStates.OK, ResultTypes.EXECUTED, "") Else m_ResultCallbackDlg(CommandTypes.CONNECT, CommandStates.ERROR_, ResultTypes.EXECUTED, "Errore: impossibile connettersi!") Return End If ' creo classe di gestione variabili Catch ex As Exception m_ResultCallbackDlg(CommandTypes.CONNECT, CommandStates.ERROR_, ResultTypes.EXECUTED, "Errore: impossibile connettersi!") Return End Try End Select End Sub Public Sub Disconnect() Select Case CurrentMachine.NCType Case NCTypes.TPA Dim bOk As Boolean = Tpa.remObject.OnClose() m_bConnected = Not bOk m_ResultCallbackDlg(CommandTypes.DISCONNECT, If(bOk, CommandStates.OK, CommandStates.ERROR_), ResultTypes.EXECUTED, "") ' chiudo classe Tpa Me.OnDispose() Tpa.OnDispose() Case NCTypes.NUM_FLEXIUM m_bConnected = False m_ResultCallbackDlg(CommandTypes.DISCONNECT, CommandStates.OK, ResultTypes.EXECUTED, "") ' chiudo classe Num_Flexium Me.OnDispose() Case NCTypes.NUM_AXIUM_APSERVER m_bConnected = False Num_Axium_APServer.CloseFxObjects() m_ResultCallbackDlg(CommandTypes.DISCONNECT, CommandStates.OK, ResultTypes.EXECUTED, "") ' chiudo classe Num_Flexium Me.OnDispose() Case NCTypes.NUM_AXIUM_PCTOOLKIT m_bConnected = False Num_Axium_PCToolkit.CloseFxObjects() m_ResultCallbackDlg(CommandTypes.DISCONNECT, CommandStates.OK, ResultTypes.EXECUTED, "") ' chiudo classe Num_Flexium Me.OnDispose() Case NCTypes.SIEMENS_SHARP7 m_bConnected = False If Not IsNothing(Siemens_Sharp7) Then Siemens_Sharp7.CloseConnection() End If m_ResultCallbackDlg(CommandTypes.DISCONNECT, CommandStates.OK, ResultTypes.EXECUTED, "") ' chiudo classe Num_Flexium Me.OnDispose() End Select ' termino thread di comunicazione MachineCommThread.StopThread() End Sub Public Sub SetOPState(CNMode As NUMFlexiumComm.CNMode) Select Case CurrentMachine.NCType Case NCTypes.NUM_FLEXIUM Num_Flexium.SetMode(CNMode) Case NCTypes.NUM_AXIUM_APSERVER Num_Axium_APServer.SetMode(CNMode) Case NCTypes.NUM_AXIUM_PCTOOLKIT Num_Axium_PCToolkit.SetMode(CNMode) End Select End Sub Public Sub Start() Select Case CurrentMachine.NCType Case NCTypes.TPA Dim bOk As Boolean ' imposto programma default.iso If Tpa.opState = MachineOperatingState.End OrElse Tpa.opState = MachineOperatingState.Unspecified Then Tpa.remObject.RemoveAllProgramsFromList() Dim bFileOk As Boolean = False Dim DefaultIsoFilePath As String = "C:\Albatros\system\DEFAULT.iso" ' verifico se esiste path Try If File.Exists(DefaultIsoFilePath) Then bFileOk = True Catch ex As Exception bFileOk = False End Try If Not bFileOk Then Try File.Copy(Map.refMainWindowVM.MainWindowM.sMachineMacroDir & "\" & "DEFAULT.ISO", DefaultIsoFilePath) bFileOk = True Catch ex As Exception m_ResultCallbackDlg(CommandTypes.START, CommandStates.ERROR_, ResultTypes.NULL, "Error in copying DEFAULT.ISO file") EgtBEAMWALL.Core.EgtMessageBoxV.Show(Application.Current.MainWindow, EgtMsg(62548), EgtMsg(15001), MessageBoxButton.OK, MessageBoxImage.Error) Return End Try End If bOk = Tpa.remObject.AddProgramToList(DefaultIsoFilePath) Threading.Thread.Sleep(1000) bOk = Tpa.remObject.SetCommand(CInt(ISOCNC.Remoting.Commands.Start)) m_ResultCallbackDlg(CommandTypes.START, If(bOk, CommandStates.OK, CommandStates.ERROR_), ResultTypes.EXECUTED, "DEFAULT.ISO send") End If bOk = Tpa.remObject.SetCommand(CInt(ISOCNC.Remoting.Commands.Start)) m_bStartPending = bOk m_ResultCallbackDlg(CommandTypes.START, If(bOk, CommandStates.OK, CommandStates.ERROR_), ResultTypes.EXECUTED, "") Case NCTypes.NUM_FLEXIUM Num_Flexium.Start() Case NCTypes.NUM_AXIUM_APSERVER Num_Axium_APServer.Start() Case NCTypes.NUM_AXIUM_PCTOOLKIT Num_Axium_PCToolkit.Start() End Select ' aggiorno stato bottoni in LeftPanel Map.refLeftPanelVM.UpdateButtonIsEnabledState() End Sub Public Sub [Stop]() Select Case CurrentMachine.NCType Case NCTypes.TPA Dim bOk As Boolean = Tpa.remObject.SetCommand(CInt(ISOCNC.Remoting.Commands.[Stop])) m_ResultCallbackDlg(CommandTypes.STOP_, If(bOk, CommandStates.OK, CommandStates.ERROR_), ResultTypes.EXECUTED, "") Case NCTypes.NUM_FLEXIUM Num_Flexium.Stop_() Case NCTypes.NUM_AXIUM_APSERVER Num_Axium_APServer.Stop_() Case NCTypes.NUM_AXIUM_PCTOOLKIT Num_Axium_PCToolkit.Stop_() End Select End Sub Public Sub Reset() Select Case CurrentMachine.NCType Case NCTypes.TPA Dim bOk As Boolean = Tpa.remObject.SetCommand(CInt(ISOCNC.Remoting.Commands.[End])) m_ResultCallbackDlg(CommandTypes.RESET, If(bOk, CommandStates.OK, CommandStates.ERROR_), ResultTypes.EXECUTED, "") Case NCTypes.NUM_FLEXIUM Num_Flexium.Reset() Case NCTypes.NUM_AXIUM_APSERVER Num_Axium_APServer.Reset() Case NCTypes.NUM_AXIUM_PCTOOLKIT Num_Axium_PCToolkit.Reset() Case NCTypes.SIEMENS_SHARP7 ' annullo solamente step di avanzamento Siemens_Sharp7.ResetStep(True) End Select ' aggiorno stato bottoni in LeftPanel Map.refLeftPanelVM.UpdateButtonIsEnabledState() End Sub Public Sub Step_() Select Case CurrentMachine.NCType Case NCTypes.TPA Dim bOk As Boolean = Tpa.remObject.SetCommand(CInt(ISOCNC.Remoting.Commands.Step)) m_ResultCallbackDlg(CommandTypes.STEP_, If(bOk, CommandStates.OK, CommandStates.ERROR_), ResultTypes.EXECUTED, "") Case NCTypes.NUM_FLEXIUM '' End Select End Sub Public Sub SetPoint() Select Case CurrentMachine.NCType Case NCTypes.TPA Dim bOk As Boolean = Tpa.remObject.SetCommand(CInt(ISOCNC.Remoting.Commands.SetPoint)) m_ResultCallbackDlg(CommandTypes.SETPOINT, If(bOk, CommandStates.OK, CommandStates.ERROR_), ResultTypes.EXECUTED, "") Case NCTypes.NUM_FLEXIUM Map.refLeftPanelVM.SelOPMode = Map.refLeftPanelVM.OPModeList.Find(Function(x) x.Id = OPModes.Home) Case NCTypes.NUM_AXIUM_APSERVER Map.refLeftPanelVM.SelOPMode = Map.refLeftPanelVM.OPModeList.Find(Function(x) x.Id = OPModes.Home) Case NCTypes.NUM_AXIUM_PCTOOLKIT Map.refLeftPanelVM.SelOPMode = Map.refLeftPanelVM.OPModeList.Find(Function(x) x.Id = OPModes.Home) End Select End Sub Public Function SendProgram(ProgramPath As String, ProgramId As String, Optional MyMachGroup As MyMachGroupVM = Nothing) As Boolean Select Case CurrentMachine.NCType Case NCTypes.TPA If Tpa.opState = MachineOperatingState.Pending Then Tpa.remObject.RemoveAllProgramsFromList() Dim bOk As Boolean = False ProgramPath = ProgramPath.Replace("\\", "\") bOk = Tpa.remObject.AddProgramToList(ProgramPath) Threading.Thread.Sleep(1000) bOk = Tpa.remObject.SetCommand(CInt(ISOCNC.Remoting.Commands.Start_Program_Soft)) m_ResultCallbackDlg(CommandTypes.SENDPROG, If(bOk, CommandStates.OK, CommandStates.ERROR_), ResultTypes.EXECUTED, "") Return bOk End If Return False Case NCTypes.NUM_FLEXIUM Dim sFileType As String = "%" & ProgramId.ToString() Num_Flexium.FileDownload(sFileType, ProgramPath) Num_Flexium.StartTransfer() Return True Case NCTypes.NUM_AXIUM_APSERVER Dim sFileType As String = "%" & ProgramId.ToString() Num_Axium_APServer.FileDownload(sFileType, ProgramPath) Num_Axium_APServer.StartTransfer() Return True Case NCTypes.NUM_AXIUM_PCTOOLKIT Dim nFileType As Integer = 0 If Integer.TryParse(ProgramId, nFileType) AndAlso nFileType > 0 Then Num_Axium_PCToolkit.FileDownload(nFileType * 10, ProgramPath) End If Return True Case NCTypes.SIEMENS_SHARP7 ' EgtOutLog("Pre Download") Dim nFileType As Integer = 0 If Integer.TryParse(ProgramId, nFileType) AndAlso nFileType > 0 Then Dim sDestDir As String = "" GetPrivateProfileString(S_GENERAL, K_ISOFILEDIR, "c:/Saomad/ISO", sDestDir, CurrentMachine.sMachIniFile) DebugMessage(1, "Copio programma") File.Copy(ProgramPath, sDestDir & "\" & nFileType & ".mpf", True) ' copio POSIZ file Dim sPosizPath As String = Path.GetDirectoryName(ProgramPath) & "\" & Path.GetFileNameWithoutExtension(ProgramPath) & "_POSIZ.mpf" File.Copy(sPosizPath, sDestDir & "\" & nFileType & "_POSIZ.mpf", True) ' se primo dopo start If m_bFirstRaw Then m_bFirstRaw = False DebugMessage(1, "Primo grezzo") ' annullo step di ripartenza If Not Map.refMachManaging.Siemens_Sharp7.ResetStep(Not (MyMachGroup.dtStartTime <> DateTime.MinValue OrElse MyMachGroup.nProduction_State = ItemState.WIP)) Then Return False End If ' imposto larghezza barra Dim WCarico As Variable = Map.refMachCommandMessagePanelVM.MainVariablesList.FirstOrDefault(Function(x) x.sName = W_CARICO) WCarico.sValue = DoubleToString(MyMachGroup.dW, 1) DebugMessage(1, "Imposto larghezza: " & MyMachGroup.dW) ' resetto eventuale stop working Dim StopWorking As Variable = Map.refMachCommandMessagePanelVM.MainVariablesList.FirstOrDefault(Function(x) x.sName = STOP_WORKING) If StopWorking.sValue = "1" Then StopWorking.sValue = "0" End If ' imposto numero programma scritto Dim ISONumVariable As Variable = Map.refMachCommandMessagePanelVM.MainVariablesList.FirstOrDefault(Function(x) x.sName = ISO_NUM) DebugMessage(1, "Imposto programma inviato: " & nFileType) ISONumVariable.sValue = nFileType End If Return True End Select Return False End Function Public Sub RemoveProgram(ProgramIndex As Integer, ProgramPath As String, ProgramType As String) Select Case CurrentMachine.NCType Case NCTypes.TPA Dim bOk As Boolean Dim sError As String = "" If ProgramIndex > 0 Then bOk = CN.remObject.RemoveProgramFromListAtIndex(ProgramIndex) ElseIf Not String.IsNullOrEmpty(ProgramPath) Then bOk = CN.remObject.RemoveProgramFromList(ProgramPath) Else bOk = False sError = "Errore: nessun parametro passato" End If m_ResultCallbackDlg(CommandTypes.REMOVEPROG, If(bOk, CommandStates.OK, CommandStates.ERROR_), ResultTypes.EXECUTED, sError) Case NCTypes.NUM_FLEXIUM Num_Flexium.FileDelete(ProgramType, ProgramPath) Num_Flexium.StartTransfer() Case NCTypes.NUM_AXIUM_APSERVER Num_Axium_APServer.FileDelete(ProgramType, ProgramPath) Num_Axium_APServer.StartTransfer() Case NCTypes.NUM_AXIUM_PCTOOLKIT Num_Axium_PCToolkit.FileDelete(ProgramType, ProgramPath) End Select End Sub Public Sub RemoveAllProgram() Dim bOk As Boolean = CN.remObject.RemoveAllProgramsFromList() m_ResultCallbackDlg(CommandTypes.REMOVEALLPROG, If(bOk, CommandStates.OK, CommandStates.ERROR_), ResultTypes.EXECUTED, "") End Sub Public Sub DeleteAlarms() Select Case CurrentMachine.NCType Case NCTypes.TPA Dim bOk As Boolean = CN.remObject.DeleteAlarms(CInt(AlarmType.ISO)) bOk = CN.remObject.DeleteAlarms(CInt(AlarmType.Message)) bOk = CN.remObject.DeleteAlarms(CInt(AlarmType.Cycle)) bOk = CN.remObject.DeleteAlarms(CInt(AlarmType.System)) m_ResultCallbackDlg(CommandTypes.DELETEALARMS, If(bOk, CommandStates.OK, CommandStates.ERROR_), ResultTypes.EXECUTED, "") End Select End Sub Public Sub SetChannel(value As Integer) Select Case CurrentMachine.NCType Case NCTypes.NUM_FLEXIUM Num_Flexium.SetChannel(value) Case NCTypes.NUM_AXIUM_APSERVER Num_Axium_APServer.SetChannel(value) Case NCTypes.NUM_AXIUM_PCTOOLKIT Num_Axium_PCToolkit.SetChannel(value) End Select End Sub Public Sub SendMDI(value As String) Select Case CurrentMachine.NCType Case NCTypes.NUM_FLEXIUM Num_Flexium.MDI_Execute(value) Case NCTypes.NUM_AXIUM_APSERVER Num_Axium_APServer.MDI_Execute(value) Case NCTypes.NUM_AXIUM_PCTOOLKIT Num_Axium_PCToolkit.MDI_Execute(value) End Select End Sub Public Sub WriteVar(Address As String, Value As String, Type As CommVar.Types) Select Case CurrentMachine.NCType Case NCTypes.TPA Tpa.RWVariableManager.WriteVarByAddress(Address, Value) Case NCTypes.NUM_FLEXIUM Select Case Type Case CommVar.Types.PLC Num_Flexium.WritePlcVariables(Address, Value) Case CommVar.Types.CN Num_Flexium.WriteNCVariables(Address, Value) End Select Case NCTypes.NUM_AXIUM_APSERVER Select Case Type Case CommVar.Types.PLC Num_Axium_APServer.WritePlcVariables(Address, Value) Case CommVar.Types.CN Num_Axium_APServer.WriteNCVariables(Address, Value) End Select Case NCTypes.NUM_AXIUM_PCTOOLKIT Select Case Type Case CommVar.Types.PLC Num_Axium_PCToolkit.WritePlcVariables(Address, Value) Case CommVar.Types.CN Num_Axium_PCToolkit.WriteNCVariables(Address, Value) End Select Case NCTypes.SIEMENS_SHARP7 Select Case Type Case CommVar.Types.PLC Siemens_Sharp7.WriteVariable(Address, Value) 'Case CommVar.Types.CN ' Num_Axium_PCToolkit.WriteNCVariables(Address, Value) End Select End Select End Sub Public Shared Function InitVar(Section As String, nIndex As Integer) As CommVar Dim NewVar As CommVar = GetPrivateProfileVariable(Section, nIndex, CurrentMachine.sMachIniFile) If IsNothing(NewVar) Then Return Nothing Select Case CurrentMachine.NCType Case NCTypes.TPA Return RWVariableManager.InitVar(NewVar) Case NCTypes.NUM_FLEXIUM Return NUMFlexiumComm.InitVar(NewVar) Case NCTypes.NUM_AXIUM_APSERVER Return NUMAxiumComm.InitVar(NewVar) Case NCTypes.NUM_AXIUM_PCTOOLKIT Return NUMAxiumPcToolkitComm.InitVar(NewVar) Case NCTypes.SIEMENS_SHARP7 Return SIEMENSSharp7Comm.InitVar(NewVar) End Select Return Nothing End Function Private Shared Function GetPrivateProfileVariable(IpAppName As String, IpKeyName As String, IpFileName As String) As CommVar Dim sVariable As String = "" EgtUILib.GetPrivateProfileString(IpAppName, IpKeyName, "", sVariable, IpFileName) If String.IsNullOrWhiteSpace(sVariable) Then Return Nothing Dim sVariableValues() As String = sVariable.Split(","c) 'If Not sVariableValues.Count >= 4 Then Return Nothing For Index As Integer = 0 To sVariableValues.Count - 1 sVariableValues(Index) = sVariableValues(Index).Trim() Next Dim ReadType As CommVar.ReadTypes Select Case sVariableValues(2).ToLower() Case "o" ReadType = CommVar.ReadTypes.ONETIME Case "c" ReadType = CommVar.ReadTypes.CONTINUOUS Case Else ReadType = CommVar.ReadTypes.NULL End Select Dim Type As CommVar.Types Select Case sVariableValues(3).ToLower() Case "plc" Type = CommVar.Types.PLC Case "cn" Type = CommVar.Types.CN Case Else Type = CommVar.ReadTypes.NULL End Select Dim Paragraph As Paragraphs = Paragraphs.NULL Select Case IpAppName Case S_MAINVARIABLES Paragraph = Paragraphs.MAIN Case S_INPUTVARIABLES Paragraph = Paragraphs.INPUT Case S_OUTPUTVARIABLES Paragraph = Paragraphs.OUTPUT End Select Dim sDescription As String = "" If sVariableValues.Length >= 5 Then Dim nDescription As Integer If Integer.TryParse(sVariableValues(4), nDescription) Then Dim MsgParagraph As MsgParagraphs Select Case Paragraph Case Paragraphs.INPUT MsgParagraph = MsgParagraphs.INPUT Case Paragraphs.OUTPUT MsgParagraph = MsgParagraphs.OUTPUT Case Else MsgParagraph = MsgParagraphs.INPUT End Select sDescription = MachMsg(MsgParagraph, nDescription) Else sDescription = sVariableValues(4) End If End If Return New CommVar(sVariableValues(0), sVariableValues(1), ReadType, Type, Paragraph, sDescription) End Function Private Sub ReadPLCMessages() Dim nPlc_Msg(5) As Integer For Index As Integer = 1 To 6 Dim nIndex As Integer = Index Dim PLCMessagesVariable As Variable = Map.refMachCommandMessagePanelVM.MainVariablesList.FirstOrDefault(Function(x) x.sName = PLC_MESSAGES & nIndex) If IsNothing(PLCMessagesVariable) OrElse IsNothing(PLCMessagesVariable.sValue) Then Return Dim nTemp As Integer = 0 Integer.TryParse(PLCMessagesVariable.sValue, nTemp) Dim Bytes As Byte() = BitConverter.GetBytes(nTemp) Dim NewBytes As Byte() = BitConverter.GetBytes(nTemp) For nBIndex = Bytes.Count - 1 To 0 Step -1 NewBytes(Bytes.Count - 1 - nBIndex) = Bytes(nBIndex) Next Dim Res = BitConverter.ToInt32(NewBytes, 0) nPlc_Msg(nIndex - 1) = Res Next Dim BitArray As New BitArray(nPlc_Msg) Dim ErrorList As New List(Of Integer) For BitIndex = 0 To BitArray.Count - 1 If BitIndex <= 169 AndAlso BitArray(BitIndex) Then ErrorList.Add(BitIndex) End If Next Select Case CurrentMachine.NCType Case NCTypes.NUM_AXIUM_APSERVER Num_Axium_APServer.objErrorHandler_ErrorFromActiveCnc2(ErrorList) Case NCTypes.NUM_AXIUM_PCTOOLKIT Num_Axium_PCToolkit.objErrorHandler_ErrorFromActiveCnc2(ErrorList) End Select End Sub #Region "Debug" Friend Sub DebugMessage(nLevel As Integer, sMessage As String) If m_Debug >= nLevel Then EgtOutLog(sMessage) End If End Sub #End Region ' Debug End Class