优化内存随着拍照不断增加的问题

master
lhiven 1 year ago
parent 7e22473be9
commit 6ff5229e2d

@ -18,7 +18,10 @@ namespace Rs.MotionPlat.Commom
public class MatchResult public class MatchResult
{ {
bool _disposed = false;
public MatchResult(HTuple modelParm) { public MatchResult(HTuple modelParm) {
HOperatorSet.GenEmptyObj(out _Himage);
_Himage.Dispose();
ModelParam=modelParm; ModelParam=modelParm;
if(ModelParam != null ) if(ModelParam != null )
{ {
@ -29,9 +32,26 @@ namespace Rs.MotionPlat.Commom
} }
} }
~MatchResult()
{
if(_Himage!=null)
{
_Himage.Dispose();
_Himage = null;
}
}
public MatchResult() { } public MatchResult() { }
public HObject Himage { get; set; }
private HObject _Himage;
public HObject Himage
{
get { return _Himage; }
set { _Himage = value; }
}
public HTuple ModelParam { get; set; } public HTuple ModelParam { get; set; }
public double ModelRow { get; set; } = 0.0; public double ModelRow { get; set; } = 0.0;
public double ModelCol { get; set; } = 0.0; public double ModelCol { get; set; } = 0.0;
@ -141,13 +161,17 @@ namespace Rs.MotionPlat.Commom
List<MatchResult > matches = new List<MatchResult>(); List<MatchResult > matches = new List<MatchResult>();
foreach (var image in images) foreach (var image in images)
{ {
hImage = image;
HObject hratImage = new HObject();
if(image==null) if(image==null)
continue; continue;
if(needRotate) if(needRotate)
{ {
HOperatorSet.RotateImage(image, out hImage, SysConfigParam.GetValue<double>("DownLocationCameraRotate"), "constant"); HOperatorSet.RotateImage(image, out hImage, SysConfigParam.GetValue<double>("DownLocationCameraRotate"), "constant");
image.Dispose();
}
else
{
hImage = image.Clone();
image.Dispose();
} }
if (downCamSearchRegion.IsInitialized()) if (downCamSearchRegion.IsInitialized())
{ {
@ -184,12 +208,12 @@ namespace Rs.MotionPlat.Commom
if (mr.ScanOK) if (mr.ScanOK)
{ {
mr.IsOK = true; mr.IsOK = true;
HOperatorSet.WriteImage(hImage, "bmp", 0, $"{dirname}//{mr.SN.Replace("\\", "").Replace("\"", "") + "_" + DateTime.Now.ToString("yyyyMMddHHmmssfff")}"); //HOperatorSet.WriteImage(hImage, "bmp", 0, $"{dirname}//{mr.SN.Replace("\\", "").Replace("\"", "") + "_" + DateTime.Now.ToString("yyyyMMddHHmmssfff")}");
} }
else else
{ {
HOperatorSet.WriteImage(hImage, "bmp", 0, $"{dirname}//{DateTime.Now.ToString("yyyyMMddHHmmssfff")}"); //HOperatorSet.WriteImage(hImage, "bmp", 0, $"{dirname}//{DateTime.Now.ToString("yyyyMMddHHmmssfff")}");
} }
} }

@ -1,4 +1,5 @@
using HalconDotNet; using HalconDotNet;
using Rs.Framework;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
@ -12,7 +13,28 @@ namespace Rs.MotionPlat.Flow.Camera
/// </summary> /// </summary>
public class VisionResult public class VisionResult
{ {
public HObject SourceImage { get; set; } public VisionResult() {
HOperatorSet.GenEmptyObj(out _SourceImage);
_SourceImage.Dispose();
}
~VisionResult()
{
if(_SourceImage != null)
{
_SourceImage.Dispose();
_SourceImage = null;
}
}
bool _disposed = false;
private HObject _SourceImage;
public HObject SourceImage
{
get { return _SourceImage; }
set { _SourceImage = value; }
}
/// <summary> /// <summary>
/// 是否找到模板 /// 是否找到模板
/// </summary> /// </summary>
@ -40,5 +62,6 @@ namespace Rs.MotionPlat.Flow.Camera
public string SN { get; set; } public string SN { get; set; }
public int SlotIndex { get; set; } public int SlotIndex { get; set; }
} }
} }

@ -231,6 +231,7 @@ namespace Rs.MotionPlat.Flow
} }
else else
{ {
//endInputClicked = true;
//结束上料 //结束上料
TestCenter.Instance.EndInput(); TestCenter.Instance.EndInput();
LoadAndUnloadTask.Instance.ClearUndoTask(); LoadAndUnloadTask.Instance.ClearUndoTask();
@ -841,6 +842,11 @@ namespace Rs.MotionPlat.Flow
} }
break; break;
case EDischargeFlowStep.: case EDischargeFlowStep.:
if (mrs != null && mrs.Count > 0)
{
mrs.Clear();
GC.Collect();
}
mrs = VisionProcess.Instance.MatchDownCam(imgs); mrs = VisionProcess.Instance.MatchDownCam(imgs);
if (mrs != null && mrs.Count == imgs.Length && (mrs.Where(m=>m.IsOK==true).Count()==imgs.Length || GlobalVar.DownCameraFlyRegrabNum==0)) if (mrs != null && mrs.Count == imgs.Length && (mrs.Where(m=>m.IsOK==true).Count()==imgs.Length || GlobalVar.DownCameraFlyRegrabNum==0))
{ {
@ -1653,6 +1659,20 @@ namespace Rs.MotionPlat.Flow
} }
else else
{ {
//release memory
//foreach (var item in mrs)
//{
// item.Dispose();
//}
//mrs.Clear();
if(mrs!=null&&mrs.Count>0)
{
Array.Clear(imgs, 0, imgs.Length);
mrs.Clear();
GC.Collect();
}
//GC.Collect();
if(curNozzle.ToType== TurnoverType.Turnover) if(curNozzle.ToType== TurnoverType.Turnover)
{ {
ScanBarCode(); ScanBarCode();
@ -1718,47 +1738,52 @@ namespace Rs.MotionPlat.Flow
} }
else else
{ {
//这里检测到料盘种已经没有产品了,需要切盘 //if(!endInputClicked)
bool skip = false;
while (!skip)
{ {
if (Ops.IsOff("2号料仓缺盘光电检测")) //这里检测到料盘种已经没有产品了,需要切盘
bool skip = false;
while (!skip)
{ {
logInfo = "Input料仓最后一盘料请确认是否继续上料?"; if (Ops.IsOn("2号料仓缺盘光电检测"))
msgBox = MsgBox.ShowDialog(111, logInfo, (ETipButton.Yes | ETipButton.No), new Dictionary<ETipButton, string>() { { ETipButton.Yes, "是|Yes" }, { ETipButton.No, "结束上料|EndInput" } });
if (msgBox.Button == ETipButton.Yes)
{ {
//flowStep = EDischargeFlowStep.到取料位上方; logInfo = GetClassName() + $"{curTask.FromType.ToString()}盘无料,准备切换料盘";
MessageQueue.Instance.Insert(logInfo);
TakeTrayFlow.Instance.Take(ETrayType.Input, ETrayType.Empty1,
() =>
{
Task.Run(() =>
{
StockManager.Instance.GetStock(ETrayType.Input).Load(EStockTrayLoadMode.Whole, null);
});
}, null,
() =>
{
Task.Run(() =>
{
StockManager.Instance.GetStock(ETrayType.Empty1).Unload(EStockTrayUnLoadMode.Whole, null);
});
});
StockManager.Instance.GetStock(ETrayType.Input).WaitFinished();
skip = true;
//logInfo = "Input料仓最后一盘料请确认是否继续上料?";
//msgBox = MsgBox.ShowDialog(111, logInfo, (ETipButton.Yes | ETipButton.No), new Dictionary<ETipButton, string>() { { ETipButton.Yes, "是|Yes" }, { ETipButton.No, "结束上料|EndInput" } });
//if (msgBox.Button == ETipButton.Yes)
//{
// //flowStep = EDischargeFlowStep.到取料位上方;
//}
//else
//{
// //结束上料
// endInputClicked = true;
// TestCenter.Instance.EndInput();
// skip = true;
//}
} }
else else
{ {
//结束上料
TestCenter.Instance.EndInput();
skip = true;
} }
} }
else
{
logInfo = GetClassName() + $"{curTask.FromType.ToString()}盘无料,准备切换料盘";
MessageQueue.Instance.Insert(logInfo);
TakeTrayFlow.Instance.Take(ETrayType.Input, ETrayType.Empty1,
() =>
{
Task.Run(() =>
{
StockManager.Instance.GetStock(ETrayType.Input).Load(EStockTrayLoadMode.Whole, null);
});
}, null,
() =>
{
Task.Run(() =>
{
StockManager.Instance.GetStock(ETrayType.Empty1).Unload(EStockTrayUnLoadMode.Whole, null);
});
});
StockManager.Instance.GetStock(ETrayType.Input).WaitFinished();
skip = true;
}
} }
flowStep = EDischargeFlowStep.; flowStep = EDischargeFlowStep.;
} }
@ -1844,8 +1869,8 @@ namespace Rs.MotionPlat.Flow
//找拍照起点和终点 //找拍照起点和终点
SlotPoint grabStartPoint = TrayPointManager.GetSlotPoint(ETrayType.Turnover, 1); SlotPoint grabStartPoint = TrayPointManager.GetSlotPoint(ETrayType.Turnover, 1);
SlotPoint grabEndPoint = TrayPointManager.GetSlotPoint(ETrayType.Turnover, 8); SlotPoint grabEndPoint = TrayPointManager.GetSlotPoint(ETrayType.Turnover, 8);
UpCameraScanBarCodeFlow.Instance.ScanMulti(1, false); List<VisionResult> result = UpCameraScanBarCodeFlow.Instance.ScanMulti(1, false);
List<VisionResult> result = UpCameraScanBarCodeFlow.Instance.Wait(); //List<VisionResult> result = UpCameraScanBarCodeFlow.Instance.Wait();
foreach (var vr in result) foreach (var vr in result)
{ {
if (TurnoverTrayManager.Instance.Slot(vr.SlotIndex).IsHasProduct) if (TurnoverTrayManager.Instance.Slot(vr.SlotIndex).IsHasProduct)
@ -1892,6 +1917,11 @@ namespace Rs.MotionPlat.Flow
//LoadAndUnloadTask.Instance.CopyBarcodeToTask(vr.SlotIndex - 1, ""); //LoadAndUnloadTask.Instance.CopyBarcodeToTask(vr.SlotIndex - 1, "");
Thread.Sleep(1000); Thread.Sleep(1000);
} }
if(vrsigle != null)
{
vrsigle=null;
GC.Collect();
}
} }
else else
{ {
@ -1924,6 +1954,12 @@ namespace Rs.MotionPlat.Flow
{ {
OnShowGrabResult?.Invoke(vr, false); OnShowGrabResult?.Invoke(vr, false);
} }
//vr.Dispose();
}
if (result != null && result.Count > 0)
{
result.Clear();
GC.Collect();
} }
//OnUpCameraGrabResult?.Invoke(result); //OnUpCameraGrabResult?.Invoke(result);
} }
@ -1933,8 +1969,8 @@ namespace Rs.MotionPlat.Flow
//找拍照起点和终点 //找拍照起点和终点
SlotPoint grabStartPoint = TrayPointManager.GetSlotPoint(ETrayType.Turnover, 17); SlotPoint grabStartPoint = TrayPointManager.GetSlotPoint(ETrayType.Turnover, 17);
SlotPoint grabEndPoint = TrayPointManager.GetSlotPoint(ETrayType.Turnover, 24); SlotPoint grabEndPoint = TrayPointManager.GetSlotPoint(ETrayType.Turnover, 24);
UpCameraScanBarCodeFlow.Instance.ScanMulti(24, true); List<VisionResult> result = UpCameraScanBarCodeFlow.Instance.ScanMulti(24, true);
List<VisionResult> result = UpCameraScanBarCodeFlow.Instance.Wait(); // List<VisionResult> result = UpCameraScanBarCodeFlow.Instance.Wait();
foreach (var vr in result) foreach (var vr in result)
{ {
if (TurnoverTrayManager.Instance.Slot(vr.SlotIndex).IsHasProduct) if (TurnoverTrayManager.Instance.Slot(vr.SlotIndex).IsHasProduct)
@ -1983,6 +2019,11 @@ namespace Rs.MotionPlat.Flow
//LoadAndUnloadTask.Instance.CopyBarcodeToTask(vr.SlotIndex - 1, ""); //LoadAndUnloadTask.Instance.CopyBarcodeToTask(vr.SlotIndex - 1, "");
Thread.Sleep(1000); Thread.Sleep(1000);
} }
if(vrsigle != null)
{
vrsigle = null;
GC.Collect();
}
} }
else else
{ {
@ -2014,6 +2055,12 @@ namespace Rs.MotionPlat.Flow
{ {
OnShowGrabResult?.Invoke(vr, false); OnShowGrabResult?.Invoke(vr, false);
} }
//vr.Dispose();
}
if (result != null && result.Count > 0)
{
result.Clear();
GC.Collect();
} }
//OnUpCameraGrabResult?.Invoke(result); //OnUpCameraGrabResult?.Invoke(result);

@ -265,7 +265,7 @@ namespace Rs.MotionPlat.Flow
} }
break; break;
case ETakeTrayFlowStep.: case ETakeTrayFlowStep.:
if (DischargeFlow.Instance.XYCanGoTurnoverTray()) if (DischargeFlow.Instance.XYCanGoLocalArea())
{ {
//if(GlobalVar.RunSpace) //if(GlobalVar.RunSpace)
//{ //{

@ -60,7 +60,7 @@ namespace Rs.MotionPlat.Flow.SubFlow
HObject[] grabImages= null; HObject[] grabImages= null;
Stopwatch timeout = new Stopwatch(); Stopwatch timeout = new Stopwatch();
string logInfo = string.Empty; string logInfo = string.Empty;
List<VisionResult> vReslutList = new List<VisionResult>();
VisionResult singleResult; VisionResult singleResult;
bool exit = true; bool exit = true;
ManualResetEvent grabFinishedEvent = new ManualResetEvent(true); ManualResetEvent grabFinishedEvent = new ManualResetEvent(true);
@ -71,16 +71,17 @@ namespace Rs.MotionPlat.Flow.SubFlow
/// <param name="startPoint">拍照起始点</param> /// <param name="startPoint">拍照起始点</param>
/// <param name="endPoint">拍照终止点</param> /// <param name="endPoint">拍照终止点</param>
/// <param name="isReverse">是否反转拍照</param> /// <param name="isReverse">是否反转拍照</param>
public void ScanMulti(int startSlotIndex,bool isReverse) public List<VisionResult> ScanMulti(int startSlotIndex,bool isReverse)
{ {
if(exit==false) return; List<VisionResult> vReslutList = new List<VisionResult>();
if (exit == false) return null;
grabFinishedEvent.Reset(); grabFinishedEvent.Reset();
SlotPoint startPoint = TrayPointManager.GetSlotPoint(ETrayType.Turnover, startSlotIndex); SlotPoint startPoint = TrayPointManager.GetSlotPoint(ETrayType.Turnover, startSlotIndex);
SlotPoint endPoint = new SlotPoint(); SlotPoint endPoint = new SlotPoint();
exit = false; exit = false;
step = EUpCameraScanBarCodeFlowStep.; step = EUpCameraScanBarCodeFlowStep.;
Task.Run(() => { //Task.Run(() => {
while (!exit) while (!exit)
{ {
if (MachineManage.Instance.MachineStatus == EMachineStatus.Stop) if (MachineManage.Instance.MachineStatus == EMachineStatus.Stop)
@ -228,6 +229,7 @@ namespace Rs.MotionPlat.Flow.SubFlow
break; break;
case EUpCameraScanBarCodeFlowStep.: case EUpCameraScanBarCodeFlowStep.:
vReslutList.Clear(); vReslutList.Clear();
GC.Collect();
int slotIndex = 0; int slotIndex = 0;
foreach (var img in grabImages) foreach (var img in grabImages)
{ {
@ -254,9 +256,9 @@ namespace Rs.MotionPlat.Flow.SubFlow
break; break;
} }
} }
}); // });
return vReslutList;
} }
@ -351,11 +353,11 @@ namespace Rs.MotionPlat.Flow.SubFlow
{ {
return "UpCameraScanBarCodeFlow-"; return "UpCameraScanBarCodeFlow-";
} }
public List<VisionResult> Wait() //public List<VisionResult> Wait()
{ //{
grabFinishedEvent.WaitOne(); // grabFinishedEvent.WaitOne();
return vReslutList; // return vReslutList;
} //}
public VisionResult WaitSingle() public VisionResult WaitSingle()
{ {

@ -63,13 +63,15 @@ namespace Rs.MotionPlat
{ {
hwin.ClearWindow(); hwin.ClearWindow();
hwin.HobjectToHimage(matchResult.Himage); hwin.HobjectToHimage(matchResult.Himage);
if(matchResult.IsOK) if (matchResult.IsOK)
{ {
hwin.DispObj(matchResult.ContourXld, "green"); hwin.DispObj(matchResult.ContourXld, "green");
HalconTool.DispMessage(hwin.hWindowControl.HalconWindow, matchResult.SN,20,20,"green"); string OffsetCol = matchResult.OffsetCol.ToString("0.000");
HalconTool.DispMessage(hwin.hWindowControl.HalconWindow, $"X:{matchResult.OffsetCol.ToString("0.000")}", 200, 20, "green"); string OffsetRow = matchResult.OffsetRow.ToString("0.000");
HalconTool.DispMessage(hwin.hWindowControl.HalconWindow, $"Y:{matchResult.OffsetRow.ToString("0.000")}", 400, 20, "green"); string OffsetA = matchResult.OffsetA.ToString("0.000");
HalconTool.DispMessage(hwin.hWindowControl.HalconWindow, $"R:{matchResult.OffsetA.ToString("0.000")}", 600, 20, "green"); HalconTool.DispMessage(hwin.hWindowControl.HalconWindow, $"X:{OffsetCol}", 200, 20, "green");
HalconTool.DispMessage(hwin.hWindowControl.HalconWindow, $"Y:{OffsetRow}", 400, 20, "green");
HalconTool.DispMessage(hwin.hWindowControl.HalconWindow, $"R:{OffsetA}", 600, 20, "green");
} }
else else
{ {
@ -280,17 +282,17 @@ namespace Rs.MotionPlat
hWindow_Final3.HobjectToHimage(arg1.SourceImage); hWindow_Final3.HobjectToHimage(arg1.SourceImage);
if(isOK) if(isOK)
{ {
HalconTool.DispMessage(hWindow_Final3.hWindowControl.HalconWindow, isOK ? "OK" : "NG", 20, 20, "green"); //HalconTool.DispMessage(hWindow_Final3.hWindowControl.HalconWindow, isOK ? "OK" : "NG", 20, 20, "green");
HalconTool.DispMessage(hWindow_Final3.hWindowControl.HalconWindow, $"X:{arg1.OffsetX.ToString("0.000")}", 200, 20, "green"); //HalconTool.DispMessage(hWindow_Final3.hWindowControl.HalconWindow, $"X:{arg1.OffsetX.ToString("0.000")}", 200, 20, "green");
HalconTool.DispMessage(hWindow_Final3.hWindowControl.HalconWindow, $"Y:{arg1.OffsetY.ToString("0.000")}", 400, 20, "green"); //HalconTool.DispMessage(hWindow_Final3.hWindowControl.HalconWindow, $"Y:{arg1.OffsetY.ToString("0.000")}", 400, 20, "green");
HalconTool.DispMessage(hWindow_Final3.hWindowControl.HalconWindow, $"R:{arg1.OffsetR.ToString("0.000")}", 600, 20, "green"); //HalconTool.DispMessage(hWindow_Final3.hWindowControl.HalconWindow, $"R:{arg1.OffsetR.ToString("0.000")}", 600, 20, "green");
} }
else else
{ {
HalconTool.DispMessage(hWindow_Final3.hWindowControl.HalconWindow, isOK ? "OK" : "NG", 20, 20, "red"); //HalconTool.DispMessage(hWindow_Final3.hWindowControl.HalconWindow, isOK ? "OK" : "NG", 20, 20, "red");
HalconTool.DispMessage(hWindow_Final3.hWindowControl.HalconWindow, $"X:{arg1.OffsetX.ToString("0.000")}", 200, 20, "red"); //HalconTool.DispMessage(hWindow_Final3.hWindowControl.HalconWindow, $"X:{arg1.OffsetX.ToString("0.000")}", 200, 20, "red");
HalconTool.DispMessage(hWindow_Final3.hWindowControl.HalconWindow, $"Y:{arg1.OffsetY.ToString("0.000")}", 400, 20, "red"); //HalconTool.DispMessage(hWindow_Final3.hWindowControl.HalconWindow, $"Y:{arg1.OffsetY.ToString("0.000")}", 400, 20, "red");
HalconTool.DispMessage(hWindow_Final3.hWindowControl.HalconWindow, $"R:{arg1.OffsetR.ToString("0.000")}", 600, 20, "red"); //HalconTool.DispMessage(hWindow_Final3.hWindowControl.HalconWindow, $"R:{arg1.OffsetR.ToString("0.000")}", 600, 20, "red");
} }
} }
} }
@ -303,11 +305,11 @@ namespace Rs.MotionPlat
hwin_turnoverTrayHasOrNot.HobjectToHimage(obj.SourceImage); hwin_turnoverTrayHasOrNot.HobjectToHimage(obj.SourceImage);
if(obj.HasProduct) if(obj.HasProduct)
{ {
hwin_turnoverTrayHasOrNot.DispObj(obj.SearchRegion,"green"); //h//win_turnoverTrayHasOrNot.DispObj(obj.SearchRegion,"green");
} }
else else
{ {
hwin_turnoverTrayHasOrNot.DispObj(obj.SearchRegion,"red"); //hwin_turnoverTrayHasOrNot.DispObj(obj.SearchRegion,"red");
} }
} }
} }
@ -320,18 +322,17 @@ namespace Rs.MotionPlat
hWindow_Final4.HobjectToHimage(obj.SourceImage); hWindow_Final4.HobjectToHimage(obj.SourceImage);
if(obj.HasProduct) if(obj.HasProduct)
{ {
hWindow_Final4.DispObj(obj.SearchRegion,"green"); //hWindow_Final4.DispObj(obj.SearchRegion,"green");
} }
else else
{ {
hWindow_Final4.DispObj(obj.SearchRegion,"red"); //hWindow_Final4.DispObj(obj.SearchRegion,"red");
} }
} }
} }
private void Instance_OnShowGrabResult(VisionResult matchResult, bool arg2) private void Instance_OnShowGrabResult(VisionResult matchResult, bool arg2)
{ {
HWindow_Final hwin = null; HWindow_Final hwin = null;
switch (matchResult.SlotIndex) switch (matchResult.SlotIndex)
{ {
@ -377,11 +378,9 @@ namespace Rs.MotionPlat
{ {
if (matchResult.ScanBarCodeOK) if (matchResult.ScanBarCodeOK)
{ {
string SN = matchResult.SN;
hwin.HobjectToHimage(matchResult.SourceImage); hwin.HobjectToHimage(matchResult.SourceImage);
HalconTool.DispMessage(hwin.hWindowControl.HalconWindow, $"sn:{matchResult.SN}", 20, 20, "green"); HalconTool.DispMessage(hwin.hWindowControl.HalconWindow, $"sn:{SN}", 20, 20, "green");
//HalconTool.DispMessage(hwin.hWindowControl.HalconWindow, $"x:{matchResult.OffsetX}", 200, 20, "green");
//HalconTool.DispMessage(hwin.hWindowControl.HalconWindow, $"y:{matchResult.OffsetY}", 400, 20, "green");
//HalconTool.DispMessage(hwin.hWindowControl.HalconWindow, $"r:{matchResult.OffsetR}", 600, 20, "green");
} }
else else
{ {

@ -18,6 +18,8 @@ using Rs.MotionPlat.Commom;
using static System.Runtime.CompilerServices.RuntimeHelpers; using static System.Runtime.CompilerServices.RuntimeHelpers;
using Rs.Motion.GugaoPulse; using Rs.Motion.GugaoPulse;
using Rs.MotionPlat.SysConfig; using Rs.MotionPlat.SysConfig;
using System.Runtime.InteropServices;
using System.Diagnostics;
namespace Rs.MotionPlat namespace Rs.MotionPlat
{ {
@ -238,6 +240,7 @@ namespace Rs.MotionPlat
private void timer1_Tick(object sender, EventArgs e) private void timer1_Tick(object sender, EventArgs e)
{ {
GC.Collect();
if(MachineManage.Instance.MachineStatus.ToString()!=lblMachineState.Text) if(MachineManage.Instance.MachineStatus.ToString()!=lblMachineState.Text)
lblMachineState.Text=MachineManage.Instance.MachineStatus.ToString(); lblMachineState.Text=MachineManage.Instance.MachineStatus.ToString();
if(MachineManage.Instance.GetLoadUnloadStatus().ToString() != lblRunState.Text.Replace("RunState:","")) if(MachineManage.Instance.GetLoadUnloadStatus().ToString() != lblRunState.Text.Replace("RunState:",""))
@ -254,6 +257,13 @@ namespace Rs.MotionPlat
if (TurnoverFlow.Instance.GetStep().ToString() != lblTurnoverFlow.Text.Replace("Turnover:", "")) if (TurnoverFlow.Instance.GetStep().ToString() != lblTurnoverFlow.Text.Replace("Turnover:", ""))
lblTurnoverFlow.Text = "Turnover:" + TurnoverFlow.Instance.GetStep().ToString(); lblTurnoverFlow.Text = "Turnover:" + TurnoverFlow.Instance.GetStep().ToString();
} }
Process proc = Process.GetCurrentProcess();
if (proc != null)
{
long userdMem = proc.PrivateMemorySize64;
lblMemory.Text = $"Mem:{(userdMem/1024)/1024} MB";
}
} }
public override bool WindowsClose() public override bool WindowsClose()
@ -269,5 +279,27 @@ namespace Rs.MotionPlat
return false; return false;
} }
} }
#region 内存回收
[DllImport("kernel32.dll", EntryPoint = "SetProcessWorkingSetSize")]
public static extern int SetProcessWorkingSetSize(IntPtr process, int minSize, int maxSize);
/// <summary>
/// 释放内存
/// </summary>
public static void ClearMemory()
{
GC.Collect();
GC.WaitForPendingFinalizers();
if (Environment.OSVersion.Platform == PlatformID.Win32NT)
{
SetProcessWorkingSetSize(System.Diagnostics.Process.GetCurrentProcess().Handle, -1, -1);
}
}
#endregion
private void timer2_Tick(object sender, EventArgs e)
{
//ClearMemory();
}
} }
} }

@ -55,6 +55,7 @@
this.panel2 = new System.Windows.Forms.Panel(); this.panel2 = new System.Windows.Forms.Panel();
this.lblVersion = new System.Windows.Forms.Label(); this.lblVersion = new System.Windows.Forms.Label();
this.timer1 = new System.Windows.Forms.Timer(this.components); this.timer1 = new System.Windows.Forms.Timer(this.components);
this.timer2 = new System.Windows.Forms.Timer(this.components);
this.tableLayoutPanel2.SuspendLayout(); this.tableLayoutPanel2.SuspendLayout();
this.panel1.SuspendLayout(); this.panel1.SuspendLayout();
this.panel5.SuspendLayout(); this.panel5.SuspendLayout();
@ -451,6 +452,12 @@
this.timer1.Interval = 300; this.timer1.Interval = 300;
this.timer1.Tick += new System.EventHandler(this.timer1_Tick); this.timer1.Tick += new System.EventHandler(this.timer1_Tick);
// //
// timer2
//
this.timer2.Enabled = true;
this.timer2.Interval = 60000;
this.timer2.Tick += new System.EventHandler(this.timer2_Tick);
//
// Home // Home
// //
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F); this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
@ -508,5 +515,6 @@
private System.Windows.Forms.Label lblDischargeFlow; private System.Windows.Forms.Label lblDischargeFlow;
private System.Windows.Forms.Panel panel5; private System.Windows.Forms.Panel panel5;
private System.Windows.Forms.Label lblMemory; private System.Windows.Forms.Label lblMemory;
private System.Windows.Forms.Timer timer2;
} }
} }

@ -120,4 +120,7 @@
<metadata name="timer1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"> <metadata name="timer1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value> <value>17, 17</value>
</metadata> </metadata>
<metadata name="timer2.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>107, 17</value>
</metadata>
</root> </root>

@ -31,6 +31,6 @@ using System.Runtime.InteropServices;
// //
//可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值 //可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值
//通过使用 "*",如下所示: //通过使用 "*",如下所示:
[assembly: AssemblyVersion("1.0.0")] [assembly: AssemblyVersion("2.20.24.1")]
//[assembly: AssemblyVersion("1.0.0.0")] //[assembly: AssemblyVersion("1.0.0.0")]
//[assembly: AssemblyFileVersion("1.0.0.0")] //[assembly: AssemblyFileVersion("1.0.0.0")]

Loading…
Cancel
Save