Exemple #1
0
        static void OnTimedEvent(object sender, System.EventArgs e)
        {
            decimal?weightInLb, weightInG, weightInOz, weightInKg;
            bool?   isStable;

            USBScale s = new USBScale();

            s.Connect();

            if (s.IsConnected)
            {
                s.GetWeight(out weightInG, out weightInOz, out weightInLb, out weightInKg, out isStable);
                s.DebugScaleData();
                Console.WriteLine("Weight: {0:0.00} g", weightInG);
                Console.WriteLine("Weight: {0:0.00} oz", weightInOz);
                Console.WriteLine("Weight: {0:0.00} LBS", weightInLb);
                Console.WriteLine("Weight: {0:0.00} KG", weightInKg);
                Console.WriteLine("Stable?: {0}", isStable);
                Console.WriteLine("--------------------- {0}", DateTime.Now);
                s.Disconnect();
            }
            else
            {
                Console.WriteLine("No Scale Connected.");
            }
        }
Exemple #2
0
        public void OnTimer(object sender, System.Timers.ElapsedEventArgs args)
        {
            decimal?weight;
            bool?   isStable;

            USBScale s = new USBScale();

            s.Connect();

            if (s.IsConnected)
            {
                s.GetWeight(out weight, out isStable);
                s.DebugScaleData();
                s.Disconnect();

                if (debugmode == "true")
                {
                    File.AppendAllText(ScaleLogFile, weight.ToString() + " LBS" + System.Environment.NewLine);
                }
                else
                {
                }
                SendMessage(weight);
            }
            else
            {
                if (debugmode == "true")
                {
                    File.AppendAllText(ScaleLogFile, "No scale connected" + Environment.NewLine);
                }
                else
                {
                }
            }
        }
Exemple #3
0
    public static void Main(string[] args)
    {
      decimal? weight;
      bool? isStable;

      USBScale s = new USBScale();
      s.Connect();

      if (s.IsConnected)
      {
        s.GetWeight(out weight, out isStable);
        s.DebugScaleData();
        s.Disconnect();
        Console.WriteLine("Weight: {0:0.00} LBS", weight);
      } else {
        Console.WriteLine("No Scale Connected.");
      }
    }
Exemple #4
0
        public FormPostage()
        {
            InitializeComponent();
            decimal?weight;
            bool?   isStable;
            decimal iPounds = 0;
            decimal iOunces = 0;
            decimal postageCalculated;

            USBScale s = new USBScale();

            s.Connect();
            if (s.IsConnected)
            {
                labelStatus.Text = "Status:  Found Stamps.com scale";
                s.GetWeight(out weight, out isStable);
                //s.DebugScaleData();
                s.Disconnect();
                iPounds = Math.Floor(Convert.ToDecimal(weight));
                iOunces = Convert.ToDecimal(Math.Round(
                                                Convert.ToDecimal(weight - iPounds) * 16, 2, MidpointRounding.AwayFromZero
                                                ));
                textBoxPounds.Text = iPounds.ToString();
                textBoxOunces.Text = iOunces.ToString();
                if (iPounds > 1 || (iOunces > Convert.ToDecimal(3.5)))
                {
                    if (iPounds > 1 || (iOunces > Convert.ToDecimal(13.499)))
                    {
                        // ----------------------------------------------------------------------------
                        // 13.5 ounces and over, need Priority Mail flat-rate envelope
                        labelStatus.Text        = "Status:  > 13.5 oz., use Priority Mail flat-rate envelope";
                        textBoxPostage.Text     = "";
                        textBoxNum49Stamps.Text = "";
                        textBoxNum21Stamps.Text = "";
                    }
                    else
                    {
                        // ----------------------------------------------------------------------------
                        // Over 3.5 ounces but under 13.5, need FLATS calculation
                        labelStatus.Text = "Status:  > 3.5 oz., using FLATS calculation";
                        if (iPounds < Convert.ToDecimal(4.0) && iOunces < Convert.ToDecimal(0.999))
                        {
                            // 3.5 to 3.99
                            textBoxPostage.Text     = "1.61";
                            textBoxNum49Stamps.Text = "2";
                            textBoxNum21Stamps.Text = "3";
                        }
                        else
                        {
                            if (iPounds < Convert.ToDecimal(4.0) && iOunces < Convert.ToDecimal(0.5))
                            {
                                // 4.0 to 4.5 ounces = $0.98
                                textBoxPostage.Text     = "1.61";
                                textBoxNum49Stamps.Text = "2";
                                textBoxNum21Stamps.Text = "3";
                            }
                            else
                            {
                                // 5 ounces and over = $0.98 + $0.21 per ounce after the first
                                postageCalculated = Convert.ToDecimal(0.98) +
                                                    ((iPounds * 16) + Math.Round(iOunces, 0, MidpointRounding.AwayFromZero) - Convert.ToDecimal(1.0)) * Convert.ToDecimal(0.21);
                                textBoxPostage.Text = postageCalculated.ToString();
                                // postage / cost of $0.98 stamp, rounded to integer
                                textBoxNum49Stamps.Text = "2";
                                textBoxNum21Stamps.Text = (
                                    Math.Ceiling((postageCalculated - Convert.ToDecimal(0.98))
                                                 / Convert.ToDecimal(0.21))
                                    ).ToString();
                            }
                        }
                    }
                    // ----------------------------------------------------------------------------
                }
                else
                {
                    // ----------------------------------------------------------------------------
                    // Using standard calculation
                    // ----------------------------------------------------------------------------
                    if (iPounds < Convert.ToDecimal(1.0) && iOunces < Convert.ToDecimal(0.5))
                    {
                        // Less than 0.5 ounces assumes that the rounding for ounces makes that
                        // zero or 0 lbs. 0 oz.
                        textBoxPostage.Text     = "0.49";
                        textBoxNum49Stamps.Text = "1";
                        textBoxNum21Stamps.Text = "0";
                    }
                    else
                    {
                        if (iOunces < Convert.ToDecimal(1.5))
                        {
                            // 0.5 to 1.5 ounces = $0.49
                            textBoxPostage.Text     = "0.49";
                            textBoxNum49Stamps.Text = "1";
                            textBoxNum21Stamps.Text = "0";
                        }
                        else
                        {
                            // 1.5 to 3.5 ounces = $0.49 + $0.21 per ounce after the first
                            postageCalculated = Convert.ToDecimal(0.49) +
                                                ((iPounds * 16) + Math.Round(iOunces, 0, MidpointRounding.AwayFromZero) - Convert.ToDecimal(1.0)) * Convert.ToDecimal(0.21);
                            textBoxPostage.Text = postageCalculated.ToString();
                            // postage / cost of $0.49 stamp, rounded to integer
                            textBoxNum49Stamps.Text = "1";
                            textBoxNum21Stamps.Text = (
                                Math.Ceiling((postageCalculated - Convert.ToDecimal(0.49))
                                             / Convert.ToDecimal(0.21))
                                ).ToString();
                        }
                    }
                    // ----------------------------------------------------------------------------
                }
            }
            else
            {
                labelStatus.Text = "Status:  Could not find Stamps.com scale";
            }
        }