我正在研究基于在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();
}
答案 0 :(得分:0)
由于初始化GPIO引脚而导致的此问题正在使用中。因为每次单击按钮时都会执行以下行:
await mfrc.InitIO();
要解决此问题,您可以像这样编辑代码:
private Mfrc522 mfrc = new Mfrc522();
public static bool IsGpioInitialized = false;
public async Task ReadNFCAsync()
{
if (!IsGpioInitialized)
{
await mfrc.InitIO();
IsGpioInitialized = true;
}
}