// using the reflection get the command function and to run
 public void callTCACommand(TelnetAppSession AppSession, StringRequestInfo stringRequestInfo)
 {
     if (stringRequestInfo.Key == "help")
     {
         help(AppSession, stringRequestInfo);
         return;
     }
     if (!tCAIsOpen)
     {
         AppSession.Send("TCA is not running, start TCA...");
         startTCAProgramm(AppSession, stringRequestInfo);
         if (tCAIsOpen)
         {
             AppSession.Send("TCA start finished");
         }
         else
         {
             AppSession.Send("TCA start error");
         }
     }
     if (tcaCommandMethod.ContainsKey(stringRequestInfo.Key))
     {
         object[] parameters = new object[] { AppSession, stringRequestInfo };
         tcaCommandMethod[stringRequestInfo.Key].Invoke(this, parameters);
     }
     else
     {
         AppSession.sendNoNewLine("can not find this command");
     }
 }
Exemplo n.º 2
0
 private void connectedRequestPrintHelp(TelnetAppSession AppSession, StringRequestInfo stringRequestInfo)
 {
     foreach (var item in connectedRequestHandleAction)
     {
         AppSession.Send(item.Key);
     }
     AppSession.sendPropmt();
 }
 public void help(TelnetAppSession AppSession, StringRequestInfo stringRequestInfo)
 {
     foreach (var item in tcaCommandMethod)
     {
         AppSession.Send(item.Key);
     }
     AppSession.sendNoNewLine(">");
 }
Exemplo n.º 4
0
 internal void Run(TelnetAppSession AppSession, StringRequestInfo stringRequestInfo)
 {
     if (runAction != null)
     {
         runAction(AppSession, stringRequestInfo);
     }
     else
     {
         AppSession.Send("Session internal error!");
     }
 }
Exemplo n.º 5
0
 public void runAction(TelnetAppSession AppSession, StringRequestInfo stringRequestInfo)
 {
     if (stringRequestInfo.Key.Length == 0)
     {
         AppSession.sendPropmt();
     }
     else if (connectedRequestHandleAction.ContainsKey(stringRequestInfo.Key))
     {
         connectedRequestHandleAction[stringRequestInfo.Key](AppSession, stringRequestInfo);
     }
     else
     {
         AppSession.Send(@"Unkonw Command, Please use [" + "help" + "] list the vaild command");
         AppSession.sendPropmt();
     }
 }
        public void CpcFileGetCurrent(TelnetAppSession AppSession, StringRequestInfo stringRequestInfo)
        {
            if (getParameterNumber(stringRequestInfo) != 1)
            {
                sendParameterError(AppSession);
                return;
            }
            RunTimeError error = new RunTimeError();

            string[] paramMeter = stringRequestInfo.Parameters;
            string   data       = tCAControl.CpcFileGetCurrent(error, paramMeter[0]);

            if (error.IsError)
            {
                AppSession.sendWithAppendPropmt(error.Errordescription);
                return;
            }
            AppSession.Send(data);
        }
Exemplo n.º 7
0
        private void tryEnterRuCommandsMode(TelnetAppSession AppSession, StringRequestInfo stringRequestInfo)
        {
            if (!connectedfSMData.ruSerialPort.isOpen)
            {
                RunTimeError runTimeError = new RunTimeError();
                if ((stringRequestInfo.GetFirstParam().Length == 0 && connectedfSMData.comPortName == null) ||
                    !SerialPort.GetPortNames().ToList().Contains(connectedfSMData.comPortName))
                {
                    printHelp();
                    return;
                }
                else if (stringRequestInfo.GetFirstParam().Length > 0 && !connectedfSMData.ruSerialPort.openComport(stringRequestInfo.GetFirstParam(), runTimeError))
                {
                    AppSession.sendWithAppendPropmt(string.Format("open serial port:{0} fail: " + runTimeError.Errordescription, stringRequestInfo.GetFirstParam()));
                    return;
                }
                else if (stringRequestInfo.GetFirstParam().Length == 0 && SerialPort.GetPortNames().ToList().Contains(connectedfSMData.comPortName))
                {
                    if (!connectedfSMData.ruSerialPort.openComport(connectedfSMData.comPortName, runTimeError))
                    {
                        AppSession.sendWithAppendPropmt(string.Format("open serial port:{0} fail: " + runTimeError.Errordescription, connectedfSMData.comPortName));
                        return;
                    }
                }
                else if (stringRequestInfo.GetFirstParam().Equals("Portlist"))
                {
                    foreach (var item in RuSerialPort.getSerialPortList())
                    {
                        AppSession.Send(item);
                    }
                    AppSession.sendPropmt();
                    return;
                }
                this.connectedfSMData.elevator.Fire(Events.RuCommand);
            }
            this.connectedfSMData.elevator.Fire(Events.RuCommand);

            void printHelp()
            {
                AppSession.sendWithAppendPropmt("RuCommand [ Portlist | serial name[COM3]]");
            }
        }
        public void getHwSn(TelnetAppSession AppSession, StringRequestInfo stringRequestInfo)
        {
            if (getParameterNumber(stringRequestInfo) != 0)
            {
                sendParameterError(AppSession);
                return;
            }
            RunTimeError error = new RunTimeError();

            string[] hwSn = tCAControl.getHwSn(error);
            if (error.IsError)
            {
                AppSession.sendWithAppendPropmt(error.Errordescription);
                return;
            }
            foreach (var item in hwSn)
            {
                AppSession.Send(item);
            }
        }
        public void IQFilesGetList(TelnetAppSession AppSession, StringRequestInfo stringRequestInfo)
        {
            if (getParameterNumber(stringRequestInfo) != 1)
            {
                sendParameterError(AppSession);
                return;
            }
            RunTimeError error = new RunTimeError();

            string[] paramMeter = stringRequestInfo.Parameters;
            string[] data       = tCAControl.IQFilesGetList(error, paramMeter[0]);
            if (error.IsError)
            {
                AppSession.sendWithAppendPropmt(error.Errordescription);
                return;
            }
            foreach (var item in data)
            {
                AppSession.Send(item);
            }
        }
Exemplo n.º 10
0
 private void startTCAProgramm(TelnetAppSession AppSession, StringRequestInfo stringRequestInfo)
 {
     if (!tCAIsOpen)
     {
         RunTimeError runTimeError = new RunTimeError();
         if (tslPath.Length == 0)
         {
             AppSession.sendNoNewLine("please set the Lab PC TCA(TSL.exe) path");
             return;
         }
         if (!TCAControler.startTCA(runTimeError, "localhost", tslPath))
         {
             AppSession.sendWithAppendPropmt("open TCA fail:" + runTimeError.Errordescription);
             tCAIsOpen = false;
             return;
         }
         tCAIsOpen = true;
     }
     else
     {
         AppSession.Send("TCA instance is started, not need start again!");
     }
 }
Exemplo n.º 11
0
 public void runAction(TelnetAppSession AppSession, StringRequestInfo stringRequestInfo)
 {
     if (stringRequestInfo.Key.Length != 0)
     {
         if (stringRequestInfo.Key == "ExitIcolishMode")
         {
             exitIcolishMode(AppSession, stringRequestInfo);
         }
         if (!_isEnterMode)
         {
             if (stringRequestInfo.Key == "OpenVirtualChannel")
             {
                 RunTimeError runTimeError = new RunTimeError();
                 string       cpriPort     = stringRequestInfo.GetFirstParam();
                 string       comPortName  = "";
                 int          objectID     = 0;
                 if (!ComportDic.ContainsKey(cpriPort))
                 {
                     if (!openVirtualChannel(AppSession, stringRequestInfo, out objectID))
                     {
                         return;
                     }
                 }
                 ComportDic[cpriPort].Second = objectID;
                 comPortName = (string)ComportDic[cpriPort].First;
                 if (isOpen)
                 {
                     ruSerialPort.stopForwardRecviThread();
                     ruSerialPort.close();
                     isOpen = false;
                 }
                 if (openComPort(runTimeError, comPortName))
                 {
                     isOpen = true;
                     ruSerialPort.startForwardRecviThread(AppSession);
                     _isEnterMode = true;
                 }
                 else
                 {
                     AppSession.Send(runTimeError.Errordescription + "\n&");
                 }
             }
             else
             {
                 AppSession.Send("please OpenVirtualChannel: OpenVirtualChannel [CpriPort] \r\n\t like:  OpenVirtualChannel 1A \n&");
             }
         }
         else
         {
             string cmd = "";
             if (stringRequestInfo.GetFirstParam().Length > 0)
             {
                 cmd = stringRequestInfo.Key + " " + stringRequestInfo.Body;
             }
             else
             {
                 cmd = stringRequestInfo.Key;
             }
             ruSerialPort.send(cmd);
         }
     }
     else
     {
         AppSession.sendNoNewLine("&");
     }
 }
Exemplo n.º 12
0
        public static bool CreateComport(TelnetAppSession AppSession, StringRequestInfo stringRequestInfo, out int PortObjectID)
        {
            RunTimeError error = new RunTimeError();

            if (!tCAIsOpen)
            {
                if (TCAControler.startTCA(error, "localhost", tslPath))
                {
                    tCAIsOpen = true;
                }
                else
                {
                    AppSession.Send("startTCA error" + "\n&");
                    PortObjectID = 0;
                    return(false);
                }
            }

            if (getParameterNumber(stringRequestInfo) != 1)
            {
                sendParameterError(AppSession);
                PortObjectID = 0;
                return(false);
            }
            string comPortName      = "";
            var    vaildcomportList = TCAControler.getTCATPFComports(error);

            if (vaildcomportList.Length == 0)
            {
                AppSession.Send("Can not find vaild TCA serial port!" + "\n&");
                PortObjectID = 0;
                return(false);
            }
            foreach (var item in vaildcomportList)
            {
                SerialPort serialPort = new SerialPort(item);
                try
                {
                    serialPort.Open();
                }
                catch (System.Exception ex)
                {
                    serialPort.Close();
                    continue;
                }
                if (serialPort.IsOpen)
                {
                    serialPort.Close();
                    comPortName  = item;
                    PortObjectID = TCAControler.CreateComport(error, getParameter(stringRequestInfo, 0), comPortName);
                    if (!error.IsError)
                    {
                        ComportCreated?.Invoke(null, new Tuple <string, string>(getParameter(stringRequestInfo, 0), comPortName));
                        return(true);
                    }
                    error.Errordescription = "";
                }
            }
            AppSession.Send("Create the TCA virtual serial port faild:" + error.Errordescription + "\n&");
            PortObjectID = 0;
            return(false);
        }