private void timerWrite_Tick(object sender, EventArgs e) { byte[] dataBytes = EMCardEncoder.ReadBytes(maskedTextBoxWrite.Text); if (dataBytes == null) { throw new ArgumentNullException("data"); } if (dataBytes.Length == 0) { throw new ArgumentException("Data must be provided", "data"); } if (dataBytes.Length != 5) { throw new ArgumentException("Provided data must be 5 bytes", "data"); } // Check if there is a message pending byte[] ack = emCardEncoder.ReadMessage(); if (ByteArrayCompare(ack, dataBytes)) { maskedTextBoxRead.Text = (EMCardEncoder.FormatBytes(ack)); timerRead.Enabled = false; } else { emCardEncoder.SendWrite(dataBytes, writeProtect); Thread.Sleep(250); ack = emCardEncoder.ReadMessage(); emCardEncoder.SendRead(); Thread.Sleep(50); ack = emCardEncoder.ReadMessage(); } }
private void timerPoll_Tick(object sender, EventArgs e) { // Check if there is a message pending byte[] ack = emCardEncoder.ReadMessage(); if ((ack != null) && (ack.Length > 0)) { maskedTextBoxRead.Text = (EMCardEncoder.FormatBytes(ack)); } else { emCardEncoder.SendRead(); } }
public static void Poll(string port) { using (var emCardEncoder = new EMCardEncoder()) { emCardEncoder.Open(port); while (true) { emCardEncoder.SendRead(); Thread.Sleep(50); byte[] ack = emCardEncoder.ReadMessage(); if ((ack != null) && (ack.Length > 0)) { System.Console.WriteLine(EMCardEncoder.FormatBytes(ack)); } } } }
public static void Hello(string port) { using (var emCardEncoder = new EMCardEncoder()) { emCardEncoder.Open(port); emCardEncoder.SendHello(); Thread.Sleep(50); byte[] ack = emCardEncoder.ReadMessage(); if ((ack != null) && (ack.Length > 0)) { System.Console.WriteLine(EMCardEncoder.FormatBytes(ack)); } else if ((ack != null) && (ack.Length == 0)) { System.Console.WriteLine("ACK"); } } }
public static void Write(string port, string data, bool wait, bool writeProtect) { byte[] dataBytes = EMCardEncoder.ReadBytes(data); if (dataBytes == null) { throw new ArgumentNullException("data"); } if (dataBytes.Length == 0) { throw new ArgumentException("Data must be provided", "data"); } if (dataBytes.Length != 5) { throw new ArgumentException("Provided data must be 5 bytes", "data"); } using (var emCardEncoder = new EMCardEncoder()) { emCardEncoder.Open(port); byte[] ack = null; do { emCardEncoder.SendWrite(dataBytes, writeProtect); Thread.Sleep(250); ack = emCardEncoder.ReadMessage(); Thread.Sleep(50); emCardEncoder.SendRead(); Thread.Sleep(50); ack = emCardEncoder.ReadMessage(); }while ((!ByteArrayCompare(ack, dataBytes)) && wait); if ((ack != null) && (ack.Length > 0)) { System.Console.WriteLine(EMCardEncoder.FormatBytes(ack)); } else if ((ack != null) && (ack.Length == 0)) { System.Console.WriteLine("ACK"); } } }
private void buttonWrite_Click(object sender, EventArgs e) { byte[] dataBytes = EMCardEncoder.ReadBytes(maskedTextBoxWrite.Text); if (dataBytes == null) { throw new ArgumentNullException("data"); } if (dataBytes.Length == 0) { throw new ArgumentException("Data must be provided", "data"); } if (dataBytes.Length != 5) { throw new ArgumentException("Provided data must be 5 bytes", "data"); } if (emCardEncoder != null) { byte[] ack = null; do { emCardEncoder.SendWrite(dataBytes, writeProtect); Thread.Sleep(250); ack = emCardEncoder.ReadMessage(); emCardEncoder.SendRead(); Thread.Sleep(50); ack = emCardEncoder.ReadMessage(); }while ((!ByteArrayCompare(ack, dataBytes)) && wait); if ((ack != null) && (ack.Length > 0)) { maskedTextBoxRead.Text = (EMCardEncoder.FormatBytes(ack)); } } }
private void comboBoxPortNames_SelectedIndexChanged(object sender, EventArgs e) { port = null; if (emCardEncoder != null) { emCardEncoder.Close(); emCardEncoder.Dispose(); emCardEncoder = null; } string selectedPort = comboBoxPortNames.SelectedItem as string; try { emCardEncoder = new EMCardEncoder(); emCardEncoder.Open(selectedPort); emCardEncoder.SendHello(); Thread.Sleep(50); byte[] ack = emCardEncoder.ReadMessage(); if ((ack != null) && (ack.Length == 0)) { port = selectedPort; } else { port = null; emCardEncoder.Close(); emCardEncoder.Dispose(); emCardEncoder = null; } } catch (Exception) { } TogglePortCorrect(); }
private void buttonRead_Click(object sender, EventArgs e) { if (wait) { timerRead.Enabled = true; return; } if (emCardEncoder != null) { byte[] ack = null; do { emCardEncoder.SendRead(); Thread.Sleep(50); ack = emCardEncoder.ReadMessage(); }while ((ack == null) && wait); if ((ack != null) && (ack.Length > 0)) { maskedTextBoxRead.Text = (EMCardEncoder.FormatBytes(ack)); } } }