The connection read-only property of the MIDIPort interface returns the connection state of the port.
connection
external MIDIPortConnectionState get connection;