DarthAffe / OBD.NET

C#-Library to read data from car through an ELM327-/STN1170-Adapter
GNU General Public License v2.0
178 stars 82 forks source link

Set Service Mode #14

Closed dakriege closed 4 years ago

dakriege commented 4 years ago

I need to request the Vehicle Information using Service 09. The SendCommand function references a static mode 01. I need the retrieve the VIN from service 09. 09 02

You have a TODO to implement different modes in ELM327 in the Mode declaration. What were your thoughts on setting a different service mode ?

I'm going to create new RequestData function. RequestData(service,pid) where the service would be set against the values specified in the Mode declaration.

pid data types should have another member to set the service code.

I'll need to create a data type for the VIN to return the string. 17 bytes.

I'll let your know how it works.

dakriege commented 4 years ago

Recreated a function to send a Service Code 09 , PID 02 Vehicle Vin.

Set mode to : Mode = Mode.RequestVehicleInformation; When the 0902 command is sent the adapter returns a multi line response.

it doesn't appear that you designed the driver to receive a multiple line response from the adapter.

9/20/2019 7:08:37 AM - Debug - Requesting SC 09 Type VehicleVin ... 9/20/2019 7:08:37 AM - Debug - Requesting SC 09: PID 02 ... 9/20/2019 7:08:37 AM - Verbose - Queuing Command: '0902'' 9/20/2019 7:08:37 AM - Verbose - Writing Command: '0902'' 9/20/2019 7:08:37 AM - Verbose - Response: 'SEARCHING...' 9/20/2019 7:08:42 AM - Verbose - Response: '014' 9/20/2019 7:08:42 AM - Verbose - Response: '0:490201314654' 9/20/2019 7:08:42 AM - Verbose - Response: '1:4C523446455842' 9/20/2019 7:08:42 AM - Verbose - Response: '2:50413938393934'

OnDataReceived calls FinishLine() for each line returned in the response. Shouldn't it be testing for '>' end of command, versus FinishLine() on an \r to know the entire response has been sent ?

Finishline() then calls ProcessMessage for each line returned versus concatenating the entire response then calling ProcessMesage.

My VehicleVin data type never gets processed to return the VIN.

It converts the RawData 17 bytes to a String.

I'm going to try some tests in the response processing.

DarthAffe commented 4 years ago

Yes, right now it's not designed to work with multi-line responses, but since the command is finished with the prompt (>) it should be possible to change that without causing too much side effects. I'm just not sure which is better: Making the result more abstract to distinguish between single/multi-line result or changing everything to handle multiple lines (even if data-commands are always returning only one).

dakriege commented 4 years ago

Changes made to the driver to support:

PID 01 01 - Monitor Status of DTCs - Added a new PID data type - DTCStatus which returns a single value indicating - Check Engine and number of active DTCs

Added multi-line response support for Service Mode 03 and 0902

Modified - QueuedCommand class - Added a property to to store a multi-line response string Modified - OnDataReceived() and FinishLine(), InternalProcessMessage(), ProcessResponse(), AbstractOBDData.Load()

OnDataReceived() tests the CurrentCommand.Text for a command 03 (DTC Codes) or a command 0902 (Vin) if either are true a global is set indicating the response is multi-line

If the multi-line global is set the response lines are concatenated and then saved to the raw data buffer. The response classes for the 03 and 0902 are saved as a string. The strings are then parsed in the requestData responses by the application.

Service Mode 03 - Read stored DTC codes - Added a new request data function - RequestDataSC03 which sends the the command '03' to the module. There is no PID.

Service Mode 0902 - Read the VIN - Added a new request Data function - RequestDataSC09