From c44c1b442fde596c1d20c0ad82e4d308f71ec806 Mon Sep 17 00:00:00 2001 From: xcd <834800634@qq.com> Date: 星期六, 01 八月 2020 13:55:46 +0800 Subject: [PATCH] 部分修改 --- src/Bro.M071.Process/UI/M071_MainForm.cs | 12 +++++ src/Bro.Process/Bro.Process.csproj | 10 +---- src/Bro.UI.Model.Winform/UI/CanvasImage.cs | 3 + src/Bro.Common.Model/Helper/SettingHelper.cs | 9 +++- src/Bro.M071.Process/UI/M071_MainForm.Designer.cs | 27 ++++++++----- src/Bro.M071.Process/UI/M071_MainForm.resx | 3 + src/Bro.Process/ProcessControl.cs | 12 ++++- src/Bro.Common.Model/Interface/IProcess.cs | 4 +- src/Bro.Device.HikCamera/HikCameraDriver.cs | 9 ++-- src/Bro.Common.Model/GlobalVar.cs | 10 ++++ 10 files changed, 67 insertions(+), 32 deletions(-) diff --git a/src/Bro.Common.Model/GlobalVar.cs b/src/Bro.Common.Model/GlobalVar.cs index cc555e4..d0b5310 100644 --- a/src/Bro.Common.Model/GlobalVar.cs +++ b/src/Bro.Common.Model/GlobalVar.cs @@ -6,6 +6,8 @@ { public static ContainerBuilder Builder { get; set; } = new ContainerBuilder(); + private static object containerLock = new object(); + private static IContainer container = null; public static IContainer Container { @@ -13,7 +15,13 @@ { if (container == null) { - container = Builder.Build(); + lock (containerLock) + { + if (container == null) + { + container = Builder.Build(); + } + } } return container; diff --git a/src/Bro.Common.Model/Helper/SettingHelper.cs b/src/Bro.Common.Model/Helper/SettingHelper.cs index a14100e..99f93c2 100644 --- a/src/Bro.Common.Model/Helper/SettingHelper.cs +++ b/src/Bro.Common.Model/Helper/SettingHelper.cs @@ -76,9 +76,15 @@ return codes; } - public static List<string> AddNewProductionCode(string code) + public static void AddNewProductionCode(string code) { var dataTemp = GetSettingData(); + + if (!dataTemp.ContainsKey(PROPERTY_PRODUCTIONCODES)) + { + dataTemp.Add(PROPERTY_PRODUCTIONCODES, new JArray()); + } + if (dataTemp != null && dataTemp.ContainsKey(PROPERTY_PRODUCTIONCODES)) { List<string> codes = GetProductionCodes(); @@ -96,7 +102,6 @@ writer.Close(); } } - return GetProductionCodes(); } public static string GetConfigFilePath() diff --git a/src/Bro.Common.Model/Interface/IProcess.cs b/src/Bro.Common.Model/Interface/IProcess.cs index 403375d..3a5669c 100644 --- a/src/Bro.Common.Model/Interface/IProcess.cs +++ b/src/Bro.Common.Model/Interface/IProcess.cs @@ -51,7 +51,7 @@ //event Action<string, Bitmap, string> OnBitmapOutput; event Action<DeviceState> OnProcessStateChanged; - event Action<string> OnAlarmUpdate; + event Action<string> OnAlarmUpdate; Action<DateTime, int> OnUpdateResult { get; set; } Action<float> OnUpdateCT { get; set; } @@ -59,7 +59,7 @@ #region 鏁版嵁搴撴搷浣� void SaveProcessConfig(IProcessConfig config); - void CreateNewConfig(IProcessConfig config,string newProductionCode); + void CreateNewConfig(IProcessConfig config, string newProductionCode); #endregion } } diff --git a/src/Bro.Device.HikCamera/HikCameraDriver.cs b/src/Bro.Device.HikCamera/HikCameraDriver.cs index f308873..b77232f 100644 --- a/src/Bro.Device.HikCamera/HikCameraDriver.cs +++ b/src/Bro.Device.HikCamera/HikCameraDriver.cs @@ -463,15 +463,14 @@ { if (nMsgType == MyCamera.MV_EXCEPTION_DEV_DISCONNECT) { - Thread.Sleep(1000); - - Stop(); - if (CurrentState != EnumHelper.DeviceState.DSClose) { int reTryTimes = 3; do { + Thread.Sleep(1000); + Stop(); + try { Start(); @@ -484,7 +483,7 @@ if (reTryTimes > 0) { //OnLog?.Invoke(DateTime.Now, this, "閲嶆柊杩炴帴鐩告満寮傚父\r\n" + ex.GetExceptionMessage()); - LogAsync(DateTime.Now, "閲嶆柊杩炴帴寮傚父", ex.GetExceptionMessage()); + LogAsync(DateTime.Now, $"{this.Name}閲嶆柊杩炴帴寮傚父", ex.GetExceptionMessage()); } else { diff --git a/src/Bro.M071.Process/UI/M071_MainForm.Designer.cs b/src/Bro.M071.Process/UI/M071_MainForm.Designer.cs index bbe64d2..a702101 100644 --- a/src/Bro.M071.Process/UI/M071_MainForm.Designer.cs +++ b/src/Bro.M071.Process/UI/M071_MainForm.Designer.cs @@ -33,6 +33,7 @@ this.tsmiShowToolBar = new System.Windows.Forms.ToolStripMenuItem(); this.tsmiShowStatusBar = new System.Windows.Forms.ToolStripMenuItem(); this.tsmiShowEditor = new System.Windows.Forms.ToolStripMenuItem(); + this.tsmiRefreshLabels = new System.Windows.Forms.ToolStripMenuItem(); this.btnReset = new System.Windows.Forms.Button(); this.btnStartMeasure = new System.Windows.Forms.Button(); this.lblCT = new System.Windows.Forms.Label(); @@ -48,7 +49,7 @@ this.lvMeasures = new System.Windows.Forms.ListView(); this.columnHeader1 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); this.propGridKeyIndicator = new System.Windows.Forms.PropertyGrid(); - this.tsmiRefreshLabels = new System.Windows.Forms.ToolStripMenuItem(); + this.timer1 = new System.Windows.Forms.Timer(this.components); this.contextMenuStrip1.SuspendLayout(); this.plImage.SuspendLayout(); this.tscEditLocation.ContentPanel.SuspendLayout(); @@ -68,13 +69,13 @@ this.tsmiShowEditor, this.tsmiRefreshLabels}); this.contextMenuStrip1.Name = "contextMenuStrip1"; - this.contextMenuStrip1.Size = new System.Drawing.Size(181, 114); + this.contextMenuStrip1.Size = new System.Drawing.Size(149, 92); // // tsmiShowToolBar // this.tsmiShowToolBar.CheckOnClick = true; this.tsmiShowToolBar.Name = "tsmiShowToolBar"; - this.tsmiShowToolBar.Size = new System.Drawing.Size(180, 22); + this.tsmiShowToolBar.Size = new System.Drawing.Size(148, 22); this.tsmiShowToolBar.Text = "鏄剧ず宸ュ叿鏉�"; this.tsmiShowToolBar.CheckedChanged += new System.EventHandler(this.tsmiShowToolBar_CheckedChanged); // @@ -82,7 +83,7 @@ // this.tsmiShowStatusBar.CheckOnClick = true; this.tsmiShowStatusBar.Name = "tsmiShowStatusBar"; - this.tsmiShowStatusBar.Size = new System.Drawing.Size(180, 22); + this.tsmiShowStatusBar.Size = new System.Drawing.Size(148, 22); this.tsmiShowStatusBar.Text = "鏄剧ず鐘舵�佹爮"; this.tsmiShowStatusBar.CheckedChanged += new System.EventHandler(this.tsmiShowStatusBar_CheckedChanged); // @@ -90,9 +91,16 @@ // this.tsmiShowEditor.CheckOnClick = true; this.tsmiShowEditor.Name = "tsmiShowEditor"; - this.tsmiShowEditor.Size = new System.Drawing.Size(180, 22); + this.tsmiShowEditor.Size = new System.Drawing.Size(148, 22); this.tsmiShowEditor.Text = "缂栬緫鏄剧ず鐐逛綅"; this.tsmiShowEditor.CheckedChanged += new System.EventHandler(this.tsmiShowEditor_CheckedChanged); + // + // tsmiRefreshLabels + // + this.tsmiRefreshLabels.Name = "tsmiRefreshLabels"; + this.tsmiRefreshLabels.Size = new System.Drawing.Size(148, 22); + this.tsmiRefreshLabels.Text = "鍒锋柊鏄剧ず鐐逛綅"; + this.tsmiRefreshLabels.Click += new System.EventHandler(this.tsmiRefreshLabels_Click); // // btnReset // @@ -293,12 +301,10 @@ this.propGridKeyIndicator.TabIndex = 0; this.propGridKeyIndicator.ToolbarVisible = false; // - // tsmiRefreshLabels + // timer1 // - this.tsmiRefreshLabels.Name = "tsmiRefreshLabels"; - this.tsmiRefreshLabels.Size = new System.Drawing.Size(180, 22); - this.tsmiRefreshLabels.Text = "鍒锋柊鏄剧ず鐐逛綅"; - this.tsmiRefreshLabels.Click += new System.EventHandler(this.tsmiRefreshLabels_Click); + this.timer1.Interval = 3000; + this.timer1.Tick += new System.EventHandler(this.timer1_Tick); // // M071_MainForm // @@ -353,5 +359,6 @@ private System.Windows.Forms.Button btnReset; private System.Windows.Forms.ColumnHeader columnHeader1; private System.Windows.Forms.ToolStripMenuItem tsmiRefreshLabels; + private System.Windows.Forms.Timer timer1; } } \ No newline at end of file diff --git a/src/Bro.M071.Process/UI/M071_MainForm.cs b/src/Bro.M071.Process/UI/M071_MainForm.cs index efadaed..0ed4652 100644 --- a/src/Bro.M071.Process/UI/M071_MainForm.cs +++ b/src/Bro.M071.Process/UI/M071_MainForm.cs @@ -40,6 +40,8 @@ cvImage.SetScreenSize(); cvImage.OnElementChangedHandle -= CvImage_OnElementChangedHandle; cvImage.OnElementChangedHandle += CvImage_OnElementChangedHandle; + + timer1.Enabled = true; }; } @@ -284,6 +286,10 @@ { _barcode += keyStr.ToUpper(); } + else if (keyStr.Length == 2 && keyStr.StartsWith("D")) + { + _barcode += keyStr.Substring(1).ToUpper(); + } if (e.KeyValue == 13) { @@ -337,7 +343,7 @@ btnStartMeasure.BackColor = lblMachineState.BackColor = Color.Lime; btnStartMeasure.ForeColor = lblMachineState.ForeColor = Color.Black; lblMachineState.Text = "灏辩华"; - + btnStartMeasure.Text = "寮�濮嬫祴閲�"; btnStartMeasure.Enabled = true; break; @@ -475,5 +481,9 @@ } #endregion + private void timer1_Tick(object sender, EventArgs e) + { + cvImage.Refresh(); + } } } diff --git a/src/Bro.M071.Process/UI/M071_MainForm.resx b/src/Bro.M071.Process/UI/M071_MainForm.resx index ad53752..2b01b4a 100644 --- a/src/Bro.M071.Process/UI/M071_MainForm.resx +++ b/src/Bro.M071.Process/UI/M071_MainForm.resx @@ -120,4 +120,7 @@ <metadata name="contextMenuStrip1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"> <value>17, 17</value> </metadata> + <metadata name="timer1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"> + <value>182, 17</value> + </metadata> </root> \ No newline at end of file diff --git a/src/Bro.Process/Bro.Process.csproj b/src/Bro.Process/Bro.Process.csproj index d7b408b..e56f5e8 100644 --- a/src/Bro.Process/Bro.Process.csproj +++ b/src/Bro.Process/Bro.Process.csproj @@ -128,9 +128,7 @@ </ItemGroup> <ItemGroup> <None Include="packages.config" /> - <None Include="Setting.json"> - <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> - </None> + <None Include="Setting.json" /> </ItemGroup> <ItemGroup> <EmbeddedResource Include="Forms\Calibration\FrmCalibration_9P.resx"> @@ -170,9 +168,5 @@ <Error Condition="!Exists('..\..\packages\PostSharp.6.2.7\build\PostSharp.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\..\packages\PostSharp.6.2.7\build\PostSharp.targets'))" /> </Target> <Import Project="..\..\packages\PostSharp.6.2.7\build\PostSharp.targets" Condition="Exists('..\..\packages\PostSharp.6.2.7\build\PostSharp.targets')" /> - <ProjectExtensions> - <VisualStudio> - <UserProperties setting_1json__JsonSchema="https://batect.dev/configSchema.json" /> - </VisualStudio> - </ProjectExtensions> + <ProjectExtensions /> </Project> \ No newline at end of file diff --git a/src/Bro.Process/ProcessControl.cs b/src/Bro.Process/ProcessControl.cs index ca587d2..8a4c27f 100644 --- a/src/Bro.Process/ProcessControl.cs +++ b/src/Bro.Process/ProcessControl.cs @@ -348,10 +348,16 @@ { if (config == null) throw new ProcessException("淇濆瓨鐨勯厤缃俊鎭笉鑳戒负绌�"); - ProductionCode = newProductionCode; + + string newConfigPath = Path.Combine(Path.GetDirectoryName(_configPath), $"Config_{newProductionCode}.json"); + if (File.Exists(newConfigPath)) + { + throw new ProcessException($"{newProductionCode}閰嶇疆鏂囦欢宸茬粡瀛樺湪"); + } + //鐢熸垚config.json string newConfig = JsonConvert.SerializeObject(config, new JsonSerializerSettings() { TypeNameHandling = TypeNameHandling.All }); - using (StreamWriter writer = new StreamWriter(_configPath, false, System.Text.Encoding.UTF8)) + using (StreamWriter writer = new StreamWriter(newConfigPath, false, System.Text.Encoding.UTF8)) { writer.Write(newConfig); writer.Flush(); @@ -359,7 +365,7 @@ } //娣诲姞鍒癝etting.json - SettingHelper.AddNewProductionCode(ProductionCode); + SettingHelper.AddNewProductionCode(newProductionCode); } catch (Exception ex) { diff --git a/src/Bro.UI.Model.Winform/UI/CanvasImage.cs b/src/Bro.UI.Model.Winform/UI/CanvasImage.cs index 76beeac..978e513 100644 --- a/src/Bro.UI.Model.Winform/UI/CanvasImage.cs +++ b/src/Bro.UI.Model.Winform/UI/CanvasImage.cs @@ -614,6 +614,9 @@ if (map == null) return; + MAP?.Dispose(); + MAP = null; + MAP = map; //MAP = map; -- Gitblit v1.8.0