1. Home
  2. Docs
  3. Python 3.X Documentation
  4. Examples
  5. Opening a serial port communication, sending a command, receiving a response and closing the serial port

Opening a serial port communication, sending a command, receiving a response and closing the serial port

The example below shows how to use the serial_connection module send commands and receive response from a device.

# Import serial connection class.
from serial_connection import SerialConnection

if __name__ == "__main__":
    # Create the serial port connection object with default settings.
    serial = SerialConnection("R246744")

    # Get device name and friendly description.
    print(serial.name)
    print(serial.description)

    # Open connection.
    serial.open()

    # Send command.
    serial.send(b"info")

    # Get response.
    response = serial.receive()

    # Print response in binary format.
    print(response)

    # Close connection.
    serial.close()