Skip to content

Move EnhancedSerialPort and SerialConnection out of OBD.Desktop #22

@Penlane

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?

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