Esempio n. 1
0
 public static void UpdateDCB(ref Win32Serial.DCB dcb, SerialTerminalSettings param)
 {
     dcb.BaudRate = (uint)param.BaudRate;
     dcb.ByteSize = param.ByteSize;
     dcb.Parity   = (byte)param.Parity;
     dcb.StopBits = (byte)param.StopBits;
     //フロー制御:TeraTermのソースからちょっぱってきた
     if (param.FlowControl == FlowControl.Xon_Xoff)
     {
         //dcb.fOutX = TRUE;
         //dcb.fInX = TRUE;
         //dcbを完全にコントロールするオプションが必要かもな
         dcb.Misc    |= 0x300; //上記2行のかわり
         dcb.XonLim   = 2048;  //CommXonLim;
         dcb.XoffLim  = 2048;  //CommXoffLim;
         dcb.XonChar  = 0x11;
         dcb.XoffChar = 0x13;
     }
     else if (param.FlowControl == FlowControl.Hardware)
     {
         //dcb.fOutxCtsFlow = TRUE;
         //dcb.fRtsControl = RTS_CONTROL_HANDSHAKE;
         dcb.Misc |= 0x4 | 0x2000;
     }
 }
Esempio n. 2
0
        public override ITerminalSettings Clone()
        {
            SerialTerminalSettings p = new SerialTerminalSettings();

            p.Import(this);
            return(p);
        }
Esempio n. 3
0
 public SerialSocket(SerialTerminalConnection parent, IntPtr filehandle, SerialTerminalSettings settings)
 {
     _parent               = parent;
     _serialSettings       = settings;
     _fileHandle           = filehandle;
     _writeOverlappedEvent = new ManualResetEvent(false);
 }
        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.SelectedIndex      = (int)_terminalSettings.Parity;
            _stopBitsBox.SelectedIndex    = (int)_terminalSettings.StopBits;
            _flowControlBox.SelectedIndex = (int)_terminalSettings.FlowControl;

            _encodingBox.SelectedIndex  = (int)_terminalSettings.Encoding;
            _newLineBox.SelectedIndex   = _newLineBox.FindStringExact(_terminalSettings.TransmitNL.ToString());
            _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;
            }
        }
Esempio n. 5
0
        public bool IsSupporting(ITerminalParameter param, ITerminalSettings settings)
        {
            SerialTerminalParam    sp = param as SerialTerminalParam;
            SerialTerminalSettings ts = settings as SerialTerminalSettings;

            return(sp != null && ts != null);
        }
        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);
            }
        }
Esempio n. 7
0
        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));
        }
Esempio n. 8
0
 public static SerialTerminalSettings CreateDefaultSerialTerminalSettings(string portName)
 {
     SerialTerminalSettings ts = new SerialTerminalSettings();
     ts.BeginUpdate();
     ts.Icon = SerialPortPlugin.Instance.LoadIcon();
     ts.Caption = portName;
     ts.EndUpdate();
     return ts;
 }
Esempio n. 9
0
 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;
 }
Esempio n. 10
0
 public static SerialTerminalSettings CreateDefaultSerialTerminalSettings(int port)
 {
     SerialTerminalSettings ts = new SerialTerminalSettings();
     ts.BeginUpdate();
     ts.Icon = SerialPortPlugin.Instance.LoadIcon();
     ts.Caption = String.Format("COM{0}", port);
     ts.EndUpdate();
     return ts;
 }
Esempio n. 11
0
        public static SerialTerminalSettings CreateDefaultSerialTerminalSettings(string portName)
        {
            SerialTerminalSettings ts = new SerialTerminalSettings();

            ts.BeginUpdate();
            ts.Icon    = SerialPortPlugin.Instance.LoadIcon();
            ts.Caption = portName;
            ts.EndUpdate();
            return(ts);
        }
Esempio n. 12
0
        public static SerialTerminalSettings CreateDefaultSerialTerminalSettings(int port)
        {
            SerialTerminalSettings ts = new SerialTerminalSettings();

            ts.BeginUpdate();
            ts.Icon    = SerialPortPlugin.Instance.LoadIcon();
            ts.Caption = String.Format("COM{0}", port);
            ts.EndUpdate();
            return(ts);
        }
Esempio n. 13
0
        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();
            }
        }
Esempio n. 14
0
        public void ApplySerialParam(SerialTerminalSettings settings)
        {
            //paramの内容でDCBを更新してセットしなおす
            Win32Serial.DCB dcb = new Win32Serial.DCB();
            SerialPortUtil.FillDCB(_fileHandle, ref dcb);
            SerialPortUtil.UpdateDCB(ref dcb, settings);

            if (!Win32Serial.SetCommState(_fileHandle, ref dcb))
            {
                throw new ArgumentException(SerialPortPlugin.Instance.Strings.GetString("Message.SerialTerminalConnection.ConfigError"));
            }
        }
Esempio n. 15
0
        public override void Import(ITerminalSettings src)
        {
            base.Import(src);
            SerialTerminalSettings p = src as SerialTerminalSettings;

            Debug.Assert(p != null);

            _baudRate             = p._baudRate;
            _byteSize             = p._byteSize;
            _parity               = p._parity;
            _stopBits             = p._stopBits;
            _flowControl          = p._flowControl;
            _transmitDelayPerChar = p._transmitDelayPerChar;
            _transmitDelayPerLine = p._transmitDelayPerLine;
        }
Esempio n. 16
0
        public void ApplyParam(SerialTerminalParam param, SerialTerminalSettings settings)
        {
            _terminalParam    = param == null ? new SerialTerminalParam() : param;
            _terminalSettings = settings == null?SerialPortUtil.CreateDefaultSerialTerminalSettings(_terminalParam.PortName) : settings;

            // 設定のポート名称のアイテムを選択。それが選択できなければ最初の項目を選択。
            _portBox.SelectedItem = _terminalParam.PortName;
            if (_portBox.SelectedItem == null && 0 < _portBox.Items.Count)
            {
                _portBox.SelectedIndex = 0;
            }

            //これらの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;
            }
        }
Esempio n. 17
0
        public object Deserialize(StructuredText node)
        {
            SerialTerminalSettings ts = SerialPortUtil.CreateDefaultSerialTerminalSettings(1);

            //TODO Deserializeの別バージョンを作ってimportさせるべきだろう。もしくはService側の実装から変える。要素側には空引数コンストラクタを強制すればいいか
            StructuredText basenode = node.FindChild(typeof(TerminalSettings).FullName);

            if (basenode != null)
            {
                ts.BaseImport((ITerminalSettings)SerialPortPlugin.Instance.SerializeService.Deserialize(basenode));
            }

            ts.BaudRate             = ParseUtil.ParseInt(node.Get("baud-rate"), 9600);
            ts.ByteSize             = (byte)ParseUtil.ParseInt(node.Get("byte-size"), 8);
            ts.Parity               = ParseUtil.ParseEnum <Parity>(node.Get("parity"), Parity.NOPARITY);
            ts.StopBits             = ParseUtil.ParseEnum <StopBits>(node.Get("stop-bits"), StopBits.ONESTOPBIT);
            ts.FlowControl          = ParseUtil.ParseEnum <FlowControl>(node.Get("flow-control"), FlowControl.None);
            ts.TransmitDelayPerChar = ParseUtil.ParseInt(node.Get("delay-per-char"), 0);
            ts.TransmitDelayPerLine = ParseUtil.ParseInt(node.Get("delay-per-line"), 0);

            return(ts);
        }
Esempio n. 18
0
            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);
            }
Esempio n. 19
0
        public StructuredText Serialize(object obj)
        {
            SerialTerminalSettings ts = obj as SerialTerminalSettings;

            Debug.Assert(ts != null);

            StructuredText node = new StructuredText(this.ConcreteType.FullName);

            node.AddChild(SerialPortPlugin.Instance.SerializeService.Serialize(typeof(TerminalSettings), ts));

            node.Set("baud-rate", ts.BaudRate.ToString());
            if (ts.ByteSize != 8)
            {
                node.Set("byte-size", ts.ByteSize.ToString());
            }
            if (ts.Parity != Parity.NOPARITY)
            {
                node.Set("parity", ts.Parity.ToString());
            }
            if (ts.StopBits != StopBits.ONESTOPBIT)
            {
                node.Set("stop-bits", ts.StopBits.ToString());
            }
            if (ts.FlowControl != FlowControl.None)
            {
                node.Set("flow-control", ts.FlowControl.ToString());
            }
            if (ts.TransmitDelayPerChar != 0)
            {
                node.Set("delay-per-char", ts.TransmitDelayPerChar.ToString());
            }
            if (ts.TransmitDelayPerLine != 0)
            {
                node.Set("delay-per-line", ts.TransmitDelayPerLine.ToString());
            }

            return(node);
        }
Esempio n. 20
0
 public static void UpdateDCB(ref Win32Serial.DCB dcb, SerialTerminalSettings param)
 {
     dcb.BaudRate = (uint)param.BaudRate;
     dcb.ByteSize = param.ByteSize;
     dcb.Parity = (byte)param.Parity;
     dcb.StopBits = (byte)param.StopBits;
     //フロー制御:TeraTermのソースからちょっぱってきた
     if (param.FlowControl == FlowControl.Xon_Xoff) {
         //dcb.fOutX = TRUE;
         //dcb.fInX = TRUE;
         //dcbを完全にコントロールするオプションが必要かもな
         dcb.Misc |= 0x300; //上記2行のかわり
         dcb.XonLim = 2048; //CommXonLim;
         dcb.XoffLim = 2048; //CommXoffLim;
         dcb.XonChar = 0x11;
         dcb.XoffChar = 0x13;
     }
     else if (param.FlowControl == FlowControl.Hardware) {
         //dcb.fOutxCtsFlow = TRUE;
         //dcb.fRtsControl = RTS_CONTROL_HANDSHAKE;
         dcb.Misc |= 0x4 | 0x2000;
     }
 }
Esempio n. 21
0
        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);
            }
        }
Esempio n. 22
0
 public SerialSocket(SerialTerminalConnection parent, IntPtr filehandle, SerialTerminalSettings settings)
 {
     _parent = parent;
     _serialSettings = settings;
     _fileHandle = filehandle;
     _writeOverlappedEvent = new ManualResetEvent(false);
 }
Esempio n. 23
0
        public void ApplyParam(SerialTerminalParam param, SerialTerminalSettings settings)
        {
            _terminalParam = param == null ? new SerialTerminalParam() : param;
            _terminalSettings = settings == null ? SerialPortUtil.CreateDefaultSerialTerminalSettings(_terminalParam.PortName) : settings;

            // 設定のポート名称のアイテムを選択。それが選択できなければ最初の項目を選択。
            _portBox.SelectedItem = _terminalParam.PortName;
            if (_portBox.SelectedItem == null && 0 < _portBox.Items.Count) {
                _portBox.SelectedIndex = 0;
            }

            //これらの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;
            }
        }
Esempio n. 24
0
        public void ApplySerialParam(SerialTerminalSettings settings)
        {
            //paramの内容でDCBを更新してセットしなおす
            Win32Serial.DCB dcb = new Win32Serial.DCB();
            SerialPortUtil.FillDCB(_fileHandle, ref dcb);
            SerialPortUtil.UpdateDCB(ref dcb, settings);

            if (!Win32Serial.SetCommState(_fileHandle, ref dcb))
                throw new ArgumentException(SerialPortPlugin.Instance.Strings.GetString("Message.SerialTerminalConnection.ConfigError"));
        }
Esempio n. 25
0
        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�̐ݒ�̓R���{�{�b�N�X�ɐݒ肵�����ڏ��Ɉˑ����Ă���̂Œ��Ӑ[�����邱��
            _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;
            }
        }
Esempio n. 26
0
 public override ITerminalSettings Clone() {
     SerialTerminalSettings p = new SerialTerminalSettings();
     p.Import(this);
     return p;
 }
Esempio n. 27
0
        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();
                }
            }
        }
Esempio n. 28
0
 public static void UpdateDCB(ref Win32Serial.DCB dcb, SerialTerminalSettings param)
 {
     dcb.BaudRate = (uint)param.BaudRate;
     dcb.ByteSize = param.ByteSize;
     dcb.Parity = (byte)param.Parity;
     dcb.StopBits = (byte)param.StopBits;
     //�t���[����FTeraTerm�̃\�[�X���炿����ς��Ă���
     if (param.FlowControl == FlowControl.Xon_Xoff) {
         //dcb.fOutX = TRUE;
         //dcb.fInX = TRUE;
         //dcb����S�ɃR���g���[������I�v�V�������K�v�����
         dcb.Misc |= 0x300; //��L�Q�s�̂����
         dcb.XonLim = 2048; //CommXonLim;
         dcb.XoffLim = 2048; //CommXoffLim;
         dcb.XonChar = 0x11;
         dcb.XoffChar = 0x13;
     }
     else if (param.FlowControl == FlowControl.Hardware) {
         //dcb.fOutxCtsFlow = TRUE;
         //dcb.fRtsControl = RTS_CONTROL_HANDSHAKE;
         dcb.Misc |= 0x4 | 0x2000;
     }
 }
Esempio n. 29
0
 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;
 }