Example #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();
        }
Example #2
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, "", " "));
         }
     }
 }
        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);
            }
        }
Example #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;
        }
Example #5
0
        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                rd = Reader.Create("192.168.1.101", ModuleTech.Region.NA, 4);
            }
            catch (Exception ex)
            {
                MessageBox.Show("连接失败,请检查读写器地址是否正确" + ex.ToString());

                return;
            }

            lst1.Items.Add("连接成功!");
            int[] connectedants = (int[])rd.ParamGet("ConnectedAntennas");
            for (int c = 0; c < connectedants.Length; ++c)
            {
                lst1.Items.Add(c + "->" + connectedants[c]);
            }
            TagFilter tf = (TagFilter)rd.ParamGet("Singulation");

            // rd.read

            int[]         ants   = new int[] { 1, 4 };
            Gen2TagFilter filter = new Gen2TagFilter(ByteFormat.FromHex("FFFFFFFF"), MemBank.EPC, 32, false);

            rd.ParamSet("Singulation", filter);
            SimpleReadPlan searchPlan = new SimpleReadPlan(ants);

            rd.ParamSet("ReadPlan", searchPlan);
        }
Example #6
0
 /// <summary>
 /// Write Untraceable operation to tag
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void btmWriteToTag_Click(object sender, RoutedEventArgs e)
 {
     try
     {
         if (((bool)rdBtnShowSpecificEpc.IsChecked) && (txtbxEpcLen.Text == ""))
         {
             MessageBox.Show("Please Enter length of EPC to Show", "Universal Reader Assistant Message", MessageBoxButton.OK, MessageBoxImage.Warning);
             return;
         }
         else
         {
             epcLen = 6;
         }
         antenna = ((null != GetSelectedAntennaList()) ? (GetSelectedAntennaList()[0]) : antenna);
         objReader.ParamSet("/reader/tagop/antenna", antenna);
         if ((bool)rdBtnShowSpecificEpc.IsChecked)
         {
             epcLen = Convert.ToInt32(txtbxEpcLen.Text);
         }
         Gen2.Password    accessPassWord = new Gen2.Password(ByteConv.ToU32(ByteFormat.FromHex(txtbxAccesspaasword.Text.Replace(" ", "")), 0));
         Gen2.Untraceable tagOp          = new Gen2.NXP.AES.Untraceable(epc, epcLen, tid, user, range, accessPassWord.Value);
         objReader.ExecuteTagOp(tagOp, searchSelect);
         MessageBox.Show("Write operation is successfull", "Universal Reader Assistant Message", MessageBoxButton.OK, MessageBoxImage.Information);
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
     }
 }
Example #7
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);
                }
            }
        }
Example #8
0
        private void SetReadPlan()
        {
            TagFilter filter = null;


            if (selectMemBank == Gen2.Bank.EPC)
            {
                if (txtEpc.Text != "")
                {
                    filter = new TagData(txtEpc.Text);
                }
            }
            else
            {
                byte[] data = ByteFormat.FromHex(txtData.Text);

                if (null == data)
                {
                    dataLength = 0;
                }
                else
                {
                    dataLength = data.Length;
                }

                filter = new Gen2.Select(false, selectMemBank, Convert.ToUInt16(startAddress * 16), Convert.ToUInt16(dataLength * 8), data);
            }

            SimpleReadPlan srp = new SimpleReadPlan(new int[] { antenna }, TagProtocol.GEN2, filter, 1000);

            objReader.ParamSet("/reader/read/plan", srp);
        }
Example #9
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("");
     }
 }
Example #10
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);
 }
Example #11
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, "", " "));
                    }
                }
            }
        }
Example #12
0
        /// <summary>
        /// Insert keys into tag
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnInsertKeys_Click(object sender, RoutedEventArgs e)
        {
            TagOp op;

            try
            {
                if (txtbxKeyOne.Text.Replace(" ", "").Length == 32 && txtbxKeyZero.Text.Replace(" ", "").Length == 32)
                {
                    byte[]   KeytoWrite = ByteFormat.FromHex(txtbxKeyZero.Text.Replace(" ", ""));
                    ushort[] Key0       = new ushort[KeytoWrite.Length / 2];
                    Key0 = ByteConv.ToU16s(KeytoWrite);
                    op   = new Gen2.WriteData(Gen2.Bank.USER, 0xC0, Key0);
                    objReader.ExecuteTagOp(op, searchSelect);

                    KeytoWrite = ByteFormat.FromHex(txtbxKeyOne.Text.Replace(" ", ""));
                    ushort[] Key1 = new ushort[KeytoWrite.Length / 2];
                    Key1 = ByteConv.ToU16s(KeytoWrite);
                    op   = new Gen2.WriteData(Gen2.Bank.USER, 0xD0, Key1);
                    objReader.ExecuteTagOp(op, searchSelect);
                    MessageBox.Show("Insert keys operation success", "Universal Reader Assistant", MessageBoxButton.OK, MessageBoxImage.Information);
                }
                else
                {
                    MessageBox.Show("Please input valid Keys to insert ", "Universal Reader Assistant", MessageBoxButton.OK, MessageBoxImage.Error);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Universal Reader Assistant", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
Example #13
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();
        }
Example #14
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)
            {
            }
        }
Example #15
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);
        }
Example #16
0
        /// <summary>
        /// Create new ByteValue, but default to base 1024
        /// </summary>
        ///
        /// <param name="value">The number value in the specified format</param>
        /// <param name="initialFormat">The initial format to parse the value as</param>
        /// <param name="numBase">he base for calculations, i.e. a megabyte is base 1000 but a mebibyte is 1024</param>
        public ByteValue(double value, ByteFormat initialFormat, int numBase = 1024)
        {
            Base = numBase;

            // Convert everything to bytes for ease of calculation
            switch (initialFormat)
            {
            case ByteFormat.B:
                Bytes = value;
                break;

            case ByteFormat.KB:
                Bytes = value * Math.Pow(numBase, 1);
                break;

            case ByteFormat.MB:
                Bytes = value * Math.Pow(numBase, 2);
                break;

            case ByteFormat.GB:
                Bytes = value * Math.Pow(numBase, 3);
                break;

            case ByteFormat.TB:
                Bytes = value * Math.Pow(numBase, 4);
                break;
            }
        }
Example #17
0
        void ReConnect(Mach mc)
        {
            int    i, j, k;
            String Ret = "";

            if (mc.ReConnectedCount > 5)
            {
                /*本设备重连超过五次不成功,可能连接存在问题
                 */

                MyManager.AddInfoToDB("错误", mc.MachName + "重连5次不成功,不再尝试连接。");
                return;
            }

            try
            {
                mc.ReConnectedCount++;

                MyManager.AddInfoToDB("信息", mc.MachName + "开始重连.");
                mc.rd = Reader.Create(mc.MachIP, ModuleTech.Region.NA, 4);

                int[] connectedants = (int[])mc.rd.ParamGet("ConnectedAntennas");

                if (connectedants.Length < 1)
                {
                    Ret = "";
                    int[] xx = { 0, 0, 0, 0 };
                    for (j = 0; j < connectedants.Length; j++)
                    {
                        xx[connectedants[j] - 1] = 1;
                    }
                    for (k = 0; k < 4; k++)
                    {
                        if (xx[k] == 0)
                        {
                            Ret += (k + 1).ToString() + " ";
                        }
                    }
                    Ret = mc.MachName + "," + Ret + "号天线未连接!!";
                    MyManager.AddInfoToDB("错误", Ret);
                }
                mc.ConnectedAnts = (int[])connectedants.Clone();
                Gen2TagFilter filter = new Gen2TagFilter(ByteFormat.FromHex("FFFFFFFF"), MemBank.EPC, 32, false);
                mc.rd.ParamSet("Singulation", filter);
                SimpleReadPlan searchPlan = new SimpleReadPlan(mc.ConnectedAnts);
                mc.rd.ParamSet("ReadPlan", searchPlan);
                mc.Mthread = new Thread(new ParameterizedThreadStart(TagMonitorThread));
                mc.Mthread.Start(mc);
                MyManager.AddInfoToDB("信息", mc.MachName + "重连并启动监视线程成功!");
                mc.ReConnectedCount--;
            }
            catch (Exception ex)
            {
                Ret = mc.MachName + ",重连-->" + ex.ToString();
                MyManager.AddInfoToDB("错误", Ret);
                ReConnect(mc);
            }
            mc.ReConnectedCount = 0;
        }
Example #18
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, "", " ");
        }
Example #19
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,
     }));
 }
Example #20
0
        private void btnWrite_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                Mouse.SetCursor(Cursors.Wait);
                Window   mainWindow         = App.Current.MainWindow;
                ComboBox CheckRegionCombobx = (ComboBox)mainWindow.FindName("regioncombo");
                if (CheckRegionCombobx.SelectedValue.ToString() == "Select")
                {
                    MessageBox.Show("Please select region", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                    return;
                }
                if ((bool)rbFirstTag.IsChecked)
                {
                    antenna = ((null != GetSelectedAntennaList()) ? (GetSelectedAntennaList()[0]) : antenna);
                }

                objReader.ParamSet("/reader/tagop/antenna", antenna);

                if ((bool)rbSelectedTag.IsChecked)
                {
                    TagFilter searchSelect = null;


                    if (lblSelectFilter.Content.ToString().Contains("EPC ID"))
                    {
                        searchSelect = new TagData(txtEpc.Text);
                    }
                    else
                    {
                        byte[] SearchSelectData = ByteFormat.FromHex(txtData.Text);
                        if (null == SearchSelectData)
                        {
                            dataLength = 0;
                        }
                        else
                        {
                            dataLength = SearchSelectData.Length;
                        }

                        searchSelect = new Gen2.Select(false, selectMemBank, Convert.ToUInt16(startAddress * 16), Convert.ToUInt16(dataLength * 8), SearchSelectData);
                    }
                    WriteEPC(searchSelect, txtWriteEPC.Text);
                }
                else
                {
                    WriteEPC(null, txtWriteEPC.Text);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
            }
            finally
            {
                Mouse.SetCursor(Cursors.Arrow);
            }
        }
Example #21
0
    /// <exception cref="TextFormatNotSupportedException">Text-formatted GBX files are not supported.</exception>
    internal bool Read(GameBoxReader reader)
    {
        if (!reader.HasMagic(GameBox.Magic))
        {
            Log.Write("GBX magic missing! Corrupted file or not a GBX file.", ConsoleColor.Red);
            return(false);
        }

        Log.Write("GBX recognized!", ConsoleColor.Green);

        Version = reader.ReadInt16();
        Log.Write("- Version: " + Version.ToString());

        if (Version >= 3)
        {
            ByteFormat = (GameBoxByteFormat)reader.ReadByte();
            Log.Write("- Byte format: " + ByteFormat.ToString());

            if (ByteFormat == GameBoxByteFormat.Text)
            {
                throw new TextFormatNotSupportedException();
            }

            CompressionOfRefTable = (GameBoxCompression)reader.ReadByte();
            Log.Write("- Ref. table compression: " + CompressionOfRefTable.ToString());

            CompressionOfBody = (GameBoxCompression)reader.ReadByte();
            Log.Write("- Body compression: " + CompressionOfBody.ToString());

            if (Version >= 4)
            {
                UnknownByte = (char)reader.ReadByte();
                Log.Write("- Unknown byte: " + UnknownByte.ToString());
            }

            ID = CMwNod.Remap(reader.ReadUInt32());
            Log.Write("- Class ID: 0x" + ID.Value.ToString("X8"));

            if (Version >= 6)
            {
                var userDataSize = reader.ReadInt32();
                Log.Write($"- User data size: {(userDataSize / 1024f).ToString()} kB");

                if (userDataSize > 0)
                {
                    UserData = reader.ReadBytes(userDataSize);
                }
            }

            NumNodes = reader.ReadInt32();
            Log.Write("- Number of nodes: " + NumNodes.ToString());
        }

        Log.Write("Header completed!", ConsoleColor.Green);

        return(true);
    }
Example #22
0
        public void TestByteUnsignedRange()
        {
            ByteFormat bFormat      = new ByteFormat();
            int        expectedUMax = bFormat.GetUMax();
            int        expectedUMin = bFormat.GetUMin();

            Assert.AreEqual(expectedUMax, 255);
            Assert.AreEqual(expectedUMin, 0);
        }
Example #23
0
        public void TestByteSignedRange()
        {
            ByteFormat bFormat     = new ByteFormat();
            int        expectedMax = bFormat.GetSMax();
            int        expectedMin = bFormat.GetSMin();

            Assert.AreEqual(expectedMax, 127);
            Assert.AreEqual(expectedMin, -128);
        }
Example #24
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);
                }
            }
        }
Example #25
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
                                        ));
 }
Example #26
0
 /// <summary>
 /// Get the value in a given ByteFormat
 /// </summary>
 ///
 /// <param name="format">The target format</param>
 ///
 /// <returns>The value in the given ByteFormat</returns>
 public double Get(ByteFormat format)
 {
     return(format switch
     {
         ByteFormat.B => Bytes,
         ByteFormat.KB => Kilobytes,
         ByteFormat.MB => Megabytes,
         ByteFormat.GB => Gigabytes,
         ByteFormat.TB => Terabytes,
         _ => - 1,
     });
Example #27
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, "", " "));
 }
Example #28
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), "", " ");
            }
        }
Example #29
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());
                }
            }
        }
Example #30
0
        public static List <byte> Get14443AMemory(Reader reader, Iso14443a.TagType tag, ref byte blockCount, string UID)
        {
            List <byte> data = new List <byte>();

            byte[]    _uid      = ByteFormat.FromHex(UID);
            TagFilter tagFilter = new Select_UID((byte)(_uid.Length * 8), _uid);

            string[] block = Get14443AMemoryLayout(tag);

            data = GetTagData(reader, tagFilter, Convert.ToInt32(block[0]), 0, ref blockCount);
            return(data);
        }