serial_write(ser, tx_data)
Features
This function writes the data (tx_data) to a serial port.
Parameters
Parameter Name | Data Type | Default Value | Description |
---|---|---|---|
ser | serial.Serial | - | Serial instance |
tx_data | byte | - | Data to be transmitted
|
Return
Value | Description |
---|---|
0 | Success |
-1 | The port is not open. |
-2 | serial.SerialException error occurred |
Exception
Exception | Description |
---|---|
DR_Error (DR_ERROR_TYPE) | Parameter data type error occurred |
Example
ser = serial_open(port="COM", baudrate=115200, bytesize=DR_EIGHTBITS,
parity=DR_PARITY_NONE, stopbits=DR_STOPBITS_ONE)
serial_write(ser, b"123456789") # b means the byte type.
# Convert string to byte
msg = “abcd” # msg is a string variable
serial_write(ser, msg.encode()) # encode() converts string type to byte type
serial_close(ser)