# serial.write ## Function Write data to the opened serial port. Supports String, byte arrays and Bytes. ## Syntax ```bt device.open(config).write(data) ``` ## Parameters | Parameters | Type | Required | Default value | Description | | ------ | ------ | ------ | ------ | ------ | | data | String/Array/Bytes | Yes | None | String is written as UTF-8; Array elements must be 0 to 255; Bytes writes raw bytes directly. | ## Return value | Type | Description | | ------ | ------ | | Int | Returns the number of bytes written. | ## Example ```bt port = device.open({type: 'serial', port: 'COM3'}) result = port.write(bytes('010300000002c40b', 'hex')) // Output: 8 print result ``` ## Notes - An error will be reported when illegal bytes appear in the array. - No string conversion is done when writing Bytes.