+ All Categories
Home > Documents > Matthew S. Shotwell · 2017. 9. 21. · Matthew S. Shotwell Vanderbilt University Department of...

Matthew S. Shotwell · 2017. 9. 21. · Matthew S. Shotwell Vanderbilt University Department of...

Date post: 13-Oct-2020
Category:
Upload: others
View: 1 times
Download: 0 times
Share this document with a friend
13
Experimenting with a TTY Connection for R Matthew S. Shotwell Vanderbilt University Department of Biostatistics August 16, 2011
Transcript
Page 1: Matthew S. Shotwell · 2017. 9. 21. · Matthew S. Shotwell Vanderbilt University Department of Biostatistics August 16, 2011. What is a TTY? A TTY, or computer terminal is a two-way

Experimenting with a TTY Connection for R

Matthew S. Shotwell

Vanderbilt UniversityDepartment of Biostatistics

August 16, 2011

Page 2: Matthew S. Shotwell · 2017. 9. 21. · Matthew S. Shotwell Vanderbilt University Department of Biostatistics August 16, 2011. What is a TTY? A TTY, or computer terminal is a two-way

What is a TTY?

A TTY, or computer terminal is a two-way asynchronouscommunications channel with configurable properties.The name “TTY” derives from the teletype or texttelephone.

Page 3: Matthew S. Shotwell · 2017. 9. 21. · Matthew S. Shotwell Vanderbilt University Department of Biostatistics August 16, 2011. What is a TTY? A TTY, or computer terminal is a two-way

Text Terminal

configurable:

I line endings: ‘\n’ vs. ‘\n\r’I keyboard interrupts: ctrl-c → SIGINT

Page 4: Matthew S. Shotwell · 2017. 9. 21. · Matthew S. Shotwell Vanderbilt University Department of Biostatistics August 16, 2011. What is a TTY? A TTY, or computer terminal is a two-way

Serial Terminal

configurable:

I serial protocol: baud rate, character size, stop bits,

I serial protocol: parity, flow control

Page 5: Matthew S. Shotwell · 2017. 9. 21. · Matthew S. Shotwell Vanderbilt University Department of Biostatistics August 16, 2011. What is a TTY? A TTY, or computer terminal is a two-way

POSIX

I Portable Operating System Interface for Unix

I “POSIX” suggested by Richard Stallman (useR! 2010 Invitee)

I [IEEE and The Open Group, 2008]I Defines a standard and API for OS interface

I Character Set & LocaleI Environment VariablesI HeadersI General Terminal Interface

The General Terminal Interface shall be supported on anyasynchronous communications ports if theimplementation provides them.

Page 6: Matthew S. Shotwell · 2017. 9. 21. · Matthew S. Shotwell Vanderbilt University Department of Biostatistics August 16, 2011. What is a TTY? A TTY, or computer terminal is a two-way

OS Support for the General Terminal Interface

I Linux and UN*X (native)

I Mac OS X (native)

I Microsoft Windows (indirect)

Page 7: Matthew S. Shotwell · 2017. 9. 21. · Matthew S. Shotwell Vanderbilt University Department of Biostatistics August 16, 2011. What is a TTY? A TTY, or computer terminal is a two-way

Implementing the General Terminal Interface in R

Strategy:

I specify a new type of R connection

I implement a tty function

I configure the TTY using arguments to tty

Rationale:

I parsimonious with the R/S concept of IO

I utilize generic funcionality (readBin, flush, etc.)

Page 8: Matthew S. Shotwell · 2017. 9. 21. · Matthew S. Shotwell Vanderbilt University Department of Biostatistics August 16, 2011. What is a TTY? A TTY, or computer terminal is a two-way

Implementing a New R Connection

The R connection internal code is NOT available to packagedevelopers. Hence, new R connection implementations

I cannot be in an R package

I must patch the R source code

I cannot be distributed via the CRAN

The R connection internals (at R 2.12.0) are detailed in anunofficial collection of notes: R Connection Internals[Shotwell, 2010] in HTML and PDF. patch + instructions.

Page 9: Matthew S. Shotwell · 2017. 9. 21. · Matthew S. Shotwell Vanderbilt University Department of Biostatistics August 16, 2011. What is a TTY? A TTY, or computer terminal is a two-way

The TTY Connection for R: The tty Function

The TTY connection patch provides:

tty <- function (description, open = "", blocking = TRUE, baudrate = NULL,

input = NULL, output = NULL, control = NULL, local = NULL,

chars = NULL) { ... }

I input, output, control, local, and chars are each lists ofconfigurable TTY parameters (see ?tty and the GeneralTerminal Interface [IEEE and The Open Group, 2008])

I tty returns an instance of the ‘connection’ class

Page 10: Matthew S. Shotwell · 2017. 9. 21. · Matthew S. Shotwell Vanderbilt University Department of Biostatistics August 16, 2011. What is a TTY? A TTY, or computer terminal is a two-way

The TTY Connection for R: Text Terminal Application

#get a password from the terminal, don’t echo characters

getpass <- function(prompt="password:") {

cat(prompt)

con <- tty("/dev/tty", local=list(ICANON=TRUE,ECHO=FALSE))

pw <- readLines(con, 1)

close(con)

cat("\n")

invisible(pw)

}

R> print(getpass())

password:

[1] "mysecretpassword"

Page 11: Matthew S. Shotwell · 2017. 9. 21. · Matthew S. Shotwell Vanderbilt University Department of Biostatistics August 16, 2011. What is a TTY? A TTY, or computer terminal is a two-way

The TTY Connection for R: Serial Terminal Application

µC Temperature Sensor Interface

Page 12: Matthew S. Shotwell · 2017. 9. 21. · Matthew S. Shotwell Vanderbilt University Department of Biostatistics August 16, 2011. What is a TTY? A TTY, or computer terminal is a two-way

The TTY Connection for R: Biomedical Application

Time

V

−2

0

2

0 5 10 15 20

ECG

−2

0

2

High Frequency Filter

−2

0

2

Low Frequency Filter

−2

0

2

Raw

http://biostatmatt.com/archives/78

Page 13: Matthew S. Shotwell · 2017. 9. 21. · Matthew S. Shotwell Vanderbilt University Department of Biostatistics August 16, 2011. What is a TTY? A TTY, or computer terminal is a two-way

IEEE and The Open Group (2008).

Standard 1003.1 & Base Specifications Issue 7.Technical report, Institute of Electrical and Electronics Engineers & The Open Group.URL: http://pubs.opengroup.org/onlinepubs/9699919799/ retrieved Aug. 7, 2011.

Shotwell, M. (2010).

R connection internals.Technical report, BioStatMatt.com.URL: http://biostatmatt.com/R/R-conn-ints.


Recommended