Browse Source

优化参数设置

callm 2 days ago
parent
commit
92248e5996

+ 15 - 0
FileWatcher/.workbuddy/memory/2026-10-19.md

@@ -0,0 +1,15 @@
+# 2026-10-19
+
+## AutoSMTRXY 参数设置抽离为独立窗体
+- 需求:把主界面红框内的设置项(密码、串口、波特率、读取、回写、停止、清零、启用扫描、计数方式)移到新窗体,点「设置参数」弹出,标题按用户截图样式。
+- 新增 `AutoSMTRXYSetting.cs / .Designer.cs / .resx`:载入缓存值,默认锁定,输入密码 1234 后解锁编辑,按钮变「保存」写入缓存(BaseUtil.SetCacheData,含新增的 Stop 缓存)并返回 DialogResult.OK。
+- 主窗体 `AutoSMTRXY`:
+  - Designer 移除上述 18 个控件(保留「设置参数」按钮),`Setting_Click` 改为 ShowDialog 新窗体,保存后 `ReloadSettings()` 从缓存刷新。
+  - 主窗体改用私有字段 ComPort/BaudRate/Read/Write/Stop/ToZero/UseScan/CountType,替换所有原控件 `.Text` 引用(PLC 读写、串口、清零、启动/停止指令等)。
+  - FileWatcher.csproj(旧式)已注册新窗体的 Compile/EmbeddedResource 条目。
+- 注意:本机沙箱拦截 MSBuild/csc,未做编译验证,建议用户在 VS 里编译确认。
+- 二次调整:设置窗体 5 个标题按用户新截图改为——读取→计数地址、清零→计数清零、停止→计划限制数量地址、启用扫描→扫码启动地址、回写→扫码成功反馈地址,并按截图顺序排列(密码/串口/波特率/计数地址/计数清零/计划限制数量地址/扫码启动地址/扫码成功反馈地址/计数方式)。控件内部字段名不变,仅改显示文字与行序。
+- 三次调整(对齐):标签改为 AutoSize=false 固定宽 140、TextAlign=MiddleRight 统一右对齐,输入框统一 x=203 宽 150,窗体收窄到 430,按钮居中,解决标签与输入框间距过大问题。
+- 四次调整(上下对齐):统一给 9 个输入控件(Password/ComPort/BaudRate/Read/ToZero/Stop/UseScan/Write/CountType)显式设置 Font = 微软雅黑 10.8F,与标签字体一致。
+- 五次调整(按钮看不见 + 最终对齐):用户在高DPI(200%)机器上用 VS 设计器打开过本窗体,VS 把 AutoScaleDimensions 改成 12F,24F 并把所有坐标×2 序列化,导致客户端区 860×1102、窗口高约 1170 超出屏幕,底部按钮被裁掉;同时标签被拉成 70 高而输入框只有 46 高、y 也不同,造成上下错位。
+- 最终布局(200% 设计空间,勿再用 VS 设计器随意拖动以免再次被×2 序列化):标签 x=60 w=280 右对齐、输入框 x=356 w=300 h=46,标签与输入框**同 y 同高**;行 y=40/110(串口行高70)/200/270/340/410/480/550/620;按钮(118,700)与(374,700)尺寸 224×70;ClientSize 716×808,AutoScaleDimensions 12F,24F。

+ 67 - 292
FileWatcher/AutoSMTRXY.Designer.cs

@@ -45,46 +45,29 @@
             this.Counter = new System.Windows.Forms.RadioButton();
             this.StopWatch = new System.Windows.Forms.Button();
             this.StartWatch = new System.Windows.Forms.Button();
-            this.BaudRate = new System.Windows.Forms.TextBox();
-            this.BaudRate_label = new System.Windows.Forms.Label();
-            this.ComPort_label = new System.Windows.Forms.Label();
             this.Timer = new System.Windows.Forms.Timer(this.components);
             this.pr_pcbacount = new System.Windows.Forms.NumericUpDown();
             this.label7 = new System.Windows.Forms.Label();
-            this.Read = new System.Windows.Forms.TextBox();
-            this.Read_label = new System.Windows.Forms.Label();
-            this.Write = new System.Windows.Forms.TextBox();
-            this.Write_label = new System.Windows.Forms.Label();
-            this.ToZero = new System.Windows.Forms.TextBox();
-            this.ToZero_label = new System.Windows.Forms.Label();
             this.CleanData = new System.Windows.Forms.Button();
             this.Setting = new System.Windows.Forms.Button();
-            this.CountType_label = new System.Windows.Forms.Label();
-            this.CountType = new System.Windows.Forms.ComboBox();
-            this.UseScan = new System.Windows.Forms.TextBox();
-            this.UseScan_label = new System.Windows.Forms.Label();
-            this.Password = new System.Windows.Forms.TextBox();
-            this.label3 = new System.Windows.Forms.Label();
-            this.ComPort = new FileWatcher.SerialPortCombox();
             this.ms_sncode = new FileWatcher.EnterTextBox();
             this.ma_code = new FileWatcher.SearchTextBox();
             this.li_code = new FileWatcher.SearchTextBox();
-            this.Stop = new System.Windows.Forms.TextBox();
-            this.label6 = new System.Windows.Forms.Label();
+            this.Start = new System.Windows.Forms.Button();
             ((System.ComponentModel.ISupportInitialize)(this.pr_pcbacount)).BeginInit();
             this.SuspendLayout();
-            // 
+            //
             // OperateResult
-            // 
+            //
             this.OperateResult.Location = new System.Drawing.Point(1208, 23);
             this.OperateResult.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3);
             this.OperateResult.Name = "OperateResult";
             this.OperateResult.Size = new System.Drawing.Size(489, 535);
             this.OperateResult.TabIndex = 7;
             this.OperateResult.Text = "";
-            // 
+            //
             // Clean
-            // 
+            //
             this.Clean.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
             this.Clean.Location = new System.Drawing.Point(1380, 580);
             this.Clean.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3);
@@ -94,9 +77,9 @@
             this.Clean.Text = "清除";
             this.Clean.UseVisualStyleBackColor = true;
             this.Clean.Click += new System.EventHandler(this.Clean_Click);
-            // 
+            //
             // MakeCode_lable
-            // 
+            //
             this.MakeCode_lable.AutoSize = true;
             this.MakeCode_lable.Font = new System.Drawing.Font("微软雅黑", 10.8F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
             this.MakeCode_lable.Location = new System.Drawing.Point(51, 120);
@@ -105,9 +88,9 @@
             this.MakeCode_lable.Size = new System.Drawing.Size(104, 38);
             this.MakeCode_lable.TabIndex = 12;
             this.MakeCode_lable.Text = "工单号";
-            // 
+            //
             // Type
-            // 
+            //
             this.Type.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
             this.Type.FormattingEnabled = true;
             this.Type.Items.AddRange(new object[] {
@@ -117,9 +100,9 @@
             this.Type.Name = "Type";
             this.Type.Size = new System.Drawing.Size(436, 32);
             this.Type.TabIndex = 18;
-            // 
+            //
             // label1
-            // 
+            //
             this.label1.AutoSize = true;
             this.label1.Font = new System.Drawing.Font("微软雅黑", 10.8F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
             this.label1.Location = new System.Drawing.Point(51, 261);
@@ -128,9 +111,9 @@
             this.label1.Size = new System.Drawing.Size(75, 38);
             this.label1.TabIndex = 19;
             this.label1.Text = "类型";
-            // 
+            //
             // AutoStart
-            // 
+            //
             this.AutoStart.AutoSize = true;
             this.AutoStart.Checked = true;
             this.AutoStart.CheckState = System.Windows.Forms.CheckState.Checked;
@@ -140,17 +123,17 @@
             this.AutoStart.TabIndex = 20;
             this.AutoStart.Text = "开机自动启动";
             this.AutoStart.UseVisualStyleBackColor = true;
-            // 
+            //
             // NowQTY
-            // 
+            //
             this.NowQTY.Location = new System.Drawing.Point(221, 347);
             this.NowQTY.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3);
             this.NowQTY.Name = "NowQTY";
             this.NowQTY.Size = new System.Drawing.Size(145, 35);
             this.NowQTY.TabIndex = 26;
-            // 
+            //
             // label4
-            // 
+            //
             this.label4.AutoSize = true;
             this.label4.Font = new System.Drawing.Font("微软雅黑", 10.8F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
             this.label4.Location = new System.Drawing.Point(51, 343);
@@ -159,9 +142,9 @@
             this.label4.Size = new System.Drawing.Size(133, 38);
             this.label4.TabIndex = 25;
             this.label4.Text = "当前计数";
-            // 
+            //
             // label5
-            // 
+            //
             this.label5.AutoSize = true;
             this.label5.Font = new System.Drawing.Font("微软雅黑", 12F);
             this.label5.Location = new System.Drawing.Point(51, 191);
@@ -169,9 +152,9 @@
             this.label5.Size = new System.Drawing.Size(82, 41);
             this.label5.TabIndex = 27;
             this.label5.Text = "线别";
-            // 
+            //
             // label2
-            // 
+            //
             this.label2.AutoSize = true;
             this.label2.Font = new System.Drawing.Font("微软雅黑", 10.8F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
             this.label2.Location = new System.Drawing.Point(51, 424);
@@ -180,14 +163,14 @@
             this.label2.Size = new System.Drawing.Size(104, 38);
             this.label2.TabIndex = 34;
             this.label2.Text = "录入框";
-            // 
+            //
             // RemindTimer
-            // 
+            //
             this.RemindTimer.Interval = 5000;
             this.RemindTimer.Tick += new System.EventHandler(this.RemindTimer_Tick);
-            // 
+            //
             // RemindVoice
-            // 
+            //
             this.RemindVoice.AutoSize = true;
             this.RemindVoice.Checked = true;
             this.RemindVoice.CheckState = System.Windows.Forms.CheckState.Checked;
@@ -197,9 +180,9 @@
             this.RemindVoice.TabIndex = 35;
             this.RemindVoice.Text = "开启提示音";
             this.RemindVoice.UseVisualStyleBackColor = true;
-            // 
+            //
             // SN
-            // 
+            //
             this.SN.AutoSize = true;
             this.SN.Location = new System.Drawing.Point(221, 485);
             this.SN.Name = "SN";
@@ -208,9 +191,9 @@
             this.SN.Text = "扫描SN";
             this.SN.UseVisualStyleBackColor = true;
             this.SN.CheckedChanged += new System.EventHandler(this.SN_CheckedChanged);
-            // 
+            //
             // Counter
-            // 
+            //
             this.Counter.AutoSize = true;
             this.Counter.Checked = true;
             this.Counter.Location = new System.Drawing.Point(357, 485);
@@ -221,12 +204,12 @@
             this.Counter.Text = "计数器";
             this.Counter.UseVisualStyleBackColor = true;
             this.Counter.CheckedChanged += new System.EventHandler(this.Counter_CheckedChanged);
-            // 
+            //
             // StopWatch
-            // 
+            //
             this.StopWatch.Enabled = false;
             this.StopWatch.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
-            this.StopWatch.Location = new System.Drawing.Point(403, 552);
+            this.StopWatch.Location = new System.Drawing.Point(357, 552);
             this.StopWatch.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3);
             this.StopWatch.Name = "StopWatch";
             this.StopWatch.Size = new System.Drawing.Size(128, 56);
@@ -234,9 +217,9 @@
             this.StopWatch.Text = "停止监控";
             this.StopWatch.UseVisualStyleBackColor = true;
             this.StopWatch.Click += new System.EventHandler(this.StopWatch_Click);
-            // 
+            //
             // StartWatch
-            // 
+            //
             this.StartWatch.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
             this.StartWatch.Location = new System.Drawing.Point(205, 552);
             this.StartWatch.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3);
@@ -246,46 +229,14 @@
             this.StartWatch.Text = "开始监控";
             this.StartWatch.UseVisualStyleBackColor = true;
             this.StartWatch.Click += new System.EventHandler(this.StartWatch_Click);
-            // 
-            // BaudRate
-            // 
-            this.BaudRate.Enabled = false;
-            this.BaudRate.Location = new System.Drawing.Point(1020, 229);
-            this.BaudRate.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3);
-            this.BaudRate.Name = "BaudRate";
-            this.BaudRate.Size = new System.Drawing.Size(145, 35);
-            this.BaudRate.TabIndex = 43;
-            this.BaudRate.Text = "9600";
-            // 
-            // BaudRate_label
-            // 
-            this.BaudRate_label.AutoSize = true;
-            this.BaudRate_label.Font = new System.Drawing.Font("微软雅黑", 10.8F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
-            this.BaudRate_label.Location = new System.Drawing.Point(896, 229);
-            this.BaudRate_label.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
-            this.BaudRate_label.Name = "BaudRate_label";
-            this.BaudRate_label.Size = new System.Drawing.Size(104, 38);
-            this.BaudRate_label.TabIndex = 42;
-            this.BaudRate_label.Text = "波特率";
-            // 
-            // ComPort_label
-            // 
-            this.ComPort_label.AutoSize = true;
-            this.ComPort_label.Font = new System.Drawing.Font("微软雅黑", 10.8F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
-            this.ComPort_label.Location = new System.Drawing.Point(925, 177);
-            this.ComPort_label.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
-            this.ComPort_label.Name = "ComPort_label";
-            this.ComPort_label.Size = new System.Drawing.Size(75, 38);
-            this.ComPort_label.TabIndex = 41;
-            this.ComPort_label.Text = "串口";
-            // 
+            //
             // Timer
-            // 
+            //
             this.Timer.Interval = 2000;
             this.Timer.Tick += new System.EventHandler(this.Timer_Tick);
-            // 
+            //
             // pr_pcbacount
-            // 
+            //
             this.pr_pcbacount.Location = new System.Drawing.Point(537, 347);
             this.pr_pcbacount.Name = "pr_pcbacount";
             this.pr_pcbacount.Size = new System.Drawing.Size(120, 35);
@@ -295,9 +246,9 @@
             0,
             0,
             0});
-            // 
+            //
             // label7
-            // 
+            //
             this.label7.AutoSize = true;
             this.label7.Font = new System.Drawing.Font("微软雅黑", 10.8F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
             this.label7.Location = new System.Drawing.Point(409, 343);
@@ -306,71 +257,11 @@
             this.label7.Size = new System.Drawing.Size(104, 38);
             this.label7.TabIndex = 44;
             this.label7.Text = "拼版数";
-            // 
-            // Read
-            // 
-            this.Read.Enabled = false;
-            this.Read.Location = new System.Drawing.Point(1019, 285);
-            this.Read.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3);
-            this.Read.Name = "Read";
-            this.Read.Size = new System.Drawing.Size(145, 35);
-            this.Read.TabIndex = 47;
-            // 
-            // Read_label
-            // 
-            this.Read_label.AutoSize = true;
-            this.Read_label.Font = new System.Drawing.Font("微软雅黑", 10.8F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
-            this.Read_label.Location = new System.Drawing.Point(935, 280);
-            this.Read_label.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
-            this.Read_label.Name = "Read_label";
-            this.Read_label.Size = new System.Drawing.Size(75, 38);
-            this.Read_label.TabIndex = 46;
-            this.Read_label.Text = "读取";
-            // 
-            // Write
-            // 
-            this.Write.Enabled = false;
-            this.Write.Location = new System.Drawing.Point(1019, 339);
-            this.Write.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3);
-            this.Write.Name = "Write";
-            this.Write.Size = new System.Drawing.Size(145, 35);
-            this.Write.TabIndex = 49;
-            // 
-            // Write_label
-            // 
-            this.Write_label.AutoSize = true;
-            this.Write_label.Font = new System.Drawing.Font("微软雅黑", 10.8F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
-            this.Write_label.Location = new System.Drawing.Point(935, 335);
-            this.Write_label.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
-            this.Write_label.Name = "Write_label";
-            this.Write_label.Size = new System.Drawing.Size(75, 38);
-            this.Write_label.TabIndex = 48;
-            this.Write_label.Text = "回写";
-            // 
-            // ToZero
-            // 
-            this.ToZero.Enabled = false;
-            this.ToZero.Location = new System.Drawing.Point(1019, 432);
-            this.ToZero.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3);
-            this.ToZero.Name = "ToZero";
-            this.ToZero.Size = new System.Drawing.Size(145, 35);
-            this.ToZero.TabIndex = 51;
-            // 
-            // ToZero_label
-            // 
-            this.ToZero_label.AutoSize = true;
-            this.ToZero_label.Font = new System.Drawing.Font("微软雅黑", 10.8F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
-            this.ToZero_label.Location = new System.Drawing.Point(935, 428);
-            this.ToZero_label.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
-            this.ToZero_label.Name = "ToZero_label";
-            this.ToZero_label.Size = new System.Drawing.Size(75, 38);
-            this.ToZero_label.TabIndex = 50;
-            this.ToZero_label.Text = "清零";
-            // 
+            //
             // CleanData
-            // 
+            //
             this.CleanData.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
-            this.CleanData.Location = new System.Drawing.Point(595, 552);
+            this.CleanData.Location = new System.Drawing.Point(513, 552);
             this.CleanData.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3);
             this.CleanData.Name = "CleanData";
             this.CleanData.Size = new System.Drawing.Size(128, 56);
@@ -378,9 +269,9 @@
             this.CleanData.Text = "计数清零";
             this.CleanData.UseVisualStyleBackColor = true;
             this.CleanData.Click += new System.EventHandler(this.CleanData_Click);
-            // 
+            //
             // Setting
-            // 
+            //
             this.Setting.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
             this.Setting.Location = new System.Drawing.Point(973, 23);
             this.Setting.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3);
@@ -390,82 +281,9 @@
             this.Setting.Text = "设置参数";
             this.Setting.UseVisualStyleBackColor = true;
             this.Setting.Click += new System.EventHandler(this.Setting_Click);
-            // 
-            // CountType_label
-            // 
-            this.CountType_label.AutoSize = true;
-            this.CountType_label.Font = new System.Drawing.Font("微软雅黑", 10.8F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
-            this.CountType_label.Location = new System.Drawing.Point(880, 528);
-            this.CountType_label.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
-            this.CountType_label.Name = "CountType_label";
-            this.CountType_label.Size = new System.Drawing.Size(133, 38);
-            this.CountType_label.TabIndex = 55;
-            this.CountType_label.Text = "计数方式";
-            // 
-            // CountType
-            // 
-            this.CountType.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
-            this.CountType.Enabled = false;
-            this.CountType.FormattingEnabled = true;
-            this.CountType.Items.AddRange(new object[] {
-            "PLC",
-            "计数器"});
-            this.CountType.Location = new System.Drawing.Point(1020, 534);
-            this.CountType.Name = "CountType";
-            this.CountType.Size = new System.Drawing.Size(137, 32);
-            this.CountType.TabIndex = 54;
-            // 
-            // UseScan
-            // 
-            this.UseScan.Enabled = false;
-            this.UseScan.Location = new System.Drawing.Point(1019, 482);
-            this.UseScan.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3);
-            this.UseScan.Name = "UseScan";
-            this.UseScan.Size = new System.Drawing.Size(145, 35);
-            this.UseScan.TabIndex = 57;
-            // 
-            // UseScan_label
-            // 
-            this.UseScan_label.AutoSize = true;
-            this.UseScan_label.Font = new System.Drawing.Font("微软雅黑", 10.8F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
-            this.UseScan_label.Location = new System.Drawing.Point(877, 480);
-            this.UseScan_label.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
-            this.UseScan_label.Name = "UseScan_label";
-            this.UseScan_label.Size = new System.Drawing.Size(133, 38);
-            this.UseScan_label.TabIndex = 56;
-            this.UseScan_label.Text = "启用扫描";
-            // 
-            // Password
-            // 
-            this.Password.Location = new System.Drawing.Point(1019, 127);
-            this.Password.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3);
-            this.Password.Name = "Password";
-            this.Password.PasswordChar = '*';
-            this.Password.Size = new System.Drawing.Size(145, 35);
-            this.Password.TabIndex = 59;
-            // 
-            // label3
-            // 
-            this.label3.AutoSize = true;
-            this.label3.Font = new System.Drawing.Font("微软雅黑", 10.8F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
-            this.label3.Location = new System.Drawing.Point(923, 124);
-            this.label3.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
-            this.label3.Name = "label3";
-            this.label3.Size = new System.Drawing.Size(75, 38);
-            this.label3.TabIndex = 58;
-            this.label3.Text = "密码";
-            // 
-            // ComPort
-            // 
-            this.ComPort.Enabled = false;
-            this.ComPort.Location = new System.Drawing.Point(1019, 181);
-            this.ComPort.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5);
-            this.ComPort.Name = "ComPort";
-            this.ComPort.Size = new System.Drawing.Size(148, 40);
-            this.ComPort.TabIndex = 40;
-            // 
+            //
             // ms_sncode
-            // 
+            //
             this.ms_sncode.AllPower = null;
             this.ms_sncode.BackColor = System.Drawing.Color.White;
             this.ms_sncode.ID = null;
@@ -478,9 +296,9 @@
             this.ms_sncode.Str2 = null;
             this.ms_sncode.TabIndex = 33;
             this.ms_sncode.KeyDown += new System.Windows.Forms.KeyEventHandler(this.ms_sncode_KeyDown);
-            // 
+            //
             // ma_code
-            // 
+            //
             this.ma_code.AllPower = null;
             this.ma_code.Caller = null;
             this.ma_code.Condition = null;
@@ -496,9 +314,9 @@
             this.ma_code.TabIndex = 29;
             this.ma_code.TableName = null;
             this.ma_code.TextBoxEnable = false;
-            // 
+            //
             // li_code
-            // 
+            //
             this.li_code.AllPower = null;
             this.li_code.Caller = null;
             this.li_code.Condition = null;
@@ -514,54 +332,29 @@
             this.li_code.TabIndex = 28;
             this.li_code.TableName = null;
             this.li_code.TextBoxEnable = false;
-            // 
-            // Stop
-            // 
-            this.Stop.Enabled = false;
-            this.Stop.Location = new System.Drawing.Point(1020, 386);
-            this.Stop.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3);
-            this.Stop.Name = "Stop";
-            this.Stop.Size = new System.Drawing.Size(145, 35);
-            this.Stop.TabIndex = 61;
-            // 
-            // label6
-            // 
-            this.label6.AutoSize = true;
-            this.label6.Font = new System.Drawing.Font("微软雅黑", 10.8F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
-            this.label6.Location = new System.Drawing.Point(936, 382);
-            this.label6.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
-            this.label6.Name = "label6";
-            this.label6.Size = new System.Drawing.Size(75, 38);
-            this.label6.TabIndex = 60;
-            this.label6.Text = "停止";
-            // 
+            //
+            // Start
+            //
+            this.Start.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
+            this.Start.Location = new System.Drawing.Point(673, 552);
+            this.Start.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3);
+            this.Start.Name = "Start";
+            this.Start.Size = new System.Drawing.Size(128, 56);
+            this.Start.TabIndex = 62;
+            this.Start.Text = "启动";
+            this.Start.UseVisualStyleBackColor = true;
+            this.Start.Click += new System.EventHandler(this.Start_Click);
+            //
             // AutoSMTRXY
-            // 
+            //
             this.AutoScaleDimensions = new System.Drawing.SizeF(12F, 24F);
             this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
             this.ClientSize = new System.Drawing.Size(1709, 640);
-            this.Controls.Add(this.Stop);
-            this.Controls.Add(this.label6);
-            this.Controls.Add(this.Password);
-            this.Controls.Add(this.label3);
-            this.Controls.Add(this.UseScan);
-            this.Controls.Add(this.UseScan_label);
-            this.Controls.Add(this.CountType_label);
-            this.Controls.Add(this.CountType);
+            this.Controls.Add(this.Start);
             this.Controls.Add(this.Setting);
             this.Controls.Add(this.CleanData);
-            this.Controls.Add(this.ToZero);
-            this.Controls.Add(this.ToZero_label);
-            this.Controls.Add(this.Write);
-            this.Controls.Add(this.Write_label);
-            this.Controls.Add(this.Read);
-            this.Controls.Add(this.Read_label);
             this.Controls.Add(this.pr_pcbacount);
             this.Controls.Add(this.label7);
-            this.Controls.Add(this.BaudRate);
-            this.Controls.Add(this.BaudRate_label);
-            this.Controls.Add(this.ComPort_label);
-            this.Controls.Add(this.ComPort);
             this.Controls.Add(this.StopWatch);
             this.Controls.Add(this.StartWatch);
             this.Controls.Add(this.SN);
@@ -614,29 +407,11 @@
         private System.Windows.Forms.RadioButton Counter;
         private System.Windows.Forms.Button StopWatch;
         private System.Windows.Forms.Button StartWatch;
-        private System.Windows.Forms.TextBox BaudRate;
-        private System.Windows.Forms.Label BaudRate_label;
-        private System.Windows.Forms.Label ComPort_label;
-        private SerialPortCombox ComPort;
         private System.Windows.Forms.Timer Timer;
         private System.Windows.Forms.NumericUpDown pr_pcbacount;
         private System.Windows.Forms.Label label7;
-        private System.Windows.Forms.TextBox Read;
-        private System.Windows.Forms.Label Read_label;
-        private System.Windows.Forms.TextBox Write;
-        private System.Windows.Forms.Label Write_label;
-        private System.Windows.Forms.TextBox ToZero;
-        private System.Windows.Forms.Label ToZero_label;
         private System.Windows.Forms.Button CleanData;
         private System.Windows.Forms.Button Setting;
-        private System.Windows.Forms.Label CountType_label;
-        private System.Windows.Forms.ComboBox CountType;
-        private System.Windows.Forms.TextBox UseScan;
-        private System.Windows.Forms.Label UseScan_label;
-        private System.Windows.Forms.TextBox Password;
-        private System.Windows.Forms.Label label3;
-        private System.Windows.Forms.TextBox Stop;
-        private System.Windows.Forms.Label label6;
+        private System.Windows.Forms.Button Start;
     }
 }
-

+ 107 - 65
FileWatcher/AutoSMTRXY.cs

@@ -49,6 +49,18 @@ namespace FileWatcher
 
         HslCommunication.Profinet.Panasonic.PanasonicMewtocol plc;
 
+        /// <summary>
+        /// 参数设置(由“设置参数”窗口配置并写入缓存)
+        /// </summary>
+        string ComPort = "";
+        string BaudRate = "9600";
+        string Read = "";
+        string Write = "";
+        string Stop = "";
+        string ToZero = "";
+        string UseScan = "";
+        string CountType = "";
+
         public AutoSMTRXY()
         {
             InitializeComponent();
@@ -65,7 +77,6 @@ namespace FileWatcher
 
         private void Form1_Load(object sender, EventArgs e)
         {
-            CountType.Text = "PLC";
             CheckForIllegalCrossThreadCalls = false;
             FormBorderStyle = FormBorderStyle.FixedSingle;
             InitDB = new Thread(ConnectDB);
@@ -84,14 +95,9 @@ namespace FileWatcher
             //获取缓存信息
             try
             {
-                ComPort.Text = BaseUtil.GetCacheData("ComPort").ToString();
                 Type.Text = BaseUtil.GetCacheData("Type").ToString();
                 li_code.Text = BaseUtil.GetCacheData("Line").ToString();
-                Read.Text = BaseUtil.GetCacheData("Read").ToString();
-                Write.Text = BaseUtil.GetCacheData("Write").ToString();
-                ToZero.Text = BaseUtil.GetCacheData("ToZero").ToString();
-                CountType.Text = BaseUtil.GetCacheData("CountType").ToString();
-                UseScan.Text = BaseUtil.GetCacheData("UseScan").ToString();
+                ReloadSettings();
             }
             catch (Exception ex) { OperateResult.AppendText(ex.Message); }
 
@@ -131,17 +137,17 @@ namespace FileWatcher
                     dh.ExecuteSql("insert into makehourcount(mhc_id,mhc_macode,mhc_indate,mhc_type,mhc_qty,mhc_linecode,mhc_pcbcount)" +
                              "values(makehourcount_seq.nextval,'" + ma_code.Text + "',sysdate,'" + Type.Text + "','" + (qty - lastqty) + "','" + li_code.Text + "','" + pr_pcbacount.Value + "')", "insert");
                 }
-                dt = (DataTable)dh.ExecuteSql("select nvl(sum(MHC_QTY* MHC_PCBCOUNT),0)MHC_QTY,max(ma_qty)ma_qty from makehourcount left join make on ma_code=mhc_macode where mhc_macode='" + ma_code.Text + "'", "select");
+                dt = (DataTable)dh.ExecuteSql("select nvl(sum(MHC_QTY* MHC_PCBCOUNT),0)MHC_QTY,max(nvl(ma_qty,0)+nvl(ma_boutqty,0))ma_qty from makehourcount left join make on ma_code=mhc_macode where mhc_macode='" + ma_code.Text + "'", "select");
                 if (dt.Rows.Count > 0)
                 {
                     int MHC_QTY = int.Parse(dt.Rows[0]["MHC_QTY"].ToString());
                     int ma_qty = int.Parse(dt.Rows[0]["ma_qty"].ToString());
                     if (MHC_QTY >= ma_qty)
                     {
-                        OperateResult write = plc.Write(Stop.Text, 1);
+                        OperateResult write = plc.Write(Stop, 1);
                         if (write.IsSuccess)
                         {
-                            OperateResult.AppendText("通过,发送指令" + Stop.Text + "写入1\n");
+                            OperateResult.AppendText("通过,发送指令" + Stop + "写入1\n");
                             OperateResult.ScrollToCaret();
                         }
                         else
@@ -230,16 +236,20 @@ namespace FileWatcher
                 }
                 if (dt.Rows.Count > 0)
                 {
-                    OperateResult write = plc.Write(Stop.Text, 1);
-                    if (write.IsSuccess)
+                    if (plc != null)
                     {
-                        OperateResult.AppendText("通过,发送指令" + Stop.Text + "写入1\n");
-                        OperateResult.ScrollToCaret();
-                    }
-                    else
-                    {
-                        OperateResult.AppendText("写入失败\n");
-                        OperateResult.ScrollToCaret();
+                        OperateResult write = plc.Write(Stop, 1);
+                        if (write.IsSuccess)
+                        {
+                            OperateResult.AppendText("通过,发送指令" + Stop + "写入1\n");
+                            OperateResult.ScrollToCaret();
+                        }
+                        else
+                        {
+                            OperateResult.AppendText("写入失败\n");
+                            OperateResult.ScrollToCaret();
+                        }
+
                     }
                 }
             }
@@ -286,10 +296,10 @@ namespace FileWatcher
                 string error = "";
                 if (SN.Checked)
                 {
-                    OperateResult write = plc.Write(Write.Text, 1);
+                    OperateResult write = plc.Write(Write, 1);
                     if (write.IsSuccess)
                     {
-                        OperateResult.AppendText("通过,发送指令" + Write.Text + "写入1\n");
+                        OperateResult.AppendText("通过,发送指令" + Write + "写入1\n");
                         OperateResult.ScrollToCaret();
                     }
                     else
@@ -326,15 +336,8 @@ namespace FileWatcher
 
         private void StartWatch_Click(object sender, EventArgs e)
         {
-            BaseUtil.SetCacheData("ComPort", ComPort.Text);
-            BaseUtil.SetCacheData("BaudRate", BaudRate.Text);
             BaseUtil.SetCacheData("Line", li_code.Text);
-            BaseUtil.SetCacheData("Read", Read.Text);
-            BaseUtil.SetCacheData("Write", Write.Text);
-            BaseUtil.SetCacheData("ToZero", ToZero.Text);
             BaseUtil.SetCacheData("Type", Type.Text);
-            BaseUtil.SetCacheData("CountType", CountType.Text);
-            BaseUtil.SetCacheData("UseScan", UseScan.Text);
 
 
             if (!dh.CheckExist("Make", "ma_code='" + ma_code.Text + "'"))
@@ -342,12 +345,20 @@ namespace FileWatcher
                 OperateResult.AppendText("工单号不能为空\n");
                 return;
             }
-            if (CountType.Text == "")
+            string DL_STATUSCODE = dh.getFieldDataByCondition("deviceline", "DL_STATUSCODE", "DL_LINECODE='" + li_code.Text + "' and DL_MACODE='" + ma_code.Text + "'").ToString();
+
+            if (DL_STATUSCODE != "STARTED")
+            {
+                OperateResult.AppendText("机台尚未启动,请在APP上启动机台\n");
+                return;
+            }
+
+            if (CountType == "")
             {
                 OperateResult.AppendText("请选择计数类型\n");
                 return;
             }
-            if (ComPort.Text == "")
+            if (ComPort == "")
             {
                 OperateResult.AppendText("请选择串口\n");
                 return;
@@ -374,12 +385,12 @@ namespace FileWatcher
             StopWatch.Enabled = true;
             try
             {
-                if (CountType.Text == "PLC")
+                if (CountType == "PLC")
                 {
                     plc = new HslCommunication.Profinet.Panasonic.PanasonicMewtocol();
                     plc.Station = 238;
                     HslCommunication.Core.Pipe.PipeSerialPort pipe = new HslCommunication.Core.Pipe.PipeSerialPort();
-                    pipe.SerialPortInni(ComPort.Text, 9600, 8, StopBits.One, Parity.Odd);
+                    pipe.SerialPortInni(ComPort, 9600, 8, StopBits.One, Parity.Odd);
                     pipe.RtsEnable = false;
                     pipe.DtrEnable = false;
                     pipe.SleepTime = 20;
@@ -387,10 +398,10 @@ namespace FileWatcher
                     plc.CommunicationPipe = pipe;
                     if (Counter.Checked)
                     {
-                        OperateResult write = plc.Write(UseScan.Text, 0);
+                        OperateResult write = plc.Write(UseScan, 0);
                         if (write.IsSuccess)
                         {
-                            OperateResult.AppendText("通过,发送指令" + UseScan.Text + "写入0\n");
+                            OperateResult.AppendText("通过,发送指令" + UseScan + "写入0\n");
                         }
                         else
                         {
@@ -399,10 +410,10 @@ namespace FileWatcher
                     }
                     else
                     {
-                        OperateResult write = plc.Write(UseScan.Text, 2);
+                        OperateResult write = plc.Write(UseScan, 2);
                         if (write.IsSuccess)
                         {
-                            OperateResult.AppendText("通过,发送指令" + UseScan.Text + "写入2\n");
+                            OperateResult.AppendText("通过,发送指令" + UseScan + "写入2\n");
                         }
                         else
                         {
@@ -412,15 +423,15 @@ namespace FileWatcher
                 }
                 else
                 {
-                    serialPort1.PortName = ComPort.Text;
-                    serialPort1.BaudRate = int.Parse(BaudRate.Text);
+                    serialPort1.PortName = ComPort;
+                    serialPort1.BaudRate = int.Parse(BaudRate);
                     serialPort1.Open();
                 }
                 Timer.Start();
             }
             catch (Exception mes)
             {
-                if (BaudRate.Text == "" || BaudRate.Text == "")
+                if (BaudRate == "" || ComPort == "")
                     OperateResult.AppendText(">>请先维护波特率和串口\n");
                 else
                     OperateResult.AppendText(">>" + mes.Message + "\n");
@@ -441,10 +452,10 @@ namespace FileWatcher
 
         private void Timer_Tick(object sender, EventArgs e)
         {
-            if (CountType.Text == "PLC")
+            if (CountType == "PLC")
             {
                 string error = "";
-                OperateResult<short> read = plc.ReadInt16(Read.Text);
+                OperateResult<short> read = plc.ReadInt16(Read);
                 //OperateResult.AppendText("读取数据\n");
                 if (read.IsSuccess)
                 {
@@ -459,10 +470,10 @@ namespace FileWatcher
                         //{
                         //    if (qty - lastqty > 0)
                         //    {
-                        //        OperateResult write = plc.Write(Write.Text, 1);
+                        //        OperateResult write = plc.Write(Write, 1);
                         //        if (write.IsSuccess)
                         //        {
-                        //            OperateResult.AppendText("通过,发送指令" + Write.Text + "写入1\n");
+                        //            OperateResult.AppendText("通过,发送指令" + Write + "写入1\n");
                         //        }
                         //        else
                         //        {
@@ -538,10 +549,10 @@ namespace FileWatcher
             if (ExitConfirm == "Yes")
             {
                 NowQTY.Text = "0";
-                OperateResult write = plc.Write(ToZero.Text, 0);
+                OperateResult write = plc.Write(ToZero, 0);
                 if (write.IsSuccess)
                 {
-                    OperateResult.AppendText("通过,发送指令" + ToZero.Text + "写入0\n");
+                    OperateResult.AppendText("通过,发送指令" + ToZero + "写入0\n");
                 }
                 else
                 {
@@ -552,28 +563,46 @@ namespace FileWatcher
 
         private void Setting_Click(object sender, EventArgs e)
         {
-            if (Read.Enabled == true)
+            //打开参数设置窗口,保存后刷新本窗体的参数
+            AutoSMTRXYSetting settingForm = new AutoSMTRXYSetting();
+            settingForm.StartPosition = FormStartPosition.CenterParent;
+            if (settingForm.ShowDialog(this) == DialogResult.OK)
             {
-                ComPort.Enabled = false; Read.Enabled = false; Write.Enabled = false;
-                BaudRate.Enabled = false; ToZero.Enabled = false; UseScan.Enabled = false;
-                CountType.Enabled = false; Read.Enabled = false;
+                ReloadSettings();
+                OperateResult.AppendText("参数设置已保存\n");
+                OperateResult.ScrollToCaret();
             }
-            else
+        }
+
+        /// <summary>
+        /// 从缓存重新加载参数设置
+        /// </summary>
+        private void ReloadSettings()
+        {
+            ComPort = GetCacheString("ComPort");
+            BaudRate = GetCacheString("BaudRate");
+            Read = GetCacheString("Read");
+            Write = GetCacheString("Write");
+            ToZero = GetCacheString("ToZero");
+            CountType = GetCacheString("CountType");
+            UseScan = GetCacheString("UseScan");
+            Stop = GetCacheString("Stop");
+            if (BaudRate == "")
             {
-                if (Password.Text == "1234")
-                {
-                    ComPort.Enabled = true; Read.Enabled = true; Write.Enabled = true;
-                    BaudRate.Visible = true; ToZero.Enabled = true; UseScan.Enabled = true;
-                    CountType.Enabled = true; Read.Enabled = true;
-                    Password.Text = "";
-                }
-                else
-                {
-                    OperateResult.AppendText("密码不对\n");
-                }
+                BaudRate = "9600";
+            }
+            if (CountType == "")
+            {
+                CountType = "PLC";
             }
         }
 
+        private string GetCacheString(string ParamName)
+        {
+            object value = BaseUtil.GetCacheData(ParamName);
+            return value == null ? "" : value.ToString();
+        }
+
         private void Counter_CheckedChanged(object sender, EventArgs e)
         {
             if (Counter.Checked)
@@ -581,10 +610,10 @@ namespace FileWatcher
                 string ExitConfirm = MessageBox.Show(this, "确认切换为计数器?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question).ToString();
                 if (ExitConfirm == "Yes")
                 {
-                    OperateResult write = plc.Write(UseScan.Text, 0);
+                    OperateResult write = plc.Write(UseScan, 0);
                     if (write.IsSuccess)
                     {
-                        OperateResult.AppendText("通过,发送指令" + UseScan.Text + "写入0\n");
+                        OperateResult.AppendText("通过,发送指令" + UseScan + "写入0\n");
                     }
                     else
                     {
@@ -611,10 +640,10 @@ namespace FileWatcher
                         OperateResult.AppendText("请先开始监控\n");
                         return;
                     }
-                    OperateResult write = plc.Write(UseScan.Text, 2);
+                    OperateResult write = plc.Write(UseScan, 2);
                     if (write.IsSuccess)
                     {
-                        OperateResult.AppendText("通过,发送指令" + UseScan.Text + "写入2\n");
+                        OperateResult.AppendText("通过,发送指令" + UseScan + "写入2\n");
                     }
                     else
                     {
@@ -628,5 +657,18 @@ namespace FileWatcher
             }
 
         }
+
+        private void Start_Click(object sender, EventArgs e)
+        {
+            OperateResult write = plc.Write(Stop, 0);
+            if (write.IsSuccess)
+            {
+                OperateResult.AppendText("通过,发送指令" + Stop + "写入0\n");
+            }
+            else
+            {
+                OperateResult.AppendText("写入失败\n");
+            }
+        }
     }
 }

+ 326 - 0
FileWatcher/AutoSMTRXYSetting.Designer.cs

@@ -0,0 +1,326 @@
+namespace FileWatcher
+{
+    partial class AutoSMTRXYSetting
+    {
+        /// <summary>
+        /// 必需的设计器变量。
+        /// </summary>
+        private System.ComponentModel.IContainer components = null;
+
+        /// <summary>
+        /// 清理所有正在使用的资源。
+        /// </summary>
+        /// <param name="disposing">如果应释放托管资源,为 true;否则为 false。</param>
+        protected override void Dispose(bool disposing)
+        {
+            if (disposing && (components != null))
+            {
+                components.Dispose();
+            }
+            base.Dispose(disposing);
+        }
+
+        #region Windows 窗体设计器生成的代码
+
+        /// <summary>
+        /// 设计器支持所需的方法 - 不要修改
+        /// 使用代码编辑器修改此方法的内容。
+        /// </summary>
+        private void InitializeComponent()
+        {
+            this.label3 = new System.Windows.Forms.Label();
+            this.Password = new System.Windows.Forms.TextBox();
+            this.ComPort_label = new System.Windows.Forms.Label();
+            this.ComPort = new FileWatcher.SerialPortCombox();
+            this.BaudRate_label = new System.Windows.Forms.Label();
+            this.BaudRate = new System.Windows.Forms.TextBox();
+            this.Read_label = new System.Windows.Forms.Label();
+            this.Read = new System.Windows.Forms.TextBox();
+            this.ToZero_label = new System.Windows.Forms.Label();
+            this.ToZero = new System.Windows.Forms.TextBox();
+            this.label6 = new System.Windows.Forms.Label();
+            this.Stop = new System.Windows.Forms.TextBox();
+            this.UseScan_label = new System.Windows.Forms.Label();
+            this.UseScan = new System.Windows.Forms.TextBox();
+            this.Write_label = new System.Windows.Forms.Label();
+            this.Write = new System.Windows.Forms.TextBox();
+            this.CountType_label = new System.Windows.Forms.Label();
+            this.CountType = new System.Windows.Forms.ComboBox();
+            this.Confirm = new System.Windows.Forms.Button();
+            this.Cancel = new System.Windows.Forms.Button();
+            this.SuspendLayout();
+            // 
+            // label3
+            // 
+            this.label3.Font = new System.Drawing.Font("微软雅黑", 10.8F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
+            this.label3.Location = new System.Drawing.Point(60, 40);
+            this.label3.Margin = new System.Windows.Forms.Padding(6, 0, 6, 0);
+            this.label3.Name = "label3";
+            this.label3.Size = new System.Drawing.Size(280, 46);
+            this.label3.TabIndex = 0;
+            this.label3.Text = "密码";
+            this.label3.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
+            // 
+            // Password
+            // 
+            this.Password.Font = new System.Drawing.Font("微软雅黑", 10.8F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
+            this.Password.Location = new System.Drawing.Point(356, 40);
+            this.Password.Margin = new System.Windows.Forms.Padding(8, 6, 8, 6);
+            this.Password.Name = "Password";
+            this.Password.PasswordChar = '*';
+            this.Password.Size = new System.Drawing.Size(300, 46);
+            this.Password.TabIndex = 1;
+            // 
+            // ComPort_label
+            // 
+            this.ComPort_label.Font = new System.Drawing.Font("微软雅黑", 10.8F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
+            this.ComPort_label.Location = new System.Drawing.Point(60, 110);
+            this.ComPort_label.Margin = new System.Windows.Forms.Padding(6, 0, 6, 0);
+            this.ComPort_label.Name = "ComPort_label";
+            this.ComPort_label.Size = new System.Drawing.Size(280, 70);
+            this.ComPort_label.TabIndex = 2;
+            this.ComPort_label.Text = "串口";
+            this.ComPort_label.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
+            // 
+            // ComPort
+            // 
+            this.ComPort.Font = new System.Drawing.Font("微软雅黑", 10.8F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
+            this.ComPort.Location = new System.Drawing.Point(356, 110);
+            this.ComPort.Margin = new System.Windows.Forms.Padding(8, 10, 8, 10);
+            this.ComPort.Name = "ComPort";
+            this.ComPort.Size = new System.Drawing.Size(300, 70);
+            this.ComPort.TabIndex = 3;
+            // 
+            // BaudRate_label
+            // 
+            this.BaudRate_label.Font = new System.Drawing.Font("微软雅黑", 10.8F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
+            this.BaudRate_label.Location = new System.Drawing.Point(60, 200);
+            this.BaudRate_label.Margin = new System.Windows.Forms.Padding(6, 0, 6, 0);
+            this.BaudRate_label.Name = "BaudRate_label";
+            this.BaudRate_label.Size = new System.Drawing.Size(280, 46);
+            this.BaudRate_label.TabIndex = 4;
+            this.BaudRate_label.Text = "波特率";
+            this.BaudRate_label.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
+            // 
+            // BaudRate
+            // 
+            this.BaudRate.Font = new System.Drawing.Font("微软雅黑", 10.8F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
+            this.BaudRate.Location = new System.Drawing.Point(356, 200);
+            this.BaudRate.Margin = new System.Windows.Forms.Padding(8, 6, 8, 6);
+            this.BaudRate.Name = "BaudRate";
+            this.BaudRate.Size = new System.Drawing.Size(300, 46);
+            this.BaudRate.TabIndex = 5;
+            this.BaudRate.Text = "9600";
+            // 
+            // Read_label
+            // 
+            this.Read_label.Font = new System.Drawing.Font("微软雅黑", 10.8F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
+            this.Read_label.Location = new System.Drawing.Point(60, 270);
+            this.Read_label.Margin = new System.Windows.Forms.Padding(6, 0, 6, 0);
+            this.Read_label.Name = "Read_label";
+            this.Read_label.Size = new System.Drawing.Size(280, 46);
+            this.Read_label.TabIndex = 6;
+            this.Read_label.Text = "计数地址";
+            this.Read_label.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
+            // 
+            // Read
+            // 
+            this.Read.Font = new System.Drawing.Font("微软雅黑", 10.8F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
+            this.Read.Location = new System.Drawing.Point(356, 270);
+            this.Read.Margin = new System.Windows.Forms.Padding(8, 6, 8, 6);
+            this.Read.Name = "Read";
+            this.Read.Size = new System.Drawing.Size(300, 46);
+            this.Read.TabIndex = 7;
+            // 
+            // ToZero_label
+            // 
+            this.ToZero_label.Font = new System.Drawing.Font("微软雅黑", 10.8F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
+            this.ToZero_label.Location = new System.Drawing.Point(60, 340);
+            this.ToZero_label.Margin = new System.Windows.Forms.Padding(6, 0, 6, 0);
+            this.ToZero_label.Name = "ToZero_label";
+            this.ToZero_label.Size = new System.Drawing.Size(280, 46);
+            this.ToZero_label.TabIndex = 12;
+            this.ToZero_label.Text = "计数清零";
+            this.ToZero_label.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
+            // 
+            // ToZero
+            // 
+            this.ToZero.Font = new System.Drawing.Font("微软雅黑", 10.8F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
+            this.ToZero.Location = new System.Drawing.Point(356, 340);
+            this.ToZero.Margin = new System.Windows.Forms.Padding(8, 6, 8, 6);
+            this.ToZero.Name = "ToZero";
+            this.ToZero.Size = new System.Drawing.Size(300, 46);
+            this.ToZero.TabIndex = 13;
+            // 
+            // label6
+            // 
+            this.label6.Font = new System.Drawing.Font("微软雅黑", 10.8F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
+            this.label6.Location = new System.Drawing.Point(60, 410);
+            this.label6.Margin = new System.Windows.Forms.Padding(6, 0, 6, 0);
+            this.label6.Name = "label6";
+            this.label6.Size = new System.Drawing.Size(280, 46);
+            this.label6.TabIndex = 10;
+            this.label6.Text = "计划限制数量地址";
+            this.label6.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
+            // 
+            // Stop
+            // 
+            this.Stop.Font = new System.Drawing.Font("微软雅黑", 10.8F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
+            this.Stop.Location = new System.Drawing.Point(356, 410);
+            this.Stop.Margin = new System.Windows.Forms.Padding(8, 6, 8, 6);
+            this.Stop.Name = "Stop";
+            this.Stop.Size = new System.Drawing.Size(300, 46);
+            this.Stop.TabIndex = 11;
+            // 
+            // UseScan_label
+            // 
+            this.UseScan_label.Font = new System.Drawing.Font("微软雅黑", 10.8F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
+            this.UseScan_label.Location = new System.Drawing.Point(60, 480);
+            this.UseScan_label.Margin = new System.Windows.Forms.Padding(6, 0, 6, 0);
+            this.UseScan_label.Name = "UseScan_label";
+            this.UseScan_label.Size = new System.Drawing.Size(280, 46);
+            this.UseScan_label.TabIndex = 14;
+            this.UseScan_label.Text = "扫码启动地址";
+            this.UseScan_label.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
+            // 
+            // UseScan
+            // 
+            this.UseScan.Font = new System.Drawing.Font("微软雅黑", 10.8F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
+            this.UseScan.Location = new System.Drawing.Point(356, 480);
+            this.UseScan.Margin = new System.Windows.Forms.Padding(8, 6, 8, 6);
+            this.UseScan.Name = "UseScan";
+            this.UseScan.Size = new System.Drawing.Size(300, 46);
+            this.UseScan.TabIndex = 15;
+            // 
+            // Write_label
+            // 
+            this.Write_label.Font = new System.Drawing.Font("微软雅黑", 10.8F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
+            this.Write_label.Location = new System.Drawing.Point(60, 550);
+            this.Write_label.Margin = new System.Windows.Forms.Padding(6, 0, 6, 0);
+            this.Write_label.Name = "Write_label";
+            this.Write_label.Size = new System.Drawing.Size(280, 46);
+            this.Write_label.TabIndex = 8;
+            this.Write_label.Text = "扫码成功反馈地址";
+            this.Write_label.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
+            // 
+            // Write
+            // 
+            this.Write.Font = new System.Drawing.Font("微软雅黑", 10.8F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
+            this.Write.Location = new System.Drawing.Point(356, 550);
+            this.Write.Margin = new System.Windows.Forms.Padding(8, 6, 8, 6);
+            this.Write.Name = "Write";
+            this.Write.Size = new System.Drawing.Size(300, 46);
+            this.Write.TabIndex = 9;
+            // 
+            // CountType_label
+            // 
+            this.CountType_label.Font = new System.Drawing.Font("微软雅黑", 10.8F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
+            this.CountType_label.Location = new System.Drawing.Point(60, 620);
+            this.CountType_label.Margin = new System.Windows.Forms.Padding(6, 0, 6, 0);
+            this.CountType_label.Name = "CountType_label";
+            this.CountType_label.Size = new System.Drawing.Size(280, 46);
+            this.CountType_label.TabIndex = 16;
+            this.CountType_label.Text = "计数方式";
+            this.CountType_label.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
+            // 
+            // CountType
+            // 
+            this.CountType.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
+            this.CountType.Font = new System.Drawing.Font("微软雅黑", 10.8F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
+            this.CountType.FormattingEnabled = true;
+            this.CountType.Items.AddRange(new object[] {
+            "PLC",
+            "计数器"});
+            this.CountType.Location = new System.Drawing.Point(356, 620);
+            this.CountType.Margin = new System.Windows.Forms.Padding(6, 6, 6, 6);
+            this.CountType.Name = "CountType";
+            this.CountType.Size = new System.Drawing.Size(300, 46);
+            this.CountType.TabIndex = 17;
+            // 
+            // Confirm
+            // 
+            this.Confirm.Font = new System.Drawing.Font("微软雅黑", 10.8F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
+            this.Confirm.Location = new System.Drawing.Point(118, 700);
+            this.Confirm.Margin = new System.Windows.Forms.Padding(8, 6, 8, 6);
+            this.Confirm.Name = "Confirm";
+            this.Confirm.Size = new System.Drawing.Size(224, 70);
+            this.Confirm.TabIndex = 18;
+            this.Confirm.Text = "确定";
+            this.Confirm.UseVisualStyleBackColor = true;
+            this.Confirm.Click += new System.EventHandler(this.Confirm_Click);
+            // 
+            // Cancel
+            // 
+            this.Cancel.Font = new System.Drawing.Font("微软雅黑", 10.8F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
+            this.Cancel.Location = new System.Drawing.Point(374, 700);
+            this.Cancel.Margin = new System.Windows.Forms.Padding(8, 6, 8, 6);
+            this.Cancel.Name = "Cancel";
+            this.Cancel.Size = new System.Drawing.Size(224, 70);
+            this.Cancel.TabIndex = 19;
+            this.Cancel.Text = "关闭";
+            this.Cancel.UseVisualStyleBackColor = true;
+            this.Cancel.Click += new System.EventHandler(this.Cancel_Click);
+            // 
+            // AutoSMTRXYSetting
+            // 
+            this.AutoScaleDimensions = new System.Drawing.SizeF(12F, 24F);
+            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
+            this.ClientSize = new System.Drawing.Size(716, 808);
+            this.Controls.Add(this.label3);
+            this.Controls.Add(this.Password);
+            this.Controls.Add(this.ComPort_label);
+            this.Controls.Add(this.ComPort);
+            this.Controls.Add(this.BaudRate_label);
+            this.Controls.Add(this.BaudRate);
+            this.Controls.Add(this.Read_label);
+            this.Controls.Add(this.Read);
+            this.Controls.Add(this.ToZero_label);
+            this.Controls.Add(this.ToZero);
+            this.Controls.Add(this.label6);
+            this.Controls.Add(this.Stop);
+            this.Controls.Add(this.UseScan_label);
+            this.Controls.Add(this.UseScan);
+            this.Controls.Add(this.Write_label);
+            this.Controls.Add(this.Write);
+            this.Controls.Add(this.CountType_label);
+            this.Controls.Add(this.CountType);
+            this.Controls.Add(this.Confirm);
+            this.Controls.Add(this.Cancel);
+            this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
+            this.Margin = new System.Windows.Forms.Padding(8, 6, 8, 6);
+            this.MaximizeBox = false;
+            this.MinimizeBox = false;
+            this.Name = "AutoSMTRXYSetting";
+            this.SizeGripStyle = System.Windows.Forms.SizeGripStyle.Hide;
+            this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
+            this.Text = "参数设置";
+            this.Load += new System.EventHandler(this.AutoSMTRXYSetting_Load);
+            this.ResumeLayout(false);
+            this.PerformLayout();
+
+        }
+
+        #endregion
+
+        private System.Windows.Forms.Label label3;
+        private System.Windows.Forms.TextBox Password;
+        private System.Windows.Forms.Label ComPort_label;
+        private SerialPortCombox ComPort;
+        private System.Windows.Forms.Label BaudRate_label;
+        private System.Windows.Forms.TextBox BaudRate;
+        private System.Windows.Forms.Label Read_label;
+        private System.Windows.Forms.TextBox Read;
+        private System.Windows.Forms.Label ToZero_label;
+        private System.Windows.Forms.TextBox ToZero;
+        private System.Windows.Forms.Label label6;
+        private System.Windows.Forms.TextBox Stop;
+        private System.Windows.Forms.Label UseScan_label;
+        private System.Windows.Forms.TextBox UseScan;
+        private System.Windows.Forms.Label Write_label;
+        private System.Windows.Forms.TextBox Write;
+        private System.Windows.Forms.Label CountType_label;
+        private System.Windows.Forms.ComboBox CountType;
+        private System.Windows.Forms.Button Confirm;
+        private System.Windows.Forms.Button Cancel;
+    }
+}

+ 121 - 0
FileWatcher/AutoSMTRXYSetting.cs

@@ -0,0 +1,121 @@
+using System;
+using System.Windows.Forms;
+
+namespace FileWatcher
+{
+    public partial class AutoSMTRXYSetting : Form
+    {
+        /// <summary>
+        /// 设置参数解锁密码
+        /// </summary>
+        private const string SettingPassword = "1234";
+
+        /// <summary>
+        /// 是否已通过密码解锁
+        /// </summary>
+        private bool UnLocked = false;
+
+        public AutoSMTRXYSetting()
+        {
+            InitializeComponent();
+            StartPosition = FormStartPosition.CenterScreen;
+        }
+
+        private void AutoSMTRXYSetting_Load(object sender, EventArgs e)
+        {
+            ComPort.Text = GetCacheString("ComPort");
+            BaudRate.Text = GetCacheString("BaudRate");
+            Read.Text = GetCacheString("Read");
+            Write.Text = GetCacheString("Write");
+            Stop.Text = GetCacheString("Stop");
+            ToZero.Text = GetCacheString("ToZero");
+            UseScan.Text = GetCacheString("UseScan");
+            CountType.Text = GetCacheString("CountType");
+            if (BaudRate.Text == "")
+            {
+                BaudRate.Text = "9600";
+            }
+            if (CountType.Text == "")
+            {
+                CountType.Text = "PLC";
+            }
+            LockControls();
+        }
+
+        private string GetCacheString(string ParamName)
+        {
+            object value = BaseUtil.GetCacheData(ParamName);
+            return value == null ? "" : value.ToString();
+        }
+
+        /// <summary>
+        /// 锁定设置项(未输入密码前不可编辑)
+        /// </summary>
+        private void LockControls()
+        {
+            UnLocked = false;
+            ComPort.Enabled = false;
+            BaudRate.Enabled = false;
+            Read.Enabled = false;
+            Write.Enabled = false;
+            Stop.Enabled = false;
+            ToZero.Enabled = false;
+            UseScan.Enabled = false;
+            CountType.Enabled = false;
+            Password.Text = "";
+            Confirm.Text = "确定";
+        }
+
+        /// <summary>
+        /// 密码正确后解锁设置项
+        /// </summary>
+        private void UnLockControls()
+        {
+            UnLocked = true;
+            ComPort.Enabled = true;
+            BaudRate.Enabled = true;
+            Read.Enabled = true;
+            Write.Enabled = true;
+            Stop.Enabled = true;
+            ToZero.Enabled = true;
+            UseScan.Enabled = true;
+            CountType.Enabled = true;
+            Password.Text = "";
+            Confirm.Text = "保存";
+        }
+
+        private void Confirm_Click(object sender, EventArgs e)
+        {
+            if (!UnLocked)
+            {
+                //未解锁时先校验密码
+                if (Password.Text == SettingPassword)
+                {
+                    UnLockControls();
+                }
+                else
+                {
+                    MessageBox.Show(this, "密码不对", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
+                }
+                return;
+            }
+            //解锁状态下点击则保存并关闭
+            BaseUtil.SetCacheData("ComPort", ComPort.Text);
+            BaseUtil.SetCacheData("BaudRate", BaudRate.Text);
+            BaseUtil.SetCacheData("Read", Read.Text);
+            BaseUtil.SetCacheData("Write", Write.Text);
+            BaseUtil.SetCacheData("Stop", Stop.Text);
+            BaseUtil.SetCacheData("ToZero", ToZero.Text);
+            BaseUtil.SetCacheData("UseScan", UseScan.Text);
+            BaseUtil.SetCacheData("CountType", CountType.Text);
+            MessageBox.Show(this, "保存成功", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
+            DialogResult = DialogResult.OK;
+            Close();
+        }
+
+        private void Cancel_Click(object sender, EventArgs e)
+        {
+            Close();
+        }
+    }
+}

+ 120 - 0
FileWatcher/AutoSMTRXYSetting.resx

@@ -0,0 +1,120 @@
+<?xml version="1.0" encoding="utf-8"?>
+<root>
+  <!-- 
+    Microsoft ResX Schema 
+    
+    Version 2.0
+    
+    The primary goals of this format is to allow a simple XML format 
+    that is mostly human readable. The generation and parsing of the 
+    various data types are done through the TypeConverter classes 
+    associated with the data types.
+    
+    Example:
+    
+    ... ado.net/XML headers & schema ...
+    <resheader name="resmimetype">text/microsoft-resx</resheader>
+    <resheader name="version">2.0</resheader>
+    <resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
+    <resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
+    <data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
+    <data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
+    <data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
+        <value>[base64 mime encoded serialized .NET Framework object]</value>
+    </data>
+    <data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
+        <value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
+        <comment>This is a comment</comment>
+    </data>
+                
+    There are any number of "resheader" rows that contain simple 
+    name/value pairs.
+    
+    Each data row contains a name, and value. The row also contains a 
+    type or mimetype. Type corresponds to a .NET class that support 
+    text/value conversion through the TypeConverter architecture. 
+    Classes that don't support this are serialized and stored with the 
+    mimetype set.
+    
+    The mimetype is used for serialized objects, and tells the 
+    ResXResourceReader how to depersist the object. This is currently not 
+    extensible. For a given mimetype the value must be set accordingly:
+    
+    Note - application/x-microsoft.net.object.binary.base64 is the format 
+    that the ResXResourceWriter will generate, however the reader can 
+    read any of the formats listed below.
+    
+    mimetype: application/x-microsoft.net.object.binary.base64
+    value   : The object must be serialized with 
+            : System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
+            : and then encoded with base64 encoding.
+    
+    mimetype: application/x-microsoft.net.object.soap.base64
+    value   : The object must be serialized with 
+            : System.Runtime.Serialization.Formatters.Soap.SoapFormatter
+            : and then encoded with base64 encoding.
+
+    mimetype: application/x-microsoft.net.object.bytearray.base64
+    value   : The object must be serialized into a byte array 
+            : using a System.ComponentModel.TypeConverter
+            : and then encoded with base64 encoding.
+    -->
+  <xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
+    <xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
+    <xsd:element name="root" msdata:IsDataSet="true">
+      <xsd:complexType>
+        <xsd:choice maxOccurs="unbounded">
+          <xsd:element name="metadata">
+            <xsd:complexType>
+              <xsd:sequence>
+                <xsd:element name="value" type="xsd:string" minOccurs="0" />
+              </xsd:sequence>
+              <xsd:attribute name="name" use="required" type="xsd:string" />
+              <xsd:attribute name="type" type="xsd:string" />
+              <xsd:attribute name="mimetype" type="xsd:string" />
+              <xsd:attribute ref="xml:space" />
+            </xsd:complexType>
+          </xsd:element>
+          <xsd:element name="assembly">
+            <xsd:complexType>
+              <xsd:attribute name="alias" type="xsd:string" />
+              <xsd:attribute name="name" type="xsd:string" />
+            </xsd:complexType>
+          </xsd:element>
+          <xsd:element name="data">
+            <xsd:complexType>
+              <xsd:sequence>
+                <xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
+                <xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
+              </xsd:sequence>
+              <xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
+              <xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
+              <xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
+              <xsd:attribute ref="xml:space" />
+            </xsd:complexType>
+          </xsd:element>
+          <xsd:element name="resheader">
+            <xsd:complexType>
+              <xsd:sequence>
+                <xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
+              </xsd:sequence>
+              <xsd:attribute name="name" type="xsd:string" use="required" />
+            </xsd:complexType>
+          </xsd:element>
+        </xsd:choice>
+      </xsd:complexType>
+    </xsd:element>
+  </xsd:schema>
+  <resheader name="resmimetype">
+    <value>text/microsoft-resx</value>
+  </resheader>
+  <resheader name="version">
+    <value>2.0</value>
+  </resheader>
+  <resheader name="reader">
+    <value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
+  </resheader>
+  <resheader name="writer">
+    <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
+  </resheader>
+</root>

+ 9 - 0
FileWatcher/FileWatcher.csproj

@@ -175,6 +175,12 @@
     <Compile Include="AutoSMTRXY.Designer.cs">
       <DependentUpon>AutoSMTRXY.cs</DependentUpon>
     </Compile>
+    <Compile Include="AutoSMTRXYSetting.cs">
+      <SubType>Form</SubType>
+    </Compile>
+    <Compile Include="AutoSMTRXYSetting.Designer.cs">
+      <DependentUpon>AutoSMTRXYSetting.cs</DependentUpon>
+    </Compile>
     <Compile Include="LogManager.cs" />
     <Compile Include="RichTextAutoBottom.cs">
       <SubType>Component</SubType>
@@ -358,6 +364,9 @@
     <EmbeddedResource Include="AutoSMTRXY.resx">
       <DependentUpon>AutoSMTRXY.cs</DependentUpon>
     </EmbeddedResource>
+    <EmbeddedResource Include="AutoSMTRXYSetting.resx">
+      <DependentUpon>AutoSMTRXYSetting.cs</DependentUpon>
+    </EmbeddedResource>
     <EmbeddedResource Include="SOP_PNE.resx">
       <DependentUpon>SOP_PNE.cs</DependentUpon>
     </EmbeddedResource>