Example #1
0
        public OltProtocol()
        {
            Version     = OltProtocolVersion.OltDiagV1;
            diagRequest = OltDiagV1DataRequest;
            ReadFreq    = 0;
            Requests    = new Queue <Request>();
            readThread  = new BackgroundWorker {
                WorkerSupportsCancellation = true
            };
            readThread.DoWork += readThread_DoWork;
            serialPort         = new SafeSerialPort("COM1", 10400, Parity.None, 8, StopBits.One)
            {
                WriteTimeout = 100,
                ReadTimeout  = 100
            };

            ecuSn           = new byte[8];
            ecuSnHashBuffer = DiagProtocolHelper.InitEcuSnHashBuffer(ecuSn, 240);
        }
Example #2
0
        /// <summary>
        /// Запуск опроса ЭБУ
        /// </summary>
        /// <returns></returns>
        public bool Start()
        {
            IsBusy         = true;
            lastUpdateTime = DateTime.Now.AddSeconds(5).Ticks;
            try
            {
                serialPort.PortName = PortName;
                serialPort.BaudRate = 10400;
                serialPort.Open();
                serialPort.DiscardInBuffer();
                serialPort.DiscardOutBuffer();
                serialPort.DataReceived += DataReceivedHandler;
                AddOperationLog(String.Format("Open ECU serial port: {0}", PortName));

                AddOperationLog("Send start communication...");
                ExecuteRequest(StartCommunication);
                if (!StartCommunication.Test())
                {
                    AddOperationLog("Error start communication");
                    serialPort.Close();
                    return(false);
                }

                Request startDiag;

                switch (baundRate)
                {
                case enBaundRate.Medium:
                    startDiag = StartDiagnosticSessionMedium;
                    break;

                case enBaundRate.Hi:
                    startDiag = StartDiagnosticSessionHi;
                    break;

                default:
                    startDiag = StartDiagnosticSessionLow;
                    break;
                }

                AddOperationLog("Send start diagnostic session ...");
                ExecuteRequest(startDiag);
                if (!startDiag.Test())
                {
                    AddOperationLog("Error diagnostic session");
                    serialPort.Close();
                    return(false);
                }

                if (baundRate != enBaundRate.Low)
                {
                    SetBaundRate();
                }

                AddOperationLog("Send tester present ...");
                ExecuteRequest(TesterPresent);

                switch (Version)
                {
                case OltProtocolVersion.OltDiagV1:
                    AddOperationLog("Test new diag protocol support ...");
                    ExecuteRequest(J7esOltDiagDataRequest);
                    diagRequest = J7esOltDiagDataRequest.Valid ? J7esOltDiagDataRequest : OltDiagV1DataRequest;
                    break;

                case OltProtocolVersion.OltDiagV3:
                    diagRequest = OltDiagV3DataRequest;
                    break;

                case OltProtocolVersion.Euro2:
                    diagRequest = Euro2DiagDataRequest;
                    break;

                case OltProtocolVersion.Rus83:
                    diagRequest = Rus83DiagDataRequest;
                    break;
                }

                IdleRequest = (Request)diagRequest;
                Connected   = true;

                readThread.RunWorkerAsync();

                return(true);
            }

            finally
            {
                IsBusy = false;
            }
        }