This article explains how to run and debug .NET Applications on TorizonCore using the Visual Studio Code extension provided by Toradex.
The goal is to show a simple LED blink using .NET Core Console template and being able to debug the code with breakpoints using the Torizon Visual Studio Code Extension.
This article complies to the Typographic Conventions for Torizon Documentation.
F1 on Visual Studio Code and then type
Torizon/.NET: Create .NET Core Application to create an application:
After creating it write the application name on the same command bar:
Select a folder on system to store the project files:
After the folder selection two options will appear to select the right target architecture of your board:
torizon on the username label:
A .NET Core project with the following files will be created:
Understand how to add Nuget packages, library dependencies and more in the next subsections.
For this article we will set up a project to make a simple blink LED as Hello World example.
For add .NET Core dependencies packages on .NET Core Torizon project there are no differences between a standard .NET Core project. Open a new terminal using the Visual Studio Code and enter the command:
dotnet add package System.Device.Gpio
This will add the dotnet/iot library to our project, which will have the APIs for access GPIO through .NET Core using C#.
Some Nuget packages may depend on other packages and shared libraries. Open the Torizon configuration and edit the
extrapackages configuration, just need to click on the pen icon and add
This is done to add support to
In some cases it will be necessary to run some commands to add settings to the image generated by the extension. For these cases there is the
buildcommands configuration. Open the Torizon configuration and edit the
buildcommands value with:
RUN usermod -a -G gpio torizon
This will add our user
torizon to the
gpio group to have access to GPIO management.
The example code used in this article comes from the sample https://github.com/toradex/torizon-samples/tree/master/gpio/dotnet/console/
For the purposes of example in this article, the Apalis iMX6Q and Ixora carrier board will be used.
For the LED connection, the
SODIMM_5 of the Apalis family will be used, which in the case corresponds to the Ixora Extension Header
x27 pin 15:
Which for Linux corresponds to the GPIO bank
6. See our article How to Use GPIO on TorizonCore to know more.
For projects that need to access hardware devices, listed in TorizonCore
/dev/, it is necessary to add the device path in the settings for the application to have access to it. Open Torizon configuration and add a
/dev/gpiochip1 device on
Edit https://github.com/toradex/torizon-samples/tree/master/gpio/dotnet/console/Program.cs lines
19, 20 with the content below:
sharp int gpioBank = 1; int gpioLine = 6;
And remove lines
12, 13, 14, 15, 16 and
Warning: In this article we are using
/dev/gpiochip1 (GPIO bank 1) and line 6 for example purposes. Remember to enter the
line number device for the pin that will be used in your project
After the setup of hardware and replacing the GPIO bank and line on source code, add a breakpoint on line
25 by clicking on the left side of the line, it will make a red dot appear.
Warning: You may have to enable setting breakpoints anywhere in a file via File → Preferences → Settings → `Debug: Allow Breakpoints Everywhere.
Let the debug process begin. Press F5 and the Torizon VS Code Extension will build and deploy the debug container image to the Toradex computer on module. This process will take some time for the first time or whenever you edit the
The application runtime will stop on line
So we can use the VS Code debug tools to follow the code step by step, and check the LED turning on and off at each step.
After going on the process of deploying and debugging the application, you can now deploy and release it .
F1 in VS Code to open the command bar and write the command
Torizon/.NET: Build release container for Python application.
Warning: Just note that the building process can take some time.
Your terminal output should be like the following:
Building release container (this may take some time)... Publishing application... Building container image... Release image has been built successfully.
Now that your container was successfully built, you can press
F1 again and enter the
Torizon: Deploy release container, which deploys your container.
Deploying release container... Device 05204061 selected. Deploying image to target (this may take a few minutes). Container has been deployed.
You can confirm if the image was actually deployed to your Torizon device by running the following command on the module:
# docker images
To get more information about Docker Containers and their commands, please refer to Docker Oficial Documentation.