Player APIs (BrightScript & Ja...
...
Object Reference
Input/Output Objects

roSequenceMatcher

4min
this object is used to send rosequencematchevent events when the specified byte sequence patterns are matched once a pattern has been matched and the event has been posted, all contributing bytes are discarded as a result, if one pattern is a prefix of another pattern, then the second, longer pattern will never be matched by the object this object provides both a standard interface and an overloaded interface for sending events to a message port ifmessageport setport(port as romessageport) posts messages of type rosequencematchevent to the attached message port ifsequencematcher setport(a as object) specifies the message port where rosequencematchevent objects will be posted add(pattern as object, user data as object) as boolean adds a pattern to be matched by the rosequencematcher object instance the pattern should be specified as an object that is convertible to a byte sequence (e g robytearray , rostring ) for the user data, pass the object that should be returned if the specified pattern is matched example function fromhex(hex as string) as object bytes = createobject("robytearray") bytes fromhexstring(hex) return bytes end function sub main() serial = createobject("roserialport", 1, 115200) mp = createobject("romessageport") button1 seq = fromhex("080a01040001e000") button2 seq = fromhex("080e01040001e000") matcher = createobject("rosequencematcher") matcher setmessageport(mp) matcher add(button1 seq, { name "button1" }) matcher add(button2 seq, { name "button2" }) matcher add("flibbet", { name "flibbet" }) matcher add("flobbet", { name "flobbet" }) if not serial setmatcher(matcher) then stop end if finished = false while not finished ev = mp waitmessage(10000) if ev = invalid then finished = true else if type(ev) = "rosequencematchevent" then print "got button "; ev getuserdata() name else print "unexpected event "; type(ev) end if end while end sub