Motors or generators having non-mechanical commutating devices