private void Button_WriteBytes_Click(object sender, RoutedEventArgs e) { if (comboBox_TagID.SelectedIndex == -1) { //For Writebytes 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("-", " ")); //Initialize bytes to write => length defined in TextBox byte[] dataToWrite = new byte[length]; //Get data to write from TextBox & convert from HEX-String string[] aux = textBox_DataToWriteHex.Text.Split(new char[] { ' ', '-' }); if (aux.Length < length) { MessageBox.Show(this, "Not enough data available to write in TextBox"); return; } int j = 0; foreach (string str in aux) { if (str.Equals(" ")) { continue; } try { dataToWrite[j] = Convert.ToByte(str, 16); } catch { MessageBox.Show(this, "Error converting from HEX"); return; } j++; } if (m_DocInterface != null) { if (m_DocInterface.IsInitialized) { //This functions starts the "WriteBytes" process in a new thread, and reports the result using "DocResultChanged" event m_DocInterface.StartWriteBytes(tagID, page, from, dataToWrite); textBox_ThreadLog.Text += "\n = StartWriteBytes =\n"; textBox_ThreadLog.ScrollToEnd(); progressBar.IsIndeterminate = true; mLastDocResultTimestamp = DateTime.Now; } } }
private static void Console_Execute_WriteBytes(DocInterfaceControl _docIntControl) { //WriteBytes 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 WriteBytes"); return; } //First make sure DocInterfaceControl is initialized if (_docIntControl != null) { if (_docIntControl.IsInitialized) { Console.WriteLine(""); Console.WriteLine("Writing \"00-11-22-33-44-55-66-77-88-99-AA-BB-CC-DD-EE-FF\" from position 0 (for UHF using page 3)"); byte[] toWrite = new byte[] { 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF }; docOperationCompleted = false; //Start WriteBytes // TagID --> m_LastTagID (contins first 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) // Data --> "toWrite" array containing the data to be written _docIntControl.StartWriteBytes(m_LastTagID, 3, 0, toWrite); //For demo purposes, just wait blocking execution until DOC process is completed (notified using "DocResultChanged" event, ProcessFinished = true) while (!docOperationCompleted) { Thread.Sleep(100); } Console.WriteLine(""); } else { Console.WriteLine("DocInterfaceControl not initialized!"); } } }