Exemplo n.º 1
0
        //根据板块类型和协议类型创建通道
        public static CPort CreatePort(string sPortType, string sPortProtocol)
        {
            CPort newPort = null;

            switch (sPortType)
            {
            case "串口":
                switch (sPortProtocol)
                {
                case "Modbus_RTU":
                    newPort = new CPortSerial();
                    break;

                case "恒温槽RE215":
                    newPort = new CPortSerial();
                    break;

                case "真空硅901P":
                    newPort = new CPortSerial();
                    break;
                }
                break;

            case "TCP":
                newPort = new CPortTCPClient();
                break;

            default: break;
            }
            return(newPort);
        }
Exemplo n.º 2
0
        private void UpdateTreelist(TreeNodeCollection aNodes)
        {
            int i = 0;

            foreach (TreeNode item in aNodes)//遍历Treeview的所有节点
            {
                string sType = item.Name.Substring(0, 3);
                switch (sType)
                {
                case "Prj":
                    break;

                case "Prt":
                    i = int.Parse(item.Name.Substring(4));
                    CPort nPort = (CPort)frmMain.staComm.ListPort[i];
                    if (nPort != null)
                    {
                        if (nPort.bOpen)
                        {
                            item.BackColor = Color.Lime;
                        }
                        else
                        {
                            item.BackColor = Color.Red;
                        }
                    }
                    break;

                case "Sta":
                    i = int.Parse(item.Name.Substring(4));
                    CStation nSta = (CStation)frmMain.staComm.ListStation[i];
                    if (nSta != null)
                    {
                        if (nSta.CommStateE == ECommSatate.Unknown)
                        {
                            item.BackColor = Color.White;
                        }
                        else if (nSta.CommStateE == ECommSatate.Failure)
                        {
                            item.BackColor = Color.Red;
                        }
                        else if (nSta.CommStateE == ECommSatate.Normal)
                        {
                            item.BackColor = Color.Lime;
                        }
                    }
                    break;

                default:
                    break;
                }
                UpdateTreelist(item.Nodes);
            }
        }
Exemplo n.º 3
0
        private void AddPortToTable(int iIndex)
        {
            if (iIndex < 0)
            {
                return;
            }

            CPort nPort = (CPort)frmMain.staComm.ListPort[iIndex];

            foreach (CStation nSta in nPort.ListStation)
            {
                AddStaToTable(nSta);
            }
        }
Exemplo n.º 4
0
        //从PortInf_Table.xml中获取端口信息,存入ListPort
        public bool GetPortsFromXML()//获取端口信息
        {
            ListPort.Clear();
            XmlDocument MyXmlDoc = new XmlDocument();

            MyXmlDoc.Load(sIOPath);

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

            foreach (XmlElement item in childNode.ChildNodes)
            {
                string sPortType     = item.GetAttribute("PortType");
                string sPortProtocol = item.GetAttribute("PortProtocol");
                CPort  nPort         = (CPort)CDAModule.CreatePort(sPortType, sPortProtocol);
                if (nPort == null)
                {
                    continue;
                }
                nPort.LoadFromNode(item);
                ListPort.Add(nPort);
            }
            return(true);
        }