-
Notifications
You must be signed in to change notification settings - Fork 583
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature serial port #1834
Feature serial port #1834
Conversation
/// In the Windows implementation, this is EV_RXFLAG. | ||
/// </summary> | ||
Eof = 0x02 | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Something to think about is a nothing of WatchChar we have introduced in nanoFramework: https://github.com/nanoframework/System.IO.Ports/blob/develop/System.IO.Ports/SerialData.cs.
See usage here: https://github.com/nanoframework/System.IO.Ports#case-of-watchchar
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see, this is substantially the same principle used in Win32 for watching a specific character.
Why did you rename the Eof=0x02
to WatchChar=0x02
in SerialData
give they have the same meaning?
If I understand well this enum can be left as-is for compat reasons. Then we can add the WatchChar
property to specify what is the character that will trigger the event.
Did I miss something?
/// Both the Request-to-Send (RTS) hardware control and | ||
/// the XON/XOFF software controls are used | ||
/// </summary> | ||
RequestToSendXOnXOff |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This enum should be reviewed. RequestToSendXOnXOff
is probably never used (I can't think of a reason why you would use hw flow control and sw flow control at the same time), but instead RtsCts
handshake (bidirectional full hardware flow control) should be added.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Totally agree, I also have never seen that mix
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We will have to futher discuss what handshakes we want to support because I am reading an old book on the serial port and there are plenty variations.
public enum Parity | ||
{ | ||
/// <summary> | ||
/// No parity check occurs. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This description is wrong. Right would be: No parity bit is sent or expected.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch, as I said many descriptions from the official docs are inaccurate.
…om runtime/common.
src/System.Device.Ports/System.Device.Ports.SerialPort/System.Device.Ports.SerialPort.csproj
Show resolved
Hide resolved
src/System.Device.Ports/System.Device.Ports.SerialPort/System.Device.Ports.SerialPort.csproj
Outdated
Show resolved
Hide resolved
src/System.Device.Ports/System.Device.Ports.SerialPort/System.Device.Ports.SerialPort.csproj
Outdated
Show resolved
Hide resolved
src/System.Device.Ports/System.Device.Ports.SerialPort/System.Device.Ports.SerialPort.csproj
Outdated
Show resolved
Hide resolved
src/System.Device.Ports/System.Device.Ports.SerialPort/System.Device.Ports.SerialPort.csproj
Outdated
Show resolved
Hide resolved
src/System.Device.Ports/System.Device.Ports.SerialPort/System.Device.Ports.SerialPort.csproj
Outdated
Show resolved
Hide resolved
...vice.Ports/System.Device.Ports.SerialPort/buildTransitive/net5.0/System.Device.Ports.targets
Outdated
Show resolved
Hide resolved
using System.Net.Sockets; | ||
using System.Runtime.InteropServices; | ||
|
||
using Microsoft.Win32.SafeHandles; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NIT: extra space.
using System.Device.Ports.SerialPort.Resources; | ||
using System.IO; | ||
|
||
using Marshal = System.Runtime.InteropServices.Marshal; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NIT: why do we need to use aliases?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just got the code from the original SerialPort class, no particular reason.
src/System.Device.Ports/System.Device.Ports.SerialPort/Interop/Unix/Interop.Unix.Libraries.cs
Outdated
Show resolved
Hide resolved
src/System.Device.Ports/System.Device.Ports.SerialPort/Resources/Strings.Designer.cs
Outdated
Show resolved
Hide resolved
...evice.Ports/System.Device.Ports.SerialPort.Tests/System.Device.Ports.SerialPort.Tests.csproj
Show resolved
Hide resolved
Thanks for starting to work on this @raffaeler and sorry for the delayed review. I added some comments but feel free to only address what you think you should for this first iteration. I'm fine if you decide to address some of those changes in a follow up PR. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks good to me as a starting point. We should probably consider naming the library System.Device.Ports instead of System.Device.Ports.SerialPort, but no need to block the PR for that as we can continue to make progress and discuss naming and structure later in API Review.
…-neutral properties with validations. New platform specific skeleton methods.
…c implementations
After a brief discussion with @joperezr , I implemented the factory pattern to avoid separate builds for each platform. I will first start implementing the Windows communication to see if there is the need to change something. Next "experimental step":
The goal of the experimental step is to provide the following communication patterns without having to deal with the serial port specifics:
|
{ | ||
/// <summary> | ||
/// A character was received and placed in the input buffer. | ||
/// In the Windows implementation, this is EV_RXCHAR. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd leave platform implementation details out of here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agree. I just ported the class in the project to resolve other issues in the first place.
if (value == _breakState) | ||
{ | ||
return; | ||
} | ||
*/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you write a comment why this is commented out?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am going to add this comment:
In the old implementation SetBreakState is set every time using platform specific code for this reason, this code is commented but I left it here because the old behavior is still to be confirmed.
{ | ||
get | ||
{ | ||
if (!_isOpen) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should we have similar check everywhere?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have to see as soon as something starts working.
I am trying to port the same behavior of the SerialPort
even if the code is different.
/// <summary> | ||
/// Gets or sets the byte encoding for pre- and post-transmission conversion of text. | ||
/// </summary> | ||
public Encoding Encoding |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd prefer we didn't depend on encoding (i.e. remove all string related helper methods and encourage people to use string writer)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As I wrote in my comment after the last push, I am willing to remove any read/write method from the SerialPort class.
Instead, I plan to add a sort of "plugin" (based on an interface) that allows to customize the typology of reads/writes.
For example Laurent asked to have separate streams for the read and write channels.
This is the initial work to create a new SerialPort class as for #1832.
The initial phase is the following:
More to come.
Microsoft Reviewers: Open in CodeFlow