Exemple #1
0
        /// <summary>
        /// Closes the stage down
        /// </summary>
        /// <param name="args"> argument values for stage</param>
        static void stageclose(Form1 formObject)
        {
            Form1  form1        = formObject;
            string testSerialNo = form1.arg[0];
            // stop polling
            bool ret = false;

            ret = CKCubeDCServo.CC_StopPolling(testSerialNo);
            short retb;

            // close device
            retb = CKCubeDCServo.CC_Close(testSerialNo);
        }
Exemple #2
0
        /// <summary>
        /// Move's stage to the input position
        /// </summary>
        /// <param name="position"> desired position </param>
        /// <param name="testSerialNo"> stage serial number</param>
        /// <param name="formObject"></param>
        internal void StageMove(int position, string testSerialNo, Form1 formObject)
        {
            Form1 form1 = formObject;

            CKCubeDCServo.CC_MoveToPosition(testSerialNo, position);//Move to position
            //read current position and compare to desired position (more detailed explanation see stagepos
            float pos = CKCubeDCServo.CC_GetPosition(testSerialNo);

            while (pos != position)
            {
                Thread.Sleep(1000);
                pos = CKCubeDCServo.CC_GetPosition(testSerialNo);
            }
            form1.TestBox_StagePosition.Text = Convert.ToString(pos / form1.motorFactor);
        }
Exemple #3
0
        /// <summary>
        /// Starts the stage
        /// </summary>
        /// <param name="formObject">the main form</param>
        internal void stagestart(Form1 formObject)
        {
            Form1 form1    = formObject;
            int   velocity = 0;                     //initialises velocity variable

            if (form1.arg.GetLength(0) > 2)         //Checks velocity has been specified in arg
            {
                velocity = int.Parse(form1.arg[2]); //sets velocity to value specified in arg
            }



            if (CKCubeDCServo.TLI_BuildDeviceList() == 0)       // Build list of connected device
            {
                // get device list size
                short n = CKCubeDCServo.TLI_GetDeviceListSize();
                // get TDC serial numbers
                string[] serialNos;
                CKCubeDCServo.TLI_GetDeviceListByTypes(out serialNos, new[] { 27 }, 1);
                // output list of matching devices
                foreach (string serialNo in serialNos)
                {
                    // get device info from device
                    TestStruct s     = new TestStruct();
                    int        iSize = Marshal.SizeOf(typeof(TestStruct));
                    IntPtr     iPtr  = Marshal.AllocHGlobal(iSize);
                    CKCubeDCServo.TLI_GetDeviceInfo(serialNo, iPtr);
                    // get strings from device info structure
                    s = (TestStruct)(Marshal.PtrToStructure(iPtr, typeof(TestStruct)));
                    Marshal.FreeHGlobal(iPtr);
                    string x1 = new string(s.description);
                    x1 = x1.Substring(0, x1.IndexOf('\0'));
                    string x2 = new string(s.serialNo);
                    x2 = x2.Substring(0, x2.IndexOf('\0'));
                    // output
                }
                // if our device exists, test it
                if (serialNos.AsEnumerable().Contains(form1.arg[0]))
                {
                    // open device
                    if (CKCubeDCServo.CC_Open(form1.arg[0]) == 0)
                    {
                        //Console.SetOut(TextWriter.Null);
                        // start the device polling at 200ms intervals
                        CKCubeDCServo.CC_StartPolling(form1.arg[0], 200);
                        //Console.SetIn(TextWriter.Null);

                        float pos = CKCubeDCServo.CC_GetPosition(form1.arg[0]);

                        Thread.Sleep(3000);
                        // Home device
                        CKCubeDCServo.CC_Home(form1.arg[0]);

                        //checks whether stage is in position every second until in place
                        while (pos != 0)
                        {
                            Thread.Sleep(1000);
                            pos = CKCubeDCServo.CC_GetPosition(form1.arg[0]);
                        }
                        form1.TestBox_StagePosition.Text = Convert.ToString(pos / form1.motorFactor);       //outputs position
                        // set velocity if desired
                        if (velocity > 0)
                        {
                            int currentVelocity = 0, currentAcceleration = 0;
                            CKCubeDCServo.CC_GetVelParams(form1.arg[0], ref currentVelocity, ref currentAcceleration);
                            CKCubeDCServo.CC_SetVelParams(form1.arg[0], velocity, currentAcceleration);
                        }
                    }
                }
                else
                {
                    MessageBoxButtons buttons = MessageBoxButtons.OK;
                    DialogResult      result;
                    result = MessageBox.Show("Motor Not Detected. Please connect motor and then retry", "Program will close", buttons);
                    form1.Close();
                }
            }
        }