I'm creating a C/C++ library that will send and receive data to a bluetooth device. This library will be used for both iOS and Android. So, prior to the data transmission, I paired the iOS device (iPod) to the bluetooth device. Once the connection is successful, I start sending data from the C++ library. But the problem is, my code is failing when opening the port (open returns -1). Below is my code snippet:
struct termios options;
int tty_fd;
//const char *port = "/dev/rfcomm0";
const char* port = "/dev/tty.F4-VFI-PWM-iRDA-SerialP";
cout << "Trying to open port: " << port << endl;
tty_fd = open(port, (O_RDWR | O_NOCTTY | O_NONBLOCK)); //O_NDELAY
if (tty_fd < 0)
{
cout << "Failed to open port: " << port << ", error code: " << tty_fd << endl;
}
Does anyone knows the correct way to communicate to a bluetooth device using C/C++ in iOS?