| | |
| | | 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 |
| | | { |
| | |
| | | { |
| | | Console.WriteLine($"发生错误:{ex}"); |
| | | } |
| | | dataGridView1.DataSource = System_Bll.GetSystemLog(FrmLogin.LocalIP, "称重"); |
| | | dataGridView1.DataSource = System_Bll.GetSystemLog(FrmLogin.LocalIP, "四码合一"); |
| | | macBox.Text = GetMacByNetworkInterface(); |
| | | |
| | | } |
| | |
| | | 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); |
| | |
| | | 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); ; |
| | | } |
| | | |
| | |
| | | CreateUserName = FrmLogin.loginUserName, |
| | | LocalIP = FrmLogin.LocalIP, |
| | | LogMessage = "WI6027调用失败!", |
| | | Type = "称重", |
| | | Type = "四码合一", |
| | | ClassName = typeof(FrmLogin).ToString() |
| | | }); |
| | | return; |
| | |
| | | } |
| | | } |
| | | } |
| | | dataGridView1.DataSource = System_Bll.GetSystemLog(FrmLogin.LocalIP, "称重"); |
| | | dataGridView1.DataSource = System_Bll.GetSystemLog(FrmLogin.LocalIP, "四码合一"); |
| | | Refresh(); |
| | | } |
| | | |
| | |
| | | CreateUserName = FrmLogin.loginUserName, |
| | | LocalIP = FrmLogin.LocalIP, |
| | | LogMessage = "WI601K接口调用失败:" + jo["content"].ToString(), |
| | | Type = "称重", |
| | | Type = "四码合一", |
| | | ClassName = typeof(FrmLogin).ToString() |
| | | }); |
| | | return false; |
| | |
| | | CreateUserName = FrmLogin.loginUserName, |
| | | LocalIP = FrmLogin.LocalIP, |
| | | LogMessage = "WI1032接口调用失败:" + jo["content"].ToString(), |
| | | Type = "称重", |
| | | Type = "四码合一", |
| | | ClassName = typeof(FrmLogin).ToString() |
| | | }); |
| | | return null; |
| | |
| | | CreateUserName = FrmLogin.loginUserName, |
| | | LocalIP = FrmLogin.LocalIP, |
| | | LogMessage = "WI6041接口调用失败:" + jo["content"].ToString(), |
| | | Type = "称重", |
| | | Type = "四码合一", |
| | | ClassName = typeof(FrmLogin).ToString() |
| | | }); |
| | | return false; |