From b5c9b31edff446e920b6d5a45c4293e126a80128 Mon Sep 17 00:00:00 2001 From: Nicola Carminati Date: Tue, 27 Feb 2018 17:08:52 +0100 Subject: [PATCH] Fix Fanuc Nc Window integration --- Client.Config/SubModels/VendorHmi.cs | 2 + Client.Utils/Constants.cs | 22 +++++++-- Client/View/NcWindow.cs | 59 +++++++++++++++++++------ Client/View/OpeningForm.cs | 7 +-- Step/wwwroot/assets/styles/base/nc.less | 9 ++++ Step/wwwroot/assets/styles/style.css | 8 ++++ Step/wwwroot/src/App.vue | 2 +- 7 files changed, 88 insertions(+), 21 deletions(-) diff --git a/Client.Config/SubModels/VendorHmi.cs b/Client.Config/SubModels/VendorHmi.cs index 226ab1a4..138949e8 100644 --- a/Client.Config/SubModels/VendorHmi.cs +++ b/Client.Config/SubModels/VendorHmi.cs @@ -11,6 +11,8 @@ namespace Client.Config.SubModels public Boolean Enabled { get; set; } public Boolean FollowNcWindow { get; set; } public ushort Type { get; set; } /* 0: Demo - 1: Fanuc - 2: Siemens - 3: Osai */ + public string IpAddress { get; set; } + public string Port { get; set; } } } diff --git a/Client.Utils/Constants.cs b/Client.Utils/Constants.cs index d63732eb..532de5d5 100644 --- a/Client.Utils/Constants.cs +++ b/Client.Utils/Constants.cs @@ -40,10 +40,24 @@ namespace Client.Utils //HMI Size & Position - public const int HMI_WINDOW_POS_X = 56; - public const int HMI_WINDOW_POS_Y = 176; - public const int HMI_WINDOW_WIDTH = 1024; - public const int HMI_WINDOW_HEIGHT = 768; + public const int HMI_WINDOW_WIDTH_DEMO = 1024; + public const int HMI_WINDOW_HEIGHT_DEMO = 768; + public const int HMI_WINDOW_WIDTH_FANUC = 960; + public const int HMI_WINDOW_HEIGHT_FANUC = 740; + public const int HMI_WINDOW_WIDTH_SIEMENS = 1024; + public const int HMI_WINDOW_HEIGHT_SIEMENS = 768; + public const int HMI_WINDOW_WIDTH_OSAI = 1024; + public const int HMI_WINDOW_HEIGHT_OSAI = 768; + + public const int HMI_WINDOW_POS_X_DEMO = 56; + public const int HMI_WINDOW_POS_Y_DEMO = 176; + public const int HMI_WINDOW_POS_X_FANUC = 88; + public const int HMI_WINDOW_POS_Y_FANUC = 190; + public const int HMI_WINDOW_POS_X_SIEMENS = 56; + public const int HMI_WINDOW_POS_Y_SIEMENS = 176; + public const int HMI_WINDOW_POS_X_OSAI = 56; + public const int HMI_WINDOW_POS_Y_OSAI = 176; + public const string HMI_WINDOW_TITLE_FANUC = "CNC Screen Display Function"; //KEYBOARD Constants public const int KEYB_HEIGHT = 377; diff --git a/Client/View/NcWindow.cs b/Client/View/NcWindow.cs index f869b0fc..cfc1e804 100644 --- a/Client/View/NcWindow.cs +++ b/Client/View/NcWindow.cs @@ -57,7 +57,6 @@ namespace CMS_Client.View private static IntPtr MainViewHandle; private static IntPtr TaskBarHandle; private static IntPtr StartBtnHandle; - private static IntPtr PopupHandle; private static uint MainProcessPID; private static uint NcProcessPID; private static uint ActualPID; @@ -67,7 +66,6 @@ namespace CMS_Client.View private static uint KeyboardPID; private static int TriedTimes; private static bool ProcKilled; - private static bool IsNcSiemens; private static bool KeyboardVisible; private static IntPtr KeyboardHandle; private static CfrRect LastKeybPoint; @@ -79,6 +77,10 @@ namespace CMS_Client.View private static IntPtr NcHND; private static Thread CaptureThread; private static Thread FollowNCThread; + private static int ncWindowWidth; + private static int ncWindowHeight; + private static int ncWindowX; + private static int ncWindowY; public static NcState State { get { return state; } } private static NcState state; @@ -111,7 +113,7 @@ namespace CMS_Client.View StartBtnHandle = FindWindow(Win7StartBtnCL, Win7StartBtnTxt); //Kill tool processes if they had been started whitout HMI (Only Siemens) - if (IsNcSiemens && processes.Length <= 0) + if (Config.VendorHmiConfig.Type == 2 && processes.Length <= 0) { //Kill All Windows KillAllProcessWithName(SiemensTool2Name); @@ -126,7 +128,7 @@ namespace CMS_Client.View //Wait until the process is started TriedTimes = 1; - while (processes[0].MainWindowHandle == IntPtr.Zero && TriedTimes < TimesToTryKill) + while ((processes[0].MainWindowHandle == IntPtr.Zero || !isWindowReady(processes[0].MainWindowTitle)) && TriedTimes < TimesToTryKill) { processes = Process.GetProcessesByName(processname); if (processes[0].MainWindowHandle == IntPtr.Zero) @@ -158,13 +160,17 @@ namespace CMS_Client.View //Setup the Process path ncprocess.StartInfo.FileName = processpath; + //Add arguments if is Fanuc NC + if(Config.VendorHmiConfig.Type == 1) + ncprocess.StartInfo.Arguments = "/H=" + Config.VendorHmiConfig.IpAddress + ":" + Config.VendorHmiConfig.Port + "/T=30"; + //Start the Process ncprocess.Start(); ncprocess.WaitForInputIdle(); //Wait until the process is started TriedTimes = 1; - while ((processes.Length <= 0 || (processes[0].MainWindowHandle == IntPtr.Zero)) && TriedTimes < TimesToTryOpen) + while ((processes.Length <= 0 || (processes[0].MainWindowHandle == IntPtr.Zero) || !isWindowReady(processes[0].MainWindowTitle)) && TriedTimes < TimesToTryOpen) { processes = Process.GetProcessesByName(processname); if (processes.Length <= 0 || (processes[0].MainWindowHandle == IntPtr.Zero)) @@ -190,7 +196,7 @@ namespace CMS_Client.View //Show the Main Window & Hide the Others (Only Siemens) ShowWindow(ncprocess.MainWindowHandle, WS_SHOW); - if (IsNcSiemens) + if (Config.VendorHmiConfig.Type == 2) { //Wait 500 ms of Siemens software Thread.Sleep(500); @@ -204,6 +210,8 @@ namespace CMS_Client.View SetNcIcon(Resources.SinumerikHmi); } + //Wait until window title become correct + //Remove the Frame Border style = GetWindowLong(ncprocess.MainWindowHandle, GWL_STYLE); SetWindowLong(ncprocess.MainWindowHandle, GWL_STYLE, (style & ~WS_CAPTION & ~WS_THICKFRAME)); @@ -224,7 +232,7 @@ namespace CMS_Client.View StopNcFollowing(); //If the NC is Siemens Exit from Function and lets the HMI to continue his life - if (IsNcSiemens) + if (Config.VendorHmiConfig.Type == 2) { HideNcWindow(); return; @@ -258,7 +266,7 @@ namespace CMS_Client.View } //Kill Tool Process - if (IsNcSiemens) + if (Config.VendorHmiConfig.Type == 2) KillAllProcessWithName(SiemensTool2Name); } @@ -375,7 +383,7 @@ namespace CMS_Client.View GetWindowThreadProcessId(ncprocess.MainWindowHandle, out NcProcessPID); //Resize the Window - ResizeAndMoveNcWindow(HMI_WINDOW_POS_X, HMI_WINDOW_POS_Y, HMI_WINDOW_WIDTH, HMI_WINDOW_HEIGHT); + ResizeAndMoveNcWindow(ncWindowX, ncWindowY, ncWindowWidth, ncWindowHeight); //Start the Hook if (MainViewHandle != IntPtr.Zero && ncprocess.MainWindowHandle != IntPtr.Zero && MainProcessPID != 0 && NcProcessPID != 0 && windowstarted) @@ -413,7 +421,7 @@ namespace CMS_Client.View public static void StopNcFollowing() { //Un-parent the window - if (IsNcSiemens && ncprocess.MainWindowHandle != IntPtr.Zero) + if ((Config.VendorHmiConfig.Type == 2) && ncprocess.MainWindowHandle != IntPtr.Zero) SetParent(ncprocess.MainWindowHandle, IntPtr.Zero); //Detach the hook @@ -772,10 +780,20 @@ namespace CMS_Client.View } + + //Resize & Move NC Window + private static bool isWindowReady(string Title) + { + if (Config.VendorHmiConfig.Type == 1) + return (Title.Contains(HMI_WINDOW_TITLE_FANUC) && Title.Contains(Config.VendorHmiConfig.IpAddress)); + else + return true; + } + + //Setup the Path/Name of the process Method private static void SetupNcProcess() { - IsNcSiemens = false; switch (Config.VendorHmiConfig.Type) { // 0: Demo @@ -783,21 +801,32 @@ namespace CMS_Client.View { processname = DemoName; processpath = @"C:\CMS\STEP\DEMO" + DemoPath; - }; break; + ncWindowWidth = HMI_WINDOW_WIDTH_DEMO; + ncWindowHeight = HMI_WINDOW_HEIGHT_DEMO; + ncWindowX = HMI_WINDOW_POS_X_DEMO; + ncWindowY = HMI_WINDOW_POS_Y_DEMO; + }; break; // 1: Fanuc case 1: { processname = FanucName; processpath = getProgramFilesx86Path() + FanucPath; + ncWindowWidth = HMI_WINDOW_WIDTH_FANUC; + ncWindowHeight = HMI_WINDOW_HEIGHT_FANUC; + ncWindowX = HMI_WINDOW_POS_X_FANUC; + ncWindowY = HMI_WINDOW_POS_Y_FANUC; }; break; // 2: Siemens case 2: { - IsNcSiemens = true; processname = SiemensName; processpath = getProgramFilesx86Path() + SiemensPath; + ncWindowWidth = HMI_WINDOW_WIDTH_SIEMENS; + ncWindowHeight = HMI_WINDOW_HEIGHT_SIEMENS; + ncWindowX = HMI_WINDOW_POS_X_SIEMENS; + ncWindowY = HMI_WINDOW_POS_Y_SIEMENS; }; break; // 3: Osai @@ -805,6 +834,10 @@ namespace CMS_Client.View { processname = OsaiName; processpath = getProgramFilesx86Path() + OsaiPath; + ncWindowWidth = HMI_WINDOW_WIDTH_OSAI; + ncWindowHeight = HMI_WINDOW_HEIGHT_OSAI; + ncWindowX = HMI_WINDOW_POS_X_OSAI; + ncWindowY = HMI_WINDOW_POS_Y_OSAI; }; break; } } diff --git a/Client/View/OpeningForm.cs b/Client/View/OpeningForm.cs index 87613261..2e9205bf 100644 --- a/Client/View/OpeningForm.cs +++ b/Client/View/OpeningForm.cs @@ -208,7 +208,7 @@ namespace CMS_Client.View //Check if it's connected if (Connected) { - var jsonDefinition = new { ncVendor = "", showHMI = "" }; + var jsonDefinition = new { ncVendor = "", showHMI = "", ncIp = "", ncPort = "" }; setStatus("Connected!", ""); //Read the configuration from Server @@ -222,8 +222,9 @@ namespace CMS_Client.View { String ncVendorName = ConfigResponse.ncVendor.ToUpper(); String ncVendorHMI = ConfigResponse.showHMI.ToUpper(); - - + Config.VendorHmiConfig.IpAddress = ConfigResponse.ncIp.ToUpper(); + Config.VendorHmiConfig.Port = ConfigResponse.ncPort.ToUpper(); + //Read the Server Type if (ncVendorName.Equals("DEMO")) Config.VendorHmiConfig.Type = 0; diff --git a/Step/wwwroot/assets/styles/base/nc.less b/Step/wwwroot/assets/styles/base/nc.less index 02d98ac5..664e9046 100644 --- a/Step/wwwroot/assets/styles/base/nc.less +++ b/Step/wwwroot/assets/styles/base/nc.less @@ -19,6 +19,15 @@ border: none; } +#nc-hmi-img-fanuc{ + position: absolute; + top: 22px; + left: 40px; + height: 740px; + width: 960px; + border: none; +} + #nc-softkeys-container{ position: absolute; bottom: 48px; diff --git a/Step/wwwroot/assets/styles/style.css b/Step/wwwroot/assets/styles/style.css index accb4dc1..19c9df4c 100644 --- a/Step/wwwroot/assets/styles/style.css +++ b/Step/wwwroot/assets/styles/style.css @@ -1244,6 +1244,14 @@ footer .container button:not([disabled]).big:before { width: 1024px; border: none; } +#nc-hmi-img-fanuc { + position: absolute; + top: 22px; + left: 40px; + height: 740px; + width: 960px; + border: none; +} #nc-softkeys-container { position: absolute; bottom: 48px; diff --git a/Step/wwwroot/src/App.vue b/Step/wwwroot/src/App.vue index 91db8e80..ec8e2bf2 100644 --- a/Step/wwwroot/src/App.vue +++ b/Step/wwwroot/src/App.vue @@ -7,7 +7,7 @@
- +