dotnet/runtime

System.IO.Ports.SerialPort.Close() ignores disabled HUPCL flag on Linux

Open

#97.741 aperta il 31 gen 2024

Vedi su GitHub
 (2 commenti) (0 reazioni) (0 assegnatari)C# (5445 fork)batch import
area-System.IO.Portshelp wanted

Metriche repository

Star
 (17.886 star)
Metriche merge PR
 (Merge medio 12g 11h) (661 PR mergiate in 30 g)

Descrizione

Description

OS: DietPi arm64 bookworm on Raspberry Pi 4 Arduino connected via USB2 to the Pi

HUPCL (hang up on close) is disabled either by stty or a small Python program. When the serial port is closed using a .NET program, this is ignored and HUPCL is signaled leading to a reset of Arduino. Using the same with a Python program, HUPCL is not signaled on close.

Reproduction Steps

2 ways to disable HUPCL: stty -F /dev/ttyUSB0 -hupcl

or

small Python program: https://raspberrypi.stackexchange.com/a/31298

Minimal CLI program

var serialPort = new SerialPort("/dev/ttyUSB0") {
    ReadTimeout = 500,
    BaudRate = 250000,
    Parity = Parity.None,
    DataBits = 8,
    StopBits = StopBits.One,
    Handshake = Handshake.None,
    NewLine = "\r\n"
};
serialPort.Open();
serialPort.Close();

Expected behavior

  • HUPCL shall not be signaled an serialPort.Close();
  • A method to disable HUPCL using C#/.NET would be helpful

Actual behavior

HUPCL is signaled on serialPort.Close(); leading Arduino to reset

Regression?

No response

Known Workarounds

On Windows it is working as excpected.

Configuration

No response

Other information

No response

Guida contributor