Esempio n. 1
0
        /// <summary>
        /// event-handler that is called when the PC should be synchronized after driving
        /// </summary>
        private void OnSynchronizeAfterDriving()
        {
            // INFO: you can upload the current control-unit settings here
            //       to get the driving statistics, positions, etc.

            VirtualHandset.ControlUnitSettings Settings = new VirtualHandset.ControlUnitSettings();

            // get all settings from the control-unit and check for error
            if (Handset.GetAllSettings(ref Settings) < 0)
            {
                MessageBox.Show("Could not get settings!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }

            // inform the virtual handset that we have finished synchronizing our data
            // NOTE: if you do not upload data, you do not need to call this function.
            Handset.SynchronizeAfterDrivingFinished();
        }
Esempio n. 2
0
        private void btnGetAllSettings_Click(object sender, EventArgs e)
        {
            this.Enabled = false;

            VirtualHandset.ControlUnitSettings Settings = new VirtualHandset.ControlUnitSettings();

            // get all settings from the control-unit and check for error
            if (Handset.GetAllSettings(ref Settings) < 0)
            {
                MessageBox.Show("Could not get settings!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }

            // NOTE: use the "watch" feature to examine the information in the Settings-variable.
            //       plenty of information can be read from there.
            // TO BE ADDED: process the settings and display information.

            this.Enabled = true;
        }
Esempio n. 3
0
        /// <summary>
        /// event-handler that is called when the PC should be synchronized after driving
        /// </summary>
        private void OnSynchronizeAfterDriving()
        {
            // INFO: you can upload the current control-unit settings here
            //       to get the driving statistics, positions, etc.

            VirtualHandset.ControlUnitSettings Settings = new VirtualHandset.ControlUnitSettings();

            // get all settings from the control-unit and check for error
            if (Handset.GetAllSettings(ref Settings) < 0)
            {
                MessageBox.Show("Could not get settings!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }

            // inform the virtual handset that we have finished synchronizing our data
            // NOTE: if you do not upload data, you do not need to call this function.
            Handset.SynchronizeAfterDrivingFinished();
        }
Esempio n. 4
0
        private void btnGetAllSettings_Click(object sender, EventArgs e)
        {
            this.Enabled = false;

            VirtualHandset.ControlUnitSettings Settings = new VirtualHandset.ControlUnitSettings();

            // get all settings from the control-unit and check for error
            if (Handset.GetAllSettings(ref Settings) < 0)
            {
                MessageBox.Show("Could not get settings!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }

            // NOTE: use the "watch" feature to examine the information in the Settings-variable.
            //       plenty of information can be read from there.
            // TO BE ADDED: process the settings and display information.

            this.Enabled = true;
        }
Esempio n. 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();
            }
        }
Esempio n. 6
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();
            }

		}