Excitation of an electromagnetic field by an electron beam traveling close to a diffraction grating