using EC.AutoWeightServer.Model.EventArgsEx; using EC.Utils.SerialPortHelper; using System; namespace EC.AutoWeightServer.IfManager.Scales { public class Scales : IScales { protected ECSerialPort _port; protected string ComName; protected int BaudRate; protected int ReceivedBytesThreshold; public Scales() { } public Scales(string comName, int baudRate) { this.ComName = comName; this.BaudRate = baudRate; } public Scales(string comName, int baudRate, int receivedBytesThreshold) { this.ComName = comName; this.BaudRate = baudRate; this.ReceivedBytesThreshold = receivedBytesThreshold; } public bool StartServer() { _port = SerialPortManager.CreateSerialPort(ComName, BaudRate, ReceivedBytesThreshold); _port.OnRecData += RecData; _port.OpenCom(); return true; } public bool StopServer() { _port?.CloseCom(); _port = null; return true; } public bool IsOpen() { if (_port == null) return false; if (!_port.IsOpen()) return false; return true; } public virtual event EventHandler OnRecData; public virtual void RecData(object sender, byte[] buf) { } } }