Example #1
0
        public static void GatherAlarmData(SAlarmEvent almEV, short clientNo)
        {
            AlarmData alm = new AlarmData();

            alm.time     = DateTime.Now;
            alm.isOnOff  = almEV.begin;
            alm.alarmNo  = almEV.alarmNo;
            alm.alarmTxt = System.Text.Encoding.Default.GetString(almEV.alarmText).Trim('\0');

            LineDevice.CNC result = MainForm.cnclist.Find(
                delegate(LineDevice.CNC temp)
            {
                return(temp.HCNCShareData.sysData.clientNo == clientNo);
            }
                );

            if (result != null)
            {
                if (MainForm.m_CheckHander != null && MainForm.m_CheckHander.AlarmSendDataEvenHandle != null)
                {
                    EquipmentCheck.AlarmSendData SendMeg = new EquipmentCheck.AlarmSendData();
//                     SendMeg.alardat = new ScadaHncData.AlarmData();
                    SendMeg.NeedFindTeX = false;
                    SendMeg.BujianID    = result.BujianID;
                    SendMeg.alardat     = alm;
                    MainForm.m_CheckHander.AlarmSendDataEvenHandle.BeginInvoke(null, SendMeg, null, null);
                }

                if (result.HCNCShareData.alarmList.Count == result.HCNCShareData.AlmLstLen)
                {
                    result.HCNCShareData.alarmList.RemoveRange(0, result.HCNCShareData.AlmLstLen / 2);
                }
                UpdateCurrentAlarmLst(result.HCNCShareData, alm);
            }
            else if (PLCDataShare.m_plclist != null && PLCDataShare.m_plclist.Count > 0 &&
                     PLCDataShare.m_plclist[0].m_hncPLCCollector != null && clientNo == Collector.CollectHNCPLC.m_clientNo)//HNC8 PLC报警
            {
                if (MainForm.m_CheckHander != null && MainForm.m_CheckHander.AlarmSendDataEvenHandle != null)
                {
                    EquipmentCheck.AlarmSendData SendMeg = new EquipmentCheck.AlarmSendData();
//                     SendMeg.alardat = new ScadaHncData.AlarmData();
                    SendMeg.NeedFindTeX = false;
                    SendMeg.BujianID    = PLCDataShare.m_plclist[0].m_hncPLCCollector.EQUIP_CODE;
                    SendMeg.alardat     = alm;
                    MainForm.m_CheckHander.AlarmSendDataEvenHandle.BeginInvoke(null, SendMeg, null, null);
                }
            }
        }
Example #2
0
        private void ConnectThreadFunc()
        {
            bool           ConnectNoFinish = false;
            List <HNCData> ncDatas         = new List <HNCData>();

            while (true)
            {
                if (ConnectNoFinish)
                {
                    ConnectNoFinish = false;
                    ncDatas.Clear();
                    foreach (CollectHNCData collecncdata in m_gatherHNCLst)
                    {
                        if (!collecncdata.hncdata.sysData.isConnect)
                        {
                            if (ClientPingTest(collecncdata.hncdata.sysData.addr.ip))
                            {
                                collecncdata.hncdata.sysData.clientNo = Instance().HNC_NetConnect(collecncdata.hncdata.sysData.addr.ip, collecncdata.hncdata.sysData.addr.port, true);
                                if (collecncdata.hncdata.sysData.clientNo >= 0 && collecncdata.hncdata.sysData.clientNo < 256)
                                {
//                                     for (int hageii = 0; hageii < 10; hageii++)
                                    {
                                        collecncdata.UpDataChAxList();
//                                         if (collecncdata.hncdata.chanDataLst.Count > 0 && collecncdata.hncdata.axlist.Count > 0)
//                                         {
//                                             break;
//                                         }

                                        ncDatas.Add(collecncdata.hncdata);
                                    }
                                    if (collecncdata.hncdata.chanDataLst.Count > 0 && collecncdata.hncdata.axlist.Count > 0)//确保采集器是初始化OK
                                    {
                                        collecncdata.CollectConstData();
                                        if (collecncdata.hncdata.sysData.clientNo >= 0 && collecncdata.hncdata.sysData.clientNo < 256 &&
                                            collecncdata.hncdata.sysData.macSN != null && collecncdata.hncdata.sysData.macSN.Length > 0)
                                        {
                                            collecncdata.threaFucRuningF_OK = true;
                                            collecncdata.Get_Reg_threaFucEvent.Set();
                                            collecncdata.hncdata.sysData.isConnect = true;

                                            if (collecncdata.m_cnc.CNCchanDataEventHandler != null)
                                            {
                                                int[] senddata = new int[2];
                                                senddata[0] = (int)LineDevice.CNC.CNCchanDataEventType.CNCStateChage;
                                                senddata[1] = (int)LineDevice.CNC.CNCState.IDLE;
                                                collecncdata.m_cnc.CNCchanDataEventHandler.BeginInvoke(this, senddata, null, null);
                                            }

                                            AlarmData alm = new AlarmData();
                                            m_Instance.HNC_AlarmRefresh(collecncdata.hncdata.sysData.clientNo);
                                            int alarm_num = 0;
                                            m_Instance.HNC_AlarmGetNum((int)HNCAPI.AlarmType.ALARM_TYPE_ALL, (int)HNCAPI.AlarmLevel.ALARM_ERR, ref alarm_num, collecncdata.hncdata.sysData.clientNo);
                                            for (int i = 0; i < alarm_num; i++)
                                            {
                                                m_Instance.HNC_AlarmGetData((int)HNCAPI.AlarmType.ALARM_TYPE_ALL, //获取所有类型的报警
                                                                            (int)HNCAPI.AlarmLevel.ALARM_ERR,     //仅获取error
                                                                            i,
                                                                            ref alm.alarmNo,                      //获取此报警的唯一ID,可用于报警识别
                                                                            ref alm.alarmTxt,                     //报警文本
                                                                            collecncdata.hncdata.sysData.clientNo);
                                                alm.isOnOff = 1;
                                                if (MainForm.m_CheckHander != null && MainForm.m_CheckHander.AlarmSendDataEvenHandle != null)
                                                {
                                                    EquipmentCheck.AlarmSendData SendMeg = new EquipmentCheck.AlarmSendData();
//                                                     SendMeg.alardat = new ScadaHncData.AlarmData();
                                                    SendMeg.NeedFindTeX     = false;
                                                    SendMeg.BujianID        = collecncdata.m_cnc.BujianID;
                                                    SendMeg.alardat.isOnOff = 1;
                                                    SendMeg.alardat         = alm;
                                                    MainForm.m_CheckHander.AlarmSendDataEvenHandle.BeginInvoke(null, SendMeg, null, null);
                                                }

                                                UpdateCurrentAlarmLst(collecncdata.hncdata, alm);
                                            }
                                            SCADA.LogData.EventHandlerSendParm SendParm = new SCADA.LogData.EventHandlerSendParm();
                                            SendParm.Node1NameIndex = (int)SCADA.LogData.Node1Name.Equipment_CNC;
                                            SendParm.LevelIndex     = (int)SCADA.LogData.Node2Level.MESSAGE;
                                            SendParm.EventID        = ((int)SCADA.LogData.Node2Level.MESSAGE).ToString();
                                            SendParm.Keywords       = "CNC采集器开启";
                                            SendParm.EventData      = collecncdata.m_cnc.BujianID + ":ip = " + collecncdata.hncdata.sysData.addr.ip
                                                                      + "  链接号 = " + collecncdata.hncdata.sysData.clientNo.ToString()
                                                                      + " sn = " + collecncdata.hncdata.sysData.macSN;
                                            SCADA.MainForm.m_Log.AddLogMsgHandler.BeginInvoke(this, SendParm, null, null);
                                        }
                                    }
                                    else
                                    {
//                                         SCADA.LogData.EventHandlerSendParm SendParm = new SCADA.LogData.EventHandlerSendParm();
//                                         SendParm.Node1NameIndex = (int)SCADA.LogData.Node1Name.Equipment_CNC;
//                                         SendParm.LevelIndex = (int)SCADA.LogData.Node2Level.消息;
//                                         SendParm.EventID = ((int)SCADA.LogData.Node2Level.消息).ToString();
//                                         SendParm.Keywords = "collecncdata.hncdata.chanDataLst.Count = 0";
//                                         SendParm.EventData = collecncdata.hncdata.sysData.addr.ip;
//                                         SCADA.MainForm.m_Log.AddLogMsgHandler.BeginInvoke(this, SendParm, null, null);
                                    }
                                }
                            }
                        }
                        if (!collecncdata.hncdata.sysData.isConnect)
                        {
                            ConnectNoFinish = true;
                        }
                    }
                }
                else
                {
                    threaFucEvent.WaitOne();
                    ConnectNoFinish = true;
                }

                //---------------------------------added by zb 20151105--------------------------start
                if (ncDatas.Count > 0)
                {
                    monitor.ProcessConnDatPosi(ncDatas);
                }
                //---------------------------------added by zb 20151105--------------------------end

                //                 Thread.Sleep(CONNECT_THREAD_SLEEP_TIME);
            }
        }