PDA

View Full Version : Decode USB data stream



KRO74
April 3rd, 2012, 09:11 AM
Hi
I am trying to decode data from a USB connected weather station and need some support/help regarding pattern matching,
I have tried "everything" like,

"%x255([^%x255]*)"
([^%x255%x255]*)
"(.-%xff%xff)"
and search the "entire" internet without successes,

I want with a string.find capture the data between 0xff0xff any data 0xff0xff.

Below is an example of the data (in hex)


FF FF 00 48 0F 0C 0B D0 00 00 20 5E 01 FF FF 00 42 81 47 00 28 3C 80 00 00 EE 01 FF FF 00 42 80 0A 01 11 00 00 00 00 DE 00 FF FF 00 48 06 0C 06 D0 00 00 20 50 01 FF FF 00 42 80 0A 01 11 00 00 00 00 DE 00 FF FF 00 48 09 .H..... ^..BG.(<....B.........H..... P..B.........H.

Is there any friendly soulout there wiling to help......would be very much appriciated.

Regards

KRO74
April 4th, 2012, 05:58 AM
I got it.
Kind of obvious when you see it........

The following did the trick,

pattern = string.char(255)..string.char(255).."(.-)"..string.char(255)..string.char(255)
st, en, wdata = string.find(c, pattern)

Maybe not the best way to do it but it is working