private static void CheckAvaliableTrack1() { if (ModbusProtocol.GetDataCoils(9) == false && ModbusProtocol.GetDataCoils(12) == false && ModbusProtocol.GetDataCoils(10) == false && ModbusProtocol.GetDataCoils(6) == false && ModbusProtocol.GetDataCoils(5) == false) { availableTrack = 401; } else if (ModbusProtocol.GetDataCoils(9) == true && ModbusProtocol.GetDataCoils(12) == false && ModbusProtocol.GetDataCoils(10) == false && ModbusProtocol.GetDataCoils(6) == true && ModbusProtocol.GetDataCoils(8) == false && ModbusProtocol.GetDataCoils(5) == false) { availableTrack = 402; } else if (ModbusProtocol.GetDataCoils(11) == false && ModbusProtocol.GetDataCoils(12) == true && ModbusProtocol.GetDataCoils(7) == false && ModbusProtocol.GetDataCoils(5) == true) { availableTrack = 403; } else if (ModbusProtocol.GetDataCoils(10) == true && ModbusProtocol.GetDataCoils(12) == false && ModbusProtocol.GetDataCoils(8) == true && ModbusProtocol.GetDataCoils(6) == true && ModbusProtocol.GetDataCoils(5) == false) { availableTrack = 404; } else if (ModbusProtocol.GetDataCoils(11) == true && ModbusProtocol.GetDataCoils(12) == true && ModbusProtocol.GetDataCoils(11) == true && ModbusProtocol.GetDataCoils(7) == true && ModbusProtocol.GetDataCoils(5) == true) { availableTrack = 405; } else { availableTrack = 0; } }
private static void Modbus_DataStoreWriteTo(object sender, DataStoreEventArgs e) { int number = 0; int Address = e.StartAddress;//e.StartAddress; switch (e.ModbusDataType) { case ModbusDataType.HoldingRegister: SetInputStatus(68, false); Console.WriteLine("Holding Register"); Console.WriteLine("address: " + Address.ToString()); Console.WriteLine("length frame: " + e.Data.B.Count.ToString()); Console.Write("data: "); for (int i = 1; i <= e.Data.B.Count; i++) { Console.Write(ModbusProtocol.GetDataHoldingRegister(Address + i) + ","); } Console.WriteLine(); ViewModel.VisualizationViewModel.HideMessage(); if (Address == 0) { if (GetDataCoils(15) == true) { ViewModel.VisualizationViewModel.TurnpikePutDown(SetSpeedTurnpike()); } else if (GetDataCoils(15) == false) { ViewModel.VisualizationViewModel.TurnpikePutUp(SetSpeedTurnpike()); } } break; case ModbusDataType.Coil: Console.WriteLine("Coil"); Console.WriteLine("address: " + Address.ToString()); Console.WriteLine("length frame: " + e.Data.A.Count.ToString()); Console.Write("data: "); for (int i = 0; i < e.Data.A.Count; i++) { Console.Write(ModbusProtocol.GetDataCoils(Address + i + 1) + ","); number++; } ViewModel.VisualizationViewModel.HideMessage(); SetInputStatus(68, false); Answers(Address); CheckAvaliableDeparture(); SetAvaliableTrack1(); SetAvaliableTrack2(); Console.WriteLine("avaliable track: {0}", availableTrack); Console.WriteLine("avaliable track2: {0}", availableTrack2); Console.WriteLine("avaliable departure track: {0}", avaliableDeparture); Console.WriteLine(); break; } }