none
How to save my RFID Fixed reader log into sqlserver RRS feed

  • Question

  • Hello I am looking to save my Reader Log into the sql server. whenever a RFID tag detected through fixed reader i am getting a notification.

    I had a notification textbox  in the application. It display every tag detection and is going to be updated  every minute , whenever a new tag detected  for ex as given below:

    i had my textbox to display all notification : txtNotifications 

    Tag:0042 3000 0000 0000 0000 0000, Disc:2012/10/16 21:42:27.364, Last:2012/10/16 21:57:10.243, Count:537, Ant:0, Proto:2

    Tag:0043 3000 0000 0000 0000 0000, Disc:2012/10/16 21:42:28.364, Last:2012/10/16 21:58:10.243, Count:537, Ant:0, Proto:2

    Tag:0044 3000 0000 0000 0000 0000, Disc:2012/10/16 21:42:29.364, Last:2012/10/16 21:59:10.243, Count:537, Ant:0Proto:2

    every time whenever a new tag detected i need to insert into my sqlserver table ( Tagno,Time)

    tagno is : for the last log  00443, Time : 2012/10/16 21:42:29. 

    If the same tag detected in 10min , it should not be saved.

    Please help me out in this as i am looking for the solution from long time.

    Thanks in advance....


    • Edited by Kris_sp2013 Friday, October 26, 2012 5:31 PM
    Friday, October 26, 2012 5:29 PM

Answers

  • Hi Subhash-KPCL,

    When you get a item of data(e.g.Tag:0042 3000 0000 0000 0000 0000, Disc:2012/10/16 21:42:27.364, Last:2012/10/16 21:57:10.243, Count:537, Ant:0, Proto:2)You should :

    1. Split string on Tag, use String.Substring() to get the right format of the tagno and time.
    2. Compare the tagno with the former one, if same, turn  to step3, else insert into DB.
    3. Compare the time  with the former one , if time interval >10min,  insert this item of data into DB.Here, you can use  DateTime.Subtract() to calculate the time interval.

     In order to remember the former tagno and time, please define two variables.

     I have a simple code sample, hope this helps:

       //Assuming that we know the former insert data
            String tagno = "00433";
            DateTime time = new DateTime(2012, 10, 16, 21, 42, 28);
            private void button2_Click(object sender, EventArgs e)
            {
              
              string data = "Tag:0043 3000 0000 0000 0000 0000,Disc:2012/10/16 22:52:29.364,Last:2012/10/16 21:59:10.243,Count:537,Ant:0Proto:2";//the latest data
              string[] tagData = data.Split(',');
              string newTagno = tagData[0].Substring(4, 6).Replace(" ", "");//get the right format of the new tagno
              if (newTagno == tagno)
              {
                  DateTime NewTime = Convert.ToDateTime(tagData[1].Substring(5, 19));
                  TimeSpan tspan = NewTime.Subtract(time); //get time interval
                  int timeInterval = tspan.Hours * 60 + tspan.Minutes;
                  if (timeInterval > 10)
                  {
                      MessageBox.Show("Please insert");
                      // insert data
                      ...
                      // don't forget to update the tagno and time
                      tagno = newTagno;
                      time = NewTime;
                  }
              }
              else
              {
                  //insert data
                  ...
              }
      
            }

    Regards,


    Lisa Zhu [MSFT]
    MSDN Community Support | Feedback to us

    Monday, October 29, 2012 8:54 AM
    Moderator

All replies

  • Maybe you can create a Windows Service and use System.Timers.Timer to cope with that period of time.

    我的博客园
    慈善点击,点击此处
    和谐拯救危机,全集下载,净化人心

    Saturday, October 27, 2012 3:50 AM
  • First you would need to get your text string broken out into parts to grab you tag and time:

    string tagData = "Tag:0043 000 ... ";
    string[] parts = tagData.Split(',');
    

    Then you need to take those two fields and get them inserted into your database table.

    private void InsertInfo()
    {
    
           SqlConnection conn = new SqlConnection(GetConnectionString());
    
           string sql = "INSERT INTO TagTable(TagNo, Date) VALUES (@Val1,@Val2)";
    
           try
           {
               conn.Open();
               SqlCommand cmd = new SqlCommand(sql, conn);
               cmd.Parameters.AddWithValue("@Val1", parts[0]);
               cmd.Parameters.AddWithValue("@Val2", parts[2]);
               cmd.CommandType = CommandType.Text;
               cmd.ExecuteNonQuery();
    
           }
           catch (System.Data.SqlClient.SqlException ex)
           {
               string msg = "Insert Error:";
               msg += ex.Message;
               throw new Exception(msg);
    
           }
           finally
           {
               conn.Close();
           }
    }


    Saturday, October 27, 2012 4:25 AM
  • Biztalk Server has a RFID extension:

    http://msdn.microsoft.com/en-us/biztalk/dd409102.aspx

    Roar Jørstad aka sveroa
    Senior Consultant, EVRY as
    Blog: Notebook, trick & tips
    Please mark as answer or helpful if my post is useful

    Saturday, October 27, 2012 8:29 AM
  • i will get  more than 20 records in a span of 3minutes time. So how can i insert all the rows of data.

    My code as follows :


    private void displayText(String data)  // here i will get each tagno as string.
    {
    try
    {
    if (this.InvokeRequired)
    {
    object[] temp = {data};
    this.Invoke(new displayMessageDlgt(displayText),temp);
    return;
    }
    else
    {
    txtNotifications.Text += data.Replace("\0","") + "\r\n";  //list of all tags 

    NotifyInfo ni = null;
    AlienUtils.ParseNotification(data, out ni);
    if (ni != null)
    {
    lblReaderName.Text = ni.ReaderName;
    }
    }
    }
    catch(Exception ex)
    {
    Debug.WriteLine("Exception in the DiscplayText(): " + ex.Message);
    }
    }

    Pls advice..


    Subhash

    Saturday, October 27, 2012 9:38 AM
  • Hi Subhash-KPCL,

    When you get a item of data(e.g.Tag:0042 3000 0000 0000 0000 0000, Disc:2012/10/16 21:42:27.364, Last:2012/10/16 21:57:10.243, Count:537, Ant:0, Proto:2)You should :

    1. Split string on Tag, use String.Substring() to get the right format of the tagno and time.
    2. Compare the tagno with the former one, if same, turn  to step3, else insert into DB.
    3. Compare the time  with the former one , if time interval >10min,  insert this item of data into DB.Here, you can use  DateTime.Subtract() to calculate the time interval.

     In order to remember the former tagno and time, please define two variables.

     I have a simple code sample, hope this helps:

       //Assuming that we know the former insert data
            String tagno = "00433";
            DateTime time = new DateTime(2012, 10, 16, 21, 42, 28);
            private void button2_Click(object sender, EventArgs e)
            {
              
              string data = "Tag:0043 3000 0000 0000 0000 0000,Disc:2012/10/16 22:52:29.364,Last:2012/10/16 21:59:10.243,Count:537,Ant:0Proto:2";//the latest data
              string[] tagData = data.Split(',');
              string newTagno = tagData[0].Substring(4, 6).Replace(" ", "");//get the right format of the new tagno
              if (newTagno == tagno)
              {
                  DateTime NewTime = Convert.ToDateTime(tagData[1].Substring(5, 19));
                  TimeSpan tspan = NewTime.Subtract(time); //get time interval
                  int timeInterval = tspan.Hours * 60 + tspan.Minutes;
                  if (timeInterval > 10)
                  {
                      MessageBox.Show("Please insert");
                      // insert data
                      ...
                      // don't forget to update the tagno and time
                      tagno = newTagno;
                      time = NewTime;
                  }
              }
              else
              {
                  //insert data
                  ...
              }
      
            }

    Regards,


    Lisa Zhu [MSFT]
    MSDN Community Support | Feedback to us

    Monday, October 29, 2012 8:54 AM
    Moderator