Beispiel #1
0
    protected void TurnOff(object sender, EventArgs e)
    {
        //
        ScaleClient scale = (ScaleClient)Session["Scale"];

        try {
            if (scale.IsOn())
            {
                scale.TurnOff();
            }
            this.lblIsOn.Text      = scale.IsOn().ToString();
            this.btnStart.Enabled  = !scale.IsOn();
            this.btnStop.Enabled   = scale.IsOn();
            this.btnWeight.Enabled = scale.IsOn();
            this.btnZero.Enabled   = scale.IsOn();
        }
        catch (TimeoutException ex) {
            reportError(new ApplicationException("The service operation timed out.", ex));
            scale.Abort();
        }
        catch (FaultException <Devices.ScaleFault> f) {
            reportError(new ApplicationException("There was a scale fault- " + f.ToString()));
            scale.Abort();
        }
        catch (CommunicationException ex) {
            reportError(new ApplicationException("There was a communication problem.", ex));
            scale.Abort();
        }
    }
Beispiel #2
0
    //
    protected void Page_Load(object sender, EventArgs e)
    {
        //
        ScaleClient scale = null;

        if (!Page.IsPostBack)
        {
            scale            = new ScaleClient(new InstanceContext(new ScaleCallbacks()), "WSDualHttpBinding_IScale");
            Session["Scale"] = scale;
            try {
                //Service
                this.lblService.Text = scale.Endpoint.Address.Uri.ToString();
                this.lblIsOn.Text    = scale.IsOn().ToString();

                //Settings
                this.lblBornOn.Text = scale.BornOn().ToLongTimeString();
                PortSettings ps = scale.GetSettings();
                this.lblPort.Text      = ps.PortName;
                this.lblBaud.Text      = ps.BaudRate.ToString();
                this.lblData.Text      = ps.DataBits.ToString();
                this.lblStop.Text      = ps.StopBits.ToString();
                this.lblParity.Text    = ps.Parity.ToString();
                this.lblHandshake.Text = ps.Handshake.ToString();

                this.btnStart.Enabled  = true;
                this.btnStop.Enabled   = false;
                this.btnWeight.Enabled = false;
                this.btnZero.Enabled   = false;
            }
            catch (TimeoutException ex) {
                reportError(new ApplicationException("The service operation timed out.", ex));
                scale.Abort();
            }
            catch (FaultException <Devices.ScaleFault> f) {
                reportError(new ApplicationException("There was a scale fault- " + f.ToString()));
                scale.Abort();
            }
            catch (CommunicationException ex) {
                reportError(new ApplicationException("There was a communication problem.", ex));
                scale.Abort();
            }
        }
    }
Beispiel #3
0
    protected void GetWeight(object sender, EventArgs e)
    {
        //
        ScaleClient scale = (ScaleClient)Session["Scale"];

        try {
            bool isStable = false;
            this.lblWeight.Text = scale.GetWeight(ref isStable).ToString();
        }
        catch (TimeoutException ex) {
            reportError(new ApplicationException("The service operation timed out.", ex));
            scale.Abort();
        }
        catch (FaultException <Devices.ScaleFault> f) {
            reportError(new ApplicationException("There was a scale fault- " + f.ToString()));
            scale.Abort();
        }
        catch (CommunicationException ex) {
            reportError(new ApplicationException("There was a communication problem.", ex));
            scale.Abort();
        }
    }