示例#1
0
        /// <summary>
        /// 发送数据
        /// </summary>
        /// <param name="datatemp"></param>
        void SendZoomData(H3CPowerGridData datatemp)
        {
            // oldId =zoomId;
            stateCount += datatemp.PowerGridState;
            H3CMsgType type = (H3CMsgType)Enum.Parse(typeof(H3CMsgType), datatemp.PowerGridState.ToString());

            if (handleDataCount != 0)
            {
                //if (datatemp.DeviceIp == "10.0.177.204")
                //{
                //    int y = 0;
                //}
                H3CZoomStatus?.Invoke(datatemp);
                ShowMsg(string.Format("{0}:电压{1} V 电流{2} A 状态 {3}", datatemp.ZoomId, datatemp.Voltage, datatemp.PowerFlow, type.ToString()));
            }
            if (allZoomData.Count < zCount || allZoomData.Count - zCount < zCount)
            {
                allZoomData.Add(datatemp);
            }
            //if ((zoomId == zCount.ToString() || int.Parse(zoomId) - zCount == zCount) && allZoomData.Count== zCount)
            if (allZoomData.Count == zCount || allZoomData.Count - zCount == zCount)
            {
                if (handleDataCount != 0)
                {
                    H3CAllZoomStatus?.Invoke((H3CMsgType)Enum.Parse(typeof(H3CMsgType), stateCount == 0 ? "0" : "7"), allZoomData);
                }
                allZoomData.Clear();
                oldId           = "0";
                handleDataCount = 1;
            }
        }
示例#2
0
        void ExceptionData(int i)
        {
            H3CPowerGridData datatemp = new H3CPowerGridData()
            {
                DeviceIp = powerIp, ZoomId = i, EventType = H3CMsgType.异常, CombatPower = 0, PowerFlow = "0.0", Voltage = "0000", PowerGridState = 7
            };

            SendZoomData(datatemp);
        }
示例#3
0
        /// <summary>
        /// 正常数据
        /// </summary>
        void  NormalData(string[] msg)
        {
            //if (zoomId == oldId)
            //    return;

            string statusNo = Hexadecimal.ConvertBase(msg[0], 16, 10);

            if (string.IsNullOrWhiteSpace(statusNo))
            {
                return;
            }
            string status = Enum.GetName(typeof(H3CMsgType), int.Parse(statusNo));

            if (string.IsNullOrWhiteSpace(status))
            {
                return;
            }
            oldId = zoomId;
            string dianya = Hexadecimal.ConvertBase(msg[1] + msg[2], 16, 10);

            StringHelper.RepairZero(dianya, 4);
            string dianliu = (double.Parse(Hexadecimal.ConvertBase(msg[3], 16, 10)) / 10).ToString("#0.0");

            if (dianliu == "0.0" && dianya == "0" && status == "正常")
            {
                //checkTime = DateTime.Now;
                // return;
                status   = "异常";
                statusNo = "7";
            }
            H3CPowerGridData data = new H3CPowerGridData()
            {
                DeviceIp       = powerIp,
                EventType      = (H3CMsgType)Enum.Parse(typeof(H3CMsgType), statusNo),
                PowerFlow      = dianliu,
                PowerGridState = int.Parse(statusNo),
                Voltage        = dianya,
                ZoomId         = int.Parse(zoomId)
            };

            SendZoomData(data);
        }
示例#4
0
        private void MyEvent(object sender)
        {
            try
            {
                if (sender == null)
                {
                    return;
                }
                byte[] date   = sender as byte[];
                string strMsg = Encoding.Default.GetString(date, 0, date.Length);// 将接受到的字节数据转化成字符串;
                strMsg = ByteHelper.ByteToHexStr(date, date.Length);
                strMsg = strMsg.Trim('\0');
                int    x = 0;
                string w = "";
                foreach (char item in strMsg)
                {
                    if (x == 1)
                    {
                        w += item + " ";
                        x  = 0;
                    }
                    else
                    {
                        w += item;
                        x++;
                    }
                }
                w = w.Substring(0, w.Length - " ".Length);
                string[] msg = w.Split(' ');

                if (msg.Length == 8)
                {
                    if (msg[0] == "FF" && msg[1] == "0C" && msg[2] == "02")
                    {
                        id = Hexadecimal.ConvertBase(msg[3], 16, 10);
                    }
                }
                else if (msg.Length == 6)
                {
                    if (id != "" && id != "0")
                    {
                        if (id == oldId)
                        {
                            return;
                        }
                        oldId = id;
                        string statusNo = Hexadecimal.ConvertBase(msg[0], 16, 10);
                        string status   = Enum.GetName(typeof(H3CMsgType), int.Parse(statusNo));
                        string dianya   = Hexadecimal.ConvertBase(msg[1] + msg[2], 16, 10);
                        if (dianya.Length < 4)
                        {
                            int count = dianya.Length;
                            for (int i = 0; i < 4 - count; i++)
                            {
                                dianya = "0" + dianya;
                            }
                        }
                        string           dianliu = (double.Parse(Hexadecimal.ConvertBase(msg[3], 16, 10)) / 10).ToString("#0.0");
                        H3CPowerGridData data    = new H3CPowerGridData();
                        data.DeviceIp       = powerIp;
                        data.EventType      = (H3CMsgType)Enum.Parse(typeof(H3CMsgType), statusNo);
                        data.PowerFlow      = dianliu;
                        data.PowerGridState = int.Parse(statusNo);
                        data.Voltage        = dianya;
                        data.ZoomId         = int.Parse(id);
                        if (dianliu == "0" && dianya == "0" && status == "正常")
                        {
                            return;
                        }
                        H3CZoomStatus?.Invoke(data);
                        dianliu += " ";
                        dianya  += " ";
                        ShowMsg(string.Format("{0}:电压{1} V 电流{2} A 状态 {3}", id, dianya, dianliu, status));
                        if (id == "")
                        {
                            return;
                        }
                        stateCount += int.Parse(statusNo);
                        if (int.Parse(id) <= ZoomCount)
                        {
                            txt += string.Format("{0}:电压{1}电流{2}状态 {3};", id, dianya, dianliu, status);
                            allZoomData.Add(data);
                        }
                        if (id == ZoomCount.ToString())
                        {
                            if (allZoomData.Count == ZoomCount)
                            {
                                H3CPowerGridFormatStatus?.Invoke((H3CMsgType)Enum.Parse(typeof(H3CMsgType), stateCount == 0 ? "0" : "7"), allZoomData);
                            }
                            txt = "  ";
                            allZoomData.Clear();
                            //Thread.Sleep(3000);
                        }
                        id = "";
                    }
                }
            }
            catch (Exception) { }
            checkTime = DateTime.Now;
        }