yangsong8-a1 opened a new pull request, #16086:
URL: https://github.com/apache/nuttx/pull/16086

   ## Summary
   
   If the expected amount of data is not read during read, check again whether 
there is data in buffer(CDCACM... might have buffered data received). If so, 
continue processing the data. If not, then check the file or dev flags.
   
   ## Impact
   
   Serial read. Move the judgment of the file or dev flag to after the second 
check of the rx buffer data amount.
   
   ## Testing
   
   Tested on sim and raspberrypi-pico-2 board. 
   When using cdcacm, if use usb req buf directly as the serial buf, execute 
the following code:
   Before the fix, Refer to the comments in the code for the execution status.
   After the fix, We can read the expected amount of data.
   ```
             int bytes_available = 0;
             int retval = ioctl(ttyacm_fd, FIONREAD, &bytes_available);
   
             /* Collect 2 characters at a time to the buffer and
              * print them out
              */
   
             int bytes_to_read = 2;
   
             if (retval == 0 && bytes_available >= bytes_to_read)
               {
                 memset(buffer, 0, sizeof(buffer));
   
                 /* The following should read as many characters as there are, 
up to sizeof(buffer) bytes.
                  * since we only end up here, if FIONREAD above returns >= 2, 
there should be at least 2 characters
                  * /
             
                 nread = read(ttyacm_fd, buffer, sizeof(buffer));
   
                 /* But here nread is just 1, and printing out the "buffer" we 
find out that we received only 1 character! */
   
                 if (nread)
                   {
                     printf("got %d bytes: %s\n", nread, buffer);
                   }
               }
   ```
   
   
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscr...@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to