Esempio n. 1
0
 //Add data to overspeed counter
 private void AddDataToOverspeedCount(double Time)
 {
     try
     {
         double speedLimit = TrainMethods.GetSpeedLimit();
         double speedData  = Math.Abs(TrainMethods.GetSpeed());
         //
         if (speedData > speedLimit)
         {
             if (isInOverspeedProcess)
             {
                 overspeedLastingTime += TimerUpdate.Interval / 1000;
             }
             else
             {
                 isInOverspeedProcess = true;
                 overspeedCount++;
                 overspeedLastingTime = 0;
             }
         }
         else
         {
             if (isInOverspeedProcess)
             {
                 chartSpeed.Series[2].Points.AddXY(Time - overspeedLastingTime, overspeedLastingTime);
                 //
                 chartSpeed.ChartAreas["ChartOverspeedArea"].AxisX.ScaleView.Position =
                     xData - chartSpeed.ChartAreas["ChartOverspeedArea"].AxisX.ScaleView.Size;
                 isInOverspeedProcess = false;
             }
         }
     }catch (Exception ex) { };
 }
Esempio n. 2
0
        //
        /// <summary>
        /// get train data by dataID
        /// </summary>
        static public string GetData(int dataID)
        {
            //SPEED, POWER, BRAKE, REVERSER, SIGNAL, SIGNAL_DISTANCE, SPEED_LIMIT
            switch (dataID)
            {
            case SPEED:
                return(TrainMethods.GetSpeed().ToString());

            case POWER:
                return(TrainMethods.GetPower().ToString());

            case BRAKE:
                return(TrainMethods.GetBrake().ToString());

            case REVERSER:
                return(TrainMethods.GetReverser().ToString());

            case SIGNAL:
                return(TrainMethods.GetSignal().ToString());

            case SIGNAL_DISTANCE:
                return(TrainMethods.GetSignalDis().ToString());

            case SPEED_LIMIT:
                return(TrainMethods.GetSpeedLimit().ToString());

            case RC_MODE:
                return(TrainMethods.GetConstSpeed() == 0 ? NORMAL.ToString() : OVERWRITE.ToString());
            }
            return(trainData[dataID].ToString());
        }
Esempio n. 3
0
        private void tmrUpdate_Tick(object sender, EventArgs e)
        {
            try
            {
                //invoke the TrainManager to throw a error
                TrainManager.Train trainInfo = TrainManager.PlayerTrain;
                txtBoxReserver.Text    = "REV : " + TrainMethods.GetReverser().ToString();
                txtBoxSignal.Text      = "SIG : " + TrainMethods.GetSignal().ToString();
                txtBoxSignalDis.Text   = "SIG_DIS : " + TrainMethods.GetSignalDis().ToString();
                txtBoxSpeed.Text       = "SPD : " + TrainMethods.GetSpeed().ToString();
                txtBoxSpdLimit.Text    = "SPD_LIM : " + TrainMethods.GetSpeedLimit().ToString();
                txtBoxBrakeHandle.Text = "BKE : " + TrainMethods.GetBrake().ToString();
                txtBoxPowerHandle.Text = "PWR : " + trainInfo.Handles.Power.Driver.ToString();
                txtBoxConstSpeed.Text  = "CON_SPD : " + TrainMethods.GetConstSpeed().ToString();
                //
                btnBack.Enabled      = true;
                btnDown.Enabled      = true;
                btnFor.Enabled       = true;
                btnHornSt.Enabled    = true;
                btnNeu.Enabled       = true;
                btnUp.Enabled        = true;
                btnAPOFF.Enabled     = true;
                btnAPON.Enabled      = true;
                btnEmeOn.Enabled     = true;
                btnEmeOff.Enabled    = true;
                btnKeyLock.Enabled   = true;
                btnKeyUnlock.Enabled = true;
            }
            catch (Exception ex)
            {
                //continue
                btnBack.Enabled      = false;
                btnDown.Enabled      = false;
                btnFor.Enabled       = false;
                btnHornSt.Enabled    = false;
                btnNeu.Enabled       = false;
                btnUp.Enabled        = false;
                btnAPOFF.Enabled     = false;
                btnAPON.Enabled      = false;
                btnEmeOn.Enabled     = false;
                btnEmeOff.Enabled    = false;
                btnKeyLock.Enabled   = false;
                btnKeyUnlock.Enabled = false;
            }

            if (SerialPort.GetPortNames().Length > cmbSerials.Items.Count)
            {
                cmbSerials.Items.Clear();
                cmbSerials.Items.AddRange(SerialPort.GetPortNames());
                cmbSerials.SelectedIndex = this.cmbSerials.Items.Count - 1;
            }

            if (SerialPort.GetPortNames().Length == 0)
            {
                btnRead.Enabled     = false;
                btnStopRead.Enabled = false;
                cmbSerials.Items.Clear();
            }
        }
Esempio n. 4
0
 private void formCM_Load(object sender, EventArgs e)
 {
     this.Top  = 50;
     this.Left = 1;
     this.cmbSerials.Items.AddRange(SerialPort.GetPortNames());
     this.cmbSerials.SelectedIndex = this.cmbSerials.Items.Count - 1;
     formMonitorPosition.X         = this.Location.X;
     formMonitorPosition.Y         = this.Location.Y + 594;
     TrainMethods.AttachMainTimerInterrupt(500);
     isConnected = false;
 }
Esempio n. 5
0
 //Add data to speed
 private void AddDataToSpeedChart(double Time)
 {
     try
     {
         double speedData = Math.Abs(TrainMethods.GetSpeed());
         chartSpeed.Series[0].Points.AddXY(Time, speedData);
         //
         chartSpeed.ChartAreas["ChartSpeedArea"].AxisX.ScaleView.Position = xData - chartSpeed.ChartAreas["ChartSpeedArea"].AxisX.ScaleView.Size;
     }
     catch (Exception ex) { };
 }
 private void OnLoadEvents()
 {
     TrainMethods.EventsRegister();
     DataManagerClient.EventsRegister();
     RAGLINKCommons.RPlatform.ProjectLoader.TrainDataLoaderEvent      += LoadTrain;
     RAGLINKCommons.RPlatform.ProjectLoader.RouteDataLoaderEvent      += LoadRoute;
     RAGLINKCommons.RPlatform.ProjectLoader.GraphicOptionsLoaderEvent += ApplyGraphicOptions;
     RAGLINKCommons.RPlatform.ProjectLoader.StartSimulatorEvent       += StartSimulator;
     UpdatePlanFileList();
     labelVersion.Text = "API 版本:" + RAGLINKCommons.RPlatform.SettingsContent.simulatorVersion.ToString();
     RAGLINKCommons.RPlatform.PackagesManager.UpdatePackageList();
     RAGLINKCommons.RPlatform.ControlObjects.ResetControlObjects();
     RAGLINKCommons.RPlatform.ControlObjects.UpdateControlObjectsItem();
 }
Esempio n. 7
0
 private void btnRestartGame_Click(object sender, EventArgs e)
 {
     try
     {
         if (MessageBox.Show("Would you want to restart the simulator?", "RAGLINK+ CabViewer",
                             MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
         {
             if (!TrainMethods.RestartGame())
             {
                 MessageBox.Show("Unable to restart simulator.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
             }
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show("Unable to restart simulator.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }
Esempio n. 8
0
        //
        /// <summary>
        /// send operation data to train
        /// </summary>
        static private void SendControlToTrain(int dataID,int value)
        {
            switch (dataID)
            {
            case REVERSER:
                TrainMethods.SetReverser(value);
                break;

            case POWER:
                TrainMethods.SetPower(value);
                break;

            case BRAKE:
                TrainMethods.SetBrake(value);
                break;

            case HORN:
                TrainMethods.SetHorn(value);
                break;

            case MASTER_KEY:
                TrainMethods.SetMasterKey(value);
                break;

            case EMERGENCY:
                TrainMethods.SetEmergency(value);
                break;

            case SPEED_CONST:
            {
                if (value == 0)
                {
                    trainData[RC_MODE] = NORMAL;
                }
                else
                {
                    trainData[RC_MODE] = OVERWRITE;
                }
                TrainMethods.SetAutoPilot(value);
                break;
            }
            }
        }
Esempio n. 9
0
 private void frmMain_FormClosing(object sender, FormClosingEventArgs e)
 {
     try
     {
         if (MessageBox.Show("Would you want to restart the simulator?", "RAGLINK+ CabViewer",
                             MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
         {
             this.DisposeSerialPort();
             if (!TrainMethods.RestartGame())
             {
                 MessageBox.Show("Unable to restart simulator.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
             }
         }
         e.Cancel = true;
     }
     catch (Exception ex)
     {
         MessageBox.Show("Unable to restart simulator.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }
Esempio n. 10
0
 //Add data to overspeed rate
 private void AddDataToOverspeedRate(double Time)
 {
     try
     {
         double speedLimit = TrainMethods.GetSpeedLimit();
         double speedData  = Math.Abs(TrainMethods.GetSpeed());
         double rate       = 0;
         //
         if (speedData <= speedLimit)
         {
             rate = 0;
         }
         else
         {
             rate = (speedData - speedLimit) / speedLimit * 100;
         }
         //
         chartSpeed.Series[3].Points.AddXY(Time, rate);
         //
         chartSpeed.ChartAreas["ChartOverspeedRate"].AxisX.ScaleView.Position =
             xData - chartSpeed.ChartAreas["ChartOverspeedRate"].AxisX.ScaleView.Size;
     }catch (Exception ex) { };
 }
Esempio n. 11
0
 private void btnLeftDoorOpen_Click(object sender, EventArgs e)
 {
     TrainMethods.LeftDoorOpen();
 }
Esempio n. 12
0
        //
        /// <summary>
        /// send operation data to train
        /// </summary>
        static private void SendControlToTrain(int dataID, int value)
        {
            switch (dataID)
            {
            case REVERSER:
                TrainMethods.SetReverser(value);
                break;

            case POWER:
                TrainMethods.SetPower(value);
                break;

            case BRAKE:
                TrainMethods.SetBrake(value);
                break;

            case HORN:
                TrainMethods.SetHorn(value);
                break;

            case MASTER_KEY:
                TrainMethods.SetMasterKey(value);
                break;

            case EMERGENCY:
                //TrainMethods.SetEmergency(value);
                break;

            case SPEED_CONST:
            {
                /*if (value == 0) trainData[RC_MODE] = NORMAL;
                 * else trainData[RC_MODE] = OVERWRITE;
                 * if (value == TrainMethods.GetSetConstSpeed()) break;
                 * //test code
                 * while (TrainMethods.inSettingAP);
                 * //
                 * TrainMethods.SetAutoPilot(value);*/
                break;
            }

            case LDOOR_OPEN:
            {
                if (value != TrainMethods.GetLeftDoorState())
                {
                    if (value == 1)
                    {
                        TrainMethods.LeftDoorOpen();
                    }
                    else
                    {
                        TrainMethods.LeftDoorClose();
                    }
                }
                break;
            }

            case RDOOR_OPEN:
            {
                if (value != TrainMethods.GetRightDoorState())
                {
                    if (value == 1)
                    {
                        TrainMethods.RightDoorOpen();
                    }
                    else
                    {
                        TrainMethods.RightDoorClose();
                    }
                }
                break;
            }
            }
        }
Esempio n. 13
0
 private void btnAPON_Click(object sender, EventArgs e)
 {
     TrainMethods.SetAutoPilot(TrainMethods.GetSpeed());
 }
Esempio n. 14
0
 private void btnAPOFF_Click(object sender, EventArgs e)
 {
     TrainMethods.SetAutoPilot(0);
 }
Esempio n. 15
0
 private void btnEmeOff_Click(object sender, EventArgs e)
 {
     TrainMethods.SetEmergency(0);
 }
Esempio n. 16
0
 private void btnKeyLock_Click(object sender, EventArgs e)
 {
     TrainMethods.SetMasterKey(0);
 }
Esempio n. 17
0
 private void btnHornSt_MouseDown(object sender, MouseEventArgs e)
 {
     TrainMethods.HornStart();
 }
Esempio n. 18
0
 private void btnHornSt_MouseUp(object sender, MouseEventArgs e)
 {
     TrainMethods.HornStop();
 }
Esempio n. 19
0
 private void btnRightDoorClose_Click(object sender, EventArgs e)
 {
     TrainMethods.RightDoorClose();
 }
Esempio n. 20
0
 private void btnHornEd_Click(object sender, EventArgs e)
 {
     TrainMethods.HornStop();
 }
Esempio n. 21
0
 private void btnFor_Click(object sender, EventArgs e)
 {
     TrainMethods.ReverserForward();
 }
Esempio n. 22
0
 private void btnBack_Click(object sender, EventArgs e)
 {
     TrainMethods.ReverserBackward();
 }
Esempio n. 23
0
 private void btnNeu_Click(object sender, EventArgs e)
 {
     TrainMethods.ReverserNeutral();
 }
Esempio n. 24
0
 private void btnUp_Click(object sender, EventArgs e)
 {
     TrainMethods.PowerUp();
 }
Esempio n. 25
0
 private void btnAPOFF_Click(object sender, EventArgs e)
 {
     TrainMethods.SetATCState(false);
 }
Esempio n. 26
0
 private void btnDown_Click(object sender, EventArgs e)
 {
     TrainMethods.PowerDown();
 }
Esempio n. 27
0
 private void formCM_Load(object sender, EventArgs e)
 {
     this.cmbSerials.Items.AddRange(SerialPort.GetPortNames());
     this.cmbSerials.SelectedIndex = this.cmbSerials.Items.Count - 1;
     TrainMethods.AttachMainTimerInterrupt(500);
 }
Esempio n. 28
0
        //
        /// <summary>
        /// get train data by dataID
        /// </summary>
        static public string GetData(int dataID, int Invoker)
        {
            //SPEED, POWER, BRAKE, REVERSER, SIGNAL, SIGNAL_DISTANCE, SPEED_LIMIT
            switch (dataID)
            {
            case SPEED:
                return(TrainMethods.GetSpeed().ToString());

            case SPEED_HMI:
                return(((int)(TrainMethods.GetSpeedDouble() * 10)).ToString());

            case POWER:
                return(TrainMethods.GetPower().ToString());

            case BRAKE:
                return(TrainMethods.GetBrake().ToString());

            case REVERSER:
                return(TrainMethods.GetReverser().ToString());

            case SIGNAL_INFO:
                return(TrainMethods.GetSignal().ToString());

            case SIGNAL_DISTANCE:
                return(TrainMethods.GetSignalDis().ToString());

            case SPEED_LIMIT:
                return(TrainMethods.GetSpeedLimit().ToString());

            case RC_MODE:
                return(TrainMethods.GetATCState() == false?NORMAL.ToString() : OVERWRITE.ToString());

            case LDOOR_OPEN:
                return(TrainMethods.GetLeftDoorState() != -1 ? TrainMethods.GetLeftDoorState().ToString() : "0");

            case RDOOR_OPEN:
                return(TrainMethods.GetRightDoorState() != -1 ? TrainMethods.GetRightDoorState().ToString() : "0");

            case LDDOR_IN_OP:
                return(trainData[LDOOR_OPEN].ToString());

            case RDOOR_IN_OP:
                return(trainData[RDOOR_OPEN].ToString());

            case CURRENT_STATION_NAME:
            {
                if (Invoker == 0)
                {
                    return(" ");
                }
                return(TrainMethods.GetCurrentStationName());
            }

            case CURRENT_STATION_DEPART:
            {
                if (Invoker == 0)
                {
                    return(" ");
                }
                return(TrainMethods.GetCurrentStationDepartureTime());
            }

            case NEXT_STATION_NAME:
            {
                if (Invoker == 0)
                {
                    return(" ");
                }
                return(TrainMethods.GetNextStationName());
            }

            case NEXT_STATION_ARRIVAL:
            {
                if (Invoker == 0)
                {
                    return(" ");
                }
                return(TrainMethods.GetNextStationArrialTime());
            }

            case NEXT_STATION_DIS:
            {
                if (Invoker == 0)
                {
                    return(" ");
                }
                return((TrainMethods.GetNextStationDis() >= 1000 ?
                        decimal.Round(decimal.Parse((TrainMethods.GetNextStationDis() / 1000).ToString()), 2) :
                        decimal.Round(decimal.Parse((TrainMethods.GetNextStationDis()).ToString()), 1)) +
                       (TrainMethods.GetNextStationDis() >= 1000 ? " KM":" M") +
                       " / " +
                       (TrainMethods.GetNextStationStopMode() == 1 ? "VIA" : "STOP"));
            }

            case CURRENT_TIME:
            {
                if (Invoker == 0)
                {
                    return(" ");
                }
                return(TrainMethods.GetCurrentTime());
            }

            case CYLINER_PRESSURE:
                return(((int)(TrainMethods.GetCylinderPressure() * 10)).ToString());

            case PIPE_PRESSURE:
                return(((int)(TrainMethods.GetPipePressure() * 10)).ToString());

            case DEST_STATION_NAME:
                return(TrainMethods.GetDestinationName());

            case STATION_COUNTER:
                return(TrainMethods.GetNextStationIndex().ToString() + " / " + TrainMethods.GetStationCount().ToString());
            }
            return(dataType[dataID] != _STRING ? trainData[dataID].ToString() : trainDataStr[dataID]);
        }
Esempio n. 29
0
        private void tmrUpdate_Tick(object sender, EventArgs e)
        {
            try
            {
                //invoke the TrainManager to throw a error
                txtBoxReserver.Text       = "REV : " + TrainMethods.GetReverser().ToString();
                txtBoxSignal.Text         = "SIG : " + TrainMethods.GetSignal().ToString();
                txtBoxSignalDis.Text      = "SIG_DIS : " + TrainMethods.GetSignalDis().ToString();
                txtBoxSpeed.Text          = "SPD : " + ((double)((int)(TrainMethods.GetSpeedDouble() * 10)) / 10.0).ToString();
                txtBoxSpdLimit.Text       = "SPD_LIM : " + TrainMethods.GetSpeedLimit().ToString();
                txtBoxBrakeHandle.Text    = "BKE : " + TrainMethods.GetBrake().ToString();
                txtBoxPowerHandle.Text    = "PWR : " + TrainMethods.GetPower().ToString();
                txtBoxConstSpeed.Text     = "ATC_SPD : " + ((double)((int)(TrainMethods.GetATCCurrentSpeed() * 10)) / 10.0).ToString();
                txtBoxCurrentStation.Text = "CUR_STA : " + TrainMethods.GetCurrentStationName();
                txtBoxNextStation.Text    = "NEX_STA : " + TrainMethods.GetNextStationName();
                txtBoxNextStationDis.Text = "NEX_STADIS : " +
                                            (TrainMethods.GetNextStationDis() >= 1000 ?
                                             decimal.Round(decimal.Parse((TrainMethods.GetNextStationDis() / 1000).ToString()), 2) :
                                             decimal.Round(decimal.Parse((TrainMethods.GetNextStationDis()).ToString()), 1)) +
                                            " / " + (TrainMethods.GetNextStationStopMode() == 1 ? "VIA" : "STOP");
                txtBoxArrivalTime.Text    = "AT : " + TrainMethods.GetNextStationArrialTime();
                txtBoxDepartureTime.Text  = "DT : " + TrainMethods.GetCurrentStationDepartureTime();
                txtBoxCurrentTime.Text    = "TIME : " + TrainMethods.GetCurrentTime();
                txtBoxRouteName.Text      = "ROUTE_NAME : " + TrainMethods.GetCurrentRouteName();
                txBoxTrainName.Text       = "TRAIN : " + TrainMethods.GetCurrentTrainName();
                txtBoxCylinder.Text       = "CYL : " + TrainMethods.GetCylinderPressure().ToString();
                txtBoxPipe.Text           = "PIP : " + TrainMethods.GetPipePressure().ToString();
                txtBoxDestination.Text    = "DEST_STA : " + TrainMethods.GetDestinationName();
                txtBoxStationCounter.Text = "STATION : " + TrainMethods.GetNextStationIndex().ToString() + " / " + TrainMethods.GetStationCount().ToString();
                //
                btnBack.Enabled           = true;
                btnDown.Enabled           = true;
                btnFor.Enabled            = true;
                btnHornSt.Enabled         = true;
                btnNeu.Enabled            = true;
                btnUp.Enabled             = true;
                btnAPOFF.Enabled          = true;
                btnAPON.Enabled           = true;
                btnEmeOn.Enabled          = true;
                btnEmeOff.Enabled         = true;
                btnKeyLock.Enabled        = true;
                btnKeyUnlock.Enabled      = true;
                btnRestartGame.Enabled    = true;
                btnLeftDoorClose.Enabled  = true;
                btnLeftDoorOpen.Enabled   = true;
                btnRightDoorClose.Enabled = true;
                btnRightDoorOpen.Enabled  = true;
                //
                if (toolStripLabel.Text == "Environment initializing...")
                {
                    toolStripLabel.Text = "Ready.";
                }
            }
            catch (Exception ex)
            {
                //continue
                btnBack.Enabled           = false;
                btnDown.Enabled           = false;
                btnFor.Enabled            = false;
                btnHornSt.Enabled         = false;
                btnNeu.Enabled            = false;
                btnUp.Enabled             = false;
                btnAPOFF.Enabled          = false;
                btnAPON.Enabled           = false;
                btnEmeOn.Enabled          = false;
                btnEmeOff.Enabled         = false;
                btnKeyLock.Enabled        = false;
                btnKeyUnlock.Enabled      = false;
                btnRestartGame.Enabled    = false;
                btnLeftDoorClose.Enabled  = false;
                btnLeftDoorOpen.Enabled   = false;
                btnRightDoorClose.Enabled = false;
                btnRightDoorOpen.Enabled  = false;
                //
                toolStripLabel.Text = "Environment initializing...";
            }

            if (SerialPort.GetPortNames().Length > cmbSerials.Items.Count)
            {
                cmbSerials.Items.Clear();
                cmbSerials.Items.AddRange(SerialPort.GetPortNames());
                cmbSerials.SelectedIndex = this.cmbSerials.Items.Count - 1;
                //
            }

            if (SerialPort.GetPortNames().Length == 0)
            {
                DisposeSerialPort();
                btnRead.Enabled     = false;
                btnStopRead.Enabled = false;
                cmbSerials.Items.Clear();
            }
            //
        }