コード例 #1
0
ファイル: RFIDScanner.cs プロジェクト: ediux/WBeParkingPDA
        public bool DisableReader()
        {
            try
            {
                if (_form.InvokeRequired)
                {
                    return((bool)_form.Invoke(new BooleanReturnInvoker(DisableReader)));
                }
                else
                {
                    if (properties["isreading"] == "yes")
                    {
                        logger.Debug("Calling StopReading from StopReads");
                        ReadMgr.GetReader().StopReading();
                        logger.Debug("Called StopReading from StopReads");
                        ReadMgr.GetReader().TagRead       -= _ObjReader_TagRead;
                        ReadMgr.GetReader().ReadException -= _ObjReader_ReadException;
                        ReadMgr.GetReader().ParamSet("/reader/powerMode", Reader.PowerMode.MINSAVE);
                        properties["isreading"] = "no";
                        properties["powermode"] = "minsave";
                        Utility.SaveConfigurations(properties);
                        return(true);
                    }

                    return(false);
                }
            }
            catch (Exception ex)
            {
                writeErrorLog(ex.Message, ex);
                throw ex;
            }
        }
コード例 #2
0
ファイル: RFIDScanner.cs プロジェクト: ediux/WBeParkingPDA
 /// <summary>
 /// Stop read while exception
 /// </summary>
 private void ExceptionStopReads()
 {
     if (_form != null && _form.InvokeRequired)
     {
         _form.Invoke(new NoneReturnInvoker(ExceptionStopReads));
     }
     else
     {
         try
         {
             ReadMgr.GetReader().TagRead       -= _ObjReader_TagRead;
             ReadMgr.GetReader().ReadException -= _ObjReader_ReadException;
             properties["isreading"] = "no";
             properties["powermode"] = "minsave";
             Utility.SaveConfigurations(properties);
         }
         catch (Exception ex)
         {
             writeErrorLog(ex.Message, ex);
             throw ex;
         }
     }
 }
コード例 #3
0
ファイル: Utility.cs プロジェクト: ediux/WBeParkingPDA
        /// <summary>
        /// 切換時區對應地區:PA692 預設對應區域為北美
        /// </summary>
        /// <param name="regionName">時區名稱</param>
        public static void SwitchRegion(string regionName)
        {
            switch (regionName.ToLower())
            {
            case "na": ReadMgr.GetReader().ParamSet("/reader/region/id", Reader.Region.NA); break;

            case "in": ReadMgr.GetReader().ParamSet("/reader/region/id", Reader.Region.IN); break;

            case "au": ReadMgr.GetReader().ParamSet("/reader/region/id", Reader.Region.AU); break;

            case "eu": ReadMgr.GetReader().ParamSet("/reader/region/id", Reader.Region.EU); break;

            case "eu2": ReadMgr.GetReader().ParamSet("/reader/region/id", Reader.Region.EU2); break;

            case "eu3": ReadMgr.GetReader().ParamSet("/reader/region/id", Reader.Region.EU3); break;

            case "jp": ReadMgr.GetReader().ParamSet("/reader/region/id", Reader.Region.JP); break;

            case "kr": ReadMgr.GetReader().ParamSet("/reader/region/id", Reader.Region.KR); break;

            case "kr2": ReadMgr.GetReader().ParamSet("/reader/region/id", Reader.Region.KR2); break;

            case "prc": ReadMgr.GetReader().ParamSet("/reader/region/id", Reader.Region.PRC); break;

            case "prc2": ReadMgr.GetReader().ParamSet("/reader/region/id", Reader.Region.PRC2); break;

            case "nz":
                // MCS++
#if MCS_NOMAD
                // MCS++
                // Nomad
                // ReadMgr.GetReader().ParamSet("/reader/region/id", Reader.Region.NZ);
                // NZ Region not supported on M5ec module, so hack it here.
                ReadMgr.GetReader().ParamSet("/reader/region/id", Reader.Region.OPEN);
                ReadMgr.GetReader().ParamSet("/reader/region/hopTable", new int[] {
                    864400,
                    865150,
                    864900,
                    865900,
                    865400,
                    864650,
                    865650,
                });
                // MCS--
#else
                // MCS++
                // T41
                ReadMgr.GetReader().ParamSet("/reader/region/id", Reader.Region.NZ);
                // MCS--
#endif
                // MCS--
                break;

            case "open": ReadMgr.GetReader().ParamSet("/reader/region/id", Reader.Region.OPEN); break;

            case "unspec": ReadMgr.GetReader().ParamSet("/reader/region/id", Reader.Region.UNSPEC); break;

            default:
                throw new ArgumentException("Unknown Region: " + regionName);
            }
        }
コード例 #4
0
ファイル: Utility.cs プロジェクト: ediux/WBeParkingPDA
        /// <summary>
        /// Set the properties on the reader
        /// </summary>
        /// <param name="objReader">Reader</param>
        /// <param name="Properties">configurations</param>
        public static void SetReaderSettings(Reader objReader, Dictionary <string, string> Properties)
        {
            using (ReadMgr.Session rsess = ReadMgr.GetSession())
            {
                //Set tagencoding value
                switch (Properties["tagencoding"].ToLower())
                {
                case "fm0":
                    rsess.Reader.ParamSet("/reader/gen2/tagEncoding", Gen2.TagEncoding.FM0);
                    break;

                case "m2":
                    rsess.Reader.ParamSet("/reader/gen2/tagEncoding", Gen2.TagEncoding.M2);
                    break;

                case "m4":
                    rsess.Reader.ParamSet("/reader/gen2/tagEncoding", Gen2.TagEncoding.M4);
                    break;

                case "m8":
                    rsess.Reader.ParamSet("/reader/gen2/tagEncoding", Gen2.TagEncoding.M8);
                    break;
                }
                //Set target value
                switch (Properties["gen2target"].ToLower())
                {
                case "a":
                    rsess.Reader.ParamSet("/reader/gen2/target", Gen2.Target.A);
                    break;

                case "b":
                    rsess.Reader.ParamSet("/reader/gen2/target", Gen2.Target.B);
                    break;

                case "ab":
                    rsess.Reader.ParamSet("/reader/gen2/target", Gen2.Target.AB);
                    break;

                case "ba":
                    rsess.Reader.ParamSet("/reader/gen2/target", Gen2.Target.BA);
                    break;
                }
                //Set gen2 session value
                switch (Properties["gen2session"].ToLower())
                {
                case "s0":
                    rsess.Reader.ParamSet("/reader/gen2/session", Gen2.Session.S0);
                    break;

                case "s1":
                    rsess.Reader.ParamSet("/reader/gen2/session", Gen2.Session.S1);
                    break;

                case "s2":
                    rsess.Reader.ParamSet("/reader/gen2/session", Gen2.Session.S2);
                    break;

                case "s3":
                    rsess.Reader.ParamSet("/reader/gen2/session", Gen2.Session.S3);
                    break;
                }
                //Set Q value
                switch (Properties["gen2q"].ToLower())
                {
                case "dynamicq":
                    rsess.Reader.ParamSet("/reader/gen2/q", new Gen2.DynamicQ()); break;

                case "staticq":
                    rsess.Reader.ParamSet("/reader/gen2/q", new Gen2.StaticQ(Convert.ToByte(Properties["staticqvalue"].ToString()))); break;

                default:
                    break;
                }
                rsess.Reader.ParamSet("/reader/read/asyncOffTime", Convert.ToInt32(Properties["rfofftime"]));
                rsess.Reader.ParamSet("/reader/read/asyncOnTime", Convert.ToInt32(Properties["rfontime"]));
            }
        }
コード例 #5
0
ファイル: RFIDScanner.cs プロジェクト: ediux/WBeParkingPDA
        public void EnableReader()
        {
            try
            {
                // Make sure reader is connected
                _ObjReader = ReadMgr.GetReader();

                if (_ObjReader == null)
                {
                    //if (scannerstatuslabel != null)
                    //{
                    //    scannerstatuslabel.Text = "RFID Reader Failed!";
                    //    scannerstatuslabel.Visible = true;
                    //}
                    if (OnTagReadException != null)
                    {
                        OnTagReadException.Invoke(this, new ReaderExceptionEventArgs(new ReaderException("RFID Reader Failed!")));
                    }
                    return;
                }

                System.Text.ASCIIEncoding encoding = new System.Text.ASCIIEncoding();

                Cursor.Current = Cursors.WaitCursor;
                try
                {
                    // MCS++
                    //Check the battery power level
                    switch (BatteryStatusCheck())
                    {
                    case 1:         //Battery percentage low
                        throw new Exception("Battery level is too low to read tags.");

                    //MessageBox.Show();
                    //return;
                    case 2:         //Battery Voltage low
                        throw new Exception("Battery voltage is too low to read tags.");
                        //MessageBox.Show();
                        //return;
                    }
                    // MCS--

                    properties["isreading"] = "yes";
                    Utility.SaveConfigurations(properties);

                    //disable read power coverage

                    ReadMgr.GetReader().ParamSet("/reader/transportTimeout", 2000);
                    string storagevalue = properties["readpower"];
                    int    powerLevel   = Convert.ToInt32(storagevalue);
                    ReadMgr.GetReader().ParamSet("/reader/radio/readPower", powerLevel);
                    Utility.SwitchRegion(properties["region"]);
                    // MCS++
#if MCS_NOMAD
                    ReadMgr.GetReader().ParamSet("/reader/antenna/txRxMap", new int[][] { new int[] { 1, 1, 1 } });
                    ant.Add(1);
#else
                    // MCS++ - Will we use 1 or 2 antenna?
                    ReadMgr.GetReader().ParamSet("/reader/antenna/txRxMap", new int[][] { new int[] { 2, 2, 2 } });
                    // MCS--
#endif
                    // MCS--
                    SimpleReadPlan plan = new SimpleReadPlan(ant.ToArray(), TagProtocol.GEN2);
                    ReadMgr.GetReader().ParamSet("/reader/read/plan", plan);

                    //set properties
                    ReadMgr.GetReader().ParamSet("/reader/read/asyncOffTime", 50);
                    ReadMgr.GetReader().ParamSet("/reader/powerMode", Reader.PowerMode.FULL);

                    //set the tag population settings
                    ReadMgr.GetReader().ParamSet("/reader/gen2/target", Gen2.Target.A);//default target
                    string tagPopulation = properties["tagpopulation"];
                    switch (tagPopulation)
                    {
                    case "small":
                        ReadMgr.GetReader().ParamSet("/reader/gen2/q", new Gen2.StaticQ(2));
                        ReadMgr.GetReader().ParamSet("/reader/gen2/session", Gen2.Session.S0);
                        ReadMgr.GetReader().ParamSet("/reader/gen2/tagEncoding", Gen2.TagEncoding.M4);
                        break;

                    case "medium":
                        ReadMgr.GetReader().ParamSet("/reader/gen2/q", new Gen2.StaticQ(4));
                        ReadMgr.GetReader().ParamSet("/reader/gen2/session", Gen2.Session.S1);
                        ReadMgr.GetReader().ParamSet("/reader/gen2/tagEncoding", Gen2.TagEncoding.M4);
                        break;

                    case "large":
                        ReadMgr.GetReader().ParamSet("/reader/gen2/q", new Gen2.StaticQ(6));
                        ReadMgr.GetReader().ParamSet("/reader/gen2/session", Gen2.Session.S1);
                        ReadMgr.GetReader().ParamSet("/reader/gen2/tagEncoding", Gen2.TagEncoding.M2);
                        break;

                    default: break;
                    }

                    if (null != properties)
                    {
                        Utility.SetReaderSettings(ReadMgr.GetReader(), properties);
                    }
                    else
                    {
                        throw new Exception("properties are null");
                    }
                    //MessageBox.Show("properties are null");
                    //set the read plan and filter
                    TagFilter filter;
                    int       addressToRead = int.Parse(properties["selectionaddress"]);
                    Gen2.Bank bank          = Gen2.Bank.EPC;
                    switch (properties["tagselection"].ToLower())
                    {
                    case "None":
                    case "epc": bank = Gen2.Bank.EPC; break;

                    case "tid": bank = Gen2.Bank.TID; break;

                    case "user": bank = Gen2.Bank.USER; break;

                    case "reserved": bank = Gen2.Bank.RESERVED; break;

                    default: break;
                    }
                    if ("yes" == properties["ismaskselected"])
                    {
                        filter = new Gen2.Select(true, bank, (uint)addressToRead * 8, (ushort)(properties["selectionmask"].Length * 4), ByteFormat.FromHex(properties["selectionmask"]));
                    }
                    else
                    {
                        filter = new Gen2.Select(false, bank, (uint)addressToRead * 8, (ushort)(properties["selectionmask"].Length * 4), ByteFormat.FromHex(properties["selectionmask"]));
                    }

                    // MCS++
#if MCS_NOMAD
                    SimpleReadPlan srp;
                    if (properties["tagselection"].ToLower() == "none")
                    {
                        srp = new SimpleReadPlan(new int[] { 1 }, TagProtocol.GEN2, null, 0);
                    }
                    else
                    {
                        srp = new SimpleReadPlan(new int[] { 1 }, TagProtocol.GEN2, filter, 0);
                    }
                    ReadMgr.GetReader().ParamSet("/reader/read/plan", srp);
#else
                    // MCS++ - use antenna 2
                    SimpleReadPlan srp;
                    if (properties["tagselection"].ToLower() == "none")
                    {
                        //srp = new SimpleReadPlan(new int[] { 1 }, TagProtocol.GEN2, null, 0);
                        srp = new SimpleReadPlan(new int[] { 2 }, TagProtocol.GEN2, null, 0);
                    }
                    else
                    {
                        //srp = new SimpleReadPlan(new int[] { 1 }, TagProtocol.GEN2, filter, 0);
                        srp = new SimpleReadPlan(new int[] { 2 }, TagProtocol.GEN2, filter, 0);
                    }
                    ReadMgr.GetReader().ParamSet("/reader/read/plan", srp);
                    // MCS--
#endif
                    // MCS--
                    ReadMgr.GetReader().ReadException += _ObjReader_ReadException;
                    ReadMgr.GetReader().TagRead       += _ObjReader_TagRead;
                    ReadMgr.GetReader().StartReading();
                }
                catch (Exception ex)
                {
                    writeErrorLog(ex.Message, ex);
                    ReadMgr.GetReader().ParamSet("/reader/powerMode", Reader.PowerMode.MAXSAVE);
                    properties["isreading"] = "no";
                    Utility.SaveConfigurations(properties);
                    throw ex;
                }
                finally
                {
                    Cursor.Current = Cursors.Default;
                }
            }
            catch (Exception ex)
            {
                writeErrorLog(ex.ToString(), ex);
                if (-1 != ex.Message.IndexOf("RFID reader was not found"))
                {
                    //MessageBox.Show(ex.Message, "Error");
                    throw ex;
                }
                else
                {
                    properties["isreading"] = "no";
                    Utility.SaveConfigurations(properties);
                    throw ex;
                }
            }
        }