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