ningshuxia
2022-10-28 3ccb7c60e1ed8b6748ed7fb8b64b1dbe50d62abf
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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
 
namespace TProduct.Link.Debugger.RS485
{
    /// <summary>
    /// 南通农业
    /// </summary>
    internal class NtnyMsgHelper
    {
 
 
 
 
        /// <summary>
        /// 获取控制指令(真空泵_关)
        /// </summary>
        /// <returns></returns>
        public byte[] GetControlMsg调频(double frequece)
        {
            var iFrequece = (int)(frequece * 10);
 
            byte[] commandSend = null;
            TProduct.RS485.ModBusRtuHelper.BuildSendMessage06(0x01, 20, 2, iFrequece, ref commandSend);
 
            return commandSend;
        }
 
        /// <summary>
        /// 获取查询指令(监控值)
        /// </summary>
        /// <returns></returns>
        public byte[] GetMonitorMsg监控值()
        {
            return new byte[] { 0x01, 0x03, 0x00, 0x19, 0x00, 0x19, 0x55, 0xC7 };
        }
 
 
 
        /// <summary>
        /// 获取查询指令(状态值)
        /// </summary>
        /// <returns></returns>
        public byte[] GetMonitorMsg状态值()
        {
            return new byte[] { 0x01, 0x03, 0x00, 0x19, 0x00, 0x23, 0xD5, 0xD4 };
        }
 
 
 
        public class MonitorValvue
        {
            public long ID { get; set; }
            public double Value { get; set; }
        }
 
        /// <summary>
        /// 字符串转16进制字符2
        /// </summary>
        /// <param name="content">字符串</param>
        /// <param name="encode">编码格式</param>
        /// <returns></returns>
        private List<byte> StringToHexValuve(string content, out string error_info)
        {
            //去掉空格
            string[] arr = content.Split(' ');
 
            if (arr.Length < 3)
            {
                error_info = "字符无法解析";
                return null;
            }
            List<byte> result = new List<byte>();
            for (int i = 0; i < arr.Length; i++)
            {
                if (string.IsNullOrWhiteSpace(arr[i]))
                    continue;
 
                var dddd = Convert.ToByte(arr[i], 16);
                result.Add(dddd);
            }
            error_info = null;
            return result;
        }
 
 
        /// <summary>
        /// 分析监控数据
        /// </summary>
        /// <param name="msg"></param>
        /// <returns></returns>
  /*      public List<MonitorValvue> AnaReceiveMonitorMsg(string msg)
        {
            string error_info;
            var byteMessage = StringToHexValuve(msg, out error_info);
            if (byteMessage == null)
            {
                MessageBox.Show(error_info);
            }
            else
            {
                return ReadMessage监控值(byteMessage);
            }
        }
        /// <summary>
        /// 读取消息(监控值)
        /// </summary>
        /// <param name="byteMessage"></param>
        private List<MonitorValvue> ReadMessage监控值(List<byte> byteMessage)
        {
            try
            {
                //显示消息
                //string strMessage = BitConverter.ToString(byteMessage, 0, byteMessage.Length);
                //DisplayMessage(string.Format(" 收到的消息:  {0} ", strMessage));
 
 
                //DisplayMessage(string.Format(" 设备地址: {0} (0x{1})", byteMessage[0], Convert.ToString(byteMessage[0], 16)));
                //DisplayMessage(string.Format(" 功能码: {0} ", byteMessage[1]));
 
                byte start = 0x1A;
                string msg;
 
                //当前管网压力:26
                //3 = 3+(26-26)*2
                DisplayMessage(string.Format("########当前管网压力 -----> {0} Mpa 数据二进制{1}", GetInt2Byte(byteMessage, 3, out msg), msg));//0.001Mpa
                //变频频率:27
                //5 = 3+(27-26)*2
                DisplayMessage(string.Format("########变频频率 -----> {0} Hz 数据二进制{1}", GetInt2Byte(byteMessage, 3 + (27 - start) * 2, out msg) * 0.1, msg));//0.1HZ
                //变频电流:28
                DisplayMessage(string.Format("########变频电流 -----> {0} A 数据二进制{1}", GetInt2Byte(byteMessage, 3 + (28 - start) * 2, out msg) * 0.1, msg));//0.1A
                //真空当前压力:29
                DisplayMessage(string.Format("########真空当前压力 -----> {0} Mpa 数据二进制{1}", GetInt2Byte(byteMessage, 3 + (29 - start) * 2, out msg) * 0.001, msg));//0.001Mpa
                //A相电压:30
                //3 = 3+(30-26)*2
                DisplayMessage(string.Format("########A相电压 -----> {0}  数据二进制{1}  ", GetDouble1(byteMessage, 3 + (30 - start) * 2, out msg), msg));
                //B相电压:32
                DisplayMessage(string.Format("########B相电压 -----> {0} 数据二进制{1}", GetDouble1(byteMessage, 3 + (32 - start) * 2, out msg), msg));
                //C相电压:34
                DisplayMessage(string.Format("########C相电压 -----> {0} 数据二进制{1} ", GetDouble1(byteMessage, 3 + (34 - start) * 2, out msg), msg));
 
                //A相电流:36
                DisplayMessage(string.Format("########A相电流 -----> {0} 数据二进制{1}", GetDouble1(byteMessage, 3 + (36 - start) * 2, out msg), msg));
                //B相电流:38
                DisplayMessage(string.Format("########B相电流 -----> {0} 数据二进制{1}", GetDouble1(byteMessage, 3 + (38 - start) * 2, out msg), msg));
                //C相电流:40
                DisplayMessage(string.Format("########C相电流 -----> {0} 数据二进制{1}", GetDouble1(byteMessage, 3 + (40 - start) * 2, out msg), msg));
 
                //变频泵状态:42
                DisplayMessage(string.Format("########变频泵状态 -----> {0}   数据二进制{1}", GetInt2Byte(byteMessage, 3 + (42 - start) * 2, out msg), msg));
                //真空泵状态 :43                                                                                                                                                                                                                                                                           //变频泵状态:42
                DisplayMessage(string.Format("########真空泵状态 -----> {0}   数据二进制{1}", GetInt2Byte(byteMessage, 3 + (43 - start) * 2, out msg), msg));
                //电动阀开阀状态 :44   
                DisplayMessage(string.Format("########电动阀开阀状态 -----> {0}   数据二进制{1}", GetInt2Byte(byteMessage, 3 + (44 - start) * 2, out msg), msg));
                //电动阀关阀状态 :45   
                DisplayMessage(string.Format("########电动阀关阀状态 -----> {0}   数据二进制{1}", GetInt2Byte(byteMessage, 3 + (45 - start) * 2, out msg), msg));
                //电磁阀状态 :46   
                DisplayMessage(string.Format("########电磁阀状态 -----> {0}   数据二进制{1}", GetInt2Byte(byteMessage, 3 + (46 - start) * 2, out msg), msg));
                //水位状态:47   
                DisplayMessage(string.Format("########水位状态 -----> {0}   数据二进制{1}", GetInt2Byte(byteMessage, 3 + (47 - start) * 2, out msg), msg));
                //超压状态:48   
                DisplayMessage(string.Format("########超压状态 -----> {0}   数据二进制{1}", GetInt2Byte(byteMessage, 3 + (48 - start) * 2, out msg), msg));
                //报警状态:49   
                DisplayMessage(string.Format("########报警状态 -----> {0}   数据二进制{1}", GetInt2Byte(byteMessage, 3 + (49 - start) * 2, out msg), msg));
                //变频器状态:50   
                DisplayMessage(string.Format("########变频器状态 -----> {0}   数据二进制{1}", GetInt2Byte(byteMessage, 3 + (50 - start) * 2, out msg), msg));
 
 
 
                //当前液位:51
                DisplayMessage(string.Format("########当前液位 -----> {0} 数据二进制{1} ", GetInt2Byte(byteMessage, 3 + (51 - start) * 2, out msg) * 0.01, msg));
                //瞬时流量:52
                DisplayMessage(string.Format("########瞬时流量 -----> {0} 数据二进制{1} ", GetInt4Byte(byteMessage, 3 + (52 - start) * 2, out msg) * 0.001, msg));
                //累计流量:54
                DisplayMessage(string.Format("########累计流量 -----> {0} 数据二进制{1} ", GetInt4Byte(byteMessage, 3 + (54 - start) * 2, out msg) * 1.0, msg));
                //有功功率:56
                DisplayMessage(string.Format("########有功功率 -----> {0} 数据二进制{1} ", GetDouble1(byteMessage, 3 + (56 - start) * 2, out msg), msg));
 
 
            }
            catch (Exception err)
            {
                MessageBox.Show(err.Message);
                return null;
            }
        }
  */
 
    }
}