Пример #1
0
        private async Task <string> GetVIN()
        {
            var result = await SendAndReceive("0902\r");

            if (result.StartsWith("49"))
            {
                while (!result.Contains("49 02 05"))
                {
                    string tmp = await ReceiveAsync();

                    result += tmp;
                }
            }

            return(ObdParser.ParseVINMsg(result));
        }
Пример #2
0
        private async Task <string> RunCmd(string cmd)
        {
            var result = await SendAndReceive(cmd + "\r");

            return(ObdParser.ParseObd01Msg(result));
        }
Пример #3
0
        public async Task <bool> Init()
        {
            _running = true;
            _data    = new Dictionary <string, string> {
                { "vin", DEFAULT_VALUE }
            };
            _parameterIDs = ObdParser.GetParameterIds();

            foreach (var v in _parameterIDs.Values)
            {
                _data.Add(v, DEFAULT_VALUE);
            }

            bool isObdReaderAvailable = false;

            foreach (var netInterface in NetworkInterface.GetAllNetworkInterfaces())
            {
                if (netInterface.NetworkInterfaceType == NetworkInterfaceType.Wireless80211 ||
                    netInterface.NetworkInterfaceType == NetworkInterfaceType.Ethernet)
                {
                    foreach (var addrInfo in netInterface.GetIPProperties().UnicastAddresses)
                    {
                        var ipaddr = addrInfo.Address;
                        if (ipaddr.ToString().StartsWith("192.168.0"))
                        {
                            isObdReaderAvailable = true;
                            break;
                        }
                    }
                }
            }

            if (!isObdReaderAvailable)
            {
                _socket    = null;
                _running   = false;
                _connected = false;
                return(false);
            }

            if (!ConnectSocket())
            {
                _socket    = null;
                _running   = false;
                _connected = false;
                return(false);
            }

            if (_connected)
            {
                // initialize the device
                string s;
                s = await SendAndReceive("ATZ\r");

                s = await SendAndReceive("ATE0\r");

                s = await SendAndReceive("ATL1\r");

                s = await SendAndReceive("ATSP00\r");

                PollObd();

                return(true);
            }
            else
            {
                return(false);
            }
        }