/ dev / ttyACM0和/ dev / ttyACM1中的相同文件描述符

时间:2018-08-17 10:53:30

标签: linux raspberry-pi debian usb file-descriptor

我正在尝试使用RasPI从2 gps接收器读取数据。我在2个不同的shell中启动2个程序。一个程序必须读取ttyACM0,而另一个程序必须读取ttyACM1。

不幸的是,即使我在第一个程序之后启动第二个程序,我也为两个端口(fd = 7)获得了相同的文件描述符(所以它应该得到fd = 8但确实发生了)。

你知道为什么他们得到相同的f.d.吗? 我是否必须将所有读取的程序放在一个程序中? (我检查了一下,如果我仅在一个程序中打开usb端口,我将得到acm0 fd = 7和acm1 fd = 8)

程序。 1:

//Open the file with name saved in char* port0
pUSB0  = fopen(port0, "r+");                                                        // r+ = read and write 
if (pUSB0 == NULL) perror ("Error opening USB0\n");
// Get the file descriptor
fdpUSB0 = fileno(pUSB0);
if (fdpUSB0 < 0 ){
    fprintf(stdout, "Can't get the File Descriptor of %s\n", port0);
    fprintf(stdout, "Error: %s", strerror(errno));
}
fprintf(stdout, "The file descriptor's port0 %s is fd = %d\n", port0, fdpUSB0);

程序。 2:

与1相同,但端口1 = / dev / ttyACM1;

0 个答案:

没有答案