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.
In Linux systems, including TorizonCore, UART devices can be accessed through
/dev/tty*. Depending on the UART hardware implementation, those devices can have different names. Take a look to UART (Linux) article to understand the different
/dev/tty* names across the Toradex's Modules.
Once you identify the exact name for your UART device, you can add it to your application.
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
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.
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-tty4 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.
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
RUN usermod -a -G dialout torizon
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
The example code used in this documentation comes from the sample https://github.com/toradex/torizon-samples/tree/master/gps/dotnet/console/
Change the line
serialDev.PortName = "/dev/apalis-tty4";
Warning: Remember to modify the device path according to the serial device you are going to use.
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 debug tools.