Close the heartbeat connection

Greetings,

I am connecting to the Pixhawk through pymavlink with the following code:

the_connection = mavutil.mavlink_connection('COM10', baud=57600)
the_connection.wait_heartbeat()
print("Heartbeat from system (system %u component %u)" % (the_connection.target_system, the_connection.target_component))

I am able to receive the output successfully.

Heartbeat from system (system 1 component 0)

I want to implement a disconnect button in the GUI I am developing. Is there a way to close this connection?

Hi @varshini, welcome to the forum :slight_smile:

Pymavlink’s mavlink_connection outputs have a .close() method defined, so you should be able to just run the_connection.close() at the end of the connection’s lifetime (e.g. in a finally block, or as part of a context manager).