private void Button_ReadBytes_Click(object sender, RoutedEventArgs e) { textBox_DataRead.Text = ""; if (comboBox_TagID.SelectedIndex == -1) { //For ReadBytes the UID must be already read using "Identify" MessageBox.Show(this, "Identifier is needed --> Call Identify first"); return; } //Get parameters from Window int from = int.Parse(textBox_From.Text); int length = int.Parse(textBox_Length.Text); int page = int.Parse(textBox_Page.Text); byte[] tagID = iIDReaderLibrary.Utils.HelperFunctions.HexConverter.ToByteArray(comboBox_TagID.Text.Replace("-", " ")); if (m_DocInterface != null) { if (m_DocInterface.IsInitialized) { DateTime startTime = DateTime.UtcNow; try { textBox_ThreadLog.Text += "\n = ReadBytes =\n"; var result = m_DocInterface.ReadBytes(tagID, page, from, length); TimeSpan processSpan = DateTime.UtcNow - startTime; if (result != null) { //Update result in UI textBox_DataRead.Text = BitConverter.ToString(result); string toLog = string.Format("Result: OK. Duration: {0}\n", processSpan); toLog += string.Format("\tPage: {0}\n", page); toLog += string.Format("\tStartByte: {0}, Length: {1}\n", from, length); toLog += string.Format(" DataRead: {0}", BitConverter.ToString(result)); toLog += "\n"; textBox_ThreadLog.Text += toLog; textBox_ThreadLog.ScrollToEnd(); } else { //Update result in UI textBox_ThreadLog.Text += string.Format("Result: FAIL. Duration: {0}\n", processSpan); textBox_ThreadLog.ScrollToEnd(); } } catch (Exception ex) { TimeSpan processSpan = DateTime.UtcNow - startTime; textBox_ThreadLog.Text += string.Format("Result: Exception. Duration: {0}\n", processSpan); textBox_ThreadLog.ScrollToEnd(); System.Diagnostics.Debug.WriteLine(ex.ToString()); } } } }
private static void Console_Execute_ReadBytes(DocInterfaceControl _docIntControl) { //ReadBytes function needs a Tag ID as parameter --> Obtained using "Identify" if (m_LastTagID == null) { Console.WriteLine("Perform \"Identify\" until a transponder is found before calling ReadBytes"); return; } //First make sure DocInterfaceControl is initialized if (_docIntControl != null) { if (_docIntControl.IsInitialized) { try { Console.WriteLine(""); Console.WriteLine("Reading 16 Bytes from position 0 (for UHF using page 3)"); DateTime startTime = DateTime.UtcNow; //Call ReadBytes and show result // TagID --> m_LastTagID (contains TagID found in last call to Identify) // Page --> 3 (for HF tags not needed, for UHF page 3 is user-block) // From --> 0 (first byte in memory) // Length --> 16 (Bytes 0 - 15 will be read) var readResult = _docIntControl.ReadBytes(m_LastTagID, 3, 0, 16); TimeSpan processSpan = DateTime.UtcNow - startTime; if (readResult != null) { Console.Write("Data read:"); Console.WriteLine(BitConverter.ToString(readResult)); Console.WriteLine(string.Format("(Duration: {0})", processSpan)); } else { //Update result in UI Console.WriteLine(string.Format("Result: FAIL. Duration: {0}", processSpan)); } } catch { Console.WriteLine("Exception"); } } else { Console.WriteLine("DocInterfaceControl not initialized!"); } } }