标题:新人求助:程序运行出现的问题。
取消只看楼主
andreiguodal
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2014-5-31
结帖率:0
已结贴  问题点数:20 回复次数:0 
新人求助:程序运行出现的问题。
最近在做光通信,通过USB口读取数据,以下是编的代码,但是发现从“comm.BaudRate = 9600; ”这个语句之后貌似就直接跳过不运行了,不知道问题出在哪里,求老师们帮助。多谢!!

using System;
using System.Collections.Generic;
using
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using
using System.Text.RegularExpressions;
using System.Threading;

namespace 读串口
{
    public partial class Form1 : Form
    {
        private string ll = "55";
        private StringBuilder builder = new StringBuilder();
        private SerialPort comm = new SerialPort();
        //private Thread thread;
        public Form1()
        {
            InitializeComponent();
        }
        private void Form1_Load(object sender, EventArgs e)
        {
            comm.PortName = "COM1";
            comm.BaudRate = 9600;
            //comm.Open();
            int n;
            //while (true)
            //{
            //System.Threading.Thread.Sleep(2000);

            n = comm.BytesToRead;
            byte[] buf = new byte[n];
            comm.Read(buf, 0, n);
            ll = Encoding.Default.GetString(buf);
            //MessageBox.Show(ll);
            if (ll.StartsWith("U"))
            {
                ll = "55";
            }
            else
            {
                ll = "66";
            }
            comm.Close();
            textBox1.Text = ll;
        }
    }
}
搜索更多相关主题的帖子: 通信 public 
2014-05-31 17:12



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-432335-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.049137 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved