Чтение и запись с / на ttyS0 - PullRequest
0 голосов
/ 11 апреля 2020

У меня RPI Zero W, подключенный к моей виртуальной машине через USB, который можно найти в / dev / ttyS0 как на P C, так и на RPI. В настоящее время я пытаюсь отправить что-то из RPI через USB-кабель на виртуальную машину (P C).

Я пытаюсь прочитать на порту следующий код:

    #include <stdio.h>   /* Standard input/output definitions */    
    #include <string.h>  /* String function definitions */    
    #include <unistd.h>  /* UNIX standard function definitions */    
    #include <fcntl.h>   /* File control definitions */    
    #include <errno.h>   /* Error number definitions */    
    #include <termios.h> /* POSIX terminal control definitions */    

    /*     * 'open_port()' − Open serial port 1.     *     
    * Returns the file descriptor on success or −1 on error.     */    

   int fd; /* File descriptor for the port */

   int open_port(void)    
   {            
     fd = open("/dev/ttyS0", O_RDWR | O_NOCTTY | O_NDELAY);   

     if(fd == -1) 
     {       
       /*        * Could not open the port.        */        
       perror("open_port: Unable to open /dev/ttyS0 − ");      
     }      
     else        
      fcntl(fd, F_SETFL, FNDELAY);      

    return (fd);    
  }

  int close_port(void)
  {
    close(fd);
    return (fd);
  }


  int main()
  {
    printf("Serial reader has started...\n\n");
    while(1)
    {
      open_port();
      close_port();
    }

    return 0;
  }

, а на стороне RPI я создал небольшой скрипт bash, который отправляет символ 1:

while :
do
    echo "sending character 1 to /dev/ttyS0"
    echo "1" > /dev/ttyS0
done

Однако, хотя скрипт bash и программа c работают в непрерывных циклах, я ничего не получаю на стороне P C.

В чем может быть причина?

...