public ControllerResponse Query(ObdAdapter.Mode parameterMode, ObdAdapter.PID parameterID) { String responseData = String.Empty; try { Byte[] data = System.Text.Encoding.ASCII.GetBytes(Convert.ToUInt32(parameterMode).ToString("X2") + Convert.ToUInt32(parameterID).ToString("X2") + "\r"); TcpClientConnection.GetStream().Write(data, 0, data.Length); Console.WriteLine("Sent: {0}", data.ToString()); data = new Byte[256]; Int32 bytes = TcpClientConnection.GetStream().Read(data, 0, data.Length); responseData = System.Text.Encoding.ASCII.GetString(data, 0, bytes); Console.WriteLine("Received: {0}", responseData); } catch (ArgumentNullException e) { Console.WriteLine("ArgumentNullException: {0}", e); } catch (SocketException e) { TcpClientConnection.Client.Shutdown(SocketShutdown.Both); TcpClientConnection.Client.Disconnect(true); Console.WriteLine("SocketException: {0}", e); } return(new ControllerResponse(responseData, parameterMode, parameterID)); }
public ControllerResponse(string raw, ObdAdapter.Mode requestedMode = ObdAdapter.Mode.Unknown, ObdAdapter.PID requestedPID = ObdAdapter.PID.Unknown) { Raw = raw; RequestedPID = requestedPID; RequestedMode = requestedMode; }