You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
61 lines
1.2 KiB
61 lines
1.2 KiB
3 years ago
|
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<ScaleEventArgs> OnRecData;
|
||
|
|
||
|
public virtual void RecData(object sender, byte[] buf)
|
||
|
{
|
||
|
}
|
||
|
}
|
||
|
}
|