コード例 #1
0
 public InputServer(ILog log, IInputController inputController)
 {
     this.log             = log;
     this.inputController = inputController;
     server = new OscServer(TransportType.Udp, IPAddress.Any, DEFAULT_VIP_PORT);
     server.RegisterMethod(JOYPAD_BUTTON_EVENT);
     server.RegisterMethod(MOUSE_EVENT);
     server.RegisterMethod(SCROLL_EVENT);
     server.RegisterMethod(KEYBOARD_EVENT);
     server.RegisterMethod(VOLUME_EVENT);
     server.MessageReceived += new OscMessageReceivedHandler(server_MessageReceived);
     server.Start();
     log.Log(LogLevel.Info, "Starting Input Server");
 }
コード例 #2
0
        public void Initialise()
        {
            var server = new OscServer(TransportType.Udp, IPAddress.Loopback, Convert.ToInt32(ConfigurationManager.AppSettings["ListenOnPort"]));

            server.RegisterMethod("/");
            server.MessageReceived += MessageReceived;
            server.Start();
        }
コード例 #3
0
ファイル: Program.cs プロジェクト: ImfeldC/NuvoControl2
        public static void Main(string[] args)
        {
            OscServer oscServer;
            DemoType  demoType = GetDemoType();
            //IPAddress ipAddress = IPAddress.Loopback;
            //IPAddress ipAddress = IPAddress.Parse("192.168.1.118");
            IPAddress ipAddress = IPAddress.Parse(Properties.Settings.Default.IPAddress);

            switch (demoType)
            {
            case DemoType.Udp:
                oscServer = new OscServer(TransportType.Udp, ipAddress, Properties.Settings.Default.Port);
                break;

            case DemoType.Tcp:
                oscServer = new OscServer(TransportType.Tcp, ipAddress, Properties.Settings.Default.Port);
                break;

            case DemoType.Multicast:
                oscServer = new OscServer(IPAddress.Parse("224.25.26.27"), Properties.Settings.Default.Port);
                break;

            default:
                throw new Exception("Unsupported receiver type.");
            }

            oscServer.FilterRegisteredMethods = false;
            oscServer.RegisterMethod(AliveMethod);
            oscServer.RegisterMethod(TestMethod);
            oscServer.RegisterMethod(PingMethod);       // used by TouchOSC
            oscServer.BundleReceived          += new EventHandler <OscBundleReceivedEventArgs>(oscServer_BundleReceived);
            oscServer.MessageReceived         += new EventHandler <OscMessageReceivedEventArgs>(oscServer_MessageReceived);
            oscServer.ReceiveErrored          += new EventHandler <ExceptionEventArgs>(oscServer_ReceiveErrored);
            oscServer.ConsumeParsingExceptions = false;

            oscServer.Start();

            Console.WriteLine("Osc Receiver: " + demoType.ToString());
            Console.WriteLine("with IP Address={0} on Port={1}", ipAddress, Properties.Settings.Default.Port);
            Console.WriteLine("Press any key to exit.");
            Console.ReadKey();
            oscServer.Stop();
        }
コード例 #4
0
        public static void Main(string[] args)
        {
            OscServer oscServer;
            DemoType  demoType = GetDemoType();

            switch (demoType)
            {
            case DemoType.Udp:
                oscServer = new OscServer(TransportType.Udp, IPAddress.Loopback, Port);
                break;

            case DemoType.Tcp:
                oscServer = new OscServer(TransportType.Tcp, IPAddress.Loopback, Port);
                break;

            case DemoType.Multicast:
                oscServer = new OscServer(IPAddress.Parse("224.25.26.27"), Port);
                break;

            default:
                throw new Exception("Unsupported receiver type.");
            }

            oscServer.FilterRegisteredMethods = false;
            oscServer.RegisterMethod(AliveMethod);
            oscServer.RegisterMethod(TestMethod);
            oscServer.BundleReceived          += new EventHandler <OscBundleReceivedEventArgs>(oscServer_BundleReceived);
            oscServer.MessageReceived         += new EventHandler <OscMessageReceivedEventArgs>(oscServer_MessageReceived);
            oscServer.ReceiveErrored          += new EventHandler <ExceptionEventArgs>(oscServer_ReceiveErrored);
            oscServer.ConsumeParsingExceptions = false;

            oscServer.Start();

            Console.WriteLine("Osc Receiver: " + demoType.ToString());
            Console.WriteLine("Press any key to exit.");
            Console.ReadKey();
            oscServer.Stop();
        }
コード例 #5
0
        public static void Main(string[] args)
        {
            OscServer oscServer;
            DemoType  demoType = /*GetDemoType();*/ DemoType.Udp;

            switch (demoType)
            {
            case DemoType.Udp:
                oscServer = new OscServer(TransportType.Udp, IPAddress.Any, Port);
                break;

            case DemoType.Tcp:
                oscServer = new OscServer(TransportType.Tcp, IPAddress.Loopback, Port);
                break;

            case DemoType.Multicast:
                oscServer = new OscServer(IPAddress.Parse("224.25.26.27"), Port);
                break;

            default:
                throw new Exception("Unsupported receiver type.");
            }

            oscServer.FilterRegisteredMethods = false;
            oscServer.RegisterMethod(AliveMethod);
            oscServer.RegisterMethod(TestMethod);
            oscServer.RegisterMethod(MouseMethod);
            oscServer.BundleReceived          += new EventHandler <OscBundleReceivedEventArgs>(oscServer_BundleReceived);
            oscServer.MessageReceived         += new EventHandler <OscMessageReceivedEventArgs>(oscServer_MessageReceived);
            oscServer.ReceiveErrored          += new EventHandler <ExceptionEventArgs>(oscServer_ReceiveErrored);
            oscServer.ConsumeParsingExceptions = false;

            handsets = new VirtualHandset[HANDSET_COUNT];
            motorMin = new int[HANDSET_COUNT];
            motorMax = new int[HANDSET_COUNT];

            String[] comPorts = { "COM9", "COM4", "COM5", "COM6", "COM7", "COM8" };
            for (int i = 0; i < HANDSET_COUNT; i++)
            {
                VirtualHandset handset = new VirtualHandset();
                int            result  = handset.Connect(comPorts[i]);
                if (result != 0)
                {
                    // -20 = virtual com port device not found (USB unplugged)
                    // -30 = com port found but couldn't connect to hardware
                    Console.WriteLine("error " + result + " opening " + comPorts[i]);
                    continue;
                }

                VirtualHandset.ControlUnitSettings settings = new VirtualHandset.ControlUnitSettings();
                result = handset.GetAllSettings(ref settings);
                if (result == 0)
                {
                    Console.Write(comPorts[i] + ": OEM Information: " + (char)settings.OEMInformation[0] + " " + (char)settings.OEMInformation[1] +
                                  " " + (char)settings.OEMInformation[2] + " " + (char)settings.OEMInformation[3] + " (" + (settings.OEMInformation.Length - 4) + " more) ");
                }
                else
                {
                    Console.WriteLine("error " + result + " getting control unit settings for " + comPorts[i]);
                    continue;
                }

                int handsetIndex = 0;
                if ((char)settings.OEMInformation[0] == 'L')
                {
                    handsetIndex = 0;
                }
                else if ((char)settings.OEMInformation[0] == 'R')
                {
                    handsetIndex = 3;
                }
                else
                {
                    Console.WriteLine(comPorts[i] + ": invalid OEMInformation[0] '" + (char)settings.OEMInformation[0] + "' (should be 'L' or 'R')");
                    continue;
                }

                if ((char)settings.OEMInformation[1] == '1')
                {
                    handsetIndex += 0;
                }
                else if ((char)settings.OEMInformation[1] == '2')
                {
                    handsetIndex += 1;
                }
                else if ((char)settings.OEMInformation[1] == '3')
                {
                    handsetIndex += 2;
                }
                else
                {
                    Console.WriteLine(comPorts[i] + ": invalid OEMInformation[1] '" + (char)settings.OEMInformation[1] + "' (should be '1', '2' or '3')");
                    continue;
                }

                handsets[handsetIndex] = handset;
                motorMin[handsetIndex] = settings.LowerLimit[0] + 1; // don't drive right to the very limit
                motorMax[handsetIndex] = settings.UpperLimit[0] - 1; // don't drive right to the very limit
                Console.WriteLine(" lower " + motorMin[handsetIndex] + " upper " + motorMax[handsetIndex]);
                Console.WriteLine("  -> assigning handset to index " + handsetIndex);

                // add event-handler for synchronizing the PC after driving
                //handsets[handsetIndex].OnSynchronizeAfterDriving += new VirtualHandset.OnSynchronizeAfterDrivingDelegate(onSynchronizeAfterDriving);
            }

            for (int i = 0; i < HANDSET_COUNT; i++)
            {
                if (handsets[i] == null)
                {
                    Console.WriteLine("handset " + i + " missing, filling in with dummy");
                    handsets[i] = new VirtualHandset();
                }
                // moveMotorToPosition(i, INITIAL_POS);
            }

            oscServer.Start();

            // figure out my ip address
            IPHostEntry host;
            string      localIP = "?";

            host = Dns.GetHostEntry(Dns.GetHostName());
            foreach (IPAddress ip in host.AddressList)
            {
                if (ip.AddressFamily.ToString() == "InterNetwork")
                {
                    localIP = ip.ToString();
                }
            }
            Console.WriteLine("Osc Receiver: " + demoType.ToString() + " listening on address " + localIP + " port " + Port);
            Console.WriteLine("Press any key to exit.");
            Console.ReadKey();

            oscServer.Stop();

            for (int i = 0; i < HANDSET_COUNT; i++)
            {
                if (handsets[i] == null)
                {
                    continue;
                }
                handsets[i].Disconnect();
                handsets[i].Dispose();
            }
        }
コード例 #6
0
        public static Boolean Initialize()
        {
            try
            {
                if (!m_boolInitialized && !m_boolInitError)
                {
                    // Check if Muse-IO is running

                    // Launch Muse-IO
                    String musePath = "";
                    if (File.Exists(@"C:\Program Files (x86)\Muse\muse-io.exe"))
                    {
                        musePath = @"C:\Program Files (x86)\Muse\muse-io.exe";
                    }
                    else if (File.Exists(@"C:\Program Files\Muse\muse-io.exe"))
                    {
                        musePath = @"C:\Program Files\Muse\muse-io.exe";
                    }
                    else
                    {
                        if (MessageBox.Show("Could not find Muse-IO. Would you like to install it?", "Install Muse SDK", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1) == DialogResult.Yes)
                        {
                            System.Diagnostics.Process.Start("http://storage.googleapis.com/musesdk/musesdk-2.4.2-windows-installer.exe");
                        }
                        else
                        {
                            MessageBox.Show("You can manually launch Muse-IO with this command: \r\nmuse-io --preset 14 --device Muse --osc osc.tcp://localhost:5000", "Muse IO Command Line", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1);
                        }
                    }

                    if (musePath != "")
                    {
                        museIO = Process.Start(musePath, "muse-io --preset 14 --osc osc.tcp://localhost:5000");
                    }

                    oscServer = new OscServer(TransportType.Tcp, IPAddress.Loopback, 5000);

                    oscServer.FilterRegisteredMethods = false;
                    oscServer.RegisterMethod(AliveMethod);
                    oscServer.RegisterMethod(TestMethod);
                    oscServer.BundleReceived          += oscServer_BundleReceived;
                    oscServer.MessageReceived         += oscServer_MessageReceived;
                    oscServer.ConsumeParsingExceptions = false;

                    oscServer.Start();

                    m_boolInitialized = true;
                    return(true);
                }

                if (m_boolInitialized)
                {
                    return(true);
                }
            }
            catch (Exception ex)
            {
                m_boolInitError = true;
                throw (new Exception("The 'Muse' plugin failed to initialize: " + ex.Message));
            }
            return(false);
        }