TCP/IP - RS232 Bricklet

This is the description of the TCP/IP protocol for the RS232 Bricklet. General information and technical specifications for the RS232 Bricklet are summarized in its hardware description.

API

A general description of the TCP/IP protocol structure can be found here.

Basic Functions

BrickletRS232.write
Function ID:

1

Request:
  • message -- char[60]
  • length -- uint8
Response:
  • written -- uint8

Writes a string of up to 60 characters to the RS232 interface. The string can be binary data, ASCII or similar is not necessary.

The length of the string has to be given as an additional parameter.

The return value is the number of bytes that could be written.

See set_configuration for configuration possibilities regarding baudrate, parity and so on.

BrickletRS232.read
Function ID:

2

Request:

empty payload

Response:
  • message -- char[60]
  • length -- uint8

Returns the currently buffered message. The maximum length of message is 60. If the length is given as 0, there was no new data available.

Instead of polling with this function, you can also use callbacks. See enable_read_callback and CALLBACK_READ callback.

BrickletRS232.set_configuration
Function ID:

6

Request:
  • baudrate -- uint8
  • parity -- uint8
  • stopbits -- uint8
  • wordlength -- uint8
  • hardware_flowcontrol -- uint8
  • software_flowcontrol -- uint8
Response:

no response

Sets the configuration for the RS232 communication. Available options:

  • Baudrate between 300 and 230400 baud.
  • Parity of none, odd, even or forced parity.
  • Stopbits can be 1 or 2.
  • Word length of 5 to 8.
  • Hard-/Software flow control can either be on or off but not both simultaneously on.

The default is: 115200 baud, parity none, 1 stop bit, word length 8, hard-/software flow control off.

The following meanings are defined for the parameters of this function:

  • 0: 300, for baudrate
  • 1: 600, for baudrate
  • 2: 1200, for baudrate
  • 3: 2400, for baudrate
  • 4: 4800, for baudrate
  • 5: 9600, for baudrate
  • 6: 14400, for baudrate
  • 7: 19200, for baudrate
  • 8: 28800, for baudrate
  • 9: 38400, for baudrate
  • 10: 57600, for baudrate
  • 11: 115200, for baudrate
  • 12: 230400, for baudrate
  • 0: none, for parity
  • 1: odd, for parity
  • 2: even, for parity
  • 3: forced parity 1, for parity
  • 4: forced parity 0, for parity
  • 1: 1, for stopbits
  • 2: 2, for stopbits
  • 5: 5, for wordlength
  • 6: 6, for wordlength
  • 7: 7, for wordlength
  • 8: 8, for wordlength
  • 0: off, for hardware_flowcontrol
  • 1: on, for hardware_flowcontrol
  • 0: off, for software_flowcontrol
  • 1: on, for software_flowcontrol
BrickletRS232.get_configuration
Function ID:

7

Request:

empty payload

Response:
  • baudrate -- uint8
  • parity -- uint8
  • stopbits -- uint8
  • wordlength -- uint8
  • hardware_flowcontrol -- uint8
  • software_flowcontrol -- uint8

Returns the configuration as set by set_configuration.

The following meanings are defined for the parameters of this function:

  • 0: 300, for baudrate
  • 1: 600, for baudrate
  • 2: 1200, for baudrate
  • 3: 2400, for baudrate
  • 4: 4800, for baudrate
  • 5: 9600, for baudrate
  • 6: 14400, for baudrate
  • 7: 19200, for baudrate
  • 8: 28800, for baudrate
  • 9: 38400, for baudrate
  • 10: 57600, for baudrate
  • 11: 115200, for baudrate
  • 12: 230400, for baudrate
  • 0: none, for parity
  • 1: odd, for parity
  • 2: even, for parity
  • 3: forced parity 1, for parity
  • 4: forced parity 0, for parity
  • 1: 1, for stopbits
  • 2: 2, for stopbits
  • 5: 5, for wordlength
  • 6: 6, for wordlength
  • 7: 7, for wordlength
  • 8: 8, for wordlength
  • 0: off, for hardware_flowcontrol
  • 1: on, for hardware_flowcontrol
  • 0: off, for software_flowcontrol
  • 1: on, for software_flowcontrol
BrickletRS232.set_break_condition
Function ID:

10

Request:
  • break_time -- uint16
Response:

no response

Sets a break condition (the TX output is forced to a logic 0 state). The parameter sets the hold-time of the break condition (in ms).

New in version 2.0.2 (Plugin).

Advanced Functions

BrickletRS232.get_identity
Function ID:

255

Request:

empty payload

Response:
  • uid -- char[8]
  • connected_uid -- char[8]
  • position -- char
  • hardware_version -- uint8[3]
  • firmware_version -- uint8[3]
  • device_identifier -- uint16

Returns the UID, the UID where the Bricklet is connected to, the position, the hardware and firmware version as well as the device identifier.

The position can be 'a', 'b', 'c' or 'd'.

The device identifier numbers can be found here

Callback Configuration Functions

BrickletRS232.enable_read_callback
Function ID:3
Request:empty payload
Response:no response

Enables the CALLBACK_READ callback.

By default the callback is disabled.

BrickletRS232.disable_read_callback
Function ID:4
Request:empty payload
Response:no response

Disables the CALLBACK_READ callback.

By default the callback is disabled.

BrickletRS232.is_read_callback_enabled
Function ID:

5

Request:

empty payload

Response:
  • enabled -- bool

Returns true if the CALLBACK_READ callback is enabled, false otherwise.

Callbacks

BrickletRS232.CALLBACK_READ
Function ID:

8

Response:
  • message -- char[60]
  • length -- uint8

This callback is called if new data is available. The message has a maximum size of 60 characters. The actual length of the message is given in addition.

To enable this callback, use enable_read_callback.

BrickletRS232.CALLBACK_ERROR
Function ID:

9

Response:
  • error -- uint8

This callback is called if an error occurs. Possible errors are overrun, parity or framing error.

The following meanings are defined for the parameters of this function:

  • 1: overrun, for error
  • 2: parity, for error
  • 4: framing, for error

New in version 2.0.1 (Plugin).