From 9948f33a4f77fb96ed51aebec49a00c198b4f477 Mon Sep 17 00:00:00 2001 From: Darth Affe Date: Tue, 11 Aug 2020 20:32:21 +0200 Subject: [PATCH] Added method to request data with a non-generic type-parameter --- OBD.NET/OBD.NET.Common/Devices/ELM327.cs | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/OBD.NET/OBD.NET.Common/Devices/ELM327.cs b/OBD.NET/OBD.NET.Common/Devices/ELM327.cs index 372d5ca..1c96122 100644 --- a/OBD.NET/OBD.NET.Common/Devices/ELM327.cs +++ b/OBD.NET/OBD.NET.Common/Devices/ELM327.cs @@ -134,6 +134,18 @@ namespace OBD.NET.Common.Devices return await RequestDataAsync(pid) as T; } + /// + /// Requests the data asynchronous and return the data when available + /// + /// + /// + public virtual async Task RequestDataAsync(Type type) + { + Logger?.WriteLine("Requesting Type " + type.Name + " ...", OBDLogLevel.Debug); + byte pid = ResolvePid(type); + return await RequestDataAsync(pid) as IOBDData; + } + /// /// Request data based on a pid /// @@ -182,9 +194,12 @@ namespace OBD.NET.Common.Devices protected virtual byte ResolvePid() where T : class, IOBDData, new() + => ResolvePid(typeof(T)); + + protected virtual byte ResolvePid(Type type) { - if (!PidCache.TryGetValue(typeof(T), out byte pid)) - pid = AddToPidCache(); + if (!PidCache.TryGetValue(type, out byte pid)) + pid = AddToPidCache(type); return pid; }