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

时间:2016-10-08 19:04:27

标签: c# visual-studio visual-studio-2012 arduino-uno

我在arduino串行监视器上获取以下数据。我想从visual studio读取这些数据并保存为数组。请有人帮助我。这对我来说是一个很大的帮助。请

Arduino串口监视器

enter image description here

1 个答案:

答案 0 :(得分:0)

我要承担winforms。如果没有,那么这将不会有所帮助。

首先,从工具箱中向表单添加一个串行端口。然后做这样的事情将数据放入数组:

            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' });