public void ApplyParam(SerialTerminalParam param, SerialTerminalSettings settings) { _terminalParam = param == null ? new SerialTerminalParam() : param; _terminalSettings = settings == null?SerialPortUtil.CreateDefaultSerialTerminalSettings(_terminalParam.Port) : settings; _portBox.SelectedIndex = _terminalParam.Port - 1; //COM1からなので //これらのSelectedIndexの設定はコンボボックスに設定した項目順に依存しているので注意深くすること _baudRateBox.SelectedIndex = _baudRateBox.FindStringExact(_terminalSettings.BaudRate.ToString()); _dataBitsBox.SelectedIndex = _terminalSettings.ByteSize == 7 ? 0 : 1; _parityBox.SelectedItem = _terminalSettings.Parity; // select EnumListItem<T> by T _stopBitsBox.SelectedItem = _terminalSettings.StopBits; // select EnumListItem<T> by T _flowControlBox.SelectedItem = _terminalSettings.FlowControl; // select EnumListItem<T> by T _encodingBox.SelectedItem = _terminalSettings.Encoding; // select EnumListItem<T> by T _newLineBox.SelectedItem = _terminalSettings.TransmitNL; // select EnumListItem<T> by T _localEchoBox.SelectedIndex = _terminalSettings.LocalEcho ? 1 : 0; _transmitDelayPerCharBox.Text = _terminalSettings.TransmitDelayPerChar.ToString(); _transmitDelayPerLineBox.Text = _terminalSettings.TransmitDelayPerLine.ToString(); IAutoExecMacroParameter autoExecParams = param.GetAdapter(typeof(IAutoExecMacroParameter)) as IAutoExecMacroParameter; if (autoExecParams != null && SerialPortPlugin.Instance.MacroEngine != null) { _autoExecMacroPathBox.Text = (autoExecParams.AutoExecMacroPath != null) ? autoExecParams.AutoExecMacroPath : String.Empty; } else { _autoExecMacroPathLabel.Enabled = false; _autoExecMacroPathBox.Enabled = false; _selectAutoExecMacroButton.Enabled = false; } }
public bool IsSupporting(ITerminalParameter param, ITerminalSettings settings) { SerialTerminalParam sp = param as SerialTerminalParam; SerialTerminalSettings ts = settings as SerialTerminalSettings; return(sp != null && ts != null); }
public object Clone() { SerialTerminalParam tp = new SerialTerminalParam(); tp._port = _port; tp._terminalType = _terminalType; return(tp); }
private bool ValidateParam() { SerialTerminalSettings settings = _terminalSettings; SerialTerminalParam param = _terminalParam; try { LogType logtype = (LogType)EnumDescAttribute.For(typeof(LogType)).FromDescription(_logTypeBox.Text, LogType.None); ISimpleLogSettings logsettings = null; if (logtype != LogType.None) { logsettings = CreateSimpleLogSettings(logtype, _logFileBox.Text); if (logsettings == null) { return(false); //動作キャンセル } } param.Port = _portBox.SelectedIndex + 1; string autoExecMacroPath = null; if (_autoExecMacroPathBox.Text.Length != 0) { autoExecMacroPath = _autoExecMacroPathBox.Text; } IAutoExecMacroParameter autoExecParams = param.GetAdapter(typeof(IAutoExecMacroParameter)) as IAutoExecMacroParameter; if (autoExecParams != null) { autoExecParams.AutoExecMacroPath = autoExecMacroPath; } settings.BeginUpdate(); if (logsettings != null) { settings.LogSettings.Reset(logsettings); } settings.Caption = String.Format("COM{0}", param.Port); settings.BaudRate = Int32.Parse(_baudRateBox.Text); settings.ByteSize = (byte)(_dataBitsBox.SelectedIndex == 0? 7 : 8); settings.StopBits = (StopBits)_stopBitsBox.SelectedIndex; settings.Parity = (Parity)_parityBox.SelectedIndex; settings.FlowControl = (FlowControl)_flowControlBox.SelectedIndex; settings.Encoding = (EncodingType)_encodingBox.SelectedIndex; settings.LocalEcho = _localEchoBox.SelectedIndex == 1; settings.TransmitNL = (NewLine)EnumDescAttribute.For(typeof(NewLine)).FromDescription(_newLineBox.Text, LogType.None); settings.TransmitDelayPerChar = Int32.Parse(_transmitDelayPerCharBox.Text); settings.TransmitDelayPerLine = Int32.Parse(_transmitDelayPerLineBox.Text); settings.EndUpdate(); return(true); } catch (Exception ex) { GUtil.Warning(this, ex.Message); return(false); } }
public object Deserialize(StructuredText node) { SerialTerminalParam tp = new SerialTerminalParam(); tp.Port = ParseUtil.ParseInt(node.Get("Port"), 1); tp.SetTerminalName(node.Get("TerminalType", "vt100")); tp.AutoExecMacroPath = node.Get("autoexec-macro", null); return(tp); }
public ITerminalConnection EstablishConnection(IPoderosaMainWindow window, ITerminalParameter param, ITerminalSettings settings) { SerialTerminalParam sp = param as SerialTerminalParam; SerialTerminalSettings ts = settings as SerialTerminalSettings; Debug.Assert(sp != null && ts != null); return(SerialPortUtil.CreateNewSerialConnection(window, sp, ts)); }
public SerialTerminalConnection(SerialTerminalParam p, SerialTerminalSettings settings, IntPtr fh) { _serialTerminalParam = p; _fileHandle = fh; _serialSocket = new SerialSocket(this, fh, settings); _serialTerminalOutput = new SerialTerminalOutput(fh); //_socket = _serialSocket; //_terminalOutput = _serialTerminalOutput; }
public static SerialTerminalConnection CreateNewSerialConnection(IPoderosaMainWindow window, SerialTerminalParam param, SerialTerminalSettings settings) { bool successful = false; FileStream strm = null; try { StringResource sr = SerialPortPlugin.Instance.Strings; //Debug.WriteLine("OPENING COM"+param.Port); string portstr = String.Format("\\\\.\\{0}", param.PortName); IntPtr ptr = Win32Serial.CreateFile(portstr, Win32.GENERIC_READ | Win32.GENERIC_WRITE, 0, IntPtr.Zero, Win32.OPEN_EXISTING, Win32.FILE_ATTRIBUTE_NORMAL | Win32.FILE_FLAG_OVERLAPPED, IntPtr.Zero); if (ptr == Win32.INVALID_HANDLE_VALUE) { string msg = sr.GetString("Message.FailedToOpenSerial"); int err = Marshal.GetLastWin32Error(); if (err == 2) msg += sr.GetString("Message.NoSuchDevice"); else if (err == 5) msg += sr.GetString("Message.DeviceIsBusy"); else msg += "\nGetLastError=" + Marshal.GetLastWin32Error(); throw new Exception(msg); } //strm = new FileStream(ptr, FileAccess.Write, true, 8, true); Win32Serial.DCB dcb = new Win32Serial.DCB(); FillDCB(ptr, ref dcb); UpdateDCB(ref dcb, settings); if (!Win32Serial.SetCommState(ptr, ref dcb)) { Win32.CloseHandle(ptr); throw new Exception(sr.GetString("Message.FailedToConfigSerial")); } Win32Serial.COMMTIMEOUTS timeouts = new Win32Serial.COMMTIMEOUTS(); Win32Serial.GetCommTimeouts(ptr, ref timeouts); timeouts.ReadIntervalTimeout = 0xFFFFFFFF; timeouts.ReadTotalTimeoutConstant = 0; timeouts.ReadTotalTimeoutMultiplier = 0; timeouts.WriteTotalTimeoutConstant = 100; timeouts.WriteTotalTimeoutMultiplier = 100; Win32Serial.SetCommTimeouts(ptr, ref timeouts); successful = true; SerialTerminalConnection r = new SerialTerminalConnection(param, settings, ptr); return r; } catch (Exception ex) { RuntimeUtil.SilentReportException(ex); if (window != null) window.Warning(ex.Message); else GUtil.Warning(Form.ActiveForm, ex.Message); //TODO 苦しい逃げ。IPoderosaFormを実装したベースクラスをCoreにでも持っていたほうがいいのか return null; } finally { if (!successful && strm != null) strm.Close(); } }
public object Deserialize(StructuredText node) { SerialTerminalParam tp = new SerialTerminalParam(); if (node.Get("Port") != null) { // accept old parameter. // "PortName" setting overwrites this setting. tp.PortName = "COM" + node.Get("Port"); } tp.PortName = node.Get("PortName", tp.PortName); tp.SetTerminalName(node.Get("TerminalType", "vt100")); tp.AutoExecMacroPath = node.Get("autoexec-macro", null); return(tp); }
public StructuredText Serialize(object obj) { SerialTerminalParam tp = obj as SerialTerminalParam; Debug.Assert(tp != null); StructuredText node = new StructuredText(this.ConcreteType.FullName); node.Set("Port", tp.Port.ToString()); if (tp.TerminalType != "vt100") { node.Set("TerminalType", tp.TerminalType); } if (tp.AutoExecMacroPath != null) { node.Set("autoexec-macro", tp.AutoExecMacroPath); } return(node); }
public override CommandResult InternalExecute(ICommandTarget target, params IAdaptable[] args) { IPoderosaMainWindow window = (IPoderosaMainWindow)target.GetAdapter(typeof(IPoderosaMainWindow)); SerialLoginDialog dlg = new SerialLoginDialog(); using (dlg) { SerialTerminalParam tp = new SerialTerminalParam(); SerialTerminalSettings ts = SerialPortUtil.CreateDefaultSerialTerminalSettings(tp.Port); dlg.ApplyParam(tp, ts); if (dlg.ShowDialog(window.AsForm()) == DialogResult.OK) //TODO 親ウィンドウ指定 { ITerminalConnection con = dlg.ResultConnection; if (con != null) { return(_instance.CommandManager.Execute(_instance.TerminalSessionsService.TerminalSessionStartCommand, window, con, dlg.ResultTerminalSettings)); } } } return(CommandResult.Cancelled); }
public override CommandResult InternalExecute(ICommandTarget target, params IAdaptable[] args) { IPoderosaMainWindow window = (IPoderosaMainWindow)target.GetAdapter(typeof(IPoderosaMainWindow)); SerialLoginDialog dlg = new SerialLoginDialog(); using (dlg) { SerialTerminalParam tp = new SerialTerminalParam(); SerialTerminalSettings ts = SerialPortUtil.CreateDefaultSerialTerminalSettings(tp.PortName); dlg.ApplyParam(tp, ts); if (dlg.ShowDialog(window.AsForm()) == DialogResult.OK) { //TODO 親ウィンドウ指定 ITerminalConnection con = dlg.ResultConnection; if (con != null) { return _instance.CommandManager.Execute(_instance.TerminalSessionsService.TerminalSessionStartCommand, window, con, dlg.ResultTerminalSettings); } } } return CommandResult.Cancelled; }
public bool UIEquals(ITerminalParameter param) { SerialTerminalParam tp = param as SerialTerminalParam; return(tp != null && _port == tp.Port); }
public static SerialTerminalConnection CreateNewSerialConnection(IPoderosaMainWindow window, SerialTerminalParam param, SerialTerminalSettings settings) { bool successful = false; FileStream strm = null; try { StringResource sr = SerialPortPlugin.Instance.Strings; //Debug.WriteLine("OPENING COM"+param.Port); string portstr = String.Format("\\\\.\\{0}", param.PortName); IntPtr ptr = Win32Serial.CreateFile(portstr, Win32.GENERIC_READ | Win32.GENERIC_WRITE, 0, IntPtr.Zero, Win32.OPEN_EXISTING, Win32.FILE_ATTRIBUTE_NORMAL | Win32.FILE_FLAG_OVERLAPPED, IntPtr.Zero); if (ptr == Win32.INVALID_HANDLE_VALUE) { string msg = sr.GetString("Message.FailedToOpenSerial"); int err = Marshal.GetLastWin32Error(); if (err == 2) { msg += sr.GetString("Message.NoSuchDevice"); } else if (err == 5) { msg += sr.GetString("Message.DeviceIsBusy"); } else { msg += "\nGetLastError=" + Marshal.GetLastWin32Error(); } throw new Exception(msg); } //strm = new FileStream(ptr, FileAccess.Write, true, 8, true); Win32Serial.DCB dcb = new Win32Serial.DCB(); FillDCB(ptr, ref dcb); UpdateDCB(ref dcb, settings); if (!Win32Serial.SetCommState(ptr, ref dcb)) { Win32.CloseHandle(ptr); throw new Exception(sr.GetString("Message.FailedToConfigSerial")); } Win32Serial.COMMTIMEOUTS timeouts = new Win32Serial.COMMTIMEOUTS(); Win32Serial.GetCommTimeouts(ptr, ref timeouts); timeouts.ReadIntervalTimeout = 0xFFFFFFFF; timeouts.ReadTotalTimeoutConstant = 0; timeouts.ReadTotalTimeoutMultiplier = 0; timeouts.WriteTotalTimeoutConstant = 100; timeouts.WriteTotalTimeoutMultiplier = 100; Win32Serial.SetCommTimeouts(ptr, ref timeouts); successful = true; SerialTerminalConnection r = new SerialTerminalConnection(param, settings, ptr); return(r); } catch (Exception ex) { RuntimeUtil.SilentReportException(ex); if (window != null) { window.Warning(ex.Message); } else { GUtil.Warning(Form.ActiveForm, ex.Message); //TODO 苦しい逃げ。IPoderosaFormを実装したベースクラスをCoreにでも持っていたほうがいいのか } return(null); } finally { if (!successful && strm != null) { strm.Close(); } } }
private bool ValidateParam() { SerialTerminalSettings settings = _terminalSettings; SerialTerminalParam param = _terminalParam; try { LogType logtype = ((EnumListItem <LogType>)_logTypeBox.SelectedItem).Value; ISimpleLogSettings logsettings = null; if (logtype != LogType.None) { logsettings = CreateSimpleLogSettings(logtype, _logFileBox.Text); if (logsettings == null) { return(false); //動作キャンセル } } param.PortName = _portBox.SelectedItem as string; if (param.PortName == null) { return(false); } string autoExecMacroPath = null; if (_autoExecMacroPathBox.Text.Length != 0) { autoExecMacroPath = _autoExecMacroPathBox.Text; } IAutoExecMacroParameter autoExecParams = param.GetAdapter(typeof(IAutoExecMacroParameter)) as IAutoExecMacroParameter; if (autoExecParams != null) { autoExecParams.AutoExecMacroPath = autoExecMacroPath; } settings.BeginUpdate(); if (logsettings != null) { settings.LogSettings.Reset(logsettings); } settings.Caption = param.PortName; settings.BaudRate = Int32.Parse(_baudRateBox.Text); settings.ByteSize = (byte)(_dataBitsBox.SelectedIndex == 0 ? 7 : 8); settings.StopBits = ((EnumListItem <StopBits>)_stopBitsBox.SelectedItem).Value; settings.Parity = ((EnumListItem <Parity>)_parityBox.SelectedItem).Value; settings.FlowControl = ((EnumListItem <FlowControl>)_flowControlBox.SelectedItem).Value; settings.Encoding = ((EnumListItem <EncodingType>)_encodingBox.SelectedItem).Value; settings.LocalEcho = _localEchoBox.SelectedIndex == 1; settings.TransmitNL = ((EnumListItem <NewLine>)_newLineBox.SelectedItem).Value; settings.TransmitDelayPerChar = Int32.Parse(_transmitDelayPerCharBox.Text); settings.TransmitDelayPerLine = Int32.Parse(_transmitDelayPerLineBox.Text); settings.EndUpdate(); return(true); } catch (Exception ex) { GUtil.Warning(this, ex.Message); return(false); } }
public SerialTerminalConnection(SerialTerminalParam p, SerialTerminalSettings settings, IntPtr fh) { _serialTerminalParam = p; _fileHandle = fh; _serialSocket = new SerialSocket(this, fh, settings); _serialTerminalOutput = new SerialTerminalOutput(fh); //_socket = _serialSocket; //_terminalOutput = _serialTerminalOutput; }