/*#--------------------------------------------------------------------------#*/
        /*  Description: FiddleYardApplication constructor
         *
         *  Input(s)   :
         *
         *  Output(s)  :
         *
         *  Returns    :
         *
         *  Pre.Cond.  :
         *
         *  Post.Cond. :
         *
         *  Notes      :
         *
         */
        /*#--------------------------------------------------------------------------#*/
        public FiddleYardApplication(string instance, FiddleYardIOHandleVariables FYIOHandleVar, iFiddleYardIOHandle iFYIOH)
        {
            m_instance = instance;
            m_FYIOHandleVar = FYIOHandleVar;
            m_iFYIOH = iFYIOH;

            if ("TOP" == m_instance)
            {
                path = @"c:\localdata\Siebwalde\" + DateTime.Now.Day + "-" + DateTime.Now.Month + "-" + DateTime.Now.Year + "_FiddleYardApplicationTOP.txt"; //  different logging file per target, this is default
                FiddleYardApplicationLogging = new Log2LoggingFile(path);
            }
            else if ("BOT" == m_instance)
            {
                path = @"c:\localdata\Siebwalde\" + DateTime.Now.Day + "-" + DateTime.Now.Month + "-" + DateTime.Now.Year + "_FiddleYardApplicationBOT.txt"; //  different logging file per target, this is default
                FiddleYardApplicationLogging = new Log2LoggingFile(path);
            }

            // Sub programs
            FYAppVar = new FiddleYardApplicationVariables(m_FYIOHandleVar);                 // FiddleYard Application variables class, holds all variables and functions regarding variables
            FYMIP50 = new FiddleYardMip50(m_instance, m_FYIOHandleVar, m_iFYIOH, FYAppVar);
            FYAppRun = new FiddleYardAppRun(m_FYIOHandleVar, m_iFYIOH, FYAppVar, FYMIP50, FiddleYardApplicationLogging);
            FYTDT = new FiddleYardTrainDetection(m_FYIOHandleVar, FYAppVar, FYMIP50, FiddleYardApplicationLogging);
            FYAppInit = new FiddleYardAppInit(m_FYIOHandleVar, FYAppVar, FYMIP50, FYTDT, FiddleYardApplicationLogging);
            FYFORM = new FiddleYardForm(this);//, FYMip50SettingsForm);

            //Init and setup FYFORM (after the creation of the sensors and commands)
            if ("TOP" == m_instance)
                FYFORM.Name = "FiddleYardTOP";
            else if ("BOT" == m_instance)
                FYFORM.Name = "FiddleYardBOT";

            FYFORM.Show();
            FYFORM.Hide();
            FYFORM.Connect(m_FYIOHandleVar, FYAppVar); // connect the Form to the FYIOHandle interface
        }
 /*#--------------------------------------------------------------------------#*/
 /*  Description: FiddleYardSimTrainDetect Constructor
  *
  *  Input(s)   :
  *
  *  Output(s)  :
  *
  *  Returns    :
  *
  *  Pre.Cond.  :
  *
  *  Post.Cond. :
  *
  *  Notes      :
  */
 /*#--------------------------------------------------------------------------#*/
 public FiddleYardSimTrainDetect(iFiddleYardSimulator iFYSim, Log2LoggingFile FiddleYardSimulatorLogging, FiddleYardSimulatorVariables FYSimVar, FiddleYardSimMove FYMove)
 {
     m_iFYSim = iFYSim;
     m_FYSimLog = FiddleYardSimulatorLogging;
     m_FYSimVar = FYSimVar;
     m_FYMove = FYMove;
     FiddleTrDtState = 0;
     AliveUpdateCnt = 0;
 }
 /*#--------------------------------------------------------------------------#*/
 /*  Description: FiddleYardOneMove Constructor
  *
  *  Input(s)   :
  *
  *  Output(s)  :
  *
  *  Returns    :
  *
  *  Pre.Cond.  :
  *
  *  Post.Cond. :
  *
  *  Notes      :
  */
 /*#--------------------------------------------------------------------------#*/
 public FiddleYardSimMove(iFiddleYardSimulator iFYSim, Log2LoggingFile FiddleYardSimulatorLogging, FiddleYardSimulatorVariables FYSimVar)
 {
     m_iFYSim = iFYSim;
     m_FYSimLog = FiddleYardSimulatorLogging;
     m_FYSimVar = FYSimVar;
     FiddleOneMoveState = 0;
     AliveUpdateCnt = 0;
     GetTrackNoCnt = 0;
     GetNewTrackNo = 0;
     MoveDirection = null;
 }
 /*#--------------------------------------------------------------------------#*/
 /*  Description: FiddleYardAppInit()
  *               Constructor
  *
  *
  *  Input(s)   :
  *
  *  Output(s)  :
  *
  *  Returns    :
  *
  *  Pre.Cond.  :
  *
  *  Post.Cond. :
  *
  *  Notes      :
  */
 /*#--------------------------------------------------------------------------#*/
 public FiddleYardAppInit(FiddleYardIOHandleVariables FYIOHandleVar, FiddleYardApplicationVariables FYAppVar, FiddleYardMip50 FYMIP50, FiddleYardTrainDetection FYTDT, Log2LoggingFile FiddleYardApplicationLogging)
 {
     m_FYIOHandleVar = FYIOHandleVar;
     m_FYAppVar = FYAppVar;
     m_FYMIP50 = FYMIP50;
     m_FYTDT = FYTDT;
     m_FYAppLog = FiddleYardApplicationLogging;
     FiddleYardInitStarted = new MessageUpdater();
     State_Machine = State.Idle;
     Message Msg_uControllerReady = new Message("uControllerReady", " uControllerReady ", (name, log) => SetMessage(name, log)); // initialize and subscribe readback action, Message
     m_FYIOHandleVar.uControllerReady.Attach(Msg_uControllerReady);
 }
        /*#--------------------------------------------------------------------------#*/
        /*  Description: FiddleYardTrainDetection
         *               Constructor
         *
         *
         *  Input(s)   :
         *
         *  Output(s)  :
         *
         *  Returns    :
         *
         *  Pre.Cond.  :
         *
         *  Post.Cond. :
         *
         *  Notes      :
         */
        /*#--------------------------------------------------------------------------#*/
        public FiddleYardTrainDetection(FiddleYardIOHandleVariables FYIOHandleVar, FiddleYardApplicationVariables FYAppVar, FiddleYardMip50 FYMIP50, Log2LoggingFile FiddleYardApplicationLogging)
        {
            m_FYIOHandleVar = FYIOHandleVar;
            m_FYAppVar = FYAppVar;
            m_FYMIP50 = FYMIP50;
            m_FYAppLog = FiddleYardApplicationLogging;
            State_Machine = State.Idle;

            Sensor Sns_CL_10_Heart = new Sensor("CL10Heart", " CL 10 Heart ", 0, (name, val, log) => SetLedIndicator(name, val, log)); // initialize and subscribe sensors
            FYAppVar.CL10Heart.Attach(Sns_CL_10_Heart);
            Sensor Sns_F10 = new Sensor("F10", " F10 ", 0, (name, val, log) => SetLedIndicator(name, val, log)); // initialize and subscribe sensors
            FYAppVar.F10.Attach(Sns_F10);
        }
        /*#--------------------------------------------------------------------------#*/
        /*  Description: FiddleYardAppTrainDrive()
         *               Constructor
         *
         *
         *  Input(s)   :
         *
         *  Output(s)  :
         *
         *  Returns    :
         *
         *  Pre.Cond.  :
         *
         *  Post.Cond. :
         *
         *  Notes      :
         */
        /*#--------------------------------------------------------------------------#*/
        public FiddleYardAppTrainDrive(FiddleYardIOHandleVariables FYIOHandleVar, iFiddleYardIOHandle iFYIOH, FiddleYardApplicationVariables FYAppVar,
            FiddleYardMip50 FYMIP50, Log2LoggingFile FiddleYardApplicationLogging)
        {
            m_FYIOHandleVar = FYIOHandleVar;
            m_iFYIOH = iFYIOH;
            m_FYAppVar = FYAppVar;
            m_FYMIP50 = FYMIP50;
            m_FYAppLog = FiddleYardApplicationLogging;
            TrainDriveIn_Machine = State.Start;
            TrainDriveOut_Machine = State.Start;
            TrainDriveThrough_Machine = State.Start;

            Message Msg_uControllerReady = new Message("uControllerReady", " uControllerReady ", (name, log) => SetMessage(name, log)); // initialize and subscribe readback action, Message
            m_FYIOHandleVar.uControllerReady.Attach(Msg_uControllerReady);
        }
        /*#--------------------------------------------------------------------------#*/
        /*  Description: FiddleYardAppRun()
         *               Constructor
         *
         *
         *  Input(s)   :
         *
         *  Output(s)  :
         *
         *  Returns    :
         *
         *  Pre.Cond.  :
         *
         *  Post.Cond. :
         *
         *  Notes      :
         */
        /*#--------------------------------------------------------------------------#*/
        public FiddleYardAppRun(FiddleYardIOHandleVariables FYIOHandleVar, iFiddleYardIOHandle iFYIOH, FiddleYardApplicationVariables FYAppVar, FiddleYardMip50 FYMIP50, Log2LoggingFile FiddleYardApplicationLogging)
        {
            m_iFYIOH = iFYIOH;
            m_FYIOHandleVar = FYIOHandleVar;
            m_FYAppVar = FYAppVar;
            m_FYMIP50 = FYMIP50;
            m_FYAppLog = FiddleYardApplicationLogging;
            FYAppTrainDrive = new FiddleYardAppTrainDrive(m_FYIOHandleVar, m_iFYIOH, m_FYAppVar, m_FYMIP50, m_FYAppLog);
            State_Machine = State.Idle;

            Message Msg_TrackPower15VDown = new Message("TrackPower15VDown", " TrackPower15VDown ", (name, log) => SetMessage(name, 0, log)); // initialize and subscribe readback action, Message
            m_FYIOHandleVar.TrackPower15VDown.Attach(Msg_TrackPower15VDown);
            Sensor Sns_TrackPower15V = new Sensor("15VTrackPower", " 15V Track Power ", 0, (name, val, log) => SetMessage(name, val, log)); // initialize and subscribe sensors
            m_FYIOHandleVar.TrackPower15V.Attach(Sns_TrackPower15V);
            Command Act_Collect = new Command("Collect", (name) => SetMessage(name, 0, "")); // initialize and subscribe Commands
            m_FYAppVar.FormCollect.Attach(Act_Collect);
        }
Пример #8
0
        public Main()
        {
            Siebwalde_Application.Properties.Settings.Default.Reload();
            SiebwaldeApplicationMainLogging = new Log2LoggingFile(path);
            this.StartPosition = FormStartPosition.Manual;
            this.Location = new Point(0, 0);
            InitializeComponent();

            StartApplication.Visible = true;
            LStartApplication.Visible = true;
            FiddleYardFormTop.Visible = false;
            FiddleYardFormBot.Visible = false;
            MaintrackForm.Visible = false;
            YardForm.Visible = false;

            FYLinkActivity.Visible = false;
            LFYLinkActivity.Visible = false;
            FYLinkActivity.Minimum = 0;
            FYLinkActivity.Maximum = LINKACTMAX;
            FYLinkActivity.Step = 1;
            FYLinkActivity.Value = 0;
            FYLinkActivity.Location = new System.Drawing.Point(this.Width - FYLinkActivity.Width - 20, 1);
            LFYLinkActivity.Location = new System.Drawing.Point(this.Width - FYLinkActivity.Width - 20 - LFYLinkActivity.Width, 6);
        }
        private UInt32[] TrackForward = new UInt32[12] { 0, 0, 42800, 85600, 128400, 171200, 214000, 256800, 299600, 342400, 385200, 428000 }; // New track coordinates forward movement 1 --> 11 to be moved and get from Application Variables

        #endregion Fields

        #region Constructors

        /*#--------------------------------------------------------------------------#*/
        /*  Description: FiddleYardSimulator constructor
         *
         *  Input(s)   :
         *
         *  Output(s)  :
         *
         *  Returns    :
         *
         *  Pre.Cond.  :
         *
         *  Post.Cond. :
         *
         *  Notes      :
         *
         */
        /*#--------------------------------------------------------------------------#*/
        public FiddleYardSimulator(string Instance, FiddleYardIOHandleVariables FYIOHandleVar)
        {
            m_FYIOHandleVar = FYIOHandleVar;
            m_instance = Instance;

            if ("TOP" == m_instance)
            {
                path = @"c:\localdata\Siebwalde\" + DateTime.Now.Day + "-" + DateTime.Now.Month + "-" + DateTime.Now.Year + "_FiddleYardSimulatorTOP.txt"; //  different logging file per target, this is default
                FiddleYardSimulatorLogging = new Log2LoggingFile(path);
            }
            else if ("BOT" == m_instance)
            {
                path = @"c:\localdata\Siebwalde\" + DateTime.Now.Day + "-" + DateTime.Now.Month + "-" + DateTime.Now.Year + "_FiddleYardSimulatorBOT.txt"; //  different logging file per target, this is default
                FiddleYardSimulatorLogging = new Log2LoggingFile(path);
            }

            FYSimVar = new FiddleYardSimulatorVariables();
            FYSimMove = new FiddleYardSimMove(this, FiddleYardSimulatorLogging, FYSimVar);
            FYSimTrDt = new FiddleYardSimTrainDetect(this, FiddleYardSimulatorLogging, FYSimVar, FYSimMove);

            FYSimVar.TrackNo.Count = 1;

            Sensor Sns_FYSimSpeedSetting = new Sensor("FYSimSpeedSetting", " FYSimSpeedSetting ", 0, (name, val, log) => SimulatorSettings(name, val, log)); // initialize and subscribe sensors
            Siebwalde_Application.Properties.Settings.Default.FYSimSpeedSetting.Attach(Sns_FYSimSpeedSetting);
        }
        /*#--------------------------------------------------------------------------#*/
        /*  Description: Connect
         *               hookup sensors/messages etc
         *
         *
         *
         *  Input(s)   :
         *
         *  Output(s)  :
         *
         *  Returns    :
         *
         *  Pre.Cond.  :
         *
         *  Post.Cond. :
         *
         *  Notes      :
         */
        /*#--------------------------------------------------------------------------#*/
        public void Connect(FiddleYardIOHandleVariables FYIOHandleVar, FiddleYardApplicationVariables FYAppVar)
        {
            m_FYIOHandleVar = FYIOHandleVar;    // connect to FYIOHandle interface, save interface in variable
            m_FYAppVar = FYAppVar;                  // connect to FYApplication variables, save interface in variable

            if (this.Name == "FiddleYardTOP")
            {
                path = @"c:\localdata\Siebwalde\" + DateTime.Now.Day + "-" + DateTime.Now.Month + "-" + DateTime.Now.Year + "_FiddleYardFormTOP.txt"; //  different logging file per target, this is default
                FiddleYardFormLogging = new Log2LoggingFile(path);
            }
            else if (this.Name == "FiddleYardBOT")
            {
                path = @"c:\localdata\Siebwalde\" + DateTime.Now.Day + "-" + DateTime.Now.Month + "-" + DateTime.Now.Year + "_FiddleYardFormBOT.txt"; //  different logging file per target, this is default
                FiddleYardFormLogging = new Log2LoggingFile(path);
            }

            #region Attach sensors
            //Sensors -----------------------------> to be pushed from Application variables
            Sensor Led_CL_10_Heart = new Sensor("LLed_Heart", " CL 10 Heart ",0, (name, val, log) => SetLedIndicator(name, val, log)); // initialize and subscribe sensors
            m_FYAppVar.CL10Heart.Attach(Led_CL_10_Heart);
            Sensor Led_F11 = new Sensor("LLed_F11", " F11 ", 0, (name, val, log) => SetLedIndicator(name, val, log)); // initialize and subscribe sensors
            m_FYAppVar.F11.Attach(Led_F11);
            Sensor Led_EOS10 = new Sensor("LLed_EOS10", " EOS 10 ", 0, (name, val, log) => SetLedIndicator(name, val, log)); // initialize and subscribe sensors
            m_FYAppVar.EOS10.Attach(Led_EOS10);
            Sensor Led_EOS11 = new Sensor("LLed_EOS11", " EOS 11 ", 0, (name, val, log) => SetLedIndicator(name, val, log)); // initialize and subscribe sensors
            m_FYAppVar.EOS11.Attach(Led_EOS11);
            Sensor Led_F13 = new Sensor("LLed_F13", " F13 ", 0, (name, val, log) => SetLedIndicator(name, val, log)); // initialize and subscribe sensors
            m_FYAppVar.F13.Attach(Led_F13);
            Sensor Led_F12 = new Sensor("LLed_F12", " F12 ", 0, (name, val, log) => SetLedIndicator(name, val, log)); // initialize and subscribe sensors
            m_FYAppVar.F12.Attach(Led_F12);
            Sensor Led_Block5B = new Sensor("LLed_Block5B", " Occupied from 5B ", 0, (name, val, log) => SetLedIndicator(name, val, log)); // initialize and subscribe sensors
            m_FYAppVar.Block5B.Attach(Led_Block5B);
            Sensor Led_Block8A = new Sensor("LLed_Block8A", " Occupied from 8A ", 0, (name, val, log) => SetLedIndicator(name, val, log)); // initialize and subscribe sensors
            m_FYAppVar.Block8A.Attach(Led_Block8A);
            Sensor Led_TrackPowerTop = new Sensor("LLed_TrackPower", " Enable Track ", 0, (name, val, log) => SetLedIndicator(name, val, log)); // initialize and subscribe sensors
            m_FYAppVar.TrackPower.Attach(Led_TrackPowerTop);
            Sensor Led_Block5BIn = new Sensor("LLed_Block5BIn", " Occupied to 5B ", 0, (name, val, log) => SetLedIndicator(name, val, log)); // initialize and subscribe sensors
            m_FYAppVar.Block5BIn.Attach(Led_Block5BIn);
            Sensor Led_Block6In = new Sensor("LLed_Block6In", " Occupied to 6 ", 0, (name, val, log) => SetLedIndicator(name, val, log)); // initialize and subscribe sensors
            m_FYAppVar.Block6In.Attach(Led_Block6In);
            Sensor Led_Block7In = new Sensor("LLed_Block7In", " Occupied to 7 ", 0, (name, val, log) => SetLedIndicator(name, val, log)); // initialize and subscribe sensors
            m_FYAppVar.Block7In.Attach(Led_Block7In);
            Sensor Led_ResistorTop = new Sensor("LLed_Resistor", " Occupied Resistor ", 0, (name, val, log) => SetLedIndicator(name, val, log)); // initialize and subscribe sensors
            m_FYAppVar.Resistor.Attach(Led_ResistorTop);
            Sensor Led_Track1Top = new Sensor("LLed_Track1", " Trains On Fiddle Yard Track1 ", 0, (name, val, log) => SetLedIndicator(name, val, log)); // initialize and subscribe sensors
            m_FYAppVar.Track1.Attach(Led_Track1Top);
            Sensor Led_Track2Top = new Sensor("LLed_Track2", " Trains On Fiddle Yard Track2 ", 0, (name, val, log) => SetLedIndicator(name, val, log)); // initialize and subscribe sensors
            m_FYAppVar.Track2.Attach(Led_Track2Top);
            Sensor Led_Track3Top = new Sensor("LLed_Track3", " Trains On Fiddle Yard Track3 ", 0, (name, val, log) => SetLedIndicator(name, val, log)); // initialize and subscribe sensors
            m_FYAppVar.Track3.Attach(Led_Track3Top);
            Sensor Led_Track4Top = new Sensor("LLed_Track4", " Trains On Fiddle Yard Track4 ", 0, (name, val, log) => SetLedIndicator(name, val, log)); // initialize and subscribe sensors
            m_FYAppVar.Track4.Attach(Led_Track4Top);
            Sensor Led_Track5Top = new Sensor("LLed_Track5", " Trains On Fiddle Yard Track5 ", 0, (name, val, log) => SetLedIndicator(name, val, log)); // initialize and subscribe sensors
            m_FYAppVar.Track5.Attach(Led_Track5Top);
            Sensor Led_Track6Top = new Sensor("LLed_Track6", " Trains On Fiddle Yard Track6 ", 0, (name, val, log) => SetLedIndicator(name, val, log)); // initialize and subscribe sensors
            m_FYAppVar.Track6.Attach(Led_Track6Top);
            Sensor Led_Track7Top = new Sensor("LLed_Track7", " Trains On Fiddle Yard Track7 ", 0, (name, val, log) => SetLedIndicator(name, val, log)); // initialize and subscribe sensors
            m_FYAppVar.Track7.Attach(Led_Track7Top);
            Sensor Led_Track8Top = new Sensor("LLed_Track8", " Trains On Fiddle Yard Track8 ", 0, (name, val, log) => SetLedIndicator(name, val, log)); // initialize and subscribe sensors
            m_FYAppVar.Track8.Attach(Led_Track8Top);
            Sensor Led_Track9Top = new Sensor("LLed_Track9", " Trains On Fiddle Yard Track9 ", 0, (name, val, log) => SetLedIndicator(name, val, log)); // initialize and subscribe sensors
            m_FYAppVar.Track9.Attach(Led_Track9Top);
            Sensor Led_Track10Top = new Sensor("LLed_Track10", " Trains On Fiddle Yard Track10 ", 0, (name, val, log) => SetLedIndicator(name, val, log)); // initialize and subscribe sensors
            m_FYAppVar.Track10.Attach(Led_Track10Top);
            Sensor Led_Track11Top = new Sensor("LLed_Track11", " Trains On Fiddle Yard Track11 ", 0, (name, val, log) => SetLedIndicator(name, val, log)); // initialize and subscribe sensors
            m_FYAppVar.Track11.Attach(Led_Track11Top);
            Sensor Led_Block6 = new Sensor("LLed_Block6", " Occupied from 6 ", 0, (name, val, log) => SetLedIndicator(name, val, log)); // initialize and subscribe sensors
            m_FYAppVar.Block6.Attach(Led_Block6);
            Sensor Led_Block7 = new Sensor("LLed_Block7", " Occupied from 7 ", 0, (name, val, log) => SetLedIndicator(name, val, log)); // initialize and subscribe sensors
            m_FYAppVar.Block7.Attach(Led_Block7);
            Sensor Led_F10 = new Sensor("LLed_F10", " F10 ", 0, (name, val, log) => SetLedIndicator(name, val, log)); // initialize and subscribe sensors
            m_FYAppVar.F10.Attach(Led_F10);
            Sensor Led_M10 = new Sensor("LLed_M10", " M10 ", 0, (name, val, log) => SetLedIndicator(name, val, log)); // initialize and subscribe sensors
            m_FYAppVar.M10.Attach(Led_M10);
            Sensor Led_TrackNoTop = new Sensor("Track_No", " Track Nr ", 0, (name, val, log) => SetLedIndicator(name, val, log)); // initialize and subscribe sensors
            m_FYAppVar.TrackNo.Attach(Led_TrackNoTop);
            Sensor Led_TrackPower15VTOP = new Sensor("LLed_TrackPower15V", " 15V Track Power ", 0, (name, val, log) => SetLedIndicator(name, val, log)); // initialize and subscribe sensors
            m_FYAppVar.TrackPower15V.Attach(Led_TrackPower15VTOP);

            Sensor Sns_ForceNextTrack = new Sensor("ForceNextTrack", " ForceNextTrack ", 0, (name, val, log) => SetLedIndicator(name, val, log)); // initialize and subscribe sensors
            m_FYAppVar.TrainDriveOutPointer.Attach(Sns_ForceNextTrack);

            //Messages
            Message Msg_TrainDetectionTop = new Message("TrainDetectionFinished", " Train Detection Finished ", (name, log) => SetMessage(name, log)); // initialize and subscribe readback action, Message
            m_FYAppVar.TrainDetection.Attach(Msg_TrainDetectionTop);
            Message Msg_TrainDetectionStarted = new Message("TrainDetectionStarted", " Train Detection Started ", (name, log) => SetMessage(name, log)); // initialize and subscribe readback action, Message
            m_FYAppVar.TrainDetectionStarted.Attach(Msg_TrainDetectionStarted);
            Message Msg_FiddleYardStopped = new Message("FiddleYardStopped", " FiddleYard Auto mode Stopped ", (name, log) => SetMessage(name, log));
            m_FYAppVar.FiddleYardStopped.Attach(Msg_FiddleYardStopped);
            Message Msg_FiddleYardStart = new Message("FiddleYardStart", " FiddleYard Auto mode Start ", (name, log) => SetMessage(name, log));
            m_FYAppVar.FiddleYardStart.Attach(Msg_FiddleYardStart);
            Message Msg_FiddleYardNotHomed = new Message("FiddleYardNotHomed", " FiddleYard not homed, start homing ", (name, log) => SetMessage(name, log));
            m_FYAppVar.FiddleYardNotHomed.Attach(Msg_FiddleYardNotHomed);
            Message Msg_FiddleYardHomingFinished = new Message("FiddleYardHomingFinished", " FiddleYard homing finished ", (name, log) => SetMessage(name, log));
            m_FYAppVar.FiddleYardHomingFinished.Attach(Msg_FiddleYardHomingFinished);
            Message Msg_FiddleYardTrainObstruction = new Message("FiddleYardTrainObstruction", " FiddleYard train obstruction... ", (name, log) => SetMessage(name, log));
            m_FYAppVar.FiddleYardTrainObstruction.Attach(Msg_FiddleYardTrainObstruction);
            Message Msg_FiddleYardTrackAligned = new Message("FiddleYardTrackAligned", " FiddleYard track aligned ", (name, log) => SetMessage(name, log));
            m_FYAppVar.FiddleYardTrackAligned.Attach(Msg_FiddleYardTrackAligned);
            Message Msg_TrainHasLeftFiddleYardSuccessfully = new Message("TrainHasLeftFiddleYardSuccessfully", " Train has left FiddleYard successfully ", (name, log) => SetMessage(name, log));
            m_FYAppVar.TrainHasLeftFiddleYardSuccessfully.Attach(Msg_TrainHasLeftFiddleYardSuccessfully);
            Message Msg_EMOPressed15VTrackPowerDown = new Message("EMOPressed15VTrackPowerDown", " EMO pressed, 15V Track Power down! ", (name, log) => SetMessage(name, log));
            m_FYAppVar.EMOPressed15VTrackPowerDown.Attach(Msg_EMOPressed15VTrackPowerDown);
            Message Msg_EMOPressed15VTrackPowerUp = new Message("EMOPressed15VTrackPowerUp", " EMO released, 15V Track Power up! ", (name, log) => SetMessage(name, log));
            m_FYAppVar.EMOPressed15VTrackPowerUp.Attach(Msg_EMOPressed15VTrackPowerUp);
            Message Msg_FiddleYardAutoModeStart = new Message("FiddleYardAutoModeStart", " FiddleYard Auto mode Start ", (name, log) => SetMessage(name, log));
            m_FYAppVar.FiddleYardAutoModeStart.Attach(Msg_FiddleYardAutoModeStart);
            Message Msg_FiddleYardInit = new Message("FiddleYardInit", " FiddleYard init... ", (name, log) => SetMessage(name, log));
            m_FYAppVar.FiddleYardInit.Attach(Msg_FiddleYardInit);
            Message Msg_FiddleYardAutoModeIsGoingToStop = new Message("FiddleYardAutoModeIsGoingToStop", " FiddleYard Auto mode is going to stop... ", (name, log) => SetMessage(name, log));
            m_FYAppVar.FiddleYardAutoModeIsGoingToStop.Attach(Msg_FiddleYardAutoModeIsGoingToStop);
            Message Msg_FiddleYardReset = new Message("FiddleYardReset", " FiddleYard Reset ", (name, log) => SetMessage(name, log));
            m_FYAppVar.FiddleYardReset.Attach(Msg_FiddleYardReset);
            Message Msg_FiddleYardInitFinished = new Message("FiddleYardInitFinished", " FiddleYard init Finished ", (name, log) => SetMessage(name, log));
            m_FYAppVar.FiddleYardInitFinished.Attach(Msg_FiddleYardInitFinished);
            Message Msg_FiddleYardApplicationRunning = new Message("FiddleYardApplicationRunning", " FiddleYard Application running... ", (name, log) => SetMessage(name, log));
            m_FYAppVar.FiddleYardApplicationRunning.Attach(Msg_FiddleYardApplicationRunning);
            Message Msg_FiddleYardAutoModeIsStopped = new Message("FiddleYardAutoModeIsStopped", " FiddleYard Auto mode is Stopped ", (name, log) => SetMessage(name, log));
            m_FYAppVar.FiddleYardAutoModeIsStopped.Attach(Msg_FiddleYardAutoModeIsStopped);
            Message Msg_CollectingTrainsEnabled = new Message("CollectingTrainsEnabled", " Collecting Trains enabled ", (name, log) => SetMessage(name, log));
            m_FYAppVar.CollectingTrainsEnabled.Attach(Msg_CollectingTrainsEnabled);
            Message Msg_CollectingTrainsDisabled = new Message("CollectingTrainsDisabled", " Collecting Trains disabled ", (name, log) => SetMessage(name, log));
            m_FYAppVar.CollectingTrainsDisabled.Attach(Msg_CollectingTrainsDisabled);
            //Message Msg_FiddleYardMoveAndF12Assert = new Message("FiddleYardMoveAndF12Assert", " FiddleYard Moving And F12 Assert!!! FiddleYard Stopped!!! ", (name, log) => SetMessage(name, log));
            //m_FYIOHandleVar.FiddleYardMoveAndF12Assert.Attach(Msg_FiddleYardMoveAndF12Assert);
            //Message Msg_FiddleYardMoveAndF13Assert = new Message("FiddleYardMoveAndF13Assert", " FiddleYard Moving And F13 Assert!!! FiddleYard Stopped!!! ", (name, log) => SetMessage(name, log));
            //m_FYIOHandleVar.FiddleYardMoveAndF13Assert.Attach(Msg_FiddleYardMoveAndF13Assert);
            Message Msg_FYNotHomed = new Message("FYNotHomed", " Fiddle Yard Not Homed! Press Home FY Button to start Homing... ", (name, log) => SetMessage(name, log));
            m_FYAppVar.FYNotHomed.Attach(Msg_FYNotHomed);
            #endregion Attach sensors

            // Init Track colors
            LLed_Track1.BackColor = m_FYAppVar.TrackNotInitializedColor;
            LLed_Track2.BackColor = m_FYAppVar.TrackNotInitializedColor;
            LLed_Track3.BackColor = m_FYAppVar.TrackNotInitializedColor;
            LLed_Track4.BackColor = m_FYAppVar.TrackNotInitializedColor;
            LLed_Track5.BackColor = m_FYAppVar.TrackNotInitializedColor;
            LLed_Track5.BackColor = m_FYAppVar.TrackNotInitializedColor;
            LLed_Track6.BackColor = m_FYAppVar.TrackNotInitializedColor;
            LLed_Track7.BackColor = m_FYAppVar.TrackNotInitializedColor;
            LLed_Track8.BackColor = m_FYAppVar.TrackNotInitializedColor;
            LLed_Track9.BackColor = m_FYAppVar.TrackNotInitializedColor;
            LLed_Track10.BackColor = m_FYAppVar.TrackNotInitializedColor;
            LLed_Track11.BackColor = m_FYAppVar.TrackNotInitializedColor;

            LLed_F10.BackColor = m_FYAppVar.TrackNotInitializedColor; ;
            LLed_F10.ForeColor = Color.Black;
            LLed_F11.BackColor = m_FYAppVar.TrackNotInitializedColor; ;
            LLed_F11.ForeColor = Color.Black;
            LLed_F12.BackColor = m_FYAppVar.TrackNotInitializedColor; ;
            LLed_F12.ForeColor = Color.Black;
            LLed_F13.BackColor = m_FYAppVar.TrackNotInitializedColor; ;
            LLed_F13.ForeColor = Color.Black;

            PB_Tr1_Active.BackColor = LLed_Track1.BackColor;
            PB_Tr1_Inline.BackColor = LLed_Track1.BackColor;
            PB_Tr1_Train.BackColor = LLed_Track1.BackColor;
            PB_Tr2_Active.BackColor = LLed_Track2.BackColor;
            PB_Tr2_Inline.BackColor = LLed_Track2.BackColor;
            PB_Tr2_Train.BackColor = LLed_Track2.BackColor;
            PB_Tr3_Active.BackColor = LLed_Track3.BackColor;
            PB_Tr3_Inline.BackColor = LLed_Track3.BackColor;
            PB_Tr3_Train.BackColor = LLed_Track3.BackColor;
            PB_Tr4_Active.BackColor = LLed_Track4.BackColor;
            PB_Tr4_Inline.BackColor = LLed_Track4.BackColor;
            PB_Tr4_Train.BackColor = LLed_Track4.BackColor;
            PB_Tr5_Active.BackColor = LLed_Track5.BackColor;
            PB_Tr5_Inline.BackColor = LLed_Track5.BackColor;
            PB_Tr5_Train.BackColor = LLed_Track5.BackColor;
            PB_Tr6_Active.BackColor = LLed_Track6.BackColor;
            PB_Tr6_Inline.BackColor = LLed_Track6.BackColor;
            PB_Tr6_Train.BackColor = LLed_Track6.BackColor;
            PB_Tr7_Active.BackColor = LLed_Track7.BackColor;
            PB_Tr7_Inline.BackColor = LLed_Track7.BackColor;
            PB_Tr7_Train.BackColor = LLed_Track7.BackColor;
            PB_Tr8_Active.BackColor = LLed_Track8.BackColor;
            PB_Tr8_Inline.BackColor = LLed_Track8.BackColor;
            PB_Tr8_Train.BackColor = LLed_Track8.BackColor;
            PB_Tr9_Active.BackColor = LLed_Track9.BackColor;
            PB_Tr9_Inline.BackColor = LLed_Track9.BackColor;
            PB_Tr9_Train.BackColor = LLed_Track9.BackColor;
            PB_Tr10_Active.BackColor = LLed_Track10.BackColor;
            PB_Tr10_Inline.BackColor = LLed_Track10.BackColor;
            PB_Tr10_Train.BackColor = LLed_Track10.BackColor;
            PB_Tr11_Active.BackColor = LLed_Track11.BackColor;
            PB_Tr11_Inline.BackColor = LLed_Track11.BackColor;
            PB_Tr11_Train.BackColor = LLed_Track11.BackColor;

            PB_Bk5_Train.Hide();
            PB_Bk6_Train.Hide();
            PB_Bk8A_Train.Hide();
            PB_Bk7_Train.Hide();

            PB_Bk7_Train.Image = null;
            PB_Bk8A_Train.Image = null;
        }
        /*#--------------------------------------------------------------------------#*/
        /*  Description: FiddleYardSimTrain constructor
         *
         *  Input(s)   :
         *
         *  Output(s)  :
         *
         *  Returns    :
         *
         *  Pre.Cond.  :
         *
         *  Post.Cond. :
         *
         *  Notes      :
         *
         */
        /*#--------------------------------------------------------------------------#*/
        public FiddleYardSimTrain(string instance, iFiddleYardSimulator iFYSim, FiddleYardIOHandleVariables FYIOHandleVar, FiddleYardSimulatorVariables FYSimVar)
        {
            m_FYSimVar = FYSimVar;
            m_iFYSim = iFYSim;
            m_FYIOHandleVar = FYIOHandleVar;
            m_instance = instance;

            Sensor Cmd_TargetAlive = new Sensor("TargetAlive", "TargetAlive", 0, (name, val, log) => SimulatorCmd(name, val, log)); // initialize and subscribe sensors
            m_FYSimVar.TargetAlive.Attach(Cmd_TargetAlive);
            Sensor TrackNo = new Sensor("Track_No", " Track Nr ", 0, (name, val, log) => SimulatorCmd(name, val, log)); // initialize and subscribe sensors
            m_FYIOHandleVar.TrackNo.Attach(TrackNo);

            if ("TOP" == m_instance)
            {
                path = @"c:\localdata\Siebwalde\" + DateTime.Now.Day + "-" + DateTime.Now.Month + "-" + DateTime.Now.Year + "_FiddleYardSimTrainTOP.txt"; //  different logging file per target, this is default
                FiddleYardSimTrainLogging = new Log2LoggingFile(path);
            }
            else if ("BOT" == m_instance)
            {
                path = @"c:\localdata\Siebwalde\" + DateTime.Now.Day + "-" + DateTime.Now.Month + "-" + DateTime.Now.Year + "_FiddleYardSimTrainBOT.txt"; //  different logging file per target, this is default
                FiddleYardSimTrainLogging = new Log2LoggingFile(path);
            }

            Sensor Sns_FYSimSpeedSetting = new Sensor("FYSimSpeedSetting", " FYSimSpeedSetting ", 0, (name, val, log) => SimulatorSettings(name, val, log)); // initialize and subscribe sensors
            Siebwalde_Application.Properties.Settings.Default.FYSimSpeedSetting.Attach(Sns_FYSimSpeedSetting);
        }
        //private const int TEMPOFFSET = 700;
        //public uint[] TrackForward = new uint[12] { 0, 0, 42800, 85600, 128400, 171200, 214000, 256800, 299600, 342400, 385200, 428000 };// New track coordinates forward movement 1 --> 11
        //public uint[] TrackBackwardOffset = new uint[12] { 0, TEMPOFFSET, TEMPOFFSET, TEMPOFFSET, TEMPOFFSET, TEMPOFFSET, TEMPOFFSET, TEMPOFFSET, TEMPOFFSET, TEMPOFFSET, TEMPOFFSET, 0 };   // New track coordinates forward movement 11 --> 1 offset number
        /*#--------------------------------------------------------------------------#*/
        /*  Description: FiddleYardApplication constructor
         *
         *  Input(s)   : instance == TOP || BOTTOM, FYIOHancleVar (FY IO handle variables class)
                         and interface to FY IO Handler
         *
         *  Output(s)  :
         *
         *  Returns    :
         *
         *  Pre.Cond.  :
         *
         *  Post.Cond. :
         *
         *  Notes      :
         *
         */
        /*#--------------------------------------------------------------------------#*/
        public FiddleYardMip50(string instance, FiddleYardIOHandleVariables FYIOHandleVar, iFiddleYardIOHandle iFYIOH, FiddleYardApplicationVariables FYAppVar)
        {
            m_instance = instance;
            m_FYIOHandleVar = FYIOHandleVar;
            m_iFYIOH = iFYIOH;
            m_FYAppVar = FYAppVar;

            if ("TOP" == m_instance)
            {
                path = @"c:\localdata\Siebwalde\" + DateTime.Now.Day + "-" + DateTime.Now.Month + "-" + DateTime.Now.Year + "_FiddleYardMIP50TOP.txt"; //  different logging file per target, this is default
                FiddleYardMIP50Logging = new Log2LoggingFile(path);
            }
            else if ("BOT" == m_instance)
            {
                path = @"c:\localdata\Siebwalde\" + DateTime.Now.Day + "-" + DateTime.Now.Month + "-" + DateTime.Now.Year + "_FiddleYardMIP50BOT.txt"; //  different logging file per target, this is default
                FiddleYardMIP50Logging = new Log2LoggingFile(path);
            }
        }