This function is used in Python Scripting.


Read numberOfBytes bytes from a serial port and convert them to a String. If a specific encoding is needed to match the source of the data, use system.serial.readBytes and use the desired encoding to decode the byte array returned.

Client Permission Restrictions

This scripting function has no Client Permission restrictions.


system.serial.readBytesAsString(port, numberOfBytes, [timeout], [encoding])

  • Parameters

String port - The previously configured serial port to use.

Integer numberOfBytes - The number of bytes to read.

Integer timeout - Maximum amount of time, in milliseconds, to block before returning. Default is 5000. [optional]

String encoding- Encoding to use when constructing the string. Defaults to the platform's default character set. [optional]

  • Returns

String - A String created from the bytes read.

  • Scope

Gateway, Vision Client, Perspective Session

The Encoding Parameter

The encoding parameter can be used to decode a string with any of the possible encoding character sets that are available. By default, the following character sets are provided by the Java platform (dash characters and underscores are interchangeable). Dashed examples are shown below:

  • ISO-8859-1
  • UTF-16
  • UTF-16BE
  • UTF-16LE
  • UTF-8
Code Examples
Code Snippet
# This example will read a specified number of bytes as a String from a port called "COM1".
port = "COM1"
numberOfBytes = 2


system serial readBytesAsString, serial.readBytesAsString