- 신규로 표시
- 북마크
- 구독
- 소거
- RSS 피드 구독
- 강조
- 인쇄
- 부적절한 컨텐트 신고
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;
}
링크가 복사됨
2 응답
- 신규로 표시
- 북마크
- 구독
- 소거
- RSS 피드 구독
- 강조
- 인쇄
- 부적절한 컨텐트 신고
1. print errno. It will say what happening.
2. Show ls -l /dev/ttyS0 Maybe you have no ttyS0 or you have not permission.- 신규로 표시
- 북마크
- 구독
- 소거
- RSS 피드 구독
- 강조
- 인쇄
- 부적절한 컨텐트 신고
the read function always returns to -1 and it tells " Resource temporarily unavailable". i really don't know why, :(
