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."); } }
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 { } } }
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."); } }