- funzione che restituisce prossima porta aggiorna lo stato

- aggiunta funzione PlgExecProcess
- aggiunti bottoni di scrittura variabili macchina
- aggiunta finestrella statistiche processi
This commit is contained in:
Emmanuele Sassi
2024-08-23 19:04:41 +02:00
parent 6ed36ac02c
commit 296e18704e
9 changed files with 689 additions and 138 deletions
@@ -144,7 +144,11 @@ Public Class DoorListPageVM
End Sub
Friend Function GetNextDoor() As Door
Return m_DoorList.FirstOrDefault(Function(x) x.nState >= Door.DoorStates.SENT_TO_PRODUCTION AndAlso x.nState <= Door.DoorStates.IN_PRODUCTION)
Dim NextDoor As Door = m_DoorList.FirstOrDefault(Function(x) x.nState = Door.DoorStates.READY_FOR_PRODUCTION)
If Not IsNothing(NextDoor) Then
NextDoor.SetState(Door.DoorStates.SENT_TO_PRODUCTION)
End If
Return NextDoor
End Function
#End Region ' METHODS
@@ -261,7 +265,7 @@ Public Class DoorListPageVM
Dim sCamExePath As String = ""
GetPluginPrivateProfileString(S_GENERAL, "CAMExePath", "", sCamExePath)
Dim sMainLuaPath As String = ""
GetPluginPrivateProfileString(S_GENERAL, "MainLUA", "", sMainLuaPath)
GetPluginPrivateProfileString(S_GENERAL, "MainPipeLUA", "", sMainLuaPath)
Dim bStartExecProcessManager As Boolean = False
If IsNothing(m_ExecProcessManager) Then
bStartExecProcessManager = True
@@ -350,7 +354,7 @@ Public Class DoorListPageVM
If IsNothing(SelDoor) Then Return
Dim nOldIndex As Integer = m_DoorList.IndexOf(SelDoor)
If nOldIndex = 0 Then Return
If m_DoorList(nOldIndex - 1).nState >= Door.DoorStates.SENT_TO_PRODUCTION Then Return
If m_DoorList(nOldIndex - 1).nState >= Door.DoorStates.READY_FOR_PRODUCTION Then Return
m_DoorList.Move(nOldIndex, nOldIndex - 1)
WriteBackup()
End Sub
@@ -369,7 +373,7 @@ Public Class DoorListPageVM
End Property
Public Sub MoveDown()
If IsNothing(SelDoor) OrElse SelDoor.nState >= Door.DoorStates.SENT_TO_PRODUCTION Then Return
If IsNothing(SelDoor) OrElse SelDoor.nState >= Door.DoorStates.READY_FOR_PRODUCTION Then Return
Dim nOldIndex As Integer = m_DoorList.IndexOf(SelDoor)
If nOldIndex = m_DoorList.Count - 1 Then Return
m_DoorList.Move(nOldIndex, nOldIndex + 1)
@@ -390,7 +394,7 @@ Public Class DoorListPageVM
End Property
Public Sub Delete()
If IsNothing(SelDoor) OrElse SelDoor.nState >= Door.DoorStates.SENT_TO_PRODUCTION Then Return
If IsNothing(SelDoor) OrElse SelDoor.nState >= Door.DoorStates.READY_FOR_PRODUCTION Then Return
If MessageBox.Show("Are you sure you want to delete the selected door?", "Info", MessageBoxButton.YesNo, MessageBoxImage.Information) = MessageBoxResult.Yes Then
m_DoorList.Remove(SelDoor)
WriteBackup()
@@ -415,7 +419,7 @@ Public Class DoorListPageVM
If MessageBox.Show("Are you sure you want to delete all the doors?", "Info", MessageBoxButton.YesNo, MessageBoxImage.Information) = MessageBoxResult.Yes Then
For nDoorIndex = m_DoorList.Count - 1 To 0 Step -1
Dim Door As Door = m_DoorList(nDoorIndex)
If Door.nState >= Door.DoorStates.SENT_TO_PRODUCTION Then Continue For
If Door.nState >= Door.DoorStates.READY_FOR_PRODUCTION Then Continue For
m_DoorList.Remove(Door)
Next
WriteBackup()
@@ -438,13 +442,13 @@ Public Class DoorListPageVM
Public Sub Produce()
If IsNothing(SelDoor) OrElse SelDoor.nState = Door.DoorStates.SKIPPED OrElse
SelDoor.nState = Door.DoorStates.VERIFICATION_FAILED OrElse
SelDoor.nState >= Door.DoorStates.SENT_TO_PRODUCTION Then Return
SelDoor.nState >= Door.DoorStates.READY_FOR_PRODUCTION Then Return
' la sposto dopo l'ultima da produrre
Dim nNewIndex As Integer = m_DoorList.IndexOf(m_DoorList.FirstOrDefault(Function(x) x.nState < Door.DoorStates.SENT_TO_PRODUCTION))
Dim nNewIndex As Integer = m_DoorList.IndexOf(m_DoorList.FirstOrDefault(Function(x) x.nState < Door.DoorStates.READY_FOR_PRODUCTION))
Dim nOldIndex As Integer = m_DoorList.IndexOf(SelDoor)
Dim SelectedDoor As Door = m_SelDoor
m_DoorList.Move(nOldIndex, nNewIndex)
SelectedDoor.SetState(Door.DoorStates.SENT_TO_PRODUCTION)
SelectedDoor.SetState(Door.DoorStates.READY_FOR_PRODUCTION)
WriteBackup()
End Sub
@@ -480,7 +484,7 @@ Public Class DoorListPageVM
End Property
Public Sub Refresh()
m_SelDoor.SetState(Door.DoorStates.SENT_TO_PRODUCTION)
m_SelDoor.SetState(Door.DoorStates.READY_FOR_PRODUCTION)
'RefreshGraphicsTimer_Tick(Nothing, Nothing)
End Sub
@@ -500,8 +504,9 @@ Public Class Door
VERIFIED = 10
VERIFICATION_FAILED = 11
SKIPPED = 20
SENT_TO_PRODUCTION = 30
IN_PRODUCTION = 31
READY_FOR_PRODUCTION = 30
SENT_TO_PRODUCTION = 31
IN_PRODUCTION = 32
PRODUCED = 32
SCRAP = 40
End Enum
@@ -3,6 +3,20 @@ Imports KeraLua
Public Module Lua_General
Friend func_PlgGetNextDoor As LuaFunction = AddressOf Lua_PlgGetNextDoor
Friend func_PlgExecProcess As LuaFunction = AddressOf Lua_PlgExecProcess
Private Function Lua_PlgExecProcess(ByVal p As IntPtr) As Integer
Dim state = Lua.FromIntPtr(p)
Dim sDDFName As String = ""
LuaCheckParam(state, 1, sDDFName)
LuaClearStack(state)
If Map.refDoorListPageVM.ExecCAMProcess(sDDFName) Then
state.PushBoolean(True)
Return 1
Else
Return 0
End If
End Function
Private Function Lua_PlgGetNextDoor(ByVal p As IntPtr) As Integer
Dim state = Lua.FromIntPtr(p)
@@ -20,6 +34,7 @@ Public Module Lua_General
Friend Function LuaInstallGeneral(state As Lua) As Boolean
If IsNothing(state) Then Return False
state.Register("PlgGetNextDoor", func_PlgGetNextDoor)
state.Register("PlgExecProcess", func_PlgExecProcess)
Return True
End Function
@@ -1,9 +1,11 @@
<Grid x:Class="MachinePageV"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:Supervisor.Plugin.FiveLakes">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="1*"/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<!--<Grid.RowDefinitions>
<RowDefinition Height="1*"/>
@@ -39,87 +41,236 @@
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
<!--<Grid Grid.Column="1">
<Grid.Resources>
<Style x:Key="Table" TargetType="Border">
<Setter Property="BorderBrush" Value="Gray"/>
<Setter Property="BorderThickness" Value="5"/>
<Setter Property="Background" Value="LightGray"/>
</Style>
<Style x:Key="Door" TargetType="Border">
<Setter Property="BorderBrush" Value="SaddleBrown"/>
<Setter Property="BorderThickness" Value="5"/>
<Setter Property="Background" Value="SandyBrown"/>
<Setter Property="Height" Value="40"/>
<Setter Property="Width" Value="80"/>
</Style>
</Grid.Resources>
<Grid Grid.Column="1">
<Grid.RowDefinitions>
<RowDefinition Height="2*"/>
<RowDefinition Height="1*"/>
<RowDefinition Height="2*"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<Grid Grid.Row="1">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="1*"/>
<ColumnDefinition Width="0.5*"/>
<ColumnDefinition Width="1*"/>
<ColumnDefinition Width="0.5*"/>
<ColumnDefinition Width="1*"/>
<ColumnDefinition Width="0.5*"/>
<ColumnDefinition Width="1*"/>
<ColumnDefinition Width="0.5*"/>
<ColumnDefinition Width="1*"/>
</Grid.ColumnDefinitions>
<Border Style="{StaticResource Table}"/>
<Border Grid.Column="1"
Style="{StaticResource Table}"/>
<Border Grid.Column="2"
Style="{StaticResource Table}"/>
<Border Grid.Column="3"
Style="{StaticResource Table}"/>
<Border Grid.Column="4"
Style="{StaticResource Table}"/>
<Border Grid.Column="5"
Style="{StaticResource Table}"/>
<Border Grid.Column="6"
Style="{StaticResource Table}"/>
<Border Grid.Column="7"
Style="{StaticResource Table}"/>
<Border Grid.Column="8"
Style="{StaticResource Table}"/>
<Border Grid.Column="9"
Style="{StaticResource Table}"/>
<Grid>
<Grid.Resources>
<Style x:Key="Table" TargetType="Border">
<Setter Property="BorderBrush" Value="Gray"/>
<Setter Property="BorderThickness" Value="5"/>
<Setter Property="Background" Value="LightGray"/>
</Style>
<Style x:Key="Door" TargetType="Border">
<Setter Property="BorderBrush" Value="SaddleBrown"/>
<Setter Property="BorderThickness" Value="5"/>
<Setter Property="Background" Value="SandyBrown"/>
<Setter Property="Height" Value="40"/>
<Setter Property="Width" Value="80"/>
</Style>
</Grid.Resources>
<Grid.RowDefinitions>
<RowDefinition Height="2*"/>
<RowDefinition Height="1*"/>
<RowDefinition Height="2*"/>
</Grid.RowDefinitions>
<Grid Grid.Row="1">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="1*"/>
<ColumnDefinition Width="0.5*"/>
<ColumnDefinition Width="1*"/>
<ColumnDefinition Width="0.5*"/>
<ColumnDefinition Width="1*"/>
<ColumnDefinition Width="0.5*"/>
<ColumnDefinition Width="1*"/>
<ColumnDefinition Width="0.5*"/>
<ColumnDefinition Width="1*"/>
</Grid.ColumnDefinitions>
<Border Style="{StaticResource Table}"/>
<Border Grid.Column="1"
Style="{StaticResource Table}"/>
<Border Grid.Column="2"
Style="{StaticResource Table}"/>
<Border Grid.Column="3"
Style="{StaticResource Table}"/>
<Border Grid.Column="4"
Style="{StaticResource Table}"/>
<Border Grid.Column="5"
Style="{StaticResource Table}"/>
<Border Grid.Column="6"
Style="{StaticResource Table}"/>
<Border Grid.Column="7"
Style="{StaticResource Table}"/>
<Border Grid.Column="8"
Style="{StaticResource Table}"/>
<Border Grid.Column="9"
Style="{StaticResource Table}"/>
</Grid>
<ItemsControl Grid.Row="1"
ItemsSource="{Binding DoorOnMachineList}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<Canvas/>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate>
<Border Canvas.Bottom="{Binding dBottomPosition}"
Canvas.Left="{Binding dLeftPosition}"
Style="{StaticResource Door}">
<TextBlock Text="{Binding nId}"
FontSize="20"
HorizontalAlignment="Center"
VerticalAlignment="Center"/>
</Border>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
<!--<Canvas Grid.Row="1">
<Border Canvas.Top="30"
Canvas.Left="30"
Style="{StaticResource Door}">
<TextBlock Text="5"
FontSize="20"
HorizontalAlignment="Center"
VerticalAlignment="Center"/>
</Border>
</Canvas>-->
</Grid>
<ItemsControl Grid.Row="1"
ItemsSource="{Binding DoorOnMachineList}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<Canvas/>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate>
<Border Canvas.Bottom="{Binding dBottomPosition}"
Canvas.Left="{Binding dLeftPosition}"
Style="{StaticResource Door}">
<TextBlock Text="{Binding nId}"
FontSize="20"
HorizontalAlignment="Center"
VerticalAlignment="Center"/>
</Border>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
--><!--<Canvas Grid.Row="1">
<Border Canvas.Top="30"
Canvas.Left="30"
Style="{StaticResource Door}">
<TextBlock Text="5"
FontSize="20"
HorizontalAlignment="Center"
VerticalAlignment="Center"/>
</Border>
</Canvas>--><!--
</Grid>-->
<Grid Grid.Row="1">
<Grid.RowDefinitions>
<RowDefinition Height="1*"/>
<RowDefinition Height="1*"/>
<RowDefinition Height="1*"/>
</Grid.RowDefinitions>
<StackPanel Orientation="Horizontal">
<StackPanel>
<TextBlock Text="Presenza porta M1S0"/>
<Button Content="0"
Command="{Binding WriteVariable_Command}"
CommandParameter="1,2,980,0"
Width="30"/>
<Button Content="1"
Command="{Binding WriteVariable_Command}"
CommandParameter="1,2,980,1"
Width="30"/>
</StackPanel>
<StackPanel>
<TextBlock Text="Avanza porta in M1S1"/>
<Button Content="0"
Command="{Binding MoveVariable_Command}"
CommandParameter="1,1,1360->1,1,1361"
Width="30"/>
</StackPanel>
<StackPanel>
<TextBlock Text="Avanza porta in M1S2"/>
<Button Content="0"
Command="{Binding MoveVariable_Command}"
CommandParameter="1,1,1361->1,1,1362"
Width="30"/>
</StackPanel>
<StackPanel>
<TextBlock Text="Avanza porta in M1S3"/>
<Button Content="0"
Command="{Binding MoveVariable_Command}"
CommandParameter="1,1,1362->1,1,1363"
Width="30"/>
</StackPanel>
<StackPanel>
<TextBlock Text="Avanza porta in M1S4/M2S0"/>
<Button Content="0"
Command="{Binding MoveVariable_Command}"
CommandParameter="1,1,1363->1,1,1364;2,1,1360"
Width="30"/>
</StackPanel>
<StackPanel>
<TextBlock Text="Presenza porta M2S0"/>
<Button Content="0"
Command="{Binding WriteVariable_Command}"
CommandParameter="2,2,980,0"
Width="30"/>
<Button Content="1"
Command="{Binding WriteVariable_Command}"
CommandParameter="2,2,980,1"
Width="30"/>
</StackPanel>
<StackPanel>
<TextBlock Text="Avanza porta in M2S1"/>
<Button Content="0"
Command="{Binding MoveVariable_Command}"
CommandParameter="1,1,1364;2,1,1360->2,1,1361"
Width="30"/>
</StackPanel>
<StackPanel>
<TextBlock Text="Avanza porta in M2S2"/>
<Button Content="0"
Command="{Binding MoveVariable_Command}"
CommandParameter="2,1,1361->2,1,1362"
Width="30"/>
</StackPanel>
<StackPanel>
<TextBlock Text="Avanza porta in M2S3"/>
<Button Content="0"
Command="{Binding MoveVariable_Command}"
CommandParameter="2,1,1362->2,1,1363"
Width="30"/>
</StackPanel>
<StackPanel>
<TextBlock Text="Avanza porta in M2S4"/>
<Button Content="0"
Command="{Binding MoveVariable_Command}"
CommandParameter="2,1,1363->2,1,1364"
Width="30"/>
</StackPanel>
</StackPanel>
<StackPanel Grid.Row="1"
Orientation="Horizontal">
<TextBlock Text="State M1"/>
<Button Content="0"
Command="{Binding WriteVariable_Command}"
CommandParameter="1,1,1352,0"
Width="30"/>
<Button Content="1"
Command="{Binding WriteVariable_Command}"
CommandParameter="1,1,1352,1"
Width="30"/>
<Button Content="2"
Command="{Binding WriteVariable_Command}"
CommandParameter="1,1,1352,2"
Width="30"/>
<Button Content="3"
Command="{Binding WriteVariable_Command}"
CommandParameter="1,1,1352,3"
Width="30"/>
<Button Content="4"
Command="{Binding WriteVariable_Command}"
CommandParameter="1,1,1352,4"
Width="30"/>
<Button Content="5"
Command="{Binding WriteVariable_Command}"
CommandParameter="1,1,1352,5"
Width="30"/>
</StackPanel>
<StackPanel Grid.Row="2"
Orientation="Horizontal">
<TextBlock Text="State M2"/>
<Button Content="0"
Command="{Binding WriteVariable_Command}"
CommandParameter="2,1,1352,0"
Width="30"/>
<Button Content="1"
Command="{Binding WriteVariable_Command}"
CommandParameter="2,1,1352,1"
Width="30"/>
<Button Content="2"
Command="{Binding WriteVariable_Command}"
CommandParameter="2,1,1352,2"
Width="30"/>
<Button Content="3"
Command="{Binding WriteVariable_Command}"
CommandParameter="2,1,1352,3"
Width="30"/>
<Button Content="4"
Command="{Binding WriteVariable_Command}"
CommandParameter="2,1,1352,4"
Width="30"/>
<Button Content="5"
Command="{Binding WriteVariable_Command}"
CommandParameter="2,1,1352,5"
Width="30"/>
</StackPanel>
</Grid>
</Grid>
</Grid>
@@ -1,5 +1,8 @@
Imports System.Collections.ObjectModel
Imports System.Reflection
Imports System.Windows.Threading
Imports Newtonsoft.Json.Linq
Imports Supervisor.Plugin.FiveLakes.Variable
Public Class MachinePageVM
@@ -19,6 +22,10 @@ Public Class MachinePageVM
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),
@@ -43,7 +50,31 @@ Public Class MachinePageVM
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.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()
@@ -87,6 +118,164 @@ Public Class MachinePageVM
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
@@ -0,0 +1,52 @@
<Window x:Class="ProcessManagerV"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Height="200"
Width="300">
<StackPanel>
<Grid HorizontalAlignment="Center">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="30"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<TextBlock Text="Arguments Queue Count: "/>
<TextBlock Grid.Column="1"
Text="{Binding ArgumentsQueue}"/>
<TextBlock Grid.Row="1"
Text="ResultQueue: "/>
<TextBlock Grid.Column="1"
Grid.Row="1"
Text="{Binding ResultQueueCount}"/>
</Grid>
<!--<DataGrid ItemsSource="{Binding ThreadList}"
AutoGenerateColumns="False">
<DataGrid.Columns>
<DataGridTextColumn Header="Process Status"
Binding="{Binding ProcessStatus}"/>
<DataGridTextColumn Header="Curr Request Id"
Binding="{Binding CurrRequest.nId}"/>
<DataGridTextColumn Header="Curr Request Args"
Binding="{Binding CurrRequest.sArgs}"/>
<DataGridTextColumn Header="Process Result"
Binding="{Binding nProcResult}"/>
</DataGrid.Columns>
</DataGrid>-->
<ItemsControl ItemsSource="{Binding ThreadList}">
<ItemsControl.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<TextBlock Text="{Binding ProcessStatus}"/>
<TextBlock Text="{Binding CurrRequest.nId}"/>
<TextBlock Text="{Binding CurrRequest.sArgs}"/>
<TextBlock Text="{Binding nProcResult}"/>
</StackPanel>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</StackPanel>
</Window>
@@ -0,0 +1,18 @@
Public Class ProcessManagerV
Private WithEvents m_ProcessManagerVM As ProcessManagerVM
Sub New(Owner As Window, ProcessManagerVM As ProcessManagerVM)
'MyBase.New(Owner)
' This call is required by the designer.
InitializeComponent()
Me.DataContext = ProcessManagerVM
' Assegno al riferimento locale al VM il VM preso dal DataContext
m_ProcessManagerVM = ProcessManagerVM
End Sub
'Private Sub CloseWindow(bDialogResult As Boolean) Handles m_ProcessManagerVM.m_CloseWindow
' Me.DialogResult = bDialogResult
'End Sub
End Class
@@ -0,0 +1,52 @@
Imports System.Windows.Threading
Imports System.Collections.ObjectModel
Public Class ProcessManagerVM
Inherits VMBase
Private m_UpdateDataTimer As New DispatcherTimer
Private m_ExecProcessManager As ExecProcessManager
Public ReadOnly Property ExecProcessManager As ExecProcessManager
Get
Return m_ExecProcessManager
End Get
End Property
Public ReadOnly Property ArgumentsQueue As String
Get
Return m_ExecProcessManager.ArgumentsQueueCount.ToString()
End Get
End Property
Public ReadOnly Property ResultQueue As String
Get
Return m_ExecProcessManager.ArgumentsResultQueueCount.ToString()
End Get
End Property
Public ReadOnly Property ThreadList As ObservableCollection(Of ThreadData)
Get
If Not IsNothing(m_ExecProcessManager.ThreadDataList) Then
Return New ObservableCollection(Of ThreadData)(m_ExecProcessManager.ThreadDataList.ToList())
Else
Return New ObservableCollection(Of ThreadData)
End If
End Get
End Property
Sub New(ExecProcessManager As ExecProcessManager)
m_ExecProcessManager = ExecProcessManager
m_UpdateDataTimer.Interval = New TimeSpan(0, 0, 1)
AddHandler m_UpdateDataTimer.Tick, AddressOf UpdateDataTimer_Tick
m_UpdateDataTimer.Start()
End Sub
Private Sub UpdateDataTimer_Tick(sender As Object, e As EventArgs)
NotifyPropertyChanged(NameOf(ArgumentsQueue))
NotifyPropertyChanged(NameOf(ResultQueue))
NotifyPropertyChanged(NameOf(ThreadList))
End Sub
End Class
@@ -101,6 +101,9 @@
<DependentUpon>DoorListPageV.xaml</DependentUpon>
</Compile>
<Compile Include="DoorListPage\DoorListPageVM.vb" />
<Compile Include="ProcessManager\ProcessManagerV.xaml.vb">
<DependentUpon>ProcessManagerV.xaml</DependentUpon>
</Compile>
<Compile Include="FiveLakesUI.xaml.vb">
<DependentUpon>FiveLakesUI.xaml</DependentUpon>
</Compile>
@@ -116,6 +119,7 @@
<DependentUpon>MainMenuV.xaml</DependentUpon>
</Compile>
<Compile Include="MainMenu\MainMenuVM.vb" />
<Compile Include="ProcessManager\ProcessManagerVM.vb" />
<Compile Include="Utility\Dictionary.xaml.vb">
<DependentUpon>Dictionary.xaml</DependentUpon>
</Compile>
@@ -156,6 +160,10 @@
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="ProcessManager\ProcessManagerV.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="FiveLakesUI.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
@@ -2,6 +2,7 @@
Imports System.Threading
Imports MS.Internal
Imports Supervisor.Plugin.FiveLakes.ThreadData
Imports System.Windows.Threading
Public Class ExecProcessManager
@@ -12,6 +13,21 @@ Public Class ExecProcessManager
STOPPED = 2
End Enum
Private Enum ProcessManagerStates
NULL = 0
OPEN = 1
CLOSE = 2
End Enum
Private m_ProcessManagerTimer As New DispatcherTimer
Private m_ProcessManagerState As ProcessManagerStates
Private m_ProcessManagerV As ProcessManagerV
Public ReadOnly Property ProcessManagerV As ProcessManagerV
Get
Return m_ProcessManagerV
End Get
End Property
' riferimento al thread principale
Private m_ExecutionThread As Thread
Private m_ExecutionThreadStatus As ExecutionThreadStatuses = ExecutionThreadStatuses.STOPPED
@@ -21,9 +37,14 @@ Public Class ExecProcessManager
End Get
End Property
' array dei thread
Private ThreadList As Thread()
Private m_ThreadList As Thread()
' array dei dati dei thread
Private ThreadDataList As ThreadData()
Private m_ThreadDataList As ThreadData()
Friend ReadOnly Property ThreadDataList As ThreadData()
Get
Return m_ThreadDataList
End Get
End Property
' variabile che ferma i processi
Private m_bStopProcess As Boolean = False
' variabile che conferma chiusura dei processi
@@ -70,6 +91,26 @@ Public Class ExecProcessManager
Sub New(sProcessFileName As String, sProcessArguments As String)
m_sProcessFileName = sProcessFileName
m_sProcessArguments = sProcessArguments
m_ProcessManagerTimer.Interval = New TimeSpan(0, 0, 1)
AddHandler m_ProcessManagerTimer.Tick, AddressOf ProcessManagerTimer_Tick
m_ProcessManagerTimer.Start()
End Sub
Private Sub ProcessManagerTimer_Tick(sender As Object, e As EventArgs)
Select Case m_ProcessManagerState
Case ProcessManagerStates.OPEN
' creo finestra statistiche processi
m_ProcessManagerV = New ProcessManagerV(Application.Current.MainWindow, New ProcessManagerVM(Me))
ProcessManagerV.Show()
m_ProcessManagerState = ProcessManagerStates.NULL
Case ProcessManagerStates.CLOSE
' chiudo finestra statistiche processi
If Not IsNothing(m_ProcessManagerV) Then
ProcessManagerV.Close()
m_ProcessManagerV = Nothing
End If
m_ProcessManagerState = ProcessManagerStates.NULL
End Select
End Sub
Public Function ArgumentsEnqueue(ProcessArgs As ProcessArgs) As Boolean
@@ -90,6 +131,14 @@ Public Class ExecProcessManager
Return DequeueProcessArgs
End Function
Public Function ArgumentsQueueCount() As Integer
Dim nCount As Integer = 0
SyncLock ArgumentsQueueLock
nCount = m_ArgumentsQueue.Count
End SyncLock
Return nCount
End Function
Public Function ArgumentsResultEnqueue(ProcessArgsResult As ProcessArgsResult) As Boolean
SyncLock ArgumentsResultQueueLock
m_ArgumentsResultQueue.Enqueue(ProcessArgsResult)
@@ -107,6 +156,14 @@ Public Class ExecProcessManager
Return DequeueProcessArgsResult
End Function
Public Function ArgumentsResultQueueCount() As Integer
Dim nCount As Integer = 0
SyncLock ArgumentsResultQueueLock
nCount = m_ArgumentsResultQueue.Count
End SyncLock
Return nCount
End Function
Public Sub SetMaxCamInstances(nValue As Integer)
' Numero di core logici da utilizzare (minimo tra presenti sul PC e imposti da INI)
Dim nMaxThread As Integer = Math.Min(Environment.ProcessorCount, nValue)
@@ -127,6 +184,8 @@ Public Class ExecProcessManager
m_ExecutionThread.Start()
m_ExecutionThreadStatus = ExecutionThreadStatuses.RUNNING
' lancio apertura finestra statistiche processi
m_ProcessManagerState = ProcessManagerStates.OPEN
End Sub
Public Sub StopExecutionThread()
@@ -142,8 +201,10 @@ Public Class ExecProcessManager
End While
m_ExecutionThread = Nothing
End If
ThreadList = Nothing
m_ThreadList = Nothing
m_ExecutionThreadStatus = ExecutionThreadStatuses.STOPPED
' lancio chiusura finestra statistiche processi
m_ProcessManagerState = ProcessManagerStates.CLOSE
End Sub
' funzione di esecuzione del thread principale che gestice i processi
@@ -154,14 +215,14 @@ Public Class ExecProcessManager
bStopMainProcess = m_bStopProcess
' se processo fermato, fermo i thread
If bStopMainProcess Then
If Not IsNothing(ThreadList) AndAlso ThreadList.Count > 0 AndAlso Not IsNothing(ThreadList(0)) Then
If Not IsNothing(m_ThreadList) AndAlso m_ThreadList.Count > 0 AndAlso Not IsNothing(m_ThreadList(0)) Then
' li fermo
m_bStopProcess = True
' verifico siano terminati
Dim bOneNotEnded As Boolean = True
While bOneNotEnded
bOneNotEnded = False
For Each Thread In ThreadList
For Each Thread In m_ThreadList
If Not IsNothing(Thread) Then
If Thread.IsAlive Then
bOneNotEnded = True
@@ -170,8 +231,8 @@ Public Class ExecProcessManager
Next
End While
' pulisco la lista
For ThreadIndex = 0 To ThreadList.Count - 1
ThreadList(ThreadIndex) = Nothing
For ThreadIndex = 0 To m_ThreadList.Count - 1
m_ThreadList(ThreadIndex) = Nothing
Next
m_bStopProcess = False
End If
@@ -179,31 +240,31 @@ Public Class ExecProcessManager
Return
End If
' se lista processi nulla o vuota, li faccio partire
If (IsNothing(ThreadList) OrElse ThreadList.Count = 0) Then
ThreadList = New Thread(m_MaxCamInstances - 1) {}
ThreadDataList = New ThreadData(m_MaxCamInstances - 1) {}
If (IsNothing(m_ThreadList) OrElse m_ThreadList.Count = 0) Then
m_ThreadList = New Thread(m_MaxCamInstances - 1) {}
m_ThreadDataList = New ThreadData(m_MaxCamInstances - 1) {}
For nThreadIndex = 0 To m_MaxCamInstances - 1
Dim ThreadId As Integer = nThreadIndex
ThreadList(nThreadIndex) = New Thread(Sub()
ThreadFunction(ThreadId)
End Sub)
ThreadList(nThreadIndex).SetApartmentState(ApartmentState.STA)
m_ThreadList(nThreadIndex) = New Thread(Sub()
ThreadFunction(ThreadId)
End Sub)
m_ThreadList(nThreadIndex).SetApartmentState(ApartmentState.STA)
' avvio thread di gestione della macchina che avvia la connessione
ThreadList(nThreadIndex).Start()
m_ThreadList(nThreadIndex).Start()
Thread.Sleep(100)
Next
End If
' se qualche processo in stop, lo faccio ripartire
For ThreadIndex = 0 To ThreadList.Count - 1
If ThreadIndex < ThreadList.Count Then
Dim Thread = ThreadList(ThreadIndex)
For ThreadIndex = 0 To m_ThreadList.Count - 1
If ThreadIndex < m_ThreadList.Count Then
Dim Thread = m_ThreadList(ThreadIndex)
If Not IsNothing(Thread) Then
If Thread.ThreadState = ThreadState.Stopped OrElse
Thread.ThreadState = ThreadState.Aborted OrElse
Thread.ThreadState = ThreadState.Suspended OrElse
(Not ThreadDataList(ThreadIndex).ProcessStatus = ProcessStatuses.TOBESTARTED AndAlso
(IsNothing(ThreadDataList(ThreadIndex).Process) OrElse
(Not IsNothing(ThreadDataList(ThreadIndex).Process) AndAlso ThreadDataList(ThreadIndex).Process.HasExited))) Then
(Not m_ThreadDataList(ThreadIndex).ProcessStatus = ProcessStatuses.TOBESTARTED AndAlso
(IsNothing(m_ThreadDataList(ThreadIndex).Process) OrElse
(Not IsNothing(m_ThreadDataList(ThreadIndex).Process) AndAlso m_ThreadDataList(ThreadIndex).Process.HasExited))) Then
' inserire un ritardo di rilancio?
' lo chiudo e rilancio
'Thread.Sleep(500)
@@ -214,22 +275,22 @@ Public Class ExecProcessManager
End While
Thread = Nothing
Dim ThreadId As Integer = ThreadIndex
ThreadList(ThreadIndex) = New Thread(Sub()
ThreadFunction(ThreadId)
End Sub)
ThreadList(ThreadIndex).SetApartmentState(ApartmentState.STA)
m_ThreadList(ThreadIndex) = New Thread(Sub()
ThreadFunction(ThreadId)
End Sub)
m_ThreadList(ThreadIndex).SetApartmentState(ApartmentState.STA)
' avvio thread di gestione della macchina che avvia la connessione
ThreadList(ThreadIndex).Start()
m_ThreadList(ThreadIndex).Start()
End If
Else
Dim ThreadId As Integer = ThreadIndex
If ThreadIndex < ThreadList.Count Then
ThreadList(ThreadIndex) = New Thread(Sub()
ThreadFunction(ThreadId)
End Sub)
ThreadList(ThreadIndex).SetApartmentState(ApartmentState.STA)
If ThreadIndex < m_ThreadList.Count Then
m_ThreadList(ThreadIndex) = New Thread(Sub()
ThreadFunction(ThreadId)
End Sub)
m_ThreadList(ThreadIndex).SetApartmentState(ApartmentState.STA)
' avvio thread di gestione della macchina che avvia la connessione
ThreadList(ThreadIndex).Start()
m_ThreadList(ThreadIndex).Start()
End If
End If
End If
@@ -241,7 +302,7 @@ Public Class ExecProcessManager
End SyncLock
If nQueueArgs = 0 Then
Dim bProcessWaiting As Boolean = False
For Each ThreadData In ThreadDataList
For Each ThreadData In m_ThreadDataList
If ThreadData.ProcessStatus = ProcessStatuses.WAITINGANSWER OrElse ThreadData.ProcessStatus = ProcessStatuses.ANSWERRECEIVED Then
bProcessWaiting = True
Exit For
@@ -263,7 +324,7 @@ Public Class ExecProcessManager
' funzione di esecuzione del singolo processo che comunica con il programma
Private Sub ThreadFunction(ThreadIndex As Integer)
Dim MyThreadData As New ThreadData
ThreadDataList(ThreadIndex) = MyThreadData
m_ThreadDataList(ThreadIndex) = MyThreadData
'Dim CurrThreadStat As New ThreadStat(ThreadIndex, DateTime.Now)
'HistoryThreadDataList.Add(CurrThreadStat)
'MyThreadData.SetThreadStat(CurrThreadStat)
@@ -495,9 +556,9 @@ Public Class ExecProcessManager
Dim nResult As Integer = -1
If Integer.TryParse(Results(1), nIndex) AndAlso nIndex >= 0 Then
If Integer.TryParse(Results(2), nResult) AndAlso nResult >= 0 Then
ThreadDataList(nIndex).SetProcResult(nResult)
m_ThreadDataList(nIndex).SetProcResult(nResult)
End If
ThreadDataList(nIndex).SetProcessStatus(ThreadData.ProcessStatuses.ANSWERRECEIVED)
m_ThreadDataList(nIndex).SetProcessStatus(ThreadData.ProcessStatuses.ANSWERRECEIVED)
End If
End If
End If
@@ -544,15 +605,15 @@ Public Class ThreadData
m_CurrRequest = value
End Sub
Private m_sDdfPath As String
Public ReadOnly Property sDdfPath As String
Get
Return m_sDdfPath
End Get
End Property
Friend Sub SetDdfPath(value As String)
m_sDdfPath = value
End Sub
'Private m_sDdfPath As String
'Public ReadOnly Property sDdfPath As String
' Get
' Return m_sDdfPath
' End Get
'End Property
'Friend Sub SetDdfPath(value As String)
' m_sDdfPath = value
'End Sub
Private m_nProcResult As Integer
Public ReadOnly Property nProcResult As Integer