0

I am connecting my Raspberry Pi to a device using the serial port to record data coming from the device at 19.2 kbit/s. Currently I am using a USB-to-serial adapter, but this could change in the future.

The data transmitted from the device is something like:

R1234R1234R1234R1234R1234R1234R1234R1234R1234R1234R1234R1234R1234R1234R1234<LF>
R1234R1234R1234R1234R1234R1234R1234R1234R1234R1234R1234R1234R1234R1234R1234<LF>
R1234R1234R1234R1234R1234R1234R1234R1234R1234R1234R1234R1234R1234R1234R1234<LF>
R1234R1234R1234R1234R1234R1234R1234R1234R1234R1234R1234R1234R1234R1234R1234<LF>
A-990I0123C-990T0123S0123D0123<LF>
R1234R1234R1234R1234R1234R1234R1234R1234R1234R1234R1234R1234R1234R1234R1234<LF>
R1234R1234R1234R1234R1234R1234R1234R1234R1234R1234R1234R1234R1234R1234R1234<LF>
R1234R1234R1234R1234R1234R1234R1234R1234R1234R1234R1234R1234R1234R1234R1234<LF>

The only bit that I need to record is the line starting with A. I want to write a program to detect this line, and record it, prefarably in C (as this is the language that I have had the most experience in, although I am far from an expert).

I can't think of a good strategy to quickly read, recognise, and save the required data, and I was wondering if there was a function, or similar, to detect a particular sequence in an ongoing stream of data?

  • What did you try so far? – Bex Aug 8 '14 at 9:34
1

Assuming you have opened the serial device as a FILE *.

Use fgets to fetch each line. Store the line if the first character is 'A' otherwise discard the line. Repeat.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.