Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8601321
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T01:48:53+00:00 2026-06-12T01:48:53+00:00

static void barreader_method() { barreader.OpenPort(barport, 19200); //opens the port connected to the rfid reader

  • 0
static void barreader_method()
{
   barreader.OpenPort(barport, 19200); //opens the port connected to the rfid reader
   byte TagType; //tag type
   byte[] TagSerial = new byte[4]; //tag serial in reverse order
   byte ReturnCode = 0; //return code sent from the rfid reader
   string bartagno; //tag no as a string

   while (true)
   {
      bartagno = "";
      while (!barreader.CMD_SelectTag(out TagType, out TagSerial, out ReturnCode)) /*wait until a tag is present in the rf field, if present return the tag number.*/
      {
      }
      for (int i = 0; i < 4; i++)
      {
         bartagno += TagSerial[i].ToString("X2");
      }
      barprocess(bartagno); //barprocess method
      Thread.Sleep(1200); //this is to prevent multiple reads
   }
}

If the bartagno variable gets the same value within a minute, i don’t want to execute the barprocess method but to continue the infinite loop. Otherwise barprocess method will be executed. How can i achieve this? I don’t even know where to start. I tried different datetime, loop combinations with no success.

———————————————————progress added below———————————————–

Multiple cards can be read within a minute, so comparing only with the previous one won’t help unfortunately. I tried to use an arraylist instead building on Kelly Ethridge’s answer (thanks). But if we get readings once every ten seconds for example, this will be useless. We still have to delete items older than 1 minute.

static void barreader_method()
{
    barreader.OpenPort(barport, 19200);
    byte TagType;
    byte[] TagSerial = new byte[4];
    byte ReturnCode = 0;
    string bartagno;
    ArrayList previoustagnos = new ArrayList();
    DateTime lastreaddt = DateTime.MinValue;

    while (true)
    {
        bartagno = "";
        while (!barreader.CMD_SelectTag(out TagType, out TagSerial, out ReturnCode))
        {
        }
        for (int i = 0; i < 4; i++)
        {
            bartagno += TagSerial[i].ToString("X2");
        }
        if (DateTime.Now - lastreaddt > TimeSpan.FromMinutes(1))
        {
            previoustagnos.Clear();
            barprocess(bartagno);
            previoustagnos.Add(bartagno);
            lastreaddt = DateTime.Now;
        }
        else
        {
            previoustagnos.Sort();
            if (previoustagnos.BinarySearch(bartagno) < 0)
            {
                barprocess(bartagno);
                previoustagnos.Add(bartagno);
                lastreaddt = DateTime.Now;
            }
        }
        Thread.Sleep(1200);
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T01:48:55+00:00Added an answer on June 12, 2026 at 1:48 am
    static void barreader_method()
    {
        barreader.OpenPort(barport, 19200);
        byte TagType;
        byte[] TagSerial = new byte[4];
        byte ReturnCode = 0;
        string bartagno;
        List<Tuple<DateTime, String>> previoustags = new List<Tuple<DateTime, String>>();
        DateTime lastreaddt = DateTime.MinValue;
    
        while (true)
        {
            bartagno = "";
            while (!barreader.CMD_SelectTag(out TagType, out TagSerial, out ReturnCode))
            {
            }
            for (int i = 0; i < 4; i++)
            {
                bartagno += TagSerial[i].ToString("X2");
            }
            if (DateTime.Now - lastreaddt > TimeSpan.FromMinutes(1))
            {
                previoustags.Clear();
                barprocess(bartagno);
                previoustags.Add(Tuple.Create(DateTime.Now, bartagno));
                lastreaddt = DateTime.Now;
            }
            else
            {
                if (!previoustags.Exists(a => a.Item2.Equals(bartagno)))
                {
                    barprocess(bartagno);
                    previoustags.Add(Tuple.Create(DateTime.Now, bartagno));
                    lastreaddt = DateTime.Now;
                }
            }
            previoustags.RemoveAll(a => a.Item1.CompareTo(DateTime.Now - TimeSpan.FromMinutes(1)) < 0);
            Thread.Sleep(1200);
        }
    }
    

    Thanks a lot Dan and Kelly. Without your help, i wouldn’t be able to solve this.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

static void testlock() { for(int i=0;i<10000000;i++) { float f=2.0/i; } } static void TEST()
static void Main() { string str; str = Console.ReadLine(); while (str != null)//HERE! {
static void Main(string[] args) { //read in the file StreamReader convert = new StreamReader(../../convert.txt);
static void main(args){ System.in.withReader { def input = it.readLine() for(def i = 0; i
public static void main(String[] args) { int i = 0; while(i==0){ System.out.println(Possibilities: R, T,
public static void main(String[] args) { // TODO Auto-generated method stub BufferedReader br1 =
public static void main(String Data[]) { ConnectionPoolDataSource dps; try { cnt=new InitialContext(); cnt.rebind(java:comp/env/jdbc/pool/dragon, dps);
Code static void MyClass::ThreadEntryStatic() { //... } void MyClass::Begin() { CreateThread(..,ThreadEntryStatic,..); } In which
public static void MyFunction(MyErrorClass err) { var query = from filter in DataContext.ErrorFilters select
public static void fillCheckList(string ListType,int RecordNum,CheckBox chkRequired,TextBox txtComplete,TextBox txtMemo) { string sql_Check = String.Format(@SELECT

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.