public void ChangeScale(string scaleType, string portName) { //Change station scale try { if (scaleType != "" && portName != "") { //Create and configure a scale IScale oScale = DeviceFactory.CreateScale(scaleType, portName); PortSettings oSettings = oScale.DefaultSettings; NameValueCollection nvcScale = (NameValueCollection)ConfigurationManager.GetSection("station/scale"); oSettings.PortName = portName; oSettings.BaudRate = Convert.ToInt32(nvcScale["BaudRate"]); switch (nvcScale["Parity"].ToString().ToLower()) { case "none": oSettings.Parity = Parity.None; break; case "even": oSettings.Parity = Parity.Even; break; case "odd": oSettings.Parity = Parity.Odd; break; } oScale.Settings = oSettings; //Atach scale to sort station and turn-on if (this.mScale != null) { this.mScale.TurnOff(); } this.mScale = oScale; this.mScale.TurnOn(); } } catch (System.IO.IOException) { } catch (ApplicationException ex) { throw ex; } catch (Exception ex) { throw new ApplicationException("Unexpected error while setting the scale.", ex); } finally { if (this.ScaleChanged != null) { this.ScaleChanged(this, new EventArgs()); } } }
public void ChangeScale(string scaleType, string portName) { //Change station scale try { if (scaleType != "" && portName != "") { //Create and configure a scale IScale oScale = DeviceFactory.CreateScale(scaleType, portName); PortSettings oSettings = oScale.DefaultSettings; NameValueCollection nvcScale = (NameValueCollection)ConfigurationSettings.GetConfig("station/scale"); oSettings.PortName = portName; oSettings.BaudRate = Convert.ToInt32(nvcScale["BaudRate"]); switch (nvcScale["Parity"].ToString().ToLower()) { case "none": oSettings.Parity = RS232Parity.None; break; case "even": oSettings.Parity = RS232Parity.Even; break; case "odd": oSettings.Parity = RS232Parity.Odd; break; } oScale.Settings = oSettings; //Atach scale to sort station and turn-on if (this.mScale != null) { this.mScale.TurnOff(); } this.mScale = oScale; this.mScale.TurnOn(500); //Notify clients if (this.ScaleChanged != null) { this.ScaleChanged(this, new EventArgs()); } } } catch (Exception ex) { throw ex; } }