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]]"); } }
private bool openComPort(RunTimeError runTimeError, string comPortName) { ruSerialPort = new RuSerialPort(); return(ruSerialPort.openComport(comPortName, runTimeError)); }