Example #1
0
        public static void EngineConnect()
        {
            var veh = config.GetVehicle(config.Vehicle);

            if (veh == null)
            {
                veh = new ConfigVehicleData();
            }

            if (HOBD.engine == null)
            {
                HOBD.engine = Engine.CreateInstance(veh.ECUEngine);
            }

            IStream stream = null;

            if (config.Port.StartsWith("btspp"))
            {
                stream = new BluetoothStream();
            }
            else if (config.Port.StartsWith("tcp"))
            {
                stream = new TCPStream();
            }
            else
            {
                stream = new SerialStream();
            }

            engine.Deactivate();
            engine.Registry = Registry;
            engine.Init(stream, config.Port, "");
        }
Example #2
0
        public static void EngineConnect()
        {
            if (HOBD.engine == null)
                HOBD.engine = Engine.CreateInstance(config.GetVehicle(config.Vehicle).ECUEngine);

            IStream stream = null;
            if (config.Port.StartsWith("btspp"))
                stream = new BluetoothStream();
            else
                stream = new SerialStream();

            engine.Deactivate();
            engine.Registry = Registry;
            engine.Init(stream, config.Port, "");
        }
Example #3
0
        public void Open(String url)
        {
            var u = SerialStream.ParseUrl(url);

            Logger.trace("SerialStream", "Port " + u[0] + " baud " + u[1] + " parity " + u[2] + " hs " + u[3]);

            var baudRate = 38400;
            var parity   = Parity.None;
            var dataBits = 8;
            var stopBits = StopBits.One;

            if (u[URL_BAUD] != null)
            {
                baudRate = int.Parse(u[URL_BAUD]);
            }
            switch (u[URL_PARITY])
            {
            case "none":
                parity = Parity.None;
                break;

            case "odd":
                parity = Parity.Odd;
                break;

            case "even":
                parity = Parity.Even;
                break;

            case "mark":
                parity = Parity.Mark;
                break;

            case "space":
                parity = Parity.Space;
                break;
            }

            try
            {
                port = new SerialPort(u[URL_PORT], baudRate, parity, dataBits, stopBits);
                switch (u[URL_HANDSHAKE])
                {
                case "none":
                    port.Handshake = Handshake.None;
                    break;

                case "x":
                    port.Handshake = Handshake.XOnXOff;
                    break;

                case "rts":
                    port.Handshake = Handshake.RequestToSend;
                    break;

                case "xrts":
                    port.Handshake = Handshake.RequestToSendXOnXOff;
                    break;
                }
                port.ReadBufferSize         = 0x40;
                port.ReceivedBytesThreshold = 1;
                port.ReadTimeout            = 2000;
                port.WriteTimeout           = 2000;
            }
            catch (Exception) {}

            try
            {
                port.Open();
            }
            catch (Exception)
            {
                Close();
                throw;
            }
        }