diff --git a/Exe/SupervisorD32.exe b/Exe/SupervisorD32.exe index 26a0f32..a801804 100644 Binary files a/Exe/SupervisorD32.exe and b/Exe/SupervisorD32.exe differ diff --git a/Supervisor.Plugin.FiveLakes/DoorListPage/DoorListPageVM.vb b/Supervisor.Plugin.FiveLakes/DoorListPage/DoorListPageVM.vb index 1c9ac07..9ef56bf 100644 --- a/Supervisor.Plugin.FiveLakes/DoorListPage/DoorListPageVM.vb +++ b/Supervisor.Plugin.FiveLakes/DoorListPage/DoorListPageVM.vb @@ -45,6 +45,7 @@ Public Class DoorListPageVM #Region "CONSTRUCTOR" Sub New() + Map.SetRefDoorListPageVM(Me) Dim sBackupDirPath As String = "" GetPluginPrivateProfileString(S_GENERAL, "BackupDir", "", sBackupDirPath) Dim sBackupFilePath As String = sBackupDirPath & "\Backup.json" @@ -131,6 +132,10 @@ Public Class DoorListPageVM End If 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) + End Function + #End Region ' METHODS #Region "COMMANDS" @@ -247,10 +252,10 @@ Public Class DoorListPageVM For nQuantityIndex = 1 To nQuantity Dim nId As Integer = 1 If m_DoorList.Count > 0 Then - Dim LastDoor = m_DoorList.LastOrDefault() - If Not IsNothing(LastDoor) AndAlso LastDoor.nId < 1000 Then - nId = LastDoor.nId + 1 - End If + Dim nMaxId As Integer = m_DoorList.Max(Of Integer)(Function(x) x.nId) + 'If nMaxId < 100 Then + nId = nMaxId + 1 + 'End If End If Dim NewDoor As New Door(nId, nLineIndex, Values(nDDFNameIndex), Path.GetFileName(sCSVPath), 1, dWidth, dHeight, dThickness, Headers, Values) @@ -373,8 +378,15 @@ Public Class DoorListPageVM End Property Public Sub DeleteAll() - If IsNothing(SelDoor) OrElse SelDoor.nState >= Door.DoorStates.SENT_TO_PRODUCTION Then Return - WriteBackup() + If m_DoorList.Count = 0 Then Return + 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 + m_DoorList.Remove(Door) + Next + WriteBackup() + End If End Sub #End Region ' DeleteAll @@ -397,9 +409,9 @@ Public Class DoorListPageVM ' 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 nOldIndex As Integer = m_DoorList.IndexOf(SelDoor) - + Dim SelectedDoor As Door = m_SelDoor m_DoorList.Move(nOldIndex, nNewIndex) - SelDoor.SetState(Door.DoorStates.SENT_TO_PRODUCTION) + SelectedDoor.SetState(Door.DoorStates.SENT_TO_PRODUCTION) WriteBackup() End Sub diff --git a/Supervisor.Plugin.FiveLakes/LUA/LuaManager.vb b/Supervisor.Plugin.FiveLakes/LUA/LuaManager.vb new file mode 100644 index 0000000..344f455 --- /dev/null +++ b/Supervisor.Plugin.FiveLakes/LUA/LuaManager.vb @@ -0,0 +1,16 @@ +Imports System.ComponentModel.Composition +Imports Supervisor.Plugin.Interface +Imports KeraLua + + + +Public Class LuaManager + Implements IPluginLuaManager + + Private state As Lua + + Public Function PlgInit(state As Object) As Boolean Implements IPluginLuaManager.PlgInit + Return LuaInstallGeneral(state) + End Function + +End Class diff --git a/Supervisor.Plugin.FiveLakes/LUA/Lua_Aux.vb b/Supervisor.Plugin.FiveLakes/LUA/Lua_Aux.vb new file mode 100644 index 0000000..31a7fe6 --- /dev/null +++ b/Supervisor.Plugin.FiveLakes/LUA/Lua_Aux.vb @@ -0,0 +1,363 @@ +Imports KeraLua + +Public Module Lua_Aux + + Friend Function LuaClearStack(state As Lua) + Dim nIndex As Integer = state.GetTop() + If nIndex > 0 Then + state.Pop(nIndex) + End If + Return True + End Function + + Friend Function LuaCheckParam(state As Lua, nIndex As Integer, ByRef bValue As Boolean) + If Not LuaGetParam(state, nIndex, bValue) Then + Return state.Error(" Invalid Parameter # " & nIndex) + End If + Return True + End Function + + Friend Function LuaCheckParam(state As Lua, nIndex As Integer, ByRef nValue As Integer) + If Not LuaGetParam(state, nIndex, nValue) Then + Return state.Error(" Invalid Parameter # " & nIndex) + End If + Return True + End Function + + Friend Function LuaCheckParam(state As Lua, nIndex As Integer, ByRef dValue As Double) + If Not LuaGetParam(state, nIndex, dValue) Then + Return state.Error(" Invalid Parameter # " & nIndex) + End If + Return True + End Function + + Friend Function LuaCheckParam(state As Lua, nIndex As Integer, ByRef sValue As String) + If Not LuaGetParam(state, nIndex, sValue) Then + Return state.Error(" Invalid Parameter # " & nIndex) + End If + Return True + End Function + + Friend Function LuaGetParam(state As Lua, nIndex As Integer, ByRef bValue As Boolean) As Boolean + If Not state.IsBoolean(nIndex) Then Return False + bValue = state.ToBoolean(nIndex) + Return True + End Function + + Friend Function LuaGetParam(state As Lua, nIndex As Integer, ByRef nValue As Integer) As Boolean + If Not state.IsNumber(nIndex) Then Return False + nValue = Math.Round(state.ToNumber(nIndex)) + Return True + End Function + + Friend Function LuaGetParam(state As Lua, nIndex As Integer, ByRef dValue As Double) As Boolean + If Not state.IsNumber(nIndex) Then Return False + dValue = state.ToNumber(nIndex) + Return True + End Function + + Friend Function LuaGetParam(state As Lua, nIndex As Integer, ByRef sValue As String) As Boolean + If Not state.IsString(nIndex) Then Return False + sValue = state.ToString(nIndex) + Return True + End Function + + Friend Function LuaSetParam(state As Lua) As Boolean + Try + state.PushNil() + Catch ex As Exception + Return False + End Try + Return True + End Function + + Friend Function LuaSetParam(state As Lua, ByRef bValue As Boolean) As Boolean + Try + state.PushBoolean(bValue) + Catch ex As Exception + Return False + End Try + Return True + End Function + + Friend Function LuaSetParam(state As Lua, ByRef nValue As Integer) As Boolean + Try + state.PushInteger(nValue) + Catch ex As Exception + Return False + End Try + Return True + End Function + + Friend Function LuaSetParam(state As Lua, ByRef dValue As Double) As Boolean + Try + state.PushNumber(dValue) + Catch ex As Exception + Return False + End Try + Return True + End Function + + Friend Function LuaSetParam(state As Lua, ByRef sValue As String) As Boolean + Try + state.PushString(sValue) + Catch ex As Exception + Return False + End Try + Return True + End Function + + Friend Function LuaGetTabFieldParam(state As Lua, nIndex As Integer, sVarName As String, ByRef bValue As Boolean) As Boolean + If Not state.IsTable(nIndex) Then Return False + state.GetField(nIndex, sVarName) + Dim bResult As Boolean = LuaGetParam(state, -1, bValue) + state.Pop(1) + Return bResult + End Function + + Friend Function LuaGetTabFieldParam(state As Lua, nIndex As Integer, sVarName As String, ByRef nValue As Integer) As Boolean + If Not state.IsTable(nIndex) Then Return False + state.GetField(nIndex, sVarName) + Dim bResult As Boolean = LuaGetParam(state, -1, nValue) + state.Pop(1) + Return bResult + End Function + + Friend Function LuaGetTabFieldParam(state As Lua, nIndex As Integer, sVarName As String, ByRef dValue As Double) As Boolean + If Not state.IsTable(nIndex) Then Return False + state.GetField(nIndex, sVarName) + Dim bResult As Boolean = LuaGetParam(state, -1, dValue) + state.Pop(1) + Return bResult + End Function + + Friend Function LuaGetTabFieldParam(state As Lua, nIndex As Integer, sVarName As String, ByRef sValue As String) As Boolean + If Not state.IsTable(nIndex) Then Return False + state.GetField(nIndex, sVarName) + Dim bResult As Boolean = LuaGetParam(state, -1, sValue) + state.Pop(1) + Return bResult + End Function + + Friend Function LuaGetGlobVar(state As Lua, ByRef sName As String, ByRef bValue As Boolean) As Boolean + ' se variabile standard + If Not sName.Contains("."c) Then + state.GetGlobal(sName) + Dim bResult As Boolean = LuaGetParam(state, -1, bValue) + state.Pop(1) + Return bResult + Else + Dim sTableName As String = "", sVarName As String = "" + Dim sParams() As String = sName.Split("."c) + sTableName = sParams(0) + sVarName = sParams(1) + state.GetGlobal(sTableName) + Dim bResult As Boolean = LuaGetTabFieldParam(state, -1, sVarName, bValue) + state.Pop(1) + Return bResult + End If + End Function + + Friend Function LuaGetGlobVar(state As Lua, ByRef sName As String, ByRef nValue As Integer) As Boolean + ' se variabile standard + If Not sName.Contains("."c) Then + state.GetGlobal(sName) + Dim bResult As Boolean = LuaGetParam(state, -1, nValue) + state.Pop(1) + Return bResult + Else + Dim sTableName As String = "", sVarName As String = "" + Dim sParams() As String = sName.Split("."c) + sTableName = sParams(0) + sVarName = sParams(1) + state.GetGlobal(sTableName) + Dim bResult As Boolean = LuaGetTabFieldParam(state, -1, sVarName, nValue) + state.Pop(1) + Return bResult + End If + End Function + + Friend Function LuaGetGlobVar(state As Lua, ByRef sName As String, ByRef dValue As Double) As Boolean + ' se variabile standard + If Not sName.Contains("."c) Then + state.GetGlobal(sName) + Dim bResult As Boolean = LuaGetParam(state, -1, dValue) + state.Pop(1) + Return bResult + Else + Dim sTableName As String = "", sVarName As String = "" + Dim sParams() As String = sName.Split("."c) + sTableName = sParams(0) + sVarName = sParams(1) + state.GetGlobal(sTableName) + Dim bResult As Boolean = LuaGetTabFieldParam(state, -1, sVarName, dValue) + state.Pop(1) + Return bResult + End If + End Function + + Friend Function LuaGetGlobVar(state As Lua, ByRef sName As String, ByRef sValue As String) As Boolean + ' se variabile standard + If Not sName.Contains("."c) Then + state.GetGlobal(sName) + Dim bResult As Boolean = LuaGetParam(state, -1, sValue) + state.Pop(1) + Return bResult + Else + Dim sTableName As String = "", sVarName As String = "" + Dim sParams() As String = sName.Split("."c) + sTableName = sParams(0) + sVarName = sParams(1) + state.GetGlobal(sTableName) + Dim bResult As Boolean = LuaGetTabFieldParam(state, -1, sVarName, sValue) + state.Pop(1) + Return bResult + End If + End Function + + Friend Function LuaSetTabFieldParam(state As Lua, nIndex As Integer, sVarName As String) As Boolean + If Not state.IsTable(nIndex) Then Return False + If Not LuaSetParam(state) Then Return False + Dim nPos As Integer = (If(nIndex > 0, nIndex, nIndex - 1)) + state.SetField(nPos, sVarName) + Return True + End Function + + Friend Function LuaSetTabFieldParam(state As Lua, nIndex As Integer, sVarName As String, ByRef bValue As Boolean) As Boolean + If Not state.IsTable(nIndex) Then Return False + If Not LuaSetParam(state, bValue) Then Return False + Dim nPos As Integer = (If(nIndex > 0, nIndex, nIndex - 1)) + state.SetField(nPos, sVarName) + Return True + End Function + + Friend Function LuaSetTabFieldParam(state As Lua, nIndex As Integer, sVarName As String, ByRef nValue As Integer) As Boolean + If Not state.IsTable(nIndex) Then Return False + If Not LuaSetParam(state, nValue) Then Return False + Dim nPos As Integer = (If(nIndex > 0, nIndex, nIndex - 1)) + state.SetField(nPos, sVarName) + Return True + End Function + + Friend Function LuaSetTabFieldParam(state As Lua, nIndex As Integer, sVarName As String, ByRef dValue As Double) As Boolean + If Not state.IsTable(nIndex) Then Return False + If Not LuaSetParam(state, dValue) Then Return False + Dim nPos As Integer = (If(nIndex > 0, nIndex, nIndex - 1)) + state.SetField(nPos, sVarName) + Return True + End Function + + Friend Function LuaSetTabFieldParam(state As Lua, nIndex As Integer, sVarName As String, ByRef sValue As String) As Boolean + If Not state.IsTable(nIndex) Then Return False + If Not LuaSetParam(state, sValue) Then Return False + Dim nPos As Integer = (If(nIndex > 0, nIndex, nIndex - 1)) + state.SetField(nPos, sVarName) + Return True + End Function + + Friend Function LuaSetGlobVar(state As Lua, ByRef sName As String, ByRef bValue As Boolean) As Boolean + ' se variabile standard + If Not sName.Contains("."c) Then + If Not LuaSetParam(state, bValue) Then Return False + state.SetGlobal(sName) + Return True + ' altrimenti campo di tabella + Else + Dim sTableName As String = "", sVarName As String = "" + Dim sParams() As String = sName.Split("."c) + sTableName = sParams(0) + sVarName = sParams(1) + state.GetGlobal(sTableName) + Dim bResult As Boolean = LuaSetTabFieldParam(state, -1, sVarName, bValue) + state.Pop(1) + Return bResult + End If + End Function + + Friend Function LuaSetGlobVar(state As Lua, ByRef sName As String, ByRef nValue As Integer) As Boolean + ' se variabile standard + If Not sName.Contains("."c) Then + If Not LuaSetParam(state, nValue) Then Return False + state.SetGlobal(sName) + Return True + ' altrimenti campo di tabella + Else + Dim sTableName As String = "", sVarName As String = "" + Dim sParams() As String = sName.Split("."c) + sTableName = sParams(0) + sVarName = sParams(1) + state.GetGlobal(sTableName) + Dim bResult As Boolean = LuaSetTabFieldParam(state, -1, sVarName, nValue) + state.Pop(1) + Return bResult + End If + End Function + + Friend Function LuaSetGlobVar(state As Lua, ByRef sName As String, ByRef dValue As Double) As Boolean + ' se variabile standard + If Not sName.Contains("."c) Then + If Not LuaSetParam(state, dValue) Then Return False + state.SetGlobal(sName) + Return True + ' altrimenti campo di tabella + Else + Dim sTableName As String = "", sVarName As String = "" + Dim sParams() As String = sName.Split("."c) + sTableName = sParams(0) + sVarName = sParams(1) + state.GetGlobal(sTableName) + Dim bResult As Boolean = LuaSetTabFieldParam(state, -1, sVarName, dValue) + state.Pop(1) + Return bResult + End If + End Function + + Friend Function LuaSetGlobVar(state As Lua, ByRef sName As String, ByRef sValue As String) As Boolean + ' se variabile standard + If Not sName.Contains("."c) Then + If Not LuaSetParam(state, sValue) Then Return False + state.SetGlobal(sName) + Return True + ' altrimenti campo di tabella + Else + Dim sTableName As String = "", sVarName As String = "" + Dim sParams() As String = sName.Split("."c) + sTableName = sParams(0) + sVarName = sParams(1) + state.GetGlobal(sTableName) + Dim bResult As Boolean = LuaSetTabFieldParam(state, -1, sVarName, sValue) + state.Pop(1) + Return bResult + End If + End Function + + Friend Function LuaResetGlobVar(state As Lua, ByRef sName As String) As Boolean + ' se variabile standard + If Not sName.Contains("."c) Then + If Not LuaSetParam(state) Then Return False + state.SetGlobal(sName) + Return True + ' altrimenti campo di tabella + Else + Dim sTableName As String = "", sVarName As String = "" + Dim sParams() As String = sName.Split("."c) + sTableName = sParams(0) + sVarName = sParams(1) + state.GetGlobal(sTableName) + Dim bResult As Boolean = LuaSetTabFieldParam(state, -1, sVarName) + state.Pop(1) + Return bResult + End If + End Function + + Friend Function LuaCreateGlobTable(state As Lua, ByRef sName As String) As Boolean + Try + state.NewTable() + state.SetGlobal(sName) + Catch ex As Exception + Return False + End Try + Return True + End Function + +End Module diff --git a/Supervisor.Plugin.FiveLakes/LUA/Lua_General.vb b/Supervisor.Plugin.FiveLakes/LUA/Lua_General.vb new file mode 100644 index 0000000..c8afa82 --- /dev/null +++ b/Supervisor.Plugin.FiveLakes/LUA/Lua_General.vb @@ -0,0 +1,26 @@ +Imports KeraLua + +Public Module Lua_General + + Friend func_PlgGetNextDoor As LuaFunction = AddressOf Lua_PlgGetNextDoor + + Private Function Lua_PlgGetNextDoor(ByVal p As IntPtr) As Integer + Dim state = Lua.FromIntPtr(p) + LuaClearStack(state) + Dim NextDoor As Door = Map.refDoorListPageVM.GetNextDoor() + If Not IsNothing(NextDoor) Then + ' restituisco il risultato + LuaSetParam(state, NextDoor.nId) + LuaSetParam(state, NextDoor.sDDFName) + Return 2 + End If + Return 0 + End Function + + Friend Function LuaInstallGeneral(state As Lua) As Boolean + If IsNothing(state) Then Return False + state.Register("PlgGetNextDoor", func_PlgGetNextDoor) + Return True + End Function + +End Module diff --git a/Supervisor.Plugin.FiveLakes/MachinePage/MachinePageVM.vb b/Supervisor.Plugin.FiveLakes/MachinePage/MachinePageVM.vb index 66c7b15..8e02eb0 100644 --- a/Supervisor.Plugin.FiveLakes/MachinePage/MachinePageVM.vb +++ b/Supervisor.Plugin.FiveLakes/MachinePage/MachinePageVM.vb @@ -77,10 +77,9 @@ Public Class MachinePageVM Dim sIndexSplit() As String = Var.sIndex.Split("."c) Integer.TryParse(sIndexSplit(0), nIndex) Integer.TryParse(sIndexSplit(1), nBit) - Integer.TryParse(Var.sIndex, nIndex) - Dim dValue As Double = 0 - If Map.refSupervisorFunction.ComReadBitVar(nIndex, nBit, dValue, Var.nMachine) Then - Var.SetValue(dValue) + 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 diff --git a/Supervisor.Plugin.FiveLakes/Supervisor.Plugin.FiveLakes.vbproj b/Supervisor.Plugin.FiveLakes/Supervisor.Plugin.FiveLakes.vbproj index cfb8520..897736b 100644 --- a/Supervisor.Plugin.FiveLakes/Supervisor.Plugin.FiveLakes.vbproj +++ b/Supervisor.Plugin.FiveLakes/Supervisor.Plugin.FiveLakes.vbproj @@ -11,6 +11,8 @@ Custom true {7C77F537-8235-40AB-B24A-4E71CFB96D2C} + + true @@ -49,6 +51,9 @@ ..\..\..\EgtProg\DllD32\EgtWPFLib48.dll + + ..\packages\KeraLua.1.4.1\lib\net46\KeraLua.dll + ..\packages\Newtonsoft.Json.13.0.3\lib\net45\Newtonsoft.Json.dll @@ -100,6 +105,9 @@ FiveLakesUI.xaml + + + MachinePageV.xaml @@ -173,4 +181,11 @@ copy $(TargetPath) c:\EgtData\Supervisor\Plugin\Supervisor.Plugin.FiveLakes\Supervisor.Plugin.FiveLakes.dll + + + + This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. + + + \ No newline at end of file diff --git a/Supervisor.Plugin.FiveLakes/Utility/Map.vb b/Supervisor.Plugin.FiveLakes/Utility/Map.vb index fcf27f5..59ddb52 100644 --- a/Supervisor.Plugin.FiveLakes/Utility/Map.vb +++ b/Supervisor.Plugin.FiveLakes/Utility/Map.vb @@ -3,6 +3,7 @@ Module Map Private m_refFiveLakesUIVM As FiveLakesUIVM + Private m_refDoorListPageVM As DoorListPageVM Private m_refSupervisorFunction As IHost 'Private m_refMyStatusBarVM As MyStatusBarVM @@ -46,6 +47,12 @@ Module Map End Get End Property + Public ReadOnly Property refDoorListPageVM As DoorListPageVM + Get + Return m_refDoorListPageVM + End Get + End Property + Public ReadOnly Property refSupervisorFunction As IHost Get Return m_refSupervisorFunction @@ -264,6 +271,11 @@ Module Map Return Not IsNothing(m_refSupervisorFunction) End Function + Friend Function SetRefDoorListPageVM(DoorListPageVM As DoorListPageVM) As Boolean + m_refDoorListPageVM = DoorListPageVM + Return Not IsNothing(m_refDoorListPageVM) + End Function + ' Friend Function SetRefProjManagerVM(ProjManagerVM As ProjManagerVM) As Boolean ' m_refProjManagerVM = ProjManagerVM ' Return Not IsNothing(m_refProjManagerVM) diff --git a/Supervisor.Plugin.FiveLakes/packages.config b/Supervisor.Plugin.FiveLakes/packages.config index e46d5a8..03464bd 100644 --- a/Supervisor.Plugin.FiveLakes/packages.config +++ b/Supervisor.Plugin.FiveLakes/packages.config @@ -1,4 +1,5 @@  + \ No newline at end of file