Exemplo n.º 1
0
 /// <summary>
 /// Write Untraceable operation to tag
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void btmWriteToTag_Click(object sender, RoutedEventArgs e)
 {
     try
     {
         if (((bool)rdBtnShowSpecificEpc.IsChecked) && (txtbxEpcLen.Text == ""))
         {
             MessageBox.Show("Please Enter length of EPC to Show", "Universal Reader Assistant Message", MessageBoxButton.OK, MessageBoxImage.Warning);
             return;
         }
         else
         {
             epcLen = 6;
         }
         antenna = ((null != GetSelectedAntennaList()) ? (GetSelectedAntennaList()[0]) : antenna);
         objReader.ParamSet("/reader/tagop/antenna", antenna);
         if ((bool)rdBtnShowSpecificEpc.IsChecked)
         {
             epcLen = Convert.ToInt32(txtbxEpcLen.Text);
         }
         Gen2.Password    accessPassWord = new Gen2.Password(ByteConv.ToU32(ByteFormat.FromHex(txtbxAccesspaasword.Text.Replace(" ", "")), 0));
         Gen2.Untraceable tagOp          = new Gen2.NXP.AES.Untraceable(epc, epcLen, tid, user, range, accessPassWord.Value);
         objReader.ExecuteTagOp(tagOp, searchSelect);
         MessageBox.Show("Write operation is successfull", "Universal Reader Assistant Message", MessageBoxButton.OK, MessageBoxImage.Information);
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
     }
 }
        public uint?ReadTagSync()
        {
            var action = new Action <Exception>(exception =>
            {
                var error = "Error reading tags. " + exception.Message;
                MessageBox.Show(error, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                Trace.TraceError(error + exception.StackTrace);
            });

            uint?tag = null;

            try
            {
                CheckParams();

                // Create a simplereadplan which uses the antenna list created above
                SimpleReadPlan plan = new SimpleReadPlan(new[] { 1 }, TagProtocol.GEN2, null, null, 1000);
                // Set the created readplan
                _reader.ParamSet("/reader/read/plan", plan);

                // Create and add tag listener
                _reader.TagRead += delegate(Object sender, TagReadDataEventArgs e)
                {
                    var data = e.TagReadData;

                    tag = ByteConv.ToU32(data.Epc, 0);
                    Trace.TraceInformation("Tag " + tag + " has been read.");
                };

                // Create and add read exception listener
                _reader.ReadException += delegate(object sender, ReaderExceptionEventArgs reea)
                {
                    if (reea.ReaderException != null)
                    {
                        action(reea.ReaderException);
                    }
                };

                // Search for tags in the background
                _reader.StartReading();

                do
                {
                    Thread.Sleep(200);

                    // do events
                    Application.Current.Dispatcher.Invoke(() => { });
                } while (!tag.HasValue || _cancelReading);

                _reader.StopReading();
                _cancelReading = false;
            }
            catch (Exception exception)
            {
                action(exception);
            }

            return(tag);
        }
Exemplo n.º 3
0
 /// <summary>
 /// getUTCTimestamp - retrieves the UTC timestamp from the response
 /// </summary>
 public UInt32 getUTCTimestamp(byte[] response, int readIndex, int uidLen)
 {
     if (uidLen > 0)
     {
         readIndex = uidLen + 2 + 4; // exclude uidLength(2 bytes), uidBits(uidLen bytes) and sensorData(4 bytes)
     }
     else
     {
         readIndex = 4; //exclude sensor data
     }
     // Extract utc timestamp(4 bytes)
     byte[] utcTimeArray = new byte[4];
     Array.Copy(response, readIndex, utcTimeArray, 0, 4);
     return(ByteConv.ToU32(utcTimeArray, 0));;
 }
        /// <summary>
        /// Apply lock action on the tag
        /// </summary>
        public bool ApplyLockAction(Gen2.LockAction action, string accessPassword)
        {
            try
            {
                _reader.ParamSet("/reader/tagop/protocol", TagProtocol.GEN2);

                _reader.ExecuteTagOp(new Gen2.Lock(ByteConv.ToU32(
                                                       ByteFormat.FromHex(accessPassword.Replace(" ", "")), 0), action), null);
                return(true);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                return(false);
            }
        }
Exemplo n.º 5
0
            /// <summary>
            /// getSensorData - retrieves the sensor data from the response
            /// </summary>
            public SensorData getSensorData(byte[] response, int readIndex, int uidLen)
            {
                // Extract sensor data(4 bytes)
                byte[] sensorDataArray = new byte[4];
                if (uidLen > 0)
                {
                    readIndex = uidLen + 2;// exclude uidLength(2 bytes) and uid bits(uidLen bytes)
                }
                else
                {
                    readIndex = 0;
                }
                Array.Copy(response, readIndex, sensorDataArray, 0, 4);
                UInt32 sData = ByteConv.ToU32(sensorDataArray, 0);

                return(new SensorData(sData));
            }
        public bool CheckEpcIsLocked(string accessPassword)
        {
            try
            {
                _reader.ParamSet("/reader/tagop/protocol", TagProtocol.GEN2);

                _reader.ExecuteTagOp(new Gen2.Lock(ByteConv.ToU32(
                                                       ByteFormat.FromHex(accessPassword.Replace(" ", "")), 0), new Gen2.LockAction(Gen2.LockAction.EPC_UNLOCK)), null);
                return(false);
            }
            catch (Exception ex)
            {
                if (ex is FAULT_GEN2_PROTOCOL_MEMORY_LOCKED_Exception)
                {
                    return(true);
                }
                Trace.TraceError("Error checking EPC. " + ex.Message + ex.StackTrace);
                return(false);
            }
        }
 // seems like the wrong method
 private uint?ReadTag(int timeout)
 {
     try
     {
         CheckParams();
         var data = _reader.Read(timeout);
         if (data.Length > 0)
         {
             var tag = ByteConv.ToU32(data[0].Epc, 0);
             Trace.TraceInformation("Tag " + tag + " has been read.");
             return(tag);
         }
         return(null);
     }
     catch (Exception exception)
     {
         var error = "Error reading tags. " + exception.Message;
         MessageBox.Show(error, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
         Trace.TraceError(error + exception.StackTrace);
         return(null);
     }
 }
Exemplo n.º 8
0
 public void Kill()
 {
     try
     {
         DateTime timeBeforeRead = DateTime.Now;
         using (Reader reader = Reader.Create("tmr:///" + Vars.comport.ToLower()))
         {
             reader.Connect();
             uint           killPassword = ByteConv.ToU32(ByteFormat.FromHex(textBox3.Text), 0);
             TagOp          tagOp        = new Gen2.Kill(killPassword);
             SimpleReadPlan plan         = new SimpleReadPlan(null, TagProtocol.GEN2, null, tagOp, 1000);
             reader.ParamSet("/reader/read/plan", plan);
             reader.ExecuteTagOp(tagOp, tagData);
         }
         DateTime timeAfterRead = DateTime.Now;
         TimeSpan timeElapsed   = timeAfterRead - timeBeforeRead;
         commandTotalTimeTextBox.Text = timeElapsed.TotalSeconds.ToString();
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
 }