- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi all,
I have ported uClinux onto an DE2 2C35 board and i want to communicate with my PC using the RS232 port. I can open and write data to "dev/ttyS0" well. But I can't read from "dev/ttyS0" by using read or fread functions. :confused: Can u guys tell me how to solve this problem? Thanks for reading :):) here's my code:#include <string.h>
# include <unistd.h>
# include <fcntl.h>
# include <errno.h>
# include <termios.h>
int main(void)
{
char buf;
int fd1, count;
fd1 = open("/dev/ttyS0", O_RDWR | O_NOCTTY | O_NDELAY);
if (fd1 == -1)
{
perror("open_port: Unable to open /dev/ttyS0 - ");
}
while(count = read(fd1, buf, 10) > 0)
printrf("%s", buf);
close(fd1);
return 0;
}
Link Copied
2 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
1. print errno. It will say what happening.
2. Show ls -l /dev/ttyS0 Maybe you have no ttyS0 or you have not permission.- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
the read function always returns to -1 and it tells " Resource temporarily unavailable". i really don't know why, :(
Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page