Skip to main content
Version: 8.1

system.serial.readBytesAsString

This function is used in Python Scripting.

Description​

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.

Syntax​

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

Parameters​

TypeParameterDescription
StringportThe previously configured serial port to use.
IntegernumberOfBytesThe number of bytes to read.
IntegertimeoutMaximum amount of time, in milliseconds, to block before returning. Default is 5000. [optional]
StringencodingEncoding 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
  • US-ASCII
  • UTF-16
  • UTF-16BE
  • UTF-16LE
  • UTF-8

Code Example​

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(port,numberOfBytes)