On Apr 20, 2010, at 10:33 AM, Blair Christian wrote:
> Does anybody know if there is any support to read from serial ports? I just
got an arduino, and wanted to write some scripts for working with real time
streaming sensor data...
>
Yes (I have Arduinos reporting measurements from all sensors in the house to R
on my iMac which produces plots that are synchronized with my webserver). In
principle you can simply use /dev/tty.usb... and read from it. In most cases the
default setting is already fine (9600,n,8,1 on Mac) or you can use tools the set
it up in advance (setserial on Linux etc.) so you don't have to worry about
setting up the serial from R.
Depending on your OS you may be able to read from the serial device directly
with a regular file connection or you can use a pipe connection to a tool which
pipes out from the tty to stdout (written for a Mac but may work on other
unices):
https://svn.rforge.net/C/trunk/tools/ttys.c
and then use something like
f=pipe("ttys /dev/tty.usbserial-X1234")
A rather handy option -d prepends current time to each line so you can track
output over time. I have some more tools for this (even allowing you to share
form Arduino output with several computers or even send remote commands to your
Arduino including encryption etc ...).
Cheers,
Simon
PS: From experience I can say that Arduinos are highly addictive so beware ;).
> In base::connections documentation, it's not clear if there's an
easy
> way to do this? Any ideas on hacking it? I'm open to win/linux/mac
> solutions. I'm not sure how sockets work, but possibly there is a way
> to pipe things to a buffer and read from a buffer in bash (in my linux
> mind I have the thought of trying to redirect /dev/something to a
> file, or symlinking a file to point to the hardware, but know that
> there has to be some secret sauce to go from streaming in to a
> readable file, but don't know what the missing components are).
>
> Thoughts?
>
> ______________________________________________
> R-devel at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
>
>