An American airline pilot who was caught carrying a high voltage stun gun in his luggage at Edinburgh Airport has escaped a jail sentence.