Exemple #1
0
        public bool Initialize(PoKeysStepperBoardConfiguration config, int?pokeysIndex)
        {
            if (Initialized)
            {
                return(false);
            }

            if (poKeysDevice == null)
            {
                if (!pokeysIndex.HasValue)
                {
                    return(false);
                }

                poKeysDevice = PoKeysEnumerator.Singleton.PoKeysDevice;

                if (!poKeysDevice.ConnectToDevice(pokeysIndex.Value))
                {
                    Error = Translations.Main.PokeysConnectError;
                    return(false);
                }
            }

            // Configure the positioning device...
            poKeysDevice.PEv2_GetStatus(ref PE);
            for (int i = 0; i < 8; i++)
            {
                PE.param1 = (byte)i;
                poKeysDevice.PEv2_GetAxisConfiguration(ref PE);
            }

            UpdateConfiguration(config);

            //
            // Change Pulse Engine State to RUNNING
            //
            PE.PulseEngineStateSetup = (byte)ePoKeysPEState.peRUNNING;
            poKeysDevice.PEv2_SetState(ref PE);

            //
            // Get Pulse Engine Statue and Check to confirm we are RUNNING
            //
            poKeysDevice.PEv2_GetStatus(ref PE);
            StepperRunning = (PE.PulseEngineState == (byte)ePoKeysPEState.peRUNNING);

            Initialized = true;

            if (posThread == null)
            {
                posThread = new Thread(new ThreadStart(StepperPositioningThreadStub));
                posThread.Start();
            }

            return(true);
        }