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;
}
}
}
我根据 barny 给我的信息弄明白了。我现在可以调整延迟以匹配波特率。
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);
}
}
选中某个框时,我在流式传输逗号分隔变量时遇到问题。我希望数据流不断流向 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;
}
}
}
我根据 barny 给我的信息弄明白了。我现在可以调整延迟以匹配波特率。
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); } }