示例#1
0
文件: Form1.cs 项目: fyyc1204/MTSICS
        private void button2_Click(object sender, EventArgs e)
        {
            String portName = textBox2.Text;//端口名称
            int baudeRate =Convert.ToInt32(textBox3.Text);//波特率
            Parity parity = (Parity)Enum.Parse(typeof(Parity), textBox4.Text);//奇偶校验位
            int dataBits = Convert.ToInt32(textBox5.Text);
            StopBits stopBits = (StopBits)Enum.Parse(typeof(StopBits), textBox6.Text);

            mtsics = new MT_SICS.MT_SICS(portName, baudeRate, parity, dataBits, stopBits);
            mtsics.OnDataStable+=new MT_SICS.MT_SICS.DataStableEventHandler(mtsics_OnDataStable);
            mtsics.Open();
            MessageBox.Show("串口打开成功");
        }
示例#2
0
文件: Form1.cs 项目: wpmyj/MTSICS
        private void button2_Click(object sender, EventArgs e)
        {
            String   portName  = textBox2.Text;                                     //端口名称
            int      baudeRate = Convert.ToInt32(textBox3.Text);                    //波特率
            Parity   parity    = (Parity)Enum.Parse(typeof(Parity), textBox4.Text); //奇偶校验位
            int      dataBits  = Convert.ToInt32(textBox5.Text);
            StopBits stopBits  = (StopBits)Enum.Parse(typeof(StopBits), textBox6.Text);

            mtsics = new MT_SICS.MT_SICS(portName, baudeRate, parity, dataBits, stopBits);
            mtsics.OnDataStable += new MT_SICS.MT_SICS.DataStableEventHandler(mtsics_OnDataStable);
            mtsics.Open();
            MessageBox.Show("串口打开成功");
        }
示例#3
0
        //打开串口
        private void buttonX14_Click(object sender, EventArgs e)
        {
            try
                {

                    String portName = comboBoxEx1_com.Items[comboBoxEx1_com.SelectedIndex] + "";//端口名称
                    MessageBox.Show(comboBoxEx1_com.Items[comboBoxEx1_com.SelectedIndex] + "");
                    int baudeRate = Convert.ToInt32(comboBoxEx2_baud.Items[comboBoxEx2_baud.SelectedIndex] + "");//波特率
                    Parity parity = (Parity)Enum.Parse(typeof(Parity), comboBoxEx4_check.Items[comboBoxEx4_check.SelectedIndex] + "");//奇偶校验位
                    int dataBits = Convert.ToInt32(comboBoxEx3_data.Items[comboBoxEx3_data.SelectedIndex] + "");
                    StopBits stopBits = (StopBits)Enum.Parse(typeof(StopBits), comboBoxEx5_stop.Items[comboBoxEx5_stop.SelectedIndex] + "");

                   // mtsics = new MT_SICS.MT_SICS();
                    mtsics = new MT_SICS.MT_SICS(portName, baudeRate, parity, dataBits, stopBits);

                    mtsics.OnDataStable += new MT_SICS.MT_SICS.DataStableEventHandler(mtsics_OnDataStable);

                    mtsics.Open();
                    MessageBox.Show("串口打开成功");
                    //MT_SICS.MT_SICS mt = new MT_SICS.MT_SICS();
                    // mtsics.SendSeriesWeightRequest();
                    timer1.Enabled = true;
                    buttonX14.Enabled = false;
                    buttonX15.Enabled = true;
                    buttonX3.Focus();
                }
                catch (Exception ex)
                {
                    MessageBox.Show("串口已打开或打开全口前输入信息不完整");
                    MessageBox.Show(ex.Message);

                }
        }
示例#4
0
        //打开串口
        private void button6_Click(object sender, EventArgs e)
        {
            try
                {

                    //String portName = comboBoxItem1.Items[comboBoxItem1.SelectedIndex] + "";//端口名称
                    ////MessageBox.Show(comboBoxItem2.Items[comboBoxItem2.SelectedIndex] + "");
                    //int baudeRate = Convert.ToInt32(comboBoxItem2.Items[comboBoxItem2.SelectedIndex] + "");//波特率
                    //Parity parity = (Parity)Enum.Parse(typeof(Parity), comboBoxItem3.Items[comboBoxItem3.SelectedIndex] + "");//奇偶校验位
                    //int dataBits = Convert.ToInt32(comboBoxItem5.Items[comboBoxItem5.SelectedIndex] + "");
                    //StopBits stopBits = (StopBits)Enum.Parse(typeof(StopBits), comboBoxItem4.Items[comboBoxItem4.SelectedIndex] + "");

                    mtsics = new MT_SICS.MT_SICS();
                    mtsics.OnDataStable += new MT_SICS.MT_SICS.DataStableEventHandler(mtsics_OnDataStable);

                    mtsics.Open();
                    MessageBox.Show("串口打开成功");
                    //MT_SICS.MT_SICS mt = new MT_SICS.MT_SICS();
                   // mtsics.SendSeriesWeightRequest();
                    timer1.Enabled = true;
                    //button6.Enabled = false;
                   // button7.Enabled = true;
                    buttonX3.Focus();
                }
                catch( Exception ex)
                {
                    MessageBox.Show("串口已打开或打开全口前输入信息不完整");
                    MessageBox.Show(ex.Message);

                }
        }