Skip to content

Move EnhancedSerialPort and SerialConnection out of OBD.Desktop #22

Open

Description

@Penlane

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?

Activity

  1. DarthAffe commented on Sep 16, 2021

    @DarthAffe
    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.

  2. Penlane commented on Oct 5, 2021

    @Penlane
    Author

    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions