[R] Windows serial connection

Adam Rountrey arountre at umich.edu
Thu Apr 2 04:03:29 CEST 2015


Using Windows 8.1

I have an Arduino connected and I am trying to read from and write to a
serial connection using R.  The problem involves the reading.  I am able to
establish the connection using the following:

> system("mode COM4 baud=9600 parity=n data=8", show.output.on.console=T)
> a = file("COM4", open="r+",encoding="UTF8", blocking=F)

I am able to write to the connection using:

> writeOne = function(x){
>    cat(paste(x, "\n", sep=""), file = a)
> }
> writeOne("test")

I am able to read from the connection using:

b = readLines(a,n=1)

However, if I read the last line in the COM4 buffer, and the Arduino later
writes more to the buffer, I am unable to read it.  I only get
"character(0)".  The Arduino seems to be behaving okay, as I can read an
write using the Arduino Serial Monitor.  If after reaching this point, I
close the connection and open it again, I am able to read from COM4 again
(until I read a final value again).  Any ideas as to what might be going
one here?

Many thanks for any ideas.

	[[alternative HTML version deleted]]



More information about the R-help mailing list