예제 #1
0
        /// <summary>
        /// Invoked after the read response has been received from the ECU
        /// </summary>
        private void BlockReadResponseReceived(IAsyncResult asyncResult)
        {
            BlockReadAsyncResult internalState = (BlockReadAsyncResult)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();
        }
예제 #2
0
        /// <summary>
        /// Read a block of RAM from the ECU
        /// </summary>
        public IAsyncResult BeginBlockRead(int address, int length, AsyncCallback callback, object state)
        {
            this.BeginOperation();

            BlockReadAsyncResult internalState = new BlockReadAsyncResult(callback, state);
            SsmPacket            request       = SsmPacket.CreateBlockReadRequest(address, length);

            this.stream.BeginWrite(
                request.Data,
                0,
                request.Data.Length,
                this.BlockReadRequestWritten,
                internalState);
            return(internalState);
        }
예제 #3
0
        /// <summary>
        /// Returns the read results to the caller
        /// </summary>
        public byte[] EndBlockRead(IAsyncResult asyncResult)
        {
            BlockReadAsyncResult internalState = (BlockReadAsyncResult)asyncResult;

            try
            {
                this.EndOperation();

                if (internalState.Exception != null)
                {
                    throw internalState.Exception;
                }

                return(internalState.Values);
            }
            finally
            {
                //internalState.Dispose();
            }
        }
예제 #4
0
        /// <summary>
        /// Invoked after the read request has been written to the ECU - begins waiting for the response
        /// </summary>
        private void BlockReadRequestWritten(IAsyncResult asyncResult)
        {
            BlockReadAsyncResult internalState = (BlockReadAsyncResult)asyncResult.AsyncState;

            try
            {
                this.stream.EndWrite(asyncResult);
                internalState.Parser.BeginReadFromStream(
                    stream,
                    BlockReadResponseReceived,
                    internalState);
            }
            catch (IOException ex)
            {
                internalState.Exception = ex;
                internalState.Completed();
            }
            catch (SecurityException ex)
            {
                internalState.Exception = ex;
                internalState.Completed();
            }
        }