[R] Reading data from a serial port

(Ted Harding) Ted.Harding at nessie.mcc.ac.uk
Wed Sep 14 14:15:11 CEST 2005

On 13-Sep-05 vittorio wrote:
>> Hoping this helps,
> Thanks, it helps! But Ted,
> how do you let R know the parameters of the serial connection
> (e.g. "4800 7S1") ?
> Ciao
> Vittorio

Following up, I've now had info from people pointing out the

For Windows, there's a simple DOS utility which, for a serial port,
is one the lines of

  MODE COM1:<speed>,<parity>,<databits>,<stopbuts>[,P]

where the optional "P" is to allow infinite retries to send data
to a non-responding device. This shouldn't be necessary when
passively reading data being output from external equipment.

Any of the above can be omitted (in which case the corresponding
setting is not changed) provided the requisite commas are present.

  MODE COM1:4800,E,7,1

will set 4800 baud, Even parity, 7 databits and 1 stop bit.

Thanks to Tom Mulholland for reminding me of this!

For Linux, there is the 'stty' command (which can set far more
things as well, since it is designed for terminal consoles
connected via serial lines). Something like

  stty -F /dev/ttyS0 4800 parenb -parodd cs7 -cstopb

would have the same effect as the above. See "man stty" for more

So, since there is a simple command foreither Windows or Linux,
this can be sent from within an R session using the 'system'
command, which will set up the serial port. After this, 'scan'
should simply read the incoming data (as discussed earlier).

Best wishes to all,

E-Mail: (Ted Harding) <Ted.Harding at nessie.mcc.ac.uk>
Fax-to-email: +44 (0)870 094 0861
Date: 14-Sep-05                                       Time: 13:09:55
------------------------------ XFMail ------------------------------

More information about the R-help mailing list