Fix wrong getLast function

Better cmake, add include guards on stateExtendedReader
Moved the opening of the port in the attach function so that subdevice is fully initialized when they opens