private static void DocInterfaceControl_DocResultChanged(object sender, DocResultEventArgs _docResult) { if (_docResult != null) { Console.WriteLine(_docResult.Timestamp.ToString("HH:mm:ss,fff")); if (_docResult.ResultInfo != null) { if (_docResult.ResultInfo is TELIDSensorResultInfo getSensorResult) { //Result to GetSensorData Console.WriteLine("SensorResult:"); Console.WriteLine(string.Format("\tSerNo: {0}", getSensorResult.SerialNumber)); Console.WriteLine(string.Format("\tDescription: {0}", getSensorResult.Description)); Console.WriteLine("\tMeasurements:"); foreach (var meas in getSensorResult.Measurements) { Console.WriteLine(string.Format("\t\tTimestamp: {0}", meas.Timestamp)); Console.WriteLine("\t\tValues:"); foreach (var value in meas.Values) { Console.WriteLine(string.Format("\t\t {0}{1}{2}", value.Symbol, value.Magnitude, value.Unit)); } } } } else { if (_docResult.ProcessFinished) { docOperationCompleted = true; Console.WriteLine("\tDOC function END"); return; } else { Console.WriteLine("\tResultInfo = NULL"); return; } } if (_docResult.ResultException != null) { Console.WriteLine("\tException! "); System.Diagnostics.Debug.WriteLine(_docResult.ResultException.ToString()); } } }
private void DocInterface_DocResultChanged(object sender, DocResultEventArgs _docResult) { if (_docResult != null) { TimeSpan span = DateTime.Now - mLastDocResultTimestamp; if (_docResult.ResultInfo != null) { if (_docResult.ResultInfo is HfScanResultInfo) { //Result to Identify - InterfaceType = 1356 Dispatcher.Invoke(() => { //Update result in UI - For demo purposes done using "Dispatcher.Invoke" string tagIdStr = BitConverter.ToString((_docResult.ResultInfo as HfScanResultInfo).TagID); string toLog = string.Format("{0} (Duration: {1})\n", _docResult.Timestamp, span); toLog += "- HF ScanResult -\n"; toLog += string.Format("\t{0}", tagIdStr); toLog += "\n"; textBox_ThreadLog.Text += toLog; textBox_ThreadLog.ScrollToEnd(); bool alreadyInComboBox = false; foreach (string str in comboBox_TagID.Items) { if (str.CompareTo(tagIdStr) == 0) { alreadyInComboBox = true; break; } } if (!alreadyInComboBox) { comboBox_TagID.Items.Add(tagIdStr); //Select first ID to be used in ReadBytes/WriteBytes comboBox_TagID.SelectedIndex = 0; if (comboBox_TagID.Items.Count > 1) { comboBox_TagID.IsEnabled = true; } } }); } if (_docResult.ResultInfo is UhfScanResultInfo) { //Result to Identify - InterfaceType = 868 Dispatcher.Invoke(() => { //Update result in UI - For demo purposes done using "Dispatcher.Invoke" string toLog = string.Format("{0} (Duration: {1})\n", _docResult.Timestamp, span); toLog += "- UHF ScanResult -\n"; toLog += " Ant\tUII-Bytes\n"; var uhfScanResult = (_docResult.ResultInfo as UhfScanResultInfo); foreach (var tsi in uhfScanResult.TagInfoList) { string tagIdStr = BitConverter.ToString(tsi.UII.UII); toLog += string.Format(" {0}\t{1}\n", tsi.AntennaNumber, tagIdStr); bool alreadyInComboBox = false; foreach (string str in comboBox_TagID.Items) { if (str.CompareTo(tagIdStr) == 0) { alreadyInComboBox = true; break; } } if (!alreadyInComboBox) { comboBox_TagID.Items.Add(tagIdStr); //Select first UII to be used in ReadBytes/WriteBytes comboBox_TagID.SelectedIndex = 0; if (comboBox_TagID.Items.Count > 1) { comboBox_TagID.IsEnabled = true; } } } textBox_ThreadLog.Text += toLog; textBox_ThreadLog.ScrollToEnd(); }); } if (_docResult.ResultInfo is ReadBytesResultInfo) { //Result to ReadBytes var readResult = (_docResult.ResultInfo as ReadBytesResultInfo); if (readResult.ReadResult != null) { //Data read Dispatcher.Invoke(() => { //Update result in UI - For demo purposes done using "Dispatcher.Invoke" string readBytesStr = BitConverter.ToString(readResult.ReadResult); string toLog = string.Format("{0} (Duration: {1})\n", _docResult.Timestamp, span); toLog += "- ReadBytesResult -\n"; toLog += string.Format("\tPage: {0}\n", readResult.FromPage); toLog += string.Format("\tStartByte: {0}, Length: {1}\n", readResult.FromByte, readResult.ReadResult.Length); toLog += string.Format(" DataRead: {0}", readBytesStr); toLog += "\n"; textBox_ThreadLog.Text += toLog; textBox_ThreadLog.ScrollToEnd(); textBox_DataRead.Text = readBytesStr; }); } if (_docResult.ProcessFinished) { ThreadProcessFinished(); } } if (_docResult.ResultInfo is WriteBytesResultInfo) { //Result to WriteBytes var writeResult = (_docResult.ResultInfo as WriteBytesResultInfo); if (writeResult.WriteResult) { //Data written Dispatcher.Invoke(() => { //Update result in UI - For demo purposes done using "Dispatcher.Invoke" string writtenBytesStr = BitConverter.ToString(writeResult.WrittenBytes); string toLog = string.Format("{0} (Duration: {1})\n", _docResult.Timestamp, span); toLog += "- WriteBytesResult -\n"; toLog += " WRITTEN\n"; toLog += string.Format("\tPage: {0}\n", writeResult.FromPage); toLog += string.Format("\tStartByte: {0}, Length: {1}\n", writeResult.FromByte, writeResult.WrittenBytes.Length); toLog += string.Format(" DataWritten: {0}", writtenBytesStr); toLog += "\n"; textBox_ThreadLog.Text += toLog; textBox_ThreadLog.ScrollToEnd(); }); } if (_docResult.ProcessFinished) { ThreadProcessFinished(); } } } else { if (_docResult.ProcessFinished) { ThreadProcessFinished(); return; } Dispatcher.Invoke(() => { textBox_ThreadLog.Text += string.Format("{0} (Duration: {1})\n ResultInfo = NULL\n", _docResult.Timestamp, span); textBox_ThreadLog.ScrollToEnd(); }); } if (_docResult.ResultException != null) { Dispatcher.Invoke(() => { textBox_ThreadLog.Text += string.Format("{0} (Duration: {1})\n Result: Exception\n", _docResult.Timestamp, span); textBox_ThreadLog.ScrollToEnd(); }); System.Diagnostics.Debug.WriteLine(_docResult.ResultException.ToString()); } mLastDocResultTimestamp = DateTime.Now; } }
private static void DocInterfaceControl_DocResultChanged(object sender, DocResultEventArgs _docResult) { // this will be called for each result if (_docResult != null) { Console.WriteLine(_docResult.Timestamp.ToString("HH:mm:ss,fff")); if (_docResult.ResultInfo != null) { if (_docResult.ResultInfo is HfScanResultInfo) { //Result to Identify - InterfaceType = 1356 Console.WriteLine("\t" + BitConverter.ToString((_docResult.ResultInfo as HfScanResultInfo).TagID)); //Save UID for "ReadBytes"/"WriteBytes" process m_LastTagID = (_docResult.ResultInfo as HfScanResultInfo).TagID; } if (_docResult.ResultInfo is UhfScanResultInfo) { //Result to Identify - InterfaceType = 868 var uhfScanResult = (_docResult.ResultInfo as UhfScanResultInfo); Console.WriteLine("\t" + uhfScanResult.ToString().Replace("\n", "\n\t")); if (uhfScanResult.TagInfoList.Count > 0) { m_LastTagID = uhfScanResult.TagInfoList[0].UII.UII; } } if (_docResult.ResultInfo is ReadBytesResultInfo) { //Result to ReadBytes var readResult = _docResult.ResultInfo as ReadBytesResultInfo; if (readResult.ReadResult != null) { //Data read Console.WriteLine("\tRead completed:"); Console.WriteLine("\t\tPage: {0}", readResult.FromPage); Console.WriteLine("\t\tStartByte: {0}, Length: {1}", readResult.FromByte, readResult.ReadResult.Length); Console.WriteLine("\t DataRead: {0}", BitConverter.ToString(readResult.ReadResult)); } if (_docResult.ProcessFinished) { docOperationCompleted = true; Console.WriteLine("\tDOC function END"); return; } } if (_docResult.ResultInfo is WriteBytesResultInfo) { //Result to WriteBytes var writeResult = (_docResult.ResultInfo as WriteBytesResultInfo); if (writeResult.WriteResult) { //Data written Console.WriteLine("\tWrite completed:"); Console.WriteLine("\t\tPage: {0}", writeResult.FromPage); Console.WriteLine("\t\tStartByte: {0}, Length: {1}", writeResult.FromByte, writeResult.WrittenBytes.Length); Console.WriteLine("\t DataWritten: {0}", BitConverter.ToString(writeResult.WrittenBytes)); } if (_docResult.ProcessFinished) { docOperationCompleted = true; Console.WriteLine("\tDOC function END"); return; } } } else { if (_docResult.ProcessFinished) { docOperationCompleted = true; Console.WriteLine("\tDOC function END"); return; } else { Console.WriteLine("\tResultInfo = NULL"); return; } } if (_docResult.ResultException != null) { Console.WriteLine("\tException! "); System.Diagnostics.Debug.WriteLine(_docResult.ResultException.ToString()); } } }
private void DocInterface_DocResultChanged(object sender, DocResultEventArgs _docResult) { if (_docResult != null) { TimeSpan span = DateTime.Now - mLastDocResultTimestamp; if (_docResult.ResultInfo != null) { if (_docResult.ResultInfo is TELIDSensorResultInfo getSensorResult) { //Result to GetSensorData Dispatcher.Invoke(() => { //Update result in UI - For demo purposes done using "Dispatcher.Invoke" string toLog = string.Format("{0} (Duration: {1})\n", _docResult.Timestamp, span); toLog += "- TELID SensorResult -\n"; if (getSensorResult != null) { toLog += string.Format("SerNo: {0}\n", getSensorResult.SerialNumber); toLog += string.Format("Description: {0}\n", getSensorResult.Description); toLog += "Measurements:\n"; foreach (var meas in getSensorResult.Measurements) { toLog += string.Format("\tTimestamp: {0}\n", meas.Timestamp); toLog += "\tValues:\n"; foreach (var value in meas.Values) { toLog += string.Format("\t {0}{1}{2}\n", value.Symbol, value.Magnitude, value.Unit); } } toLog += "\n"; textBox_Result.Text += toLog; textBox_Result.ScrollToEnd(); toLog = string.Format("Result: OK. Duration: {0}\n", span); 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 { if (_docResult.ProcessFinished) { ThreadProcessFinished(); return; } Dispatcher.Invoke(() => { textBox_ThreadLog.Text += string.Format("{0} (Duration: {1})\n ResultInfo = NULL\n", _docResult.Timestamp, span); textBox_ThreadLog.ScrollToEnd(); }); } if (_docResult.ResultException != null) { Dispatcher.Invoke(() => { textBox_ThreadLog.Text += string.Format("{0} (Duration: {1})\n Result: Exception\n", _docResult.Timestamp, span); textBox_ThreadLog.ScrollToEnd(); }); System.Diagnostics.Debug.WriteLine(_docResult.ResultException.ToString()); } mLastDocResultTimestamp = DateTime.Now; } }