コード例 #1
0
        /// <summary>
        /// 添加寄存器
        /// </summary>
        /// <param name="reg"></param>
        public void AddReg(CPLCAlarmReg reg)
        {
            try
            {
                objlock.AcquireWriterLock(-1);

                regList.Add(reg);

                if (!regMapp.ContainsKey(reg.idNo))
                {
                    regMapp.Add(reg.idNo, regList.Count);
                }
            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                objlock.ReleaseWriterLock();
            }
        }
コード例 #2
0
        /// <summary>
        /// 获取当前报警信息
        /// </summary>
        /// <param name="RegVal"></param>
        /// <param name="alarmReg"></param>
        /// <param name="er"></param>
        /// <returns></returns>
        public bool GetCurAlarmInfo(List <int> RegVal, out List <CPLCAlarmReg> alarmReg, out string er)
        {
            er = string.Empty;

            alarmReg = new List <CPLCAlarmReg>();

            try
            {
                objlock.AcquireWriterLock(-1);

                string sNowTime = DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss");

                for (int i = 0; i < RegVal.Count; i++)
                {
                    if (RegVal[i] == -1)
                    {
                        continue;
                    }

                    for (int z = 0; z < C_BIT_MAX; z++)
                    {
                        int idNo = i * C_BIT_MAX + z;

                        if (!regMapp.ContainsKey(idNo + 1))
                        {
                            continue;
                        }

                        int index = regMapp[idNo + 1] - 1;

                        int bitVal = 0;

                        if ((RegVal[i] & (1 << z)) == (1 << z))
                        {
                            bitVal = 1;
                        }

                        if (bitVal == CPLCPara.ON)
                        {
                            CPLCAlarmReg reg = new CPLCAlarmReg
                            {
                                idNo       = regList[index].idNo,
                                RegNo      = i,
                                RegBit     = z,
                                RegVal     = regList[index].RegVal,
                                RegFun     = regList[index].RegFun,
                                CurVal     = regList[index].CurVal,
                                HappenTime = sNowTime
                            };
                            alarmReg.Add(reg);
                        }
                    }
                }

                return(true);
            }
            catch (Exception ex)
            {
                er = ex.ToString();
                return(false);
            }
            finally
            {
                objlock.ReleaseWriterLock();
            }
        }