Hi all -

I'm playing around with an attempt to do some serial communication from
within R to a microcontroller board.  I open a connection:

zz = file("/dev/ttyUSB0",open="a+") ## text mode

... when I execute

writeLines("0",con=zz)

I know the board receives the "0" because the board's serial comm LEDs light
up when submit the command at the R prompt.  However, if I want to open the
connection to the board in binary mode:

zz = file("/dev/ttyUSB0",open="a+b") ## binary mode

...submitting

writeBin(as.integer(9), con=zz, size=1)

doesn't do anything (no serial comm LEDs active) until AFTER I run a

readBin(zz,"integer")

I know the data arrives at the board correctly, because if the board
receives the right byte over the serial connection, it's been programmed to
light a particular LED.  The problem is, the LED doesn't light after the
writeBin command, as one would expect, but only after the subsequent readBin
command has been issued.  As I said, the text mode behaves as expected, with
communication occurring after the writeLines command, but there seems to be
something wrong with the way writeBin is working (or at least the way I'm
using it!).

Any pointers would be greatly appreciated!

Jake

> sessionInfo()
R version 2.6.1 (2007-11-26)
i686-pc-linux-gnu

locale:
LC_CTYPE=en_US.UTF-8;LC_NUMERIC=C;LC_TIME=en_US.UTF-8;LC_COLLATE=en_US.UTF-8;LC_MONETARY=en_US.UTF-8;LC_MESSAGES=en_US.UTF-8;LC_PAPER=en_US.UTF-8;LC_NAME=C;LC_ADDRESS=C;LC_TELEPHONE=C;LC_MEASUREMENT=en_US.UTF-8;LC_IDENTIFICATION=C

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base

other attached packages:
[1] lars_0.9-7          randomForest_4.5-22 RBGL_1.14.0
[4] graph_1.16.1        cairoDevice_2.5

loaded via a namespace (and not attached):
[1] cluster_1.11.9  rcompgen_0.1-17 tools_2.6.1

        [[alternative HTML version deleted]]

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to