C# string to value form (serial port assistant)

In the process of developing the serial port assistant, the author needs to add the value in the angle box and the value in the increment box to send. Therefore, it is necessary to convert the string in the textbox into a value first, and then calculate the corresponding value by the value. Add, and then use the serial port to call the function to write the data. After trying, the author finally realizes this function, and now shares it with readers.

 private void button4_Click(object sender, EventArgs e)
        {
            if (serialPort1.IsOpen)    //如果串口设备已经打开了
            {
                if (radioButton2.Checked)  //如果是以字符的形式发送数据
                {
                    if (radioButton3.Checked)
                    {
                        try
                        {
                            string strNum = textBox3.Text ;
                            string strNum1 = textBox9.Text;
                            int age1 = int.Parse(strNum);
                            int age2 = int.Parse(strNum1);
                            int age3 = age1 + age2;
                            string mynum = Convert.ToString(age3);
                            serialPort1.WriteLine("F8"+mynum);//写数据
                        }
                        catch
                        {
                            MessageBox.Show("窗口数据写入错误", "错误");//出错提示
                        }
                    }

If readers have any questions, welcome to come to the comment area to ask questions, and welcome to discuss with the author if there is a better way.

Guess you like

Origin blog.csdn.net/weixin_61056520/article/details/129735094