How to determine data format in QByteArray (ASCII / HEX / Unicode)

96 Views Asked by At

I have a software that analyzes the serial communication between a testing machine and their software because I need to grab these values for my software. Most of the components are using ASCII-formats for their communication, but there are some that are using binary data like Modbus, etc. As I use readAll(), I've get the result into a QByteArray and when I print it by qDebug() I can clearly see whether it's ASCII or HEX (HEX-values are printed with \xdf\x01\xff...), but I did not find a way to determine by software what format it is. I think there must be a way to find out this...

1

There are 1 best solutions below

0
m7913d On

The only 100% proof solution is not guessing at all. You should interpret the data based on the documented format of the source.

Using some heuristics (such as looking at the values of the first n bytes), may work most of the time, but will fail from time to time.