Example #1
0
        public void TestNoErrorReturnMessage()
        {
            int    mode          = 01;
            int    pid           = 00;
            string returnMessage = "7E8 06 41 00 BE 3F A8 11 \r\n\r\n>";

            PIDSensor testPID = new PIDSensor(mode, pid, 2, null, "no desc");

            testPID.parseResponse(returnMessage);
        }
        public void TestNewDataSubscriber()
        {
            ConfigurationData          config = new ConfigurationData();
            OBDDeviceCommunicatorAsync obd    = new OBDDeviceCommunicatorAsync(null, config);


            string PIDreturn_engineLoad = "7E8 03 41 04 FF";
            // 0x03 bytes, mode (0x41 - 0x40) = 0x01, PID 0x04, message 0xFF = 0d255
            // betekenis: Calculated engine load value (%). Formule: A*100/255 = 255*100/255 = 100%
            string expectedAnswer = "100";
            int    mode           = 0x01;
            int    sensor         = 0x04;

            bool      answered        = false;
            string    answer          = "";
            PIDSensor loadValueSensor = config.GetSensor(mode, sensor);

            loadValueSensor.RaiseOBDSensorData += (object sender, OBDSensorDataEventArgs s) =>
            {
                answer   = s.value;
                answered = true;
            };
            obd.cleanAndHandleResponses(PIDreturn_engineLoad);
            DateTime startWaiting = DateTime.Now;

            while (!answered && DateTime.Now > startWaiting.AddSeconds(1))
            {
                ;
            }
            Assert.IsTrue(answered, "Event didn't raise within one second");
            Assert.IsTrue(answer == expectedAnswer, "Event value incorrect: is %s, should be %s", answer, expectedAnswer);

            // string PIDreturn_throttlePosition = "7E8 03 41 04 1B";
            // 0x03 bytes, mode (0x41 - 0x40) = 0x01, PID 0x11 = 0d17, message 0x26 = 0d38
            // betekenis: Throttle position (%). Formule: A*100/255 = 38*100/255 = 7%
        }