Re: Displaying Realtime Data
Re: Displaying Realtime Data
- Subject: Re: Displaying Realtime Data
- From: Cameron Hayne <email@hidden>
- Date: Wed, 29 Oct 2003 02:38:48 -0500
On 29/10/03 1:59 AM, "Saul Iversen" <email@hidden> wrote:
>
I'm not clear about one aspect of NSTask: When the Moriarity example
>
for instance explains that NSTasks are "one-shot", does this mean that
>
if my model/background process is continuously receiving data from the
>
serial port that it can continue to send data to the controller? Or
>
does it mean that I will need to continue to invoke NSTasks for each
>
chunk of data that I want to receive into the controller and
>
subsequently update in an NSTextField?
The "one-shot" thing about NSTask means merely that you use NSTask to handle
one sub-process. If you have subprocessA that starts, outputs results, then
finishes and then you want subprocessB to run, you can't use one NSTask to
handle both. NSTask instances are one-to-one with sub-processes. No serial
monogamy!
In your case, it sounds like your sub-process will never end, so your NSTask
will continue to send data that will be received by the method you register
for NSFileHandleReadCompletionNotification.
I.e. your code would look something like this:
[task setStandardOutput:[NSPipe pipe]];
taskStdoutFH = [[[task standardOutput] fileHandleForReading] retain];
NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
[nc addObserver:self
selector:@selector(getData:)
name:NSFileHandleReadCompletionNotification
object:taskStdoutFH];
[taskStdoutFH readInBackgroundAndNotify];
and your 'getData' method will get invoked whenever more data comes in.
You would parse the data in that method and then stick it into your
NSTextField.
--
Cameron Hayne (email@hidden)
Hayne of Tintagel
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.