Originally Posted by
jimblumberg
Along with the Serial howto provided above, I find
this page helpful.
Jim
I tried the code on the posted page but for some reason I am getting nothing. I know that the code opens the port because the error "failed to open port" prints only when the usb is not connected to the computer but I am only getting my other printf functions (printing the falue of fd) as
3
3
Here is the code:
Code:
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <fcntl.h>
#include <errno.h>
#include <termios.h>
int fd;
int
open_port(void)
{
fd = open("/dev/serial/by-path/name.of.usb.port0", O_RDWR | O_NOCTTY | O_NDELAY);
printf("%d\n\n", fd);
if (fd == -1)
{
printf("open_port: Unable to open usb -");
}
else
fcntl(fd, F_SETFL, 0);
return (fd);
}
main()
{
open_port();
printf("%d\n\n",fd);
}