| | |
| | | using DevExpress.Internal.WinApi; |
| | | using DevExpress.XtraBars.ToastNotifications; |
| | | using DevExpress.XtraEditors; |
| | | using DevExpress.XtraTreeList; |
| | | using Gs.DevApp.Entity; |
| | | using Gs.DevApp.ToolBox; |
| | | using Newtonsoft.Json; |
| | | using Newtonsoft.Json.Linq; |
| | | using NModbus; |
| | | using System; |
| | | using System.Collections.Generic; |
| | | using System.ComponentModel; |
| | | using System.Data; |
| | | using System.Drawing; |
| | | using System.Linq; |
| | | using System.IO; |
| | | using System.Net.Sockets; |
| | | using System.Text; |
| | | using System.Threading.Tasks; |
| | | using System.Windows.Forms; |
| | | |
| | | namespace Gs.DevApp |
| | | { |
| | |
| | | public XtraForm1() |
| | | { |
| | | InitializeComponent(); |
| | | |
| | | |
| | | } |
| | | /// <summary> |
| | | /// 是否第一次投入,0为第一次投入,1为维修过来要报废的2为已经报废过了的,3返工过来重投的4清尾工单的报废 |
| | | /// </summary> |
| | | private string flagFirst = "0"; //是否第一次投入 |
| | | |
| | | |
| | | private void simpleButton1_Click_1(object sender, EventArgs e) |
| | | { |
| | | AddDianJian(); |
| | | } |
| | | |
| | | private void simpleButton1_Click(object sender, EventArgs e) |
| | | //添加电检数据 |
| | | private string AddDianJian() |
| | | { |
| | | //toastNotificationsManager1 = new ToastNotificationsManager(); |
| | | //VanishingMessage vm = new VanishingMessage(System.Drawing.Color.OrangeRed, "操作成春树暮云顶戴槈"); |
| | | //vm.Show(); |
| | | string TM = ""; |
| | | string JD = ""; |
| | | string JY = ""; |
| | | string JN = ""; |
| | | string XL = ""; |
| | | string GV = ""; |
| | | string JDV = ""; |
| | | string JYV = ""; |
| | | string JNV = ""; |
| | | string XLV = ""; |
| | | string GVV = ""; |
| | | //if (imaQAB009.EditValue.ToString() != VSLoginInfo.SystemParam["DianJianNo"].ToString()) |
| | | //{ |
| | | // return ""; |
| | | //} |
| | | //string sql = string.Format(@" select MIG006 from BASMIG(nolock) where MIG001='DianJianQuShu' and MIG003='{0}' and MIG005='Y'", txtDAA042.EditValue.ToString()); |
| | | //DataTable dt = manager.GetDataTable(sql, "tmpBASMIG"); |
| | | //if (dt == null || dt.Rows.Count <= 0) |
| | | //{ |
| | | // return ""; |
| | | //} |
| | | try |
| | | { |
| | | //FileStream fs = new FileStream(dt.Rows[0][0].ToString(), FileMode.Open, FileAccess.Read, FileShare.ReadWrite); |
| | | //int fsLen = (int)fs.Length; |
| | | //byte[] heByte = new byte[fsLen]; |
| | | //fs.Read(heByte, 0, heByte.Length); |
| | | //string myStr = System.Text.Encoding.Default.GetString(heByte); |
| | | //fs.Close(); |
| | | string strPath = @"D:\uploadData.txt"; |
| | | string myStr = File.ReadAllText(strPath, Encoding.Default); |
| | | if (myStr == "") |
| | | { |
| | | return "NULL"; |
| | | } |
| | | File.WriteAllText(strPath, ""); |
| | | JArray dsTemp = JArray.Parse(myStr); |
| | | |
| | | Toast vm = new Toast(System.Drawing.Color.DodgerBlue, "操作成春树暮云顶戴槈"); |
| | | vm.Show(); |
| | | |
| | | foreach (var ss in dsTemp) //查找某个字段与值 |
| | | { |
| | | TM = (((JObject)ss)["TiaoMa"] == null) ? "" : ((JObject)ss)["TiaoMa"].ToString(); |
| | | JD = (((JObject)ss)["JieDi"] == null) ? "" : ((JObject)ss)["JieDi"]["state"].ToString(); |
| | | JY = (((JObject)ss)["JueYuan"] == null) ? "" : ((JObject)ss)["JueYuan"]["state"].ToString(); |
| | | JN = (((JObject)ss)["JiaoNai"] == null) ? "" : ((JObject)ss)["JiaoNai"]["state"].ToString(); |
| | | XL = (((JObject)ss)["XieLou"] == null) ? "" : ((JObject)ss)["XieLou"]["state"].ToString(); |
| | | GV = (((JObject)ss)["GongLv"] == null) ? "" : ((JObject)ss)["GongLv"]["state"].ToString(); |
| | | JDV = (((JObject)ss)["JieDi"] == null) ? "" : ((JObject)ss)["JieDi"]["value"].ToString().Replace(" ", ", "); |
| | | JYV = (((JObject)ss)["JueYuan"] == null) ? "" : ((JObject)ss)["JueYuan"]["value"].ToString().Replace(" ", ", "); |
| | | 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); |
| | | Gs.DevApp.ToolBox.LogHelper.Debug("XL", XL); |
| | | Gs.DevApp.ToolBox.LogHelper.Debug("XLV", XLV); |
| | | Gs.DevApp.ToolBox.LogHelper.Debug("GVV", GVV); |
| | | } |
| | | return "已采集"; |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | return "文件打开失败," + e.Message; |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 水检 |
| | | /// </summary> |
| | | /// <param name="sender"></param> |
| | | /// <param name="e"></param> |
| | | |
| | | private void simpleButton2_Click(object sender, EventArgs e) |
| | | { |
| | | string strCsl1 = ""; |
| | | string strSw1 = ""; |
| | | string strCsl2 = ""; |
| | | string strSw2 = ""; |
| | | string strCsl3 = ""; |
| | | string strSw3 = ""; |
| | | string strCsl4 = ""; |
| | | string strSw4 = ""; |
| | | string strCsl5 = ""; |
| | | string strSw5 = ""; |
| | | string SJJG = ""; |
| | | try//水检取数,后面补充 |
| | | { |
| | | 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, 502)); |
| | | master.Transport.ReadTimeout = 10000; |
| | | master.Transport.Retries = 10000; |
| | | DataTable dt = new DataTable(); |
| | | //参数(分别为从站地址,起始地址,长度) |
| | | 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(32.ToString()), numberOfPoints); |
| | | strCsl1 = csl1[0].ToString(); |
| | | |
| | | 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(34.ToString()), numberOfPoints); |
| | | strCsl2 = csl2[0].ToString(); |
| | | |
| | | 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(36.ToString()), numberOfPoints); |
| | | strCsl3 = csl3[0].ToString(); |
| | | |
| | | 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(38.ToString()), numberOfPoints); |
| | | strCsl4 = csl4[0].ToString(); |
| | | |
| | | 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(40.ToString()), numberOfPoints); |
| | | strCsl5 = csl5[0].ToString(); |
| | | |
| | | 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(77.ToString()), numberOfPoints); |
| | | SJJG = sjjg[0].ToString(); |
| | | /////////////////// |
| | | /// |
| | | |
| | | // 3. 读取从站设备的寄存器 |
| | | ushort startAddress = 0; // 寄存器起始地址 |
| | | ushort numRegisters = 125; // 读取 10 个寄存器 |
| | | try |
| | | { |
| | | // 读取保持寄存器(从站地址为 1) |
| | | ushort[] registers = master.ReadHoldingRegisters(1, startAddress, numRegisters); |
| | | // 输出结果 |
| | | Console.WriteLine("读取到的寄存器值:"); |
| | | foreach (var register in registers) |
| | | { |
| | | Console.WriteLine(register); |
| | | stringBuilder.Append(register.ToString()); |
| | | } |
| | | richTextBox1.Text = stringBuilder.ToString(); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | Console.WriteLine($"读取错误: {ex.Message}"); |
| | | } |
| | | |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | //VisiblePanel(txtDQBarCode.EditValue.ToString(), ex.Message, "NG", Color.Yellow); |
| | | //txtGWM.EditValue = ""; |
| | | return; |
| | | } |
| | | |
| | | } |
| | | } |
| | | } |