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 '
|
buffering |
' |
newline |
|
eof |
|
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
|
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.