The short version. When trying to open a USB device using the open() function in the fcntl.h header, the program freezes
Now the slightly longer version. I am trying to interface with a time of flight sensor (TeraRanger Evo 60m). I am working on a mac running Big Sur 11.2.1. Using ls -l /dev/tty.*
i have located the device path to be /dev/tty.usbmodem00000000001A1.
I have taken my code and heavily simplified it to isolate the issue I'm currently facing
#include <fcntl.h> // open
#include <stdio.h> // print
int main()
{
// /dev/tty.usbmodem00000000001A1
char *device = "/dev/tty.usbmodem00000000001A1";
printf("Start\n");
int fd = open(device, O_RDWR | O_NOCTTY | O_SYNC);
if(fd < 0)
{
perror(device);
return -1;
}
printf("Opened\n");
return 1;
}
When trying to open the device, the program freezes. There is no error printed to help me debug either. I have successfully connected to and received messages from another USB device I own by only changing the device path. Yet, this sensor make the code freeze.
I may also be useful to know that using the screen /dev/tty.usbmedem00000000001A1 115200
terminal command shows the output expected from the sensor. This means the device is properly functioning and it can be connected to but i have messed up my code somehow. I would greatly appreciate any help y'all can provide. Thank you!