import isystem.connect as ic
def test_findExistingInstance():
print("Finding existing instance by ID...")
cfg = ic.CConnectionConfig()
cfg.instanceId("findExistingInstanceExample")
cfg.start_if_required()
connMgr = ic.ConnectionMgr()
connMgr.connect(cfg)
cfg2 = ic.CConnectionConfig()
cfg2.start_existing()
cfg2.instanceId("findExistingInstanceExample")
connMgr.disconnect_keep()
connMgr.connect(cfg2)
port = cfg2.getTCPPort()
if port > 0:
print(f"Instance found, port: {port}")
else:
print(f"Instance with ID 'findExistingInstanceExample' not found")
connMgr.disconnect_close(False)
if __name__ == "__main__":
test_findExistingInstance()