Receiving data from elm327 device

2019-06-14 08:31发布

问题:

I want to receive data from elm327 device. in line 7 I receive AT+BRSF=24\r string instead of string with the speed.

1.private async Task<string> GetSpeed()
2.    {
3.        string retVal;
4.        _dataWriter.WriteString("010D\r"); // send pid for speed information
5.        await _dataWriter.FlushAsync(); 
6.        await _dataReader.LoadAsync(30);  // get answer
7.       String Message = _dataReader.ReadString(11);
8.        retVal = Message;
9.        if (retVal.Contains('<'))
10.        {
11.        retVal.Substring(0, retVal.IndexOf("<"));

12.        }
13.        return retVal.Replace("\n", "");
14.    }

I'm using SDP Bluetooth protocol:

PeerFinder.AlternateIdentities["Bluetooth:SDP"] = "{00001101-0000-1000-8000-00805F9B34FB}";

回答1:

the problem is with the connecting channel, I first tried with the next line:

_stream = await socket.ConnectAsync(selectedDevice.HostName,"1");

but the working channel is 16 and not 1, and the working line is:

_stream = await socket.ConnectAsync(selectedDevice.HostName,"16"):