Esempio n. 1
0
        public static void embeddedRead(TagProtocol protocol, TagFilter filter, TagOp tagop)
        {
            TagReadData[]  tagReads = null;
            SimpleReadPlan plan     = new SimpleReadPlan(antennaList, protocol, filter, tagop, 1000);

            r.ParamSet("/reader/read/plan", plan);
            tagReads = r.Read(1000);
            // Print tag reads
            foreach (TagReadData tr in tagReads)
            {
                Console.WriteLine(tr.ToString());
                if (tr.isErrorData)
                {
                    // In case of error, show the error to user. Extract error code.
                    int errorCode = ByteConv.ToU16(tr.Data, 0);
                    Console.WriteLine("Embedded Tag operation failed. Error: " + ReaderCodeException.faultCodeToMessage(errorCode));
                }
                else
                {
                    if (tagop is Gen2.EMMicro.EM4325.GetSensorData)
                    {
                        if (tr.Data.Length > 0)
                        {
                            GetSensorDataResponse rData = new GetSensorDataResponse(tr.Data);
                            Console.WriteLine("Data:" + rData.ToString());
                        }
                    }
                    else
                    {
                        Console.WriteLine("  Data:" + ByteFormat.ToHex(tr.Data, "", " "));
                    }
                }
            }
        }
Esempio n. 2
0
        static void Main(string[] args)
        {
            bool      enableFilter = false;
            TagFilter filter       = null;

            // Program setup
            if (1 > args.Length)
            {
                Usage();
            }
            for (int nextarg = 1; nextarg < args.Length; nextarg++)
            {
                string arg = args[nextarg];
                if (arg.Equals("--ant"))
                {
                    if (null != antennaList)
                    {
                        Console.WriteLine("Duplicate argument: --ant specified more than once");
                        Usage();
                    }
                    antennaList = ParseAntennaList(args, nextarg);
                    nextarg++;
                }
                else
                {
                    Console.WriteLine("Argument {0}:\"{1}\" is not recognized", nextarg, arg);
                    Usage();
                }
            }

            try
            {
                // Create Reader object, connecting to physical device.
                // Wrap reader in a "using" block to get automatic
                // reader shutdown (using IDisposable interface).
                using (r = Reader.Create(args[0]))
                {
                    //Uncomment this line to add default transport listener.
                    //r.Transport += r.SimpleTransportListener;

                    r.Connect();
                    if (Reader.Region.UNSPEC == (Reader.Region)r.ParamGet("/reader/region/id"))
                    {
                        Reader.Region[] supportedRegions = (Reader.Region[])r.ParamGet("/reader/region/supportedRegions");
                        if (supportedRegions.Length < 1)
                        {
                            throw new FAULT_INVALID_REGION_Exception();
                        }
                        r.ParamSet("/reader/region/id", supportedRegions[0]);
                    }
                    if (r.isAntDetectEnabled(antennaList))
                    {
                        Console.WriteLine("Module doesn't has antenna detection support please provide antenna list");
                        Usage();
                    }

                    //Use first antenna for operation
                    if (antennaList != null)
                    {
                        r.ParamSet("/reader/tagop/antenna", antennaList[0]);
                    }

                    if (enableFilter)
                    {
                        // If select filter is to be enabled
                        byte[] mask = new byte[] { (byte)0x30, (byte)0x28, (byte)0x35, (byte)0x4D,
                                                   (byte)0x82, (byte)0x02, (byte)0x02, (byte)0x80, (byte)0x00, (byte)0x01,
                                                   (byte)0x04, (byte)0xAC };
                        filter = new Gen2.Select(false, Gen2.Bank.EPC, 32, 96, mask);
                    }

                    //Get Sensor Data of EM4325 tag
                    bool sendUid       = true;
                    bool sendNewSample = true;
                    Gen2.EMMicro.EM4325.GetSensorData getSensorOp = new Gen2.EMMicro.EM4325.GetSensorData(sendUid, sendNewSample);
                    try
                    {
                        Console.WriteLine("****Executing standalone tag operation of Get sensor Data command of EM4325 tag****");
                        byte[] response = (byte[])r.ExecuteTagOp(getSensorOp, filter);

                        // Parse the response of GetSensorData
                        Console.WriteLine("****Get sensor Data command is success****");
                        GetSensorDataResponse rData = new GetSensorDataResponse(response);
                        Console.WriteLine(rData.ToString());
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine("Exception from executing get Sensor Data command: " + ex.Message);
                    }

                    //Embedded tag operation of Get sensor data
                    try
                    {
                        Console.WriteLine("****Executing embedded tag operation of Get sensor Data command of EM4325 tag****");
                        embeddedRead(TagProtocol.GEN2, filter, getSensorOp);
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine("Exception from embedded get sensor data: " + ex.Message);
                    }

                    //Reset alarms command
                    // Read back the temperature control word at 0xEC address to verify reset enable alarm bit is set before executing reset alarm tag op.
                    Console.WriteLine("Reading Temperature control word 1 before resetting alarms to ensure reset enable bit is set to 1");
                    byte[]        filterMask = new byte[] { (byte)0x04, (byte)0xc2 };
                    Gen2.Select   select     = new Gen2.Select(false, Gen2.Bank.EPC, 0x70, 16, filterMask);
                    Gen2.ReadData rdata      = new Gen2.ReadData(Gen2.Bank.USER, 0xEC, (byte)0x1);
                    ushort[]      resp       = (ushort[])r.ExecuteTagOp(rdata, select);
                    Console.WriteLine("Temp control word 1: ");
                    foreach (ushort i in resp)
                    {
                        Console.Write(" {0:X4}", i);
                    }
                    Console.WriteLine("\n");

                    // If temperature control word is not 0x4000, write the data
                    if (resp[0] != 0x4000)
                    {
                        ushort[]       writeData = new ushort[] { 0x4000 };
                        Gen2.WriteData wData     = new Gen2.WriteData(Gen2.Bank.USER, 0xEC, writeData);
                        r.ExecuteTagOp(wData, select);
                    }
                    Gen2.EMMicro.EM4325.ResetAlarms resetAlarmsOp = new Gen2.EMMicro.EM4325.ResetAlarms();
                    try
                    {
                        Console.WriteLine("****Executing standalone tag operation of Reset alarms command of EM4325 tag****");
                        r.ExecuteTagOp(resetAlarmsOp, filter);
                        Console.WriteLine("****Reset Alarms command is success****");
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine("Exception from executing reset alarms : " + ex.Message);
                    }

                    //Embedded tag operation of reset alarms command
                    try
                    {
                        Console.WriteLine("****Executing embedded tag operation of reset alarms command of EM4325 tag****");
                        embeddedRead(TagProtocol.GEN2, filter, resetAlarmsOp);
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine("Exception from embedded reset alarms command: " + ex.Message);
                    }
                }
            }
            catch (ReaderException re)
            {
                Console.WriteLine("Error: " + re.Message);
                Console.Out.Flush();
            }
            catch (Exception ex)
            {
                Console.WriteLine("Error: " + ex.Message);
            }
        }