Inheritance: MonoBehaviour
 public void Should_run_tag_inventory_with_default_params()
 {
     using (var r = new SerialReader(TestSettings.Instance.GetConnection()))
     {
         r.TagInventory().Wait();
     }
 }
Exemple #2
0
        public static Reader ConnectReader(string port)
        {
            Reader objReader = null;

            try
            {
                logger.Info("Starting ConnectReader(" + port + ")...");

                objReader = new SerialReader(@"/" + port);
                logger.Info("Created new SerialReader(" + @"/" + port + ")");

                logger.Info("Set baud rate to 9600");

                objReader.Connect();

                string _readerPortName = port;
                logger.Info("Connected to SerialReader on " + port);
                objReader.Transport += new EventHandler <TransportListenerEventArgs>(objReader_Transport);
            }
            catch (Exception ex)
            {
                logger.Error("In ConnectReader(" + port + "): " + ex.ToString());

                objReader = null;
            }
            return(objReader);
        }
Exemple #3
0
        public static XMBFile Load(Stream cmpStream)
        {
            var    newStream = DecompressAndSkipHeader(cmpStream);
            string data      = new StreamReader(newStream).ReadToEnd();
            var    xmb       = new XMBFile();

            if (data.Trim().StartsWith("<"))
            {
                xmb.document = XDocument.Parse(data);
            }
            else
            {
                newStream.Position = 0;
                var      b0         = newStream.ReadByte();
                var      b1         = newStream.ReadByte();
                XElement root       = new XElement("tmp");
                var      reader     = new BinaryReader(newStream);
                var      serializer = new SerialReader(reader);
                Serialize(root, serializer);

                /*char[] header = new char[2];
                 * reader.Read(header, 0, 2);
                 * Debug.Assert(header[0] == 'X' && header[1] == '1');
                 * byte[] buffer = new byte[1024];
                 * reader.Read(buffer, 0, 14);
                 *
                 * var elements = ReadStringArray(reader);
                 * var parameters = ReadStringArray(reader);
                 *
                 * XElement root = ReadElement(reader, elements, parameters);*/

                xmb.document = new XDocument(root);
            }
            return(xmb);
        }
Exemple #4
0
        public SerialDataViewModel(IEventAggregator eventAggregator)
        {
            _eventAggregator = eventAggregator;
            _eventAggregator.Subscribe(this);

            _serialReader = new SerialReader();
        }
        /// <summary>
        /// Full access contructor
        /// </summary>
        /// <param name="ComPortName"></param>
        /// <param name="ComBaudrate">Should be 115200. Other rates supported and listed in Mercury Docs</param>
        /// <param name="ReadOnTime">How long in milliseconds the reader is on before being turned off for ReadOffTime</param>
        /// <param name="ReadOffTime">How long in milliseconds the reader is off before being turned back on for ReadOnTime</param>
        /// <param name="ReadPower">Power in centi-dBm sent to the antennae. The max value is 3000 and should probably always be set to max</param>
        /// <param name="ReadTime">Total time the reader reads for when ReadTags() is called in milliseconds. If this value is more than
        ///                        60000 you begin to risk throttling due to overheating</param>
        public M6eMicroRFID(string ComPortName, int ComBaudrate, int ReadOnTime, int ReadOffTime, int ReadPower, int ReadTime)
        {
            SerialPort = new SerialPort(ComPortName, ComBaudrate);
            BaseReader = Reader.Create("eapi:///" + SerialPort.PortName);
            RFIDReader = (SerialReader)BaseReader;
            IsReading  = false;

            BaseReader.Connect();

            READER_ASYNC_ON_TIME  = ReadOnTime;
            READER_ASYNC_OFF_TIME = ReadOffTime;
            READER_READ_POWER     = ReadPower;
            READER_READ_TIME      = ReadTime;

            RFIDReader.ParamSet("/reader/region/id", Reader.Region.OPEN);           //Open Region
            RFIDReader.ParamSet("/reader/gen2/q", new Gen2.DynamicQ());             //This determines how many internal tag "slots" the reader is looking to fill
            RFIDReader.ParamSet("/reader/gen2/BLF", Gen2.LinkFrequency.LINK250KHZ); //Rate at which the tags signal back to the reader
            RFIDReader.ParamSet("/reader/gen2/tari", Gen2.Tari.TARI_6_25US);        //Controls how long it takes a tag to reader to send a communication
            RFIDReader.ParamSet("/reader/gen2/session", Gen2.Session.S1);           //Controls how often tags respond to inventory rounds
            RFIDReader.ParamSet("/reader/gen2/tagEncoding", Gen2.TagEncoding.M8);   //Controls how many times a signal is repeated so that far away tags still get the message.
            RFIDReader.ParamSet("/reader/gen2/target", Gen2.Target.A);              //This controls what order tags are read in. State A are tags which have not been read. State B are tags which have been read.
            RFIDReader.ParamSet("/reader/radio/readPower", READER_READ_POWER);
            RFIDReader.ParamSet("/reader/read/asyncOnTime", READER_ASYNC_ON_TIME);
            RFIDReader.ParamSet("/reader/read/asyncOffTime", READER_ASYNC_OFF_TIME);
            RFIDReader.ParamSet("/reader/read/plan", new SimpleReadPlan(new int[] { 1, 2, 3, 4 }, TagProtocol.GEN2));
        }
        public void Should_run_inventory_with_buffer_and_get_response(ConnectionType connectionType)
        {
            using (var r = new SerialReader(TestSettings.Instance.GetConnection(connectionType)))
            {
                var totalTagsBuffered = 0;
                var lastInventoryAgg  = 0;
                new Timing()
                .Context("Failed to read 50 tags")
                .Expect(() =>
                {
                    var res           = r.TagInventoryWithMemoryBuffer().Result;
                    totalTagsBuffered = res.TagsInBuffer;
                    lastInventoryAgg += res.TagsInLastInventory;
                    return(lastInventoryAgg > 50);
                });
                lastInventoryAgg.Should().BeGreaterThan(50);
                totalTagsBuffered.Should().BeInRange(1, 100);

                r.GetNumberOfTagsInBuffer().Result.Should().Be(totalTagsBuffered);
                var tagInBuffer = r.GetTagsFromBuffer().Result;
                tagInBuffer.Tags.Count.Should().Be(totalTagsBuffered);
                tagInBuffer.Tags.Select(x => x.TagId)
                .Intersect(TestSettings.Instance.GetKnownTagIds)
                .Count()
                .Should().BeGreaterOrEqualTo(1,
                                             $"Should find at least one tag from known tags list. " +
                                             $"Actually found: {string.Join(", ", tagInBuffer.Tags.Select(x => x.TagId))}");
                tagInBuffer.Tags[0].Antenna.Should().Be(0);
                tagInBuffer.Tags[0].Rssi.Should().BeGreaterThan(0);
                tagInBuffer.Tags[0].LastSeenTime.Should().BeAfter(DateTime.UtcNow.Date);
                tagInBuffer.Tags[0].DiscoveryTime.Should().BeAfter(DateTime.UtcNow.Date);
            }
        }
Exemple #7
0
 private void CloseReader()
 {
     if (null == rdr)
     {
         PrintLn("Reader already closed");
     }
     else
     {
         PrintLn("Closing reader...");
         string portName = Utilities.ReaderPortName;
         try
         {
             rdr.Destroy();
         }
         catch (Exception ex)
         {
             PrintLn("Caught Exception closing reader: " + ex);
         }
         finally
         {
             rdr = null;
         }
         PrintLn("Closed reader on serial port " + portName);
     }
 }
 public void Should_clear_buffer()
 {
     using (var r = new SerialReader(TestSettings.Instance.GetConnection()))
     {
         r.ClearBuffer().Wait();
     }
 }
 public void Should_not_allow_to_change_baud_on_network_reader(ConnectionType connectionType)
 {
     using (var r = new SerialReader(TestSettings.Instance.GetConnection(connectionType)))
     {
         Assert.ThrowsAsync <InvalidOperationException>(() => r.SetSerialBaudRate(BaudRates.Baud115200)).Wait();
     }
 }
        public void LoadPorts()
        {
            IEnumerable <string> ports    = SerialReader.GetAvailablePorts();
            List <string>        toChange = new List <string>();

            //Search not non-existent
            foreach (var port in ComPorts)
            {
                if (!ports.Contains(port))
                {
                    toChange.Add(port);
                }
            }
            //Delete not non-existent
            ComPorts.RemoveRange(toChange);
            toChange.Clear();
            //Search New
            foreach (var port in ports)
            {
                if (!ComPorts.Contains(port))
                {
                    toChange.Add(port);
                }
            }
            //Add New
            ComPorts.AddRange(toChange);
            //Select One if needed
            if (SelectedComPort == null || !ComPorts.Contains(SelectedComPort))
            {
                SelectedComPort = ComPorts.FirstOrDefault();
            }
        }
 public void Should_get_number_of_tags_in_buffer()
 {
     using (var r = new SerialReader(TestSettings.Instance.GetConnection()))
     {
         r.GetNumberOfTagsInBuffer().Wait();
     }
 }
        /// <summary>
        /// Serial Reader factory function
        /// </summary>
        /// <param name="uriString">URI-style path to serial device; e.g., /COM1</param>
        public static SerialReader CreateSerialReader(String uriString)
        {
            SerialReader rdr = new SerialReader(uriString,
                                                new SerialTransportTCP());

            return(rdr);
        }
 public void Should_run_inventory_with_buffer()
 {
     using (var r = new SerialReader(TestSettings.Instance.GetConnection()))
     {
         r.TagInventoryWithMemoryBuffer().Wait();
     }
 }
Exemple #14
0
 public void Should_set_inventory_scan_interval()
 {
     using var r = new SerialReader(TestSettings.Instance.GetConnection());
     r.SetInventoryScanInterval(TimeSpan.FromMilliseconds(1000)).Wait();
     r.GetReaderInfo().Result.InventoryScanInterval.Should().Be(TimeSpan.FromMilliseconds(1000));
     r.SetInventoryScanInterval(TimeSpan.FromMilliseconds(300)).Wait();
     r.GetReaderInfo().Result.InventoryScanInterval.Should().Be(TimeSpan.FromMilliseconds(300));
 }
Exemple #15
0
 public void Should_read_and_write_drm_mode(ConnectionType connectionType)
 {
     using var r = new SerialReader(TestSettings.Instance.GetConnection(connectionType));
     r.SetDrmEnabled(true).Result.Should().Be(DrmMode.On);
     r.GetDrmEnabled().Result.Should().Be(true);
     r.SetDrmEnabled(false).Result.Should().Be(DrmMode.Off);
     r.GetDrmEnabled().Result.Should().Be(false);
 }
Exemple #16
0
 public void Should_set_antenna_configuration(ConnectionType connectionType)
 {
     using var r = new SerialReader(TestSettings.Instance.GetConnection(connectionType));
     r.SetAntennaConfiguration(GenAntennaConfiguration.Antenna1 | GenAntennaConfiguration.Antenna2).Wait();
     r.GetReaderInfo().Result.AntennaConfiguration.Should().Be(GenAntennaConfiguration.Antenna1 | GenAntennaConfiguration.Antenna2);
     r.SetAntennaConfiguration(GenAntennaConfiguration.Antenna1).Wait();
     r.GetReaderInfo().Result.AntennaConfiguration.Should().Be(GenAntennaConfiguration.Antenna1);
 }
Exemple #17
0
 public void Should_get_serial_number()
 {
     using var r = new SerialReader(TestSettings.Instance.GetConnection());
     for (int i = 0; i < 5; i++)
     {
         r.GetSerialNumber().Result.Should().BeOneOf((uint)0x17439015, (uint)406196256);
     }
 }
Exemple #18
0
        public void Should_get_tags_from_buffer_empty()
        {
            using var r = new SerialReader(TestSettings.Instance.GetConnection());
            r.ClearBuffer().Wait();
            var buffer = r.GetTagsFromBuffer().Result;

            buffer.Tags.Count.Should().Be(0);
        }
        /// <summary>
        /// Serial Reader factory function
        /// </summary>
        /// <param name="uriString">URI-style path to serial device; e.g., /COM1</param>
        public static SerialReader CreateSerialReader(String uriString)
        {
            Uri          objUri = new Uri(uriString);
            SerialReader rdr    = new SerialReader(objUri.PathAndQuery,
                                                   new SerialTransportNative());

            return(rdr);
        }
Exemple #20
0
 public void Should_set_antenna_check(ConnectionType connectionType)
 {
     using var r = new SerialReader(TestSettings.Instance.GetConnection(connectionType));
     r.SetAntennaCheck(true).Wait();
     r.GetReaderInfo().Result.AntennaCheck.Should().BeTrue();
     r.SetAntennaCheck(false).Wait();
     r.GetReaderInfo().Result.AntennaCheck.Should().BeFalse();
 }
 public void Should_get_reader_temperature(ConnectionType connectionType)
 {
     using (var r = new SerialReader(TestSettings.Instance.GetConnection(connectionType)))
     {
         //Assume we run tests at home :)
         r.GetReaderTemperature().Result.Should().BeInRange(10, 50);
     }
 }
Exemple #22
0
 public void Should_get_and_set_epc_length()
 {
     using var r = new SerialReader(TestSettings.Instance.GetConnection());
     r.SetEpcLengthForBufferOperations(EpcLength.UpTo496Bits).Wait();
     r.GetEpcLengthForBufferOperations().Result.Should().Be(EpcLength.UpTo496Bits);
     r.SetEpcLengthForBufferOperations(EpcLength.UpTo128Bits).Wait();
     r.GetEpcLengthForBufferOperations().Result.Should().Be(EpcLength.UpTo128Bits);
 }
 private void InitializeReader()
 {
     if (usbdevices == null || usbdevices.Count == 0)
     {
         return;
     }
     readerdata = string.Empty;
     reader     = new SerialReader(this);
 }
Exemple #24
0
 private void OpenReader()
 {
     PrintLn("Opening reader...");
     rdr = (SerialReader)Utilities.ConnectReader();
     //rdr = (SerialReader)Reader.Create("eapi:///" + serialPortName);
     rdr.ParamSet("/reader/baudRate", 9600);
     //rdr.Log += new SerialReader.LogHandler(rdr_Log);
     rdr.Connect();
     PrintLn("Opened reader on port " + Utilities.ReaderPortName);
 }
Exemple #25
0
 public Logic(string portIn, string portOut, DbWrapper dbWrapper, RModuleWrapper rmWrapper)
     : this(portIn, dbWrapper, rmWrapper)
 {
     _readerOut = new SerialReader(new SerialPort(portOut)
     {
         ReadTimeout = 5000
     });
     _readerOut.OnSerialStringReaded += ReaderOut_OnSerialStringReaded;
     _twoReaders = true;
 }
Exemple #26
0
 public Logic(string port, DbWrapper dbWrapper, RModuleWrapper rmWrapper)
 {
     _readerIn = new SerialReader(new SerialPort(port)
     {
         ReadTimeout = 5000
     });
     _readerIn.OnSerialStringReaded += ReaderIn_OnSerialStringReaded;
     _dbWrapper = dbWrapper;
     _rmWrapper = rmWrapper;
 }
Exemple #27
0
 public SerialRetryCommand(SerialReader serial, byte[] cmd, string name, int oid = 0)
 {
     this.serial    = serial;
     this.cmd       = cmd;
     this.name      = name;
     this.oid       = oid;
     min_query_time = this.serial.reactor.monotonic();
     this.serial.register_callback(handle_callback, this.name, this.oid);
     this.send_timer = this.serial.reactor.register_timer(this.send_event, SelectReactor.NOW);
 }
Exemple #28
0
 public SerialBootStrap(SerialReader serial)
 {
     logging.Info("start load identify_data");
     this.serial   = serial;
     identify_data = new MemoryStream();
     identify_cmd  = this.serial.lookup_command("identify offset=%u count=%c");
     this.serial.register_callback(handle_identify, "identify_response");
     this.serial.register_callback(handle_unknown, "#unknown");
     this.send_timer = this.serial.reactor.register_timer(this.send_event, SelectReactor.NOW);
 }
Exemple #29
0
 public void Should_run_tag_inventory_with_optional_params()
 {
     using var r = new SerialReader(TestSettings.Instance.GetConnection());
     r.TagInventory(new TagInventoryParams
     {
         QValue         = 10,
         Session        = SessionValue.S1,
         OptionalParams = new TagInventoryOptionalParams(TimeSpan.FromMilliseconds(1000))
     }).Wait();
 }
Exemple #30
0
 public void Should_set_rf_power()
 {
     using var r = new SerialReader(TestSettings.Instance.GetConnection());
     r.SetRFPower(20).Wait();
     r.GetReaderInfo().Result.RFPower.Should().Be((byte)20);
     r.SetRFPower(0).Wait();
     r.GetReaderInfo().Result.RFPower.Should().Be((byte)0);
     r.SetRFPower(26).Wait();
     r.GetReaderInfo().Result.RFPower.Should().Be((byte)26);
 }
Exemple #31
0
        public static DDTImage Load(Stream file)
        {
            long beg = file.Position;
            var reader = new BinaryReader(file);
            string header = "";
            for (int h = 0; h < 3; ++h) header += reader.ReadChar();
            if (header != "RTS") throw new InvalidDataException();
            int version = (int)reader.ReadChar() - (int)'0';
            if (version == 3) {
                var img = new DDTImage();
                var serializer = new SerialReader(new BinaryReader(file));
                SerializeHeader(ref img.Header, serializer);

                int numColors = (img.Palette != null ? img.Palette.Length : 0);
                int[] paletteOffs = new int[5];
                if (img.Header.Format == ImageHeader.FormatE.Palette) {
                    // TODO: paletteOffs[img.Header.AlphaBits] = palette offset
                    serializer.Serialize(ref numColors);
                    int unknown02 = 0;
                    int palette15Off = 0;
                    serializer.Serialize(ref unknown02);
                    serializer.Serialize(ref paletteOffs[0]);       //16
                    serializer.Serialize(ref palette15Off);
                    serializer.Serialize(ref paletteOffs[1]);       //15b
                    serializer.Serialize(ref paletteOffs[4]);       //12
                }

                List<Tuple<int, int>> images = new List<Tuple<int, int>>();
                for (int l = 0; l < img.Header.MipLevels; ++l) {
                    int off = reader.ReadInt32();
                    int len = reader.ReadInt32();
                    images.Add(new Tuple<int,int>(off, len));
                }

                if (img.Header.Format == ImageHeader.FormatE.Palette) {
                    file.Seek(beg + paletteOffs[img.Header.AlphaBits], SeekOrigin.Begin);
                    byte[] paletteData = new byte[numColors * 2];
                    file.Read(paletteData, 0, paletteData.Length);

                    img.Palette = new Pixel[numColors];
                    switch (img.Header.AlphaBits) {
                        case 0: Convert565ToRGB(paletteData, 0, img.Palette); break;
                        case 1: Convert555ToRGB(paletteData, 0, img.Palette); break;
                        case 4: Convert444ToRGB(paletteData, 0, img.Palette); break;
                    }
                }

                file.Seek(beg + images[0].Item1, SeekOrigin.Begin);
                byte[] bytes = new byte[images[0].Item2];
                reader.Read(bytes, 0, bytes.Length);
                img.PixelData = bytes;
                return img;
            }
            return null;
        }
 private void CloseReader()
 {
     if (null == rdr)
     {
         PrintLn("Reader already closed");
     }
     else
     {
         PrintLn("Closing reader...");
         string portName = Utilities.ReaderPortName;
         try
         {
             rdr.Destroy();
         }
         catch (Exception ex)
         {
             PrintLn("Caught Exception closing reader: " + ex);
         }
         finally
         {
             rdr = null;
         }
         PrintLn("Closed reader on serial port " + portName);
     }
 }
 private void OpenReader()
 {
     PrintLn("Opening reader...");
     rdr = (SerialReader)Utilities.ConnectReader();
     //rdr = (SerialReader)Reader.Create("eapi:///" + serialPortName);
     rdr.ParamSet("/reader/baudRate", 9600);
     //rdr.Log += new SerialReader.LogHandler(rdr_Log);
     rdr.Connect();
     PrintLn("Opened reader on port " + Utilities.ReaderPortName);
 }
        /// <summary>
        /// Serial Reader factory function
        /// </summary>
        /// <param name="uriString">URI-style path to serial device; e.g., /COM1</param>
	    public static SerialReader CreateSerialReader(String uriString)
	    {
	        SerialReader rdr = new SerialReader(uriString,
                new SerialTransportNative());
            return rdr;
	    }
Exemple #35
0
 public Form1()
 {
     InitializeComponent();
     myUpdateLights = new UpdateLightsDelegate(SetLightColors);
     myReader = new SerialReader(this);
 }
Exemple #36
0
 private void thingMagicReaderToolStripMenuItem_Click(object sender, EventArgs e)
 {
     try
     {
         try
         {
             string software = (string)rdr.ParamGet("/reader/version/software");
             MessageBox.Show(string.Concat("Hardware: M6e", "  ", "Software: ", software), "About ThingMagic Reader...", MessageBoxButtons.OK);
         }
         catch (NullReferenceException)
         {
             reader = Reader.Create(string.Concat("tmr:///", readerAddress.Text));
             reader.Connect();
             rdr = (SerialReader)reader;
             string software = (string)rdr.ParamGet("/reader/version/software");
             MessageBox.Show(string.Concat("Hardware: M6e", "  ", "Software: ", software), "About ThingMagic Reader...", MessageBoxButtons.OK);
             rdr.Destroy();
         }
     }
     catch
     {
         MessageBox.Show("Connection to ThingMagic Reader not established", "Error!", MessageBoxButtons.OK);
     }
 }