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β
| Type | Parameter | Description |
|---|---|---|
| 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
- US-ASCII
- UTF-16
- UTF-16BE
- UTF-16LE
- UTF-8
Code Exampleβ
# 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)