Esempio n. 1
0
        private void OnOK(object sender, EventArgs args)
        {
            SerialTerminalParam p = (SerialTerminalParam)_con.Param.Clone();

            p.BaudRate    = Int32.Parse(_baudRateBox.Text);
            p.ByteSize    = (byte)(_dataBitsBox.SelectedIndex == 0? 7 : 8);
            p.StopBits    = (StopBits)_stopBitsBox.SelectedIndex;
            p.Parity      = (Parity)_parityBox.SelectedIndex;
            p.FlowControl = (FlowControl)_flowControlBox.SelectedIndex;
            try {
                p.TransmitDelayPerChar = Int32.Parse(_transmitDelayPerCharBox.Text);
                p.TransmitDelayPerLine = Int32.Parse(_transmitDelayPerLineBox.Text);
            }
            catch (Exception ex) {
                GUtil.Warning(this, ex.Message);
                this.DialogResult = DialogResult.None;
                return;
            }

            try {
                ((SerialTerminalConnection)_con).ApplySerialParam(p);
                this.DialogResult = DialogResult.OK;
            }
            catch (Exception ex) {
                GUtil.Warning(this, ex.Message);
                this.DialogResult = DialogResult.None;
            }
        }
Esempio n. 2
0
 public static void UpdateDCB(ref Win32.DCB dcb, SerialTerminalParam 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. 3
0
        public void ApplyParam(TerminalConnection con)
        {
            _con = con;
            SerialTerminalParam param = (SerialTerminalParam)con.Param;

            _portBox.Text = "COM" + param.Port;
            _baudRateBox.SelectedIndex    = _baudRateBox.FindStringExact(param.BaudRate.ToString());
            _dataBitsBox.SelectedIndex    = param.ByteSize == 7? 0 : 1;
            _parityBox.SelectedIndex      = (int)param.Parity;
            _stopBitsBox.SelectedIndex    = (int)param.StopBits;
            _flowControlBox.SelectedIndex = (int)param.FlowControl;
            _transmitDelayPerCharBox.Text = param.TransmitDelayPerChar.ToString();
            _transmitDelayPerLineBox.Text = param.TransmitDelayPerLine.ToString();
        }
        public CommandResult NewConnection(TerminalParam p)
        {
            if (!CheckPaneCount())
            {
                return(CommandResult.Denied);
            }

            ConnectionTag con = null;

            if (p is TCPTerminalParam)
            {
                TCPTerminalParam param = (TCPTerminalParam)p;
                if (param.IsSSH)
                {
                    SSHShortcutLoginDialog dlg = new SSHShortcutLoginDialog((SSHTerminalParam)param);
                    if (GCUtil.ShowModalDialog(_frame, dlg) == DialogResult.OK)
                    {
                        con = dlg.Result;
                    }
                }
                else
                {
                    con = CommunicationUtil.CreateNewConnection(param);
                }
            }
            else if (p is SerialTerminalParam)
            {
                SerialTerminalParam param = (SerialTerminalParam)p;
                con = CommunicationUtil.CreateNewSerialConnection(_frame, param);
            }
            else if (p is LocalShellTerminalParam)
            {
                LocalShellTerminalParam param = (LocalShellTerminalParam)p;
                con = CommunicationUtil.CreateNewLocalShellConnection(_frame, param);
            }

            if (con != null)
            {
                AddNewTerminal(con);
                return(CommandResult.Success);
            }
            else
            {
                return(CommandResult.Cancelled);
            }
        }
Esempio n. 5
0
        public void ApplyParam(SerialTerminalParam param)
        {
            _portBox.SelectedIndex = param.Port - 1;
            //これらのSelectedIndexの設定はコンボボックスに設定した項目順に依存しているので注意深くすること
            _baudRateBox.SelectedIndex    = _baudRateBox.FindStringExact(param.BaudRate.ToString());
            _dataBitsBox.SelectedIndex    = param.ByteSize == 7? 0 : 1;
            _parityBox.SelectedIndex      = (int)param.Parity;
            _stopBitsBox.SelectedIndex    = (int)param.StopBits;
            _flowControlBox.SelectedIndex = (int)param.FlowControl;

            _encodingBox.SelectedIndex  = (int)param.EncodingProfile.Type;
            _newLineBox.SelectedIndex   = _newLineBox.FindStringExact(param.TransmitNL.ToString());
            _localEchoBox.SelectedIndex = param.LocalEcho? 1 : 0;

            _transmitDelayPerCharBox.Text = param.TransmitDelayPerChar.ToString();
            _transmitDelayPerLineBox.Text = param.TransmitDelayPerLine.ToString();
        }
Esempio n. 6
0
        private SerialTerminalParam ValidateParam()
        {
            SerialTerminalParam p = new SerialTerminalParam();

            try {
                p.LogType = (LogType)EnumDescAttributeT.For(typeof(LogType)).FromDescription(_logTypeBox.Text, LogType.None);
                if (p.LogType != LogType.None)
                {
                    p.LogPath = _logFileBox.Text;
                    if (p.LogPath == GUtil.CreateLogFileName(null))
                    {
                        p.LogPath = GUtil.CreateLogFileName(String.Format("com{0}", _portBox.SelectedIndex + 1));
                    }
                    LogFileCheckResult r = GCUtil.CheckLogFileName(p.LogPath, this);
                    if (r == LogFileCheckResult.Cancel || r == LogFileCheckResult.Error)
                    {
                        return(null);
                    }
                    p.LogAppend = (r == LogFileCheckResult.Append);
                }

                p.Port        = _portBox.SelectedIndex + 1;
                p.BaudRate    = Int32.Parse(_baudRateBox.Text);
                p.ByteSize    = (byte)(_dataBitsBox.SelectedIndex == 0? 7 : 8);
                p.StopBits    = (StopBits)_stopBitsBox.SelectedIndex;
                p.Parity      = (Parity)_parityBox.SelectedIndex;
                p.FlowControl = (FlowControl)_flowControlBox.SelectedIndex;

                p.EncodingProfile = EncodingProfile.Get((EncodingType)_encodingBox.SelectedIndex);

                p.LocalEcho  = _localEchoBox.SelectedIndex == 1;
                p.TransmitNL = (NewLine)EnumDescAttributeT.For(typeof(NewLine)).FromDescription(_newLineBox.Text, LogType.None);

                p.TransmitDelayPerChar = Int32.Parse(_transmitDelayPerCharBox.Text);
                p.TransmitDelayPerLine = Int32.Parse(_transmitDelayPerLineBox.Text);
                return(p);
            }
            catch (Exception ex) {
                GUtil.Warning(this, ex.Message);
                return(null);
            }
        }
Esempio n. 7
0
        private void OnOK(object sender, EventArgs args)
        {
            _result           = null;
            this.DialogResult = DialogResult.None;

            SerialTerminalParam param = ValidateParam();

            if (param == null)
            {
                return;
            }

            try {
                _result = CommunicationUtil.CreateNewSerialConnection(this, param);
                if (_result != null)
                {
                    this.DialogResult = DialogResult.OK;
                }
            }
            catch (Exception ex) {
                GUtil.Warning(this, ex.Message);
            }
        }
        public CommandResult NewSerialConnectionWithDialog(SerialTerminalParam param)
        {
            if (!CheckPaneCount())
            {
                return(CommandResult.Denied);
            }

            SerialLoginDialog dlg = new SerialLoginDialog();

            if (param != null)
            {
                dlg.ApplyParam(param);
            }
            else
            {
                dlg.ApplyParam(GApp.ConnectionHistory.TopSerialParam);
            }

            if (GCUtil.ShowModalDialog(_frame, dlg) == DialogResult.OK)
            {
                ConnectionTag con = dlg.Result;
                if (con != null)
                {
                    AddNewTerminal(con);
                    return(CommandResult.Success);
                }
            }

            return(CommandResult.Cancelled);


            //XModemReceiver xmodem = new XModemReceiver(GEnv.Connections.ActiveTag, "C:\\IOPort\\xmodemresult.txt");
            //XModemSender xmodem = new XModemSender(GEnv.Connections.ActiveTag, "C:\\IOPort\\xslt.cs");
            //xmodem.Start();

            //return CommandResult.Success;
        }
        public ConnectionTag SilentNewConnection(TerminalParam p)
        {
            if (!CheckPaneCount())
            {
                return(null);
            }

            ConnectionTag con = null;

            if (p is SSHTerminalParam)
            {
                SSHTerminalParam tp = (SSHTerminalParam)p;
                con = CommunicationUtil.CreateNewConnection(tp, null);
            }
            else if (p is TelnetTerminalParam)
            {
                TelnetTerminalParam tp = (TelnetTerminalParam)p;
                con = CommunicationUtil.CreateNewConnection(tp);
            }
            else if (p is SerialTerminalParam)
            {
                SerialTerminalParam tp = (SerialTerminalParam)p;
                con = CommunicationUtil.CreateNewSerialConnection(_frame, tp);
            }
            else if (p is LocalShellTerminalParam)
            {
                LocalShellTerminalParam tp = (LocalShellTerminalParam)p;
                con = CommunicationUtil.CreateNewLocalShellConnection(_frame, tp);
            }

            if (con != null)
            {
                AddNewTerminal(con);
            }
            return(con);
        }
Esempio n. 10
0
 public object Clone() {
     SerialTerminalParam tp = new SerialTerminalParam();
     tp._portName = _portName;
     tp._terminalType = _terminalType;
     return tp;
 }
Esempio n. 11
0
 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;
 }
Esempio n. 12
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. 13
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. 14
0
 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;
 }
Esempio n. 15
0
        public static ConnectionTag CreateNewSerialConnection(IWin32Window parent, SerialTerminalParam param)
        {
            bool       successful = false;
            FileStream strm       = null;

            try
            {
                string portstr = String.Format("\\\\.\\COM{0}", param.Port);
                IntPtr ptr     = Win32.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 = GEnv.Strings.GetString("Message.CommunicationUtil.FailedToOpenSerial");
                    int    err = Win32.GetLastError();
                    if (err == 2)
                    {
                        msg += GEnv.Strings.GetString("Message.CommunicationUtil.NoSuchDevice");
                    }
                    else if (err == 5)
                    {
                        msg += GEnv.Strings.GetString("Message.CommunicationUtil.DeviceIsBusy");
                    }
                    else
                    {
                        msg += "\nGetLastError=" + Win32.GetLastError();
                    }
                    throw new Exception(msg);
                }
                //strm = new FileStream(ptr, FileAccess.Write, true, 8, true);
                Win32.DCB dcb = new Win32.DCB();
                FillDCB(ptr, ref dcb);
                UpdateDCB(ref dcb, param);

                if (!Win32.SetCommState(ptr, ref dcb))
                {
                    throw new Exception(GEnv.Strings.GetString("Message.CommunicationUtil.FailedToConfigSerial"));
                }
                Win32.COMMTIMEOUTS timeouts = new Win32.COMMTIMEOUTS();
                Win32.GetCommTimeouts(ptr, ref timeouts);
                timeouts.ReadIntervalTimeout         = 0xFFFFFFFF;
                timeouts.ReadTotalTimeoutConstant    = 0;
                timeouts.ReadTotalTimeoutMultiplier  = 0;
                timeouts.WriteTotalTimeoutConstant   = 100;
                timeouts.WriteTotalTimeoutMultiplier = 100;
                Win32.SetCommTimeouts(ptr, ref timeouts);
                successful = true;
                System.Drawing.Size      sz = GEnv.Frame.TerminalSizeForNextConnection;
                SerialTerminalConnection r  = new SerialTerminalConnection(param, ptr, sz.Width, sz.Height);
                r.SetServerInfo("COM" + param.Port, null);
                return(new ConnectionTag(r));
            }
            catch (Exception ex)
            {
                GUtil.Warning(parent, ex.Message);
                return(null);
            }
            finally
            {
                if (!successful && strm != null)
                {
                    strm.Close();
                }
            }
        }