I found the solution to this, i'll keep the question just because it can be useful for someone in need of the same function since i found no other thread with a proper solution about this topic.
The function to use is quite hidden in the documentation and is:
it is incredibly good since it also manages the inport/ouport connection by itself