Skip to content

Commit

Permalink
Merge pull request #10 from ChrisPea/master
Browse files Browse the repository at this point in the history
copied and override sendReadRequest in KWP/KWPHandler.cs to fit to th…
  • Loading branch information
mattiasclaesson committed Nov 3, 2015
2 parents 4295b8a + 5c2e34c commit 5a0589e
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 0 deletions.
33 changes: 33 additions & 0 deletions TrionicCANLib/KWP/KWPHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -838,6 +838,39 @@ public KWPResult sendReadSymbolMapRequest()
return result;
}

/// <summary>
/// This method send a request for reading from ECU memory (both RAM and flash).
/// It sets up start address and the length to read. The resulting response contains the requested values.
/// </summary>
/// <param name="a_address">The address to start reading from.</param>
/// <param name="a_length">The total length to read.</param>
/// <returns>true on success, otherwise false</returns>
public bool sendReadRequest(uint a_address, uint a_length, out byte[] data)
{
logger.Debug("sendReadRequest");

KWPReply reply = new KWPReply();
KWPResult result;
data = new byte[a_length];
byte[] lengthAndAddress = new byte[6];
//set address and length (byte 0)
lengthAndAddress[0] = (byte)(a_address >> 16);
lengthAndAddress[1] = (byte)(a_address >> 8);
lengthAndAddress[2] = (byte)(a_address);
lengthAndAddress[3] = (byte)(a_length);
lengthAndAddress[4] = 0x01;
lengthAndAddress[5] = 0;
KWPRequest request = new KWPRequest(0x23, lengthAndAddress);
request.ElmExpectedResponses = 1;
result = sendRequest(request, out reply);
data = reply.getData();

if (result == KWPResult.OK)
return true;
else
return false;
}

/// <summary>
/// This method send a request for reading from ECU memory (both RAM and flash).
/// It sets up start address and the length to read.
Expand Down
26 changes: 26 additions & 0 deletions TrionicCANLib/Trionic7.cs
Original file line number Diff line number Diff line change
Expand Up @@ -569,6 +569,32 @@ public byte[] ReadMapfromSRAM(SymbolHelper sh, bool showProgress)
return completedata;
}

public byte[] ReadValueFromSRAM(Int64 sramaddress, Int32 length, out bool _success)
{
_success = false;
byte[] data = new byte[length];
try
{
KWPHandler.getInstance().requestSequrityAccess(false);

if (canUsbDevice is LPCCANDevice) // or ELM327?
{
Thread.Sleep(1);
}
if (KWPHandler.getInstance().sendReadRequest((uint)(sramaddress), (uint)length, out data))
{
Thread.Sleep(0); //<GS-11022010>
_success = true;
}
}

catch (Exception E)
{
logger.Debug("Failed to read memory: " + E.Message);
}
return data;
}

public byte[] ReadMapFromSRAM(Int64 sramaddress, Int32 length, out bool _success)
{
_success = false;
Expand Down

0 comments on commit 5a0589e

Please sign in to comment.