问题遇到的现象和发生背景 读不出数据
问题相关代码,请勿粘贴截图 using NLE.Device.UHF;
using NLE.Device.UHF;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using System.Windows.Threading;
namespace WpfApplication1
{
public partial class UHFWindow : Window
{
private UHFReader rfidDevice = new UHFReader("COM7");
private DispatcherTimer dispatcherTimer;
public UHFWindow()
{
InitializeComponent();
dispatcherTimer = new DispatcherTimer();
dispatcherTimer.Tick += DispatcherTimer_Tick;
dispatcherTimer.Interval = new TimeSpan(0, 0, 1);
}
private void DispatcherTimer_Tick(object sender, EventArgs e)
{
ThreadPool.QueueUserWorkItem(o =>
{
if (rfidDevice != null)
{
string[] rfids = rfidDevice.ReadEpcSection();
if (rfids.Length > 0)
{
if (Application.Current.Dispatcher.Thread != System.Threading.Thread.CurrentThread)
{
Application.Current.Dispatcher.Invoke(new Action(() =>
{
foreach (var item in rfids)
txtUHF.Text += item + "\r\n";
}));
}
}
}
});
}
private void btnUHF_Click(object sender, RoutedEventArgs e)
{
dispatcherTimer.Start();
//if (rfidDevice != null)
//{
// string[] rfids = rfidDevice.ReadEpcSection();
// if (rfids.Length > 0)
// {
// foreach (var item in rfids)
// txtUHF.Text += item + "\r\n";
// }
//}
}
private void Window_Loaded(object sender, RoutedEventArgs e)
{
if (!rfidDevice.Connect())
{
MessageBox.Show("未能打开中距离串口");
}
}
}
}