Synchronising a generator for connection to a network or to another generator