private BoardRS getBoardRS(BoardConfig boardConfig, string rsName) { if (boardConfig.listBoardRS.Count != 0) { foreach (BoardRS boardRS in boardConfig.listBoardRS) { if (rsName == boardRS.Name) { return(boardRS); } } } return(null); }
public TestBoard openBoardXML(StandSignals standSignals, string XMLname) { BoardSignal boardSignal = null; BoardSignals boardSignals = new BoardSignals(); //BoardConfig boardConfig = null; BoardConfig boardConfig = new BoardConfig(); BoardScenario scenario = null; Periodic periodic = new Periodic(); Manual manual = new Manual(); Test runTest = new Test(); //GroupSignals groupSignal = null; string commentString = null; string imageLinkString = null; string str; bool bSectionSet = false; bool bSectionGet = false; bool bSectionConfig = false; //string name; string paramName = ""; string setSourceName = ""; string getSourceName = ""; string boardSignalName = null; string boardRSName = null; UInt16 delay = 1000; ushort numBytes = 0; byte marker = 0x0; byte setIndexByte = 0; byte setIndexBit = 0; byte getIndexByte = 0; byte getIndexBit = 0; bool bSetValueON = true; bool bGetValueON = true; UInt32 uiSetValueON = 0xffffffff; UInt32 uiGetValueON = 0xffffffff; UInt32 uiGetMAX = 0x0; UInt32 uiGetMIN = 0xffffffff; ushort setSizeByte = 0; ushort getSizeByte = 0; UInt32 uiSetValueOFF = 0xffffffff; TYPERSSIGNAL setRSignalType = TYPERSSIGNAL.NULL; TYPERSSIGNAL getRSignalType = TYPERSSIGNAL.NULL; //TYPERSSIGNAL rsSignalType = TYPERSSIGNAL.NULL; XmlTextReader reader = new XmlTextReader(XMLname); Buttons buttonsObj = new Buttons(); SysButton sysButton = null; double dI27MAX = 999; double dI15MAX = 999; double dI12MAX = 999; double dI05MAX = 999; double dI03MAX = 999; string sysButtonName = string.Empty; while (reader.Read()) { switch (reader.NodeType) { case XmlNodeType.Element: // Узел является элементом. if (reader.Name == "RS") { reader.MoveToNextAttribute(); if (reader.Name == "NAME") { if (bSectionConfig) { boardRSName = reader.Value; } } setRSignalType = TYPERSSIGNAL.NULL; getRSignalType = TYPERSSIGNAL.NULL; } paramName = reader.Name; str = "<" + reader.Name + ">"; if (reader.Name == "SIGNAL") { getSourceName = null; setSourceName = null; commentString = string.Empty; imageLinkString = string.Empty; dI27MAX = 999; dI15MAX = 999; dI12MAX = 999; dI05MAX = 999; dI03MAX = 999; reader.MoveToNextAttribute(); str += " " + reader.Name + "='" + reader.Value + "'" + ">"; if (reader.Name == "NAME") { //baseSignal = new BaseSignal(reader.Value); boardSignalName = reader.Value; } } //Console.Write("<" + reader.Name); else { // while (reader.MoveToNextAttribute()) // Чтение атрибутов. // str += " " + reader.Name + "='" + reader.Value + "'" + ">"; } if (reader.Name == "BUTTON") { reader.MoveToNextAttribute(); if (reader.Name == "NAME") { //baseSignal = new BaseSignal(reader.Value); sysButtonName = reader.Value; sysButton = new SysButton(sysButtonName); useSignalType = TYPESIGUSING.BUTTON; } } if (reader.Name == "SET") { bSectionSet = true; } if (reader.Name == "GET") { bSectionGet = true; getSourceName = ""; } if (reader.Name == "CONFIG") { bSectionConfig = true; } if (reader.Name == "PERIODIC") { useSignalType = TYPESIGUSING.PERIODIC; } if (reader.Name == "TEST") { useSignalType = TYPESIGUSING.TEST; } if (reader.Name == "MANUAL") { useSignalType = TYPESIGUSING.MANUAL; } str += ">"; //lstBxXML.Items.Add(str); break; case XmlNodeType.Text: // Вывести текст в каждом элементе. str = reader.Value; //lstBxXML.Items.Add(str); //Console.WriteLine(reader.Value); if (paramName == "SOURCE") { if (bSectionSet) { setSourceName = reader.Value; } if (bSectionGet) { getSourceName = reader.Value; } } if (paramName == "VALUEOFF") { uint uValue = 0xffffffff; if (str2uint(reader.Value, out uValue)) { if (bSectionSet) { uiSetValueOFF = uValue; } } } if (paramName == "MIN") { uint uValue = 0; if (str2uint(reader.Value, out uValue)) { if (bSectionGet) { getRSignalType = TYPERSSIGNAL.ANALOG; uiGetMIN = uValue; } } } if (paramName == "MAX") { uint uValue = 0; if (str2uint(reader.Value, out uValue)) { if (bSectionGet) { getRSignalType = TYPERSSIGNAL.ANALOG; uiGetMAX = uValue; } } } if (paramName == "VALUEON") { bool bValue; if (bool.TryParse(reader.Value, out bValue)) { if (bSectionSet) { setRSignalType = TYPERSSIGNAL.BIT; bSetValueON = bValue; } if (bSectionGet) { getRSignalType = TYPERSSIGNAL.BIT; bGetValueON = bValue; } } else { uint uValue = 0; if (str2uint(reader.Value, out uValue)) { if (bSectionSet) { setRSignalType = TYPERSSIGNAL.ANALOG; uiSetValueON = uValue; } if (bSectionGet) { uiGetValueON = uValue; } } } } if (paramName == "SIZEBYTE") { ushort val; if (ushort.TryParse(reader.Value, out val)) { if (bSectionSet) { setSizeByte = val; } if (bSectionGet) { getSizeByte = val; } } } if (paramName == "INDEXBYTE") { byte index; if (byte.TryParse(reader.Value, out index)) { if (bSectionSet) { setIndexByte = index; } if (bSectionGet) { getIndexByte = index; } } } if (paramName == "INDEXBIT") { byte index; if (byte.TryParse(reader.Value, out index)) { if (bSectionSet) { setIndexBit = index; } if (bSectionGet) { getIndexBit = index; } } } if (paramName == "COMMENT") { commentString = reader.Value; } if (paramName == "IMAGELINK") { imageLinkString = reader.Value; } if (paramName == "DELAY") { UInt16 _delay; if (UInt16.TryParse(reader.Value, out _delay)) { delay = _delay; } } if (paramName == "RUN") { //runTestName = reader.Value; //BoardSignal _boardSignal = getBoardSignal(runTestName, boardSignals); BoardSignal _boardSignal = getBoardSignal(reader.Value, boardSignals); if (_boardSignal != null) { switch (useSignalType) { case TYPESIGUSING.PERIODIC: periodic.listRun.Add(_boardSignal); break; case TYPESIGUSING.TEST: runTest.listRun.Add(_boardSignal); break; case TYPESIGUSING.MANUAL: manual.listRun.Add(_boardSignal); break; case TYPESIGUSING.BUTTON: sysButton.listRun.Add(_boardSignal); break; } } } if (paramName == "D27MAX") { double dValue = 0; if (str2double(reader.Value, out dValue)) { dI27MAX = dValue; } } if (paramName == "D15MAX") { double dValue = 0; if (str2double(reader.Value, out dValue)) { dI15MAX = dValue; } } if (paramName == "D12MAX") { double dValue = 0; if (str2double(reader.Value, out dValue)) { dI12MAX = dValue; } } if (paramName == "D5MAX") { double dValue = 0; if (str2double(reader.Value, out dValue)) { dI05MAX = dValue; } } if (paramName == "D3MAX") { double dValue = 0; if (str2double(reader.Value, out dValue)) { dI03MAX = dValue; } } /* * if (paramName == "VALUE") * { * * } * * * paramName = ""; */ if (paramName == "NUMBYTES") { ushort _numBytes; if (ushort.TryParse(reader.Value, out _numBytes)) { if (bSectionConfig) { numBytes = _numBytes; } } } if (paramName == "MARKER") { byte _marker; if (byte.TryParse(reader.Value.Substring(2), System.Globalization.NumberStyles.HexNumber, null, out _marker)) { if (bSectionConfig) { marker = _marker; } } } break; case XmlNodeType.EndElement: // Вывести конец элемента. //Console.Write("</" + reader.Name); if (reader.Name == "CONFIG") { bSectionConfig = false; } if (reader.Name == "RS") { if (bSectionConfig) { BaseRS baseRS; if ((baseRS = getBaseRS(standSignals, boardRSName)) != null) { GroupSignals groupRS = new GroupSignals(baseRS.Name, numBytes); if (groupRS.valueTX.Length > 0) { if (marker != 0xff) { groupRS.valueTX[0] = marker; } } groupRS.valueRX = new byte[64]; baseRS.Group = groupRS; BoardRS boardRS = new BoardRS(boardRSName, numBytes, marker); boardConfig.listBoardRS.Add(boardRS); } } } if (reader.Name == "SIGNAL") { bool err = false; iSet set = null; iGet get = null; if (setSourceName != null) { if (setSourceName.Substring(0, 2) != "RS") { BaseSignal baseSignal = getBaseSignal(standSignals, setSourceName); if (baseSignal != null) { switch (baseSignal.type) { case SIGNALTYPE.LOGIC: set = new Set_STAND_BIT(baseSignal, commentString, imageLinkString); break; case SIGNALTYPE.ARRAY: set = new Set_ARRAY(baseSignal, commentString, imageLinkString); break; case SIGNALTYPE.ANALOG: set = new Set_STAND_ANALOG(baseSignal, uiSetValueON, commentString, imageLinkString, uiSetValueOFF); break; } } else { err = true; } } else { //BaseRS baseRS=getBaseRS BaseRS baseRS = getBaseRS(standSignals, setSourceName); BoardRS boardRS = getBoardRS(boardConfig, setSourceName); if (setRSignalType == TYPERSSIGNAL.BIT) { set = new Set_RS_BIT(baseRS, boardRS, bSetValueON, setIndexByte, setIndexBit, commentString, imageLinkString); } else { if (setRSignalType == TYPERSSIGNAL.ANALOG) { set = new Set_RS_ANALOG(baseRS, boardRS, uiSetValueON, setSizeByte, setIndexByte, commentString, imageLinkString, uiSetValueOFF); } //baseRS, boardRS, bSetValueON, setIndexByte, setIndexBit, commentString, imageLinkString); } } } if (getSourceName != null) { if (getSourceName.Length >= 2) { if (getSourceName.Substring(0, 2) != "RS") { BaseSignal baseSignal = getBaseSignal(standSignals, getSourceName); if (baseSignal != null) { switch (baseSignal.type) { case SIGNALTYPE.LOGIC: get = new Get_STAND_BIT(baseSignal); break; case SIGNALTYPE.ARRAY: get = new Get_ARRAY(baseSignal); break; case SIGNALTYPE.ANALOG: get = new Get_STAND_ANALOG(baseSignal, uiGetMIN, uiGetMAX); break; default: get = new Get_ARRAY(null); break; } } } else { BaseRS baseRS = getBaseRS(standSignals, getSourceName); BoardRS boardRS = getBoardRS(boardConfig, getSourceName); if (getRSignalType == TYPERSSIGNAL.BIT) { get = new Get_RS_BIT(baseRS, boardRS, bGetValueON, getIndexByte, getIndexBit); } else { if (getRSignalType == TYPERSSIGNAL.ANALOG) { get = new Get_RS_ANALOG(baseRS, uiGetMIN, uiGetMAX, getSizeByte, getIndexByte); } } } } if (get == null) { get = new Get_ARRAY(null); } } if (!err) { boardSignal = new BoardSignal(boardSignalName, set, get, delay, dI27MAX, dI15MAX, dI12MAX, dI05MAX, dI03MAX); } else { boardSignal = null; } boardSignals.listBoardSignals.Add(boardSignal); //boardSignals = new BoardSignals(); } if (reader.Name == "BUTTON") { if (sysButton != null) { buttonsObj.listButtons.Add(sysButton); useSignalType = TYPESIGUSING.NULL; sysButton = null; } } if (reader.Name == "SET") { bSectionSet = false; } if (reader.Name == "GET") { bSectionGet = false; } str = "</" + reader.Name + ">"; //lstBxXML.Items.Add(str); //Console.WriteLine(">"); //lstBxXML.Items.Add(">"); break; } } scenario = new BoardScenario(periodic, runTest, manual, buttonsObj); testBoard = new TestBoard(boardConfig, boardSignals, scenario); return(testBoard); }
public TestBoard(BoardConfig boardConfigObj, BoardSignals boardSignalsObj, BoardScenario scenarioObj) { config = boardConfigObj; signals = boardSignalsObj; scenario = scenarioObj; }