Try adding the System.IO.Ports NuGet package:

<PackageReference Include="System.IO.Ports" Version="7.0.0" />

Also note that the fully qualified name is System.IO.Ports.SerialPort, not System.IO.SerialPort

Answer from Marc Gravell on Stack Overflow
🌐
Microsoft Learn
learn.microsoft.com › en-us › dotnet › api › system.io.ports.serialport
SerialPort Class (System.IO.Ports) | Microsoft Learn
Imports System.IO.Ports Imports System.Threading Public Class PortChat Shared _continue As Boolean Shared _serialPort As SerialPort Public Shared Sub Main() Dim name As String Dim message As String Dim stringComparer__1 As StringComparer = StringComparer.OrdinalIgnoreCase Dim readThread As New Thread(AddressOf Read) ' Create a new SerialPort object with default settings.
🌐
NuGet
nuget.org › packages › system.io.ports
NuGet Gallery | System.IO.Ports 10.0.8
using System.IO.Ports; // Provides list of available serial ports string[] portNames = SerialPort.GetPortNames(); // First available port string myPortName = portNames[0]; int baudRate = 9600; SerialPort sp = new SerialPort(myPortName, baudRate); sp.Open(); sp.WriteLine("Hello World!");
Discussions

Serial on System.IO.Ports seems needlessly complicated
How could the serial port know that the external hardware has finished sending its message? Your code needs to know how to tell when it has the entire message (fixed length? length sent at the start of the message? terminator?) and keep receiving until it knows it has the full message. More on reddit.com
🌐 r/csharp
19
0
February 21, 2024
C# .Net 6.0 System.IO.Ports is depricated. How can I use SerialPort? - Stack Overflow
However, this code is not working on .NET 6.0. System.IO is exist but .Ports does not. So Ports.SerialPort... More on stackoverflow.com
🌐 stackoverflow.com
c# - Using System.IO.Ports.SerialPort in .NET Core 1.1 - Stack Overflow
Since .NET Core 2.0 it's possible to use the System.IO.Ports package. ... If you are using linux OS you can use SerialPortStream library. More on stackoverflow.com
🌐 stackoverflow.com
operating system - What are IO ports, serial ports and what's the difference between them? - Stack Overflow
I'm confused. I have recently started working on building an operating system while using bochs as an emulator and a certain manual online. In the manual to move the vga framebuffer cursor I'm usin... More on stackoverflow.com
🌐 stackoverflow.com
🌐
Sparx Engineering
sparxeng.com › home › blog › if you *must* use .net system.io.ports.serialport
If you *must* use .NET System.IO.Ports.SerialPort - Sparx Engineering
May 2, 2023 - The only serial port read approaches that work correctly are accessed via BaseStream. Its implementation, the System.IO.Ports.SerialStream class (which has internal visibility; you can only use it via Stream virtual methods) is also home to the few lines of code which I wouldn’t choose to rewrite.
🌐
Microsoft Learn
learn.microsoft.com › en-us › dotnet › api › system.io.ports
System.IO.Ports Namespace | Microsoft Learn
Contains classes for controlling serial ports. The most important class, SerialPort, provides a framework for synchronous and event-driven I/O, access to pin and break states, and access to serial driver properties.
🌐
GitHub
github.com › nanoframework › System.IO.Ports
GitHub - nanoframework/System.IO.Ports: 📦 System.IO.Ports library for .NET nanoFramework.
string toSend = "I ❤ nanoFramework"; port.WriteLine(toSend); // this will send the string encoded finishing by a new line, by default `\n` // You can change the new line to be anything: port.NewLine = "❤❤"; // Now it will send 2 hearts as the line ending `WriteLine` and will use 2 hearts as the terminator for `ReadLine`. // You can change it back to the `\n` default at anytime: port.NewLine = SerialPort.DefaultNewLine; // default is "\n" // This will read the existing buffer: string existingString = port.ReadExisting(); // Note that if it can't properly convert the bytes to a string, you'll get an exception // This will read a full line, it has to be terminated by the NewLine string.
Starred by 11 users
Forked by 7 users
Languages   C#
🌐
Reddit
reddit.com › r/csharp › serial on system.io.ports seems needlessly complicated
r/csharp on Reddit: Serial on System.IO.Ports seems needlessly complicated
February 21, 2024 -

I can't find a simple easy to implement solution for this problem, so I figured I'd ask here. I'm writing some software to communicate with a solid state wav recorder I use. I am able to communicate with it and send/receive commands and responses via it's usb port using rs232.

My software relies on replies sent from the machine back to my pc. Only one message can be sent/received at a time. In trying to write more functions, I'm running into the problem of my code meant to handle the reply message executing before the entire reply has arrived.

Everything I've read says I have to use a "data received" event, which does indeed get triggered when the data arrives. This is great and all, but I need my "send message" function to return the reply to the class that called it. This is basically all I'm trying to do:

public SerialResponse SendMessage(SerialMessage messageOut)

{

serialPort.Write(messageOut);

SerialResponse messageIn = WaitForFullResponse();

return messageIn;

}

Is there any simple way to achieve this?

Find elsewhere
🌐
NuGet
nuget.org › packages › System.IO.Ports › 8.0.0
NuGet Gallery | System.IO.Ports 8.0.0
November 14, 2023 - using System.IO.Ports; // Provides list of available serial ports string[] portNames = SerialPort.GetPortNames(); // First available port string myPortName = portNames[0]; int baudRate = 9600; SerialPort sp = new SerialPort(myPortName, baudRate); sp.Open(); sp.WriteLine("Hello World!");
🌐
.NET nanoFramework
docs.nanoframework.net › samplesdetails › SerialCommunication › README.html
🌶️ to 🌶️🌶️ - System.IO.Ports serial Communication sample | .NET nanoFramework Documentation
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).
🌐
Microsoft Learn
learn.microsoft.com › en-us › dotnet › api › system.io.ports.serialport.write
SerialPort.Write Method (System.IO.Ports) | Microsoft Learn
Writes a specified number of bytes to the serial port using data from a buffer. public: void Write(cli::array <System::Byte> ^ buffer, int offset, int count);
Top answer
1 of 1
3

An IO port is basically memory on the motherboard that you can write/read. The motherboard makes some memory available other than RAM. The CPU has a control bus which allows it to "tell" the motherboard that what it outputs on the data bus is to be written somewhere else than RAM. When you output to the VGA buffer, you write to video memory on the motherboard. The out/in instructions are used to write/read IO ports instead of writing to RAM. When you use out/in instructions, you instruct the CPU to set a certain line on its control bus to tell the motherboard to write/read a certain byte to an IO port instead of RAM.

Today, a lot of RAM memory is used for hardware mapping instead of IO ports. This is often called the PCI hole. It is memory mapped IO. So you will write to RAM and it will send the data to hardware like graphics memory. All of this is transparent to OS developers. You are simply using very abstract hardware interfaces which are either conventional (open source) or proprietary.

Serial ports in the meantime are simply ports which are serial in nature. A serial port is defined to be a port where data is transferred one bit at a time. USB is serial (universal serial bus). VGA is serial and others are too. These ports are not like IO ports. You can output to them indirectly using IO ports.

IO ports offer various hardware interfaces which allow to drive hardware. For example, if you have a VGA compatible screen and set text mode, the motherboard will make certain IO ports available and, when you write to these IO ports, video memory will vary depending on what you output to these ports. Eventually, the VGA screen will refresh when the video controller will output data written to video memory through the actual VGA port. I'm not totally aware of how all of this works since I'm not an electrical engineer and I never read about this stuff. To what I know, you can see the pins of the VGA port and what they do independently on wikipedia. VGA works with RGBHV. RGB stands for red, green and blue while HV stand for horizontal/vertical sync. As stated on wiki in the article on analog television:

Synchronizing pulses added to the video signal at the end of every scan line and video frame ensure that the sweep oscillators in the receiver remain locked in step with the transmitted signal so that the image can be reconstructed on the receiver screen. A sync separator circuit detects the sync voltage levels and sorts the pulses into horizontal and vertical sync.

The horizontal synchronization pulse (horizontal sync, or HSync), separates the scan lines. The horizontal sync signal is a single short pulse which indicates the start of every line. The rest of the scan line follows, with the signal ranging from 0.3 V (black) to 1 V (white), until the next horizontal or vertical synchronization pulse.

Memory in itself takes various forms in hardware. Video memory is often called VRAM (Video RAM) or the Frame Buffer as you can read in a Wikipedia article. So in itself video memory is an array of DRAM. DRAM today is one capacitor (which stores the data) and one mosfet transistor (which controls the flow of the data). So you have special wiring on the motherboard between the data bus of the processor and the VRAM. When you output data to video memory, you write to VRAM on the motherboard. Where you write and how just depends on the video mode you set up.

Most modern systems work with HDMI/Display port along with graphics card. These graphics card are other hardware interfaces which are often complex and they often cannot be known because the drivers for the cards are provided by the manufacturers. osdev.org has information on Intel HD Graphics which has a special interface to interact with. It can be used to gather info on the monitor and to determine what RAM address to use to write to the monitor.

🌐
Reddit
reddit.com › r/csharp › do system.io.serialport works the same in newer versions of .net (6, 7 or 8) vs framework?
r/csharp on Reddit: Do System.IO.SerialPort works the same in newer versions of .NET (6, 7 or 8) vs Framework?
September 4, 2024 -

Hi, Everyone!

I'm pretty new to working with System.IO.SerialPort, and I'm trying to create a WinForms app (I know it's old, but it's a school assignment) in .NET 8 to process data received from a barcode scanner. The teacher gave us a demo he created in .NET Framework 4.7.2, and it works fine using SerialPort in Windows 10/11. However, if I use the NuGet System.IO.SerialPort package, I experience a very unstable connection in Windows 10, and sometimes it disconnects when using Windows 11 (it happens mostly when I'm debugging something so I believe this is normal).

Does anyone know why?

P.S.: The teacher wants us to use newer versions of .NET; he just gave us the demo for educational purposes. Also, I don't think is a driver issue the demo works fine in both machines.

🌐
Medium
andre-benevides.medium.com › creating-a-serial-port-wrapper-c-net-framework-390584531285
Creating a Serial Port Wrapper — C# .NET Framework | by André Benevides | Medium
July 10, 2021 - If you ever went to a supermarket ... a serial port to the cashier’s application. I’ll first give you a brief introduction to what serial communication is and how it works and then we’ll do a wrapper class, in C#, for Microsoft’s .NET Framework System.IO.Ports.SerialPort ...
🌐
Scott Hanselman's Blog
hanselman.com › blog › performance-of-systemioports-versus-unmanaged-serial-port-code
Performance of System.IO.Ports versus Unmanaged Serial Port Code - Scott Hanselman's Blog
I like the idea of a dongle that is a hardware oscillator that sits between serial and the hardware. I think I'll try that. ... You could consider rewiring DTR to the TX line and creating a bit stream to drive the pattern that you want. If you set the port to databits 8, parity None, start bits 0 so you have just the raw bits and a high speed it should give you the resolution that you require.
🌐
Microsoft Learn
learn.microsoft.com › en-us › dotnet › api › system.io.ports.serialport.portname
SerialPort.PortName Property (System.IO.Ports) | Microsoft Learn
_serialPort.PortName = SetPortName(_serialPort.PortName); _serialPort.BaudRate = SetPortBaudRate(_serialPort.BaudRate); _serialPort.Parity = SetPortParity(_serialPort.Parity); _serialPort.DataBits = SetPortDataBits(_serialPort.DataBits); _serialPort.StopBits = SetPortStopBits(_serialPort.StopBits); _serialPort.Handshake = SetPortHandshake(_serialPort.Handshake); // Set the read/write timeouts _serialPort.ReadTimeout = 500; _serialPort.WriteTimeout = 500; _serialPort.Open(); _continue = true; readThread.Start(); Console.Write("Name: "); name = Console.ReadLine(); Console.WriteLine("Type QUIT to