296e18704e
- aggiunta funzione PlgExecProcess - aggiunti bottoni di scrittura variabili macchina - aggiunta finestrella statistiche processi
374 lines
18 KiB
VB.net
374 lines
18 KiB
VB.net
Imports System.Collections.ObjectModel
|
|
Imports System.Reflection
|
|
Imports System.Windows.Threading
|
|
Imports Newtonsoft.Json.Linq
|
|
Imports Supervisor.Plugin.FiveLakes.Variable
|
|
|
|
Public Class MachinePageVM
|
|
|
|
Private m_DoorOnMachineList As New ObservableCollection(Of Door)
|
|
Public ReadOnly Property DoorOnMachineList As ObservableCollection(Of Door)
|
|
Get
|
|
Return m_DoorOnMachineList
|
|
End Get
|
|
End Property
|
|
|
|
Private m_VarTimer As New DispatcherTimer
|
|
|
|
Private m_VariableList As ObservableCollection(Of Variable)
|
|
Public ReadOnly Property VariableList As ObservableCollection(Of Variable)
|
|
Get
|
|
Return m_VariableList
|
|
End Get
|
|
End Property
|
|
|
|
' Definizione comandi
|
|
Private m_cmdWriteVariable As ICommand
|
|
Private m_cmdMoveVariable As ICommand
|
|
|
|
Sub New()
|
|
m_VariableList = New ObservableCollection(Of Variable)({New Variable(Variable.VariableTypes.DOUBLE, "@WP_PR_00", "980", 1),
|
|
New Variable(Variable.VariableTypes.DOUBLE, "@WP_PR_01", "981", 1),
|
|
New Variable(Variable.VariableTypes.DOUBLE, "@WP_PR_02", "982", 1),
|
|
New Variable(Variable.VariableTypes.DOUBLE, "@WP_PR_03", "983", 1),
|
|
New Variable(Variable.VariableTypes.DOUBLE, "@WP_PR_04", "984", 1),
|
|
New Variable(Variable.VariableTypes.INTEGER, "@DOORN_S0", "1360", 1),
|
|
New Variable(Variable.VariableTypes.INTEGER, "@DOORN_S1", "1361", 1),
|
|
New Variable(Variable.VariableTypes.INTEGER, "@DOORN_S2", "1362", 1),
|
|
New Variable(Variable.VariableTypes.INTEGER, "@DOORN_S3", "1363", 1),
|
|
New Variable(Variable.VariableTypes.INTEGER, "@DOORN_S4", "1364", 1),
|
|
New Variable(Variable.VariableTypes.INTEGER, "@SENT_1", "1350", 1),
|
|
New Variable(Variable.VariableTypes.INTEGER, "@SENT_2", "1351", 1),
|
|
New Variable(Variable.VariableTypes.INTEGER, "@STATE", "1352", 1),
|
|
New Variable(Variable.VariableTypes.INTEGER, "@RESET_ON", "1365", 1),
|
|
New Variable(Variable.VariableTypes.INTEGER, "@MAST_OK", "1366", 1),
|
|
New Variable(Variable.VariableTypes.INTEGER, "@START_OK", "1367", 1),
|
|
New Variable(Variable.VariableTypes.BOOLEAN, "@BF00", "901.0", 1),
|
|
New Variable(Variable.VariableTypes.BOOLEAN, "@BF01", "901.1", 1),
|
|
New Variable(Variable.VariableTypes.BOOLEAN, "@BF02", "901.2", 1),
|
|
New Variable(Variable.VariableTypes.BOOLEAN, "@BF03", "901.3", 1),
|
|
New Variable(Variable.VariableTypes.BOOLEAN, "@BF04", "901.4", 1),
|
|
New Variable(Variable.VariableTypes.BOOLEAN, "@BF05", "901.5", 1),
|
|
New Variable(Variable.VariableTypes.BOOLEAN, "@BF06", "901.6", 1),
|
|
New Variable(Variable.VariableTypes.BOOLEAN, "@BF07", "901.7", 1),
|
|
New Variable(Variable.VariableTypes.DOUBLE, "@WP_PR_00", "980", 2),
|
|
New Variable(Variable.VariableTypes.DOUBLE, "@WP_PR_01", "981", 2),
|
|
New Variable(Variable.VariableTypes.DOUBLE, "@WP_PR_02", "982", 2),
|
|
New Variable(Variable.VariableTypes.DOUBLE, "@WP_PR_03", "983", 2),
|
|
New Variable(Variable.VariableTypes.DOUBLE, "@WP_PR_04", "984", 2),
|
|
New Variable(Variable.VariableTypes.INTEGER, "@DOORN_S0", "1360", 2),
|
|
New Variable(Variable.VariableTypes.INTEGER, "@DOORN_S1", "1361", 2),
|
|
New Variable(Variable.VariableTypes.INTEGER, "@DOORN_S2", "1362", 2),
|
|
New Variable(Variable.VariableTypes.INTEGER, "@DOORN_S3", "1363", 2),
|
|
New Variable(Variable.VariableTypes.INTEGER, "@DOORN_S4", "1364", 2),
|
|
New Variable(Variable.VariableTypes.INTEGER, "@SENT_1", "1350", 2),
|
|
New Variable(Variable.VariableTypes.INTEGER, "@SENT_2", "1351", 2),
|
|
New Variable(Variable.VariableTypes.INTEGER, "@STATE", "1352", 2),
|
|
New Variable(Variable.VariableTypes.INTEGER, "@RESET_ON", "1365", 2),
|
|
New Variable(Variable.VariableTypes.INTEGER, "@MAST_OK", "1366", 2),
|
|
New Variable(Variable.VariableTypes.INTEGER, "@START_OK", "1367", 2),
|
|
New Variable(Variable.VariableTypes.BOOLEAN, "@BF00", "901.0", 2),
|
|
New Variable(Variable.VariableTypes.BOOLEAN, "@BF01", "901.1", 2),
|
|
New Variable(Variable.VariableTypes.BOOLEAN, "@BF02", "901.2", 2),
|
|
New Variable(Variable.VariableTypes.BOOLEAN, "@BF03", "901.3", 2),
|
|
New Variable(Variable.VariableTypes.BOOLEAN, "@BF04", "901.4", 2),
|
|
New Variable(Variable.VariableTypes.BOOLEAN, "@BF05", "901.5", 2),
|
|
New Variable(Variable.VariableTypes.BOOLEAN, "@BF06", "901.6", 2),
|
|
New Variable(Variable.VariableTypes.BOOLEAN, "@BF07", "901.7", 2)})
|
|
AddHandler m_VarTimer.Tick, AddressOf VarTimer_Tick
|
|
m_VarTimer.Interval = New TimeSpan(100)
|
|
m_VarTimer.Start()
|
|
m_DoorOnMachineList.Add(New Door(35, 1, "Test.ddf", "Produzione2024", 1, 800, 1800, 40, {""}, {""}))
|
|
End Sub
|
|
|
|
Friend Sub VarTimer_Tick()
|
|
For Each Var In m_VariableList
|
|
Select Case Var.Type
|
|
Case Variable.VariableTypes.INTEGER
|
|
Dim nIndex As Integer = 0
|
|
Integer.TryParse(Var.sIndex, nIndex)
|
|
Dim nValue As Integer = 0
|
|
If Map.refSupervisorFunction.ComReadShortVar(nIndex, nValue, Var.nMachine) Then
|
|
Var.SetValue(nValue)
|
|
Else
|
|
Map.refSupervisorFunction.PlgOutLog("Error! Reading Variable " & Var.sIndex & " on machine " & Var.nMachine & "failed!")
|
|
End If
|
|
Case Variable.VariableTypes.DOUBLE
|
|
Dim nIndex As Integer = 0
|
|
Integer.TryParse(Var.sIndex, nIndex)
|
|
Dim dValue As Double = 0
|
|
If Map.refSupervisorFunction.ComReadDoubleVar(nIndex, dValue, Var.nMachine) Then
|
|
Var.SetValue(dValue)
|
|
Else
|
|
Map.refSupervisorFunction.PlgOutLog("Error! Reading Variable " & Var.sIndex & " on machine " & Var.nMachine & "failed!")
|
|
End If
|
|
Case Variable.VariableTypes.BOOLEAN
|
|
Dim nIndex As Integer = 0
|
|
Dim nBit As Integer = 0
|
|
Dim sIndexSplit() As String = Var.sIndex.Split("."c)
|
|
Integer.TryParse(sIndexSplit(0), nIndex)
|
|
Integer.TryParse(sIndexSplit(1), nBit)
|
|
Dim bValue As Boolean = 0
|
|
If Map.refSupervisorFunction.ComReadBitVar(nIndex, nBit, bValue, Var.nMachine) Then
|
|
Var.SetValue(bValue)
|
|
Else
|
|
Map.refSupervisorFunction.PlgOutLog("Error! Reading Variable " & Var.sIndex & " on machine " & Var.nMachine & "failed!")
|
|
End If
|
|
End Select
|
|
Next
|
|
End Sub
|
|
|
|
#Region "COMMANDS"
|
|
|
|
#Region "WriteVariable"
|
|
|
|
Public ReadOnly Property WriteVariable_Command As ICommand
|
|
Get
|
|
If m_cmdWriteVariable Is Nothing Then
|
|
m_cmdWriteVariable = New Command(AddressOf WriteVariable)
|
|
End If
|
|
Return m_cmdWriteVariable
|
|
End Get
|
|
End Property
|
|
|
|
Public Sub WriteVariable(sVariable As String)
|
|
Dim sVariableArgs As String() = sVariable.Split(","c)
|
|
Dim nMachineIndex As Integer = -1
|
|
Integer.TryParse(sVariableArgs(0), nMachineIndex)
|
|
Dim nVariableType As Integer = -1
|
|
Integer.TryParse(sVariableArgs(1), nVariableType)
|
|
Select Case nVariableType
|
|
Case 1
|
|
Dim nVarAddress As Integer = -1
|
|
Integer.TryParse(sVariableArgs(2), nVarAddress)
|
|
Dim nVarValue As Integer = -1
|
|
Integer.TryParse(sVariableArgs(3), nVarValue)
|
|
Map.refSupervisorFunction.ComWriteShortVar(nVarAddress, nVarValue, nMachineIndex)
|
|
Case 2
|
|
Dim nVarAddress As Integer = -1
|
|
Integer.TryParse(sVariableArgs(2), nVarAddress)
|
|
Dim dVarValue As Double = -1
|
|
StringToDouble(sVariableArgs(3), dVarValue)
|
|
Map.refSupervisorFunction.ComWriteDoubleVar(nVarAddress, dVarValue, nMachineIndex)
|
|
Case 3
|
|
Dim sVarAddress As String() = sVariableArgs(2).Split("."c)
|
|
Dim nVarAddress As Integer = -1
|
|
Integer.TryParse(sVarAddress(0), nVarAddress)
|
|
Dim nBit As Integer = -1
|
|
Integer.TryParse(sVarAddress(1), nBit)
|
|
Dim nVarValue As Integer = -1
|
|
Integer.TryParse(sVariableArgs(3), nVarValue)
|
|
Map.refSupervisorFunction.ComWriteBitVar(nVarAddress, nBit, nVarValue <> 0, nMachineIndex)
|
|
End Select
|
|
End Sub
|
|
|
|
#End Region ' WriteVariable
|
|
|
|
#Region "MoveVariable"
|
|
|
|
Public ReadOnly Property MoveVariable_Command As ICommand
|
|
Get
|
|
If m_cmdMoveVariable Is Nothing Then
|
|
m_cmdMoveVariable = New Command(AddressOf MoveVariable)
|
|
End If
|
|
Return m_cmdMoveVariable
|
|
End Get
|
|
End Property
|
|
|
|
Public Sub MoveVariable(sVariableToMove As String)
|
|
Dim sVariableToMoveArgs As String() = sVariableToMove.Split({"->"}, StringSplitOptions.None)
|
|
' leggo variabili di partenza
|
|
Dim sFromVariables As String() = sVariableToMoveArgs(0).Split(";"c)
|
|
Dim sFromVariableArgs As String() = sFromVariables(0).Split(","c)
|
|
Dim nFromMachineIndex As Integer = -1
|
|
Integer.TryParse(sFromVariableArgs(0), nFromMachineIndex)
|
|
Dim nFromVariableType As Integer = -1
|
|
Integer.TryParse(sFromVariableArgs(1), nFromVariableType)
|
|
Dim nVarValue As Integer = -1
|
|
Dim dVarValue As Double = -1
|
|
Dim bVarValue As Boolean = False
|
|
Select Case nFromVariableType
|
|
Case 1
|
|
Dim nVarAddress As Integer = -1
|
|
Integer.TryParse(sFromVariableArgs(2), nVarAddress)
|
|
Map.refSupervisorFunction.ComReadShortVar(nVarAddress, nVarValue, nFromMachineIndex)
|
|
Case 2
|
|
Dim nVarAddress As Integer = -1
|
|
Integer.TryParse(sFromVariableArgs(2), nVarAddress)
|
|
Map.refSupervisorFunction.ComReadDoubleVar(nVarAddress, dVarValue, nFromMachineIndex)
|
|
Case 3
|
|
Dim sVarAddress As String() = sFromVariableArgs(2).Split("."c)
|
|
Dim nVarAddress As Integer = -1
|
|
Integer.TryParse(sVarAddress(0), nVarAddress)
|
|
Dim nBit As Integer = -1
|
|
Integer.TryParse(sVarAddress(1), nBit)
|
|
Map.refSupervisorFunction.ComReadBitVar(nVarAddress, nBit, bVarValue, nFromMachineIndex)
|
|
End Select
|
|
' scrivo valore in variabili di arivo
|
|
Dim sToVariables As String() = sVariableToMoveArgs(1).Split(";"c)
|
|
For nToVariableIndex As Integer = 0 To sToVariables.Count - 1
|
|
Dim sToVariableArgs As String() = sToVariables(nToVariableIndex).Split(","c)
|
|
Dim nToMachineIndex As Integer = -1
|
|
Integer.TryParse(sToVariableArgs(0), nToMachineIndex)
|
|
Dim nToVariableType As Integer = -1
|
|
Integer.TryParse(sToVariableArgs(1), nToVariableType)
|
|
Select Case nToVariableType
|
|
Case 1
|
|
Dim nVarAddress As Integer = -1
|
|
Integer.TryParse(sToVariableArgs(2), nVarAddress)
|
|
Map.refSupervisorFunction.ComWriteShortVar(nVarAddress, nVarValue, nToMachineIndex)
|
|
Case 2
|
|
Dim nVarAddress As Integer = -1
|
|
Integer.TryParse(sToVariableArgs(2), nVarAddress)
|
|
Map.refSupervisorFunction.ComWriteDoubleVar(nVarAddress, dVarValue, nToMachineIndex)
|
|
Case 3
|
|
Dim sVarAddress As String() = sToVariableArgs(2).Split("."c)
|
|
Dim nVarAddress As Integer = -1
|
|
Integer.TryParse(sVarAddress(0), nVarAddress)
|
|
Dim nBit As Integer = -1
|
|
Integer.TryParse(sVarAddress(1), nBit)
|
|
Map.refSupervisorFunction.ComWriteBitVar(nVarAddress, nBit, nVarValue <> 0, nToMachineIndex)
|
|
End Select
|
|
Next
|
|
' cancello valore da variabili di partenza
|
|
Select Case nFromVariableType
|
|
Case 1
|
|
Dim nVarAddress As Integer = -1
|
|
Integer.TryParse(sFromVariableArgs(2), nVarAddress)
|
|
Map.refSupervisorFunction.ComWriteShortVar(nVarAddress, 0, nFromMachineIndex)
|
|
Case 2
|
|
Dim nVarAddress As Integer = -1
|
|
Integer.TryParse(sFromVariableArgs(2), nVarAddress)
|
|
Map.refSupervisorFunction.ComWriteDoubleVar(nVarAddress, 0, nFromMachineIndex)
|
|
Case 3
|
|
Dim sVarAddress As String() = sFromVariableArgs(2).Split("."c)
|
|
Dim nVarAddress As Integer = -1
|
|
Integer.TryParse(sVarAddress(0), nVarAddress)
|
|
Dim nBit As Integer = -1
|
|
Integer.TryParse(sVarAddress(1), nBit)
|
|
Map.refSupervisorFunction.ComWriteBitVar(nVarAddress, nBit, False, nFromMachineIndex)
|
|
End Select
|
|
For nFromVariableIndex As Integer = 1 To sFromVariables.Count - 1
|
|
sFromVariableArgs = sFromVariables(nFromVariableIndex).Split(","c)
|
|
Integer.TryParse(sFromVariableArgs(0), nFromMachineIndex)
|
|
Integer.TryParse(sFromVariableArgs(1), nFromVariableType)
|
|
Select Case nFromVariableType
|
|
Case 1
|
|
Dim nVarAddress As Integer = -1
|
|
Integer.TryParse(sFromVariableArgs(2), nVarAddress)
|
|
Map.refSupervisorFunction.ComWriteShortVar(nVarAddress, 0, nFromMachineIndex)
|
|
Case 2
|
|
Dim nVarAddress As Integer = -1
|
|
Integer.TryParse(sFromVariableArgs(2), nVarAddress)
|
|
Map.refSupervisorFunction.ComWriteDoubleVar(nVarAddress, 0, nFromMachineIndex)
|
|
Case 3
|
|
Dim sVarAddress As String() = sFromVariableArgs(2).Split("."c)
|
|
Dim nVarAddress As Integer = -1
|
|
Integer.TryParse(sVarAddress(0), nVarAddress)
|
|
Dim nBit As Integer = -1
|
|
Integer.TryParse(sVarAddress(1), nBit)
|
|
Map.refSupervisorFunction.ComWriteBitVar(nVarAddress, nBit, False, nFromMachineIndex)
|
|
End Select
|
|
Next
|
|
End Sub
|
|
|
|
#End Region ' MoveVariable
|
|
|
|
#End Region ' COMMANDS
|
|
|
|
End Class
|
|
|
|
Public Class Variable
|
|
Inherits VMBase
|
|
|
|
Public Enum VariableTypes As Integer
|
|
[INTEGER] = 1
|
|
[DOUBLE] = 2
|
|
[BOOLEAN] = 3
|
|
End Enum
|
|
|
|
Private m_Type As VariableTypes
|
|
Public ReadOnly Property Type As Integer
|
|
Get
|
|
Return m_Type
|
|
End Get
|
|
End Property
|
|
|
|
Private m_sName As String
|
|
Public ReadOnly Property sName As String
|
|
Get
|
|
Return m_sName
|
|
End Get
|
|
End Property
|
|
|
|
Private m_sIndex As String
|
|
Public ReadOnly Property sIndex As String
|
|
Get
|
|
Return m_sIndex
|
|
End Get
|
|
End Property
|
|
|
|
Private m_nMachine As Integer
|
|
Public ReadOnly Property nMachine As Integer
|
|
Get
|
|
Return m_nMachine
|
|
End Get
|
|
End Property
|
|
|
|
Private m_nValue As Integer
|
|
Private m_dValue As Double
|
|
Private m_bValue As Boolean
|
|
Public Property sValue As String
|
|
Get
|
|
Select Case Type
|
|
Case VariableTypes.INTEGER
|
|
Return m_nValue.ToString()
|
|
Case VariableTypes.DOUBLE
|
|
Return DoubleToString(m_dValue, 2)
|
|
Case VariableTypes.BOOLEAN
|
|
Return If(m_bValue, 1, 0)
|
|
End Select
|
|
End Get
|
|
Set(value As String)
|
|
Select Case Type
|
|
Case VariableTypes.INTEGER
|
|
If Not Integer.TryParse(value, m_nValue) Then
|
|
NotifyPropertyChanged(NameOf(sValue))
|
|
End If
|
|
Case VariableTypes.DOUBLE
|
|
If Not StringToDouble(value, m_dValue) Then
|
|
NotifyPropertyChanged(NameOf(sValue))
|
|
End If
|
|
Case VariableTypes.BOOLEAN
|
|
Dim nBoolean As Integer = 0
|
|
If Integer.TryParse(value, nBoolean) Then
|
|
m_bValue = If(nBoolean > 0, 1, 0)
|
|
Else
|
|
NotifyPropertyChanged(NameOf(sValue))
|
|
End If
|
|
End Select
|
|
m_nValue = value
|
|
End Set
|
|
End Property
|
|
Friend Sub SetValue(value As Integer)
|
|
m_nValue = value
|
|
NotifyPropertyChanged(NameOf(sValue))
|
|
End Sub
|
|
Friend Sub SetValue(value As Double)
|
|
m_dValue = value
|
|
NotifyPropertyChanged(NameOf(sValue))
|
|
End Sub
|
|
Friend Sub SetValue(value As Boolean)
|
|
m_bValue = value
|
|
NotifyPropertyChanged(NameOf(sValue))
|
|
End Sub
|
|
|
|
Sub New(Type As VariableTypes, sName As String, sIndex As String, nMachine As Integer)
|
|
m_Type = Type
|
|
m_sName = sName
|
|
m_sIndex = sIndex
|
|
m_nMachine = nMachine
|
|
End Sub
|
|
|
|
End Class
|