Beispiel #1
0
        public int CheckCanAddTo(DWordTextBox WordTextItem)
        {
            string       strTempStation     = "";
            string       strTempWordType    = "";
            string       strTempWordAddress = "";
            PLCBaseClass plcDriver          = PLC.Driver(WordTextItem.DriverName);

            if (plcDriver == null)
            {
                WordTextItem.m_plcRes = PLCResponse.ERROR;
                WordTextItem.FreshDriverStatus();
                return(1);
            }
            if (plcDriver.GetWordAddress(
                    WordTextItem.DriverAddr, ref strTempStation, ref strTempWordType, ref strTempWordAddress) == false)
            {
                WordTextItem.m_plcRes = PLCResponse.ADDWRONG;
                WordTextItem.FreshDriverStatus();
                return(2);
            }
            int iTempWordAdd = int.Parse(strTempWordAddress);

            if (bInit == false)
            {
                strPlcName  = WordTextItem.DriverName;
                strStation  = strTempStation;
                iStartAddr  = iTempWordAdd;
                strWordType = strTempWordType;
                iEndAdd     = iTempWordAdd + 1;
                bInit       = true;
            }
            int iPHBeginWordAdd = iEndAdd - 15;
            int iPHEndWordAdd   = iStartAddr + 15;

            if (iTempWordAdd >= iPHBeginWordAdd && iTempWordAdd <= iPHEndWordAdd && strStation == strTempStation && strWordType == strTempWordType)
            {
                if (iTempWordAdd < iStartAddr)
                {
                    iStartAddr = iTempWordAdd;
                }
                if (iTempWordAdd >= iEndAdd)
                {
                    iEndAdd = iTempWordAdd + 1;
                }
            }
            else
            {
                return(3);
            }
            string strItemFullName = strTempStation + strTempWordType + strTempWordAddress;

            if (wordCtrlItemDis.Keys.Contains(strItemFullName))
            {
                WordTextItem.m_plcRes = PLCResponse.OTHERS;
                WordTextItem.FreshDriverStatus();
                return(4);
            }
            wordCtrlItemDis.Add(strItemFullName, WordTextItem);
            return(0);
        }
        public static void ScanThread(object objGroupName)
        {
            string      strGroupName = (string)objGroupName;
            HiPerfTimer timer        = new HiPerfTimer();

            while (true)
            {
                timer.Start();
                BitCtrlGroupUnit  bitCtrlGroupUnit  = new BitCtrlGroupUnit();
                WordCtrlGroupUnit wordCtrlGroupUnit = new WordCtrlGroupUnit();
                try
                {
                    foreach (IControlPLC plsControl in PLCControlGroup[strGroupName].PLCControls)
                    {
                        if (plsControl.GetType() == typeof(BitButton))
                        {
                            BitButton bitControl = (BitButton)plsControl;
                            if (bitControl.Visible || bitControl.AlwayFresh)
                            {
                                bitCtrlGroupUnit.addItemToGroup(bitControl);
                            }
                        }
                        if (plsControl.GetType() == typeof(DWordTextBox))
                        {
                            DWordTextBox wordControl = (DWordTextBox)plsControl;
                            if (wordControl.Visible)
                            {
                                wordCtrlGroupUnit.addItemToGroup(wordControl);
                            }
                        }
                    }
                    foreach (BitCtrlGroupItem bitCtrlItem in bitCtrlGroupUnit.bitGroupList)
                    {
                        bitCtrlItem.MakeStartAndEndAddr();
                        bitCtrlItem.UpdateGroupStatus();
                        //System.Threading.Thread.Sleep(10);
                    }
                    foreach (WordCtrlGroupItem wordCtrlItem in wordCtrlGroupUnit.wordGroupList)
                    {
                        wordCtrlItem.MakeStartAndEndAddr();
                        wordCtrlItem.UpdateGroupStatus();
                        //System.Threading.Thread.Sleep(10);
                    }
                }
                catch
                {
                }

                System.Threading.Thread.Sleep(1);
                PLCScanTime[strGroupName] = timer.Duration;
                //strScanTime = timer.Duration.ToString("0.0000");
            }
        }
        public bool addItemToGroup(DWordTextBox WordTextItem)
        {
            bool bAddOk = false;

            foreach (WordCtrlGroupItem wordGroupTemp in wordGroupList)
            {
                if (wordGroupTemp.CheckCanAddTo(WordTextItem) == 3)
                {
                }
                else
                {
                    bAddOk = true;
                    break;
                }
            }
            if (!bAddOk)
            {
                WordCtrlGroupItem wordGroup = new WordCtrlGroupItem();
                wordGroupList.Add(wordGroup);
                wordGroup.CheckCanAddTo(WordTextItem);
            }
            return(true);
        }