Shows how to use the System.IO.Ports API to send/receive data using an UART (COM port).
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.
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 System.IO.Ports 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.
- 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/cloned the repository, go to the subfolder for this specific sample. Double-click the Visual Studio Solution (.sln) file.
- Press
Ctrl+Shift+B
, or selectBuild > 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
.
Important: Before deploying or running the sample, please make sure your device is visible in the Device Explorer.
Tip: To display the Device Explorer, go to Visual Studio menus:
View > Other Windows > Device Explorer
.