简体   繁体   English

在VS中从arduino接收字符串,如何将其存储在csv或xls文件中?

[英]Receiving strings from arduino in VS, how do I store them in a csv or xls file?

So I'm reading strings from my arduino via serialPort, using C#. 因此,我正在使用C#通过serialPort从arduino中读取字符串。 The strings show in a text box when I do the supposed action. 当我执行假定的操作时,字符串将显示在文本框中。 What I need to do now is to put them in an array and store them at a csv or xls file. 我现在需要做的是将它们放置在数组中,并将它们存储在csv或xls文件中。

    private void btRecOn_Click(object sender, EventArgs e)
    {
        if (serialPort1.IsOpen == true)             // COMport is open                
            Text = recon;             // string recon = "recording on"
            serialPort1.Write(Text);  // sends text "recording on" to arduino
    }

    private void SerialPort1_DataReceived(object sender, SerialDataReceivedEventArgs e)
    {
        RxString = serialPort1.ReadExisting();            // reads data from serial port
        this.Invoke(new EventHandler(trataDadoRecebido)); // calls another thread to write data in text
    }   

    private void trataDadoRecebido(object sender, EventArgs e)
    {
        textBoxReceber.AppendText(RxString);         
    }

当我与arduino交流时,它会如何显示

My objective is to press the "save" button and those strings be saved in different lines of a csv or xls file. 我的目标是按下“保存”按钮,然后将这些字符串保存在csv或xls文件的不同行中。 I already tried through interop, but it gets messy! 我已经尝试过互操作,但是会变得混乱! What is the best way in your opinion? 您认为最好的方法是什么?

Could you give me some help or tips? 您能给我些帮助或提示吗?

Thanks in advance. 提前致谢。

My suggestion would be to change the textbox into a listbox. 我的建议是将文本框更改为列表框。 In that way you got separate string items which you can write to a file. 这样,您获得了可以写入文件的单独的字符串项目。

Another advantage of using a listbox will be that you can make a selection of items that you want to write into a file. 使用列表框的另一个优点是,您可以选择要写入文件的项目。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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