Пример #1
0
        // Display the timestamp
        static void DisplayTimestamp(byte[] abyTimestamp)
        {
            double dShutterOpen = 0, dShutterClose = 0;
            uint   uiProfileCount = 0;

            //Decode the timestamp
            CLLTI.Timestamp2TimeAndCount(abyTimestamp, ref dShutterOpen, ref dShutterClose, ref uiProfileCount);
            ReadLog("ShutterOpen: " + dShutterOpen + " ShutterClose: " + dShutterClose);
            ReadLog("ProfileCount: " + uiProfileCount);
        }
Пример #2
0
        // Display the error text
        static void OnError(string strErrorTxt, int iErrorValue)
        {
            byte[] acErrorString = new byte[200];

            ReadLog(strErrorTxt);
            if (CLLTI.TranslateErrorValue(hLLT, iErrorValue, acErrorString, acErrorString.GetLength(0))
                >= CLLTI.GENERAL_FUNCTION_OK)
            {
                ReadLog(System.Text.Encoding.ASCII.GetString(acErrorString, 0, acErrorString.GetLength(0)));
            }
        }
Пример #3
0
        private void textBox1_LostFocus(object sender, EventArgs e)
        {
            if (!String.IsNullOrEmpty(textBox1.Text))
            {
                try
                {
                    string str = textBox1.Text;
                    uiExposureTimeTmp = Convert.ToDouble(str);
                    uiExposureTime    = Convert.ToUInt32(uiExposureTimeTmp * 100);
                }
                catch
                {
                    richTextBox1.AppendText("\n输入错误\n");
                    return;
                }
                if (uiExposureTimeTmp < 0.01)
                {
                    richTextBox1.AppendText("\n输入错误\n");
                    uiExposureTimeTmp = 0;
                    return;
                }
                if (button1.Text == "断开传感器")
                {
                    ReadLog("Set exposure time to " + uiExposureTimeTmp + "ms");
                    if ((iRetValue = CLLTI.SetFeature(hLLT, CLLTI.FEATURE_FUNCTION_EXPOSURE_TIME, uiExposureTime)) < CLLTI.GENERAL_FUNCTION_OK)
                    {
                        OnError("Error during SetFeature(FEATURE_FUNCTION_EXPOSURE_TIME)", iRetValue);
                        bOK = false;
                    }
                }


                Properties.Settings.Default.uiExposureTime    = uiExposureTime;
                Properties.Settings.Default.uiExposureTimeTmp = uiExposureTimeTmp;
                Properties.Settings.Default.Save();
            }
        }
Пример #4
0
        static unsafe void scanCONTROL_Sample()
        {
            uint[] auiInterfaces  = new uint[MAX_INTERFACE_COUNT];
            uint[] auiResolutions = new uint[MAX_RESOULUTIONS];

            StringBuilder sbDevName = new StringBuilder(100);
            StringBuilder sbVenName = new StringBuilder(100);

            CLLTI.ProfileReceiveMethod fnProfileReceiveMethod = null;

            uint uiBufferCount = 20, uiMainReflection = 0, uiPacketSize = 1024;

            int iInterfaceCount = 0;


            dataSaveX = new List <double[]>();
            dataSaveZ = new List <double[]>();

            hLLT         = 0;
            uiResolution = 0;

            ReadLog("----- Connect to scanCONTROL -----\n");

            //Create a Ethernet Device -> returns handle to LLT device
            hLLT = CLLTI.CreateLLTDevice(CLLTI.TInterfaceType.INTF_TYPE_ETHERNET);
            if (hLLT != 0)
            {
                ReadLog("CreateLLTDevice OK");
            }
            else
            {
                ReadLog("Error during CreateLLTDevice\n");
            }

            //Gets the available interfaces from the scanCONTROL-device
            iInterfaceCount = CLLTI.GetDeviceInterfacesFast(hLLT, auiInterfaces, auiInterfaces.GetLength(0));
            if (iInterfaceCount <= 0)
            {
                ReadLog("FAST: There is no scanCONTROL connected");
            }
            else if (iInterfaceCount == 1)
            {
                ReadLog("FAST: There is 1 scanCONTROL connected ");
            }
            else
            {
                ReadLog("FAST: There are " + iInterfaceCount + " scanCONTROL's connected");
            }

            if (iInterfaceCount >= 1)
            {
                uint target4 = auiInterfaces[0] & 0x000000FF;
                uint target3 = (auiInterfaces[0] & 0x0000FF00) >> 8;
                uint target2 = (auiInterfaces[0] & 0x00FF0000) >> 16;
                uint target1 = (auiInterfaces[0] & 0xFF000000) >> 24;

                // Set the first IP address detected by GetDeviceInterfacesFast to handle
                ReadLog("Select the device interface: " + target1 + "." + target2 + "." + target3 + "." + target4);
                if ((iRetValue = CLLTI.SetDeviceInterface(hLLT, auiInterfaces[0], 0)) < CLLTI.GENERAL_FUNCTION_OK)
                {
                    OnError("Error during SetDeviceInterface", iRetValue);
                    bOK = false;
                }

                if (bOK)
                {
                    // Connect to sensor with the device interface set before
                    ReadLog("Connecting to scanCONTROL");
                    if ((iRetValue = CLLTI.Connect(hLLT)) < CLLTI.GENERAL_FUNCTION_OK)
                    {
                        OnError("Error during Connect", iRetValue);
                        bOK = false;
                    }
                    else
                    {
                        bConnected = true;
                    }
                }

                if (bOK)
                {
                    ReadLog("\n----- Get scanCONTROL Info -----\n");

                    // Read the device name and vendor from scanner
                    ReadLog("Get Device Name");
                    if ((iRetValue = CLLTI.GetDeviceName(hLLT, sbDevName, sbDevName.Capacity, sbVenName, sbVenName.Capacity)) < CLLTI.GENERAL_FUNCTION_OK)
                    {
                        OnError("Error during GetDevName", iRetValue);
                        bOK = false;
                    }
                    else
                    {
                        ReadLog(" - Devname: " + sbDevName + "\n - Venname: " + sbVenName);
                    }
                }

                if (bOK)
                {
                    // Get the scanCONTROL type and check if it is valid
                    ReadLog("Get scanCONTROL type");
                    if ((iRetValue = CLLTI.GetLLTType(hLLT, ref tscanCONTROLType)) < CLLTI.GENERAL_FUNCTION_OK)
                    {
                        OnError("Error during GetLLTType", iRetValue);
                        bOK = false;
                    }

                    if (iRetValue == CLLTI.GENERAL_FUNCTION_DEVICE_NAME_NOT_SUPPORTED)
                    {
                        ReadLog(" - Can't decode scanCONTROL type. Please contact Micro-Epsilon for a newer version of the LLT.dll.");
                    }

                    if (tscanCONTROLType >= CLLTI.TScannerType.scanCONTROL27xx_25 && tscanCONTROLType <= CLLTI.TScannerType.scanCONTROL27xx_xxx)
                    {
                        ReadLog(" - The scanCONTROL is a scanCONTROL27xx");
                    }
                    else if (tscanCONTROLType >= CLLTI.TScannerType.scanCONTROL25xx_25 && tscanCONTROLType <= CLLTI.TScannerType.scanCONTROL25xx_xxx)
                    {
                        ReadLog(" - The scanCONTROL is a scanCONTROL25xx");
                    }
                    else if (tscanCONTROLType >= CLLTI.TScannerType.scanCONTROL26xx_25 && tscanCONTROLType <= CLLTI.TScannerType.scanCONTROL26xx_xxx)
                    {
                        ReadLog(" - The scanCONTROL is a scanCONTROL26xx");
                    }
                    else if (tscanCONTROLType >= CLLTI.TScannerType.scanCONTROL29xx_25 && tscanCONTROLType <= CLLTI.TScannerType.scanCONTROL29xx_xxx)
                    {
                        ReadLog(" - The scanCONTROL is a scanCONTROL29xx");
                    }
                    else if (tscanCONTROLType >= CLLTI.TScannerType.scanCONTROL30xx_25 && tscanCONTROLType <= CLLTI.TScannerType.scanCONTROL30xx_xxx)
                    {
                        ReadLog(" - The scanCONTROL is a scanCONTROL30xx");
                    }
                    else
                    {
                        ReadLog(" - The scanCONTROL is a undefined type\nPlease contact Micro-Epsilon for a newer SDK");
                    }

                    // Get all possible resolutions for connected sensor and save them in array
                    ReadLog("Get all possible resolutions");
                    if ((iRetValue = CLLTI.GetResolutions(hLLT, auiResolutions, auiResolutions.GetLength(0))) < CLLTI.GENERAL_FUNCTION_OK)
                    {
                        OnError("Error during GetResolutions", iRetValue);
                        bOK = false;
                    }

                    // Set the max. possible resolution
                    uiResolution = auiResolutions[0];
                }

                // Set scanner settings to valid parameters for this example

                if (bOK)
                {
                    ReadLog("\n----- Set scanCONTROL Parameters -----\n");

                    ReadLog("Set resolution to " + uiResolution);
                    if ((iRetValue = CLLTI.SetResolution(hLLT, uiResolution)) < CLLTI.GENERAL_FUNCTION_OK)
                    {
                        OnError("Error during SetResolution", iRetValue);
                        bOK = false;
                    }
                }

                if (bOK)
                {
                    ReadLog("Set BufferCount to " + uiBufferCount);
                    if ((iRetValue = CLLTI.SetBufferCount(hLLT, uiBufferCount)) < CLLTI.GENERAL_FUNCTION_OK)
                    {
                        OnError("Error during SetBufferCount", iRetValue);
                        bOK = false;
                    }
                }

                if (bOK)
                {
                    ReadLog("Set MainReflection to " + uiMainReflection);
                    if ((iRetValue = CLLTI.SetMainReflection(hLLT, uiMainReflection)) < CLLTI.GENERAL_FUNCTION_OK)
                    {
                        OnError("Error during SetMainReflection", iRetValue);
                        bOK = false;
                    }
                }

                if (bOK)
                {
                    ReadLog("Set Packetsize to " + uiPacketSize);
                    if ((iRetValue = CLLTI.SetPacketSize(hLLT, uiPacketSize)) < CLLTI.GENERAL_FUNCTION_OK)
                    {
                        OnError("Error during SetPacketSize", iRetValue);
                        bOK = false;
                    }
                }

                if (bOK)
                {
                    ReadLog("Set Profile config to PROFILE");
                    if ((iRetValue = CLLTI.SetProfileConfig(hLLT, CLLTI.TProfileConfig.PROFILE)) < CLLTI.GENERAL_FUNCTION_OK)
                    {
                        OnError("Error during SetProfileConfig", iRetValue);
                        bOK = false;
                    }
                }
                if (bOK)
                {
                    if ((iRetValue = CLLTI.SetFeature(hLLT, CLLTI.FEATURE_FUNCTION_TRIGGER, CLLTI.TRIG_INTERNAL)) < CLLTI.GENERAL_FUNCTION_OK)
                    {
                        OnError("Error during SetFeature(FEATURE_FUNCTION_TRIGGER)", iRetValue);
                        bOK = false;
                    }
                }
                if (bOK)
                {
                    ReadLog("Set trigger to pos. edge mode");
                    uint Trigger = CLLTI.TRIG_MODE_EDGE | CLLTI.TRIG_POLARITY_HIGH;
                    // Set digital input as trigger input and activate ext. triggering
                    Trigger |= CLLTI.TRIG_INPUT_DIGIN | CLLTI.TRIG_EXT_ACTIVE;
                    // Set trigger settings
                    if ((iRetValue = CLLTI.SetFeature(hLLT, CLLTI.FEATURE_FUNCTION_TRIGGER, Trigger)) < CLLTI.GENERAL_FUNCTION_OK)
                    {
                        OnError("Error during SetFeature(FEATURE_FUNCTION_TRIGGER)", iRetValue);
                        bOK = false;
                    }

                    //ReadLog("Set trigger to internal");
                    //if ((iRetValue = CLLTI.SetFeature(hLLT, CLLTI.FEATURE_FUNCTION_TRIGGER, CLLTI.TRIG_INTERNAL)) < CLLTI.GENERAL_FUNCTION_OK)
                    //{
                    //    OnError("Error during SetFeature(FEATURE_FUNCTION_TRIGGER)", iRetValue);
                    //    bOK = false;
                    //}
                }

                if (bOK)
                {
                    ReadLog("Set exposure time to " + uiExposureTimeTmp + "ms");
                    if ((iRetValue = CLLTI.SetFeature(hLLT, CLLTI.FEATURE_FUNCTION_EXPOSURE_TIME, uiExposureTime)) < CLLTI.GENERAL_FUNCTION_OK)
                    {
                        OnError("Error during SetFeature(FEATURE_FUNCTION_EXPOSURE_TIME)", iRetValue);
                        bOK = false;
                    }
                }

                if (bOK)
                {
                    //ReadLog("Set idle time to " + uiIdleTime / 100 + "ms");
                    if ((iRetValue = CLLTI.SetFeature(hLLT, CLLTI.FEATURE_FUNCTION_IDLE_TIME, uiIdleTime)) < CLLTI.GENERAL_FUNCTION_OK)
                    {
                        OnError("Error during SetFeature(FEATURE_FUNCTION_IDLE_TIME)", iRetValue);
                        bOK = false;
                    }
                }
                if (bOK)
                {
                    Console.WriteLine("Set Profile config to PROFILE");
                    if ((iRetValue = CLLTI.SetProfileConfig(hLLT, CLLTI.TProfileConfig.PROFILE)) < CLLTI.GENERAL_FUNCTION_OK)
                    {
                        OnError("Error during SetProfileConfig", iRetValue);
                        bOK = false;
                    }
                }

                // Setup callback
                if (bOK)
                {
                    ReadLog("\n----- Setup Callback function and event -----\n");

                    ReadLog("Register the callback");
                    // Set the callback function
                    fnProfileReceiveMethod = new CLLTI.ProfileReceiveMethod(ProfileEvent);

                    // Register the callback
                    if ((iRetValue = CLLTI.RegisterCallback(hLLT, CLLTI.TCallbackType.STD_CALL, fnProfileReceiveMethod, hLLT)) < CLLTI.GENERAL_FUNCTION_OK)
                    {
                        OnError("Error during RegisterCallback", iRetValue);
                        bOK = false;
                    }
                }

                // Main tasks in this example
                if (bOK)
                {
                    ReadLog("\n----- Get profiles with Callback from scanCONTROL -----\n");

                    GetProfiles_Callback();
                }
            }
        }
Пример #5
0
        /*
         * Evalute reveived profiles via callback function
         */
        static void GetProfiles_Callback()
        {
            IsOver = false;
            int  iRetValue;
            bool isTimeout;

            double[] adValueX = new double[uiResolution];
            double[] adValueZ = new double[uiResolution];
            double   ROIL     = -100000;
            double   ROIR     = 100000;

            //实时显示图像
            //myModel = new PlotModel { Title = "Display Profiles" };

            myLine.Color = OxyColors.Transparent;
            //myLine.StrokeThickness = 2;
            myLine.MarkerSize = 1;
            //myLine.MarkerStroke = OxyColors.DarkGreen;
            myLine.MarkerFill = OxyColors.Black;
            myLine.MarkerType = MarkerType.Circle;
            myLine1.Color     = OxyColors.Transparent;
            //myLine.StrokeThickness = 2;
            myLine1.MarkerSize = 0.7;
            //myLine.MarkerStroke = OxyColors.DarkGreen;
            myLine1.MarkerFill = OxyColors.Gray;
            myLine1.MarkerType = MarkerType.Circle;

            // Allocate the profile buffer to the maximal profile size times the profile count
            abyProfileBuffer = new byte[uiResolution * 64 * uiNeededProfileCount];
            byte[] abyTimestamp = new byte[16];

            // Start continous profile transmission
            ReadLog("Enable the measurement");
            if ((iRetValue = CLLTI.TransferProfiles(hLLT, CLLTI.TTransferProfileType.NORMAL_TRANSFER, 1)) < CLLTI.GENERAL_FUNCTION_OK)
            {
                OnError("Error during TransferProfiles", iRetValue);
                return;
            }

            // Wait for profile event (or timeout)
            ReadLog("Wait for needed profiles");
            while (!IsOver)
            {
                if (ROIChanged)
                {
                    ROIL = ROIX[0] < ROIX[1] ? ROIX[0] : ROIX[1];
                    ROIR = ROIX[0] > ROIX[1] ? ROIX[0] : ROIX[1];
                    myLine.Points.Clear();
                    myLine1.Points.Clear();
                    if (ROIState < 2)
                    {
                        for (int j = 0; j < adValueX.Length; j++)
                        {
                            myLine.Points.Add(new DataPoint(adValueX[j], adValueZ[j]));
                        }
                    }
                    else
                    {
                        for (int j = 0; j < adValueX.Length; j++)
                        {
                            if (adValueX[j] > ROIL && adValueX[j] < ROIR)
                            {
                                myLine.Points.Add(new DataPoint(adValueX[j], adValueZ[j]));
                            }
                            else
                            {
                                myLine1.Points.Add(new DataPoint(adValueX[j], adValueZ[j]));
                            }
                        }
                    }
                    myModel.InvalidatePlot(true);
                    ROIChanged = false;
                }
                while (!IsOver && !ROIChanged)
                {
                    isTimeout = false;

                    if (hProfileEvent.WaitOne(1) != true)
                    {
                        isTimeout = true;
                    }
                    if (!isTimeout)
                    {
                        // Test the size of profile
                        if (uiProfileDataSize == uiResolution * 64)
                        {
                            ReadLog("Profile size is OK");
                        }
                        else
                        {
                            ReadLog("Profile size is wrong");
                            continue;
                        }

                        // Convert partial profile to x and z values
                        ReadLog("Converting of profile data from the first reflection");
                        iRetValue = CLLTI.ConvertProfile2Values(hLLT, abyProfileBuffer, uiResolution, CLLTI.TProfileConfig.PROFILE, tscanCONTROLType,
                                                                0, 1, null, null, null, adValueX, adValueZ, null, null);
                        if (((iRetValue & CLLTI.CONVERT_X) == 0) || ((iRetValue & CLLTI.CONVERT_Z) == 0))
                        {
                            OnError("Error during Converting of profile data", iRetValue);
                            continue;
                        }

                        dataSaveX.Add(adValueX);
                        dataSaveZ.Add(adValueZ);
                        //// Display x and z values
                        //DisplayProfile(adValueX, adValueZ, uiResolution);

                        // Extract the 16-byte timestamp from the profile buffer into timestamp buffer and display it
                        Buffer.BlockCopy(abyProfileBuffer, 64 * (int)uiResolution - 16, abyTimestamp, 0, 16);
                        DisplayTimestamp(abyTimestamp);
                        uiProfileDataSize      = 0;
                        uiReceivedProfileCount = 0;
                        myLine.Points.Clear();
                        myLine1.Points.Clear();
                        if (ROIState < 2)
                        {
                            for (int j = 0; j < adValueX.Length; j++)
                            {
                                myLine.Points.Add(new DataPoint(adValueX[j], adValueZ[j]));
                            }
                        }
                        else
                        {
                            for (int j = 0; j < adValueX.Length; j++)
                            {
                                if (adValueX[j] > ROIL && adValueX[j] < ROIR)
                                {
                                    myLine.Points.Add(new DataPoint(adValueX[j], adValueZ[j]));
                                }
                                else
                                {
                                    myLine1.Points.Add(new DataPoint(adValueX[j], adValueZ[j]));
                                }
                            }
                        }
                        myModel.InvalidatePlot(true);
                    }
                }
            }
            if (!IsClosed)
            {
                ReadLog("Start data output.");
            }

            using (StreamWriter sw = new StreamWriter("dataTest.txt"))
            {
                for (int i = 0; i < dataSaveX.Count(); i++)
                {
                    for (int j = 0; j < dataSaveX[i].Length; j++)
                    {
                        sw.Write(dataSaveX[i][j].ToString());
                        sw.Write(" " + dataSaveZ[i][j].ToString() + '\n');
                    }
                }
            }
            if (!IsClosed)
            {
                ReadLog("Data output completed.");
            }

            if (bConnected)
            {
                if (IsClosed)
                {
                    if ((iRetValue = CLLTI.TransferProfiles(hLLT, CLLTI.TTransferProfileType.NORMAL_TRANSFER, 0)) < CLLTI.GENERAL_FUNCTION_OK)
                    {
                    }
                    if ((iRetValue = CLLTI.Disconnect(hLLT)) < CLLTI.GENERAL_FUNCTION_OK)
                    {
                    }
                    if ((iRetValue = CLLTI.DelDevice(hLLT)) < CLLTI.GENERAL_FUNCTION_OK)
                    {
                    }
                    bConnected = false;
                }
                else
                {
                    ReadLog("\n----- Disconnect from scanCONTROL -----\n");

                    ReadLog("Disable the measurement");
                    if ((iRetValue = CLLTI.TransferProfiles(hLLT, CLLTI.TTransferProfileType.NORMAL_TRANSFER, 0)) < CLLTI.GENERAL_FUNCTION_OK)
                    {
                        OnError("Error during TransferProfiles", iRetValue);
                    }

                    // Disconnect from the sensor
                    ReadLog("Disconnect the scanCONTROL");
                    if ((iRetValue = CLLTI.Disconnect(hLLT)) < CLLTI.GENERAL_FUNCTION_OK)
                    {
                        OnError("Error during Disconnect", iRetValue);
                    }

                    // Free ressources
                    ReadLog("Delete the scanCONTROL instance");
                    if ((iRetValue = CLLTI.DelDevice(hLLT)) < CLLTI.GENERAL_FUNCTION_OK)
                    {
                        OnError("Error during Delete", iRetValue);
                    }
                    bConnected = false;
                }
            }

            //for (int i = 0; i < dataSaveX.Count(); i++)
            //{
            //    myLine.Points.Clear();
            //    myModel.InvalidatePlot(true);
            //    Thread.Sleep(1000);
            //    for (int j = 0; j < dataSaveX[0].Length; j++)
            //    {

            //        myLine.Points.Add(new DataPoint(dataSaveX[i][j], dataSaveZ[i][j]));

            //    }
            //    myModel.InvalidatePlot(true);

            //    Thread.Sleep(1000);
            //}
            //Thread.Sleep(1000);
            //ReadLog("Test done.");
        }