domnulvlad / KLineKWP1281Lib

Arduino / ESP / RPi Pico library integrating the proprietary VAG Key-Word 1281 protocol (KWP1281/KW1281)
https://domnulvlad.github.io/KLineKWP1281Lib/
GNU General Public License v3.0
36 stars 5 forks source link

Multiple Blocks #6

Open PrintService3D opened 3 weeks ago

PrintService3D commented 3 weeks ago

Actually I just have a simple request, I would like to query several blocks. A query of all existing ones works, individual ones also work, but how can I, for example, query 4 blocks at the same time?

I think your work is fantastic! This is exactly the lib I was looking for ^^ I just haven't figured out how to receive multiple blocks at the same time yet

domnulvlad commented 3 weeks ago

Hi.

There isn't really such thing as "at the same time" with this protocol.

If you meant to say that the example 03 (full measurement test) works, then you can see that the code just makes a for-loop through all possible block numbers (0-255).

So, for example, if you want blocks 1, 2, 3, 4, then you should just call diag.readGroup(...) with each block one after the other. The example sketches use another function that calls diag.readGroup(...) indirectly and also shows the value in the Serial Monitor.

An even better example sketch is 04 (continuous measurement test); there, you could just copy-paste the showMeasurements() function in the loop so it requests each block you need, like:

void loop() {
    showMeasurements(1);
    showMeasurements(2);
    showMeasurements(3);
    showMeasurements(4);
}
PrintService3D commented 3 weeks ago

Thank you for the quick reply! Of course, I looked at all the existing examples and tried to figure out how to do it myself, but I couldn't figure it out because everything has a fixed link somehow. in a loop for example " showMeasurements(BLOCK_TO_READ) "

that irritated me and since your library is apparently the only one that can handle the MC33290, I didn't want to mess around now that I've finally had some success :D

I'll test tomorrow how I can implement this directly. At K-Line there is the sampling rate, for example in a single block in my car (A4 B5 from 1999) it is 1.1ms in the first measured value block.

If I can figure it out, would I paste the adapted code section here for others who are interested?

domnulvlad commented 3 weeks ago

What exactly do you mean by "fixed link"?

If you scroll to the bottom of the sketch, you can see the definition for showMeasurements. In fact, you only need to call diag.readGroup if you want to read a block. The function showMeasurements is there to additionally display the values, and also to show you how to use readGroup correctly.

Of course, if you find a solution to your problem, you can post it here.

PrintService3D commented 3 weeks ago

Any link in the voids returns to "#define BLOCK_TO_READ" like here for example:

void loop() {
  showMeasurements(BLOCK_TO_READ);
  }

It could also be that I'm just too tired right now :D

I'll test tomorrow how I can do it. I'll give you feedback when I'm well rested :+1:

PrintService3D commented 3 weeks ago

I forgot to share it yesterday. Now my code is ready. I expanded it directly with Measurement blocks that can be adjusted at the push of a button & read error codes at the push of a button

#define BLOCK1_TO_READ 1
#define MEASUREMENT1_TO_READ 0
#define BLOCK2_TO_READ 1
#define MEASUREMENT2_TO_READ 1
#define BLOCK3_TO_READ 1
#define MEASUREMENT3_TO_READ 2
#define BLOCK3_TO_READ 1
#define MEASUREMENT3_TO_READ 2
void showMeasurements() {
  showMeasurement(BLOCK1_TO_READ, MEASUREMENT1_TO_READ);
  showMeasurement(BLOCK2_TO_READ, MEASUREMENT2_TO_READ);
  showMeasurement(BLOCK3_TO_READ, MEASUREMENT3_TO_READ);
  showMeasurement(BLOCK4_TO_READ, MEASUREMENT4_TO_READ);
}
domnulvlad commented 3 weeks ago

Yes, this is one way of doing it.

I know what you shared is just an example, but since you are reading from the same block, it would be more efficient to request the block once and then process each of the 4 (or less) values.

By that I mean, first request the block with readGroup, check the return value, and if it's KLineKWP1281Lib::SUCCESS, then do getMeasurementType, getMeasurementValue, getMeasurementUnits for each measurement. The amount of measurements received is stored in the amount_of_measurements variable, so you can just make a for-loop, like the other sketches do.

And if you make a project where the user can select whatever block+measurement combination they want, it would be nice to implement a feature which detects if multiple values are taken from the same block, so it doesn't request a block multiple times for no reason.

PrintService3D commented 3 weeks ago

I actually just gave an example, I use blocks 1, 4, 7 and 115 I'll deal with the readGroup later and send an example there if I'm successful

Currently I'm just working on a code that meets my preferences :D

I actually still have one question.

Is it only possible to read error codes or can they also be deleted?

Ja, das ist eine Möglichkeit.

Ich weiß, dass das, was Sie geteilt haben, nur ein Beispiel ist, aber da Sie aus demselben Block lesen, wäre es effizienter, den Block einmal anzufordern und dann jeden der 4 (oder weniger) Werte zu verarbeiten.

Damit meine ich, dass Sie den Block zuerst mit anfordern readGroup, den Rückgabewert prüfen und, wenn er ist , für jede Messung , , ausführen. Die Anzahl der empfangenen Messungen wird in der Variablen gespeichert , KLineKWP1281Lib::SUCCESSsodass Sie einfach eine For-Schleife erstellen können, wie dies bei den anderen Skizzen der Fall ist.getMeasurementType``getMeasurementValue``getMeasurementUnits``amount_of_measurements

Und wenn Sie ein Projekt erstellen, bei dem der Benutzer jede beliebige Block-Messwert-Kombination auswählen kann, wäre es schön, eine Funktion zu implementieren, die erkennt, wenn mehrere Werte aus demselben Block übernommen werden, damit ein Block nicht grundlos mehrmals angefordert wird.

domnulvlad commented 3 weeks ago

Yes, if you check the Wiki for "library reference", you will find the clearFaults function. I didn't include it in the examples because I didn't want to clear the fault codes without the user expecting it :)

Same thing with coding and adaptation.

PrintService3D commented 3 weeks ago

Yes, if you check the Wiki for "library reference", you will find the clearFaults function. I didn't include it in the examples because I didn't want to clear the fault codes without the user expecting it :)

Same thing with coding and adaptation.

Wow, you really thought of everything! Respect!

Ich melde mich bald zurück