/// <summary> /// Invoked after the read response has been received from the ECU /// </summary> private void MultipleReadResponseReceived(IAsyncResult asyncResult) { MultipleReadAsyncResult internalState = (MultipleReadAsyncResult)asyncResult.AsyncState; try { SsmPacket response = internalState.Parser.EndReadFromStream(asyncResult); // Uncomment for easier debugging: //byte[] data = response.Data; //SsmCommand command = response.Command; //int payloadLength = response.PayloadLength; //IList<byte> values = response.Values; foreach (byte value in response.Values) { internalState.ValueList.Add(value); } } catch (IOException ex) { internalState.Exception = ex; } catch (SecurityException ex) { internalState.Exception = ex; } internalState.Completed(); }
/// <summary> /// Begins reading multiple disjoint addesses from the ECU /// </summary> public IAsyncResult BeginMultipleRead(IList <int> addresses, AsyncCallback callback, object state) { this.BeginOperation(); MultipleReadAsyncResult internalState = new MultipleReadAsyncResult(callback, state); SsmPacket request = SsmPacket.CreateMultipleReadRequest(addresses); this.stream.BeginWrite( request.Data, 0, request.Data.Length, this.MultipleReadRequestWritten, internalState); return(internalState); }
/// <summary> /// Returns the read results to the caller /// </summary> public byte[] EndMultipleRead(IAsyncResult asyncResult) { MultipleReadAsyncResult internalState = (MultipleReadAsyncResult)asyncResult; try { this.EndOperation(); if (internalState.Exception != null) { throw internalState.Exception; } return(internalState.Values); } finally { //internalState.Dispose(); } }
/// <summary> /// Invoked after the read request has been written to the ECU - begins waiting for the response /// </summary> private void MultipleReadRequestWritten(IAsyncResult asyncResult) { MultipleReadAsyncResult internalState = (MultipleReadAsyncResult)asyncResult.AsyncState; try { this.stream.EndWrite(asyncResult); internalState.Parser.BeginReadFromStream( stream, MultipleReadResponseReceived, internalState); } catch (IOException ex) { internalState.Exception = ex; internalState.Completed(); } catch (SecurityException ex) { internalState.Exception = ex; internalState.Completed(); } }