6e4645875b
- Tpa funzionante
393 lines
12 KiB
VB.net
393 lines
12 KiB
VB.net
Imports System
|
|
Imports System.Collections.Generic
|
|
Imports System.Linq
|
|
Imports System.Text
|
|
Imports System.Threading.Tasks
|
|
Imports System.Windows.Input
|
|
Imports System.Collections.ObjectModel
|
|
Imports System.Windows.Media
|
|
Imports System.Windows
|
|
Imports ISOCNC.Remoting
|
|
Imports Zebra.Sdk.Comm
|
|
Imports Zebra.Sdk.Device
|
|
Imports Zebra.Sdk.Printer
|
|
|
|
Namespace EgtCNCPLCComm
|
|
Class MainWindowVM
|
|
Inherits VMBase
|
|
|
|
Private _Connected As Boolean = False
|
|
|
|
Public ReadOnly Property Connected As Boolean
|
|
Get
|
|
Return _Connected
|
|
End Get
|
|
End Property
|
|
|
|
Public ReadOnly Property Connect_Background As SolidColorBrush
|
|
Get
|
|
Return (If(_Connected, Brushes.Green, Brushes.Red))
|
|
End Get
|
|
End Property
|
|
|
|
Private _Tpa As TPAComm = Nothing
|
|
|
|
Public ReadOnly Property Tpa As TPAComm
|
|
Get
|
|
Return _Tpa
|
|
End Get
|
|
End Property
|
|
|
|
Private _ProgramPath As String
|
|
|
|
Public ReadOnly Property ProgramPath As String
|
|
Get
|
|
Return _ProgramPath
|
|
End Get
|
|
End Property
|
|
|
|
Private _ProgramIndex As Integer = 0
|
|
|
|
Public Property ProgramIndex As Integer
|
|
Get
|
|
Return _ProgramIndex
|
|
End Get
|
|
Set(ByVal value As Integer)
|
|
_ProgramIndex = value
|
|
End Set
|
|
End Property
|
|
|
|
Private _VarName As String
|
|
|
|
Public Property VarName As String
|
|
Get
|
|
Return _VarName
|
|
End Get
|
|
Set(ByVal value As String)
|
|
_VarName = value
|
|
End Set
|
|
End Property
|
|
|
|
Private _VarValue As String = ""
|
|
|
|
Public Property VarValue As String
|
|
Get
|
|
Return _VarValue
|
|
End Get
|
|
Set(ByVal value As String)
|
|
_VarValue = value
|
|
End Set
|
|
End Property
|
|
|
|
Public Sub SetVarValue(ByVal value As Object)
|
|
_VarValue = CStr(value)
|
|
NotifyPropertyChanged(NameOf(VarValue))
|
|
End Sub
|
|
|
|
Private _AxisList As ObservableCollection(Of Axis)
|
|
|
|
Public ReadOnly Property AxisList As ObservableCollection(Of Axis)
|
|
Get
|
|
Return _AxisList
|
|
End Get
|
|
End Property
|
|
|
|
Private _OPStateList As List(Of ISOCNC.Remoting.MachineOperatingState)
|
|
|
|
Public Property OPStateList As List(Of ISOCNC.Remoting.MachineOperatingState)
|
|
Get
|
|
Return _OPStateList
|
|
End Get
|
|
Set(ByVal value As List(Of ISOCNC.Remoting.MachineOperatingState))
|
|
_OPStateList = value
|
|
End Set
|
|
End Property
|
|
|
|
Private _SelOPState As ISOCNC.Remoting.MachineOperatingState
|
|
|
|
Public Property SelOPState As ISOCNC.Remoting.MachineOperatingState
|
|
Get
|
|
Return _SelOPState
|
|
End Get
|
|
Set(ByVal value As ISOCNC.Remoting.MachineOperatingState)
|
|
_SelOPState = value
|
|
End Set
|
|
End Property
|
|
|
|
Private _ErrCycle As String
|
|
|
|
Public ReadOnly Property ErrCycle As String
|
|
Get
|
|
Return _ErrCycle
|
|
End Get
|
|
End Property
|
|
|
|
Public Sub UpdateErrCycle(ByVal msg As String)
|
|
_ErrCycle = msg
|
|
NotifyPropertyChanged(NameOf(ErrCycle))
|
|
End Sub
|
|
|
|
Private _Iso As String
|
|
|
|
Public ReadOnly Property Iso As String
|
|
Get
|
|
Return _Iso
|
|
End Get
|
|
End Property
|
|
|
|
Public Sub UpdateIso(ByVal msg As String)
|
|
_Iso = msg
|
|
NotifyPropertyChanged(NameOf(Iso))
|
|
End Sub
|
|
|
|
Private _Message As String
|
|
|
|
Public ReadOnly Property Message As String
|
|
Get
|
|
Return _Message
|
|
End Get
|
|
End Property
|
|
|
|
Public Sub UpdateMessage(ByVal msg As String)
|
|
_Message = msg
|
|
NotifyPropertyChanged(NameOf(Message))
|
|
End Sub
|
|
|
|
Private _ErrSystem As String
|
|
|
|
Public ReadOnly Property ErrSystem As String
|
|
Get
|
|
Return _ErrSystem
|
|
End Get
|
|
End Property
|
|
|
|
Public Sub UpdateErrSystem(ByVal msg As String)
|
|
_ErrSystem = msg
|
|
NotifyPropertyChanged(NameOf(ErrSystem))
|
|
End Sub
|
|
|
|
Private m_cmdConnect As ICommand
|
|
Private m_cmdDisconnect As ICommand
|
|
Private m_cmdStart As ICommand
|
|
Private m_cmdStop As ICommand
|
|
Private m_cmdStep As ICommand
|
|
Private m_cmdSearchFilePath As ICommand
|
|
Private m_cmdAddProgram As ICommand
|
|
Private m_cmdRemoveProgram As ICommand
|
|
Private m_cmdReadVar As ICommand
|
|
Private m_cmdWriteVar As ICommand
|
|
Private m_cmdDeleteAlarms As ICommand
|
|
Private m_cmdSetPoint As ICommand
|
|
Private m_cmdPrintLabel As ICommand
|
|
|
|
Public Sub New()
|
|
_AxisList = New ObservableCollection(Of Axis) From {
|
|
New Axis("X"),
|
|
New Axis("Y"),
|
|
New Axis("Z"),
|
|
New Axis("C"),
|
|
New Axis("B")
|
|
}
|
|
_OPStateList = New List(Of MachineOperatingState) From {
|
|
MachineOperatingState.Start,
|
|
MachineOperatingState.[Stop],
|
|
MachineOperatingState.[End],
|
|
MachineOperatingState.SetPoint,
|
|
MachineOperatingState.Pending,
|
|
MachineOperatingState.Unspecified
|
|
}
|
|
NotifyPropertyChanged(NameOf(Connect_Background))
|
|
End Sub
|
|
|
|
Public ReadOnly Property Connect_Command As ICommand
|
|
Get
|
|
If m_cmdConnect Is Nothing Then m_cmdConnect = New Command(AddressOf Connect)
|
|
Return m_cmdConnect
|
|
End Get
|
|
End Property
|
|
|
|
Public Sub Connect(ByVal param As Object)
|
|
_Tpa = New TPAComm(Me)
|
|
_Connected = Tpa.remObject.OnConnect()
|
|
NotifyPropertyChanged(NameOf(Connect_Background))
|
|
If _Connected Then Init()
|
|
End Sub
|
|
|
|
Private Sub Init()
|
|
_SelOPState = CType(Tpa.remObject.MachineOperativeStatus, MachineOperatingState)
|
|
NotifyPropertyChanged(NameOf(SelOPState))
|
|
Dim sAxesValue As String = ""
|
|
Dim dAxesValue As Double = 0
|
|
Dim sAxesName As String = "0.TESTA.AsseX.X"
|
|
Tpa.remObject.SetVariableCommand(CInt(ISOCNC.Remoting.VariableCommands.ReadVar), sAxesName, sAxesValue)
|
|
Double.TryParse(sAxesValue, dAxesValue)
|
|
_AxisList(0).Value = dAxesValue
|
|
sAxesName = "0.TESTA.AsseY.Y"
|
|
Tpa.remObject.SetVariableCommand(CInt(ISOCNC.Remoting.VariableCommands.ReadVar), sAxesName, sAxesValue)
|
|
Double.TryParse(sAxesValue, dAxesValue)
|
|
_AxisList(1).Value = dAxesValue
|
|
sAxesName = "0.TESTA.AsseZ.Z"
|
|
Tpa.remObject.SetVariableCommand(CInt(ISOCNC.Remoting.VariableCommands.ReadVar), sAxesName, sAxesValue)
|
|
Double.TryParse(sAxesValue, dAxesValue)
|
|
_AxisList(2).Value = dAxesValue
|
|
sAxesName = "0.TESTA.AsseC.C"
|
|
Tpa.remObject.SetVariableCommand(CInt(ISOCNC.Remoting.VariableCommands.ReadVar), sAxesName, sAxesValue)
|
|
Double.TryParse(sAxesValue, dAxesValue)
|
|
_AxisList(3).Value = dAxesValue
|
|
sAxesName = "0.TESTA.AsseB.B"
|
|
Tpa.remObject.SetVariableCommand(CInt(ISOCNC.Remoting.VariableCommands.ReadVar), sAxesName, sAxesValue)
|
|
Double.TryParse(sAxesValue, dAxesValue)
|
|
_AxisList(4).Value = dAxesValue
|
|
End Sub
|
|
|
|
Public ReadOnly Property Disconnect_Command As ICommand
|
|
Get
|
|
If m_cmdDisconnect Is Nothing Then m_cmdDisconnect = New Command(AddressOf Disconnect)
|
|
Return m_cmdDisconnect
|
|
End Get
|
|
End Property
|
|
|
|
Public Sub Disconnect(ByVal param As Object)
|
|
_Connected = Not Tpa.remObject.OnClose()
|
|
NotifyPropertyChanged(NameOf(Connect_Background))
|
|
End Sub
|
|
|
|
Public ReadOnly Property Start_Command As ICommand
|
|
Get
|
|
If m_cmdStart Is Nothing Then m_cmdStart = New Command(AddressOf Start)
|
|
Return m_cmdStart
|
|
End Get
|
|
End Property
|
|
|
|
Public Sub Start(ByVal param As Object)
|
|
Tpa.remObject.SetCommand(CInt(ISOCNC.Remoting.Commands.Start))
|
|
Tpa.remObject.SetVariableCommand(CInt(ISOCNC.Remoting.VariableCommands.WriteVar), "0.FUNM.E80048", "0")
|
|
End Sub
|
|
|
|
Public ReadOnly Property Stop_Command As ICommand
|
|
Get
|
|
If m_cmdStop Is Nothing Then m_cmdStop = New Command(AddressOf [Stop])
|
|
Return m_cmdStop
|
|
End Get
|
|
End Property
|
|
|
|
Public Sub [Stop](ByVal param As Object)
|
|
Tpa.remObject.SetCommand(CInt(ISOCNC.Remoting.Commands.[Stop]))
|
|
End Sub
|
|
|
|
Public ReadOnly Property Step_Command As ICommand
|
|
Get
|
|
If m_cmdStep Is Nothing Then m_cmdStep = New Command(AddressOf [Step])
|
|
Return m_cmdStep
|
|
End Get
|
|
End Property
|
|
|
|
Public Sub [Step](ByVal param As Object)
|
|
Tpa.remObject.SetCommand(CInt(ISOCNC.Remoting.Commands.[End]))
|
|
Tpa.remObject.RemoveAllProgramsFromList()
|
|
End Sub
|
|
|
|
Public ReadOnly Property SetPoint_Command As ICommand
|
|
Get
|
|
If m_cmdSetPoint Is Nothing Then m_cmdSetPoint = New Command(AddressOf SetPoint)
|
|
Return m_cmdSetPoint
|
|
End Get
|
|
End Property
|
|
|
|
Public Sub SetPoint(ByVal param As Object)
|
|
Tpa.remObject.SetCommand(CInt(ISOCNC.Remoting.Commands.SetPoint))
|
|
End Sub
|
|
|
|
Public ReadOnly Property PrintLabel_Command As ICommand
|
|
Get
|
|
If m_cmdPrintLabel Is Nothing Then m_cmdPrintLabel = New Command(AddressOf PrintLabel)
|
|
Return m_cmdPrintLabel
|
|
End Get
|
|
End Property
|
|
|
|
Public Sub PrintLabel(ByVal param As Object)
|
|
Dim Test As EgtCNCPLCComm.ZebraPrinter.ZebraPrinter = New EgtCNCPLCComm.ZebraPrinter.ZebraPrinter()
|
|
Test.Print()
|
|
End Sub
|
|
|
|
Public ReadOnly Property SearchFilePath_Command As ICommand
|
|
Get
|
|
If m_cmdSearchFilePath Is Nothing Then m_cmdSearchFilePath = New Command(AddressOf SearchFilePath)
|
|
Return m_cmdSearchFilePath
|
|
End Get
|
|
End Property
|
|
|
|
Public Sub SearchFilePath(ByVal param As Object)
|
|
Dim OpenFileDialog As Microsoft.Win32.OpenFileDialog = New Microsoft.Win32.OpenFileDialog()
|
|
If OpenFileDialog.ShowDialog() = True Then _ProgramPath = OpenFileDialog.FileName
|
|
NotifyPropertyChanged(NameOf(ProgramPath))
|
|
End Sub
|
|
|
|
Public ReadOnly Property AddProgram_Command As ICommand
|
|
Get
|
|
If m_cmdAddProgram Is Nothing Then m_cmdAddProgram = New Command(AddressOf AddProgram)
|
|
Return m_cmdAddProgram
|
|
End Get
|
|
End Property
|
|
|
|
Public Sub AddProgram(ByVal param As Object)
|
|
If SelOPState = MachineOperatingState.Pending Then
|
|
Dim Path As String = _ProgramPath.Replace("\\", "\")
|
|
Dim x As Boolean = Tpa.remObject.AddProgramToList(Path)
|
|
Tpa.remObject.SetCommand(CInt(ISOCNC.Remoting.Commands.Start_Program_Soft))
|
|
End If
|
|
End Sub
|
|
|
|
Public ReadOnly Property RemoveProgram_Command As ICommand
|
|
Get
|
|
If m_cmdRemoveProgram Is Nothing Then m_cmdRemoveProgram = New Command(AddressOf RemoveProgram)
|
|
Return m_cmdRemoveProgram
|
|
End Get
|
|
End Property
|
|
|
|
Public Sub RemoveProgram(ByVal param As Object)
|
|
If (Keyboard.Modifiers And ModifierKeys.Shift) = ModifierKeys.Shift Then
|
|
Tpa.remObject.RemoveAllProgramsFromList()
|
|
ElseIf _ProgramIndex < 0 Then
|
|
Tpa.remObject.RemoveProgramFromList(_ProgramPath)
|
|
Else
|
|
Tpa.remObject.RemoveProgramFromListAtIndex(_ProgramIndex)
|
|
End If
|
|
End Sub
|
|
|
|
Public ReadOnly Property ReadVar_Command As ICommand
|
|
Get
|
|
If m_cmdReadVar Is Nothing Then m_cmdReadVar = New Command(AddressOf ReadVar)
|
|
Return m_cmdReadVar
|
|
End Get
|
|
End Property
|
|
|
|
Public Sub ReadVar(ByVal param As Object)
|
|
Tpa.remObject.SetVariableCommand(CInt(ISOCNC.Remoting.VariableCommands.ReadVar), _VarName, _VarValue)
|
|
End Sub
|
|
|
|
Public ReadOnly Property WriteVar_Command As ICommand
|
|
Get
|
|
If m_cmdWriteVar Is Nothing Then m_cmdWriteVar = New Command(AddressOf WriteVar)
|
|
Return m_cmdWriteVar
|
|
End Get
|
|
End Property
|
|
|
|
Public Sub WriteVar(ByVal param As Object)
|
|
Tpa.remObject.SetVariableCommand(CInt(ISOCNC.Remoting.VariableCommands.WriteVar), _VarName, _VarValue)
|
|
End Sub
|
|
|
|
Public ReadOnly Property DeleteAlarms_Command As ICommand
|
|
Get
|
|
If m_cmdDeleteAlarms Is Nothing Then m_cmdDeleteAlarms = New Command(AddressOf DeleteAlarms)
|
|
Return m_cmdDeleteAlarms
|
|
End Get
|
|
End Property
|
|
|
|
Public Sub DeleteAlarms(ByVal param As Object)
|
|
Tpa.remObject.DeleteAlarms(CInt(ISOCNC.Remoting.AlarmType.ISO))
|
|
End Sub
|
|
End Class
|
|
|
|
End Namespace
|