Shows how to use the System.IO.Ports API to send/receive data using an UART (COM port).
Note: This sample is part of a large collection of nanoFramework feature samples. If you are unfamiliar with Git and GitHub, you can download the entire collection as a ZIP file, but be sure to unzip everything to access any shared dependencies.
This sample allows the user to configure and communicate with a Serial device over an UART (COM port). You can choose one of four scenarios:
- Configure the Serial device
- Send data over the Output stream
- Receive data from the Input stream
- Register for Events on the Serial device
This scenario demonstrates the how to instantiate a Serial Device and use of various Get/Set property APIs in order to query for/alter Serial device properties such as Baud Rate, Stop Bits etc.
NOTE: when working with ESP32 edit the nfproj file and add
BUIID_FOR_ESP32
to the DefineConstants, like this:
<DefineConstants>$(DefineConstants);BUIID_FOR_ESP32;</DefineConstants>
This scenario demonstrates the use of Output stream on the SerialDevice object in order to send data to a Serial device.
This scenario demonstrates the use of Input stream on the SerialDevice object in order to read data from a Serial device.
This scenario demonstrates the use of event notification APIs provided by Windows.Devices.SerialCommunication for Data Received event type, an subsequently read the available data from the Input stream.
Any hardware device running a nanoFramework image built with serial communication enabled. This sample is coded to use the STM32F769IDiscovery target board, but can be easily changed to any other target that features a serial port.
- If you download the samples ZIP, be sure to unzip the entire archive, not just the folder with the sample you want to build.
- Start Microsoft Visual Studio 2019 (VS 2017 should be OK too) and select File > Open > Project/Solution.
- Starting in the folder where you unzipped the samples, go to the subfolder for this specific sample. Double-click the Visual Studio Solution (.sln) file.
- Press Ctrl+Shift+B, or select Build > Build Solution.
The next steps depend on whether you just want to deploy the sample or you want to both deploy and run it.
- Select Build > Deploy Solution.
- To debug the sample and then run it, press F5 or select Debug > Start Debugging.