Hi guys,
I was able to connect my app to my OBD scanner via bluetooth.
Can someone help me with just one thing?
Can you tell me if I am missing anything when I actually send me command to the OBD2 scanner?
My code is below. I basically call ConnectBluetooth just to connect the socket. If it connects, it returns a 0 else a 1 if there's an error.
SO, once I am connected to the socket, i want to issue the command to the scanner and receive its response.
Am I doing it correctly?
Or am I missing any steps?
if (btSocket != null)
{
Task<string> SubmitTask = new Task<string>(ConnectBluetooth);
SubmitTask.Start();
//Progress.Visibility = ViewStates.Visible;
string Result = await SubmitTask;
if (Result == "0")
{
Android.Widget.Toast.MakeText(this, "Connection Successful!", Android.Widget.ToastLength.Short).Show();
String CommandToOBD = "010D" + "\r";
// convert string to stream
byte[] byteArray = Encoding.ASCII.GetBytes(CommandToOBD);
mmOutputStream = new MemoryStream(byteArray);
mmOutputStream = btSocket.OutputStream;
mmInputStream = btSocket.InputStream;
StreamReader reader = new StreamReader(mmInputStream);
string data = reader.ReadToEnd();
//string data = "41 0D FF"; //hex data from OBD2
var result = ObdParser.Parse(data);
Console.WriteLine(result.Mode); //mode: 1
Console.WriteLine(result.Command); //command: 13
Console.WriteLine(result.Name); //name: VehicleSpeed
Console.WriteLine(result.Value); //value: 255 (kph)
}