graphlcd-base/glcddrivers/port.c
changeset 21 f1573dd6dace
parent 15 cba463042186
child 29 2723893dc865
equal deleted inserted replaced
20:23b8c749e5a0 21:f1573dd6dace
   286 {
   286 {
   287 }
   287 }
   288 
   288 
   289 int cSerialPort::Open(const char * device, void (*FP)(int))
   289 int cSerialPort::Open(const char * device, void (*FP)(int))
   290 {
   290 {
   291     struct termios options;
       
   292     struct sigaction saio;
   291     struct sigaction saio;
   293 
   292 
   294     fd = open(device, O_RDWR | O_NOCTTY | O_NONBLOCK);
   293     if (FP == NULL)
   295     if (fd == -1)
       
   296     {
   294     {
   297         printf("error opening port\n");
   295         printf("error opening port\n");
   298         return -1;
   296         return -1;
   299     }
   297     }
   300 
   298 
       
   299     Open(device);
   301 
   300 
   302     // install the signal handler before making the device asynchronous/
   301     // install the signal handler before making the device asynchronous/
   303     saio.sa_handler = FP;
   302     saio.sa_handler = FP;
   304     sigemptyset (&saio.sa_mask);
   303     sigemptyset (&saio.sa_mask);
   305     saio.sa_flags = 0;
   304     saio.sa_flags = 0;
   309     // allow the process to receive SIGIO
   308     // allow the process to receive SIGIO
   310     fcntl(fd, F_SETOWN, getpid());
   309     fcntl(fd, F_SETOWN, getpid());
   311     // Make the file descriptor asynchronous 
   310     // Make the file descriptor asynchronous 
   312     fcntl(fd, F_SETFL, FASYNC | O_NONBLOCK);
   311     fcntl(fd, F_SETFL, FASYNC | O_NONBLOCK);
   313 
   312 
       
   313     return(0);
       
   314 }
       
   315 
       
   316 int cSerialPort::Open(const char * device)
       
   317 {
       
   318     struct termios options;
       
   319 
       
   320     fd = open(device, O_RDWR | O_NOCTTY | O_NONBLOCK);
       
   321     if (fd == -1)
       
   322     {
       
   323         printf("error opening port\n");
       
   324         return -1;
       
   325     }
       
   326 
   314     tcgetattr(fd, &options);
   327     tcgetattr(fd, &options);
   315 
   328 
   316     cfsetispeed(&options, B921600);
   329     cfsetispeed(&options, B921600);
   317     cfsetospeed(&options, B921600);
   330     cfsetospeed(&options, B921600);
   318 
   331