From 305e2990bb2161177e87ab7711f9dfb205762bcd Mon Sep 17 00:00:00 2001 From: kingno <30263@KINGNO> Date: 星期一, 09 六月 2025 15:52:42 +0800 Subject: [PATCH] 优化数据传递 --- libs/PFW/Bro.Common.Model.dll | 0 libs/PFW/Bro.UI.Device.Winform.dll | 0 libs/PFW/Bro.UI.Main.dll | 0 src/Bro.M141.Process/UI/UIPrinter.cs | 271 ++++++++++++++++++++++++++ libs/PFW/Bro.Common.Device.dll | 0 src/Bro.M141.Process/M141Config.cs | 75 +++++++ src/Bro.M141.Process/M141Process.cs | 21 +- src/Bro.M141.Process/M141Process_ImageCheck.cs | 19 + src/Bro.M141.Process/UI/UIPrinter.Designer.cs | 36 +-- /dev/null | 0 libs/PFW/Bro.UI.Main.exe | 0 libs/PFW/Bro.UI.Model.Winform.dll | 0 src/Bro.M141_AOI1.Process/AOI1Process.cs | 55 +++- M135.sln | 6 src/Bro.M135.Common/ProductModel.cs | 11 + src/Bro.M141.Process/M141Process_Mysql.cs | 60 ++++- libs/Nuget/System.Drawing.Common.dll | 0 17 files changed, 467 insertions(+), 87 deletions(-) diff --git a/M135.sln b/M135.sln index 279cf14..4b7ccb2 100644 --- a/M135.sln +++ b/M135.sln @@ -3,8 +3,6 @@ # Visual Studio Version 17 VisualStudioVersion = 17.2.32526.322 MinimumVisualStudioVersion = 10.0.40219.1 -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Bro.Device.PointLaser_Omron", "src\Bro.Device.PointLaser_Omron\Bro.Device.PointLaser_Omron.csproj", "{5966DFAD-1B67-478A-BA32-ADE05500B2AA}" -EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Bro.M135.Common", "src\Bro.M135.Common\Bro.M135.Common.csproj", "{82DF4C52-A0CA-4759-A6C6-64442646E85F}" EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Bro.M141.Process", "src\Bro.M141.Process\Bro.M141.Process.csproj", "{2559EE9D-1C2F-456D-AF5D-755A79066C0F}" @@ -24,10 +22,6 @@ Release|Any CPU = Release|Any CPU EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution - {5966DFAD-1B67-478A-BA32-ADE05500B2AA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {5966DFAD-1B67-478A-BA32-ADE05500B2AA}.Debug|Any CPU.Build.0 = Debug|Any CPU - {5966DFAD-1B67-478A-BA32-ADE05500B2AA}.Release|Any CPU.ActiveCfg = Release|Any CPU - {5966DFAD-1B67-478A-BA32-ADE05500B2AA}.Release|Any CPU.Build.0 = Release|Any CPU {82DF4C52-A0CA-4759-A6C6-64442646E85F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {82DF4C52-A0CA-4759-A6C6-64442646E85F}.Debug|Any CPU.Build.0 = Debug|Any CPU {82DF4C52-A0CA-4759-A6C6-64442646E85F}.Release|Any CPU.ActiveCfg = Release|Any CPU diff --git a/libs.zip b/libs.zip deleted file mode 100644 index c2bcad3..0000000 --- a/libs.zip +++ /dev/null Binary files differ diff --git a/libs/Nuget/System.Drawing.Common.dll b/libs/Nuget/System.Drawing.Common.dll index 32bb015..5f683cb 100644 --- a/libs/Nuget/System.Drawing.Common.dll +++ b/libs/Nuget/System.Drawing.Common.dll Binary files differ diff --git a/libs/PFW/Bro.Common.Device.dll b/libs/PFW/Bro.Common.Device.dll index 39d7ee4..d6f82b1 100644 --- a/libs/PFW/Bro.Common.Device.dll +++ b/libs/PFW/Bro.Common.Device.dll Binary files differ diff --git a/libs/PFW/Bro.Common.Model.dll b/libs/PFW/Bro.Common.Model.dll index 55cfeb1..a8242f0 100644 --- a/libs/PFW/Bro.Common.Model.dll +++ b/libs/PFW/Bro.Common.Model.dll Binary files differ diff --git a/libs/PFW/Bro.UI.Device.Winform.dll b/libs/PFW/Bro.UI.Device.Winform.dll index 9c39685..b1af54b 100644 --- a/libs/PFW/Bro.UI.Device.Winform.dll +++ b/libs/PFW/Bro.UI.Device.Winform.dll Binary files differ diff --git a/libs/PFW/Bro.UI.Main.dll b/libs/PFW/Bro.UI.Main.dll index bb1675a..70c10bb 100644 --- a/libs/PFW/Bro.UI.Main.dll +++ b/libs/PFW/Bro.UI.Main.dll Binary files differ diff --git a/libs/PFW/Bro.UI.Main.exe b/libs/PFW/Bro.UI.Main.exe index 9e836ae..38bff4e 100644 --- a/libs/PFW/Bro.UI.Main.exe +++ b/libs/PFW/Bro.UI.Main.exe Binary files differ diff --git a/libs/PFW/Bro.UI.Model.Winform.dll b/libs/PFW/Bro.UI.Model.Winform.dll index f5ad904..8fde443 100644 --- a/libs/PFW/Bro.UI.Model.Winform.dll +++ b/libs/PFW/Bro.UI.Model.Winform.dll Binary files differ diff --git a/src/Bro.M135.Common/ProductModel.cs b/src/Bro.M135.Common/ProductModel.cs index dbb4c72..5bebb83 100644 --- a/src/Bro.M135.Common/ProductModel.cs +++ b/src/Bro.M135.Common/ProductModel.cs @@ -3,6 +3,7 @@ using Bro.Common.Model; using Bro.M135.DBManager; using Newtonsoft.Json; +using static System.Windows.Forms.VisualStyles.VisualStyleElement.ListView; namespace Bro.M135.Common { @@ -421,12 +422,20 @@ #endregion #region PositionCheckTimes - public void InitialPositionCheckList(string positionName, List<int> checkTimes) + public void InitialPositionCheckList(string positionName, List<int> checkTimes,string stationName) { lock (_checkResultLock) { PositionCheckList[positionName] = new List<int>(checkTimes); Details.RemoveAll(u => u.PositionName == positionName); + + + P_PRODUCT_DETAIL detail = new P_PRODUCT_DETAIL(); + detail.STATION_CODE = stationName; + detail.PositionName = positionName; + detail.PID = PID; + detail.IsDone = false; + Details.Add(detail); } } diff --git a/src/Bro.M141.Process/M141Config.cs b/src/Bro.M141.Process/M141Config.cs index d403b81..5602e23 100644 --- a/src/Bro.M141.Process/M141Config.cs +++ b/src/Bro.M141.Process/M141Config.cs @@ -26,11 +26,11 @@ public List<Printer> Printers { get; set; } = new List<Printer>(); - [Category("浜у搧鏄剧ず鐣岄潰閰嶇疆")] [Description("瀛椾綋澶у皬")] [DisplayName("瀛椾綋澶у皬")] public int FontSize_p { get; set; } = 15; + [Category("浜у搧鏄剧ず鐣岄潰閰嶇疆")] [Description("姣忚鍒楁暟")] @@ -237,16 +237,13 @@ [Editor(typeof(ComplexCollectionEditor<PLCAlarmDetails>), typeof(UITypeEditor))] public List<PLCAlarmDetails> AlarmDetails { get; set; } = new List<PLCAlarmDetails>(); - - - public string GetDisplayText() { return plcname + (isused ? "鍚敤" : "绂佺敤"); } } - public class PLCAlarmDetails : IComplexDisplay + public class PLCAlarmDetails : IComplexDisplay, IImportFromFileInEditor { [Category("閰嶇疆")] [DisplayName("棣栧湴鍧�")] @@ -271,6 +268,74 @@ { return alarmname; } + + + + public IImportFromFileInEditor GetImportObject(string data, out string msg) + { + msg = ""; + PLCAlarmDetails ret = new PLCAlarmDetails(); + try + { + var temchar = data.Split(','); + ret.alarmname = temchar[0]; + ret.address =Convert.ToInt32(temchar[1]); + ret.address2 = Convert.ToInt32(temchar[2]); + } + catch (Exception ex) + { + throw ex; + } + + return ret; + + } + + public bool ICSVOutput(object o) + { + try + { + if (o is List<PLCAlarmDetails> Pl) + { + SaveFileDialog saveFileDialog = new SaveFileDialog(); + saveFileDialog.Filter = "CSV files (*.csv)|*.csv"; // 璁剧疆鏂囦欢杩囨护鍣紝鍙樉绀篊SV鏂囦欢 + saveFileDialog.Title = "Save CSV File"; // 璁剧疆瀵硅瘽妗嗘爣棰� + saveFileDialog.FileName = "PLCAlarms"; // 榛樿鏂囦欢鍚� + saveFileDialog.DefaultExt = "csv"; // 榛樿鏂囦欢鎵╁睍鍚� + string filePath = ""; + if (saveFileDialog.ShowDialog() == DialogResult.OK) + { + filePath = saveFileDialog.FileName; // 鑾峰彇鐢ㄦ埛閫夋嫨鐨勬枃浠惰矾寰� + } + else + { + return false; + } + + using (StreamWriter writer = new StreamWriter(filePath)) + { + // 鍐欏叆鏍囬琛� + writer.WriteLine("鎶ヨ鍚嶇О,棣栧湴鍧�,瀛愬湴鍧�"); + // 鍐欏叆鏁版嵁琛� + foreach (var row in Pl) + { + writer.WriteLine($"{row.alarmname},{row.address},{row.address2}"); + } + } + } + } + catch + { + + } + return true; + } + + + + + + } diff --git a/src/Bro.M141.Process/M141Process.cs b/src/Bro.M141.Process/M141Process.cs index 2fad3d8..dc29ff2 100644 --- a/src/Bro.M141.Process/M141Process.cs +++ b/src/Bro.M141.Process/M141Process.cs @@ -45,18 +45,11 @@ public static object _productListLock = new object(); public List<ProductModel> ProductList = new List<ProductModel>(); MachineLearningBase ML = null; - TcpListenerWrap TcpListener = null; Spec _errorSpec = null; - TcpListenerWrap _realTimeServer = null; - - volatile int _productIndex = 0; - - int _backgroundImageWidth = 2448; + //volatile int _productIndex = 0; M141Process_Mysql mysqlhelper = new M141Process_Mysql(); - - public override void InitialProcessMethods() @@ -131,6 +124,9 @@ public void Heartplc() { Thread.Sleep(1000); + + //Open(); + string _statisticFilePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Statistic.json"); if (File.Exists(_statisticFilePath)) { @@ -768,7 +764,7 @@ { products.ForEach(p => { - var pResults = resultList.Where(u => u.PID == p.PID).ToList(); + var pResults = resultList.ToList(); p.AddNewDetectResults(M141Config.StationCode, measureBind.WorkPosition, pResults); LogAsync(DateTime.Now, EnumHelper.LogLevel.Action, $"浜у搧{p.PID}_{p.SEQUENCE}娣诲姞宸ヤ綅{measureBind.WorkPosition}妫�娴嬬粨鏋滐紝鏁伴噺{pResults.Count}"); }); @@ -998,6 +994,7 @@ { p.BasketCode = mysqlhelper.Getbasketcode(p.SEQUENCE, out string sntem); p.SN = sntem; + p.PID = $"{sntem}_{i}"; if ("NoRead".Equals(p.BasketCode)) { LogAsync(DateTime.Now, EnumHelper.LogLevel.Error, $"{p.PID}_{p.SEQUENCE}鑾峰彇妗嗗叿鐮佸け璐� 璧嬪�糔oread"); @@ -1032,8 +1029,9 @@ //鍒濆鍖栦骇鍝佺殑妫�娴嬫鏁� var checkIndexList = M141Config.MeasureBindCollection.Where(u => u.WorkPosition == b.WorkPosition && u.ProductIndices.Contains(i)).Select(u => u.CheckIndex).OrderBy(u => u).ToList(); - p.InitialPositionCheckList(b.WorkPosition, checkIndexList); + p.InitialPositionCheckList(b.WorkPosition, checkIndexList, M141Config.StationCode); LogAsync(DateTime.Now, EnumHelper.LogLevel.Assist, $"浜у搧{p.PID}_{p.SEQUENCE}宸叉竻鐞唟b.WorkPosition}妫�娴嬫暟鎹�傚綋鍓嶅凡瀹屾垚宸ヤ綅{string.Join(",", p.Details.Select(u => u.PositionName))}"); + }); //鍒濆鍖栧伐浣嶇殑妫�娴嬫鏁� @@ -1197,6 +1195,8 @@ newp.BasketCode = p.BasketCode; newp.Result = p.Result; newp.SN = p.SN; + + Thread.Sleep(500); var plist = mysqlhelper.GetProductList(p.SEQUENCE); @@ -1207,6 +1207,7 @@ newp.Details.AddRange(item.Details); } } + LogAsync(DateTime.Now, EnumHelper.LogLevel.Error, $"AllDeviceProductRecord浠庢暟鎹簱鑾峰彇鍒版暟鎹畕p.SEQUENCE} plist鏁伴噺{plist.Count} Details鏁伴噺{newp.Details.Count}"); //newp.Details.AddRange(p.Details); diff --git a/src/Bro.M141.Process/M141Process_ImageCheck.cs b/src/Bro.M141.Process/M141Process_ImageCheck.cs index 222cddc..3836a93 100644 --- a/src/Bro.M141.Process/M141Process_ImageCheck.cs +++ b/src/Bro.M141.Process/M141Process_ImageCheck.cs @@ -516,9 +516,9 @@ } - public void PlcwritePrinter(int add,int value) + public void PlcwritePrinter(int add, int value) { - Plc2.WriteSingleAddress(add,value,out _); + Plc2.WriteSingleAddress(add, value, out _); } @@ -583,8 +583,6 @@ } } - - LogAsync(DateTime.Now, EnumHelper.LogLevel.Assist, $"浜у搧{pid}妫�娴嬮」{s.Code}璧嬪�納s.GetMeasureValueStr()}锛岀粨鏋渰s.GetMeasureResultStr()}"); } else @@ -607,6 +605,15 @@ { isOK = false; + int num = 0; + + while (p.Details.Any(u => !u.IsDone) && num < 10) + { + num++; + Thread.Sleep(500); + } + + p.InitialDetailSpecs(); var resultList = p.Details.SelectMany(u => u.ResultList).ToList(); resultList.ForEach(u => u.SetResult()); @@ -622,6 +629,8 @@ { defects.Add("TBD"); } + + defects = defects.Distinct().ToList(); isOK = defects.Count <= 0; @@ -631,7 +640,7 @@ UpdateResult(DateTime.Now, p.SN, defectClass.ClassName, ""); //浜у搧搴忓彿+1 - Interlocked.Increment(ref _productIndex); + //Interlocked.Increment(ref _productIndex); List<ISpec> specList = new List<ISpec>(); specList.AddRange(p.Details.SelectMany(u => u.SpecList).ToList().ConvertAll(u => (ISpec)u)); diff --git a/src/Bro.M141.Process/M141Process_Mysql.cs b/src/Bro.M141.Process/M141Process_Mysql.cs index 17af1a5..00d7bee 100644 --- a/src/Bro.M141.Process/M141Process_Mysql.cs +++ b/src/Bro.M141.Process/M141Process_Mysql.cs @@ -145,7 +145,6 @@ { try { - Thread.Sleep(200); if (pro.Details != null) { foreach (var item in pro.Details) @@ -153,7 +152,9 @@ if (item != null) { var defects = item.ResultList.GetDefectDescList(); - item.DefectList.AddRange(defects); + var ngSpecCodes = item.SpecList.Where(u => u.MeasureResult != true).Select(u => u.Code); + defects.AddRange(ngSpecCodes); + item.DefectList.AddRange(defects.Distinct()); } } } @@ -168,7 +169,7 @@ //CommonLogger.LogAsync(DateTime.Now, EnumHelper.LogLevel.Exception, $"{jsondata}"); - string mysqlstr = $"update forlocal set data='{jsondata}' where plcnum='{pro.SEQUENCE}'"; + string mysqlstr = $"update forlocal set data='{jsondata}',pid='{pro.PID}' where plcnum='{pro.SEQUENCE}'"; if (Operatoremysql(mysqlstr, connStrLocal)) { @@ -195,23 +196,58 @@ //string destr = "delete from forall where id not in (select id from (select id from forall order BY id desc limit 1000) as subquery)"; //Operatoremysql(destr, connStrAll); - string str1 = "select id from forall order by id desc limit 1"; - string index = selectmysql(str1, connStrAll); - if (!string.IsNullOrEmpty(index)) + if (pro.Details != null) { - string str2 = $"delete from forall where id < ({index}-1000)"; - Operatoremysql(str2, connStrAll); + foreach (var item in pro.Details) + { + if (item != null) + { + var defects = item.ResultList.GetDefectDescList(); + var ngSpecCodes = item.SpecList.Where(u => u.MeasureResult != true).Select(u => u.Code); + defects.AddRange(ngSpecCodes); + item.DefectList.AddRange(defects.Distinct()); + item.DefectList = item.DefectList.Distinct().ToList(); + } + } } - string mysqlstr = $"insert into forall (basketcode,device,plcnum,sn,data,time) values('{pro.BasketCode}','{devicestr}','{pro.SEQUENCE}','{pro.SN}','{JsonConvert.SerializeObject(pro, new JsonSerializerSettings() { TypeNameHandling = TypeNameHandling.All })}','{DateTime.Now.ToString("yyyyMMddHHmmss")}')"; + string strtem = "select * from forall where plcnum='" + pro.SEQUENCE + "' and device='" + devicestr + "' "; - if (Operatoremysql(mysqlstr, connStrAll)) + var temdb = selectdt(strtem, connStrAll); + if (temdb != null && temdb.Rows.Count > 0) { - CommonLogger.LogAsync(DateTime.Now, EnumHelper.LogLevel.Action, $"鏁版嵁搴揻orall鎻掑叆鏁版嵁鎴愬姛"); + string mysqlstr = $"update forall set data='" + JsonConvert.SerializeObject(pro, new JsonSerializerSettings() { TypeNameHandling = TypeNameHandling.All }) + "' where plcnum='" + pro.SEQUENCE + "' and device='" + devicestr + "' "; + + if (Operatoremysql(mysqlstr, connStrAll)) + { + CommonLogger.LogAsync(DateTime.Now, EnumHelper.LogLevel.Action, $"鏁版嵁搴揻orall鏇存柊鏁版嵁鎴愬姛"); + } + else + { + CommonLogger.LogAsync(DateTime.Now, EnumHelper.LogLevel.Error, $"鏁版嵁搴揻orall鏇存柊鏁版嵁寮傚父 {mysqlstr}"); + } } else { - CommonLogger.LogAsync(DateTime.Now, EnumHelper.LogLevel.Error, $"鏁版嵁搴揻orall鎻掑叆鏁版嵁寮傚け璐� {mysqlstr}"); + string str1 = "select id from forall order by id desc limit 1"; + string index = selectmysql(str1, connStrAll); + + if (!string.IsNullOrEmpty(index)) + { + string str2 = $"delete from forall where id < ({index}-1000)"; + Operatoremysql(str2, connStrAll); + } + + string mysqlstr = $"insert into forall (basketcode,device,plcnum,sn,data,time) values('{pro.BasketCode}','{devicestr}','{pro.SEQUENCE}','{pro.SN}','{JsonConvert.SerializeObject(pro, new JsonSerializerSettings() { TypeNameHandling = TypeNameHandling.All })}','{DateTime.Now.ToString("yyyyMMddHHmmss")}')"; + + if (Operatoremysql(mysqlstr, connStrAll)) + { + CommonLogger.LogAsync(DateTime.Now, EnumHelper.LogLevel.Action, $"鏁版嵁搴揻orall鎻掑叆鏁版嵁鎴愬姛"); + } + else + { + CommonLogger.LogAsync(DateTime.Now, EnumHelper.LogLevel.Error, $"鏁版嵁搴揻orall鎻掑叆鏁版嵁寮傚け璐� {mysqlstr}"); + } } } diff --git a/src/Bro.M141.Process/UI/UIPrinter.Designer.cs b/src/Bro.M141.Process/UI/UIPrinter.Designer.cs index 42ce610..aed4ac6 100644 --- a/src/Bro.M141.Process/UI/UIPrinter.Designer.cs +++ b/src/Bro.M141.Process/UI/UIPrinter.Designer.cs @@ -38,10 +38,9 @@ // // button2 // - button2.Location = new Point(283, 127); - button2.Margin = new Padding(5, 4, 5, 4); + button2.Location = new Point(180, 90); button2.Name = "button2"; - button2.Size = new Size(170, 85); + button2.Size = new Size(108, 60); button2.TabIndex = 1; button2.Text = "棰勮"; button2.UseVisualStyleBackColor = true; @@ -49,10 +48,9 @@ // // button1 // - button1.Location = new Point(50, 127); - button1.Margin = new Padding(5, 4, 5, 4); + button1.Location = new Point(32, 90); button1.Name = "button1"; - button1.Size = new Size(170, 85); + button1.Size = new Size(108, 60); button1.TabIndex = 2; button1.Text = "鎵撳嵃"; button1.UseVisualStyleBackColor = true; @@ -60,27 +58,26 @@ // // textBox1 // - textBox1.Location = new Point(178, 49); - textBox1.Margin = new Padding(5, 4, 5, 4); + textBox1.Location = new Point(125, 38); textBox1.Name = "textBox1"; - textBox1.Size = new Size(273, 30); + textBox1.Size = new Size(175, 23); textBox1.TabIndex = 3; // // label1 // label1.AutoSize = true; - label1.Location = new Point(82, 54); - label1.Margin = new Padding(5, 0, 5, 0); + label1.Location = new Point(52, 38); label1.Name = "label1"; - label1.Size = new Size(82, 24); + label1.Size = new Size(56, 17); label1.TabIndex = 4; label1.Text = "鎵撳嵃鍐呭"; // // button3 // - button3.Location = new Point(50, 308); + button3.Location = new Point(32, 218); + button3.Margin = new Padding(2, 2, 2, 2); button3.Name = "button3"; - button3.Size = new Size(127, 61); + button3.Size = new Size(81, 43); button3.TabIndex = 5; button3.Text = "鑾峰彇鐘舵��"; button3.UseVisualStyleBackColor = true; @@ -88,15 +85,14 @@ // // textBox2 // - textBox2.Location = new Point(50, 376); - textBox2.Margin = new Padding(5, 4, 5, 4); + textBox2.Location = new Point(32, 266); textBox2.Name = "textBox2"; - textBox2.Size = new Size(490, 30); + textBox2.Size = new Size(313, 23); textBox2.TabIndex = 6; // // UIPrinter // - AutoScaleDimensions = new SizeF(11F, 24F); + AutoScaleDimensions = new SizeF(7F, 17F); AutoScaleMode = AutoScaleMode.Font; Controls.Add(textBox2); Controls.Add(button3); @@ -104,9 +100,9 @@ Controls.Add(textBox1); Controls.Add(button1); Controls.Add(button2); - Margin = new Padding(3, 4, 3, 4); + Margin = new Padding(2, 3, 2, 3); Name = "UIPrinter"; - Size = new Size(559, 511); + Size = new Size(356, 362); ResumeLayout(false); PerformLayout(); } diff --git a/src/Bro.M141.Process/UI/UIPrinter.cs b/src/Bro.M141.Process/UI/UIPrinter.cs index c17e2cf..949bd0d 100644 --- a/src/Bro.M141.Process/UI/UIPrinter.cs +++ b/src/Bro.M141.Process/UI/UIPrinter.cs @@ -2,6 +2,7 @@ using Bro.Common.Helper; using Bro.Common.Interface; using Bro.UI.Model.Winform; +using Sunny.UI; using System; using System.Collections.Generic; using System.ComponentModel; @@ -15,6 +16,7 @@ using System.Windows.Forms; using ZXing; using ZXing.Common; +using static System.Windows.Forms.AxHost; //using System.Printing; @@ -83,8 +85,6 @@ Process141.PlcwritePrinter(1510, 1); } - - private void printDocument_Print(object sender, PrintPageEventArgs e) { Font fntTxt = new Font("榛戜綋", 15, System.Drawing.FontStyle.Bold);//姝f枃鏂囧瓧 @@ -92,14 +92,153 @@ try { string numvalue = message; - Bitmap bitmap = CreateCode(numvalue); - int with = (ttwith - bitmap.Width) / 2 - 20; - int heih = (ttheigh - bitmap.Height) / 2; + float Scale = (float)0.95; + int startX = 10; + int startY = 25; + + //int length = 320 * Scale; + //int height = 160 * Scale; + var g = e.Graphics; + + Font font = new Font("Arial", 8 * Scale);//璁剧疆瀛椾綋棰滆壊 + Font font2 = new Font("Arial", 11 * Scale);//璁剧疆瀛椾綋棰滆壊 + Font font3 = new Font("Arial", 36 * Scale);//璁剧疆瀛椾綋棰滆壊 + Font font4 = new Font("Arial", 12 * Scale);//璁剧疆瀛椾綋棰滆壊 + + + Pen p = new Pen(Color.Black, Scale);//瀹氫箟浜嗕竴涓粦鑹�,瀹藉害涓�1鐨勭敾绗� + g.Clear(Color.White); + g.DrawRectangle(p, startX * Scale, startY * Scale, 70 * Scale, 20 * Scale);//鍦ㄧ敾鏉夸笂鐢荤煩褰�,璧峰鍧愭爣涓�(10,10),瀹戒负80,楂樹负20 + g.DrawRectangle(p, startX * Scale, startY * Scale, 280 * Scale, 20 * Scale);//鍦ㄧ敾鏉夸笂鐢荤煩褰�,璧峰鍧愭爣涓�(90,10),瀹戒负80,楂樹负20 + g.DrawString("鍘傚晢", font, brush, (startX + 20) * Scale, (startY + 5) * Scale);// + g.DrawString("鍢夊桨绉戞妧", font2, brush, (startX + 140) * Scale, (startY + 4) * Scale); + + + //绗簩琛屾暟鎹� + g.DrawRectangle(p, startX * Scale, (startY + 20) * Scale, 70 * Scale, 20 * Scale); + g.DrawRectangle(p, startX * Scale, (startY + 20) * Scale, 280 * Scale, 20 * Scale); + g.DrawString("鍝佸悕", font, brush, (startX + 20) * Scale, (startY + 25) * Scale); + g.DrawString(@"COVER LG208H-RC100 #2", font4, brush, (startX + 71) * Scale, (startY + 22) * Scale); + + //绗笁琛屾暟鎹� + g.DrawRectangle(p, startX * Scale, (startY + 40) * Scale, 70 * Scale, 20 * Scale); + g.DrawRectangle(p, startX * Scale, (startY + 40) * Scale, 280 * Scale, 20 * Scale); + g.DrawString("鏂欏彿", font, brush, (startX + 20) * Scale, (startY + 45) * Scale); + g.DrawString(@"436LG208I000", font2, brush, (startX + 130) * Scale, (startY + 43) * Scale); + + //绗洓琛屾暟鎹� + g.DrawRectangle(p, startX * Scale, (startY + 60) * Scale, 70 * Scale, 20 * Scale); + g.DrawRectangle(p, startX * Scale, (startY + 60) * Scale, 210 * Scale, 20 * Scale); + g.DrawString("鏁伴噺", font, brush, (startX + 20) * Scale, (startY + 65) * Scale); + g.DrawString(@"50PCS", font2, brush, (startX + 120) * Scale, (startY + 62) * Scale); + + //绗簲琛屾暟鎹� + g.DrawRectangle(p, startX * Scale, (startY + 80) * Scale, 70 * Scale, 20 * Scale); + g.DrawRectangle(p, startX * Scale, (startY + 80) * Scale, 210 * Scale, 20 * Scale); + g.DrawString("鐢熶骇鏃ユ湡", font, brush, (startX + 10) * Scale, (startY + 85) * Scale); + g.DrawString($"{DateTime.Now.ToString("yyyy.MM.dd")}", font2, brush, (startX + 105) * Scale, (startY + 82) * Scale); + + //绗叚琛屾暟鎹� + g.DrawRectangle(p, startX * Scale, (startY + 100) * Scale, 70 * Scale, 20 * Scale); + g.DrawRectangle(p, startX * Scale, (startY + 100) * Scale, 140 * Scale, 20 * Scale); + g.DrawRectangle(p, startX * Scale, (startY + 100) * Scale, 210 * Scale, 20 * Scale); + g.DrawString("MARK1", font, brush, (startX + 15) * Scale, (startY + 104) * Scale); + g.DrawString("MARK2", font, brush, (startX + 155) * Scale, (startY + 104) * Scale); + + + //渚ч潰 + g.DrawRectangle(p, (startX + 210) * Scale, (startY + 60) * Scale, 70 * Scale, 60 * Scale); + g.DrawString(@"#2", font3, brush, (startX + 210) * Scale, (startY + 62) * Scale); + } + catch (Exception ee) + { + MessageBox.Show(ee.Message); + } + } + + private void printDocument_Print222(object sender, PrintPageEventArgs e) + { + Font fntTxt = new Font("榛戜綋", 15, System.Drawing.FontStyle.Bold);//姝f枃鏂囧瓧 + System.Drawing.Brush brush = new SolidBrush(System.Drawing.Color.Black);//鐢诲埛 + try + { + string numvalue = message; + //Bitmap bitmap = getexcel();// CreateCode(numvalue); + + //int with = (ttwith - bitmap.Width) / 2 - 20; + //int heih = (ttheigh - bitmap.Height) / 2; //姊濈⒓鐨勪綅缃� - e.Graphics.DrawImage(bitmap, new System.Drawing.Point(with, heih)); + //e.Graphics.DrawImage(bitmap, new System.Drawing.Point(0, 0)); //姊濈⒓淇℃伅鏁稿瓧鐨勪綅缃� - e.Graphics.DrawString(numvalue, fntTxt, brush, new System.Drawing.Point(bitmap.Width / 4 + with - 10, heih + bitmap.Height + 5)); + //e.Graphics.DrawString(numvalue, fntTxt, brush, new System.Drawing.Point(bitmap.Width / 4 + with - 10, heih + bitmap.Height + 5)); + + + //e.Graphics.DrawImage(img, new Rectangle(25, 25, bmpwidth, bmpheight), new Rectangle(0, 0, img.Width, img.Height), GraphicsUnit.Pixel); + int Scale = 1; + int startX = 10; + int startY = 25; + + int length = 320 * Scale; + int height = 160 * Scale; + var g = e.Graphics; + + Font font = new Font("Arial", 8 * Scale);//璁剧疆瀛椾綋棰滆壊 + Font font2 = new Font("Arial", 11 * Scale);//璁剧疆瀛椾綋棰滆壊 + Font font3 = new Font("Arial", 36 * Scale);//璁剧疆瀛椾綋棰滆壊 + Font font4 = new Font("Arial", 12 * Scale);//璁剧疆瀛椾綋棰滆壊 + + + //SolidBrush brush = new SolidBrush(Color.Black);//鏂板缓涓�涓敾鍒�,鍒拌繖閲屼负姝�,鎴戜滑宸茬粡鍑嗗濂戒簡鐢绘澘銆佺敾鍒枫�佸拰鏁版嵁 + + + Pen p = new Pen(Color.Black, Scale);//瀹氫箟浜嗕竴涓粦鑹�,瀹藉害涓�1鐨勭敾绗� + g.Clear(Color.White); //璁剧疆鐧借壊鑳屾櫙 + //绗竴琛屾暟鎹� + g.DrawRectangle(p, startX * Scale, startY * Scale, 70 * Scale, 20 * Scale);//鍦ㄧ敾鏉夸笂鐢荤煩褰�,璧峰鍧愭爣涓�(10,10),瀹戒负80,楂樹负20 + g.DrawRectangle(p, startX * Scale, startY * Scale, 280 * Scale, 20 * Scale);//鍦ㄧ敾鏉夸笂鐢荤煩褰�,璧峰鍧愭爣涓�(90,10),瀹戒负80,楂樹负20 + g.DrawString("鍘傚晢", font, brush, (startX + 20) * Scale, (startY + 5) * Scale);// + g.DrawString("鍢夊桨绉戞妧", font2, brush, (startX + 140) * Scale, (startY + 4) * Scale); + + + //绗簩琛屾暟鎹� + g.DrawRectangle(p, startX * Scale, (startY + 20) * Scale, 70 * Scale, 20 * Scale); + g.DrawRectangle(p, startX * Scale, (startY + 20) * Scale, 280 * Scale, 20 * Scale); + g.DrawString("鍝佸悕", font, brush, (startX + 20) * Scale, (startY + 25) * Scale); + g.DrawString(@"COVER LG208H-RC100 #2", font4, brush, (startX + 71) * Scale, (startY + 22) * Scale); + + //绗笁琛屾暟鎹� + g.DrawRectangle(p, startX * Scale, (startY + 40) * Scale, 70 * Scale, 20 * Scale); + g.DrawRectangle(p, startX * Scale, (startY + 40) * Scale, 280 * Scale, 20 * Scale); + g.DrawString("鏂欏彿", font, brush, (startX + 20) * Scale, (startY + 45) * Scale); + g.DrawString(@"436LG208I000", font2, brush, (startX + 130) * Scale, (startY + 43) * Scale); + + //绗洓琛屾暟鎹� + g.DrawRectangle(p, startX * Scale, (startY + 60) * Scale, 70 * Scale, 20 * Scale); + g.DrawRectangle(p, startX * Scale, (startY + 60) * Scale, 210 * Scale, 20 * Scale); + g.DrawString("鏁伴噺", font, brush, (startX + 20) * Scale, (startY + 65) * Scale); + g.DrawString(@"50PCS", font2, brush, (startX + 120) * Scale, (startY + 62) * Scale); + + //绗簲琛屾暟鎹� + g.DrawRectangle(p, startX * Scale, (startY + 80) * Scale, 70 * Scale, 20 * Scale); + g.DrawRectangle(p, startX * Scale, (startY + 80) * Scale, 210 * Scale, 20 * Scale); + g.DrawString("鐢熶骇鏃ユ湡", font, brush, (startX + 10) * Scale, (startY + 85) * Scale); + g.DrawString($"{DateTime.Now.ToString("yyyy.MM.dd")}", font2, brush, (startX + 105) * Scale, (startY + 82) * Scale); + + //绗叚琛屾暟鎹� + g.DrawRectangle(p, startX * Scale, (startY + 100) * Scale, 70 * Scale, 20 * Scale); + g.DrawRectangle(p, startX * Scale, (startY + 100) * Scale, 140 * Scale, 20 * Scale); + g.DrawRectangle(p, startX * Scale, (startY + 100) * Scale, 210 * Scale, 20 * Scale); + g.DrawString("MARK1", font, brush, (startX + 15) * Scale, (startY + 104) * Scale); + g.DrawString("MARK2", font, brush, (startX + 155) * Scale, (startY + 104) * Scale); + + + //渚ч潰 + g.DrawRectangle(p, (startX + 210) * Scale, (startY + 60) * Scale, 70 * Scale, 60 * Scale); + g.DrawString(@"#2", font3, brush, (startX + 210) * Scale, (startY + 62) * Scale); + + + } catch (Exception ee) @@ -153,11 +292,125 @@ PrintPreviewDialog printPreviewDialog1 = new PrintPreviewDialog(); this.printDocument1.DefaultPageSettings.PrinterSettings.PrinterName = "Honeywell PX240S (300 dpi)"; this.printDocument1.DefaultPageSettings.PaperSize = new PaperSize("Custum", ttwith, ttheigh); - this.printDocument1.PrintPage += new PrintPageEventHandler(this.printDocument_Print); + //this.printDocument1.PrintPage += new PrintPageEventHandler(this.printDocument_Print); printPreviewDialog1.Document = printDocument1; DialogResult res = printPreviewDialog1.ShowDialog(); printPreviewDialog1.Document.Dispose(); } + + + + public Bitmap getexcel() + { + + + int startX = 10; + int startY = 25; + + int Scale = 1; + + int length = 320 * Scale; + int height = 160 * Scale; + + Bitmap bmp = new Bitmap(length, height);//, System.Drawing.Imaging.PixelFormat.Format32bppArgb);//鏂板缓涓�涓浘鐗囧璞� + + //bmp.SetResolution(320, 160); + + Graphics g = Graphics.FromImage(bmp);//鍒╃敤璇ュ浘鐗囧璞$敓鎴愨�滅敾鏉库�� + + Font font = new Font("Arial", 8 * Scale);//璁剧疆瀛椾綋棰滆壊 + Font font2 = new Font("Arial", 11 * Scale);//璁剧疆瀛椾綋棰滆壊 + Font font3 = new Font("Arial", 36 * Scale);//璁剧疆瀛椾綋棰滆壊 + Font font4 = new Font("Arial", 12 * Scale);//璁剧疆瀛椾綋棰滆壊 + + + SolidBrush brush = new SolidBrush(Color.Black);//鏂板缓涓�涓敾鍒�,鍒拌繖閲屼负姝�,鎴戜滑宸茬粡鍑嗗濂戒簡鐢绘澘銆佺敾鍒枫�佸拰鏁版嵁 + + //g.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality; + //g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic; + //g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias; + + + //g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.NearestNeighbor; + //g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality; + //g.PixelOffsetMode = PixelOffsetMode.Half; + + + Pen p = new Pen(Color.Black, Scale);//瀹氫箟浜嗕竴涓粦鑹�,瀹藉害涓�1鐨勭敾绗� + g.Clear(Color.White); //璁剧疆鐧借壊鑳屾櫙 + //绗竴琛屾暟鎹� + g.DrawRectangle(p, startX * Scale, startY * Scale, 70 * Scale, 20 * Scale);//鍦ㄧ敾鏉夸笂鐢荤煩褰�,璧峰鍧愭爣涓�(10,10),瀹戒负80,楂樹负20 + g.DrawRectangle(p, startX * Scale, startY * Scale, 280 * Scale, 20 * Scale);//鍦ㄧ敾鏉夸笂鐢荤煩褰�,璧峰鍧愭爣涓�(90,10),瀹戒负80,楂樹负20 + g.DrawString("鍘傚晢", font, brush, (startX + 20) * Scale, (startY + 5) * Scale);// + g.DrawString("鍢夊桨绉戞妧", font2, brush, (startX + 140) * Scale, (startY + 4) * Scale); + + + //绗簩琛屾暟鎹� + g.DrawRectangle(p, startX * Scale, (startY + 20) * Scale, 70 * Scale, 20 * Scale); + g.DrawRectangle(p, startX * Scale, (startY + 20) * Scale, 280 * Scale, 20 * Scale); + g.DrawString("鍝佸悕", font, brush, (startX + 20) * Scale, (startY + 25) * Scale); + g.DrawString(@"COVER LG208H-RC100 #2", font4, brush, (startX + 71) * Scale, (startY + 22) * Scale); + + //绗笁琛屾暟鎹� + g.DrawRectangle(p, startX * Scale, (startY + 40) * Scale, 70 * Scale, 20 * Scale); + g.DrawRectangle(p, startX * Scale, (startY + 40) * Scale, 280 * Scale, 20 * Scale); + g.DrawString("鏂欏彿", font, brush, (startX + 20) * Scale, (startY + 45) * Scale); + g.DrawString(@"436LG208I000", font2, brush, (startX + 130) * Scale, (startY + 43) * Scale); + + //绗洓琛屾暟鎹� + g.DrawRectangle(p, startX * Scale, (startY + 60) * Scale, 70 * Scale, 20 * Scale); + g.DrawRectangle(p, startX * Scale, (startY + 60) * Scale, 210 * Scale, 20 * Scale); + g.DrawString("鏁伴噺", font, brush, (startX + 20) * Scale, (startY + 65) * Scale); + g.DrawString(@"50PCS", font2, brush, (startX + 120) * Scale, (startY + 62) * Scale); + + //绗簲琛屾暟鎹� + g.DrawRectangle(p, startX * Scale, (startY + 80) * Scale, 70 * Scale, 20 * Scale); + g.DrawRectangle(p, startX * Scale, (startY + 80) * Scale, 210 * Scale, 20 * Scale); + g.DrawString("鐢熶骇鏃ユ湡", font, brush, (startX + 10) * Scale, (startY + 85) * Scale); + g.DrawString($"{DateTime.Now.ToString("yyyy.MM.dd")}", font2, brush, (startX + 105) * Scale, (startY + 82) * Scale); + + //绗叚琛屾暟鎹� + g.DrawRectangle(p, startX * Scale, (startY + 100) * Scale, 70 * Scale, 20 * Scale); + g.DrawRectangle(p, startX * Scale, (startY + 100) * Scale, 140 * Scale, 20 * Scale); + g.DrawRectangle(p, startX * Scale, (startY + 100) * Scale, 210 * Scale, 20 * Scale); + g.DrawString("MARK1", font, brush, (startX + 15) * Scale, (startY + 104) * Scale); + g.DrawString("MARK2", font, brush, (startX + 155) * Scale, (startY + 104) * Scale); + + + //渚ч潰 + g.DrawRectangle(p, (startX + 210) * Scale, (startY + 60) * Scale, 70 * Scale, 60 * Scale); + g.DrawString(@"#2", font3, brush, (startX + 210) * Scale, (startY + 62) * Scale); + + + + + + //Font font22 = new Font("Arial", 6);//璁剧疆瀛椾綋棰滆壊 + //for (int i = 0; i < 32;i++) + //{ + // g.DrawString(i.ToString(), font22, brush, 0, i*10); + // g.DrawString(i.ToString(), font22, brush, i * 10, 0); + //} + + //bmp.Save("E:/test.bmp");//淇濆瓨涓鸿緭鍑烘祦锛屽惁鍒欓〉闈笂鏄剧ず涓嶅嚭鏉� + g.Dispose();//閲婃斁鎺夎璧勬簮 + + bmp.SetResolution(105 * Scale, 105 * Scale); + + + return bmp; + } + + + + + + + + + + + #region [DllImport("winspool.drv", CharSet = CharSet.Auto, SetLastError = true)] @@ -389,7 +642,7 @@ int statuscode = GetPrinterStatusCodeInt(); string status = GetPrinterStatusMessage(statuscode); //鍙湁鍦ㄦ墦鍗版満寮傚父鏃跺啀娆′笅鍙戞墦鍗颁换鍔″悗锛屾墠鑳借幏鍙栧埌鎵撳嵃鏈虹姸鎬併�傝繖鏄洜涓烘墦鍗版満椹卞姩绋嬪簭閫氬父鍙湪澶勭悊鎵撳嵃璇锋眰鏃舵洿鏂板叾鐘舵�佷俊鎭�傚鏋滄墦鍗版満娌℃湁鎺ユ敹鍒版柊鐨勬墦鍗颁换鍔★紝鍙兘鏃犳硶绔嬪嵆鍙嶆槧鍑虹湡瀹炵姸鎬併�� - textBox2.Text = "taskNum:" + taskNum+ ",statuscode:"+ statuscode+",status:"+status; + textBox2.Text = "taskNum:" + taskNum + ",statuscode:" + statuscode + ",status:" + status; } } } diff --git a/src/Bro.M141_AOI1.Process/AOI1Process.cs b/src/Bro.M141_AOI1.Process/AOI1Process.cs index 85fbd48..823c420 100644 --- a/src/Bro.M141_AOI1.Process/AOI1Process.cs +++ b/src/Bro.M141_AOI1.Process/AOI1Process.cs @@ -40,7 +40,7 @@ //using (StreamReader reader = new StreamReader(configPath, System.Text.Encoding.UTF8)) //{ // _configBackupStr = reader.ReadToEnd(); - + //} //ProductModel p = JsonConvert.DeserializeObject<ProductModel>(_configBackupStr, new JsonSerializerSettings() { TypeNameHandling = TypeNameHandling.All }); @@ -128,14 +128,47 @@ } else { - ret.Add(1); + if (barcode.Split('-').Length > 5) + { + int mh = Plc1.Read(4000, 1, out _)[0]; + string codestr = barcode.Split('-')[4]; + if (codestr == "L") + { + codestr = "10"; + } + + if (codestr.Equals(mh.ToString())) + { + ret.Add(1); + } + else + { + ret.Add(2); + Plc1.WriteSingleAddress(4010, 1, out _);//缁檖lc鎶ヨ + } + } + else + { + ret.Add(999); + } } FillSpecResults(results[0].PID, results[0].Specs, ret, opConfig.Products[0].SEQUENCE); opConfig.Products[0].SN = barcode; - opConfig.Products[0].Details.ForEach(u => u.SN = barcode); + opConfig.Products[0].PID = barcode + "_1"; + opConfig.Products[0].Details.ForEach(u => + { + u.SN = barcode; + u.PID = barcode + "_1"; + u.ResultList.ForEach(x => + { + + x.PID = barcode + "_1"; + + }); + }); LogAsync(DateTime.Now, EnumHelper.LogLevel.Action, $"浜у搧{opConfig.Products[0].PID}鏉$爜鑾峰彇涓簕barcode}"); } @@ -169,7 +202,6 @@ return msg; } - private string BarcodeScannerCommunicate(TcpClientWrapBase client) @@ -211,10 +243,6 @@ } return isBarcodeValid; } - - - - [ProcessMethod("ImageCheck", "CheckLineProfile", "妫�娴嬩骇鍝佺嚎杞粨搴�", InvokeType.TestInvoke)] @@ -358,17 +386,6 @@ return msg; } - - - - - - - - - - - -- Gitblit v1.8.0