Merge branch 'develop' of https://bitbucket.org/ncarminati/cms_step into develop

This commit is contained in:
Alessandro Francia
2018-04-20 16:57:58 +02:00
2 changed files with 86 additions and 36 deletions
+19 -1
View File
@@ -48,6 +48,8 @@ namespace CMS_Client.Browser_Tools
AddFunction("startNewProcess").Execute += startNewProcess;
AddFunction("openOrStartProcess").Execute += openOrStartProcess;
AddFunction("isVirtualKeybConfigured").Execute += isVirtualKeybConfigured;
AddFunction("sendHMICommand").Execute += sendHMICommand;
AddFunction("getHMICommandCount").Execute += getHMICommandCount;
}
#endregion
@@ -136,6 +138,22 @@ namespace CMS_Client.Browser_Tools
NcWindow.CaptureHMI();
e.SetReturnValue(NcWindow.NcCapture);
}
//Send a command to HMI
public void sendHMICommand(object sender, CfrV8HandlerExecuteEventArgs e)
{
if (e.Arguments.Count() == 0 || e.Arguments[0].IntValue < 0 || e.Arguments[0].IntValue > (NcWindow.NcWindowCommand.Count - 1))
return;
NcWindow.SendCommandKey(NcWindow.NcWindowCommand[e.Arguments[0].IntValue]);
}
//Get command vounts to HMI
public void getHMICommandCount(object sender, CfrV8HandlerExecuteEventArgs e)
{
e.SetReturnValue(NcWindow.NcWindowCommand.Count);
}
#endregion
@@ -146,7 +164,7 @@ namespace CMS_Client.Browser_Tools
public void getChromiumVersion(object sender, CfrV8HandlerExecuteEventArgs e)
{
e.SetReturnValue(CfxRuntime.GetChromeVersion());
}
}
#endregion
+67 -35
View File
@@ -52,6 +52,8 @@ namespace CMS_Client.View
private static Process ncprocess;
public static String NcCapture { get { return ncCapture; } }
private static String ncCapture;
public static List<String> NcWindowCommand { get { return ncWindowCommand; } }
private static List<String> ncWindowCommand;
private static int LastX, LastY;
private static int LastWidth = 1024, LastHeight = 768;
@@ -474,6 +476,54 @@ namespace CMS_Client.View
}
//Take screenshot of the Nc Window
public static void CaptureHMI()
{
RECT rc = new RECT();
Graphics gr;
bool success = false;
Bitmap bmp;
MemoryStream m = new MemoryStream();
Thread.BeginThreadAffinity();
m = new MemoryStream();
String Base64Capture;
if (ncprocess != null && ncprocess.MainWindowHandle != IntPtr.Zero)
{
GetWindowRect(ncprocess.MainWindowHandle, out rc);
bmp = new Bitmap(rc.Right - rc.Left, rc.Bottom - rc.Top);
gr = Graphics.FromImage(bmp);
success = PrintWindow(ncprocess.MainWindowHandle, gr.GetHdc(), 0);
gr.ReleaseHdc();
if (success && bmp != null)
{
bmp.Save(m, ImageFormat.Png);
Base64Capture = Convert.ToBase64String(m.ToArray());
ncCapture = "data:image/png;base64," + Base64Capture;
}
m.Dispose();
bmp.Dispose();
gr.Dispose();
}
else
ncCapture = "data:image/png;base64,";
}
//Send command to Nc window
public static void SendCommandKey(String CMD)
{
if(String.IsNullOrWhiteSpace(CMD))
return;
if (ncprocess != null && ncprocess.MainWindowHandle != IntPtr.Zero && state == NcState.SHOW)
{
SetForegroundWindow(ncprocess.MainWindowHandle);
SendKeys.SendWait(CMD);
}
}
#endregion
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -882,7 +932,14 @@ namespace CMS_Client.View
ncWindowHeight = HMI_WINDOW_HEIGHT_DEMO;
ncWindowX = HMI_WINDOW_POS_X_DEMO;
ncWindowY = HMI_WINDOW_POS_Y_DEMO;
}; break;
ncWindowCommand = new List<string>();
ncWindowCommand.Add("{F10}");
ncWindowCommand.Add("{F10}");
ncWindowCommand.Add("{F10}");
ncWindowCommand.Add("{F10}");
ncWindowCommand.Add("{F10}");
ncWindowCommand.Add("{F10}");
}; break;
// 1: Fanuc
case 1:
@@ -893,6 +950,7 @@ namespace CMS_Client.View
ncWindowHeight = HMI_WINDOW_HEIGHT_FANUC;
ncWindowX = HMI_WINDOW_POS_X_FANUC;
ncWindowY = HMI_WINDOW_POS_Y_FANUC;
ncWindowCommand = new List<string>();
}; break;
// 2: Siemens
@@ -904,6 +962,13 @@ namespace CMS_Client.View
ncWindowHeight = HMI_WINDOW_HEIGHT_SIEMENS;
ncWindowX = HMI_WINDOW_POS_X_SIEMENS;
ncWindowY = HMI_WINDOW_POS_Y_SIEMENS;
ncWindowCommand = new List<string>();
ncWindowCommand.Add("{F10}{F1}");
ncWindowCommand.Add("{F10}{F2}");
ncWindowCommand.Add("{F10}{F3}");
ncWindowCommand.Add("{F10}{F4}");
ncWindowCommand.Add("{F10}{F5}");
ncWindowCommand.Add("{F10}{F6}");
}; break;
// 3: Osai
@@ -915,6 +980,7 @@ namespace CMS_Client.View
ncWindowHeight = HMI_WINDOW_HEIGHT_OSAI;
ncWindowX = HMI_WINDOW_POS_X_OSAI;
ncWindowY = HMI_WINDOW_POS_Y_OSAI;
ncWindowCommand = new List<string>();
}; break;
}
}
@@ -994,40 +1060,6 @@ namespace CMS_Client.View
}
}
public static void CaptureHMI()
{
RECT rc = new RECT();
Graphics gr;
bool success = false;
Bitmap bmp;
MemoryStream m = new MemoryStream();
Thread.BeginThreadAffinity();
m = new MemoryStream();
String Base64Capture;
if (ncprocess != null && ncprocess.MainWindowHandle != IntPtr.Zero)
{
GetWindowRect(ncprocess.MainWindowHandle, out rc);
bmp = new Bitmap(rc.Right - rc.Left, rc.Bottom - rc.Top);
gr = Graphics.FromImage(bmp);
success = PrintWindow(ncprocess.MainWindowHandle, gr.GetHdc(), 0);
gr.ReleaseHdc();
if (success && bmp != null)
{
bmp.Save(m, ImageFormat.Png);
Base64Capture = Convert.ToBase64String(m.ToArray());
ncCapture = "data:image/png;base64," + Base64Capture;
}
m.Dispose();
bmp.Dispose();
gr.Dispose();
}
else
ncCapture = "data:image/png;base64,";
}
#endregion
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////