Example #1
0
        public override void DrawPoints(Graphics g)
        {
            //base.DrawPoints(g);

            GraphicsPath path = new GraphicsPath();

            path.AddEllipse(rect);
            SolidBrush brush = new SolidBrush(FillColor1);

            if (bShowText)
            {
                string sVar = "AV" + ShowText.PadLeft(3, '0');
                CVar   nVar = frmMain.staComm.GetVarByStaNameVarName("NJ301", sVar);

                if (nVar != null)
                {
                    bValue = nVar.GetBoolValue();
                }
            }
            if (bValue)
            {
                brush.Color = FillColor0;
            }
            g.FillPath(brush, path);
            g.DrawEllipse(new Pen(LineColor, iLineWidth), rect);
            if (bShowText)
            {
                g.DrawString(ShowText, DrawFont, FontBrush, TextRect, TextFormat);
            }
        }
Example #2
0
        private void timer1_Tick(object sender, EventArgs e)
        {
            try
            {
                foreach (object obj in this.Controls)
                {
                    if (obj.GetType() == typeof(System.Windows.Forms.NumericUpDown))
                    {
                        NumericUpDown nNumUD = (NumericUpDown)obj;
                        CVar          nVar   = frmMain.staComm.GetVarByStaNameVarName("NJ301", nNumUD.Name);

                        if (nVar != null)
                        {
                            nNumUD.ValueChanged -= new EventHandler(nCon_ValueChanged);
                            nNumUD.Value         = new decimal(new int[] { Math.Min((int)nNumUD.Maximum, (int)nVar.PLCValue[2]), 0, 0, 0 });
                            nNumUD.ValueChanged += new EventHandler(nCon_ValueChanged);
                        }
                    }
                }
                this.Invalidate();
                //Rectangle rc = new Rectangle(new Point(158, 13), new Size(203, 93));
                //this.Invalidate(rc,true);
            }
            catch (Exception ex)
            {
                Debug.WriteLine("frmChild.timer1_Tick" + ex.Message);
            }
        }
Example #3
0
        private string[] AddRow(CVar nVar, string StaName)
        {
            string[] str1 = new string[9];
            string   sWR  = "";

            if (nVar == null)
            {
                return(str1);
            }
            if (nVar.Readable > 0)
            {
                sWR += "读";
            }
            if (nVar.Writeable > 0)
            {
                sWR += "写";
            }

            iIndex++;
            str1[0] = iIndex.ToString();
            str1[1] = StaName;
            str1[2] = nVar.Name;
            str1[3] = nVar.GetStringValue(1);
            str1[4] = nVar.Description;
            str1[5] = nVar.Unit;
            str1[6] = nVar.GetTypeName();
            str1[7] = sWR;
            return(str1);
        }
Example #4
0
        public CPublicVar()
        {
            CB23      = frmMain.staComm.GetVarByStaNameVarName("NJ301", "B_23");
            nVarDI187 = frmMain.staComm.GetVarByStaNameVarName("NJ301", "DI187");
            nVarU[0]  = frmMain.staComm.GetVarByStaNameVarName("NJ301", "AI01");
            nVarU[1]  = frmMain.staComm.GetVarByStaNameVarName("NJ301", "AI02");
            nVarU[2]  = frmMain.staComm.GetVarByStaNameVarName("NJ301", "AI06");
            for (int i = 0; i < 3; i++)
            {
                nVarPV[i]     = frmMain.staComm.GetVarByStaNameVarName(sListOLName[i], "PV");
                nVarMode[i]   = frmMain.staComm.GetVarByStaNameVarName(sListOLName[i], "Mode");
                nVarPVW[i]    = frmMain.staComm.GetVarByStaNameVarName(sListOLName[i], "PV_W");
                nVarI[i]      = frmMain.staComm.GetVarByStaNameVarName(sListOLName[i], "I");
                nVarIW[i]     = frmMain.staComm.GetVarByStaNameVarName(sListOLName[i], "I_W");
                nVarPID[i, 0] = frmMain.staComm.GetVarByStaNameVarName(sListOLName[i], "PID_P");
                nVarPID[i, 1] = frmMain.staComm.GetVarByStaNameVarName(sListOLName[i], "PID_I");
                nVarPID[i, 2] = frmMain.staComm.GetVarByStaNameVarName(sListOLName[i], "PID_D");
                CStation Sta = frmMain.staComm.GetStaByStaName(sListOLName[i]);
                nOLSta[i] = (CProtcolModbusTCP)Sta;
            }

            nVarPLCI[0] = frmMain.staComm.GetVarByStaNameVarName(sListOLName[0], "I");
            nVarPLCI[1] = frmMain.staComm.GetVarByStaNameVarName(sListOLName[1], "I_1");
            nVarPLCI[2] = frmMain.staComm.GetVarByStaNameVarName(sListOLName[1], "I_3");
            nVarPLCI[3] = frmMain.staComm.GetVarByStaNameVarName(sListOLName[1], "I_4");
            nVarPLCI[4] = frmMain.staComm.GetVarByStaNameVarName(sListOLName[1], "I_6");
            nVarPLCI[5] = frmMain.staComm.GetVarByStaNameVarName(sListOLName[2], "I_1");
            nVarPLCI[6] = frmMain.staComm.GetVarByStaNameVarName(sListOLName[2], "I_3");
            nVarPLCI[7] = frmMain.staComm.GetVarByStaNameVarName(sListOLName[2], "I_4");

            LoadXml();
        }
Example #5
0
        //public	virtual void CopyTo(INode  _Node) override;
        public virtual CVar Clone()
        {
            CVar obj = (CVar)this.MemberwiseClone();

            if (nVarAlarm != null)
            {
                obj.nVarAlarm = nVarAlarm.Clone();
            }
            if (ExpressR != null)
            {
                obj.ExpressR = ExpressR.Clone();
            }
            if (ExpressW != null)
            {
                obj.ExpressW = ExpressW.Clone();
            }

            obj.ListValue = new List <SVarValue>();
            obj.IntTag    = new Single[10];
            for (int i = 0; i < 10; i++)
            {
                obj.IntTag[i] = IntTag[i];
            }
            //{
            //    obj.ListValue.Add(nValue);
            //}
            return(obj);
        }
Example #6
0
 public static string InsertToText(string str1, CStation nSta, CVar nVar)
 {
     if (str1.Length > 0)
     {
         str1 = str1.Replace("[SN]", nSta.Name);
         str1 = str1.Replace("[SD]", nSta.Description);
         str1 = str1.Replace("[VN]", nVar.Name);
         str1 = str1.Replace("[VD]", nVar.Description);
     }
     return(str1);
 }
Example #7
0
 public void GetDeviceVar(string StaName)
 {
     if (ExpressType == LCExpressType.Var)
     {
         string   str1  = Exipression.Replace(".", ",");
         string[] sPath = str1.Split(',');
         if (sPath.Length >= 3)
         {
             cSta = frmMain.staComm.GetStaByStaName(sPath[1]);
             cVar = frmMain.staComm.GetVarByStaNameVarName(sPath[1], sPath[2]);
         }
     }
     else if (ExpressType == LCExpressType.Expression)//表达式
     {
         ListParam.Clear();
         ListParam = CParameterOperate.GetParamList(Exipression, StaName);
     }
 }
Example #8
0
        public void LoadWins()//读取Wins文件
        {
            /// 创建XmlDocument类的实例
            XmlDocument myxmldoc = new XmlDocument();

            myxmldoc.Load(cForm.sPath);

            string     xpath     = "FormWindow";
            XmlElement childNode = (XmlElement)myxmldoc.SelectSingleNode(xpath);

            cForm.LoadFromXML(childNode);

            //取图元
            xpath     = "FormWindow/Misc";
            childNode = (XmlElement)myxmldoc.SelectSingleNode(xpath);
            int i = 0;

            foreach (XmlElement item in childNode.ChildNodes)
            {
                string sNodeName = item.Name;
                string str1      = sNodeName.Substring(0, 2);
                if ((sNodeName.Substring(0, 2) == "TY" || sNodeName.Substring(0, 2) == "KJ") && item.ChildNodes.Count > 0)
                {
                    foreach (XmlElement TYNode in item.ChildNodes)
                    {
                        switch (TYNode.Name)
                        {
                        case "TYLine":
                            CElementFactory.SetClassIndex(LCElementType.LINE);
                            break;

                        case "TYText":
                            CElementFactory.SetClassIndex(LCElementType.TEXT);
                            break;

                        case "TYRect":
                            CElementFactory.SetClassIndex(LCElementType.RECTANGLE);
                            break;

                        case "TYEllipse":
                            CElementFactory.SetClassIndex(LCElementType.ELLIPS);
                            break;

                        case "TYRndRect":
                            CElementFactory.SetClassIndex(LCElementType.ROUNDRECTANGLE);
                            break;

                        case "TYZLine":
                            CElementFactory.SetClassIndex(LCElementType.POLYLINE);
                            break;

                        case "TYArc":
                            CElementFactory.SetClassIndex(LCElementType.ARC);
                            break;

                        case "KJHotImage":
                            CElementFactory.SetClassIndex(LCElementType.IMAGECONTROL);
                            break;

                        case "KJIcon":
                            CElementFactory.SetClassIndex(LCElementType.GROUP);
                            break;

                        case "TYRing":
                            CElementFactory.SetClassIndex(LCElementType.Ring);
                            break;

                        case "TYPipe":
                            CElementFactory.SetClassIndex(LCElementType.Pipe);
                            break;

                        default:
                            continue;
                            //break;
                        }

                        CBase NewOb = CElementFactory.CreateElement(null, this);
                        if (NewOb == null)
                        {
                            continue;
                        }
                        NewOb.LoadFromXML(TYNode);

                        if (NewOb.ElementType == LCElementType.Pipe)
                        {
                            CPipe CNum = (CPipe)NewOb;
                            if (CNum.bShowSet)
                            {
                                NumericUpDown nNumUD = new NumericUpDown();
                                CNumUpDown    cNumUD = new CNumUpDown(CNum.ValPF, CNum.SetWidth, 20, 13);
                                nNumUD.Font     = new Font("宋体", 13, GraphicsUnit.World);
                                nNumUD.Location = CNum.ValPF;
                                nNumUD.Maximum  = new decimal(new int[] { 65535, 0, 0, 0 });
                                nNumUD.Name     = CNum.Name;
                                nNumUD.Size     = new Size((int)CNum.SetWidth, 20);

                                nNumUD.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left))));

                                nNumUD.UpDownAlign = LeftRightAlignment.Left;
                                nNumUD.TextAlign   = HorizontalAlignment.Right;
                                CVar nVar = frmMain.staComm.GetVarByStaNameVarName("NJ301", nNumUD.Name);
                                if (nVar != null)
                                {
                                    nNumUD.Value = new decimal(new int[] { (int)nVar.PLCValue[2], 0, 0, 0 });
                                }
                                else
                                {
                                    nNumUD.Value = new decimal(new int[] { 0, 0, 0, 0 });
                                }
                                nNumUD.ValueChanged += new EventHandler(nCon_ValueChanged);
                                cNumUD.nNumUD        = nNumUD;
                                ListNumericUpDown.Add(cNumUD);
                                this.Controls.Add(nNumUD);
                            }
                        }

                        for (i = ListTuYuan.Count - 1; i > -1; i--)
                        {
                            CBase Ob = (CBase)ListTuYuan[i];

                            Int32 iEO = Ob.iElementOrder;
                            if (NewOb.iElementOrder >= iEO)
                            {
                                ListTuYuan.Insert(i + 1, NewOb);
                                break;
                            }
                        }
                        if (i == -1)
                        {
                            ListTuYuan.Insert(0, NewOb);
                        }
                    }
                } //if ((sNodeName.Substring(0, 2) == "TY
            }     //foreach (XmlElement item in childNode.ChildNodes)

            //对应图元
            foreach (CBase nTY in ListTuYuan)
            {
                if (nTY.ElementType == LCElementType.GROUP && nTY.KJIconType == 2)
                {
                    foreach (KJIcon nIcon in KJIconList.ListKJIcon)
                    {
                        if (nIcon.IconName == nTY.IconName)
                        {
                            ((CGroup)nTY).BaseKJIcon = nIcon;
                        }
                    }
                    foreach (SwitchPic nSP in ((CGroup)nTY).ListSwitchPic)
                    {
                        foreach (KJIcon nIcon in KJIconList.ListKJIcon)
                        {
                            if (nIcon.IconName == nSP.PicName)
                            {
                                ((SwitchPic)nSP).BaseKJIcon = nIcon;
                            }
                        }
                    }
                }
            }
        }
Example #9
0
        public override void LoadFromXML(XmlElement CBaseNode)
        {
            try
            {
                //base.LoadFromXML(CBaseNode);
                // XmlElement TextNode = (XmlElement)(Node.SelectSingleNode("Layout"));
                iElementOrder = Convert.ToInt32(CBaseNode.GetAttribute("iElementOrder"));
                GLayerName    = CBaseNode.GetAttribute("GLayerName");
                Name          = CBaseNode.GetAttribute("Name");

                iOrgX1 = Convert.ToSingle(CBaseNode.GetAttribute("iOrgX1"));
                iOrgX2 = Convert.ToSingle(CBaseNode.GetAttribute("iOrgX2"));
                iOrgY1 = Convert.ToSingle(CBaseNode.GetAttribute("iOrgY1"));
                iOrgY2 = Convert.ToSingle(CBaseNode.GetAttribute("iOrgY2"));

                Pipefocus = Convert.ToSingle(CBaseNode.GetAttribute("Pipefocus"));
                PipeP1    = CBaseNode.GetAttribute("PipeP1");
                PipeP2    = CBaseNode.GetAttribute("PipeP2");
                PipeWidth = Convert.ToInt32(CBaseNode.GetAttribute("PipeWidth"));

                if (CBaseNode.HasAttribute("Angle"))
                {
                    m_RotateAngle = Convert.ToSingle(CBaseNode.GetAttribute("Angle"));
                }

                if (CBaseNode.HasAttribute("tpenColor"))
                {
                    IsBorder = Convert.ToBoolean(CBaseNode.GetAttribute("IsBorder"));

                    DrawPen.Color     = ColorTranslator.FromWin32(Convert.ToInt32(CBaseNode.GetAttribute("tpenColor")));
                    DrawPen.Width     = Convert.ToInt32(CBaseNode.GetAttribute("tpenWidth"));
                    DrawPen.DashStyle = (DashStyle)Enum.Parse(typeof(DashStyle), CBaseNode.GetAttribute("tpenStyle"));
                }

                if (CBaseNode.HasAttribute("tbruStyle"))
                {
                    tbruStyle = Convert.ToInt32(CBaseNode.GetAttribute("tbruStyle"));
                    tbruColor = ColorTranslator.FromWin32(Convert.ToInt32(CBaseNode.GetAttribute("tbruColor")));
                    FillColor = ColorTranslator.FromWin32(Convert.ToInt32(CBaseNode.GetAttribute("FillColor")));
                    //EmgColor = ColorTranslator.FromWin32(Convert.ToInt32(CBaseNode.GetAttribute("EmgColor")));
                    iShadeFillStyle = Convert.ToInt32(CBaseNode.GetAttribute("iShadeFillStyle"));
                }

                if (CBaseNode.HasAttribute("BShowText"))
                {
                    BShowVal        = Convert.ToInt32(CBaseNode.GetAttribute("BShowText"));
                    ShowText        = CBaseNode.GetAttribute("ShowText");
                    TextX           = Convert.ToSingle(CBaseNode.GetAttribute("TextX"));
                    TextY           = Convert.ToSingle(CBaseNode.GetAttribute("TextY"));
                    FontBrush.Color = ColorTranslator.FromWin32(Convert.ToInt32(CBaseNode.GetAttribute("TextColor")));
                    float fSize = Convert.ToSingle(CBaseNode.GetAttribute("TextSize"));
                    DrawFont = new Font("黑体", fSize, GraphicsUnit.World);

                    ValX1 = Convert.ToSingle(CBaseNode.GetAttribute("ValX1"));
                    ValY1 = Convert.ToSingle(CBaseNode.GetAttribute("ValY1"));
                    ValX2 = Convert.ToSingle(CBaseNode.GetAttribute("ValX2"));
                    ValY2 = Convert.ToSingle(CBaseNode.GetAttribute("ValY2"));
                    if (CBaseNode.HasAttribute("SetWidth"))
                    {
                        SetWidth = Convert.ToSingle(CBaseNode.GetAttribute("SetWidth"));
                    }
                    else
                    {
                        SetWidth = 48;
                    }

                    LiuVar = frmMain.staComm.GetVarByStaNameVarName("NJ301", Name);
                }
            }
            catch (Exception e)
            {
                Debug.WriteLine(e.Message);
            }
            if (iOrgY1 == iOrgY2)
            {
                iDir = 1;
            }
            else
            {
                iDir = 0;
            }
            List <PointF> LP  = new List <PointF>();
            List <PointF> LP1 = GetPipeP(PipeP1, 1, iDir);
            List <PointF> LP2 = GetPipeP(PipeP2, 2, iDir);

            for (int i = 0; i < LP1.Count; i++)
            {
                PointF p1 = new PointF(LP1[i].X * PipeWidth + iOrgX1, LP1[i].Y * PipeWidth + iOrgY1);
                LP.Add(p1);
            }

            for (int i = 0; i < LP2.Count; i++)
            {
                PointF p1 = new PointF(LP2[i].X * PipeWidth + iOrgX2, LP2[i].Y * PipeWidth + iOrgY2);
                LP.Add(p1);
            }

            if (LP.Count > 0)
            {
                PTS = new PointF[LP.Count + 1];
                PointF MinP = LP[0];
                PointF MaxP = LP[0];

                for (int i = 0; i < LP.Count; i++)
                {
                    PTS[i] = LP[i];
                    MinP.X = Math.Min(LP[i].X, MinP.X);
                    MinP.Y = Math.Min(LP[i].Y, MinP.Y);
                    MaxP.X = Math.Max(LP[i].X, MaxP.X);
                    MaxP.Y = Math.Max(LP[i].Y, MaxP.Y);
                }
                PTS[LP.Count] = PTS[0];
                rect.Location = MinP;
                rect.Size     = new SizeF(MaxP.X - MinP.X, MaxP.Y - MinP.Y);

                TextRect.Location = new PointF(MinP.X + TextX, MinP.Y + TextY);
                TextRect.Size     = new SizeF(90, 30);

                ValPF            = new Point((int)(MinP.X + ValX1), (int)(MinP.Y + ValY1));
                ValRect.Location = new PointF(MinP.X + ValX2, MinP.Y + ValY2);
                ValRect.Size     = new SizeF(SetWidth, 20);
            }
        }
Example #10
0
        //从工程中加载所有设备所有属性信息,包括变量,报文,图案等
        public bool GetDevicesALLInfo()
        {
            //先加载设备信息
            foreach (CDevice cnode in ListDevice)
            {
                cnode.ListDevVar.Clear();
            }

            //加载设备变量(CDeviceVar,categogy = 0)
            XmlDocument MyXmlDoc = new XmlDocument();

            MyXmlDoc.Load(sIOPath);

            string     xpath     = "IO/VariableInf_Table";
            XmlElement childNode = (XmlElement)MyXmlDoc.SelectSingleNode(xpath);

            foreach (XmlElement item in childNode.ChildNodes)
            {
                foreach (CDevice cnode in ListDevice)
                {
                    if (cnode.Driver == item.GetAttribute("Driver"))
                    {
                        CVar node = new CVar();
                        node.LoadFromNode(item);
                        cnode.ListDevVar.Add(node);
                    }
                }
            }

            //CMessage 请求读报文
            MyXmlDoc.Load(sIOPath);

            xpath     = "IO/MessageInf_Table";
            childNode = (XmlElement)MyXmlDoc.SelectSingleNode(xpath);
            foreach (XmlElement item in childNode.ChildNodes)
            {
                foreach (CDevice nDev in ListDevice)
                {
                    if (nDev.Driver == item.GetAttribute("Driver"))
                    {
                        CMessage nMsg = new CMessage();
                        nMsg.LoadFromNode(item);
                        switch (nMsg.MsgType)
                        {
                        case EMsgType.Msg_Loop:
                            nDev.ListMsgLoop.Add(nMsg);
                            break;

                        case EMsgType.Msg_Time:
                            nDev.ListMsgTime.Add(nMsg);
                            break;

                        case EMsgType.Msg_Call:
                            nDev.ListMsgCall.Add(nMsg);
                            break;

                        default:
                            nDev.ListMsgOther.Add(nMsg);
                            break;
                        }
                    }
                }
            }
            return(true);
        }