serialConnection {serial}R Documentation

Sets up the interface parameters.

Description

This is the constructor of the serial interface connection.

Usage

serialConnection(
  name = "",
  port = "com1",
  mode = "115200,n,8,1",
  buffering = "none",
  newline = 0,
  eof = "",
  translation = "auto",
  handshake = "none",
  buffersize = 4096
)

Arguments

name

optional name for the connection

port

comport name; also virtual com's are supported; maybe USB schould work too

mode

communication mode '<BAUD>, <PARITY>, <DATABITS>, <STOPBITS>'

BAUD

sets the baud rate (bits per second)

PARITY

n, o, e, m, s corresponds to 'none', 'odd', 'even', 'mark' and 'space'

DATABITS

integer number of data bits. The value can range from 5 to 8

STOPBITS

integer number of stop bits. This can be '1' or '2'

buffering

'none', best for RS232 serial interface. Connection buffer is flushed (send) when ever a write operation takes place. 'line', buffer is send after newline character (\n or 0x0A) is recognized. 'full' write operations will be bufferd until a flush(con) is invoked.

newline

<BOOL>, whether a transmission ends with a newline or not.

TRUE or 1

send newline-char according to <translation> befor transmitting

FALSE or 0

no newline

eof

<CHAR>, termination char of the datastream (end-of-file). It only makes sense if <translation> is 'binary' and the stream is a file. Must be in the range of 0x01 – 0x7f. When the conection is closed eof is send as the last and final character.

translation

Determines the end-of-line (eol) character and mode of operation. This could be 'lf', 'cr', 'crlf', 'binary', 'auto' (default). A transmission is complete if eol symbol is received in non binary mode.

handshake

determines the type of handshaking the communication

'none'

no handshake is done

'rtscts'

hardware handshake is enabled

'xonxoff'

software handshake via extra characters is enabled

buffersize

defines the system buffersize. The default value is 4096 bytes (4kB).

Details

Linux and Windows behave a little bit different, when utilizing serial com ports. Still, by providing the name (like 'COM1', 'ttyS1' or 'cu.<name>') and the appropriate settings, the serial interface can be used. Even virtual com ports, like the FTDI usb uart chips will work, as long they map to a standard serial interface in the system.

Since the serial package relies on R's built in Tcl/Tk engine the configuration of the serial port takes place in the Tcl framework. This becomes important when different buffer sizes are set. For Windows the Tcl "-sysbuffer" parameter is invoked, whereas on unix-like systems "-buffersize" does the job.

Value

An object of the class 'serialConnection' is returned

Binary Data

Handling binary data is possible by setting transaltion = 'binary'. Pay attention that input and output vectors are characters with a number range of 0...0xFF which might require certain conversations e. g. charToRaw() or rawToChar() functions. If eof-character is defined, this symbol terminates the input data stream. Every byte in the buffer after that symbol is deleted/ignored. The next transmission is valid again up to that symbol. If the connection is closed eof is send to terminate the output data stream. Remind, the newline option works here too. It adds a line feed or 0x0A - byte to the end of each output respectively.

ASCII Data

In non binary mode, ASCII-communication is assumed. This means, that each string, which is send or received, carries valid 8bit ASCII characters (0x01 – 0xFF). Some of these characters appear as escaped sequences, if they are not printable. A string is terminated by the end-of-line character (e. g. \n). The transmission ends and so becomes valid if the symbol is detected according to the translation setting. Sending terminated strings invokes the substitution of the end-of-line character according to the translation setting.


[Package serial version 3.0 Index]