Aplikacja odczytuje dane z otoczenia za pomocą anteny. Jeżeli dany obiekt zostanie wykryty ma zwiększać licznik. POmyślałem, że stworzę listę w klasie i będę tam zapisywał unikalne odczyty, a potem porównywał z nowymi i jak się pojawi coś nowego to zwiększa licznik. Jednak dzieje się tak, że jak odczytam przykładowo w pierwszym odczycie 8 obiektów to potem licznik zwiększa się co 8 do inf.
Załączam cały kod, przepraszam ale jest dosyć nieczytelny, teraz to robię i cały czas coś w nim zmieniam.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Threading;
using System.Windows.Forms;
using Symbol.RFID3;
using System.Reflection;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
int Licznik1 = 0;
int Licznik2 = 0;
int Licznik3 = 0;
int Licznik4 = 0;
public string test4;
List<string> TAB1 = new List<string>();
List<string> TAB2 = new List<string>();
List<string> TAB3 = new List<string>();
List<string> uni;
public Form1()
{
InitializeComponent();
timer1.Start();
}
private void Form1_Load(object sender, EventArgs e)
{
// 'Sprawdzenie czy w zasięgu czytnika są jakieś tagi
// rfid3.Actions.Inventory.Perform()
// Thread.Sleep(50)
// rfid3.Actions.Inventory.Stop()
// Dim areThereAnyTags() As TagData
// areThereAnyTags = rfid3.Actions.GetReadTags(1)
// lTagsInRange = (Not (areThereAnyTags Is Nothing))
}
private void timer1_Tick(object sender, EventArgs e)
{
string hostname = "172.22.50.2";
RFIDReader rfid3 = new RFIDReader(hostname, 0, 0);
rfid3.Connect();
rfid3.Actions.Inventory.Perform();
Thread.Sleep(1000);
rfid3.Actions.Inventory.Stop();
TagData[] remainingTags = rfid3.Actions.GetReadTags(200);
int rozmiar = remainingTags.Length;
int licznik = 0;
string stest = "B00";
for (int nIndex = 0; nIndex < rozmiar; nIndex++)
{
string temp;
richTextBox5.Text += "Tag nr:" + nIndex + " " + remainingTags[nIndex].TagID + " ";
temp = remainingTags[nIndex].TagID;
TAB1.Add(remainingTags[nIndex].TagID);
TAB2.Add(remainingTags[nIndex].TagID);
if (temp.Contains(stest))
{
licznik++;
}
}
List<string> distinct = TAB1.Distinct().ToList(); // podaje liczę unikalnych elementow w tablicy
List<string> uni = TAB2.Distinct().ToList();
for (int i = 0; i < uni.Count; i++)
{
TAB3.Add(uni[i]);
}
for (int j = 0; j < uni.Count; j++)
{
bool flaga = false;
string s1 = "AAA";
string s2 = "BBB";
string s3 = "CCC";
string s4 = "DDD";
string temp = distinct[j];
if (temp[0] == 'A' && temp[1] == 'A' && temp[2] == 'A')
{
Licznik1++;
}
else if (temp[0] == 'B' && temp[1] == 'B' && temp[2] == 'B')
{
Licznik2++;
}
else if (temp[0] == 'C' && temp[1] == 'C' && temp[2] == 'C')
{
Licznik3++;
}
else if (temp[0] == 'D' && temp[1] == 'D' && temp[2] == 'D')
{
for (int i = 0; i < uni.Count; i++)
{
if (uni[j] == TAB3[i])
{
flaga = true;
}
}
if (flaga == false)
{
Licznik4++;
}
}
}
int l_el1 = Licznik1;
string test1 = l_el1.ToString();
richTextBox1.Text = test1;
int l_el2 = Licznik2;
string test2 = l_el2.ToString();
richTextBox2.Text = test2;
int l_el3 = Licznik3;
string test3 = l_el3.ToString();
richTextBox3.Text = test3;
int l_el4 = Licznik4;
test4 = l_el4.ToString();
richTextBox4.Text = test4;
Thread.Sleep(300);
//TagData[] areThereAnyTags = rfid3.Actions.GetReadTags(2000);
rfid3.Disconnect();
timer1.Start();
}
// }
}
}
usunięcie sporej ilości pustych linii z kodu - fp