Quantcast
Channel: Active questions tagged linux-kernel - Stack Overflow
Viewing all articles
Browse latest Browse all 12369

C# .NET Core IoT Error for ARM embedded board : Unhandled exception. System.IO.IOException: Device or resource busy

$
0
0

I want to use .NET core IoT library in order to run C# code for my SAMA5D27 SOM1 EK1 ARM embedded board.

.NET core IoT github

I have build this .NET core project composed from project.cs source file :

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);                }            }        }    }}

And this is .csproj file :

<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>

As you can see, the code is used for blinking Led which is situated on PIN 81 which corresponds to PortC pin 17 on my board. I build the project in order to use on arm-linux board.

First, to check if the pin is working well, I used libgpiod library and I turned on the led of pin81 using gpioset gpiochip0 81=1 and it is working well.

Furthermore, I have checked my GPIOs using gpioinfo command and this is the result of the desired pin :

 line  81:       "PC17"       unused   input  active-high

But when I try to run the C# code, it fails with this output message :

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 23Aborted

This is my board device tree :

device_tree

PS : I have removed ISC node which is using PC17 GPIO from device tree in order to free the pin

ISC_DeviceTree_node

Why my code can't run ? any help please !


Viewing all articles
Browse latest Browse all 12369

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>