首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >用于ARM嵌入式板的C# .NET Core IoT错误:未处理异常。System.IO.IOException:设备或资源繁忙

用于ARM嵌入式板的C# .NET Core IoT错误:未处理异常。System.IO.IOException:设备或资源繁忙
EN

Stack Overflow用户
提问于 2020-06-18 15:46:35
回答 1查看 675关注 0票数 3

我想使用.NET核心IoT库,以便为我的SAMA5D27 SOM1 EK1 ARM嵌入式板运行C#代码。

.NET核心IoT github

我已经构建了这个.NET核心项目,它由project.cs源文件组成:

代码语言:javascript
运行
复制
using System;
using System.Device.Gpio;
using System.Threading;

namespace led_blink
{
    class Program
    {
        static void Main(string[] args)
        {
            var pin = 81;
            var lightTimeInMilliseconds = 1000;
            var dimTimeInMilliseconds = 200;
            
            Console.WriteLine($"Let's blink an LED!");
            using (GpioController controller = new GpioController())
            {
                controller.OpenPin(pin, PinMode.Output);
                Console.WriteLine($"GPIO pin enabled for use: {pin}");

                Console.CancelKeyPress += (object sender, ConsoleCancelEventArgs eventArgs) =>
                {
                    controller.Dispose();
                };

                while (true)
                {
                    Console.WriteLine($"Light for {lightTimeInMilliseconds}ms");
                    controller.Write(pin, PinValue.High);
                    Thread.Sleep(lightTimeInMilliseconds);
                    Console.WriteLine($"Dim for {dimTimeInMilliseconds}ms");
                    controller.Write(pin, PinValue.Low);
                    Thread.Sleep(dimTimeInMilliseconds);
                }
            }
        }
    }
}

这是.csproj文件:

代码语言:javascript
运行
复制
<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>netcoreapp3.1</TargetFramework>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Iot.Device.Bindings" Version="1.0.0" />
    <PackageReference Include="System.Device.Gpio" Version="1.0.0" />
  </ItemGroup>

</Project>

如您所见,该代码用于闪烁Led,它位于PIN 81上,它对应于我的主板上的PortC pin 17。我构建这个项目是为了在arm-linux板上使用.

首先,为了检查引脚是否正常工作,我使用了libgpiod库,并使用gpioset gpiochip0 81=1打开了pin81的引导,它运行良好。

此外,我使用gpioinfo命令检查了我的GPIOs,这是所需引脚的结果:

代码语言:javascript
运行
复制
 line  81:       "PC17"       unused   input  active-high

但是,当我尝试运行C#代码时,它在输出消息中失败:

代码语言:javascript
运行
复制
Let's blink an LED!
Unhandled exception. System.IO.IOException: Device or resource busy
   at System.IO.FileStream.WriteNative(ReadOnlySpan`1 source)
   at System.IO.FileStream.FlushWriteBuffer()
   at System.IO.FileStream.FlushInternalBuffer()
   at System.IO.FileStream.Flush(Boolean flushToDisk)
   at System.IO.FileStream.Flush()
   at System.IO.StreamWriter.Flush(Boolean flushStream, Boolean flushEncoder)
   at System.IO.StreamWriter.Dispose(Boolean disposing)
   at System.IO.TextWriter.Dispose()
   at System.IO.File.WriteAllText(String path, String contents)
   at System.Device.Gpio.Drivers.SysFsDriver.OpenPin(Int32 pinNumber)
   at System.Device.Gpio.GpioController.OpenPin(Int32 pinNumber)
   at System.Device.Gpio.GpioController.OpenPin(Int32 pinNumber, PinMode mode)
   at led_blink.Program.Main(String[] args) in /home/ubuntu/netcore/Program.cs:line 23
Aborted

这是我的板设备树:

PS :我已经从设备树中删除了使用PC17 GPIO的ISC节点,以便释放引脚。

节点

为什么我的代码不能运行?任何帮助都行!

EN

回答 1

Stack Overflow用户

发布于 2020-06-18 19:36:20

好的。在嵌入式系统上工作了45年。一开始,我认为错误来自一台连接到板上的PC。我现在意识到这个设备是控制台串口。

该设备正在从eprom启动,并首先配置控制台以便进行调试。接下来,设备试图从磁盘上挂载操作系统。您的设备有一个智能卡,是在USB连接上。我读了你的源代码,并认为USB是RS-232,但从设备文献,USB是用于智能卡。该错误看起来可能来自智能卡的启动代码。因此,要么卡没有插入,没有格式化,要么在卡上没有操作系统。

您可能不需要智能卡取决于您的需求。我在工作时使用的是Xilinx嵌入式卡,而不是智能卡,所以我们必须关闭启动选项,才能使用智能卡。在使用之前,我们还必须对Xilinx进行编程。我想Atmel也有类似的选择。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/62453974

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档