67 lines
1.5 KiB
C#
67 lines
1.5 KiB
C#
using Aurora;
|
|
using Aurora.Api;
|
|
using Aurora.Api.Devices;
|
|
using Hermes;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace AuroraScale.CAS
|
|
{
|
|
public class CASScale : SerialPortDevice
|
|
{
|
|
private double _Weight = 0;
|
|
|
|
public CASScale(string deviceId) : base(deviceId, ApplicationExt.IsSimulation)
|
|
{
|
|
IsSimul = ApplicationExt.IsSimulation;
|
|
SetMonitoringService(DoMonitoring, 100);
|
|
}
|
|
|
|
private void DoMonitoring()
|
|
{
|
|
_Weight = GetWeight();
|
|
if(_Weight > 1100)
|
|
{
|
|
//Com Error 한번 발생 시 GetWeight가 업데이트가 안됨
|
|
//IsCommError = true;
|
|
}
|
|
}
|
|
|
|
public double Weight()
|
|
{
|
|
return _Weight;
|
|
}
|
|
|
|
protected override int DoActivate(IDeviceConfig config)
|
|
{
|
|
var casConfig = config as CASScaleConfig;
|
|
IsSimul = casConfig.IsSiuml;
|
|
if (IsSimul)
|
|
{
|
|
return E1.OK;
|
|
}
|
|
return Open(casConfig.ConnConfig as SerialConnConfig);
|
|
}
|
|
|
|
protected override int DoDeactivate()
|
|
{
|
|
if (IsSimul)
|
|
{
|
|
return E1.OK;
|
|
}
|
|
return Close();
|
|
}
|
|
|
|
private double GetWeight()
|
|
{
|
|
Random r = new Random();
|
|
|
|
return r.NextDouble() * 1200;
|
|
}
|
|
}
|
|
|
|
}
|