Linux Serial Read выдает ошибку
Я пытаюсь читать с моего последовательного порта, используя следующий код C. Я могу успешно записать на компьютер для прослушивания (ууу!), Но чтение выдает ошибку (код 11 - ресурс временно недоступен). Я также заметил, что мои журналы сообщений / dmesg не содержат никакой информации о неисправностях и т. Д. Так что это хорошо.
//A bunch of INCLUDES exist here....the the code
int fd=0;
int status=0;
int running=1;
char buffer[100];
char message[7];
void main(){
fd = 1;
fd=open("/dev/ttyM0",O_RDWR | O_NOCTTY);
if(fd == -1)
{
perror("open_port: Unable to open /dev/ttys0");
}
else
{
while(running<20)
{
sprintf(message,"Test%d\r",running);
status=write(fd,message,6);
if(status<0)
{
printf("Error Writing. Status=%d\n %s\n",errno, strerror(errno));
}
status=read(fd,buffer,8); //This throws an error(11). My connected device is writing "Testing/r"
if(status<0)
{
printf("Error Reading. Status=%d \n%s\n",errno, strerror(errno));
//close(fd);
running=running+1;
}
else
{
printf("%s\n\r",buffer);
}
sleep(2);
}
close(fd);
}
} //END MAIN
Это мои серийные настройки для моего порта. Я пытаюсь читать / писать на 9600 8 бит, нет четности, 1 стоповый бит. Я думаю, что мои настройки правильные.
sudo stty -a -F /dev/ttyM0
speed 9600 baud; rows 0; columns 0; line = 0;
intr = ^C; quit = ^\; erase = ^?; kill = ^U; eof = ^D; eol = <undef>; eol2 = <undef>;
swtch = <undef>; start = ^Q; stop = ^S; susp = ^Z; rprnt = ^R; werase = ^W; lnext = ^V;
flush = ^O; min = 1; time = 0;
-parenb -parodd cs8 hupcl -cstopb cread clocal -crtscts
-ignbrk -brkint -ignpar -parmrk -inpck -istrip -inlcr -igncr icrnl ixon -ixoff -iuclc -ixany
-imaxbel -iutf8
opost -olcuc -ocrnl onlcr -onocr -onlret -ofill -ofdel nl0 cr0 tab0 bs0 vt0 ff0
isig icanon iexten echo echoe echok -echonl -noflsh -xcase -tostop -echoprt echoctl echoke
Любая помощь будет очень высоко ценится. Спасибо!