Use concise serial port names
This commit is contained in:
parent
efd0785a74
commit
f8315ff7ba
|
@ -33,12 +33,14 @@ NSString * kASSerialPortsChanged = @"PortsChanged";
|
||||||
NSMutableArray * cuPorts = [NSMutableArray array];
|
NSMutableArray * cuPorts = [NSMutableArray array];
|
||||||
for (NSString * port in [[NSFileManager defaultManager] contentsOfDirectoryAtPath:@"/dev" error: nil]) {
|
for (NSString * port in [[NSFileManager defaultManager] contentsOfDirectoryAtPath:@"/dev" error: nil]) {
|
||||||
if ([[port substringToIndex:2] isEqualToString:@"cu"])
|
if ([[port substringToIndex:2] isEqualToString:@"cu"])
|
||||||
[cuPorts addObject:[@"/dev/" stringByAppendingString:port]];
|
[cuPorts addObject:[port substringFromIndex:3]];
|
||||||
}
|
}
|
||||||
return cuPorts;
|
return cuPorts;
|
||||||
}
|
}
|
||||||
|
|
||||||
+ (NSFileHandle *)openPort:(NSString *)port withSpeed:(int)speed {
|
+ (NSFileHandle *)openPort:(NSString *)port withSpeed:(int)speed {
|
||||||
|
if (![port containsString:@"/"])
|
||||||
|
port = [NSString stringWithFormat:@"/dev/cu.%@", port];
|
||||||
int fd = open([port UTF8String], O_RDWR | O_NOCTTY | O_NONBLOCK);
|
int fd = open([port UTF8String], O_RDWR | O_NOCTTY | O_NONBLOCK);
|
||||||
if (fd < 0)
|
if (fd < 0)
|
||||||
return nil;
|
return nil;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user