This accessor sends and/or receives data from a serial port on the host.
The accessor lists all the serial ports that it finds as options.
Whenever an input is received on the
the data on that input is sent to the serial port.
Whenever data is received from the serial port, the data is
produced on the
wrapup() is invoked, this accessor closes the serial port.
The send and receive types can be any of those supported by the host.
The list of supported types will be provided as options for the
receiveType parameters. For the Nashorn host, these include at
least 'string', 'number', 'JSON', and a variety of numeric types.
The type 'number' is equivalent to 'double'.
The data chunks sent on the
received output depend on the
parameter. Each output will be of the specified type. Note that if
receivedType is 'string' or 'JSON' then the output is produced only
after a null byte is received on the serial port. If the type is 'JSON',
then this accessor will attempt to parse the JSON. If parsing fails,
then the raw byte array will be sent to the
invalid output port.
When type conversions are needed, e.g. when you send a double
sendType set to int, or an int with
sendType set to byte,
then a "primitive narrowing conversion" will be applied, as specified here:
For numeric types, you can also send an array with a single call to this.send(). The elements of the array will be sent in sequence.
Accessors that extend this one can override the
to customize what is sent.
This accessor requires the 'serial' module.
||The data to be sent over the serial port.|
||The data received from the serial port converted to the specified type.|
||Byte arrays that fail to parse in JSON.|
||int||The port on the host to connect to. This defaults to the last (most recently added, presumably) serial port in the list of serial ports on the host.|
Initiate a connection to the server using the current parameter values, set up handlers for for establishment of the connection, incoming data, errors, and closing from the server, and set up a handler for inputs on the toSend() input port.
Set up the accessor by defining the parameters, inputs, and outputs.
Handle input on 'toSend' by sending the specified data over the radio.
Close the web socket connection.