0

I want to monitor a virtual COM port (Arduino RFID) on my Mac. I can run "screen /dev/tty.serialnumber" from the terminal, and it outputs the RFID serial number when I swipe it.

As soon as I try it from Xcode with an NSTask I get the following output.

Must be connected to a terminal.

Here's my code:

NSTask *cd = [[NSTask alloc] init];

[cd setLaunchPath:@"/usr/bin/screen"];
[cd setArguments:[NSArray arrayWithObjects:@"-L",@"/dev/tty.usbserial-A800509K",nil]];

NSPipe *pipe;
pipe = [NSPipe pipe];
[cd setStandardOutput: pipe];
[cd setStandardInput:[NSPipe pipe]];

NSFileHandle *file;
file = [pipe fileHandleForReading];

[cd launch];

NSData *data;
data = [file readDataToEndOfFile];

NSString *string;
string = [[NSString alloc] initWithData: data encoding: NSUTF8StringEncoding];

NSLog (@"%@", string);

[cd waitUntilExit];
[cd release];
Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
Justin
  • 1
  • That’s `screen(1)` telling you that it can only be run from a terminal. Can’t you use another program or read /dev/tty directly? See this question: http://stackoverflow.com/questions/2504714/reading-serial-data-from-c-osx-dev-tty –  May 11 '11 at 03:18

1 Answers1

-1

I think you'd better directly access the COM port, either by using the foundation libraries, or by using third party Obj-C libs (for example, https://github.com/pbosetti/PBSerialPort). Also, if you want to monitor the COM port, you will have to set a thread reading the serial port, and updating a text area in the UI. Remember that secondary thread should update the UI via the method - (void)performSelector:(SEL)aSelector onThread:(NSThread *)thr withObject:(id)arg waitUntilDone:(BOOL)wait.

p4010
  • 943
  • 7
  • 19