コード例 #1
0
        /// <summary>
        /// Create an instance of the ComPorts class.
        /// Initialize port settings and other parameters.
        /// specify behavior on events.
        /// </summary>

        private void Form1_Load(object sender, System.EventArgs e)
        {
            Show();
            UserPort1                      = new ComPorts();
            MyPortSettingsDialog           = new PortSettingsDialog();
            tmrLookForPortChanges.Interval = 1000;
            tmrLookForPortChanges.Stop();

            //  Specify the routines that execute on events in other modules.
            //  The routines can receive data from other modules.
            timerRobotnik.Stop();
        }
コード例 #2
0
        /// <summary>
        /// Look for COM ports and display them in the combo box.
        /// </summary>

        private void btnPort_Click(object sender, System.EventArgs e)   // $$$$
        {
            ComPorts.FindComPorts();
            MyPortSettingsDialog.DisplayComPorts();
            MyPortSettingsDialog.SelectComPort(UserPort1.SelectedPort.PortName);
            MyPortSettingsDialog.SelectBitRate(UserPort1.SelectedPort.BaudRate);
            MyPortSettingsDialog.SelectHandshaking(UserPort1.SelectedPort.Handshake);

            UserPort1.ParameterChanged = false;

            //  Display the combo boxes for setting port parameters.

            MyPortSettingsDialog.ShowDialog();
        }
コード例 #3
0
        /// <summary>
        /// Set initial port parameters.
        /// </summary>

        internal void InitializePortSettings()
        {
            if (!(settingsInitialized))
            {
                // Bit rates to select from.

                bitRates[0]  = 300;
                bitRates[1]  = 600;
                bitRates[2]  = 1200;
                bitRates[3]  = 2400;
                bitRates[4]  = 9600;
                bitRates[5]  = 14400;
                bitRates[6]  = 19200;
                bitRates[7]  = 38400;
                bitRates[8]  = 57600;
                bitRates[9]  = 115200;
                bitRates[10] = 128000;

                // Place the bit rates and handshaking options in the combo boxes.

                cmbBitRate.DataSource    = bitRates;
                cmbBitRate.DropDownStyle = ComboBoxStyle.DropDownList;

                //  Handshaking options.

                cmbHandshaking.Items.Add(Handshake.None);
                cmbHandshaking.Items.Add(Handshake.XOnXOff);
                cmbHandshaking.Items.Add(Handshake.RequestToSend);
                cmbHandshaking.Items.Add(Handshake.RequestToSendXOnXOff);

                cmbHandshaking.DropDownStyle = ComboBoxStyle.DropDownList;

                // Find and display available COM ports.

                ComPorts.FindComPorts();

                cmbPort.DataSource = ComPorts.myPortNames;

                cmbPort.DropDownStyle = ComboBoxStyle.DropDownList;

                settingsInitialized = true;
            }
        }
コード例 #4
0
        /// <summary>
        /// Create an instance of the ComPorts class.
        /// Initialize port settings and other parameters.
        /// specify behavior on events.
        /// </summary>

        private void Form1_Load(object sender, System.EventArgs e)
        {
            Show();

            UserPort1 = new ComPorts();

            MyPortSettingsDialog = new PortSettingsDialog();

            tmrLookForPortChanges.Interval = 1000;
            tmrLookForPortChanges.Stop();

            InitializeDisplayElements();

            SetInitialPortParameters();

            if (ComPorts.comPortExists)
            {
                UserPort1.SelectedPort.PortName = ComPorts.myPortNames[MyPortSettingsDialog.cmbPort.SelectedIndex];

                //  A check box enables requesting to open the selected COM port on start up.
                //  Otherwise the application opens the port when the user clicks the Open Port
                //  button or types text to send.

                if (MyPortSettingsDialog.chkOpenComPortOnStartup.Checked)
                {
                    UserPort1.PortOpen = UserPort1.OpenComPort();
                    AccessForm("DisplayCurrentSettings", "", Color.Black);
                    AccessForm("DisplayStatus", "", Color.Black);
                }
                else
                {
                    DisplayCurrentSettings();
                }
            }

            //  Specify the routines that execute on events in other modules.
            //  The routines can receive data from other modules.

            ComPorts.UserInterfaceData                   += new ComPorts.UserInterfaceDataEventHandler(AccessFormMarshal);
            PortSettingsDialog.UserInterfaceData         += new PortSettingsDialog.UserInterfaceDataEventHandler(AccessFormMarshal);
            PortSettingsDialog.UserInterfacePortSettings += new PortSettingsDialog.UserInterfacePortSettingsEventHandler(SetPortParameters);
        }
コード例 #5
0
        /// <summary>
        /// Look for ports. If at least one is found, stop the timer and
        /// select the saved port if possible or the first port.
        /// This timer is enabled only when no COM ports are present.
        /// </summary>

        private void tmrLookForPortChanges_Tick(object sender, System.EventArgs e)
        {
            ComPorts.FindComPorts();

            if (ComPorts.comPortExists)
            {
                tmrLookForPortChanges.Stop();
                DisplayStatus("COM port(s) found.", Color.Black);

                MyPortSettingsDialog.DisplayComPorts();
                MyPortSettingsDialog.SelectComPort(UserPort1.SavedPortName);
                MyPortSettingsDialog.SelectBitRate(UserPort1.SavedBitRate);
                MyPortSettingsDialog.SelectHandshaking((( Handshake )(UserPort1.SavedHandshake)));

                //  Set selectedPort.

                SetPortParameters(UserPort1.SavedPortName, UserPort1.SavedBitRate, (( Handshake )(UserPort1.SavedHandshake)));

                DisplayCurrentSettings();
                UserPort1.ParameterChanged = true;
            }
        }
コード例 #6
0
ファイル: MainForm.cs プロジェクト: larrychong/DimSumProject
        /// <summary>
        /// Create an instance of the ComPorts class.
        /// Initialize port settings and other parameters. 
        /// specify behavior on events.
        /// </summary>
        private void Form1_Load( object sender, System.EventArgs e )
        {
            Show();

                UserPort1 = new ComPorts();

                MyPortSettingsDialog = new PortSettingsDialog();

                tmrLookForPortChanges.Interval = 1000;
                tmrLookForPortChanges.Stop();

                InitializeDisplayElements();

                SetInitialPortParameters();

                if (ComPorts.comPortExists)
                {
                    UserPort1.SelectedPort.PortName = ComPorts.myPortNames[MyPortSettingsDialog.cmbPort.SelectedIndex];

                    //  A check box enables requesting to open the selected COM port on start up.
                    //  Otherwise the application opens the port when the user clicks the Open Port
                    //  button or types text to send.

                    if (MyPortSettingsDialog.chkOpenComPortOnStartup.Checked)
                    {
                        UserPort1.PortOpen = UserPort1.OpenComPort();
                        AccessForm("DisplayCurrentSettings", "", Color.Black);
                        AccessForm("DisplayStatus", "", Color.Black);
                    }
                    else
                    {
                        DisplayCurrentSettings();
                    }
                }

                //  Specify the routines that execute on events in other modules.
                //  The routines can receive data from other modules.

                ComPorts.UserInterfaceData += new ComPorts.UserInterfaceDataEventHandler(AccessFormMarshal);
                PortSettingsDialog.UserInterfaceData += new PortSettingsDialog.UserInterfaceDataEventHandler(AccessFormMarshal);
                PortSettingsDialog.UserInterfacePortSettings += new PortSettingsDialog.UserInterfacePortSettingsEventHandler(SetPortParameters);
        }