Beispiel #1
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]);
        }
Beispiel #2
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();
            }
            //
        }