Exemplo n.º 1
0
        private void PerformReadAllMemOperation(TagFilter filter, TagOp op)
        {
            TagReadData[]  tagReads = null;
            SimpleReadPlan plan     = new SimpleReadPlan(null, TagProtocol.GEN2, filter, op, 1000);

            reader.ParamSet("/reader/read/plan", plan);
            Console.WriteLine("Embedded tag operation - ");
            // Read tags
            tagReads = reader.Read(500);
            foreach (TagReadData tr in tagReads)
            {
                Console.WriteLine(tr.ToString());
                if (0 < tr.Data.Length)
                {
                    Console.WriteLine(" Embedded read data: " + ByteFormat.ToHex(tr.Data, "", " "));
                    Console.WriteLine(" User memory: " + ByteFormat.ToHex(tr.USERMemData, "", " "));
                    Console.WriteLine(" Reserved memory: " + ByteFormat.ToHex(tr.RESERVEDMemData, "", " "));
                    Console.WriteLine(" Tid memory: " + ByteFormat.ToHex(tr.TIDMemData, "", " "));
                    Console.WriteLine(" EPC memory: " + ByteFormat.ToHex(tr.EPCMemData, "", " "));
                }
                Console.WriteLine(" Embedded read data length:" + tr.Data.Length);
            }
            Console.WriteLine();
            Console.WriteLine("Standalone tag operation - ");
            ushort[] data = (ushort[])reader.ExecuteTagOp(op, filter);
            //// Print tag reads
            if (0 < data.Length)
            {
                Console.WriteLine(" Standalone read data:" + ByteFormat.ToHex(ByteConv.ConvertFromUshortArray(data), "", " "));
                Console.WriteLine(" Standalone read data length:" + ByteConv.ConvertFromUshortArray(data).Length);
            }
            data = null;
            Console.WriteLine();
        }
Exemplo n.º 2
0
        private double getILianTemp(TagReadData RawRead)
        {
            //Console.WriteLine("### getILianTemp");
            double temp = UNSPECTTEMP;

            if (RawRead.Data.Length > 0)
            {
                double temperature = 0;
                byte[] bdata       = RawRead.Data;
                string sdata       = ByteFormat.ToHex(bdata, "", "");
                if (sdata.Trim().Equals("0000"))
                {
                    return(0);
                }
                Console.WriteLine("sdata={0} {1} {2}", sdata, sdata.Substring(0, 2), sdata.Substring(2, 2));
                int t1 = Convert.ToInt32(sdata.Substring(0, 2), 16);
                int t2 = Convert.ToInt32(sdata.Substring(2, 2), 16);
                temperature = (t1 - 30) + (t2 / (double)256);
                Console.WriteLine("t1={0}, t2={1}", t1 - 30, t2 / (double)256);
                Console.WriteLine("temperature=" + temperature);
                Console.WriteLine();
                //temp = temperature;
                temp = Math.Round(temperature, 2);//保留两位小数
            }
            return(temp);
        }
Exemplo n.º 3
0
 public static void parseTAM2Response(byte[] response, byte[] key, ushort protMode)
 {
     byte[] generatedIChallenge = new byte[10];
     byte[] CipherData          = new byte[16];
     byte[] IV = new byte[16];
     if (response.Length > 0)
     {
         Array.Copy(response, 0, generatedIChallenge, 0, 10);
         Console.WriteLine("Generated Ichallenge:" + ByteFormat.ToHex(generatedIChallenge, "", " "));
         Array.Copy(response, 10, IV, 0, 16);
         byte[] Challenge = DecryptIchallenge(IV, key);
         Array.Copy(Challenge, 6, Challenge, 0, 10);
         Array.Resize(ref Challenge, 10);
         Console.WriteLine("Returned Ichallenge:" + ByteFormat.ToHex(Challenge, "", " "));
         Array.Copy(response, 26, CipherData, 0, 16);
         if (protMode == 1 || protMode == 3)
         {
             Console.WriteLine("Custom Data: " + DecryptCustomData(CipherData, key, (byte[])IV.Clone()));
         }
         else
         {
             Console.WriteLine("Custom Data: " + ByteFormat.ToHex(CipherData, "", " "));
         }
     }
 }
Exemplo n.º 4
0
        public static void parseSecureIdResponse(byte[] rsp)
        {
            int readIndex = 0;

            //Extract UID length
            int uidLength = rsp[readIndex];

            // Extract UID based on length
            byte[] uid = new byte[uidLength];

            //Update the read index and copy the uid into uid array.
            readIndex += 1;
            Array.Copy(rsp, readIndex, uid, 0, uidLength);
            Console.WriteLine("UID: " + ByteFormat.ToHex(uid));
            readIndex += uidLength;

            // Extract Secure id length and ID
            int secureIdLen = rsp[readIndex];

            byte[] secureID = new byte[secureIdLen];

            //Update the read index and copy the Secure id into secureID array.
            readIndex += 1;
            Array.Copy(rsp, readIndex, secureID, 0, secureIdLen);
            Console.WriteLine("Secure ID: " + ByteFormat.ToHex(secureID));
            readIndex += secureIdLen;
        }
        public bool CheckAccessPasswordIsLocked()
        {
            try
            {
                string reservedBankData = string.Empty;
                //Read access password
                var op           = new Gen2.ReadData(Gen2.Bank.RESERVED, 2, 2);
                var reservedData = (ushort[])_reader.ExecuteTagOp(op, null);

                if (null != reservedData)
                {
                    reservedBankData = ByteFormat.ToHex(ByteConv.ConvertFromUshortArray(reservedData), "", " ");
                }

                var accessPassword = reservedBankData.Trim(' ');
                return(false);
            }
            catch (Exception ex)
            {
                if (ex is FAULT_GEN2_PROTOCOL_MEMORY_LOCKED_Exception)
                {
                    return(true);
                }
                Trace.TraceError("Error checking access password. " + ex.Message + ex.StackTrace);
                return(false);
            }
        }
Exemplo n.º 6
0
 private void btnexec_Click(object sender, EventArgs e)
 {
     if (this.cbbslot.SelectedIndex == -1)
     {
         MessageBox.Show("请选择卡槽");
         return;
     }
     if (this.tbsend.Text.Trim() == string.Empty)
     {
         MessageBox.Show("请输入cos指令");
         return;
     }
     byte[] cosresp = null;
     try
     {
         cosresp = rdr.PsamTransceiver(this.cbbslot.SelectedIndex + 1,
                                       ByteFormat.FromHex(this.tbsend.Text.Trim()));
     }
     catch (System.Exception ex)
     {
         MessageBox.Show("操作失败," + ex.ToString());
         return;
     }
     this.tbrecv.Text = ByteFormat.ToHex(cosresp);
 }
Exemplo n.º 7
0
 public string ReadPassword(uint byteIndex, uint length)
 {
     try
     {
         DateTime timeBeforeRead = DateTime.Now;
         byte[]   data           = null;
         using (Reader reader = Reader.Create("tmr:///" + Vars.comport.ToLower()))
         {
             reader.Connect();
             TagOp          tagOp = new Gen2.ReadData(Gen2.Bank.RESERVED, byteIndex, (byte)length);
             SimpleReadPlan plan  = new SimpleReadPlan(null, TagProtocol.GEN2, null, tagOp, 1000);
             reader.ParamSet("/reader/read/plan", plan);
             data = reader.ReadTagMemBytes(tagData, (int)Gen2.Bank.RESERVED, (int)byteIndex, (int)length);
         }
         DateTime timeAfterRead = DateTime.Now;
         TimeSpan timeElapsed   = timeAfterRead - timeBeforeRead;
         commandTotalTimeTextBox.Text = timeElapsed.TotalSeconds.ToString();
         return(ByteFormat.ToHex(data));
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
         return("");
     }
 }
Exemplo n.º 8
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, "", " "));
                    }
                }
            }
        }
Exemplo n.º 9
0
        private void PerformWriteOperation()
        {
            //Use first antenna for operation
            if (antennaList != null)
            {
                reader.ParamSet("/reader/tagop/antenna", antennaList[0]);
            }

            Gen2.TagData epc = new Gen2.TagData(new byte[]
            {
                0x01, 0x23, 0x45, 0x67, 0x89, 0xAB,
                0xCD, 0xEF, 0x01, 0x23, 0x45, 0x67,
            });
            Console.WriteLine("Write on epc mem: " + epc.EpcString);
            Gen2.WriteTag tagop = new Gen2.WriteTag(epc);
            reader.ExecuteTagOp(tagop, null);
            Console.WriteLine();

            ushort[] data = new ushort[] { 0x1234, 0x5678 };
            Console.WriteLine("Write on reserved mem: " + ByteFormat.ToHex(data));
            Gen2.BlockWrite blockwrite = new Gen2.BlockWrite(Gen2.Bank.RESERVED, 0, data);
            reader.ExecuteTagOp(blockwrite, null);
            Console.WriteLine();

            data = null;
            data = new ushort[] { 0xFFF1, 0x1122 };
            Console.WriteLine("Write on user mem: " + ByteFormat.ToHex(data));
            blockwrite = new Gen2.BlockWrite(Gen2.Bank.USER, 0, data);
            reader.ExecuteTagOp(blockwrite, null);
            Console.WriteLine();
        }
Exemplo n.º 10
0
        private void timer1_Tick(object sender, EventArgs e)
        {
            TagChipType nxpchiptype = TagChipType.TagChipType_None;

            try
            {
                this.labEASAlert.BackColor = Color.Gray;

                if (this.cbbnxpchiptype.SelectedIndex == 0)
                {
                    nxpchiptype = TagChipType.TagChipType_NXP_G2X;
                }
                else if (this.cbbnxpchiptype.SelectedIndex == 1)
                {
                    nxpchiptype = TagChipType.TagChipType_NXP_G2i;
                }

                NXP_EASAlarmPara   EasAlarmPara = new NXP_EASAlarmPara(0x01, 0x02, 0x01, nxpchiptype);
                NXP_EASAlarmResult result       = (NXP_EASAlarmResult)mrdr.CustomCmd(null, CustomCmdType.NXP_EASAlarm, EasAlarmPara);
                tbEASAlarmData.Text = ByteFormat.ToHex(result.EASAlarmData);
                System.Media.SystemSounds.Beep.Play();
                this.labEASAlert.BackColor = Color.Red;
            }
            catch (Exception ex)
            {
            }
        }
Exemplo n.º 11
0
        static void Main(string[] args)
        {
            //Connecting the reader and setting base parameters
            Reader r = Reader.Create("tmr:///COM3");

            r.Connect();
            r.ParamSet("/reader/region/id", Reader.Region.NA); //Region
            r.ParamSet("/reader/radio/readPower", 2000);       //Read power
            r.ParamSet("/reader/gen2/t4", 3000);               //3ms continuous wave

            //Defining the Select command to the tag
            Gen2.Select tempSelect = new Gen2.Select(false, Gen2.Bank.USER, 0xE0, 0, new byte[0]);

            //Storing Temperature data in reserved memory bank pointed at 0xE
            TagOp tempRead = new Gen2.ReadData(Gen2.Bank.RESERVED, 0xE, 1);

            SimpleReadPlan readPlan = new SimpleReadPlan(new int[] { 1 }, TagProtocol.GEN2, tempSelect, tempRead, 100);

            r.ParamSet("/reader/read/plan", readPlan);
            TagReadData[] tempReadResults = r.Read(75); //Read for 75ms

            foreach (TagReadData result in tempReadResults)
            {
                string EPC         = result.EpcString;
                string frequency   = result.Frequency.ToString();
                string tempCodeHex = ByteFormat.ToHex(result.Data, ", ");
                int    tempCode    = Convert.ToInt32(tempCodeHex, 16);
                if (tempCode > 1000 && tempCode < 3500)
                {
                    Console.WriteLine("EPC: " + EPC + "Frequency(kHz): " + frequency + "Temperature Code: " + tempCode);
                }
            }
        }
Exemplo n.º 12
0
 /// <summary>
 /// Human-readable representation
 /// </summary>
 /// <returns>Human-readable representation</returns>
 public override string ToString()
 {
     return(String.Join(" ", new string[] {
         "\n UID : " + ByteFormat.ToHex(uid),
         "\n SensorData : " + sensorData.ToString(),
         "\n UTCTimestamp=" + utcTimestamp,
     }));
 }
Exemplo n.º 13
0
        /// <summary>
        /// Refresh button to generate random 10 byte challenge
        /// </summary>
        private void btnRefresh_Click(object sender, RoutedEventArgs e)
        {
            Random rnd = new Random();

            Byte[] b = new Byte[10];
            rnd.NextBytes(b);
            lblRandomChallengeValue.Content = ByteFormat.ToHex(b, "", " ");
        }
Exemplo n.º 14
0
        public void Add(TagReadData addData)
        {
            lock (new Object())
            {
                string key = null;

                if (chkbxUniqueByData)
                {
                    if (true == chkbxShowFailedDataReads)
                    {
                        //key = addData.EpcString + ByteFormat.ToHex(addData.Data, "", " ");
                        // When CHECKED - Add the entry to the database. This will result in
                        // potentially two entries for every tag: one with the requested data and one without.
                        if (addData.Data.Length > 0)
                        {
                            key = addData.EpcString + ByteFormat.ToHex(addData.Data, "", " ");
                        }
                        else
                        {
                            key = addData.EpcString + "";
                        }
                    }
                    else if ((false == chkbxShowFailedDataReads) && (addData.Data.Length == 0))
                    {
                        // When UNCHECKED (default) - If the embedded read data fails (data.length==0) then don't add the entry to
                        // the database, thus it won't be displayed.
                        return;
                    }
                    else
                    {
                        key = addData.EpcString + ByteFormat.ToHex(addData.Data, "", " ");
                    }
                }
                else
                {
                    key = addData.EpcString;     //if only keying on EPCID
                }

                UniqueTagCounts = 0;
                TotalTagCounts  = 0;

                if (!EpcIndex.ContainsKey(key))
                {
                    TagReadRecord value = new TagReadRecord(addData);
                    value.SerialNumber = (uint)EpcIndex.Count + 1;
                    _tagList.Add(value);
                    EpcIndex.Add(key, value);
                    //Call this method to calculate total tag reads and unique tag read counts
                    UpdateTagCountTextBox(EpcIndex);
                }
                else
                {
                    EpcIndex[key].Update(addData);
                    UpdateTagCountTextBox(EpcIndex);
                }
            }
        }
Exemplo n.º 15
0
 static void objReader_Transport(object sender, TransportListenerEventArgs e)
 {
     System.Diagnostics.Debug.Write(String.Format(
                                        "{0}: {1} (timeout={2:D}ms)",
                                        e.Tx ? "TX" : "RX",
                                        ByteFormat.ToHex(e.Data, "", " "),
                                        e.Timeout
                                        ));
 }
Exemplo n.º 16
0
        public static void parseGetSystemInfoResponse(byte[] systemInfo)
        {
            int readIndex = 0;
            // Extract 1 byte of Information Flags from response
            byte infoFlags = systemInfo[readIndex++];

            //Extract UID - 8 bytes for Iso15693
            int uidLength = 8;

            byte[] uid = new byte[uidLength];
            Array.Copy(systemInfo, readIndex, uid, 0, uidLength);
            Console.WriteLine("UID: " + ByteFormat.ToHex(uid));
            readIndex += uidLength;
            if (infoFlags == 0)
            {
                Console.WriteLine("No information flags are enabled");
            }
            else
            {
                // Checks Information flags are supported or not and then extracts respective fields information.
                if ((infoFlags & 0x0001) == 0x0001)
                {
                    Console.WriteLine("DSFID is supported and DSFID field is present in the response");
                    //Extract 1 byte of DSFID
                    byte dsfid = systemInfo[readIndex++];
                    Console.WriteLine("DSFID: " + dsfid.ToString());
                }
                if ((infoFlags & 0x0002) == 0x0002)
                {
                    Console.WriteLine("AFI is supported and AFI field is present in the response");
                    //Extract 1 byte of AFI
                    byte afi = systemInfo[readIndex++];
                    Console.WriteLine("AFI: " + afi.ToString());
                }
                if ((infoFlags & 0x0004) == 0x0004)
                {
                    Console.WriteLine("VICC memory size is supported and VICC field is present in the response");
                    //Extract 2 bytes of VICC information
                    UInt16 viccInfo      = ByteConv.ToU16(systemInfo, readIndex);
                    byte   maxBlockCount = (byte)(viccInfo & 0xFF);    // holds the number of blocks
                    Console.WriteLine("Max Block count: " + maxBlockCount);
                    byte blocksize = (byte)((viccInfo & 0x1F00) >> 8); // holds blocksize
                    Console.WriteLine("Block Size: " + blocksize);
                    readIndex += 2;
                }
                if ((infoFlags & 0x0008) == 0x0008)
                {
                    Console.WriteLine("IC reference is supported and IC reference is present in the response");
                    // Extract 1 byte of IC reference
                    byte icRef = systemInfo[readIndex++];
                    Console.WriteLine("IC Reference: " + icRef.ToString());
                }
            }
        }
Exemplo n.º 17
0
        /// <summary>
        /// Parse user memory data and populate the user mem textboxes
        /// </summary>
        /// <param name="userData">accepts read user memory data</param>
        private void ParseUserMemData(ushort[] userData)
        {
            string userMemData = string.Empty;

            if (null != userData)
            {
                userMemData           = ByteFormat.ToHex(ByteConv.ConvertFromUshortArray(userData), "", "");
                txtUserDataValue.Text = ReplaceSpecialCharInAsciiData(Utilities.HexStringToAsciiString(userMemData).ToCharArray());
                txtUserMemData.Text   = ByteFormat.ToHex(ByteConv.ConvertFromUshortArray(userData), "", " ");
            }
        }
Exemplo n.º 18
0
 /// <summary>
 /// Decrypts custom data
 /// </summary>
 /// <param name="CipherData">Encrypted data</param>
 /// <param name="key">key to decrypt encrypted data</param>
 /// <param name="IV">Initialization vector</param>
 /// <returns></returns>
 public string DecryptCustomData(byte[] CipherData, byte[] key, byte[] IV)
 {
     byte[] decipheredText = new byte[16];
     decipheredText = DecryptIchallenge(CipherData, key);
     byte[] CustomData = new byte[16];
     for (int i = 0; i < IV.Length; i++)
     {
         CustomData[i] = (byte)(decipheredText[i] ^ IV[i]);
     }
     return(ByteFormat.ToHex(CustomData, "", " "));
 }
Exemplo n.º 19
0
 public static void parseTAM1Response(byte[] response, byte[] key)
 {
     byte[] generatedIChallenge = new byte[10];
     byte[] tempBuffer          = new byte[16];
     if (response.Length > 0)
     {
         Array.Copy(response, 0, generatedIChallenge, 0, 10);
         Console.WriteLine("Generated Ichallenge:" + ByteFormat.ToHex(generatedIChallenge, "", " "));
         Array.Copy(response, 10, tempBuffer, 0, 16);
         byte[] receivedIChallenge = DecryptIchallenge(tempBuffer, key);
         Array.Copy(receivedIChallenge, 6, receivedIChallenge, 0, 10);
         Array.Resize(ref receivedIChallenge, 10);
         Console.WriteLine("Returned Ichallenge : " + ByteFormat.ToHex(receivedIChallenge, "", " "));
     }
 }
Exemplo n.º 20
0
        private void btnEASAlarm_Click(object sender, EventArgs e)
        {
            int ret;

            ret = IsAntSet();
            if (ret == -1)
            {
                MessageBox.Show("please select antenna");
                return;
            }
            else if (ret == 1)
            {
                DialogResult stat = DialogResult.OK;
                stat = MessageBox.Show("execute operation on the port without finding antenna ?", "tip-off",
                                       MessageBoxButtons.OKCancel, MessageBoxIcon.Question,
                                       MessageBoxDefaultButton.Button2);
                if (stat != DialogResult.OK)
                {
                    return;
                }
            }


            try
            {
                NXP_EASAlarmPara   EasAlarmPara = new NXP_EASAlarmPara(0x01, 0x02, 0x01);
                NXP_EASAlarmResult result       = (NXP_EASAlarmResult)mrdr.CustomCmd(CustomCmdType.NXP_EASAlarm, EasAlarmPara);
                tbEASAlarmData.Text = ByteFormat.ToHex(result.EASAlarmData);
            }
            catch (OpFaidedException notagexp)
            {
                if (notagexp.ErrCode == 0x400)
                {
                    MessageBox.Show("no tag");
                }
                else
                {
                    MessageBox.Show("operation failed:" + notagexp.ToString());
                }

                return;
            }
            catch (Exception ex)
            {
                MessageBox.Show("EASAlarm failed:" + ex.ToString());
                return;
            }
        }
Exemplo n.º 21
0
        private void timer1_Tick(object sender, EventArgs e)
        {
            try
            {
                this.labEASAlert.BackColor = Color.Gray;

                NXP_EASAlarmPara   EasAlarmPara = new NXP_EASAlarmPara(0x01, 0x02, 0x01);
                NXP_EASAlarmResult result       = (NXP_EASAlarmResult)mrdr.CustomCmd(CustomCmdType.NXP_EASAlarm, EasAlarmPara);
                tbEASAlarmData.Text = ByteFormat.ToHex(result.EASAlarmData);
                System.Media.SystemSounds.Beep.Play();
                this.labEASAlert.BackColor = Color.Red;
            }
            catch (Exception ex)
            {
            }
        }
Exemplo n.º 22
0
        public static void embeddedReadAfterWrite(TagFilter filter, TagOp tagop)
        {
            TagReadData[]  tagReads = null;
            SimpleReadPlan plan     = new SimpleReadPlan(antennaList, TagProtocol.GEN2, 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 (0 < tr.Data.Length)
                {
                    Console.WriteLine("  Data:" + ByteFormat.ToHex(tr.Data, "", " "));
                }
            }
        }
Exemplo n.º 23
0
        /// <summary>
        /// Parse reserved memory data and populate the reserved mem textboxes
        /// </summary>
        /// <param name="reservedData">accepts read reserved memory data</param>
        private void ParseReservedMemData(ushort[] reservedData)
        {
            string reservedMemData = string.Empty;

            if (null != reservedData)
            {
                reservedMemData = ByteFormat.ToHex(ByteConv.ConvertFromUshortArray(reservedData), "", " ");
            }

            if (reservedMemData.Length > 0)
            {
                if (reservedMemData.Length > 11)
                {
                    // Extract kill pwd
                    txtKillPassword.Text = reservedMemData.Substring(0, 11).TrimStart(' ');
                    string tempData = reservedMemData.Substring(12).TrimStart(' ');
                    // Check if reserved memory has additional data
                    if (tempData.Length > 11)
                    {
                        // Extract access pwd
                        txtAcessPassword.Text = reservedMemData.Substring(12, 11).TrimStart(' ');
                        // Extract additional reserved memory
                        txtReservedMemUnusedValue.Text = reservedMemData.Substring(24).TrimStart(' ');

                        // Visible additional memory textboxes
                        lblAdditionalReservedMem.Visibility    = System.Windows.Visibility.Visible;
                        txtReservedMemUnusedValue.Visibility   = System.Windows.Visibility.Visible;
                        lblAdditionalReservedMemAdd.Visibility = System.Windows.Visibility.Visible;
                    }
                    else
                    {
                        // Extract access pwd
                        txtAcessPassword.Text = reservedMemData.Substring(12).TrimStart(' ');

                        // Hide additional memory textboxes
                        lblAdditionalReservedMem.Visibility    = System.Windows.Visibility.Collapsed;
                        txtReservedMemUnusedValue.Visibility   = System.Windows.Visibility.Collapsed;
                        lblAdditionalReservedMemAdd.Visibility = System.Windows.Visibility.Collapsed;
                    }
                }
                else
                {
                    txtKillPassword.Text = reservedMemData.Substring(0, reservedData.Length).TrimStart(' ');
                }
            }
        }
Exemplo n.º 24
0
 private static void r_tagRead(object sender, TagReadDataEventArgs e)
 {
     Console.WriteLine("Background read: " + e.TagReadData);
     if (0 < e.TagReadData.Data.Length)
     {
         if (e.TagReadData.isErrorData)
         {
             // In case of error, show the error to user. Extract error code.
             byte[] errorCodeBytes = e.TagReadData.Data;
             int    offset         = 0;
             //converts byte array to int value
             int errorCode = (((errorCodeBytes[offset] & 0xFF) << 8) | ((errorCodeBytes[offset + 1] & 0xFF) << 0));
             Console.WriteLine("Embedded Tag operation failed. Error: " + ReaderCodeException.faultCodeToMessage(errorCode));
         }
         else
         {
             Console.WriteLine("Data[" + e.TagReadData.dataLength + "]: " + ByteFormat.ToHex(e.TagReadData.Data, "", " "));
         }
     }
 }
Exemplo n.º 25
0
        private void readparamenu_Click(object sender, EventArgs e)
        {
            rParms.isIpModify  = false;
            rParms.isM5eModify = false;

            if (rParms.hasIP)
            {
                //if (rParms.readertype == ReaderType.MT_TWOANTS ||
                //rParms.readertype == ReaderType.MT_FOURANTS)
                //{
                if (!rParms.isGetIp)
                {
                    ReaderIPInfo ipinfo = null;
                    try
                    {
                        ipinfo         = (ReaderIPInfo)modulerdr.ParamGet("IPAddress");
                        rParms.ip      = ipinfo.IP;
                        rParms.subnet  = ipinfo.SUBNET;
                        rParms.gateway = ipinfo.GATEWAY;
                        if (ipinfo.MACADDR != null)
                        {
                            rParms.macstr = ByteFormat.ToHex(ipinfo.MACADDR);
                        }
                        rParms.isGetIp = true;
                    }
                    catch
                    {
                        rParms.hasIP = false;
                    }
                }
            }

            readerParaform frm = new readerParaform(rParms, modulerdr);

            if (frm.ShowDialog() == DialogResult.Cancel)
            {
                return;
            }
        }
Exemplo n.º 26
0
        /// <summary>
        /// Parse tid memory data and populate the tid mem textboxes
        /// </summary>
        /// <param name="tidData">accepts read tid memory data</param>
        private void ParseTIDMemData(ushort[] tidData)
        {
            string tidBankData = string.Empty;

            if (null != tidData)
            {
                tidBankData = ByteFormat.ToHex(ByteConv.ConvertFromUshortArray(tidData), "", " ");
            }

            if (tidBankData.Length > 0)
            {
                txtClsID.Text    = tidBankData.Substring(0, 2).TrimStart(' ');
                txtVendorID.Text = tidBankData.Substring(3, 4).Replace(" ", string.Empty);
                string tagModel = string.Empty;
                txtVendorValue.Text   = GetVendor(txtVendorID.Text, tidBankData.Substring(7, 4).Replace(" ", string.Empty), out tagModel);
                txtModelID.Text       = tidBankData.Substring(7, 4).Replace(" ", string.Empty);
                txtModeldIDValue.Text = tagModel;
                if (tidBankData.Length >= 12)
                {
                    txtUniqueIDValue.Text = tidBankData.Substring(12).TrimStart(' ');
                }
            }
        }
Exemplo n.º 27
0
        private void btnRead_Click(object sender, EventArgs e)
        {
            List <int> selants = new List <int>();
            bool       isalert = false;

            foreach (int antindex in allants.Keys)
            {
                if (allants[antindex].Enabled)
                {
                    if (allants[antindex].Checked)
                    {
                        selants.Add(antindex);
                        if (allants[antindex].ForeColor == Color.Red)
                        {
                            isalert = true;
                        }
                    }
                }
            }

            if (selants.Count != 1)
            {
                MessageBox.Show("必须且只能选择个一个天线");
                return;
            }


            if (isalert)
            {
                DialogResult stat = DialogResult.OK;
                stat = MessageBox.Show("在未检测到天线的端口执行操作,真的要执行吗?", "警告",
                                       MessageBoxButtons.OKCancel, MessageBoxIcon.Question,
                                       MessageBoxDefaultButton.Button2);
                if (stat != DialogResult.OK)
                {
                    return;
                }
            }

            if (listBox2.SelectedIndex == -1)
            {
                MessageBox.Show("请选中要操作的卡号");
                return;
            }

            if (this.tbStartAddr.Text.Trim() == string.Empty)
            {
                MessageBox.Show("请输入起始地址");
                return;
            }
            if (this.tbBlkCnt.Text.Trim() == string.Empty)
            {
                MessageBox.Show("请输入要读块数");
                return;
            }

            string sltag = listBox2.SelectedItem.ToString();

            try
            {
                int addrst = int.Parse(this.tbStartAddr.Text.Trim());
                int blkcnt = int.Parse(this.tbBlkCnt.Text.Trim());
                Modrdr.ParamSet("TagopAntenna", selants[0]);
                int    t1   = Environment.TickCount;
                byte[] data = Modrdr.ReadTagMemBytes(new ISO180006bTagData(ByteFormat.FromHex(sltag)), MemBank.ISO180006BMEM, addrst, blkcnt);
                Debug.WriteLine((Environment.TickCount - t1).ToString());
                this.rtbdata.Text = ByteFormat.ToHex(data);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }
Exemplo n.º 28
0
        static void Main(string[] args)
        {
            // Program setup
            if (1 > args.Length)
            {
                Usage();
            }
            int[] antennaList = null;
            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 automaticq
                // reader shutdown (using IDisposable interface).
                using (Reader r = Reader.Create(args[0]))
                {
                    //Uncomment this line to add default transport listener.
                    //r.Transport += r.SimpleTransportListener;

                    r.Connect();
                    string model = (string)r.ParamGet("/reader/version/model");
                    if ("M6e".Equals(model) || "M6e PRC".Equals(model) || "M6e JIC".Equals(model) || "M6e Micro".Equals(model) ||
                        "M6e Nano".Equals(model) || "M6e Micro USB".Equals(model) || "M6e Micro USBPro".Equals(model))
                    {
                        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 ((model.Equals("M6e Micro") || model.Equals("M6e Nano")) && antennaList == null)
                        {
                            Console.WriteLine("Module doesn't has antenna detection support please provide antenna list");
                            Usage();
                        }
                        //Uncomment the following line to revert the module settings to factory defaluts
                        //r.ParamSet("/reader/userConfig", new SerialReader.UserConfigOp(SerialReader.UserConfigOperation.CLEAR));
                        //Console.WriteLine("User profile set option:reset all configuration");

                        //Uncomment this if readerstats need to be included
                        //r.ParamSet("/reader/stats/enable", Reader.Stat.StatsFlag.TEMPERATURE);

                        /* Uncomment the following lines if want to enable embedded read and filter with autonomous operation.
                         * Add tagop object readtagOp and filter object epcFilter in simple read plan constructor.
                         */

                        //Gen2.ReadData readtagOp = new Gen2.ReadData(Gen2.Bank.RESERVED, 2, 2);
                        //Gen2.TagData epcFilter = new Gen2.TagData(new byte[] { 0x11,0x22,0x33,0x44,0x55,0x66,0x77,
                        //0x88,0x99,0x00,0x99,0x99});

                        int[] gpiPin = new int[1];
                        gpiPin[0] = 1;
                        r.ParamSet("/reader/read/trigger/gpi", gpiPin);
                        GpiPinTrigger gpiPinTrigger = new GpiPinTrigger();
                        gpiPinTrigger.enable = true;
                        SimpleReadPlan srp = new SimpleReadPlan(antennaList, TagProtocol.GEN2, null, null, 1000);

                        //To disable autonomous read make enableAutonomousRead flag to false and do SAVEWITHRREADPLAN
                        srp.enableAutonomousRead = true;
                        srp.ReadTrigger          = gpiPinTrigger;

                        r.ParamSet("/reader/read/plan", srp);
                        r.ParamSet("/reader/userConfig", new SerialReader.UserConfigOp(SerialReader.UserConfigOperation.SAVEWITHREADPLAN));
                        Console.WriteLine("User profile set option:save all configuration with read plan");

                        r.ParamSet("/reader/userConfig", new SerialReader.UserConfigOp(SerialReader.UserConfigOperation.RESTORE));
                        Console.WriteLine("User profile set option:restore all configuration");

                        #region Create and add listeners

                        // Create and add tag listener
                        r.TagRead += delegate(Object sender, TagReadDataEventArgs e)
                        {
                            Console.WriteLine("Background read: " + e.TagReadData);
                            if (0 < e.TagReadData.Data.Length)
                            {
                                Console.WriteLine("  Data:" + ByteFormat.ToHex(e.TagReadData.Data, "", " "));
                            }
                        };

                        // Add reader stats listener
                        r.StatsListener += r_StatsListener;

                        #endregion Create and add listeners

                        r.ReceiveAutonomousReading();
                        Thread.Sleep(5000);
                    }
                    else
                    {
                        Console.WriteLine("Error: This codelet works only on M6e variants");
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("Error: " + ex.Message);
            }
        }
Exemplo n.º 29
0
        public void Add(TagReadData addData)
        {
            lock (new Object())
            {
                string key = null;

                if (tagdbSensorType == SensorType.Johar_106 || tagdbSensorType == SensorType.Johar_101)
                {
                    key = addData.EpcString.Substring(0, 4);
                    //Console.WriteLine("*** tagdb add key=" + key);
                }
                else
                {
                    if (chkbxUniqueByData)
                    {
                        if (true == chkbxShowFailedDataReads)
                        {
                            //key = addData.EpcString + ByteFormat.ToHex(addData.Data, "", " ");
                            // When CHECKED - Add the entry to the database. This will result in
                            // potentially two entries for every tag: one with the requested data and one without.
                            if (addData.Data.Length > 0)
                            {
                                key = addData.EpcString + ByteFormat.ToHex(addData.Data, "", " ");
                            }
                            else
                            {
                                key = addData.EpcString + "";
                            }
                        }
                        else if ((false == chkbxShowFailedDataReads) && (addData.Data.Length == 0))
                        {
                            // When UNCHECKED (default) - If the embedded read data fails (data.length==0) then don't add the entry to
                            // the database, thus it won't be displayed.
                            return;
                        }
                        else
                        {
                            key = addData.EpcString + ByteFormat.ToHex(addData.Data, "", " ");
                        }
                    }
                    else
                    {
                        key = addData.EpcString; //if only keying on EPCID
                    }
                }
                //if (chkbxUniqueByAntenna)
                //{
                //    key += addData.Antenna.ToString();
                //}
                //if (chkbxUniqueByFrequency)
                //{
                //    key += addData.Frequency.ToString();
                //}

                UniqueTagCounts = 0;
                TotalTagCounts  = 0;

                if (!EpcIndex.ContainsKey(key))
                {
                    TagReadRecord value = new TagReadRecord(addData);
                    value.SerialNumber  = (uint)EpcIndex.Count + 1;
                    value.SensorType    = tagdbSensorType;
                    value.SensorSubType = tagdbSensorSubType;
                    Console.WriteLine(string.Format("Sensor={0}, Sub={1}", tagdbSensorType, tagdbSensorSubType));

                    _tagList.Add(value);
                    EpcIndex.Add(key, value);
                    //Call this method to calculate total tag reads and unique tag read counts
                    UpdateTagCountTextBox(EpcIndex);
                    Console.WriteLine("tagdb add [" + key + "]");
                }
                else
                {
                    EpcIndex[key].SensorSubType = tagdbSensorSubType;
                    if (tagdbSensorType == SensorType.VBL)
                    {
                        if (tagdbSensorSubType == SensorSubType.VBL_TUNE)
                        {
                            if (EpcIndex[key].TuneValue.Trim().Equals(""))
                            {
                                EpcIndex[key].TuneValue = ByteFormat.ToHex(addData.Data, "", "");
                            }
                        }
                        else if (tagdbSensorSubType == SensorSubType.VBL_NValue)
                        {
                            EpcIndex[key].TemperatureCode = ByteFormat.ToHex(addData.Data, "", "");
                        }
                    }
                    if (tagdbSensorType == SensorType.RFMicronMagnusS3)
                    {
                        if (tagdbSensorSubType == SensorSubType.RFMicroMagnusS3_CalibratedCode)
                        {
                            if (EpcIndex[key].TuneValue.Trim().Equals(""))
                            {
                                EpcIndex[key].TuneValue = ByteFormat.ToHex(addData.Data, "", "");
                            }
                            else if (tagdbSensorSubType == SensorSubType.RFMicroMagnusS3_TemperatureCode)
                            {
                                EpcIndex[key].TemperatureCode = ByteFormat.ToHex(addData.Data, "", "");
                            }
                        }
                    }

                    EpcIndex[key].Update(addData); //ToDo update temperature
                    UpdateTagCountTextBox(EpcIndex);
                }
            }
        }
Exemplo n.º 30
0
        private double getJoharTemp(TagReadData RawRead, SensorType sensorType)
        {
            double temp = UNSPECTTEMP;

            //获取EPC
            byte[] bepc = RawRead.Tag.EpcBytes;
            if (RawRead.Data.Length > 0 && bepc.Count() >= 11)
            {
                byte[] buser = RawRead.Data;
                //Console.WriteLine("EPC={0}, USER={1}", ByteFormat.ToHex(bepc, "", ""), ByteFormat.ToHex(buser, "", ""));

                byte[] user8 = null;
                byte[] user9 = null;
                user8 = new byte[] { buser[0], buser[1] };
                if (buser.Length >= 4)
                {
                    user9 = new byte[] { buser[2], buser[3] };
                    //Console.WriteLine("user8={0}, user9={1}" + ByteFormat.ToHex(user8, "", ""), ByteFormat.ToHex(user9, "", ""));
                }

                //1.获取原始温度数据
                byte[] s06 = new byte[] { bepc[8], bepc[9] };
                byte[] s07 = new byte[] { bepc[10], bepc[11] };
                //Console.WriteLine("s06=" + ByteFormat.ToHex(s06, "", ""));
                //Console.WriteLine("s07=" + ByteFormat.ToHex(s07, "", ""));

                //2.得到SEN_DATA[23:0]
                string s_SEN_DATA = ByteFormat.ToHex(s06, "", "").Substring(1) + ByteFormat.ToHex(s07, "", "").Substring(1);
                //Console.WriteLine("s_SEN_DATA=" + s_SEN_DATA);
                int i_SEN_DATA = Convert.ToInt32(s_SEN_DATA, 16);
                //Console.WriteLine("i_SEN_DATA=" + i_SEN_DATA);

                //3.传感数据验证
                if (sensorType == SensorType.Johar_101)
                {
                    string s_HEADER1        = ByteFormat.ToHex(s06, "", "").Substring(0, 1);
                    string s_HEADER2        = ByteFormat.ToHex(s07, "", "").Substring(0, 1);
                    int    i_SEN_DATA_23_19 = (i_SEN_DATA & 0x00F80000) >> 19;
                    uint   B00100           = (0xFF20FFFF & 0x00F80000) >> 19;

                    //Console.WriteLine("s_HEADER1={0}, s_HEADER2={1}", s_HEADER1, s_HEADER2);
                    //Console.WriteLine("s_SEN_DATA_23_19={0}, B00100={1}", i_SEN_DATA_23_19, B00100);
                    if (!s_HEADER1.Equals("F") || !s_HEADER2.Equals("F") || i_SEN_DATA_23_19 != B00100)
                    {
                        Console.WriteLine("sensor data check failed!");
                        return(temp);
                    }
                }

                //4.获取校验参数
                int    delta1 = 0;
                double delta2 = 0;
                delta1 = ConvertDelta1(user8);
                delta2 = delta1 / 100d - 101d;
                //Console.WriteLine("d1=" + delta1 + ", d2=" + delta2);

                //5.获得摄氏度格式温度数据
                double D1 = (i_SEN_DATA & 0x00F80000) >> 19;
                double D2 = ((i_SEN_DATA & 0x0007FFF8) >> 3) & 0x0000FFFF;
                //Console.WriteLine("D1=" + D1 + ", D2=" + D2);
                string user9_15_12 = null; //读取user9的时候根据读取值设置,否则根据读取的芯片类型设置
                if (user9 != null)
                {
                    user9_15_12 = ByteFormat.ToHex(user9, "", "").Substring(0, 1);
                }
                else
                {
                    if (sensorType == SensorType.Johar_106)
                    {
                        user9_15_12 = "1";
                    }
                    else if (sensorType == SensorType.Johar_101)
                    {
                        user9_15_12 = "2";
                    }
                    else
                    {
                        user9_15_12 = "0";
                    }
                }
                //Console.WriteLine("user9_15_12={0}", user9_15_12);

                double temperature = 0.0;
                if (user9_15_12.Equals("0") || user9_15_12.Equals("1"))
                {
                    temperature = 11984.47 / (21.25 + D1 + (D2 / 2752) + delta2) - 301.57;
                }
                else if (user9_15_12.Equals("2"))
                {
                    double Treal_temp = 11109.6 / (24 + (D2 + delta1) / 375.3) - 290;
                    if (Treal_temp >= 125)
                    {
                        temperature = Treal_temp * 1.2 - 25;
                    }
                    else
                    {
                        temperature = Treal_temp;
                    }
                }
                //Console.WriteLine("temperature={0}", temperature);
                //temp = temperature;
                temp = Math.Round(temperature, 2);//保留两位小数
            }
            return(temp);
        }