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(); } }
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(); } } }