|
|
| go ahead... be a heretic | |
| PerlMonks |
Re: Buffer in Serial read routine seemingly not working??by graff (Canon) |
| on Dec 03, 2012 at 00:02 UTC ( #1006768=note: print w/ replies, xml ) | Need Help?? |
|
I'm not sure I understand your script, but let me see if I at least understand your task. What follows is actually a different plan from what you seem to be trying to do in the OP code, but (if I understand what you said about your sample data strings) I think it might be a useful approach (and might be easier to implement, relative to what you've tried so far):
In other words, a simple 2-state machine would do what you want. The initial state stores nothing and just watches for STX. Once STX is found, you switch to storing input and looking for ETX. You'll stop storing when either ETX or NAK is found or when 80 bytes are stored, whichever comes first, and return to the initial state; if ETX was found first, you'll do something with the stored data, otherwise you'll ditch it. If that isn't what you meant to describe, please try again to see if you can explain the task more clearly. If that is what you meant, then that description should lead you to a fairly simple script, along the lines of: If you want a 2nd STX in the input to be treated as data, just comment out the @buffer = (); line in the first "if" clause. (update: made a minor fix to the 2nd "printf" format, to put a space between consecutive byte values)
In Section
Seekers of Perl Wisdom
|
|
||||||||||||||||||||||||||