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(BitButton BitButtonItem) { bool bAddOk = false; foreach (BitCtrlGroupItem bitGroupTemp in bitGroupList) { if (bitGroupTemp.CheckCanAddTo(BitButtonItem) == 3) { } else { bAddOk = true; break; } } if (!bAddOk) { BitCtrlGroupItem bitGroup = new BitCtrlGroupItem(); bitGroupList.Add(bitGroup); bitGroup.CheckCanAddTo(BitButtonItem); } return(true); }
public int CheckCanAddTo(BitButton BitButtonItem) { string strTempStation = ""; string strTempWordType = ""; string strTempWordAddress = ""; //string strTempWordEndAddress = ""; string strTempBitAddress = ""; PLCBaseClass plcDriver = PLC.Driver(BitButtonItem.DriverName); if (plcDriver == null) { BitButtonItem.m_plcRes = PLCResponse.ERROR; BitButtonItem.FreshDriverStatus(); return(1); } if (plcDriver.GetBitAddress( BitButtonItem.DriverAddrMonitor, ref strTempStation, ref strTempWordType, ref strTempWordAddress, ref strTempBitAddress) == false) { BitButtonItem.m_plcRes = PLCResponse.ADDWRONG; BitButtonItem.FreshDriverStatus(); return(2); } int iTempWordAdd = int.Parse(strTempWordAddress); if (bInit == false) { strPlcName = BitButtonItem.DriverName; strStation = strTempStation; iStartAddr = iTempWordAdd; strWordType = strTempWordType; iEndAdd = iTempWordAdd; bInit = true; } int iPHBeginWordAdd = iEndAdd - 7; int iPHEndWordAdd = iStartAddr + 7; if (iTempWordAdd >= iPHBeginWordAdd && iTempWordAdd <= iPHEndWordAdd && strStation == strTempStation && strWordType == strTempWordType) { if (iTempWordAdd < iStartAddr) { iStartAddr = iTempWordAdd; } if (iTempWordAdd > iEndAdd) { iEndAdd = iTempWordAdd; } } else { return(3); } string strItemFullName = strTempStation + strTempWordType + strTempWordAddress + strTempBitAddress; if (bitCtrlItemDis.Keys.Contains(strItemFullName)) { BitButtonItem.m_plcRes = PLCResponse.OTHERS; BitButtonItem.FreshDriverStatus(); return(4); } bitCtrlItemDis.Add(strItemFullName, BitButtonItem); return(0); }