lu
2025-05-09 9a39c7926a855b8b71f753c6fc50e704890c54a7
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
using Newtonsoft.Json.Linq;
using NModbus;
using System;
using System.Data;
using System.IO;
using System.Net.Sockets;
using System.Text;
 
namespace Gs.DevApp
{
    public partial class XtraForm1 : DevExpress.XtraEditors.XtraForm
    {
        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 string AddDianJian()
        {
            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);
 
                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;
            }
        }
 
        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//水检取数,后面补充
            {
                string hostname = "192.168.1.5";
                ModbusFactory modbusFactory = new ModbusFactory();
                IModbusMaster master = modbusFactory.CreateMaster(new TcpClient(hostname, 26));
                master.Transport.ReadTimeout = 10000;
                master.Transport.Retries = 10000;
                DataTable dt = new DataTable();
                //参数(分别为从站地址,起始地址,长度)
                byte slaveAddress = byte.Parse(dt.Rows[0][0].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);
                strCsl1 = csl1[0].ToString();
 
                ushort[] sw1 = master.ReadHoldingRegisters(slaveAddress, ushort.Parse(dt1.Rows[1]["MIG003"].ToString()), numberOfPoints);
                strSw1 = (float.Parse(sw1[0].ToString()) / 10).ToString();
 
                ushort[] csl2 = master.ReadHoldingRegisters(slaveAddress, ushort.Parse(dt1.Rows[2]["MIG003"].ToString()), numberOfPoints);
                strCsl2 = csl2[0].ToString();
 
                ushort[] sw2 = master.ReadHoldingRegisters(slaveAddress, ushort.Parse(dt1.Rows[3]["MIG003"].ToString()), numberOfPoints);
                strSw2 = (float.Parse(sw2[0].ToString()) / 10).ToString();
 
                ushort[] csl3 = master.ReadHoldingRegisters(slaveAddress, ushort.Parse(dt1.Rows[4]["MIG003"].ToString()), numberOfPoints);
                strCsl3 = csl3[0].ToString();
 
                ushort[] sw3 = master.ReadHoldingRegisters(slaveAddress, ushort.Parse(dt1.Rows[5]["MIG003"].ToString()), numberOfPoints);
                strSw3 = (float.Parse(sw3[0].ToString()) / 10).ToString();
 
                ushort[] csl4 = master.ReadHoldingRegisters(slaveAddress, ushort.Parse(dt1.Rows[6]["MIG003"].ToString()), numberOfPoints);
                strCsl4 = csl4[0].ToString();
 
                ushort[] sw4 = master.ReadHoldingRegisters(slaveAddress, ushort.Parse(dt1.Rows[7]["MIG003"].ToString()), numberOfPoints);
                strSw4 = (float.Parse(sw4[0].ToString()) / 10).ToString();
 
                ushort[] csl5 = master.ReadHoldingRegisters(slaveAddress, ushort.Parse(dt1.Rows[8]["MIG003"].ToString()), numberOfPoints);
                strCsl5 = csl5[0].ToString();
 
                ushort[] sw5 = master.ReadHoldingRegisters(slaveAddress, ushort.Parse(dt1.Rows[9]["MIG003"].ToString()), numberOfPoints);
                strSw5 = (float.Parse(sw5[0].ToString()) / 10).ToString();
 
                bool[] sjjg = master.ReadCoils(slaveAddress, ushort.Parse(dt1.Rows[10]["MIG003"].ToString()), numberOfPoints);
                SJJG = sjjg[0].ToString();
            }
            catch (Exception ex)
            {
                //VisiblePanel(txtDQBarCode.EditValue.ToString(), ex.Message, "NG", Color.Yellow);
                //txtGWM.EditValue = "";
                return;
            }
 
        }
    }
}