已有56人关注
serialPort 接收串口数据方法 (急求老师)
发表在C#图书答疑 2012-05-13
是否精华
版块置顶:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO.Ports;

namespace serialPort
{
    public partial class Form1 : Form
    {
        public Form1()
        {
      
            InitializeComponent();
        }

        SerialPort serialPort = new SerialPort("COM1", 9600, Parity.None, 8);
        private void Form1_Load(object sender, EventArgs e)
        {
           

        }

        private void button1_Click(object sender, EventArgs e)
        {
            serialPort.Open();
            byte[] data = Convert.FromBase64String(serialPort.ReadLine());
            textBox1.Text = Encoding.Unicode.GetString(data);
            serialPort.Close();
            MessageBox.Show("数据接收成功!", "系统提示");
        }
    }
}


为什么一接收就卡死了 !而在进程中又看见还在运行 就是不动   能不能帮忙看看那里出问题了怎么解决啊

另外,你们的那一本书中有关于数据更具名称的不同自动进行汇总的啊![img src=null/img]
分享到:
精彩评论 1
小科_mrkj
学分:43 LV2
2012-05-16
沙发
读者朋友:
    您好,这个问题可能是后台正在接收信息,导致窗体无响应,你可以通过Thread类新开一个线程,然后在新开的线程中使用串口接收数据。
首页上一页 1 下一页尾页 1 条记录 1/1页
手机同步功能介绍
友情提示:以下图书配套资源能够实现手机同步功能
明日微信公众号
明日之星 明日之星编程特训营
客服热线(每日9:00-17:00)
400 675 1066
mingrisoft@mingrisoft.com
吉林省明日科技有限公司Copyright ©2007-2022,mingrisoft.com, All Rights Reserved长春市北湖科技开发区盛北大街3333号长春北湖科技园项目一期A10号楼四、五层
吉ICP备10002740号-2吉公网安备22010202000132经营性网站备案信息 营业执照