Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -634,17 +634,37 @@
// set constant properties of the DCB
InitializeDCB(baudRate, parity, dataBits, stopBits, discardNull);

DtrEnable = dtrEnable;

// query and cache the initial RtsEnable value
// so that set_RtsEnable can do the (value != rtsEnable) optimization
_rtsEnable = (GetDcbFlag(Interop.Kernel32.DCBFlags.FRTSCONTROL) == Interop.Kernel32.DCBRTSFlowControl.RTS_CONTROL_ENABLE);
try
{
DtrEnable = dtrEnable;
}
catch (IOException) when (dtrEnable == false)

Check failure on line 641 in src/libraries/System.IO.Ports/src/System/IO/Ports/SerialStream.Windows.cs

View check run for this annotation

Azure Pipelines / runtime-dev-innerloop (Build linux-x64 debug Libraries_WithPackages)

src/libraries/System.IO.Ports/src/System/IO/Ports/SerialStream.Windows.cs#L641

src/libraries/System.IO.Ports/src/System/IO/Ports/SerialStream.Windows.cs(641,53): error IDE0100: (NETCORE_ENGINEERING_TELEMETRY=Build) Remove redundant equality (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0100)

Check failure on line 641 in src/libraries/System.IO.Ports/src/System/IO/Ports/SerialStream.Windows.cs

View check run for this annotation

Azure Pipelines / runtime-dev-innerloop (Build linux-x64 debug Libraries_WithPackages)

src/libraries/System.IO.Ports/src/System/IO/Ports/SerialStream.Windows.cs#L641

src/libraries/System.IO.Ports/src/System/IO/Ports/SerialStream.Windows.cs(641,53): error IDE0100: (NETCORE_ENGINEERING_TELEMETRY=Build) Remove redundant equality (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0100)

Check failure on line 641 in src/libraries/System.IO.Ports/src/System/IO/Ports/SerialStream.Windows.cs

View check run for this annotation

Azure Pipelines / runtime-dev-innerloop (Build linux-x64 debug Libraries_WithPackages)

src/libraries/System.IO.Ports/src/System/IO/Ports/SerialStream.Windows.cs#L641

src/libraries/System.IO.Ports/src/System/IO/Ports/SerialStream.Windows.cs(641,53): error IDE0100: (NETCORE_ENGINEERING_TELEMETRY=Build) Remove redundant equality (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0100)

Check failure on line 641 in src/libraries/System.IO.Ports/src/System/IO/Ports/SerialStream.Windows.cs

View check run for this annotation

Azure Pipelines / runtime-dev-innerloop

src/libraries/System.IO.Ports/src/System/IO/Ports/SerialStream.Windows.cs#L641

src/libraries/System.IO.Ports/src/System/IO/Ports/SerialStream.Windows.cs(641,53): error IDE0100: (NETCORE_ENGINEERING_TELEMETRY=Build) Remove redundant equality (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0100)

Check failure on line 641 in src/libraries/System.IO.Ports/src/System/IO/Ports/SerialStream.Windows.cs

View check run for this annotation

Azure Pipelines / runtime-dev-innerloop

src/libraries/System.IO.Ports/src/System/IO/Ports/SerialStream.Windows.cs#L641

src/libraries/System.IO.Ports/src/System/IO/Ports/SerialStream.Windows.cs(641,53): error IDE0100: (NETCORE_ENGINEERING_TELEMETRY=Build) Remove redundant equality (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0100)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is not a good approach to throw and immediately catch the exception.

Instead, the setter of DtrEnable/RtsEnable can be refactored into methods of TryEnable, then the callers here can call the TryEnable methods directly and ignores the failure.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alright, I will try to refactor the setters into methods.

I just took this approach from the unix implementation.
Do you want me to also refactor the unix implementation?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's up to the area owners for decision. Following existing pattern is also acceptable.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll leave it up to the area owners then.

{
// An IOException can be thrown when using a port which doesn't implement
// the required termios command for setting DtrEnable, but it still works without setting the value
Comment on lines +643 to +644
Copy link

Copilot AI Nov 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment refers to 'termios command' which is Unix-specific terminology. On Windows, this should refer to Windows API calls like SetCommState or EscapeCommFunction instead. Consider updating to: 'the required Windows API calls for setting DtrEnable'.

Copilot uses AI. Check for mistakes.
// so we ignore this error in the constructor only if being set to false (which is the default).
// When the property is set manually the exception is still thrown.
}

// now set this.RtsEnable to the specified value.
// Handshake takes precedence, this will be a nop if
// handshake is either RequestToSend or RequestToSendXOnXOff
if ((handshake != Handshake.RequestToSend && handshake != Handshake.RequestToSendXOnXOff))
RtsEnable = rtsEnable;
try
{
// query and cache the initial RtsEnable value
// so that set_RtsEnable can do the (value != rtsEnable) optimization
_rtsEnable = (GetDcbFlag(Interop.Kernel32.DCBFlags.FRTSCONTROL) == Interop.Kernel32.DCBRTSFlowControl.RTS_CONTROL_ENABLE);

// now set this.RtsEnable to the specified value.
// Handshake takes precedence, this will be a nop if
// handshake is either RequestToSend or RequestToSendXOnXOff
if ((handshake != Handshake.RequestToSend && handshake != Handshake.RequestToSendXOnXOff))
RtsEnable = rtsEnable;
}
catch (IOException) when (rtsEnable == false)

Check failure on line 661 in src/libraries/System.IO.Ports/src/System/IO/Ports/SerialStream.Windows.cs

View check run for this annotation

Azure Pipelines / runtime-dev-innerloop (Build linux-x64 debug Libraries_WithPackages)

src/libraries/System.IO.Ports/src/System/IO/Ports/SerialStream.Windows.cs#L661

src/libraries/System.IO.Ports/src/System/IO/Ports/SerialStream.Windows.cs(661,53): error IDE0100: (NETCORE_ENGINEERING_TELEMETRY=Build) Remove redundant equality (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0100)

Check failure on line 661 in src/libraries/System.IO.Ports/src/System/IO/Ports/SerialStream.Windows.cs

View check run for this annotation

Azure Pipelines / runtime-dev-innerloop (Build linux-x64 debug Libraries_WithPackages)

src/libraries/System.IO.Ports/src/System/IO/Ports/SerialStream.Windows.cs#L661

src/libraries/System.IO.Ports/src/System/IO/Ports/SerialStream.Windows.cs(661,53): error IDE0100: (NETCORE_ENGINEERING_TELEMETRY=Build) Remove redundant equality (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0100)

Check failure on line 661 in src/libraries/System.IO.Ports/src/System/IO/Ports/SerialStream.Windows.cs

View check run for this annotation

Azure Pipelines / runtime-dev-innerloop

src/libraries/System.IO.Ports/src/System/IO/Ports/SerialStream.Windows.cs#L661

src/libraries/System.IO.Ports/src/System/IO/Ports/SerialStream.Windows.cs(661,53): error IDE0100: (NETCORE_ENGINEERING_TELEMETRY=Build) Remove redundant equality (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0100)

Check failure on line 661 in src/libraries/System.IO.Ports/src/System/IO/Ports/SerialStream.Windows.cs

View check run for this annotation

Azure Pipelines / runtime-dev-innerloop

src/libraries/System.IO.Ports/src/System/IO/Ports/SerialStream.Windows.cs#L661

src/libraries/System.IO.Ports/src/System/IO/Ports/SerialStream.Windows.cs(661,53): error IDE0100: (NETCORE_ENGINEERING_TELEMETRY=Build) Remove redundant equality (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0100)
{
// An IOException can be thrown when using a port which doesn't implement
// the required termios command for setting RtsEnable, but it still works without setting the value
Copy link

Copilot AI Nov 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment refers to 'termios command' which is Unix-specific terminology. On Windows, this should refer to Windows API calls like SetCommState or EscapeCommFunction instead. Consider updating to: 'the required Windows API calls for setting RtsEnable'.

Suggested change
// the required termios command for setting RtsEnable, but it still works without setting the value
// the required Windows API calls (such as SetCommState or EscapeCommFunction) for setting RtsEnable, but it still works without setting the value

Copilot uses AI. Check for mistakes.
// so we ignore this error in the constructor only if being set to false (which is the default).
// When the property is set manually the exception is still thrown.
}

// NOTE: this logic should match what is in the ReadTimeout property
if (readTimeout == 0)
Expand Down
Loading