Quote Originally Posted by ELCouz View Post
The array («packet structure»):
byte 0 is the delimiter (used to delimit one array to another) constant value 0xC8
byte 1 is the function to be executed
byte 2 to 23 is the pwm value applied to each channel ( 22 channels in total)
The array is sent 100 times a seconds.
How to grab the rs232 rx data, trim , split data into 1 byte and 1 array ?
ex:
byte 0 would be discarded , it only separate array data
byte 1 would be stored in a BYTE
byte 2 to 23 would be stored in a array of 22 bytes
Sorry for such question if it's an easy one.
Many thanks!
Best Regards,
Laurent
packet var byte[23]
serin2 serinpin , serialmode , 7 , baddata , [ WAIT ($c8) , str packet\23 ]

serin2 waits for $c8...
if it doesn't see it in 7 ms, jumps to baddata: (7ms is just a tad bit longer than a packet takes to be sent)
when it does get a $c8, stores the next 23 characters in packet

But you'd better make whatever processing that comes after this happen fairly quickly.
You say your sender sends these packets 100 times per second.
At 38,400 baud, a 'packet' takes about 6.25ms.
100 packets of 6.25ms = 625ms, leaves 375ms for other stuff, figure about 3.75ms in between each packet on average.