R/ar_collect.R

Defines functions ar_collect

Documented in ar_collect

#' Stream serial port data into R console
#' 
#' @description This function wraps around `ar_read()` and will read serial
#' port data into R console until user stop it.
#' 
#' @param size Size
#' @inheritParams ar_monitor
#' 
#' @export
ar_collect <- function(fd, size = 100, flush_time = 0.5,
                       eolchar = "\n", buf_max = 256, timeout = 5000) {
  message("Flushing Port...")
  ar_flush_hard(fd, flush_time = flush_time)
  out <- character()
  pb <- progress::progress_bar$new(total = size)
  for (i in seq(size)) {
    out[i] <- ar_read(fd, eolchar, buf_max, timeout)
    pb$tick()
  }
  message("Done")
  return(out)
}
hebrewseniorlife/arduinor documentation built on May 24, 2019, 8:51 a.m.