繁体   English   中英

C#不断将串行数据流式传输到arduino

[英]C# constantly streaming serial data to arduino

当选中某个框时,我在流逗号分隔变量时遇到麻烦。 我希望即使变量没有变化,数据流也一直流向arduino。 唯一一次我能接近所有东西的时候,我陷入了无限循环。 这是我当前拥有的代码,任何帮助将不胜感激。

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Timers;

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

        private void streamBox_CheckedChanged(object sender, EventArgs e)
        {
            int a = 1;
            int b = 2;
            int c = 3;
                bool state = streamBox.Checked;
                while (state == true)
                {
                System.Console.WriteLine("{0},{1},{2}", a,b,c);

            }
        }

        private void stopStreamBtn_Click(object sender, EventArgs e)
        {
            streamBox.Checked = false;
        }
    }
}

我用信息仓库给了我答案。 我现在可以调整延迟以匹配波特率。

  private async void streamBox_CheckedChanged(object sender, EventArgs e) { int a = 1; int b = 2; int c = 3; bool state = streamBox.Checked; while (state == true) { System.Console.WriteLine("{0},{1},{2}", a,b,c); await Task.Delay(10); } } 

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM