A medical device comprising a socket unit for connecting a plug unit and an automated connection of the plug unit to the socket unit via a connecting mechanism. The connecting mechanism has a drive unit that has at least one movable drive body that carries out a translational and/or rotational movement and a position detection mechanism for detecting the linear position and/or the angular position of the drive body. The position detection mechanism includes at least two magnet elements, and at least one sensor element. The linear position and/or angular position of the drive body is determined with an evaluation unit on the basis of the magnetic field generated by the at least two magnet elements and detected by the at least one sensor element.