【发布时间】:2023-04-06 02:47:01
【问题描述】:
我正在开发一个基于在 Rasperry PI 3 上运行的 Windows 10 IoT 的 NFC 阅读器项目。
我使用库 Mfrc522lib.cs 在这里找到:RFID RC522 Raspberry PI 2 Windows IOT。 我使用异步任务来等待卡片。它第一次扫描完美,但是当我再次开始任务时(用于带有按钮的测试 puprose)。 我明白了:
Pin ' is currently opened in an incompatible sharing mode. Make sure this pin is not already in use by this application or another Application
有什么想法吗?
public MainPage()
{
this.InitializeComponent();
startNFC();
}
public void startNFC()
{
var read = ReadNFCAsync();
Windows.ApplicationModel.Core.CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal,
() =>
{
// Your UI update code goes here!
this.serial.Text = "Klar for å lese kortet ditt";
this.statusline.Fill = new SolidColorBrush(Colors.Green);
});
read.ContinueWith(prev => {
Windows.ApplicationModel.Core.CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal,
() =>
{
// Your UI update code goes here!
this.serial.Text = prev.Result.ToString();
this.statusline.Fill = new SolidColorBrush(Colors.Orange);
});
});
}
public static async Task<String> ReadNFCAsync()
{
await Task.Delay(1000);
var mfrc = new Mfrc522();
await mfrc.InitIO();
while (true)
{
if (mfrc.IsTagPresent())
{
var uid = mfrc.ReadUid();
var serial= uid.ToString();
mfrc.HaltTag();
return serial;
}
}
}
private async void Button_Click(object sender, RoutedEventArgs e)
{
startNFC();
}
【问题讨论】:
标签: c# windowsiot