yantian yue
2023-12-29 fdda48e034b2da82fb100ec04f5b51351477e2bb
YX/wt/Frmwt.cs
@@ -13,11 +13,11 @@
using System.Windows.Forms;
using System.Threading;
using System.Configuration;
using EasyModbus; // 引入EasyModbusTCP库 *****
using EasyModbus; // 引入EasyModbusTCP库
using System.IO.Ports;
using System.Net.NetworkInformation;
namespace YX.wt
namespace YX
{
    public partial class Frmwt : WindowParent
    {
@@ -49,7 +49,7 @@
            {
                Console.WriteLine($"发生错误:{ex}");
            }
            dataGridView1.DataSource = System_Bll.GetSystemLog(FrmLogin.LocalIP, "称重");
            dataGridView1.DataSource = System_Bll.GetSystemLog(FrmLogin.LocalIP, "四码合一");
            macBox.Text = GetMacByNetworkInterface();
        }
@@ -59,16 +59,13 @@
            while (true)
            {
                ProcessDelegate showProcess = new ProcessDelegate(LabelShow);
                //string str = "1\n2\n3\n";
                //str = str.Replace("\n", string.Empty); // 将 \n 替换为空字符串
                string str = ModbusTCPRead(5, 1).Trim("\n".ToCharArray());
                if (ModbusTCPRead(5, 1).Trim("\n".ToCharArray()) == "1")
                {
                    try
                    {
                        //PSN = ModbusTCPRead(5, 20).Replace("\n", string.Empty);
                        PSN = ModbusTCPReadString(25, 30).Replace("\0", string.Empty);
                        PSN = ModbusTCPReadString(25, 30).Replace("\0", string.Empty); //将\0替换为空字符串
                        PSN2 = ModbusTCPReadString(45, 20).Replace("\0", string.Empty);
                        PSN3 = ModbusTCPReadString(65, 20).Replace("\0", string.Empty);
                        label1.Invoke(showProcess);
@@ -87,26 +84,24 @@
            ConnectServer(ipAddress, port1);
            int[] data = tcpClient.ReadHoldingRegisters(startingAddress, quantity); // 读取寄存器数据
            string strData = ""; // 存储字符串数据
            //string str = "";
            //string str1 = "";
            //string str2 = "";
            string str = "";
            string str1 = "";
            string str2 = "";
            for (int i = 0; i < quantity; i++)
            {
                //str= data[i].ToString("X");
                //if (str.Length == 4)
                //{
                //    str1 = str.Substring(2, 2);
                //    str2 = str.Substring(0, 2);
                //    strData += str1 + str2;
                //}
                //if (str.Length == 2)
                //{
                //    strData += str;
                //}
                strData += data[i].ToString("X");
                str = data[i].ToString("X");
                if (str.Length == 4)
                {
                    str1 = str.Substring(2, 2);
                    str2 = str.Substring(0, 2);
                    strData += str1 + str2;
                }
                if (str.Length == 2)
                {
                    strData += str;
                }
            }
            string str66 = hexStrToStr(strData);
            return hexStrToStr(strData); ;
        }
@@ -237,7 +232,7 @@
                    CreateUserName = FrmLogin.loginUserName,
                    LocalIP = FrmLogin.LocalIP,
                    LogMessage = "WI6027调用失败!",
                    Type = "称重",
                    Type = "四码合一",
                    ClassName = typeof(FrmLogin).ToString()
                });
                return;
@@ -268,7 +263,7 @@
                    }
                }
            }
            dataGridView1.DataSource = System_Bll.GetSystemLog(FrmLogin.LocalIP, "称重");
            dataGridView1.DataSource = System_Bll.GetSystemLog(FrmLogin.LocalIP, "四码合一");
            Refresh();
        }
@@ -350,7 +345,7 @@
                    CreateUserName = FrmLogin.loginUserName,
                    LocalIP = FrmLogin.LocalIP,
                    LogMessage = "WI601K接口调用失败:" + jo["content"].ToString(),
                    Type = "称重",
                    Type = "四码合一",
                    ClassName = typeof(FrmLogin).ToString()
                });
                return false;
@@ -381,7 +376,7 @@
                    CreateUserName = FrmLogin.loginUserName,
                    LocalIP = FrmLogin.LocalIP,
                    LogMessage = "WI1032接口调用失败:" + jo["content"].ToString(),
                    Type = "称重",
                    Type = "四码合一",
                    ClassName = typeof(FrmLogin).ToString()
                });
                return null;
@@ -438,7 +433,7 @@
                    CreateUserName = FrmLogin.loginUserName,
                    LocalIP = FrmLogin.LocalIP,
                    LogMessage = "WI6041接口调用失败:" + jo["content"].ToString(),
                    Type = "称重",
                    Type = "四码合一",
                    ClassName = typeof(FrmLogin).ToString()
                });
                return false;