Exemplo n.º 1
0
        public static List <L1tag> GetTagList()
        {
            if (listTag == null)
            {
                listTag = new List <L1tag>();
                //string sql = "select id,type from  L1OPC_TAG where used=1  order by id ";
                //var dt = new sqlDbHelp().Query(sql);

                string sql = "select xuhao as id,type  L1OPC_TAG where used=1  order by id ";
                //DbMySql.GetDataTable(sql);
                //var dt = new sqlDbHelp().Query(sql);
                var dt = DbMySql.GetDataTable(sql);

                if (dt != null && dt.Rows.Count > 0)
                {
                    foreach (DataRow item in dt.Rows)
                    {
                        L1tag tag = new L1tag();
                        tag.id = Convert.ToInt16(item["id"]);
                        //tag.name = item["name"].ToString();
                        //tag.scanrate = Convert.ToInt16(item["scanrate"]);
                        //tag.datatype = Convert.ToInt16(item["datatype"]);
                        tag.type = Convert.ToInt16(item["type"]);
                        //tag.lasttime = DateTime.Now.AddHours(-2);
                        listTag.Add(tag);
                    }
                }
            }
            return(listTag);
        }
Exemplo n.º 2
0
        public static List <valRes> GetValById(int id)
        {
            List <valRes> listRes = new List <valRes>();
            valRes        curRes  = new valRes();

            curRes.id = id;
            List <L1tag> listtag = OpcHelp.GetTagList();
            L1tag        item    = listtag.Find(o => o.id == id);
            string       val     = "0";

            if (item == null)
            {
                val = "-9999";
            }
            else
            {
                if (item.type == 0)
                {
                    val = KepServer.GetInstance().getVal(id);
                }
                else if (item.type == 1)
                {
                    val = WinccBof.GetInstance().getVal(id);
                }
                else if (item.type == 2)
                {
                    val = WinccBof_B.GetInstance().getVal(id);
                }
                else if (item.type == 3)
                {
                    val = WinccCcm.GetInstance().getVal(id);
                }
                else if (item.type == 4)
                {
                    val = WinccCcm_B.GetInstance().getVal(id);
                }
                else if (item.type == 5)
                {
                    val = KepServer.GetInstance().getVal(id);
                }
            }
            curRes.val = val;
            listRes.Add(curRes);
            return(listRes);
        }
Exemplo n.º 3
0
        public List <L1tag> dt_to_list(DataTable dt)
        {
            List <L1tag> taglist = new List <L1tag>();

            if (dt != null && dt.Rows.Count > 0)
            {
                foreach (DataRow item in dt.Rows)
                {
                    L1tag tag = new L1tag();
                    tag.id       = Convert.ToInt16(item["id"]);
                    tag.name     = item["name"].ToString();
                    tag.scanrate = Convert.ToInt16(item["scanrate"]);
                    tag.datatype = Convert.ToInt16(item["datatype"]);
                    tag.lasttime = DateTime.Now.AddHours(-2);
                    taglist.Add(tag);
                }
            }
            return(taglist);
        }
Exemplo n.º 4
0
 /// <summary>
 /// 根据变量ID获取变量的值
 /// </summary>
 /// <param name="id"></param>
 /// <returns></returns>
 public string getVal(int id)
 {
     try
     {
         L1tag curitem = listTag.Find(o => o.id == id);
         //根据扫描周期、数据类型,返回变量的值
         if (curitem.scanrate >= 1)
         {
             if (curitem.datatype == 0)
             {
                 return((Math.Round(Convert.ToDouble(KepGroup.OPCItems.GetOPCItem(curitem.itmHandleServer).Value), 2)).ToString());
             }
             else if (curitem.datatype == 1)
             {
                 return((Convert.ToInt32(KepGroup.OPCItems.GetOPCItem(curitem.itmHandleServer).Value)).ToString());
             }
             else
             {
                 return(KepGroup.OPCItems.GetOPCItem(curitem.itmHandleServer).Value.ToString());
             }
         }
         else
         {
             if (curitem.datatype == 0)
             {
                 return((Math.Round(Convert.ToDouble(KepEventGroup.OPCItems.GetOPCItem(curitem.itmHandleServer).Value), 2)).ToString().ToString());
             }
             else if (curitem.datatype == 1)
             {
                 return((Convert.ToInt32(KepEventGroup.OPCItems.GetOPCItem(curitem.itmHandleServer).Value)).ToString());
             }
             else
             {
                 return(KepEventGroup.OPCItems.GetOPCItem(curitem.itmHandleServer).Value.ToString());
             }
         }
     }
     catch (Exception ex)
     {
         SysLog.Log(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "--变量:" + id + ";getVal方法获取值时出错" + ex.ToString());
         return("获取值时出错:" + ex.ToString());
     }
 }
Exemplo n.º 5
0
 /// <summary>
 /// 设置变量的值,(写入double类型)
 /// </summary>
 /// <param name="id"></param>
 /// <param name="val"></param>
 public bool setVal(int id, int val)
 {
     try
     {
         L1tag curitem = listTag.Find(o => o.id == id);
         if (curitem.scanrate >= 1)
         {
             KepGroup.OPCItems.GetOPCItem(curitem.itmHandleServer).Write(val);
         }
         else
         {
             KepEventGroup.OPCItems.GetOPCItem(curitem.itmHandleServer).Write(val);
         }
     }
     catch
     {
         return(false);
     }
     return(true);
 }
Exemplo n.º 6
0
 public void readval(string i, string val)
 {
     try
     {
         L1tag curitem = listTag.Find(o => o.id == Convert.ToInt16(i));
         //如果扫描周期小于1,按事件采集的,则不向数据库插入数据
         if (curitem.scanrate < 1)
         {
             return;
         }
         if ((DateTime.Now - curitem.lasttime).TotalSeconds >= curitem.scanrate)
         {
             curitem.lasttime = DateTime.Now;
             savedata(Convert.ToInt16(i), Math.Round(Convert.ToDouble(val), 3));
         }
     }
     catch (Exception ex)
     {
         throw new Exception("处理数据变化时出错:" + ex.ToString());
     }
 }
Exemplo n.º 7
0
        /// <summary>
        /// 根据变量id获取服务端句柄
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public int getHandleServerById(int id)
        {
            L1tag curitem = listTag.Find(o => o.id == id);

            return(curitem.itmHandleServer);
        }
Exemplo n.º 8
0
        public void readval(string i, object val)
        {
            try
            {
                #region 5#机大包剩钢事件
                if (i == "78")
                {
                    if (Convert.ToInt32(val) == 1)
                    {
                        ccm5dabaoshenggang.GetInstance().calData(1);
                    }
                    return;
                }
                if (i == "87")
                {
                    if (Convert.ToInt32(val) == 1)
                    {
                        ccm5dabaoshenggang.GetInstance().calData(0);
                    }
                    return;
                }
                #endregion

                #region 3#机切割优化状态采集事件
                //3#机大包到达
                if (i == "88")
                {
                    if (Convert.ToInt32(val) == 1)
                    {
                        ccm3cut.GetInstance().acceptCasterStatus(1);
                    }
                    return;
                }
                //3#机大包开浇
                if (i == "89")
                {
                    if (Convert.ToInt32(val) == 1)
                    {
                        ccm3cut.GetInstance().acceptCasterStatus(2);
                    }
                    return;
                }
                //3#机大包停浇
                if (i == "90")
                {
                    if (Convert.ToInt32(val) == 1)
                    {
                        ccm3cut.GetInstance().acceptCasterStatus(3);
                    }
                    return;
                }

                //3#机大包接缝状态
                if (i == "91")
                {
                    if (Convert.ToInt32(val) == 1)
                    {
                        ccm3cut.GetInstance().acceptLadlefeng(Convert.ToInt32(val));
                    }
                    return;
                }

                //3#机1流切割状态
                if (i == "92")
                {
                    ccm3cut.GetInstance().ccmCutStrand_1.acceptCutStatus(Convert.ToInt32(val));
                    return;
                }
                //3#机1流开浇状态
                if (i == "93")
                {
                    ccm3cut.GetInstance().ccmCutStrand_1.acceptStrandStatus(Convert.ToInt32(val));
                    return;
                }

                //3#机2流切割状态
                if (i == "98")
                {
                    ccm3cut.GetInstance().ccmCutStrand_2.acceptCutStatus(Convert.ToInt32(val));
                    return;
                }
                //3#机2流开浇状态
                if (i == "99")
                {
                    ccm3cut.GetInstance().ccmCutStrand_2.acceptStrandStatus(Convert.ToInt32(val));
                    return;
                }

                //3#机3流切割状态
                if (i == "104")
                {
                    ccm3cut.GetInstance().ccmCutStrand_3.acceptCutStatus(Convert.ToInt32(val));
                    return;
                }
                //3#机3流开浇状态
                if (i == "105")
                {
                    ccm3cut.GetInstance().ccmCutStrand_3.acceptStrandStatus(Convert.ToInt32(val));
                    return;
                }

                //3#机4流切割状态
                if (i == "110")
                {
                    ccm3cut.GetInstance().ccmCutStrand_4.acceptCutStatus(Convert.ToInt32(val));
                    return;
                }
                //3#机4流开浇状态
                if (i == "111")
                {
                    ccm3cut.GetInstance().ccmCutStrand_4.acceptStrandStatus(Convert.ToInt32(val));
                    return;
                }
                #endregion


                if (val == null)
                {
                    return;
                }
                L1tag curitem = listTag.Find(o => o.id == Convert.ToInt16(i));
                if (curitem.datatype == 0)
                {
                    savedata(Convert.ToInt16(i), Convert.ToInt32(val));
                }
                else
                {
                    savedata(Convert.ToInt16(i), Math.Round(Convert.ToDouble(val), 3));
                }
                ////如果扫描周期小于1,按事件采集的,则不向数据库插入数据
                //if (curitem.scanrate < 1)
                //{
                //    return;
                //}
                //if ((DateTime.Now - curitem.lasttime).TotalSeconds >= curitem.scanrate)
                //{
                //    curitem.lasttime = DateTime.Now;
                //    if (curitem.datatype == 0)
                //    {
                //        savedata(Convert.ToInt16(i), Convert.ToInt32(val));
                //    }
                //    else
                //    {
                //        savedata(Convert.ToInt16(i), Math.Round(Convert.ToDouble(val), 3));
                //    }

                //}
            }
            catch (Exception ex)
            {
                //throw new Exception("处理数据变化时出错:" + ex.ToString());
                SysLog.Log(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "--变量:" + i + ";值:" + val.ToString() + "readval方法处理数据变化时出错" + ex.ToString());
            }
        }