.NET C# is used by millions to make professional applications for phones, tablets, games, and computers. C# is an evolution of C, which is the mother of all languages and it is still the most important language today.
What is .NET?
.NET is a framework that standardizes what system functions are available to the developer, no matter what operating system or device used. .NET C# is the main language of choice for .NET but you can learn other .NET languages, like Visual Basic, using the provided C# lessons.
We will refer to .NET C# is simply C# going forward.
DUE Link Pre-Setup
DUE Link allows devices to be connected to a PC that is programmed is any programming language, including python. To prep you BrainPad to work with .NET C#, it needs to be loaded with DUE Link software.
Visit the DUE Link Console and click firmware option in the top menu.
Note that you do not need to use the console. You are only using it for the firmware update feature. This step is only necessary if the board is not already loaded with the latest DUE Link firmware and only needs to be once. Come back here to continue with .NET C#.
The best way to code .NET C# will be using Microsoft Visual Studio or Microsoft Visual Studio Code. Both are fantastic tools but we will use Visual Studio Code (VS Code) as it runs on Windows, Mac and Linux plus it supports other languages as well, such as Python.
VS Code is ever evolving with large community contributions. Instead of listing detailed instructions here that can change quickly, please visit code.visualstudio.com to download and install. There are hundreds of online videos and tutorials on creating your first project, click here for an example.
The steps are:
- Install VS Code: code.visualstudio.com
- Install .NET: dotnet.microsoft.com
- Open command prompt and create a local folder: mkdir csharptest
- Enter the folder: cd csharptest
- Create a new console application: dotnet new console
- Start VS Code from the same folder: code . (do not forget the period. This is not a typo!)
- In VS Code, open Program.cs file. VS Code will now ask you if you want to install the C# extension, if you did not have it already.
The code already contain Console.WriteLine(“Hello, World!”); Run the program and observe the Debug Console window.
We are now ready to add the DUELink NuGet library that C# uses to communicate with the BrainPad. To use the standard NuGet packages, go to extensions and install NuGet Package Manager.
Now from the pallet (hit F1) run NuGet Package Manager: Add Package and when prompted for package name enter GHIElectronics.DUELink and then for version select latest.
Modify the earlier code. If you see errors then GHIElectronics.DUELink NuGet package is still not installed.
using GHIElectronics.DUELink; Console.WriteLine("Hello BrainPad!"); var availablePort = DUELinkController.GetConnectionPort(); var BrainPad = new DUELinkController(availablePort); // Flash the LED 20 times (on for 200ms and off for 800ms) BrainPad.Led.Set(200,800,10); Console.WriteLine("Bye BrainPad!");
Run the program to verify the system is set properly. The LED will blink 10 times.
Start modifying the code and try debugging, which is stepping through code and inspecting variables. Familiarize yourself with VS Code before continuing.
At this point, your PC, your BrainPad, and you are ready to start venturing into .NET C# coding, especially physical coding things. And while you are at it, why not learn Python as well?