public static double Get_Data(Int32 filter_coeff, decimal offset_calib) { //bool error_flag = false; Int32 EXPECTED_BLOCK_SIZE = 0; if (filter_coeff >= 1) { EXPECTED_BLOCK_SIZE = filter_coeff * 3; } else { EXPECTED_BLOCK_SIZE = 1; string string_error = " Filter coefficient error: " + Convert.ToString(filter_coeff + "/nFilter coefficient set to" + Convert.ToString(EXPECTED_BLOCK_SIZE)); yazici.durum_yazici(string_error); } //EXPECTED_BLOCK_SIZE = filter_coeff*3; // sensör bir sebepten 3 veri gönderiyor, birisi ölçüm değeri, diğerleri sıfır, o yüzden 3 le çarpıyoruz. int[] raw_Data = new int[EXPECTED_BLOCK_SIZE]; //int rawData[EXPECTED_BLOCK_SIZE]; double[] scaled_Data = new double[EXPECTED_BLOCK_SIZE]; double measured_data = 0; for (int i = 0; i < raw_Data.Length; i++) { raw_Data[i] = 9; scaled_Data[i] = 9; } // Sleep 10ms, allow other things to happen, .... bool bDone = false; int try_counter = 0; MEDAQLib.ERR_CODE Ret = MEDAQLib.ERR_CODE.ERR_NOERROR; while ((!bDone) && (try_counter < 30000)) { Thread.Sleep(1); try_counter++; // Check whether there's enough data to read in. int currentlyAvailable = 0; Ret = MEDAQLib.DataAvail(iSensor, ref currentlyAvailable); Int32 expectedBlockSize = EXPECTED_BLOCK_SIZE; //double[] scaled_Data_trash = new double[currentlyAvailable]; //int[] raw_Data_trash = new int[currentlyAvailable]; //int counter_2 = 0; // 10 defa ölçüm alacağız ve bekleyeceğiz. Yoksa ölçümler hatalı geliyor. //while (counter_2 < 2) //{ //counter_2++; //Thread.Sleep(5); if (currentlyAvailable > EXPECTED_BLOCK_SIZE) { bDone = false; Ret = MEDAQLib.Poll(iSensor, raw_Data, scaled_Data, expectedBlockSize); if (Ret == MEDAQLib.ERR_CODE.ERR_NOERROR) { bDone = true; } } //} } //Console.WriteLine("Raw Data:"); //Array.ForEach(raw_Data, x => Console.WriteLine(x)); measured_data = scaled_Data.Sum(); measured_data = (measured_data / (EXPECTED_BLOCK_SIZE / 3)); if ((Convert.ToDecimal(measured_data) > Properties.Settings.Default.maxthickness) || (Convert.ToDecimal(measured_data) < Properties.Settings.Default.minthickness)) { measured_data = 0; } //Console.WriteLine("Scaled Data:"); //Array.ForEach(scaled_Data, x => Console.WriteLine(x)); //Console.WriteLine(Convert.ToString(Ret)); measured_data = measured_data + Convert.ToDouble(offset_calib); return(measured_data); }