private static void SerialPortLepton_DataReceived(object sender, SerialDataReceivedEventArgs e) { Console.WriteLine("\n data received open" + Environment.NewLine); var serialPort = (SerialPort)sender; try { var request = serialPort.ReadLine(); } catch (Exception ex) { Console.WriteLine(ex.Message); } serialPort.Close(); double max, min, mean; var devices = Lepton.CCI.GetDevices(); CCI.Rad.Enable radState = CCI.Rad.Enable.ENABLE; CCI.Rad.Enable TLinerState = CCI.Rad.Enable.ENABLE; if (devices.Count == 0) { Console.WriteLine("no Lepton CCI Devices..."); restartFunc(); } else { var device = devices[0]; var CCIHandle0 = device.Open(); try { if (CCIHandle0.rad.GetEnableState() != radState) { CCIHandle0.rad.SetEnableState(radState); } Task.Delay(100); if (CCIHandle0.rad.GetTLinearEnableState() != TLinerState) { CCIHandle0.rad.SetTLinearEnableState(TLinerState); } //------------------------------ var videoRoi = CCIHandle0.sys.GetSceneRoi(); videoRoi.startCol = 39; videoRoi.endCol = 41; videoRoi.startRow = 29; videoRoi.endRow = 31; CCIHandle0.sys.SetSceneRoi(videoRoi); var histogram = CCIHandle0.agc.GetHistogramStatistics(); max = histogram.maxIntensity; min = histogram.minIntensity; mean = histogram.meanIntensity; Console.WriteLine("max = {0} min = {1} mean = {2} \n", max, min, mean); //string strSend = string.Format("{0}:{1}", min, max); //string strSendPoint = string.Format("{0}:{1}:{2}", min, max, meanPoint); //------------------------------ #region old /* * * var histogram = CCIHandle0.agc.GetHistogramStatistics(); * var leptonFPA = CCIHandle0.sys.GetFpaTemperatureCelsius(); * * if (CCIHandle0.rad.GetEnableState() != radState) * CCIHandle0.rad.SetEnableState(radState); * * * var xMax = histogram.maxIntensity; * var xMin = histogram.minIntensity; * var xMean = histogram.meanIntensity; * * //temp = lepton_raw * b1 + c1 + fpa * fpa * d1 + e1 * fpa * * var coefPT_Celsius = (coefPT[8] - (coefPT[1] + leptonFPA * leptonFPA * coefPT[2] + leptonFPA * coefPT[3]) ) / coefPT[0]; * * * * if (xMax > coefPT_Celsius) * max = xMax * coefPT[0] + coefPT[1] + leptonFPA * leptonFPA * coefPT[2] + leptonFPA * coefPT[3]; * else * max = xMax * coefPT[4] + coefPT[5] + leptonFPA * leptonFPA * coefPT[6] + leptonFPA * coefPT[7]; * * * if (xMin > coefPT_Celsius) * min = xMin * coefPT[0] + coefPT[1] + leptonFPA * leptonFPA * coefPT[2] + leptonFPA * coefPT[3]; * else * min = xMin * coefPT[4] + coefPT[5] + leptonFPA * leptonFPA * coefPT[6] + leptonFPA * coefPT[7]; * */ #endregion //Console.WriteLine("max = {0} min = {1} mean = {2} fpa = {3}", max, min, xMean, leptonFPA); //string strSendPoint = string.Format("{0:0.#}:{1:0.#}:{2:0.#}\n", min, max, xMean); string strSendPoint = string.Format("{0:0.#}:{1:0.#}\n", min, max); serialPort.Open(); if (serialPort.IsOpen) { serialPort.WriteLine(strSendPoint); } } catch (Exception ex) { Console.WriteLine(ex.Message); } } }
//private async Task SpeechRecognize() //{ //} private static void TemperatureResponce(SerialPort serialPort) { serialPort.Close(); double max, min; var devices = Lepton.CCI.GetDevices(); CCI.Rad.Enable radState = CCI.Rad.Enable.ENABLE; if (devices.Count == 0) { Console.WriteLine("no Lepton CCI Devices..."); restartFunc(); } else { var device = devices[0]; var CCIHandle0 = device.Open(); try { if (CCIHandle0.rad.GetEnableState() != radState) { CCIHandle0.rad.SetEnableState(radState); } var histogram = CCIHandle0.agc.GetHistogramStatistics(); var leptonFPA = CCIHandle0.sys.GetFpaTemperatureCelsius(); if (CCIHandle0.rad.GetEnableState() != radState) { CCIHandle0.rad.SetEnableState(radState); } var xMax = histogram.maxIntensity; var xMin = histogram.minIntensity; var xMean = histogram.meanIntensity; //temp = lepton_raw * b1 + c1 + fpa * fpa * d1 + e1 * fpa var coefPT_Celsius = (coefPT[8] - (coefPT[1] + leptonFPA * leptonFPA * coefPT[2] + leptonFPA * coefPT[3])) / coefPT[0]; if (xMax > coefPT_Celsius) { max = xMax * coefPT[0] + coefPT[1] + leptonFPA * leptonFPA * coefPT[2] + leptonFPA * coefPT[3]; } else { max = xMax * coefPT[4] + coefPT[5] + leptonFPA * leptonFPA * coefPT[6] + leptonFPA * coefPT[7]; } if (xMin > coefPT_Celsius) { min = xMin * coefPT[0] + coefPT[1] + leptonFPA * leptonFPA * coefPT[2] + leptonFPA * coefPT[3]; } else { min = xMin * coefPT[4] + coefPT[5] + leptonFPA * leptonFPA * coefPT[6] + leptonFPA * coefPT[7]; } Console.WriteLine("max = {0} min = {1} mean = {2} fpa = {3}", max, min, xMean, leptonFPA); string strSendPoint = string.Format("{0:0.#}:{1:0.#}:{2:0.#} temperature\n", min, max, xMean); serialPort.Open(); if (serialPort.IsOpen) { serialPort.WriteLine(strSendPoint); } } catch (Exception ex) { Console.WriteLine(ex.Message); } } }