示例#1
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();
            }
        }
示例#2
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;
            }
        }
示例#3
0
        public void ApplyParam(SerialTerminalParam param)
        {
            _portBox.SelectedIndex = param.Port-1;
            //������SelectedIndex�̐ݒ�̓R���{�{�b�N�X�ɐݒ肵�����ڏ��Ɉˑ����Ă���̂Œ��Ӑ[�����邱��
            _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();
        }
示例#4
0
 internal SerialTerminalParam(SerialTerminalParam p)
     : base(p)
 {
     _port = p._port;
     _baudRate = p._baudRate;
     _byteSize = p._byteSize;
     _parity = p._parity;
     _stopBits = p._stopBits;
     _flowControl = p._flowControl;
     _transmitDelayPerChar = p._transmitDelayPerChar;
     _transmitDelayPerLine = p._transmitDelayPerLine;
 }
示例#5
0
 public static TerminalParam CreateFromConfigNode(ConfigNode sec)
 {
     string type = sec["type"];
     TerminalParam param;
     if(type=="serial")
         param = new SerialTerminalParam();
     else if(type=="tcp") {
         ConnectionMethod cm = ParseMethod(sec["method"]);
         if(cm==ConnectionMethod.Telnet)
             param = new TelnetTerminalParam();
         else
             param = new SSHTerminalParam();
     }
     else if(type=="cygwin")
         param = new CygwinTerminalParam();
     else if(type=="sfu")
         param = new SFUTerminalParam();
     else
         throw new Exception("invalid format");
     param.Import(sec);
     return param;
 }
        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 void ApplySerialParam(SerialTerminalParam param)
        {
            //param�̓�e��DCB��X�V���ăZ�b�g���Ȃ���
            Win32.DCB dcb = new Win32.DCB();
            CommunicationUtil.FillDCB(_fileHandle, ref dcb);
            CommunicationUtil.UpdateDCB(ref dcb, param);

            if(!Win32.SetCommState(_fileHandle, ref dcb))
                throw new ArgumentException(GEnv.Strings.GetString("Message.SerialTerminalConnection.ConfigError"));

            _param = param; //SetCommState������������X�V
        }
 public SerialTerminalConnection(SerialTerminalParam p, IntPtr fh, int width, int height)
     : base(p, width, height)
 {
     _fileHandle = fh;
     _buf = new byte[0x1000];
     _readOL.hEvent  = Win32.CreateEvent(IntPtr.Zero, 0, 0, null);
     _writeOL.hEvent = Win32.CreateEvent(IntPtr.Zero, 0, 0, null);
 }
示例#9
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;
     //�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;
     }
 }