I’m not sure how to title this, let alone explain it well, but here it goes.
I currently have this method:
- (void) receivedData:(NSString *)data {
}
It triggers when serial data is read. The serial data is coming in as :<DMX>255,23,1,4,6</DMX> problem is, it’s not coming in as one unified string. It comes in pieces. Like, <DM , X>255 , ,23,1,4, , etc. It’s random so I can’t track it. Sometimes it sends the whole thing, others it sends every couple characters at a time. It is what it is.
How, in my code, can I wait for the whole thing to come in (starting at <DMX> and ending at </DMX>) and then create an NSString? Maybe as the data comes in, store the pieces, wait for the end </DMX>, then combine them together?
Thanks!
If You are parsing XML, and have an option of using XML parser – use it (there are builtin XML Parsers in iOS/OSX, as well as numerous other options).
If however, you decide to code this instead…
Create
NSMutableStringivar and keep adding (appendString) to it as you receive data…Then keep track of whether you met your start/end tags already…
Something along these lines..
In
MyClass.h:In
MyClass.m: