Accessor: net/XBee


This accessor sends and/or receives messages from an XBee radio located on a specified serial port on the host. The accessor lists all the serial ports that it finds as options, although most likely only some of these are actually XBee radio devices. It is quite tricky to get this accessor working, as you have to have properly configured the XBee devices, for example to be on the same network as each other and to use the same baud rate as specified in this accessor. Information about XBee devices can be found here:


Whenever an input is received on the toSend input, the data on that input is sent to the serial port, and then presumably over the readio.

Whenever a message is received from the serial port, that message is produced on the received output.

When 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 sendType and receiveType parameters. For the Ptolemy II host, these include at least 'string', 'number', and a variety of numeric types.

If both ends of the socket are known to be JavaScript clients, then you should use the 'number' data type for numeric data. If one end or the other is not JavaScript, then you can use more specified types such as 'float' or 'int', if they are supported by the host. In all cases, received numeric data will be converted to JavaScript 'number' when emitted. For sent data, this will try to convert a JavaScript number to the specified type. The type 'number' is equivalent to 'double'.

When type conversions are needed, e.g. when you send a double with 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 all at once, and will be received in one batch and emitted as an array.

Accessors that extend this one can override the toSendInputHandler function to customize what is sent.

This accessor requires the 'xbee' module.

  • $$Id$$
  • Edward A. Lee
Name Type Description
toSend The data to be sent over the radio.
Name Type Description
received The data received from the radio.
Name Type Description
port int The port on the server to connect to. This defaults to the last (most recently added, presumably) serial port in the list of serial ports on the host.
receiveType string See above.
sendType string See above.


(static) initialize()

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.


(static) setup()

Set up the accessor by defining the parameters, inputs, and outputs.


(static) toSendInputHandler()

Handle input on 'toSend' by sending the specified data over the radio.


(static) wrapup()

Close the web socket connection.