private void getResponse() { //Read incoming port buffer string buffer = "", units = ""; decimal weight = 0; bool stable = false; try { try { buffer = this.mSerialPort.ReadExisting(); if (buffer.Length > 6) { weight = Convert.ToDecimal(buffer.Substring(2, 5)); } if (buffer.Length > 8) { units = buffer.Substring(7, 2); } if (buffer.Length > 11) { stable = Convert.ToBoolean(Convert.ToInt32(buffer.Substring(10, 2))); } } catch { } //Send notification of weight reading if scale value indicated a stable reading ScaleError error = stable ? ScaleError.None : ScaleError.ScaleUnstable; new WeightCompleteHandler(OnWeightComplete).BeginInvoke(new ScaleEventArgs(weight, error), null, null); } catch (ApplicationException) { } catch (Exception) { } }
private void getIncomingText() { //Read incoming port buffer string buffer = "", units = ""; decimal weight = 0; try { try { buffer = this.mSerialPort.ReadExisting(); #if DEBUG System.Diagnostics.Debug.WriteLine(buffer); #endif weight = parseWeight(buffer); units = parseUnits(buffer); } catch (Exception) { } //Send notification of weight reading if scale value indicated a stable reading bool stable = this.mIsStable ? checkStability(buffer) : true; ScaleError error = stable ? ScaleError.None : ScaleError.ScaleUnstable; //this.mWeightComplete.BeginInvoke(new ScaleEventArgs(weight,error),null,null); new WeightCompleteHandler(OnWeightComplete).BeginInvoke(new ScaleEventArgs(weight, error), null, null); } catch (ApplicationException) { } catch (Exception) { } }
public ScaleEventArgs(decimal weight, ScaleError error) { this._weight = weight; this._error = error; }
// public void WeightReading(decimal weight, ScaleError error) { }