Society of Robots - Robot Forum

Software => Software => Topic started by: macbook on September 20, 2011, 04:04:34 AM

Title: Serial port interface in C
Post by: macbook on September 20, 2011, 04:04:34 AM
Hi,

I am using a FriendlyARM Mini2440 board for my project and I need to serially interface a GPS receiver with it. I am writing a C code for the same. I had a doubt regarding some of the UNIX system calls.
I am using the following functions - open() (http://linux.about.com/od/commands/l/blcmdl2_open.htm (http://linux.about.com/od/commands/l/blcmdl2_open.htm)), read(), write() etc. I have a doubt in the open() call.

Code: [Select]
int fd;
fd = open("ttySAC2", O_RDWR | O_NOCTTY | O_NDELAY); //O_RDWR = Read Write

It returns 3 as the value of fd. I have not been able to find out the meaning of this value. I know if its -1, it's an error but apart from that, what does any other value signify?

Thanks.
Title: Re: Serial port interface in C
Post by: joe61 on September 20, 2011, 05:22:34 AM
Code: [Select]
int fd;
fd = open("ttySAC2", O_RDWR | O_NOCTTY | O_NDELAY); //O_RDWR = Read Write

It returns 3 as the value of fd. I have not been able to find out the meaning of this value. I know if its -1, it's an error but apart from that, what does any other value signify?

The man page for open(2) is pretty clear. If it doesn't return -1, the value it does return is the file descriptor that should be used for subsequent calls to read() write() ioctl() and close().

Man pages in general have a section called "Return Value" that tell you what to expect back from a function. The page you link to also has this section. Sometimes you have to look for it, or use the search function of your browser to search the page. But it should always tell you what the return value is, or point you to another source of information.

Joe


Joe