Hi all,
I'm running into a serial communication issue that seems specific to .NET’s System.IO.Ports implementation. Here's everything relevant:
Operating System: Windows 11 Pro
OS Version: 10.0.26100 N/A Build 26100
Visual Studio:
Microsoft Visual Studio Community 2022 (64-bit) - Version 17.13.0
Arduino IDE:
Version 2.3.6
.NET SDKs Installed:
8.0.405
.NET Runtimes Installed:
Microsoft.AspNetCore.App 8.0.13
Microsoft.NETCore.App 8.0.13
Microsoft.WindowsDesktop.App 8.0.13
Board: Arduino Uno clone with CH340 USB-to-Serial chip
Detected as: USB-SERIAL CH340 (COM3)
Uploading and serial communication via Arduino IDE works fine
Processing IDE communicates with the board without issue
COM port is confirmed as COM3 and visible in Device Manager
Using this very basic System.IO.Ports.SerialPort example in a C# console app:
using System;
using System.IO.Ports;
class Program
{
static void Main()
{
SerialPort port = new SerialPort("COM3", 9600);
try
{
port.Open();
Console.WriteLine("Connected to Arduino.");
port.Close();
}
catch (Exception ex)
{
Console.WriteLine("Error: " + ex.Message);
}
Console.ReadKey();
}
}
I consistently get this error:
Error: A device attached to the system is not functioning.
The port opens fine in other software, but System.IO.Ports always fails, even when the IDE is closed, and no other process is using COM3.
I tried toggling DtrEnable and RtsEnable as elsewhere in the forum mentioned
Ran the app as Administrator
As a temporary workaround, I’ve implemented a TCP bridge using Processing:
Processing reads/writes to the Arduino over serial
C# connects to Processing via TCP to send/receive messages
Arduino Sketch for Testing:
void setup() {
Serial.begin(9600);
}
void loop() {
}
Is there a known fix or alternate C# serial library that bypasses System.IO.Ports entirely?
Would flashing the latest bootloader make a difference seeing that its about 15 years old already.
Any help would be appreciated
Thanks,
Arnold