/*public static void DisconnectIfUptimeLimitReached(int maxUpTimeMinutes) * { * lock (instance) * { * if (instance.connectedAt.HasValue && instance.reader.IsConnected) * { * if (instance.connectedAt.Value.AddMinutes(maxUpTimeMinutes) < DateTime.Now) * { * try * { * try * { * if (instance.reader.QueryStatus().IsSingulating) * { * instance.reader.Stop(); * System.Threading.Thread.Sleep(100); * } * } * catch (OctaneSdkException sdkExc) * { * Logging.Logger.Log("ERROR", "An error occurred querying reader status when recycling. " + sdkExc.Message); * } * instance.reader.KeepaliveReceived -= Reader_KeepaliveReceived1; * instance.reader.TagsReported -= instance.Reader_TagsReported; * instance.reader.Disconnect(); * instance.connectedAt = null; * Logging.Logger.Log("INFO", "RECYCLING READER CONNECTION"); * } * catch (OctaneSdkException exc) * { * Logging.Logger.Log("ERROR", "An error occurred disconnecting from reader during recycle. " + exc.Message); * } * } * } * } * }*/ public static void SpoofRandomTag() { string serialNumber = rand.Next(8000000, 11000000).ToString(); TagItem item = new TagItem { PeakRSSI = 0.0, PhaseAngle = 0.0, Epc = serialNumber, AntennaePort = 1, Firstseen = DateTime.Now.ToUniversalTime(), Lastseen = DateTime.Now.ToUniversalTime() }; bool containsKey = false; lock (instance.tagsRead) { containsKey = instance.tagsRead.ContainsKey(item.SerialNumber); if (!containsKey) { instance.tagsRead.Add(item.SerialNumber, item); } else { var temp = instance.tagsRead[item.SerialNumber]; temp.Lastseen = item.Lastseen; } } if (!containsKey) { List <TagItem> list = new List <TagItem>(); list.Add(item); Task.Run(() => { Messenger.Default.Send <List <TagItem> >(list); }); } }
private void Reader_TagsReported(ImpinjReader reader, TagReport report) { if (DateTime.UtcNow < instance.sendEventsAfter) { return; //discard events if before time delay has elapsed } foreach (var t in report.Tags.OrderBy(t => t.FirstSeenTime)) { TagItem item = new TagItem { PeakRSSI = t.PeakRssiInDbm, PhaseAngle = t.PhaseAngleInRadians, Epc = t.Epc.ToHexString(), AntennaePort = t.AntennaPortNumber, Firstseen = t.FirstSeenTime.LocalDateTime.ToUniversalTime(), Lastseen = t.LastSeenTime.LocalDateTime.ToUniversalTime() }; bool containsKey = false; lock (tagsRead) { containsKey = tagsRead.ContainsKey(item.SerialNumber); if (!containsKey) { tagsRead.Add(item.SerialNumber, item); } else { var temp = tagsRead[item.SerialNumber]; temp.Lastseen = item.Lastseen; } } if (!containsKey) { Logging.Logger.Log("RFID", "New Tags reported."); List <TagItem> list = new List <TagItem>(); list.Add(item); Task.Run(() => { Messenger.Default.Send <List <TagItem> >(list); }); } } }