--- title: "system.serial.readBytesAsString" description: "Read numberOfBytes bytes from a serial port and convert them to a String." --- # system.serial.readBytesAsString > Read numberOfBytes bytes from a serial port and convert them to a String. 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](system-serial-readBytes.md) and use the desired encoding to decode the byte array returned. ## Client Permission Restrictions This scripting function has no [Client Permission](../../../ignition-modules/vision/vision-project-properties/vision-project-properties.md#vision-permissions-properties) 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](https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/nio/charset/StandardCharsets.html) (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 ```python title="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) ```