private async void Button_GetSensor_ClickAsync(object sender, RoutedEventArgs e) { //GetSensor --> Search for TELID® transponders if (m_DocInterface != null) { if (m_DocInterface.IsInitialized) { DateTime startTime = DateTime.UtcNow; //This function blocks & searches for a default time of 1 second (optional parameter) try { textBox_ThreadLog.Text += "\n = GetSensor =\n"; var getSensorResult = await m_DocInterface.GetSensorDataAsync(0xFC); //0xFC = scan all TELID® types TimeSpan processSpan = DateTime.UtcNow - startTime; if (getSensorResult != null) { textBox_Result.Text = "- TELID® found -\n"; textBox_Result.Text += string.Format("SerNo: {0}\n", getSensorResult.SerialNumber); textBox_Result.Text += string.Format("Description: {0}\n", getSensorResult.Description); textBox_Result.Text += "Measurements:\n"; foreach (var meas in getSensorResult.Measurements) { textBox_Result.Text += string.Format("\tTimestamp: {0}\n", meas.Timestamp); textBox_Result.Text += "\tValues:\n"; foreach (var value in meas.Values) { textBox_Result.Text += string.Format("\t {0}{1}{2}\n", value.Symbol, value.Magnitude, value.Unit); } } string toLog = string.Format("Result: OK. Duration: {0}\n", processSpan); toLog += "- Sensor Result -\n"; toLog += string.Format("\tSerNo: {0}\n", getSensorResult.SerialNumber); toLog += string.Format("\tNumMeas: {0}\n", getSensorResult.Measurements.Length); 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 async System.Threading.Tasks.Task Console_Execute_GetSensorAsync(DocInterfaceControl _docIntControl) { //First make sure DocInterfaceControl is initialized if (_docIntControl != null) { if (_docIntControl.IsInitialized) { try { //This function blocks & searches for a default time of 1 second (optional parameter) DateTime startTime = DateTime.UtcNow; //GetSensor --> Search for TELID® transponders var getSensorResult = await _docIntControl.GetSensorDataAsync(0xFC); //0xFC = scan all TELID® types TimeSpan processSpan = DateTime.UtcNow - startTime; if (getSensorResult != null) { Console.WriteLine(""); Console.WriteLine("SensorResult:"); Console.WriteLine(string.Format("SerNo: {0}", getSensorResult.SerialNumber)); Console.WriteLine(string.Format("Description: {0}", getSensorResult.Description)); Console.WriteLine("Measurements:"); foreach (var meas in getSensorResult.Measurements) { Console.WriteLine(string.Format("\tTimestamp: {0}", meas.Timestamp)); Console.WriteLine("\tValues:"); foreach (var value in meas.Values) { Console.WriteLine(string.Format("\t {0}{1}{2}", value.Symbol, value.Magnitude, value.Unit)); } } 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!"); } } }