Reputation: 129
On a mac running 10.8 i am trying to open a serial port.
ls /dev/cu* returns:
/dev/cu.Bluetooth-Modem /dev/cu.Bluetooth-PDA-Sync /dev/cu.usbserial-A1009TT7
i can see the port is there but when i try to open it i get Undefined error: 0(0). This is my code i use to open the port.
char *path = "/dev/cu.usbserial-A1009TT7";
open(path , O_RDWR | O_NOCTTY | O_NONBLOCK); // open the port
if (file == -1) {
printf("Error opening port : %s(%d).\n", strerror(errno), errno);
close(file);
return -1;
}
anyone have any idea why the port wont open?
thanks in advance.
Upvotes: 3
Views: 1956
Reputation: 213308
Whoops! You meant to type this:
file = open(path , O_RDWR | O_NOCTTY | O_NONBLOCK);
^^^^^^^
Also, there is no need to close a file descriptor that isn't open.
if (file == -1) {
printf(...);
// close(file); Completely unnecessary. It's not valid!
return -1;
}
Upvotes: 5