Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix the rs232 receive function #17

Closed
GoogleCodeExporter opened this issue Mar 14, 2015 · 3 comments
Closed

Fix the rs232 receive function #17

GoogleCodeExporter opened this issue Mar 14, 2015 · 3 comments

Comments

@GoogleCodeExporter
Copy link

With the current rs232 receive function, I experimented some buffer
synchronization problems during the pn532C106 support implementation
process (see: http://code.google.com/p/libnfc/issues/detail?id=15).

With my patch (Linux only), the function reads exactly the number of bytes
currently in the buffer:



bool rs232_receive(const serial_port sp, byte_t* pbtRx, uint32_t* puiRxLen)
{
  int iResult;
  int byteCount;
  fd_set rfds;

  // Reset file descriptor
  FD_ZERO(&rfds);
  FD_SET(((serial_port_unix*)sp)->fd,&rfds);
  iResult = select(((serial_port_unix*)sp)->fd+1, &rfds, NULL, NULL, &tv);

  // Read error
  if (iResult < 0) return false;

  // Number of bytes in the input buffer
  ioctl(((serial_port_unix*)sp)->fd, FIONREAD, &byteCount);

  // Read time-out or empty buffer
  if (iResult == 0 || byteCount == 0) return false;

  // There is something available, read the data
  *puiRxLen = read(((serial_port_unix*)sp)->fd,pbtRx,byteCount);

  return (*puiRxLen > 0);
}

Original issue reported on code.google.com by emanuele.bertoldi on 4 Sep 2009 at 10:25

@GoogleCodeExporter
Copy link
Author

Thanks for report.

Original comment by romu...@libnfc.org on 4 Sep 2009 at 1:34

  • Changed title: Fix the rs232 receive function
  • Changed state: Started
  • Added labels: OpSys-Linux

@GoogleCodeExporter
Copy link
Author

Applied in r96. Thanks!

Original comment by romu...@libnfc.org on 4 Sep 2009 at 1:48

@GoogleCodeExporter
Copy link
Author

Original comment by romu...@libnfc.org on 4 Sep 2009 at 1:48

  • Changed state: Fixed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant