Read an incoming HEX packet from Serial

Hello I am blocked on something.

I'm coding a on an arduino and I am communicating with an other device in HEX. I would like to know how to read the data he sends me.

I am sending a HEX packet (everything good here, no problem)

//Ask for Data
Serial.write(askData, sizeof(askData));

After this I will receive data (in HEX). I need to store it all to use it later. The only thing I know is that it will end with a "16". I dont know the length of the packet in advance. Here is an example or packet that I can reveive :

68 4E 4E 68 08 09 72 90 90 85 45 68 50 49 06 19 00 00 00 0C 14 02 00 00 00 8C 10 12 35 02 00 00 0B 3B 00 00 00 8C 20 14 02 00 00 00 8C 30 14 00 00 00 00 04 6D 2F 09 61 24 4C 14 02 00 00 00 42 6C 5F 2C 42 EC 7E 7F 2C 0A 92 2A 00 10 0A 92 2B 00 10 39 16

Can someone help me please ?

Here is an example or packet that I can reveive :

That is NOT what the packet will look like. That is a string representation of each value, in HEX.

The actual data will be in binary.

If you send x bytes, you simply read x bytes, and store the values in an array that can hold x bytes.

Of course, somehow both ends of the serial port need to know what x is. This is why sending binary data is so frustrating for many people. Not to mention that you can NOT guarantee that every byte sent will be received.