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
Serial on System.IO.Ports seems needlessly complicated
C# .Net 6.0 System.IO.Ports is depricated. How can I use SerialPort? - Stack Overflow
c# - Using System.IO.Ports.SerialPort in .NET Core 1.1 - Stack Overflow
operating system - What are IO ports, serial ports and what's the difference between them? - Stack Overflow
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?
For those coming to this post some years later...
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. It requires the libserial binaries and I was able to compile it only for linux (not for MacOS or Windows).
Other way is using the Mono implementation and Mono.Posix.NETStandard package. This way works only for NETStandard 2.0 projects.
I copied sources of System.IO.Ports classes from Mono into my NETStandard 2.0 project, added the Mono.Posix.NETStandard, Microsoft.Win32.Registry references and included <AllowUnsafeBlocks>true</AllowUnsafeBlocks> section into my .csproj file. And it works on MacOs and Windows.
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.