240 lines
9.8 KiB
VB.net
240 lines
9.8 KiB
VB.net
Imports System.Collections.ObjectModel
|
|
Imports System.Collections.Specialized
|
|
Imports System.Windows.Threading
|
|
Imports ISOCNC.Remoting
|
|
|
|
Class MachManaging
|
|
|
|
Private m_Timer As New DispatcherTimer
|
|
Friend ReadOnly Property Timer As New DispatcherTimer
|
|
|
|
Private m_bConnected As Boolean = False
|
|
Public ReadOnly Property bConnected As Boolean
|
|
Get
|
|
Return m_bConnected
|
|
End Get
|
|
End Property
|
|
|
|
Private m_Tpa As TPAComm = Nothing
|
|
Public ReadOnly Property Tpa As TPAComm
|
|
Get
|
|
Return m_Tpa
|
|
End Get
|
|
End Property
|
|
|
|
Public Shared WithEvents m_CommandList As ObservableCollection(Of ThreadCommand)
|
|
|
|
Sub New()
|
|
' imposto in Map
|
|
Map.SetRefMachManaging(Me)
|
|
AddHandler m_CommandList.CollectionChanged, AddressOf CommandList_CollectionChanged
|
|
m_Timer.Interval = New TimeSpan(100)
|
|
AddHandler m_Timer.Tick, AddressOf Timer_Tick
|
|
End Sub
|
|
|
|
Private Sub OnDispose()
|
|
m_Timer.Stop()
|
|
RemoveHandler m_CommandList.CollectionChanged, AddressOf CommandList_CollectionChanged
|
|
RemoveHandler m_Timer.Tick, AddressOf Timer_Tick
|
|
End Sub
|
|
|
|
Private Sub Timer_Tick(sender As Object, e As EventArgs)
|
|
'Dim bCancel As Boolean = False
|
|
'callback(0, "Init", bCancel)
|
|
|
|
' leggo tutte le variabili
|
|
Tpa.RWVariableManager.RefreshAllVars()
|
|
|
|
' eseguo ciclo principale
|
|
Dim nResetVar As Integer
|
|
'CommVar(sResetVarName, nResetVar)
|
|
Dim nP_Prod As Integer
|
|
Dim nP_Machgroup As Integer
|
|
Dim nP_Part As Integer
|
|
Dim nP_State As Integer
|
|
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)
|
|
' se macchina pronta e non sta tagliando alcun pezzo
|
|
If nResetVar = 0 AndAlso
|
|
Tpa.opState = 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
|
|
For Each MachGroup In Map.refProjectVM.SupervisorMachGroupPanelVM.MachGroupVMList
|
|
Dim MyMachGroup As MyMachGroupVM = DirectCast(MachGroup, MyMachGroupVM)
|
|
If MyMachGroup.bReadyForMachining Then
|
|
' recupero Path file CN
|
|
Dim CNPath As String = MyMachGroup.CnFilePath().Replace("\\\\", "\\")
|
|
' lo lancio
|
|
If (Map.refMachCommandMessagePanelVM.OPState = MachineOperatingState.Pending) Then
|
|
Dim bOk As Boolean = Tpa.remObject.AddProgramToList(CNPath)
|
|
Tpa.remObject.SetCommand(ISOCNC.Remoting.Commands.Start_Program_Soft)
|
|
End If
|
|
|
|
End If
|
|
Next
|
|
ElseIf nP_Prod <> 0 AndAlso
|
|
nP_Machgroup <> 0 AndAlso
|
|
nP_Part <> 0 Then
|
|
If nP_State = PartState.START Then
|
|
DbControllers.m_PartController.UpdateStart(nP_Prod, nP_Machgroup, nP_Part, DateTime.Now())
|
|
Dim MachGroup As MyMachGroupVM = Map.refProjectVM.SupervisorMachGroupPanelVM.MachGroupVMList.FirstOrDefault(Function(x) x.Id = nP_Machgroup)
|
|
MachGroup.MyMachGroupM.SetState(1)
|
|
MachGroup.NotifyPropertyChanged(NameOf(MachGroup.nState))
|
|
Dim Part As PartVM = MachGroup.PartVMList.FirstOrDefault(Function(x) x.nPartId = nP_Part)
|
|
Part.nState = 1
|
|
Part.NotifyPropertyChanged(NameOf(Part.nState))
|
|
If Not MachGroup.PartVMList.Any(Function(x) x.nState = 1) Then
|
|
DbControllers.m_MachGroupController.UpdateStart(nP_Prod, nP_Machgroup, DateTime.Now())
|
|
MachGroup.MyMachGroupM.SetState(2)
|
|
MachGroup.NotifyPropertyChanged(NameOf(MachGroup.nState))
|
|
End If
|
|
ElseIf nP_State = PartState.END_ Then
|
|
DbControllers.m_PartController.UpdateEnd(nP_Prod, nP_Machgroup, nP_Part, DateTime.Now())
|
|
Dim MachGroup As MyMachGroupVM = Map.refProjectVM.SupervisorMachGroupPanelVM.MachGroupVMList.FirstOrDefault(Function(x) x.Id = nP_Machgroup)
|
|
Dim Part As PartVM = MachGroup.PartVMList.FirstOrDefault(Function(x) x.nPartId = nP_Part)
|
|
Part.nState = 2
|
|
Part.NotifyPropertyChanged(NameOf(Part.nState))
|
|
If MachGroup.PartVMList.All(Function(x) x.nState >= 2) Then
|
|
DbControllers.m_MachGroupController.UpdateEnd(nP_Prod, nP_Machgroup, DateTime.Now())
|
|
MachGroup.MyMachGroupM.SetState(2)
|
|
MachGroup.NotifyPropertyChanged(NameOf(MachGroup.nState))
|
|
End If
|
|
' azzero variabili
|
|
Tpa.RWVariableManager.WriteVar(P_PROD, 0)
|
|
Tpa.RWVariableManager.WriteVar(P_MACHGROUP, 0)
|
|
Tpa.RWVariableManager.WriteVar(P_PART, 0)
|
|
Tpa.RWVariableManager.WriteVar(P_STATE, 0)
|
|
End If
|
|
End If
|
|
|
|
End Sub
|
|
|
|
Private Sub CommandList_CollectionChanged(sender As Object, e As NotifyCollectionChangedEventArgs)
|
|
For Index = e.NewItems.Count - 1 To 0 Step -1
|
|
ExecuteCommand(DirectCast(e.NewItems(Index), ThreadCommand))
|
|
m_CommandList.Remove(e.NewItems(Index))
|
|
Next
|
|
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.SETPOINT
|
|
SetPoint()
|
|
Case CommandTypes.SENDPROG
|
|
SendProgram(Command.sVariable)
|
|
Case CommandTypes.REMOVEPROG
|
|
RemoveProgram(Command.nVariable, Command.sVariable)
|
|
Case CommandTypes.REMOVEALLPROG
|
|
RemoveAllProgram()
|
|
Case CommandTypes.READ
|
|
Tpa.RWVariableManager.RefreshVar(Command.sVariable)
|
|
Case CommandTypes.WRITE
|
|
Tpa.RWVariableManager.WriteVar(Command.sVariable, Command.sVariable(1))
|
|
Case CommandTypes.DELETEALARMS
|
|
DeleteAlarms()
|
|
Case CommandTypes.SETOP
|
|
|
|
End Select
|
|
End Sub
|
|
|
|
Public Sub Connect()
|
|
Try
|
|
m_Tpa = New TPAComm(Me)
|
|
m_bConnected = Tpa.remObject.OnConnect()
|
|
m_ResultCallbackDlg(CommandTypes.CONNECT, CommandStates.OK, ResultTypes.EXECUTED, "")
|
|
m_Timer.Start()
|
|
' creo classe di gestione variabili
|
|
Catch ex As Exception
|
|
m_ResultCallbackDlg(CommandTypes.CONNECT, CommandStates.ERROR_, ResultTypes.EXECUTED, "Errore: impossibile connettersi!")
|
|
Return
|
|
End Try
|
|
End Sub
|
|
|
|
Public Sub Disconnect()
|
|
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()
|
|
m_Tpa.OnDispose()
|
|
End Sub
|
|
|
|
Public Sub SetOPState()
|
|
|
|
End Sub
|
|
|
|
Public Sub Start()
|
|
Dim bOk As Boolean = Tpa.remObject.SetCommand(CInt(ISOCNC.Remoting.Commands.Start))
|
|
m_ResultCallbackDlg(CommandTypes.START, If(bOk, CommandStates.OK, CommandStates.ERROR_), ResultTypes.EXECUTED, "")
|
|
End Sub
|
|
|
|
Public Sub [Stop]()
|
|
Dim bOk As Boolean = Tpa.remObject.SetCommand(CInt(ISOCNC.Remoting.Commands.[Stop]))
|
|
m_ResultCallbackDlg(CommandTypes.STOP_, If(bOk, CommandStates.OK, CommandStates.ERROR_), ResultTypes.EXECUTED, "")
|
|
End Sub
|
|
|
|
Public Sub Reset()
|
|
Dim bOk As Boolean = Tpa.remObject.SetCommand(CInt(ISOCNC.Remoting.Commands.[End]))
|
|
bOk = Tpa.remObject.SetVariableCommand(CInt(ISOCNC.Remoting.VariableCommands.WriteVar), "0.FUNM.E80048", "0")
|
|
m_ResultCallbackDlg(CommandTypes.RESET, If(bOk, CommandStates.OK, CommandStates.ERROR_), ResultTypes.EXECUTED, "")
|
|
End Sub
|
|
|
|
Public Sub SetPoint()
|
|
Dim bOk As Boolean = Tpa.remObject.SetCommand(CInt(ISOCNC.Remoting.Commands.SetPoint))
|
|
m_ResultCallbackDlg(CommandTypes.SETPOINT, If(bOk, CommandStates.OK, CommandStates.ERROR_), ResultTypes.EXECUTED, "")
|
|
End Sub
|
|
|
|
Public Sub SendProgram(ProgramPath As String)
|
|
Dim bOk As Boolean = (Tpa.opState = MachineOperatingState.Pending)
|
|
If bOk Then
|
|
ProgramPath = ProgramPath.Replace("\\", "\")
|
|
bOk = Tpa.remObject.AddProgramToList(ProgramPath)
|
|
bOk = Tpa.remObject.SetCommand(CInt(ISOCNC.Remoting.Commands.Start_Program_Soft))
|
|
End If
|
|
m_ResultCallbackDlg(CommandTypes.SENDPROG, If(bOk, CommandStates.OK, CommandStates.ERROR_), ResultTypes.EXECUTED, "")
|
|
End Sub
|
|
|
|
Public Sub RemoveProgram(ProgramIndex As Integer, ProgramPath As String)
|
|
Dim bOk As Boolean
|
|
Dim sError As String = ""
|
|
If ProgramIndex > 0 Then
|
|
bOk = Tpa.remObject.RemoveProgramFromListAtIndex(ProgramIndex)
|
|
ElseIf Not String.IsNullOrEmpty(ProgramPath) Then
|
|
bOk = Tpa.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)
|
|
End Sub
|
|
|
|
Public Sub RemoveAllProgram()
|
|
Dim bOk As Boolean = Tpa.remObject.RemoveAllProgramsFromList()
|
|
m_ResultCallbackDlg(CommandTypes.REMOVEALLPROG, If(bOk, CommandStates.OK, CommandStates.ERROR_), ResultTypes.EXECUTED, "")
|
|
End Sub
|
|
|
|
Public Sub DeleteAlarms()
|
|
Dim bOk As Boolean = Tpa.remObject.DeleteAlarms(CInt(AlarmType.ISO))
|
|
bOk = Tpa.remObject.DeleteAlarms(CInt(AlarmType.Message))
|
|
bOk = Tpa.remObject.DeleteAlarms(CInt(AlarmType.Cycle))
|
|
bOk = Tpa.remObject.DeleteAlarms(CInt(AlarmType.System))
|
|
m_ResultCallbackDlg(CommandTypes.DELETEALARMS, If(bOk, CommandStates.OK, CommandStates.ERROR_), ResultTypes.EXECUTED, "")
|
|
End Sub
|
|
|
|
End Class
|