Skip to content
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

Move EnhancedSerialPort and SerialConnection out of OBD.Desktop #22

Open
Penlane opened this issue Aug 24, 2021 · 2 comments
Open

Move EnhancedSerialPort and SerialConnection out of OBD.Desktop #22

Penlane opened this issue Aug 24, 2021 · 2 comments

Comments

@Penlane
Copy link

Penlane commented Aug 24, 2021

Hey there,

I'm using this library to read out OBD data with a Raspberry Pi on Linux.

Short Story: It works!

Long Story: There is no need for the Serial-related classes to be encapsulated in a Windows-Only .NET Framework Namespace, so why keep it there?

In order to make it work, had to manually copy the files to my own namespace and comment out the following lines:

if (!IsWindows)
{
    FieldInfo fieldInfo = BaseStream.GetType().GetField("fd", BindingFlags.Instance | BindingFlags.NonPublic);
    if (fieldInfo == null) throw new NotSupportedException("Unable to initialize SerialPort - 'fd'-field is missing.");
    _fd = (int)fieldInfo.GetValue(BaseStream);

    _disposedFieldInfo = BaseStream.GetType().GetField("disposed", BindingFlags.Instance | BindingFlags.NonPublic);
    if (_disposedFieldInfo == null) throw new NotSupportedException("Unable to initialize SerialPort - 'disposed'-field is missing.");

    fieldInfo = typeof(SerialPort).GetField("data_received", BindingFlags.Instance | BindingFlags.NonPublic);
    if (fieldInfo == null) throw new NotSupportedException("Unable to initialize SerialPort - 'data_received'-field is missing.");
    _dataReceived = fieldInfo.GetValue(this);

    _thread = new Thread(EventThreadFunction);
    _thread.Start();
}

Since it threw exceptions.

Under .NET Core or .NET 5+, Serialports work cross-platform with the System.IO.Ports package. Maybe it's time to move this out of the Desktop package?

@DarthAffe
Copy link
Owner

Ok i see two separate things here:

There is no need for the Serial-related classes to be encapsulated in a Windows-Only .NET Framework Namespace, so why keep it there?

There is no windows / non-windows separation. The desktop/universal split is .NET Framework or UWP.
As long as you run a full framework (.net 5 or >4.6.1 under mono) it's intended to use OBD.Desktop on linux too.

Since it threw exceptions.

That's of course not intended. Without the actual message it's hard to tell but I guess they changed the internals of the serial connection in .net 5. In that case the fix would be to surround this block with a #IF NET461 to only do it for old frameworks.
I can do that but I'm not able to test it.

@Penlane
Copy link
Author

Penlane commented Oct 5, 2021

As long as you run a full framework (.net 5 or >4.6.1 under mono) it's intended to use OBD.Desktop on linux too.

That's neat, I didn't know the cross-platform portion (previously .net core) is considered a full framework as of .net 5.
I thought OBD.Common was cross-platform and OBD.Desktop was limited to Windows or Mono; my misunderstanding.

I can do that but I'm not able to test it.

I can happily test a beta / preview on .net 5 under linux and report back.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants