How to Use UART with Torizon Visual Studio Code Extension (.NET Core)
Introduction
In this article, we will show how you can use the UART interface, also known as serial, with .NET Core and the Visual Studio Code Extension for Torizon.
The goal is to create a simple application using .NET Core Console template showing the data returned from a serial UART GPS.
Prerequisites
- TorizonCore installed on a Toradex module.
- Have completed the .NET Core Development and Debugging on Torizon Using Visual Studio Code lessons.
- Define which UART device you want to use.
- (optional) understand How to Use UART on TorizonCore.
Instructions
Define the UART Device
In Linux systems, including TorizonCore, UART devices can be accessed through /dev/tty*
. Toradex adds a layer of abstraction with symlinks, so the UART names are standardized for a given SoM family. Take a look at UART (Linux) article to understand the different /dev/tty*
names across the Toradex's Module families.
Once you identify the exact name of your UART device, you can add it to your application.
Connect to a Serial GPS
For this example the Ublox Neo 6M, GY-NEO-6MV2, GPS module was used:
Connect the UART of the GPS Module to an available UART on your board.
Board GPS
VCC <--------> VCC
RX <--------> TX
TX <--------> RX
GND <--------> GND
For the purposes of example in this article, the Apalis iMX6Q and Ixora carrier board will be used.
For connect GPS module we will use UART4 signals from Ixora header X27
:
Create a New Project
On VS Code, create a new Torizon .NET Application. See the .NET Core Development and Debugging on Torizon Using Visual Studio Code article for detailed instructions.
Add UART Device to the Project
To add UART to your .NET Core Torizon project, first, open the Torizon Configuration View. To do that, press F1 in Visual Studio Code command bar and then type "Torizon: Focus on Configurations View"
On the device item, press the '+' button on the right.
Type the selected tty device. As an example, we will add /dev/apalis-uart4
.
/dev/apalis-uart4
is UART4 in the case of the Apalis family. Find your UART name on the previous section Define the UART Device.
Check if the device was added to your project.
Add Serial Access Permission
To have access to the serial devices we need to add the default torizon
user to dialout
group. Go to the Torizon Visual Studio Code Extension Configurations and add the buildcommands
:
RUN usermod -a -G dialout torizon
Add Nuget Packages
To easily parse NMEA data from GPS module, we use the SharpGIS.NmeaParser
. To add it to the project open a new terminal using the Visual Studio Code and enter the following command:
dotnet add package SharpGIS.NmeaParser
Source Code
The example code used in this documentation comes from the sample https://github.com/toradex/torizon-samples/tree/master/gps/dotnet/console/
Set the Serial Port
In the Torizon properties, edit the env
property with the desired UART.
ENV GPS_SERIAL_PORT="/dev/apalis-uart4"
With the correct device set, you can now run and debug the application. See the .NET Core Development and Debugging on Torizon Using Visual Studio Code article for detailed instructions about debugging tools.