简体   繁体   English

如何从visual studio读取arduino串行监视器数据并保存为数组

[英]how to read arduino serial monitor data from visual studio and save as an array

Im getting following data on arduino serial monitor. 我在arduino串行监视器上获取以下数据。 I want to read those data from visual studio and save as an array. 我想从visual studio读取这些数据并保存为数组。 Please anybody help me. 请有人帮助我。 It will be a big help to me. 这对我来说是一个很大的帮助。 Please

Arduino serial monitor Arduino串口监视器

在此输入图像描述

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.

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