mirror of
https://github.com/DarthAffe/OBD.NET.git
synced 2025-12-13 09:18:31 +00:00
Changed the code to be valid with C#6 to fix #7
This commit is contained in:
parent
59e8580e8d
commit
2435abc2bd
@ -158,7 +158,8 @@ namespace OBD.NET.Common.Devices
|
|||||||
CommandResult result = SendCommand(((int)Mode.ShowStoredDiagnosticTroubleCodes).ToString());
|
CommandResult result = SendCommand(((int)Mode.ShowStoredDiagnosticTroubleCodes).ToString());
|
||||||
await result.WaitHandle.WaitAsync();
|
await result.WaitHandle.WaitAsync();
|
||||||
|
|
||||||
if (!(result.Result is List<TroubleCode> resultCodes)) return new TroubleCode[0];
|
List<TroubleCode> resultCodes = result.Result as List<TroubleCode>;
|
||||||
|
if (resultCodes == null) return new TroubleCode[0];
|
||||||
|
|
||||||
int count = Math.Min(dtcStatus.DTCCount, resultCodes.Count);
|
int count = Math.Min(dtcStatus.DTCCount, resultCodes.Count);
|
||||||
return resultCodes.Take(count).ToArray();
|
return resultCodes.Take(count).ToArray();
|
||||||
@ -179,15 +180,18 @@ namespace OBD.NET.Common.Devices
|
|||||||
{
|
{
|
||||||
case Mode.ShowCurrentData:
|
case Mode.ShowCurrentData:
|
||||||
byte pid = (byte)message.Substring(2, 2).GetHexVal();
|
byte pid = (byte)message.Substring(2, 2).GetHexVal();
|
||||||
if (DataTypeCache.TryGetValue(pid, out Type dataType))
|
Type dataType;
|
||||||
|
if (DataTypeCache.TryGetValue(pid, out dataType))
|
||||||
{
|
{
|
||||||
IOBDData obdData = (IOBDData)Activator.CreateInstance(dataType);
|
IOBDData obdData = (IOBDData)Activator.CreateInstance(dataType);
|
||||||
obdData.Load(message.Substring(4));
|
obdData.Load(message.Substring(4));
|
||||||
|
|
||||||
if (DataReceivedEventHandlers.TryGetValue(dataType, out IDataEventManager dataEventManager))
|
IDataEventManager dataEventManager;
|
||||||
|
if (DataReceivedEventHandlers.TryGetValue(dataType, out dataEventManager))
|
||||||
dataEventManager.RaiseEvent(this, obdData, timestamp);
|
dataEventManager.RaiseEvent(this, obdData, timestamp);
|
||||||
|
|
||||||
if (DataReceivedEventHandlers.TryGetValue(typeof(IOBDData), out IDataEventManager genericDataEventManager))
|
IDataEventManager genericDataEventManager;
|
||||||
|
if (DataReceivedEventHandlers.TryGetValue(typeof(IOBDData), out genericDataEventManager))
|
||||||
genericDataEventManager.RaiseEvent(this, obdData, timestamp);
|
genericDataEventManager.RaiseEvent(this, obdData, timestamp);
|
||||||
|
|
||||||
return obdData;
|
return obdData;
|
||||||
@ -214,7 +218,8 @@ namespace OBD.NET.Common.Devices
|
|||||||
protected virtual byte ResolvePid<T>()
|
protected virtual byte ResolvePid<T>()
|
||||||
where T : class, IOBDData, new()
|
where T : class, IOBDData, new()
|
||||||
{
|
{
|
||||||
if (!PidCache.TryGetValue(typeof(T), out byte pid))
|
byte pid;
|
||||||
|
if (!PidCache.TryGetValue(typeof(T), out pid))
|
||||||
pid = AddToPidCache<T>();
|
pid = AddToPidCache<T>();
|
||||||
|
|
||||||
return pid;
|
return pid;
|
||||||
@ -269,7 +274,8 @@ namespace OBD.NET.Common.Devices
|
|||||||
|
|
||||||
public void SubscribeDataReceived<T>(DataReceivedEventHandler<T> eventHandler) where T : IOBDData
|
public void SubscribeDataReceived<T>(DataReceivedEventHandler<T> eventHandler) where T : IOBDData
|
||||||
{
|
{
|
||||||
if (!DataReceivedEventHandlers.TryGetValue(typeof(T), out IDataEventManager eventManager))
|
IDataEventManager eventManager;
|
||||||
|
if (!DataReceivedEventHandlers.TryGetValue(typeof(T), out eventManager))
|
||||||
DataReceivedEventHandlers.Add(typeof(T), (eventManager = new GenericDataEventManager<T>()));
|
DataReceivedEventHandlers.Add(typeof(T), (eventManager = new GenericDataEventManager<T>()));
|
||||||
|
|
||||||
((GenericDataEventManager<T>)eventManager).DataReceived += eventHandler;
|
((GenericDataEventManager<T>)eventManager).DataReceived += eventHandler;
|
||||||
@ -277,7 +283,8 @@ namespace OBD.NET.Common.Devices
|
|||||||
|
|
||||||
public void UnsubscribeDataReceived<T>(DataReceivedEventHandler<T> eventHandler) where T : IOBDData
|
public void UnsubscribeDataReceived<T>(DataReceivedEventHandler<T> eventHandler) where T : IOBDData
|
||||||
{
|
{
|
||||||
if (DataReceivedEventHandlers.TryGetValue(typeof(T), out IDataEventManager eventManager))
|
IDataEventManager eventManager;
|
||||||
|
if (DataReceivedEventHandlers.TryGetValue(typeof(T), out eventManager))
|
||||||
((GenericDataEventManager<T>)eventManager).DataReceived -= eventHandler;
|
((GenericDataEventManager<T>)eventManager).DataReceived -= eventHandler;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -10,6 +10,10 @@
|
|||||||
<Version>1.1.0</Version>
|
<Version>1.1.0</Version>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
|
||||||
|
<LangVersion>6</LangVersion>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Folder Include="Properties\" />
|
<Folder Include="Properties\" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|||||||
@ -13,7 +13,7 @@ namespace OBD.NET.Common.OBDData
|
|||||||
private byte[] _rawData;
|
private byte[] _rawData;
|
||||||
public byte[] RawData
|
public byte[] RawData
|
||||||
{
|
{
|
||||||
get => _rawData;
|
get { return _rawData; }
|
||||||
set
|
set
|
||||||
{
|
{
|
||||||
if (value.Length != _length)
|
if (value.Length != _length)
|
||||||
|
|||||||
@ -10,7 +10,6 @@ namespace OBD.NET.Common.OBDData.DTC
|
|||||||
|
|
||||||
private static readonly Dictionary<TroublePart, string> PART_DESCRIPTION = new Dictionary<TroublePart, string>
|
private static readonly Dictionary<TroublePart, string> PART_DESCRIPTION = new Dictionary<TroublePart, string>
|
||||||
{
|
{
|
||||||
|
|
||||||
{ TroublePart.Powertrain, "P" },
|
{ TroublePart.Powertrain, "P" },
|
||||||
{ TroublePart.Chassis, "C" },
|
{ TroublePart.Chassis, "C" },
|
||||||
{ TroublePart.Body, "B" },
|
{ TroublePart.Body, "B" },
|
||||||
@ -21,16 +20,16 @@ namespace OBD.NET.Common.OBDData.DTC
|
|||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
byte data = (byte)(A & 0b11000000);
|
byte data = (byte)(A & 0xC0);
|
||||||
switch (data)
|
switch (data)
|
||||||
{
|
{
|
||||||
case 0:
|
case 0:
|
||||||
return TroublePart.Powertrain;
|
return TroublePart.Powertrain;
|
||||||
case 0b01000000:
|
case 0x40:
|
||||||
return TroublePart.Chassis;
|
return TroublePart.Chassis;
|
||||||
case 0b10000000:
|
case 0x80:
|
||||||
return TroublePart.Body;
|
return TroublePart.Body;
|
||||||
case 0b11000000:
|
case 0xC0:
|
||||||
return TroublePart.Network;
|
return TroublePart.Network;
|
||||||
default:
|
default:
|
||||||
throw new IndexOutOfRangeException($"Can't parse TroublePart with data {data}");
|
throw new IndexOutOfRangeException($"Can't parse TroublePart with data {data}");
|
||||||
@ -42,16 +41,16 @@ namespace OBD.NET.Common.OBDData.DTC
|
|||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
byte data = (byte)(A & 0b00110000);
|
byte data = (byte)(A & 0x30);
|
||||||
switch (data)
|
switch (data)
|
||||||
{
|
{
|
||||||
case 0:
|
case 0x0:
|
||||||
return Definition.SAEJ2012;
|
return Definition.SAEJ2012;
|
||||||
case 0b01000000:
|
case 0x40:
|
||||||
return Definition.Custom;
|
return Definition.Custom;
|
||||||
case 0b10000000:
|
case 0x80:
|
||||||
return Definition.Undefined;
|
return Definition.Undefined;
|
||||||
case 0b11000000:
|
case 0xC0:
|
||||||
return Definition.Undefined2;
|
return Definition.Undefined2;
|
||||||
default:
|
default:
|
||||||
throw new IndexOutOfRangeException($"Can't parse Definition with data {data}");
|
throw new IndexOutOfRangeException($"Can't parse Definition with data {data}");
|
||||||
@ -59,7 +58,7 @@ namespace OBD.NET.Common.OBDData.DTC
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public SpecificPart SpecificPart => (SpecificPart)(A & 0b00001111);
|
public SpecificPart SpecificPart => (SpecificPart)(A & 0xF);
|
||||||
|
|
||||||
public string FaultCode => B.ToHexString();
|
public string FaultCode => B.ToHexString();
|
||||||
|
|
||||||
|
|||||||
@ -1,14 +1,12 @@
|
|||||||
|
|
||||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||||
# Visual Studio 15
|
# Visual Studio 15
|
||||||
VisualStudioVersion = 15.0.26403.7
|
VisualStudioVersion = 15.0.27130.2027
|
||||||
MinimumVisualStudioVersion = 10.0.40219.1
|
MinimumVisualStudioVersion = 10.0.40219.1
|
||||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OBD.NET.Common", "OBD.NET.Common\OBD.NET.Common.csproj", "{D985B70E-CDF3-4CF1-AB5D-8D19C7FE7B31}"
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OBD.NET.Common", "OBD.NET.Common\OBD.NET.Common.csproj", "{D985B70E-CDF3-4CF1-AB5D-8D19C7FE7B31}"
|
||||||
EndProject
|
EndProject
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ODB.NET.Desktop", "ODB.NET.Desktop\ODB.NET.Desktop.csproj", "{14CB98E1-95DE-4923-8896-FDF5171AA49E}"
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ODB.NET.Desktop", "ODB.NET.Desktop\ODB.NET.Desktop.csproj", "{14CB98E1-95DE-4923-8896-FDF5171AA49E}"
|
||||||
EndProject
|
EndProject
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OBD.NET.Universal", "OBD.NET.Universal\OBD.NET.Universal.csproj", "{E0EAFF82-C514-4827-8F49-F1928EBA8E73}"
|
|
||||||
EndProject
|
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ODB.NET.ConsoleClient", "ODB.NET.ConsoleClient\ODB.NET.ConsoleClient.csproj", "{8F8EC5D5-94BD-47CF-9714-CA8C0198BDDC}"
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ODB.NET.ConsoleClient", "ODB.NET.ConsoleClient\ODB.NET.ConsoleClient.csproj", "{8F8EC5D5-94BD-47CF-9714-CA8C0198BDDC}"
|
||||||
EndProject
|
EndProject
|
||||||
Global
|
Global
|
||||||
@ -55,22 +53,6 @@ Global
|
|||||||
{14CB98E1-95DE-4923-8896-FDF5171AA49E}.Release|x64.Build.0 = Release|Any CPU
|
{14CB98E1-95DE-4923-8896-FDF5171AA49E}.Release|x64.Build.0 = Release|Any CPU
|
||||||
{14CB98E1-95DE-4923-8896-FDF5171AA49E}.Release|x86.ActiveCfg = Release|Any CPU
|
{14CB98E1-95DE-4923-8896-FDF5171AA49E}.Release|x86.ActiveCfg = Release|Any CPU
|
||||||
{14CB98E1-95DE-4923-8896-FDF5171AA49E}.Release|x86.Build.0 = Release|Any CPU
|
{14CB98E1-95DE-4923-8896-FDF5171AA49E}.Release|x86.Build.0 = Release|Any CPU
|
||||||
{E0EAFF82-C514-4827-8F49-F1928EBA8E73}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
|
||||||
{E0EAFF82-C514-4827-8F49-F1928EBA8E73}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
|
||||||
{E0EAFF82-C514-4827-8F49-F1928EBA8E73}.Debug|ARM.ActiveCfg = Debug|ARM
|
|
||||||
{E0EAFF82-C514-4827-8F49-F1928EBA8E73}.Debug|ARM.Build.0 = Debug|ARM
|
|
||||||
{E0EAFF82-C514-4827-8F49-F1928EBA8E73}.Debug|x64.ActiveCfg = Debug|x64
|
|
||||||
{E0EAFF82-C514-4827-8F49-F1928EBA8E73}.Debug|x64.Build.0 = Debug|x64
|
|
||||||
{E0EAFF82-C514-4827-8F49-F1928EBA8E73}.Debug|x86.ActiveCfg = Debug|x86
|
|
||||||
{E0EAFF82-C514-4827-8F49-F1928EBA8E73}.Debug|x86.Build.0 = Debug|x86
|
|
||||||
{E0EAFF82-C514-4827-8F49-F1928EBA8E73}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
|
||||||
{E0EAFF82-C514-4827-8F49-F1928EBA8E73}.Release|Any CPU.Build.0 = Release|Any CPU
|
|
||||||
{E0EAFF82-C514-4827-8F49-F1928EBA8E73}.Release|ARM.ActiveCfg = Release|ARM
|
|
||||||
{E0EAFF82-C514-4827-8F49-F1928EBA8E73}.Release|ARM.Build.0 = Release|ARM
|
|
||||||
{E0EAFF82-C514-4827-8F49-F1928EBA8E73}.Release|x64.ActiveCfg = Release|x64
|
|
||||||
{E0EAFF82-C514-4827-8F49-F1928EBA8E73}.Release|x64.Build.0 = Release|x64
|
|
||||||
{E0EAFF82-C514-4827-8F49-F1928EBA8E73}.Release|x86.ActiveCfg = Release|x86
|
|
||||||
{E0EAFF82-C514-4827-8F49-F1928EBA8E73}.Release|x86.Build.0 = Release|x86
|
|
||||||
{8F8EC5D5-94BD-47CF-9714-CA8C0198BDDC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
{8F8EC5D5-94BD-47CF-9714-CA8C0198BDDC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
{8F8EC5D5-94BD-47CF-9714-CA8C0198BDDC}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
{8F8EC5D5-94BD-47CF-9714-CA8C0198BDDC}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
{8F8EC5D5-94BD-47CF-9714-CA8C0198BDDC}.Debug|ARM.ActiveCfg = Debug|Any CPU
|
{8F8EC5D5-94BD-47CF-9714-CA8C0198BDDC}.Debug|ARM.ActiveCfg = Debug|Any CPU
|
||||||
@ -91,4 +73,7 @@ Global
|
|||||||
GlobalSection(SolutionProperties) = preSolution
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
HideSolutionNode = FALSE
|
HideSolutionNode = FALSE
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
|
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||||
|
SolutionGuid = {3B1EAB3A-F27B-451F-B23C-48D12E10AD80}
|
||||||
|
EndGlobalSection
|
||||||
EndGlobal
|
EndGlobal
|
||||||
|
|||||||
@ -22,6 +22,7 @@
|
|||||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||||
<ErrorReport>prompt</ErrorReport>
|
<ErrorReport>prompt</ErrorReport>
|
||||||
<WarningLevel>4</WarningLevel>
|
<WarningLevel>4</WarningLevel>
|
||||||
|
<LangVersion>6</LangVersion>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||||
|
|||||||
@ -63,9 +63,15 @@ namespace ODB.NET.Desktop.Communication
|
|||||||
|
|
||||||
public void Dispose() => _serialPort?.Dispose();
|
public void Dispose() => _serialPort?.Dispose();
|
||||||
|
|
||||||
public Task ConnectAsync() => throw new NotSupportedException("Asynchronous operations not supported");
|
public Task ConnectAsync()
|
||||||
|
{
|
||||||
|
throw new NotSupportedException("Asynchronous operations not supported");
|
||||||
|
}
|
||||||
|
|
||||||
public Task WriteAsync(byte[] data) => throw new NotSupportedException("Asynchronous operations not supported");
|
public Task WriteAsync(byte[] data)
|
||||||
|
{
|
||||||
|
throw new NotSupportedException("Asynchronous operations not supported");
|
||||||
|
}
|
||||||
|
|
||||||
public void Write(byte[] data) => _serialPort.Write(data, 0, data.Length);
|
public void Write(byte[] data) => _serialPort.Write(data, 0, data.Length);
|
||||||
|
|
||||||
|
|||||||
@ -21,6 +21,7 @@
|
|||||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||||
<ErrorReport>prompt</ErrorReport>
|
<ErrorReport>prompt</ErrorReport>
|
||||||
<WarningLevel>4</WarningLevel>
|
<WarningLevel>4</WarningLevel>
|
||||||
|
<LangVersion>6</LangVersion>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||||
<DebugType>pdbonly</DebugType>
|
<DebugType>pdbonly</DebugType>
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user