[英]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.