I am having trouble streaming comma delimited variables when a certain box is checked. I want the data stream to be constantly flowing to the arduino even if there is no change in the variables. The only time I have been able to get anything close I got stuck in an infinite loop. Here is the current code I have, any help would be appreciated.
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;
}
}
}
I figured it out using the info barny gave me. I can now adjust the delay to match the baudrate.
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); } }
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.