[英]how to read arduino serial monitor data from visual studio and save as an array
I'm going to assume winforms. 我将假设winforms。 If not, then this wont be helpful.
如果没有,那么这将不会有所帮助。
First, add a serial port to your form from the toolbox. 首先,从工具箱中向表单添加一个串行端口。 Then do something like this to get the data into an array:
然后执行类似的操作将数据放入数组:
string tempStr;
int size = serialPort1.BytesToRead;
//runs as long as there are bytes in the serial buffer to be read,
//you may need to change the way it runs to get all of your data depending upon
//how the device is sending data to the serial port
while (size != 0)
{
//store incoming byte
int b1 = serialPort1.ReadByte();
//converts byte to character
char c = Convert.ToChar(b1);
//puts the character into a string
tempStr = c.ToString();
//append it to Rx (output string)
Rx += tempStr;
}
//you'll may need to do some messing around with the character you use to split
string[] results = Rx.Split(new Char[] {'\r' });
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.