Hi Regina,

Can I help you?
Are you writing serial port driver with C?

Best regard,

Le Hoang Vu

Vào 18-07-2016 10:59, "Regina Choi" <[email protected]> đã viết:

> Hello Andrey,
>
> I am having almost similar problem as yours, just wondering have you found
> the reason behind it?  I have searching through the web but couldn't find
> related answer.
>
>
> Regards,
> Regina
> On Wednesday, May 7, 2014 at 2:42:34 AM UTC+8, Andrey wrote:
>>
>> Hello,
>>
>> I need to use an UART to communicate between beaglebone and the device. I
>> have written the C code, but it has a few problems within it. I can't
>> identify the cause of the problem or to be more precise don't know how fix
>> it.
>>
>> The problem is of
>> reading in the information and displaying it on a shell. I can easily
>> write any information data set that I wish, but when I try to read in
>> response it either doesn't read in, with the perror being displayed as
>> (erno = EINTR [Interrupted function call]) meaning read () function
>> returned negative number.
>>
>> #include <iostream>
>>
>> #include <termios.h>
>>
>> #include <stdio.h>
>>
>> #include <unistd.h>
>>
>> #include <fcntl.h>
>>
>> #include <sys/signal.h>
>>
>> #include <stdlib.h>
>>
>> #include <sys/ioctl.h>
>>
>> #include <errno.h>
>>
>> #define BAUDRATE B19200
>>
>> #define PORT "/dev/ttyO4"
>>
>> #define _POSIX_SOURCE 1
>>
>>
>>
>> #define FALSE 0
>>
>> #define TRUE 1
>>
>> volatile int STOP=FALSE;
>>
>>
>>
>> void signal_handler_IO(int status);
>>
>> int wait_flag = TRUE;
>>
>>
>>
>> int main ()
>>
>> {
>>
>>     int fd=0, res=0;
>>
>>     int check=0;
>>
>>
>>
>>     char SYNC  [] = {0x55};
>>
>>     char PID [] = {0x6A};
>>
>>
>>
>>     struct termios oldtio, newtio;
>>
>>     struct sigaction saio;
>>
>>     char buff[255];
>>
>>
>>
>>     fd = open(PORT, O_RDWR | O_NOCTTY | O_NONBLOCK);
>>
>>     if (fd<0) {perror(PORT); exit(-1);}
>>
>>
>>
>>     saio.sa_handler=signal_handler_IO;
>>
>>     saio.sa_flags=0;
>>
>>     saio.sa_restorer = NULL;
>>
>>     sigaction(SIGIO, &saio,NULL);
>>
>>     fcntl(fd, F_SETFL, FASYNC);
>>
>>     check = tcgetattr(fd, &oldtio);
>>
>>     if (check<0){perror("tcgetattr");}
>>
>>
>>
>>     check = newtio.c_cflag = BAUDRATE | CS8 | CLOCAL | CREAD ; if (check<
>> 0){perror("c_cflag");}
>>
>>     check = newtio.c_iflag = IGNPAR | IXON; if (check<0){perror("c_iflag"
>> );}
>>
>>     check = newtio.c_oflag = 0; if (check<0){perror("c_oflag");}
>>
>>     //check = newtio.c_lflag = ICANON | ISIG;
>>
>>     check = newtio.c_lflag = 0; if (check<0){perror("c_lflag  ");}
>> /* c_cc is responsible for an erno error */
>>
>>     check = newtio.c_cc[VMIN]=1; if (check<0){perror("c_cc[VMIN]");}
>>
>>     check = newtio.c_cc[VTIME]=0; if (check<0){perror("c_cc[VTIME]");}
>>
>>     tcflush(fd, TCIFLUSH);
>>
>>
>>     check = tcsetattr(fd, TCSANOW, &newtio); if (check<0){perror(
>> "tcsetattr");}
>>
>>
>>
>> for(;;)
>>
>> {
>>     ioctl(fd, TIOCSBRK);
>>
>>     usleep(1300);
>>
>>     ioctl(fd,TIOCCBRK);
>>
>>     usleep(200);
>>
>>
>> /* send request to actuator to receive the current setting and setup */
>>     check = write(fd, SYNC, sizeof(SYNC));  if (check<0){perror("SYNC");}
>>
>>     check = write(fd,PID, sizeof(PID)); if (check<0){perror("PID");}
>>
>> /* read response*/
>>     res = read(fd, buff,255);
>>     if (res < 0)
>>
>>     {
>>
>>         perror("read");
>>         //if(errno ==EINTR) continue;
>>     }
>>
>>         printf(": :%d :%d\n", res,buff);
>>
>>
>>
>> usleep(10000);
>>
>> }
>>
>>     close (fd);
>>
>> }
>>
>>
>>
>> void signal_handler_IO(int status)
>>
>> {
>>
>> wait_flag=FALSE;
>>
>>
>> e}
>>
>> erno EINTR error is displayed only when i'm setting any non-zero values
>> to c_cc[VTIME] or c_cc[VMIN]. but still even if i set the both to zero, I
>> cannot read anything from the port, it's just blank.
>>
>>
>> I'm confident that i'm receiving response from the device, I have checked
>> it with oscilloscope.
>>
>> Any assistance would be appreciated. if possible with the code examples
>> for me to see what should I modify.
>>
>> Thank you very much for the help.
>>
> --
> For more options, visit http://beagleboard.org/discuss
> ---
> You received this message because you are subscribed to a topic in the
> Google Groups "BeagleBoard" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/beagleboard/vbRrGiqZyfs/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
> [email protected].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/beagleboard/61ab7f12-c3c4-407b-a14a-82f2a0a3e2e3%40googlegroups.com
> <https://groups.google.com/d/msgid/beagleboard/61ab7f12-c3c4-407b-a14a-82f2a0a3e2e3%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
For more options, visit http://beagleboard.org/discuss
--- 
You received this message because you are subscribed to the Google Groups 
"BeagleBoard" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/beagleboard/CA%2B43C_nXg19G%3Ddw9JQbw1o%2Bzy%3DgcdSvOS%2BYM5%2BLr9jU_RcQP%3DQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to