日期:2014-05-17  浏览次数:20768 次

关于c# serialport接受数据怪现象
本帖最后由 h804759109 于 2013-11-27 11:53:09 编辑

   private void Form1_Load(object sender, EventArgs e)
        {
            this.serialPort1.PortName = "com8";
            this.serialPort1.BaudRate = 9600;
            this.serialPort1.DataBits = 8;
            this.serialPort1.StopBits = StopBits.One;
            this.serialPort1.Parity = Parity.Even;
            this.serialPort1.Open();
            this.timer1.Enabled = true;
            this.timer1.Interval = 500;
        }

        private void button1_Click(object sender, EventArgs e)
        {
            this.serialPort1.Close();
            this.Close();
        }

        private void ReceiveText(object sender, EventArgs e)
        {
            double datareceive_2;
            short datareceive_4 = 8;
            short datareceive_5 = 4;
            string datareceive_6;
            string datareceive_7;
            string datareceive_8;
            int datareceive_9;
            char[] datareceive_0 = datareceive.ToCharArray();//字符串转换成字符串数组        
            //byte[] datareceive_0 = Convert.FromBase64String(datareceive);   
            int i = datareceive_0.Length;//判断长度
            if (i == 7)
            {
                datareceive_4 = (short)datareceive_0[3];//获取所需
                datareceive_5 = (short)datareceive_0[4];

                datareceive_6 = Convert.ToString(datareceive_4, 16);//十进制转化十六进制
                datareceive_7&n