繁体   English   中英

在c#Arduino中存储多个临时数据

[英]Store Multiple Temporary Data in c# Arduino

我是C#的新手,我有一种使用arduino通过局域网通过局域网从某台计算机接收“ +:0”的表格,如果同一台计算机再次发送“ +”,则“ 0”将增加。 每台电脑将随机发送“ +”到表格。 问题是,如果机器A已达到“ +:5”并且机器B刚刚开始发送数据(“ +:0”),我该如何存储临时数据(不存储到数据库,仅在c#中) ),以使机器A处理机器B,直到再次调用机器A? 有什么办法吗?

这是我从IP获取数据的代码:

如果机器发送第一个数据,则downloadedString将接受"+:0"

 public AndonForm()
 {
        InitializeComponent();

        _timer.Interval = (500) * (1); 
        _timer.Enabled = true;        
        _timer.Start();
        _timer.Tick += (timerTick); 
  }


    private void timerTick(object sender, EventArgs e)
    {
        GetDataFromArduino("http://192.168.1.200/");
        GetDataFromArduino("http://192.168.1.12/");
        GetDataFromArduino("http://192.168.1.166/");
        GetDataFromArduino("http://192.168.1.6/");
    }

    private void GetDataFromArduino(string ipAddress)
    {
        WebClient client = new WebClient();
        String downloadedString = client.DownloadString(ipAddress);

        if (downloadedString.Contains("SPP"))
        {
            downloadedString = downloadedString.Split(new[] { "<html>\r\n" }, StringSplitOptions.None)[1];

            tempDownloadString = downloadedString.Substring(0, downloadedString.IndexOf(":"));

            tempCount = downloadedString.Split(new[] { ":" }, StringSplitOptions.None)[1];

        }
        else if (downloadedString.Contains("NPK"))
        {
            downloadedString = downloadedString.Split(new[] {"<html>\r\n"}, StringSplitOptions.None)[1];

            tempDownloadString = downloadedString.Substring(0, downloadedString.IndexOf(":"));

            tempCount = downloadedString.Split(new[] { ":" }, StringSplitOptions.None)[1];

            tempCount = tempCount.Substring(0, tempCount.IndexOf("<"));
        }
        else
        {
            downloadedString = downloadedString.Split(new[] {"<html>\r\n"}, StringSplitOptions.None)[1];

            tempDownloadString = downloadedString.Substring(0, downloadedString.IndexOf(":"));


            tempCount = downloadedString.Split(new[] {":"}, StringSplitOptions.None)[1];

            tempCount = tempCount.Substring(0, tempCount.IndexOf("<"));

        }

        if (SPP != null && NPK == null)
        {
            finalDownloadString = tempDownloadString;
            si_DataReceived(tempDownloadString);
            x = tempCount;
        }
        else if (SPP != null && NPK !=null)
        {

            if (x != tempCount || tempDownloadString != finalDownloadString)
            {
                si_DataReceived(tempDownloadString);
                finalDownloadString = tempDownloadString;
                x = tempCount;
            }
        }
        else
        {
            finalDownloadString = tempDownloadString;
            si_DataReceived(tempDownloadString);
            x = tempCount;  
        }
    }

您可以使用Dictionary<string, List<string>> 在您的Dictionary ,键字符串应该是ipAddress变量中的ip,而List<string>都是Arduino针对特定ip发送的数据。

暂无
暂无

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

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