There have been various changes to the buffer handling ioctls since
2013, so the behaviour will have changed a bit.
I wouldn't recommend calling comedi_mark_buffer_read() only every
"buffer size" bytes, as that would make leave the buffer vulnerable to
overflow errors because the part of the buffer that hasn't been marked
as read yet cannot be filled with new data.
One option would be call comedi_mark_buffer_read() slightly more often
so that the buffer never fills up completely.
Another option is to roll your own function that combines the
functionality of comedi_get_buffer_contents() and
comedi_mark_buffer_read(), since they both use the same comedi ioctl
internally. Here is one possible (untested) function:
int mark_read_and_get_new(comedi_t *it, unsigned int subdev,
unsigned int mark_read_bytes,
unsigned int *get_new_bytes)
{
int ret;
int fd;
comedi_bufinfo bi;
fd = comedi_fileno(it);
if (fd == -1)
return -1;
memset(&bi, 0, sizeof(bi));
bi.subdevice = subdev;
bi.bytes_read = mark_bytes_read;
ret = ioctl(fd, COMEDI_BUFINFO, &bi);
if (ret < 0)
return -1;
/* get new contents */
*get_new_bytes = bi.buf_write_count - bi.buf_read_count;
/* return amount marked read */
return bi.bytes_read;
}
The above function returns the same value as comedi_mark_buffer_read().
The 'mark_read_bytes' parameter can be set to 0 if you don't want to
mark anything as read. As a side-effect, it sets the '*get_new_bytes'
parameter to what would be returned by comedi_get_buffer_contents().
There are some slight differences in error handling, because it does not
update the "comedi errno" returned by the comedi_errno() function.
However, it does update the standard C 'errno'.
--
-=( Ian Abbott @ MEV Ltd. E-mail: <
abb...@mev.co.uk> )=-
-=( Web:
http://www.mev.co.uk/ )=-