简体   繁体   English

当前在不兼容的共享模式下打开了图钉

[英]Pin is currently opened in an incompatible sharing mode

I am currently using UWP Toolkit to navigate among app pages. 我目前正在使用UWP Toolkit在应用程序页面之间导航。 There is a page that is being used for initializing and opening RaspberryPi GPIO pins. 有一个页面用于初始化和打开RaspberryPi GPIO引脚。 The following error occurs after navigating away from that page then trying to navigate back to it again. 离开该页面然后尝试再次导航回该页面后,将发生以下错误。

The process cannot access the file because it is being used by another process .\\r\\n\\r\\nPin ' is currently opened in an incompatible sharing mode. 该进程无法访问该文件,因为该文件正在被另一个进程使用。\\ r \\ n \\ r \\ nPin'当前以不兼容的共享模式打开。 Make sure this pin is not already in use by this application or another application 确保此应用程序或其他应用程序尚未使用此引脚

I can see that the constructor is being called each time the page is visited and hence there is an attempt to open pins that are already opened. 我可以看到每次访问页面时都会调用构造函数,因此尝试打开已经打开的引脚。 What is the best way to overcome this issue? 解决此问题的最佳方法是什么?

You may add NavigationCacheMode = NavigationCacheMode.Required; 您可以添加NavigationCacheMode = NavigationCacheMode.Required; to the ctor of the page so your app will not create a new instance of it when you navigate there. 到页面ctor的位置,因此当您浏览该页面时,您的应用不会为其创建新实例。

What I always do is let a class deal with managing pins so that your user code can request pins to act on. 我一直做的是让一个类处理管脚,以便您的用户代码可以请求管脚进行操作。

public class IO
{
    private readonly GpioController _gpioController;
    private readonly Dictionary<int, GpioPin> _pins;
    public IO(GpioController gpioController)
    {
        _gpioController = gpioController;
        _pins = new Dictionary<int, GpioPin>();
    }

    public GpioPin OpenPin(int pin, GpioSharingMode mode)
    {
        if (_pins.ContainsKey(pin))
        {
            var gpioPin = _pins[pin];
            if (gpioPin.SharingMode == mode)
            {
                return gpioPin;
            }
            throw new ArgumentException($"Pin '{pin}' is already configured in mode '{gpioPin.SharingMode}'");
        }
        else
        {
            var gpioPin = _gpioController?.OpenPin(pin, mode);
            _pins[pin] = gpioPin;
            return gpioPin;
        }
    }

} }

Then my viewmodels simply request a pin as follows 然后我的视图模型只要求如下图钉

public MainViewModel()
{
    _io = ServiceContainer.Instance.Get<IO>();

    _brakingPin = _io.OpenPin(4, GpioSharingMode.Exclusive);
    _io.SetDriveMode(_brakingPin, GpioPinDriveMode.Output);
    _io.Write(_brakingPin, GpioPinValue.Low);
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Win IOT上的NFC阅读器:Pin&#39;当前在不兼容的共享模式下打开 - NFC-reader on Win IOT: Pin ' is currently opened in an incompatible sharing mode 检测目录当前是否打开 - Detect whether a directory is currently opened 共享视图演示模式? - Sharing view presentation mode? 从Process获取当前打开的Word文档 - Get Currently Opened Word Document from Process 在vsix项目中访问当前打开的解决方案 - Acessing currently opened solution in a vsix project 有没有一种方法可以检查WPF当前是否在设计模式下执行? - Is there a way to check if WPF is currently executing in design mode or not? 如何在c#中重命名当前由Windows资源管理器打开的文件夹 - How to rename a folder in c# which is currently opened by windows explorer 如何最大化/最小化当前打开的 Firefox window 到 C# - How to maximize/ minimize currently opened Firefox window through C# Azure 地图 - 渲染 - 获取 Map 图像 - 如何在默认模式下使用引脚图像而不是标记图像作为引脚 - Azure Maps - Render - Get Map Image - How to use pin image instead of marker image for the pin in default mode C#中的程序,用于判断打开的应用程序是否处于最大化模式 - A program in C# to tell whether opened applications are in maximized mode or not
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM