/// <summary> /// Create read socket or device /// </summary> private void createReadSocket() { if (this.device == null) { IsError = true; ErrorType = BluetoothErrorType.NoDevice; return; } //load data String rawName = this.device.HostName.RawName; OdbClient client = this.socketsPool[rawName]; //clear and disconnect others this.clearCachedConnections(rawName); odbClient = client; if (odbClient.IsConnected) { IsSuccess = true; IsError = false; IsFinding = false; //save preselected device this.PreselectedDevice = rawName; //connected to device triggerConnectedToDevice(); //data receive handler odbClient.DataReceive += odbClientDataReceive; //start data receiving odbClient.Start(); } else { IsError = true; IsFinding = false; ErrorType = BluetoothErrorType.OutOfRange; } }
/// <summary> /// Get response for /// </summary> /// <param name="client"></param> /// <param name="odbPid"></param> /// <param name="action"></param> private void getResponseFor(OdbClient client, OdbPid odbPid, Action<Double> action) { var response = client.RequestFor(odbPid); if (response != null) { action(response.Data); } }
/// <summary> /// Check if is odb /// </summary> /// <param name="i"></param> /// <returns></returns> private async Task<bool> isOdbDevice(PeerInformation i) { OdbClient odbClient = new OdbClient(); await odbClient.Connect(i.HostName); var isOdb = await odbClient.IsOdb(); if (isOdb) { socketsPool.Add(i.HostName.RawName, odbClient); } else { odbClient.Disconnect(); } return isOdb; }