bug
lu
2025-05-09 a282306f6e638fd1751f3ce295e9a2876503117e
bug
已修改4个文件
99 ■■■■ 文件已修改
DevApp/Gs.DevApp/Program.cs 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
DevApp/Gs.DevApp/ToolBox/UtilityHelper.cs 22 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
DevApp/Gs.DevApp/XtraForm1.Designer.cs 19 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
DevApp/Gs.DevApp/XtraForm1.cs 54 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
DevApp/Gs.DevApp/Program.cs
@@ -38,8 +38,8 @@
        /// </summary>
        private static void _startLogin()
        {
            Application.Run(new XtraForm1());
            return;
            //Application.Run(new XtraForm1());
            //return;
            CefSettings settings = new CefSettings();
            settings.Locale = "zh-CN";
            Cef.Initialize(settings);
DevApp/Gs.DevApp/ToolBox/UtilityHelper.cs
@@ -2113,6 +2113,15 @@
                return true;
            return false;
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="box1">txt_psnQty_1:每张条码数量</param>
        /// <param name="box2">txt_iCount_1:整张数值</param>
        /// <param name="sum">txt_kQty:可打印量</param>
        /// <param name="rd"></param>
        /// <param name="txt_yuliang">txt_yuliang:余量</param>
        public static void PrintJiSuan(DevExpress.XtraEditors.TextEdit box1, DevExpress.XtraEditors.TextEdit box2, string sum, DevExpress.XtraEditors.RadioGroup rd, DevExpress.XtraEditors.TextEdit txt_yuliang = null)
        {
            if (rd.SelectedIndex == 2)
@@ -2129,11 +2138,16 @@
                decimal? dc1 = Gs.DevApp.ToolBox.UtilityHelper.GetDecimal(t1);
                decimal dividend = decimal.Parse(sum); // 被除数
                decimal divisor = decimal.Parse(t1);   // 除数
                decimal quotient = dividend / divisor; // 整数部分
                decimal remainder = dividend % divisor; // 余数
                box2.Text = quotient.ToString();
                decimal shang = dividend / divisor;
                decimal integerPart = Math.Truncate(shang); // 获取整数部分
                decimal decimalPart = dividend - divisor* integerPart; // 获取小数部分
                //decimal quotient = dividend / divisor; // 整数部分
                //decimal remainder = dividend % divisor; // 余数
                box2.Text = integerPart.ToString();
                if (rd.SelectedIndex == 0)
                    txt_yuliang.Text = remainder.ToString();
                    txt_yuliang.Text = decimalPart.ToString();
            }
            catch (Exception ex)
            {
DevApp/Gs.DevApp/XtraForm1.Designer.cs
@@ -30,31 +30,41 @@
        {
            this.simpleButton1 = new DevExpress.XtraEditors.SimpleButton();
            this.simpleButton2 = new DevExpress.XtraEditors.SimpleButton();
            this.richTextBox1 = new System.Windows.Forms.RichTextBox();
            this.SuspendLayout();
            // 
            // simpleButton1
            // 
            this.simpleButton1.Location = new System.Drawing.Point(146, 51);
            this.simpleButton1.Location = new System.Drawing.Point(57, 107);
            this.simpleButton1.Name = "simpleButton1";
            this.simpleButton1.Size = new System.Drawing.Size(94, 29);
            this.simpleButton1.TabIndex = 0;
            this.simpleButton1.Text = "simpleButton1";
            this.simpleButton1.Text = "电检数据";
            this.simpleButton1.Click += new System.EventHandler(this.simpleButton1_Click_1);
            // 
            // simpleButton2
            // 
            this.simpleButton2.Location = new System.Drawing.Point(146, 234);
            this.simpleButton2.Location = new System.Drawing.Point(57, 173);
            this.simpleButton2.Name = "simpleButton2";
            this.simpleButton2.Size = new System.Drawing.Size(94, 29);
            this.simpleButton2.TabIndex = 1;
            this.simpleButton2.Text = "水检按钮";
            this.simpleButton2.Text = "水检数据";
            this.simpleButton2.Click += new System.EventHandler(this.simpleButton2_Click);
            //
            // richTextBox1
            //
            this.richTextBox1.Location = new System.Drawing.Point(57, 227);
            this.richTextBox1.Name = "richTextBox1";
            this.richTextBox1.Size = new System.Drawing.Size(740, 240);
            this.richTextBox1.TabIndex = 2;
            this.richTextBox1.Text = "";
            // 
            // XtraForm1
            // 
            this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 18F);
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.ClientSize = new System.Drawing.Size(887, 659);
            this.Controls.Add(this.richTextBox1);
            this.Controls.Add(this.simpleButton2);
            this.Controls.Add(this.simpleButton1);
            this.Name = "XtraForm1";
@@ -67,5 +77,6 @@
        private DevExpress.XtraEditors.SimpleButton simpleButton1;
        private DevExpress.XtraEditors.SimpleButton simpleButton2;
        private System.Windows.Forms.RichTextBox richTextBox1;
    }
}
DevApp/Gs.DevApp/XtraForm1.cs
@@ -80,7 +80,6 @@
                    JNV = (((JObject)ss)["JiaoNai"] == null) ? "" : ((JObject)ss)["JiaoNai"]["value"].ToString().Replace(" ", ", ");
                    XLV = (((JObject)ss)["XieLou"] == null) ? "" : ((JObject)ss)["XieLou"]["value"].ToString().Replace(" ", ", ");
                    GVV = (((JObject)ss)["GongLv"] == null) ? "" : ((JObject)ss)["GongLv"]["value"].ToString().Replace(" ", ", ");
                    Gs.DevApp.ToolBox.LogHelper.Debug("TM", TM);
                    Gs.DevApp.ToolBox.LogHelper.Debug("JD", JD);
                    Gs.DevApp.ToolBox.LogHelper.Debug("JY", JY);
@@ -111,49 +110,74 @@
            string SJJG = "";
            try//水检取数,后面补充
            {
                string hostname = "192.168.1.5";
                System.Text.StringBuilder stringBuilder = new System.Text.StringBuilder();
                string hostname = "192.168.60.51";
                ModbusFactory modbusFactory = new ModbusFactory();
                IModbusMaster master = modbusFactory.CreateMaster(new TcpClient(hostname, 26));
                IModbusMaster master = modbusFactory.CreateMaster(new TcpClient(hostname, 502));
                master.Transport.ReadTimeout = 10000;
                master.Transport.Retries = 10000;
                DataTable dt = new DataTable();
                //参数(分别为从站地址,起始地址,长度)
                byte slaveAddress = byte.Parse(dt.Rows[0][0].ToString());
                byte slaveAddress = byte.Parse(1.ToString());
                ushort numberOfPoints = ushort.Parse("1");
                float fsw = 0;
                DataTable dt1 = new DataTable();
                ushort[] csl1 = master.ReadHoldingRegisters(slaveAddress, ushort.Parse(dt1.Rows[0]["MIG003"].ToString()), numberOfPoints);
                ushort[] csl1 = master.ReadHoldingRegisters(slaveAddress, ushort.Parse(32.ToString()), numberOfPoints);
                strCsl1 = csl1[0].ToString();
                ushort[] sw1 = master.ReadHoldingRegisters(slaveAddress, ushort.Parse(dt1.Rows[1]["MIG003"].ToString()), numberOfPoints);
                ushort[] sw1 = master.ReadHoldingRegisters(slaveAddress, ushort.Parse(31.ToString()), numberOfPoints);
                strSw1 = (float.Parse(sw1[0].ToString()) / 10).ToString();
                ushort[] csl2 = master.ReadHoldingRegisters(slaveAddress, ushort.Parse(dt1.Rows[2]["MIG003"].ToString()), numberOfPoints);
                ushort[] csl2 = master.ReadHoldingRegisters(slaveAddress, ushort.Parse(34.ToString()), numberOfPoints);
                strCsl2 = csl2[0].ToString();
                ushort[] sw2 = master.ReadHoldingRegisters(slaveAddress, ushort.Parse(dt1.Rows[3]["MIG003"].ToString()), numberOfPoints);
                ushort[] sw2 = master.ReadHoldingRegisters(slaveAddress, ushort.Parse(33.ToString()), numberOfPoints);
                strSw2 = (float.Parse(sw2[0].ToString()) / 10).ToString();
                ushort[] csl3 = master.ReadHoldingRegisters(slaveAddress, ushort.Parse(dt1.Rows[4]["MIG003"].ToString()), numberOfPoints);
                ushort[] csl3 = master.ReadHoldingRegisters(slaveAddress, ushort.Parse(36.ToString()), numberOfPoints);
                strCsl3 = csl3[0].ToString();
                ushort[] sw3 = master.ReadHoldingRegisters(slaveAddress, ushort.Parse(dt1.Rows[5]["MIG003"].ToString()), numberOfPoints);
                ushort[] sw3 = master.ReadHoldingRegisters(slaveAddress, ushort.Parse(35.ToString()), numberOfPoints);
                strSw3 = (float.Parse(sw3[0].ToString()) / 10).ToString();
                ushort[] csl4 = master.ReadHoldingRegisters(slaveAddress, ushort.Parse(dt1.Rows[6]["MIG003"].ToString()), numberOfPoints);
                ushort[] csl4 = master.ReadHoldingRegisters(slaveAddress, ushort.Parse(38.ToString()), numberOfPoints);
                strCsl4 = csl4[0].ToString();
                ushort[] sw4 = master.ReadHoldingRegisters(slaveAddress, ushort.Parse(dt1.Rows[7]["MIG003"].ToString()), numberOfPoints);
                ushort[] sw4 = master.ReadHoldingRegisters(slaveAddress, ushort.Parse(37.ToString()), numberOfPoints);
                strSw4 = (float.Parse(sw4[0].ToString()) / 10).ToString();
                ushort[] csl5 = master.ReadHoldingRegisters(slaveAddress, ushort.Parse(dt1.Rows[8]["MIG003"].ToString()), numberOfPoints);
                ushort[] csl5 = master.ReadHoldingRegisters(slaveAddress, ushort.Parse(40.ToString()), numberOfPoints);
                strCsl5 = csl5[0].ToString();
                ushort[] sw5 = master.ReadHoldingRegisters(slaveAddress, ushort.Parse(dt1.Rows[9]["MIG003"].ToString()), numberOfPoints);
                ushort[] sw5 = master.ReadHoldingRegisters(slaveAddress, ushort.Parse(39.ToString()), numberOfPoints);
                strSw5 = (float.Parse(sw5[0].ToString()) / 10).ToString();
                bool[] sjjg = master.ReadCoils(slaveAddress, ushort.Parse(dt1.Rows[10]["MIG003"].ToString()), numberOfPoints);
                bool[] sjjg = master.ReadCoils(slaveAddress, ushort.Parse(77.ToString()), numberOfPoints);
                SJJG = sjjg[0].ToString();
                ///////////////////
                ///
                // 3. 读取从站设备的寄存器
                ushort startAddress = 0;   // 寄存器起始地址
                ushort numRegisters = 100;  // 读取 10 个寄存器
                try
                {
                    // 读取保持寄存器(从站地址为 1)
                    ushort[] registers = master.ReadHoldingRegisters(1, startAddress, numRegisters);
                    // 输出结果
                    Console.WriteLine("读取到的寄存器值:");
                    foreach (var register in registers)
                    {
                        Console.WriteLine(register);
                        stringBuilder.Append(register);
                    }
                    richTextBox1.Text = stringBuilder.ToString();
                }
                catch (Exception ex)
                {
                    Console.WriteLine($"读取错误: {ex.Message}");
                }
            }
            catch (Exception ex)
            {