【问题标题】:NFC-reader on Win IOT: Pin ' is currently opened in an incompatible sharing modeWin IOT 上的 NFC 阅读器:Pin ' 当前以不兼容的共享模式打开
【发布时间】: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


    【解决方案1】:

    由于正在使用初始化 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;
            }
        }
    

    【讨论】:

      猜你喜欢
      • 2017-10-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-12-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多