Example #1
0
        public static ITTLLive2 Get()
        {
            if (disposed)
                throw new Exception("Object is disposed!");

            if (variableCreated)
                return variable;

            variable = CreateVariable();
            variableCreated = true;

            return variable;
        }
Example #2
0
        void SessionThreadStart()
        {
            Monitor.Enter(sessionThread);
            {
                try
                {
                    sessionThreadControl = new Control();
                    sessionThreadControl.CreateControl();

                    session = TtlLiveSingleton.Get();

                    dataTimer = new Timer();
                    dataTimer.Interval = 100;
                    dataTimer.Tick += new EventHandler(dataTimer_Tick);

                    notificationTimer = new Timer();
                    notificationTimer.Interval = 100;
                    notificationTimer.Tick += new EventHandler(notificationTimer_Tick);
                    notificationTimer.Start();
                }
                catch (Exception ex)
                {
                    sessionThreadInitException = ex;
                    TtlLiveSingleton.Dispose();
                }
                Monitor.Pulse(sessionThread);
            }
            Monitor.Exit(sessionThread);

            //Create a message pump for this thread
            Application.Run(applicationContext);

            //Dispose of all stuff on this thread
            dataTimer.Stop();
            dataTimer.Dispose();

            notificationTimer.Stop();
            notificationTimer.Dispose();

            TtlLiveSingleton.Dispose();
            sessionThreadControl.Dispose();

            return;
        }
Example #3
0
        static void ReleaseComInstance(ITTLLive2 session)
        {
            //Release COM object
            //!!Do we have to release instance?

            //Deinitialize COM Library
            Ole32Methods.CoUninitialize();
            return;
        }
Example #4
0
        void StartThread()
        {
            //Initialize COM object
            lock (threadInitialized)
            {
                try
                {
                    session = CreateComInstance();
                    encoder = GetEncoder(session);
                }
                catch (Exception)
                {
                    connectException = true;
                }
                Monitor.Pulse(threadInitialized);

                if (connectException)  //!!Close connections?
                {
                    ReleaseComInstance(session);
                    return;
                }
            }

            //Use thread to gather data from COM object
            DataLoop();

            //!!End channels and queues
            /*
            for (int i = 0; i < channels.Length; i++)
            {

                queues[i].SignalExit();
                queues.

            }*/

            session.CloseConnections();
            ReleaseComInstance(session);
            return;
        }
Example #5
0
        //!!Make sure there are no open channels in the encoder! (drop all channels)
        TTLEncoder GetEncoder(ITTLLive2 session)
        {
            //Open connections to find all encoders connected to computer
            int scanned = 0;
            int detected = 0;
            session.OpenConnections(
                      (int)TTLLiveCtrlLib.TTLAPI_OPENCONNECTIONS_CMD_BITS.TTLAPI_OCCMD_AUTODETECT
                    , 1000
                    , ref scanned
                    , ref detected
                    );
            if (session.EncoderCount <= 0)
            {
                throw new Exception("Could not find any encoders.");
            }

            //Take first encoder
            return session.GetFirstEncoder();
        }