public void AddAccess(string path, List <CItable> CITableList) { StreamReader sr = new StreamReader(path, Encoding.Default); String line; List <string> list = new List <string>(); while ((line = sr.ReadLine()) != null) { list.Add(line); } sr.Close(); foreach (var item in list) { string[] strs = item.Split(new char[] { ',' }); CItable access = new CItable(); access.Number = Convert.ToInt16(strs[0]); access.StartSection = strs[1]; access.EndSection = strs[2]; access.StartSignal = strs[3]; access.EndSignal = strs[4]; access.AccessState = 0; access.Direction = Convert.ToInt16(strs[6]); string[] section = strs[5].Split(new char[] { '#' }); access.Section = new List <string>(); foreach (var sec in section) { access.Section.Add(sec); } CITableList.Add(access); } }
public byte[] DetermineMA(HandleVOBCData Handle) { this.Handle = Handle; int TrainSectionInt = Convert.ToInt16(HandleVOBCData.TrainPosition[Handle.NID_Train][1]) * 256 + Convert.ToInt16(HandleVOBCData.TrainPosition[Handle.NID_Train][0]);//纯数字 int RailSwitchInt = Convert.ToInt16(HandleVOBCData.TrainPosition[Handle.NID_Train][2]); string RailSwitchString; string TrainSectionString; if (TrainSectionInt == 501) { TrainSectionString = "XJ1G"; } else if (TrainSectionInt == 502) { TrainSectionString = "XJ2G"; } else { TrainSectionString = TrainSectionInt.ToString(); } if (TrainSectionString == "118") { } RailSwitchString = RailSwitchInt.ToString(); int TrainDir = Handle.Q_TrainRealDirection; foreach (var item in MainWindow.stationElements_.Elements) { if (item is Section) { if (item.Name.Length > 2) { if (item.Name.Substring(0, 3) == TrainSectionString) { FindCurTrainIn(TrainSectionString + "-0", TrainDir); } } } if (item is RailSwitch) { if ((item as RailSwitch).SectionName.Length > 2) { if ((item as RailSwitch).SectionName.Substring(0, 3) == TrainSectionString) { FindCurTrainIn(TrainSectionString + "-" + RailSwitchString, TrainDir); } } } } foreach (var item in MainWindow.stationElements_1_.Elements) { if (item is Section) { if (item.Name.Length > 2) { if (item.Name.Substring(0, 3) == TrainSectionString) { FindCurTrainIn(TrainSectionString + "-0", TrainDir); } } } if (item is RailSwitch) { if ((item as RailSwitch).SectionName.Length > 2) { if ((item as RailSwitch).SectionName.Substring(0, 3) == TrainSectionString) { FindCurTrainIn(TrainSectionString + "-" + RailSwitchString, TrainDir); } } } } CItable NextAccess = null; if (CurTrainIn.Count != 0) { foreach (var item in CurTrainIn) { if ((TrainSectionString + "-" + RailSwitchString) == item.StartSection) { Signal startSignal = TraverseSignal(item.StartSignal) as Signal; if (!startSignal.IsSignalOpen) { return(ConvertToByte(TrainSectionString, 130, TrainDir)); } } int num = item.Section.IndexOf(TrainSectionString + "-" + RailSwitchString); if (item.IsReturn) { MAEndType = 0x02; for (int i = num; i < item.Section.Count; i++) { if (!Route.Contains(item.Section[i])) { Route.Add(item.Section[i]); } } if (Route.Count > 1) { for (int i = 1; i < Route.Count; i++) { if (Route[i].Substring(0, 3) != item.Section[num].Substring(0, 3)) { byte[] a = SectionAxleOccpy(Route[i], TrainDir); if (a != null) { for (int x = i; x < Route.Count; x++) { Route.Remove(Route[i]); } return(a); } } byte[] b = SectionOccpy(Route[i], TrainDir); if (b != null) { for (int x = i; x < Route.Count; x++) { Route.Remove(Route[i]); } return(b); } } return(SetAccessEndMA(Route[Route.Count - 1], TrainDir)); } else if (Route.Count == 1) { return(SetAccessEndMA(Route[Route.Count - 1], TrainDir)); } } else { for (int i = num; i < item.Section.Count; i++) { if (!Route.Contains(item.Section[i])) { Route.Add(item.Section[i]); } if (item.Section[i].Substring(0, 3) != item.Section[num].Substring(0, 3)) { byte[] a = SectionAxleOccpy(item.Section[i], TrainDir); if (a != null) { return(a); } } byte[] b = SectionOccpy(item.Section[i], TrainDir); if (b != null) { return(b); } CItable Access = IsApproachSection(item.Section[i], TrainDir); if (Access != null) { NextAccess = Access; } } } } } if (NextAccess != null) { bool HasNextAccessOpen = true; while (HasNextAccessOpen) { if (NextAccess.IsReturn) { for (int i = 0; i < NextAccess.Section.Count; i++) { if (!Route.Contains(NextAccess.Section[i])) { Route.Add(NextAccess.Section[i]); } } MAEndType = 0x02; return(SetReturnAccess(Route, TrainDir)); } else { CItable Next = null; for (int i = 0; i < NextAccess.Section.Count; i++) { if (NextAccess.Section[i] == TrainSectionString + "-" + RailSwitchString) { } else { if (!Route.Contains(NextAccess.Section[i])) { Route.Add(NextAccess.Section[i]); } byte[] a = SectionOccpy(NextAccess.Section[i], TrainDir); if (a != null) { return(a); } Next = IsApproachSection(NextAccess.Section[i], TrainDir); } } if (Next != null) { NextAccess = Next; } else { HasNextAccessOpen = false; } } } } else { if (CurTrainIn.Count > 0) { NextAccess = CurTrainIn[CurTrainIn.Count - 1]; } else { return(null); } } MASection = NextAccess.EndSection; return(SetAccessEndMA(MASection, TrainDir));; }