[英]Store Multiple Temporary Data in c# Arduino
I am new in c#, I have a form that receive "+:0" from some machine by ethernet in LAN using arduino, the "0" will increase if the same machine send "+" again. 我是C#的新手,我有一种使用arduino通过局域网通过局域网从某台计算机接收“ +:0”的表格,如果同一台计算机再次发送“ +”,则“ 0”将增加。 Each pc will randomly send "+" to the form.
每台电脑将随机发送“ +”到表格。 the problem is, if the machine A has reached "+:5" and the machine B has just started to send the data("+:0"), how do I store the temporary data (not stored to database, just in c#) for machine A to proccess the machine B until the machine A is called back again?
问题是,如果机器A已达到“ +:5”并且机器B刚刚开始发送数据(“ +:0”),我该如何存储临时数据(不存储到数据库,仅在c#中) ),以使机器A处理机器B,直到再次调用机器A? Is there any way to do it?
有什么办法吗?
This is my code to get data from IP: 这是我从IP获取数据的代码:
The downloadedString
will accept "+:0"
if the machine send the first data. 如果机器发送第一个数据,则
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;
}
}
You can use a Dictionary<string, List<string>>
. 您可以使用
Dictionary<string, List<string>>
。 In your Dictionary
the key string should be the ip in ipAddress
variable and List<string>
are all data send by Arduino for the specific ip. 在您的
Dictionary
,键字符串应该是ipAddress
变量中的ip,而List<string>
都是Arduino针对特定ip发送的数据。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.