2017-11-15 10 views
0

で開かれた私は、ライブラリMfrc522libを使用RasperryのPIに3NFCリーダー:ピンは、「現在、互換性のない共有モード

を実行しているWindows 10のIoTに基づいてNFCリーダプロジェクトに取り組んでいます。 csはここにあります:RFID RC522 Raspberry PI 2 Windows IOT 非同期タスクを使用してカードを待ちます。初めて完全にスキャンしますが、私が再びタスクを開始すると(ボタン付きのテスト・プープローズのために)。

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

この問題は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; 
     } 
    } 
関連する問題