mirror of
https://github.com/DarthAffe/OBD.NET.git
synced 2025-12-12 16:58:30 +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());
|
||||
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);
|
||||
return resultCodes.Take(count).ToArray();
|
||||
@ -179,15 +180,18 @@ namespace OBD.NET.Common.Devices
|
||||
{
|
||||
case Mode.ShowCurrentData:
|
||||
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);
|
||||
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);
|
||||
|
||||
if (DataReceivedEventHandlers.TryGetValue(typeof(IOBDData), out IDataEventManager genericDataEventManager))
|
||||
IDataEventManager genericDataEventManager;
|
||||
if (DataReceivedEventHandlers.TryGetValue(typeof(IOBDData), out genericDataEventManager))
|
||||
genericDataEventManager.RaiseEvent(this, obdData, timestamp);
|
||||
|
||||
return obdData;
|
||||
@ -214,7 +218,8 @@ namespace OBD.NET.Common.Devices
|
||||
protected virtual byte ResolvePid<T>()
|
||||
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>();
|
||||
|
||||
return pid;
|
||||
@ -269,7 +274,8 @@ namespace OBD.NET.Common.Devices
|
||||
|
||||
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>()));
|
||||
|
||||
((GenericDataEventManager<T>)eventManager).DataReceived += eventHandler;
|
||||
@ -277,7 +283,8 @@ namespace OBD.NET.Common.Devices
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
@ -10,6 +10,10 @@
|
||||
<Version>1.1.0</Version>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
|
||||
<LangVersion>6</LangVersion>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Folder Include="Properties\" />
|
||||
</ItemGroup>
|
||||
|
||||
@ -13,7 +13,7 @@ namespace OBD.NET.Common.OBDData
|
||||
private byte[] _rawData;
|
||||
public byte[] RawData
|
||||
{
|
||||
get => _rawData;
|
||||
get { return _rawData; }
|
||||
set
|
||||
{
|
||||
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>
|
||||
{
|
||||
|
||||
{ TroublePart.Powertrain, "P" },
|
||||
{ TroublePart.Chassis, "C" },
|
||||
{ TroublePart.Body, "B" },
|
||||
@ -21,16 +20,16 @@ namespace OBD.NET.Common.OBDData.DTC
|
||||
{
|
||||
get
|
||||
{
|
||||
byte data = (byte)(A & 0b11000000);
|
||||
byte data = (byte)(A & 0xC0);
|
||||
switch (data)
|
||||
{
|
||||
case 0:
|
||||
return TroublePart.Powertrain;
|
||||
case 0b01000000:
|
||||
case 0x40:
|
||||
return TroublePart.Chassis;
|
||||
case 0b10000000:
|
||||
case 0x80:
|
||||
return TroublePart.Body;
|
||||
case 0b11000000:
|
||||
case 0xC0:
|
||||
return TroublePart.Network;
|
||||
default:
|
||||
throw new IndexOutOfRangeException($"Can't parse TroublePart with data {data}");
|
||||
@ -42,16 +41,16 @@ namespace OBD.NET.Common.OBDData.DTC
|
||||
{
|
||||
get
|
||||
{
|
||||
byte data = (byte)(A & 0b00110000);
|
||||
byte data = (byte)(A & 0x30);
|
||||
switch (data)
|
||||
{
|
||||
case 0:
|
||||
case 0x0:
|
||||
return Definition.SAEJ2012;
|
||||
case 0b01000000:
|
||||
case 0x40:
|
||||
return Definition.Custom;
|
||||
case 0b10000000:
|
||||
case 0x80:
|
||||
return Definition.Undefined;
|
||||
case 0b11000000:
|
||||
case 0xC0:
|
||||
return Definition.Undefined2;
|
||||
default:
|
||||
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();
|
||||
|
||||
|
||||
@ -1,14 +1,12 @@
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio 15
|
||||
VisualStudioVersion = 15.0.26403.7
|
||||
VisualStudioVersion = 15.0.27130.2027
|
||||
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}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ODB.NET.Desktop", "ODB.NET.Desktop\ODB.NET.Desktop.csproj", "{14CB98E1-95DE-4923-8896-FDF5171AA49E}"
|
||||
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}"
|
||||
EndProject
|
||||
Global
|
||||
@ -55,22 +53,6 @@ Global
|
||||
{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.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.Build.0 = Debug|Any CPU
|
||||
{8F8EC5D5-94BD-47CF-9714-CA8C0198BDDC}.Debug|ARM.ActiveCfg = Debug|Any CPU
|
||||
@ -91,4 +73,7 @@ Global
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||
SolutionGuid = {3B1EAB3A-F27B-451F-B23C-48D12E10AD80}
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
|
||||
@ -22,6 +22,7 @@
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<LangVersion>6</LangVersion>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||
|
||||
@ -63,9 +63,15 @@ namespace ODB.NET.Desktop.Communication
|
||||
|
||||
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);
|
||||
|
||||
|
||||
@ -21,6 +21,7 @@
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<LangVersion>6</LangVersion>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<DebugType>pdbonly</DebugType>
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user