From 2ad4cf6d588bd9bc446e8bde2a916c17aec3dad6 Mon Sep 17 00:00:00 2001
From: Gokiburi <Gokiburi@DESKTOP-9ITC11L>
Date: 星期二, 17 六月 2025 11:49:48 +0800
Subject: [PATCH] 增加离线测试功能

---
 src/Bro.M141.Process/M141Config.cs |  288 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 286 insertions(+), 2 deletions(-)

diff --git a/src/Bro.M141.Process/M141Config.cs b/src/Bro.M141.Process/M141Config.cs
index 065be49..3eb2a41 100644
--- a/src/Bro.M141.Process/M141Config.cs
+++ b/src/Bro.M141.Process/M141Config.cs
@@ -6,20 +6,38 @@
 using Bro.Common.Model;
 using Bro.M135.Common;
 using Bro.Process;
+using Newtonsoft.Json;
 using System.ComponentModel;
 using System.Drawing.Design;
 using System.Drawing.Imaging;
+using System.Drawing.Printing;
 using System.Reflection;
 using System.Windows.Forms.Design;
+using static Bro.Common.Helper.EnumHelper;
 
 namespace Bro.M141.Process
 {
     public class M141Config : ProcessConfigBase
     {
+        [Category("鎵撳嵃鏈洪厤缃�")]
+        [Description("鎵撳嵃鏈洪厤缃泦鍚�")]
+        [DisplayName("鎵撳嵃鏈洪厤缃泦鍚�")]
+        [TypeConverter(typeof(CollectionCountConvert))]
+        [Editor(typeof(ComplexCollectionEditor<Printer>), typeof(UITypeEditor))]
+        public List<Printer> Printers { get; set; } = new List<Printer>();
+
+
+      
+     
+
+
+
+
         [Category("浜у搧鏄剧ず鐣岄潰閰嶇疆")]
         [Description("瀛椾綋澶у皬")]
         [DisplayName("瀛椾綋澶у皬")]
         public int FontSize_p { get; set; } = 15;
+
 
         [Category("浜у搧鏄剧ず鐣岄潰閰嶇疆")]
         [Description("姣忚鍒楁暟")]
@@ -100,11 +118,56 @@
         public ImageFormat ImageFormatOK { get; set; } = ImageFormat.Png;
 
 
+
+        [Category("鏁版嵁搴撻厤缃�")]
+        [Description("IP")]
+        [DisplayName("IP")]
+        public string IPforall { get; set; } = "192.168.44.122";
+
+        [Category("鏁版嵁搴撻厤缃�")]
+        [Description("鏄惁涓虹粓鐐硅澶�")]
+        [DisplayName("鏄惁涓虹粓鐐硅澶�")]
+        public bool IsfinDevice { get; set; } = false;
+
+
+
+
+        [Category("鏍忓叿鏉$爜閰嶇疆")]
+        [Description("褰撳墠鏍忓叿鐮�")]
+        [DisplayName("褰撳墠鏍忓叿鐮�")]
+        public string basketcode { get; set; } = "NoRead";
+
+        [Category("鏍忓叿鏉$爜閰嶇疆")]
+        [Description("鏈珯鏄惁璇诲彇鏍忓叿鐮�")]
+        [DisplayName("鏈珯鏄惁璇诲彇鏍忓叿鐮�")]
+        public bool Isreadbasketcode { get; set; } = false;
+
+
+        [Category("PLC閰嶇疆")]
+        [Description("鎶ヨ閰嶇疆")]
+        [DisplayName("鎶ヨ閰嶇疆")]
+        [TypeConverter(typeof(CollectionCountConvert))]
+        [Editor(typeof(ComplexCollectionEditor<PLCAlarms>), typeof(UITypeEditor))]
+        public List<PLCAlarms> PLCAlarm { get; set; } = new List<PLCAlarms>();
+
+
+        [Category("PLC閰嶇疆")]
+        [Description("蹇冭烦鍦板潃")]
+        [DisplayName("蹇冭烦鍦板潃")]
+        public int heartadd { get; set; } = 1505;
+
+
     }
 
 
     public class WorkPositionSet : IComplexDisplay
     {
+        [Category("plc鍦板潃")]
+        [Description("鏄惁鍙栧浘鍗冲畬鎴�")]
+        [DisplayName("鏄惁鍙栧浘鍗冲畬鎴�")]
+        public bool ispiccover { get; set; } = false;
+
+
         [Category("plc鍦板潃")]
         [Description("瀹屾垚鍦板潃")]
         [DisplayName("瀹屾垚鍦板潃")]
@@ -158,6 +221,137 @@
 
 
 
+    public class PLCAlarms : IComplexDisplay
+    {
+
+        [Category("PLC閰嶇疆")]
+        [DisplayName("plc鍚嶇О")]
+        [Description("plc鍚嶇О")]
+        [TypeConverter(typeof(DeviceIdSelectorConverter<PLCBase>))]
+        public string plcname { get; set; } = "";
+
+
+        [Category("PLC閰嶇疆")]
+        [DisplayName("鏄惁鍚敤")]
+        [Description("鏄惁鍚敤")]
+        public bool isused { get; set; } = true;
+
+
+        [Category("鎶ヨ閰嶇疆")]
+        [Description("鎶ヨ璇︽儏")]
+        [DisplayName("鎶ヨ璇︽儏")]
+        [TypeConverter(typeof(CollectionCountConvert))]
+        [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, IImportFromFileInEditor
+    {
+        [Category("閰嶇疆")]
+        [DisplayName("棣栧湴鍧�")]
+        [Description("棣栧湴鍧�")]
+        public int address { get; set; }
+
+        [Category("閰嶇疆")]
+        [DisplayName("瀛愬湴鍧�")]
+        [Description("瀛愬湴鍧�")]
+        public int address2 { get; set; }
+
+        [Category("閰嶇疆")]
+        [DisplayName("鎶ヨ鍚嶇О")]
+        [Description("鎶ヨ鍚嶇О")]
+        public string alarmname { get; set; } = "";
+
+        [Browsable(false)]
+        [JsonIgnore]
+        public int value { get; set; } = -1;
+
+        public string GetDisplayText()
+        {
+            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;
+        }
+
+
+
+
+
+
+    }
+
+
+
+
+
+
+
+
 
     public class MeasureBind : IComplexDisplay, IHalconToolPath
     {
@@ -176,6 +370,11 @@
         [DisplayName("鍥惧儚绱㈠紩")]
         [Description("搴斿鍗曟妫�娴嬮」闇�瑕佸娆℃媿鐓ф椂锛岃褰曞浘鐗囩殑绱㈠紩鍙凤紝浠�0寮�濮�")]
         public int ImageIndex { get; set; } = 0;
+
+        [Category("鍚敤閰嶇疆")]
+        [DisplayName("鍥哄畾妫�娴嬮」")]
+        [Description("true锛氳妫�娴嬮」鏄浐瀹氭娴嬮」鐩紝蹇呴』鎵ц false锛氳妫�娴嬫槸鍙彉妫�娴嬮」鐩紝娴佺▼涓喅瀹氭槸鍚︽娴嬶紝榛樿涓嶆娴�")]
+        public bool IsFixed { get; set; } = true;
 
         [Category("鍙栧儚璁剧疆")]
         [DisplayName("鐩告満閫夋嫨")]
@@ -235,7 +434,10 @@
         [DisplayName("OK鍥剧墖淇濆瓨寮�鍏�")]
         public bool OKImageSwitch { get; set; } = false;
 
-
+        [Category("鍥剧墖淇濆瓨璁剧疆")]
+        [Description("璇ョ珯妫�娴嬪浘鐗囦繚瀛樻椂锛屼繚瀛樼殑鍥剧墖椤哄簭鍚庣紑")]
+        [DisplayName("鍥剧墖淇濆瓨椤哄簭鍚庣紑")]
+        public string ImageSaveSeq { get; set; } = "1";
 
         public string GetDisplayText()
         {
@@ -375,6 +577,43 @@
     }
 
 
+    public class Printer : IComplexDisplay
+    {
+        [Category("鎵撳嵃鏈洪厤缃�")]
+        [DisplayName("鍚嶇О")]
+        [Description("鍚嶇О")]
+        [TypeConverter(typeof(DevicePrinter))]
+        public string name { get; set; } = "";
+
+
+        [Category("鎵撳嵃鏈洪厤缃�")]
+        [DisplayName("浣嶇疆")]
+        [Description("浣嶇疆")]
+        public string station { get; set; }
+
+
+        [Category("PLC閰嶇疆")]
+        [DisplayName("plc鍚嶇О")]
+        [Description("plc鍚嶇О")]
+        [TypeConverter(typeof(DeviceIdSelectorConverter<PLCBase>))]
+        public string plcname { get; set; }
+
+        [Category("PLC閰嶇疆")]
+        [DisplayName("鐘舵�佸湴鍧�")]
+        [Description("鐘舵�佸湴鍧�")]
+        public int addstate { get; set; }
+
+        [Category("PLC閰嶇疆")]
+        [DisplayName("缁撴灉鍦板潃")]
+        [Description("缁撴灉鍦板潃")]
+        public int addresult { get; set; }
+
+
+        public string GetDisplayText()
+        {
+            return name;
+        }
+    }
 
 
 
@@ -548,7 +787,7 @@
                     string filePath = "";
                     if (saveFileDialog.ShowDialog() == DialogResult.OK)
                     {
-                         filePath = saveFileDialog.FileName; // 鑾峰彇鐢ㄦ埛閫夋嫨鐨勬枃浠惰矾寰�
+                        filePath = saveFileDialog.FileName; // 鑾峰彇鐢ㄦ埛閫夋嫨鐨勬枃浠惰矾寰�
                     }
                     else
                     {
@@ -574,6 +813,36 @@
             return true;
         }
     }
+
+
+    public class DevicePrinter : ComboBoxItemTypeConvert
+    {
+        public override Dictionary<string, string> GetConvertDict(ITypeDescriptorContext context)
+        {
+            Dictionary<string, string> table = new Dictionary<string, string>();
+            table[""] = "鏈寚瀹�";
+
+            PrintDocument print = new PrintDocument();
+            string sDefault = print.PrinterSettings.PrinterName;//榛樿鎵撳嵃鏈哄悕
+            foreach (string sPrint in PrinterSettings.InstalledPrinters)//鑾峰彇鎵�鏈夋墦鍗版満鍚嶇О
+            {
+                table[sPrint] = sPrint;
+            }
+            return table;
+        }
+    }
+
+
+
+
+
+
+
+
+
+
+
+
 
     [Device("ImageCheck", "鍥剧墖妫�娴嬫搷浣滈厤缃�", EnumHelper.DeviceAttributeType.OperationConfig)]
     public class ImageCheckOperationConfigBase : OperationConfigBase, IHalconToolPath, IImageCheckOperationConfig
@@ -653,6 +922,21 @@
     }
 
 
+    [Device("OfflineDemo", "绂荤嚎娴嬭瘯", DeviceAttributeType.OperationConfig)]
+    public class OfflineDemoOperationConfig : OperationConfigBase
+    {
+        [Category("鍥剧墖鐩綍")]
+        [Description("鍥剧墖鐩綍")]
+        [DisplayName("鍥剧墖鐩綍")]
+        [Editor(typeof(FoldDialogEditor), typeof(UITypeEditor))]
+        public string ImageFolder { get; set; }
+
+        [Category("鍚姩閰嶇疆")]
+        [Description("true锛氬惎鍔ㄧ绾挎祴璇� false锛氬仠姝㈢绾挎祴璇�")]
+        [DisplayName("娴嬭瘯寮�鍏�")]
+        public bool IsStart { get; set; } = true;
+    }
+
     public class RealTimeAdjustDataDetail : IComplexDisplay
     {
         [Category("鐐逛綅璁剧疆")]

--
Gitblit v1.8.0