[ 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. 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? Is there any way to do it?
This is my code to get data from IP:
The downloadedString
will accept "+:0"
if the machine send the first data.
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;
}
}
Answer 1
You can use a 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.