コード例 #1
0
    //==========================================================================================
    //
    //  Attempts to initialize connection to tracker
    //
    //==========================================================================================
    void AttemptConnection()
    {
        DateTime maxWait = System.DateTime.Now;
        DateTime curTime = System.DateTime.Now;

        maxWait = maxWait.AddSeconds(10.0);

        handle = 0;

        while (maxWait.CompareTo(curTime) > 0 && handle < 1)         //check for tracker for 10 seconds
        {
            handle = ISenseLib.ISD_OpenTracker(IntPtr.Zero, 0, false, true);
            if (handle < 1)
            {
                Sleep(.1f);
            }
            curTime = System.DateTime.Now;
        }

        // Check value of handle to see if tracker was located
        if (handle < 1)
        {
            print("Failed to detect");
            print(handle);
        }
        else
        {
            print("Connected to InterSense tracking device!");
            tracker     = new ISenseLib.ISD_TRACKER_INFO_TYPE();
            stationInfo = new ISenseLib.ISD_STATION_INFO_TYPE[8];
            data        = new ISenseLib.ISD_TRACKING_DATA_TYPE();

            // Get tracker configuration info
            ISenseLib.ISD_GetTrackerConfig(handle, ref tracker, true);
            ISenseLib.ISD_GetStationConfig(handle, ref stationInfo[station - 1], station, true);
            ISenseLib.ISD_SetStationConfig(handle, ref stationInfo[station - 1], station, true);


            trackerModel = (ISenseLib.ISD_SYSTEM_MODEL)tracker.TrackerModel;
            bufferSize   = 180;

            ISenseLib.ISD_RingBufferSetup(handle, station, null, bufferSize);

            ISenseLib.ISD_RingBufferStart(handle, station);
        }
    }
コード例 #2
0
        static void Main(string[] args)
        {
            int handle;

            ISenseLib.ISD_TRACKING_DATA_TYPE  data;
            ISenseLib.ISD_STATION_INFO_TYPE[] Station;
            ISenseLib.ISD_TRACKER_INFO_TYPE   Tracker;
            ISenseLib.ISD_HARDWARE_INFO_TYPE  hwInfo;
            IntPtr handy;
            bool   done        = false;
            int    station     = 1;
            uint   maxStations = 8;
            float  lastTime;

            // Detect first tracker. If you have more than one InterSense device and
            // would like to have a specific tracker, connected to a known port,
            // initialized first, then enter the port number instead of 0. Otherwise,
            // tracker connected to the rs232 port with lower number is found first
            handy = new IntPtr();
            Console.ForegroundColor = ConsoleColor.Cyan;
            Console.Out.WriteLine("Connecting to InterSense tracking device...");
            // handle = ISenseLib.ISD_OpenTracker(IntPtr.Zero, 0, false, true);
            handle = ISenseLib.ISD_OpenAllTrackers(IntPtr.Zero, ref handy, false, true);
            // Check value of handle to see if tracker was located
            if (handle < 1)
            {
                Console.Out.WriteLine("Failed to detect InterSense tracking device");
            }
            else
            {
                Console.Out.WriteLine("Connected; press 'q' to quit, 'e' for enhancement, 'i' to get info\n");

                if (handle > 0)
                {
                    Tracker = new ISenseLib.ISD_TRACKER_INFO_TYPE();
                    hwInfo  = new ISenseLib.ISD_HARDWARE_INFO_TYPE();
                    Station = new ISenseLib.ISD_STATION_INFO_TYPE[8];

                    // Get tracker configuration info
                    ISenseLib.ISD_GetTrackerConfig(handle, ref Tracker, true);

                    if (ISenseLib.ISD_GetSystemHardwareInfo(handle, ref hwInfo))
                    {
                        if (hwInfo.Valid)
                        {
                            maxStations = hwInfo.Cap_MaxStations;
                        }
                    }

                    lastTime = ISenseLib.ISD_GetTime();

                    ISenseLib.ISD_GetStationConfig(handle, ref Station[station - 1], station, true);

                    data = new ISenseLib.ISD_TRACKING_DATA_TYPE();

                    while (!done)
                    {
                        ISenseLib.ISD_GetTrackingData(handle, ref data);

                        if (ISenseLib.ISD_GetTime() - lastTime > 0.02f)
                        {
                            lastTime = ISenseLib.ISD_GetTime();

                            showStationData(handle, Tracker,
                                            Station[station - 1], data.Station[station - 1]);
                        }

                        if (Console.KeyAvailable)
                        {
                            switch (Console.ReadKey(true).KeyChar)
                            {
                            case '1':
                                station = 1;
                                Console.Write("\n>> Current Station is set to {0:d} <<\n", station);
                                break;

                            case '2':
                                if (maxStations > 1)
                                {
                                    station = 2;
                                    Console.Write("\n>> Current Station is set to {0:d} <<\n", station);
                                }
                                break;

                            case '3':
                                if (maxStations > 2)
                                {
                                    station = 3;
                                    Console.Write("\n>> Current Station is set to {0:d} <<\n", station);
                                }
                                break;

                            case '4':
                                if (maxStations > 3)
                                {
                                    station = 4;
                                    Console.Write("\n>> Current Station is set to {0:d} <<\n", station);
                                }
                                break;

                            case '5':
                                if (maxStations > 4)
                                {
                                    station = 5;
                                    Console.Write("\n>> Current Station is set to {0:d} <<\n", station);
                                }
                                break;

                            case '6':
                                if (maxStations > 5)
                                {
                                    station = 6;
                                    Console.Write("\n>> Current Station is set to {0:d} <<\n", station);
                                }
                                break;

                            case '7':
                                if (maxStations > 6)
                                {
                                    station = 7;
                                    Console.Write("\n>> Current Station is set to {0:d} <<\n", station);
                                }
                                break;

                            case '8':
                                if (maxStations > 7)
                                {
                                    station = 8;
                                    Console.Write("\n>> Current Station is set to {0:d} <<\n", station);
                                }
                                break;

                            case 'Q':
                            case 'q':
                                done = true;
                                break;

                            case 'I':
                            case 'i':
                                showTrackerStats(handle, ref hwInfo);
                                break;

                            case 'e':     // Set enhancement; IS-x products only, not for InterTrax
                            case 'E':

                                // First get current station configuration
                                if (ISenseLib.ISD_GetStationConfig(handle,
                                                                   ref Station[station - 1], station, true))
                                {
                                    // Cycle enhancement
                                    Station[station - 1].Enhancement =
                                        (Station[station - 1].Enhancement + 1) % 3;

                                    // Send the new configuration to the tracker
                                    if (ISenseLib.ISD_SetStationConfig(handle,
                                                                       ref Station[station - 1], station, true))
                                    {
                                        // display the results
                                        showTrackerStats(handle, ref hwInfo);
                                    }
                                }
                                break;

                            case 't':
                            case 'T':
                                // First get current station configuration
                                if (ISenseLib.ISD_GetStationConfig(handle,
                                                                   ref Station[station - 1], station, true))
                                {
                                    Station[station - 1].TimeStamped = !(Station[station - 1].TimeStamped);

                                    // Send the new configuration to the tracker
                                    if (ISenseLib.ISD_SetStationConfig(handle,
                                                                       ref Station[station - 1], station, true))
                                    {
                                        // display the results
                                        showTrackerStats(handle, ref hwInfo);
                                    }
                                }

                                break;

                            case 'd':
                            case 'D':
                                showTrackerStats(handle, ref hwInfo);
                                break;

                            case 'p':
                            case 'P':

                                // First get current station configuration
                                if (ISenseLib.ISD_GetStationConfig(handle,
                                                                   ref Station[station - 1], station, true))
                                {
                                    // Cycle enhancement
                                    Station[station - 1].Prediction =
                                        (Station[station - 1].Prediction + 10) % 60;

                                    // Send the new configuration to the tracker
                                    if (ISenseLib.ISD_SetStationConfig(handle,
                                                                       ref Station[station - 1], station, true))
                                    {
                                        // display the results
                                        showTrackerStats(handle, ref hwInfo);
                                    }
                                }
                                break;

                            case 's':
                            case 'S':

                                // First get current station configuration
                                if (ISenseLib.ISD_GetStationConfig(handle,
                                                                   ref Station[station - 1], station, true))
                                {
                                    // Cycle enhancement
                                    Station[station - 1].Sensitivity =
                                        (Station[station - 1].Sensitivity + 1) % 5;

                                    if (Station[station - 1].Sensitivity == 0)
                                    {
                                        Station[station - 1].Sensitivity = 1;
                                    }

                                    // Send the new configuration to the tracker
                                    if (ISenseLib.ISD_SetStationConfig(handle,
                                                                       ref Station[station - 1], station, true))
                                    {
                                        // display the results
                                        showTrackerStats(handle, ref hwInfo);
                                    }
                                }
                                break;

                            case 'c':
                            case 'C':

                                // First get current station configuration
                                if (ISenseLib.ISD_GetStationConfig(handle,
                                                                   ref Station[station - 1], station, true))
                                {
                                    // Cycle enhancement
                                    Station[station - 1].Compass =
                                        (Station[station - 1].Compass + 1) % 3;

                                    // Send the new configuration to the tracker
                                    if (ISenseLib.ISD_SetStationConfig(handle,
                                                                       ref Station[station - 1], station, true))
                                    {
                                        // display the results
                                        showTrackerStats(handle, ref hwInfo);
                                    }
                                }
                                break;
                            }
                        }
                    }

                    ISenseLib.ISD_CloseTracker(handle);
                }
            }
        }