//check product weight bool _product_weight_is_valid() { bool r = false; if (reworkInformation.PrintMode == "Combine label printing with product weighing") { int count = 0; double ul = double.Parse(product.weight) + double.Parse(product.bias); double ll = double.Parse(product.weight) - double.Parse(product.bias); MyGlobal.testFunctionLogInfo.WEIGHT.Upper_Limit = ul.ToString(); MyGlobal.testFunctionLogInfo.WEIGHT.Lower_Limit = ll.ToString(); MyGlobal.testFunctionLogInfo.WEIGHT.Unit_Of_Measurement = "g"; REP: count++; string weight_string = CAS_EDH.GetWeight(); if (weight_string == null) { if (count < 5) { goto REP; } else { reworkInformation.ErrorMessage += string.Format("Product weight can not is NULL.", weight_string); MyGlobal.testFunctionLogInfo.WEIGHT.Actual_Value = "NULL"; MyGlobal.testFunctionLogInfo.WEIGHT.Result = "FAIL"; MyGlobal.testFunctionLogInfo.Error_Message = reworkInformation.ErrorMessage; return(false); } } double weight_value; if (!double.TryParse(weight_string, out weight_value)) { if (count < 5) { goto REP; } else { reworkInformation.ErrorMessage += string.Format("Product weight {0} is not valid.", weight_string); MyGlobal.testFunctionLogInfo.WEIGHT.Actual_Value = weight_string; MyGlobal.testFunctionLogInfo.WEIGHT.Result = "FAIL"; MyGlobal.testFunctionLogInfo.Error_Message = reworkInformation.ErrorMessage; return(false); } } reworkInformation.WeightActual = weight_value.ToString(); MyGlobal.testFunctionLogInfo.WEIGHT.Actual_Value = reworkInformation.WeightActual; r = weight_value >= ll && weight_value <= ul; if (!r) { if (count < 5) { goto REP; } else { reworkInformation.ErrorMessage += string.Format("Product weight {0} is out of range {1}.", weight_string, reworkInformation.WeightLimit); MyGlobal.testFunctionLogInfo.WEIGHT.Result = "FAIL"; MyGlobal.testFunctionLogInfo.Error_Message = reworkInformation.ErrorMessage; return(false); } } else { MyGlobal.testFunctionLogInfo.WEIGHT.Result = "PASS"; MyGlobal.testFunctionLogInfo.Error_Message = reworkInformation.ErrorMessage; return(true); } } else { return(true); } }
//check product weight bool _product_weight_is_valid() { bool r = false; if (MyGlobal.MyTesting.UseScaleFlag == true) { int count = 0; double ul = double.Parse(MyGlobal.MySetting.WeightUL); double ll = double.Parse(MyGlobal.MySetting.WeightLL); MyGlobal.testFunctionLogInfo.WEIGHT.Upper_Limit = MyGlobal.MySetting.WeightUL; MyGlobal.testFunctionLogInfo.WEIGHT.Lower_Limit = MyGlobal.MySetting.WeightLL; MyGlobal.testFunctionLogInfo.WEIGHT.Unit_Of_Measurement = "g"; REP: count++; string weight_string = CAS_EDH.GetWeight(); if (weight_string == null) { if (count < 5) { goto REP; } else { MyGlobal.MyTesting.ErrorMessage += string.Format("Product weight can not is NULL.", weight_string); MyGlobal.testFunctionLogInfo.WEIGHT.Actual_Value = "NULL"; MyGlobal.testFunctionLogInfo.WEIGHT.Result = "FAIL"; MyGlobal.testFunctionLogInfo.Error_Message = MyGlobal.MyTesting.ErrorMessage; return(false); } } double weight_value; if (!double.TryParse(weight_string, out weight_value)) { if (count < 5) { goto REP; } else { MyGlobal.MyTesting.ErrorMessage += string.Format("Product weight {0} is not valid.", weight_string); MyGlobal.testFunctionLogInfo.WEIGHT.Actual_Value = weight_string; MyGlobal.testFunctionLogInfo.WEIGHT.Result = "FAIL"; MyGlobal.testFunctionLogInfo.Error_Message = MyGlobal.MyTesting.ErrorMessage; return(false); } } MyGlobal.MyTesting.WeightActual = weight_value.ToString(); MyGlobal.testFunctionLogInfo.WEIGHT.Actual_Value = MyGlobal.MyTesting.WeightActual; r = weight_value >= ll && weight_value <= ul; if (!r) { if (count < 5) { goto REP; } else { MyGlobal.MyTesting.ErrorMessage += string.Format("Product weight {0} is out of range {1}.", weight_string, MyGlobal.MyTesting.WeightStandard); MyGlobal.testFunctionLogInfo.WEIGHT.Result = "FAIL"; MyGlobal.testFunctionLogInfo.Error_Message = MyGlobal.MyTesting.ErrorMessage; return(false); } } else { MyGlobal.testFunctionLogInfo.WEIGHT.Result = "PASS"; MyGlobal.testFunctionLogInfo.Error_Message = MyGlobal.MyTesting.ErrorMessage; return(true); } } else { return(true); } }
private void Button_Click(object sender, RoutedEventArgs e) { Button b = sender as Button; switch (b.Content) { case "Go": { if (cbb_logtype.SelectedValue != null) { string text = cbb_logtype.SelectedValue.ToString(); string logpath = ""; string dir = string.Format(@"{0}\{1}\{2}\{3}", MyGlobal.MySetting.DirLog, MyGlobal.MySetting.ProductName, MyGlobal.MySetting.StationName, MyGlobal.MySetting.JigIndex ); switch (text) { case "LogTotal": { logpath = System.IO.Path.Combine(dir, "LogTotal"); break; } case "LogSingle": { logpath = System.IO.Path.Combine(dir, "LogSingle"); break; } case "LogDetail": { logpath = System.IO.Path.Combine(dir, "LogDetail"); break; } case "Default": { logpath = AppDomain.CurrentDomain.BaseDirectory; break; } default: { logpath = AppDomain.CurrentDomain.BaseDirectory; break; } } if (System.IO.Directory.Exists(logpath)) { Process.Start(logpath); } else { MessageBox.Show(string.Format("path {0} is not exist.", logpath), "Error", MessageBoxButton.OK, MessageBoxImage.Error); } } else { MessageBox.Show("Please select a log type.", "Error", MessageBoxButton.OK, MessageBoxImage.Error); } break; } case "Start Calib": { lbl_avr.Content = "--"; btn_startcalib.IsEnabled = false; btn_stopcalib.IsEnabled = true; MyGlobal.calibWeightGridItem.Clear(); _calibInfo.WeightData = ""; int count = 0, max_count = 1; bool r = int.TryParse(txt_CalibQty.Text, out max_count); max_count = r == true ? max_count : 100; calib_thread = new Thread(new ThreadStart(() => { while (count < max_count) { string data = "", w = "0"; //cho den khi can on dinh va gia tri > 100g try { while (!(data.Contains("ST") == true && double.Parse(w) > 100)) { data = CAS_EDH.GetDataFromScale(); _calibInfo.WeightData += data + "\r\n"; if (data != null) { w = CAS_EDH.GetWeightFromScaleString(data); } } } catch { //Dispatcher.Invoke(new Action(() => { // btn_startcalib.IsEnabled = true; // btn_stopcalib.IsEnabled = false; //})); //return; continue; } //get weight Dispatcher.Invoke(new Action(() => { MyGlobal.calibWeightGridItem.Add(new MyFunction.Implement.calib_WeightInfo() { Order = string.Format("{0}", count + 1), Weight = w, UOM = "g" }); _cal_avr_weight(); })); //cho den khi sp nhac ra khoi can thi reset while (!(data.Contains("US") == true)) { data = CAS_EDH.GetDataFromScale(); _calibInfo.WeightData += data + "\r\n"; } count++; //exit calib weight if (count >= max_count) { break; } } Dispatcher.Invoke(new Action(() => { btn_startcalib.IsEnabled = true; btn_stopcalib.IsEnabled = false; })); })); calib_thread.IsBackground = true; calib_thread.Start(); break; } case "Stop Calib": { _stop_calib(); break; } } }