Ejemplo n.º 1
0
        public override string Communicate(ParameterIdentification pid, int timeout = 300)
        {
            // check if the header needs to be set
            if (pid.Header != currentJ1850Header &&
                !string.IsNullOrEmpty(pid.Header))
            {
                string response = SendCommand(Protocols.Elm327.SetFrameHeader(pid.Header));
                if (!response.Contains(Protocols.Elm327.Responses.OK))
                {
                    Diagnostics.DiagnosticLogger.Log("Could not set frame header for PID" + System.Environment.NewLine + pid.ToString());
                    return(null);
                }
            }
            else if (string.IsNullOrEmpty(pid.Header))
            {
                string response = SendCommand(Protocols.Elm327.SetFrameHeader(Protocols.J1850.Headers.Default));
                if (!response.Contains(Protocols.Elm327.Responses.OK))
                {
                    Diagnostics.DiagnosticLogger.Log("Could not set default frame header for PID" + System.Environment.NewLine + pid.ToString());
                    return(null);
                }
            }

            return(pid.SimulatedResponse(this.Protocol));
        }
Ejemplo n.º 2
0
        public override string Communicate(ParameterIdentification pid, int timeout = 300)
        {
            // only the J1850 protocol needs to set the header,
            // CAN and others do not have the same set-header commands
            if (Protocol == Protocols.Protocol.J1850)
            {
                // check if the header needs to be set
                if (//pid.Header != currentJ1850Header &&
                    !string.IsNullOrEmpty(pid.Header))
                {
                    if (lastFrameHeader != pid.Header)
                    {
                        string response = SendCommand(Protocols.Elm327.SetFrameHeader(pid.Header));
                        if (!response.Contains(Protocols.Elm327.Responses.OK))
                        {
                            Diagnostics.DiagnosticLogger.Log("Could not set frame header for PID" + System.Environment.NewLine + pid.ToString());
                            return(null);
                        }

                        lastFrameHeader = pid.Header;
                    }
                }
                else if (string.IsNullOrEmpty(pid.Header))
                {
                    if (lastFrameHeader != Protocols.J1850.Headers.Default)
                    {
                        string response = SendCommand(Protocols.Elm327.SetFrameHeader(Protocols.J1850.Headers.Default));
                        if (!response.Contains(Protocols.Elm327.Responses.OK))
                        {
                            Diagnostics.DiagnosticLogger.Log("Could not set default frame header for PID" + System.Environment.NewLine + pid.ToString());
                            return(null);
                        }

                        lastFrameHeader = Protocols.J1850.Headers.Default;
                    }
                }
            }

            // send the pid value first
            if (Send(pid))
            {
                //System.Threading.Thread.Sleep(100); // FIXME: find a better way to wait for the entire data packet than just sleeping

                // if sending was successful then try to receive
                return(Receive(timeout));
            }

            // sending did not work, return false
            return(null);
        }