using System; using System.IO.Ports; using System.Windows.Forms; using iTunesLib; namespace iTunesController { class iTunesController { private SerialPort port = new SerialPort("COM1", 9600, Parity.None, 8, StopBits.One); private iTunesAppClass itunes = new iTunesAppClass(); static Form1 form; [STAThread] static void Main(string[] args) { new iTunesController(); } private iTunesController() { form = new Form1(); port.DataReceived += new SerialDataReceivedEventHandler(port_DataReceived); port.Open(); Console.WriteLine("シリアルポートから受信:"); Application.Run(form); } private void port_DataReceived(object sender, SerialDataReceivedEventArgs e) { switch (port.ReadExisting()) { case "p": if ((int)itunes.PlayerState != 1) { itunes.Play(); Console.WriteLine("Play"); } else { itunes.Pause(); Console.WriteLine("Stop"); } break; case "f": itunes.NextTrack(); Console.WriteLine("Next Track"); break; case "b": itunes.PreviousTrack(); Console.WriteLine("Previous Track"); break; case "u": itunes.SoundVolume = itunes.SoundVolume + 10; Console.WriteLine("Volume: " + itunes.SoundVolume.ToString()); break; case "d": itunes.SoundVolume = itunes.SoundVolume - 10; Console.WriteLine("Volume: " + itunes.SoundVolume.ToString()); break; } } } }