-
Notifications
You must be signed in to change notification settings - Fork 84
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use of the library in a generic way #34
Comments
You can't use variables for generics. I'm not 100% sure if I correctly understood what you're trying to do, but if you don't know which value you are selecting don't use the generic RequestData, but the one where you can directly pass the PID. For example: byte pid = 0x0D;
dev.RequestData(pid); For that you have to subscribe to the interface-data-received (as in the example) and in there handle the data depending on your use case. dev.SubscribeDataReceived<IOBDData>((_, data) =>{ /* Your logic here */ });` |
Okey, thank you ! that is what I was searching for. using System; List receibedData = new List(); SerialConnection connection = new SerialConnection("COM3"); foreach (var data in receibedData) |
The general event is only executed if you also request a particular data. For example, I have requested speed, well now that event will be executed (with the speed data obviously) but if there is no particular data it will not be executed List receibedData = new List(); SerialConnection connection = new SerialConnection("COM3"); foreach (var data in receibedData) |
I've no idea what you're trying to do. The code you added should not compile like this. |
I would like to request data by pid instead of the OBD.NET.Devices.ELM327.RequestData but I don't know how to use the event that is generated in this case when the response is received |
I have finally managed to receive data with this simple code. Thank you very much for your suggestions, they have really helped me a lot. elm327Device.RawDataReceived += (sender, args) => // Envía la solicitud de datos al dispositivo para el PID seleccionado // |
Hi, I'm trying to make a self-diagnosis application for myself. The objective of my application is to provide a table to the user with all the parameters available to analyze and so that he can select which ones are of interest.
I had thought about using the library like this: (in the example string signal would be the data selected by the user, which would have a PID associated with it)
using SerialConnection connection = new SerialConnection("COM3");
// Se crea el objeto ELM327
using ELM327 dev = new ELM327(connection, new OBDConsoleLogger(OBDLogLevel.Debug));
// Se crea una lista con los posibles datos que se pueden diagnosticar
List OBDparameters = new List
{
new RealOBDParam(typeof(EngineCoolantTemperature),"05"),
new RealOBDParam(typeof(EngineRPM),"0C"),
new RealOBDParam(typeof(VehicleSpeed),"0D")
}
// Parametro seleccionado por el usuario
string signal = "0C"
// Buscar el parametro seleccionado por el usuario en la lista
foreach (var param in this.OBDparameters)
{
// RealTime
if (param.ParameterID == signal)
{
// Suscribirse a la acción correspondiente
dev.SubscribeDataReceived<param.ParameterType>((sender, data) => Console.WriteLine("Engine RPM: " + data.Data.Rpm));
dev.RequestData<param.ParameterType>();
}
public class RealOBDParam
{
public Type ParameterType { get; set; } // Para guardar el tipo (como EngineRPM, VehicleSpeed, etc.)
public string ParameterID { get; set; } // Para guardar el nombre/descripción del parámetro
// Constructor para inicializar ambos campos
public RealOBDParam(Type parameterType, string parameterID)
{
this.ParameterType = parameterType;
this.ParameterID = parameterID;
}
}
Using the library in this way is not correct, can someone help me?
The text was updated successfully, but these errors were encountered: