using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.ComponentModel;
using FLY.Thick.Base.Server;
namespace FLY.Simulation.Casting
{
///
/// 流延
///
public class GageAD : ISimulationGageAD, INotifyPropertyChanged
{
CurveCollection curve;
//这是整个机架的数据
List datas_horizontal = new List();//横向AD数据, 1mm 一个AD值
///
/// 编码器2 1脉冲 = ? mm 辊直径120mm,编码器 转1圈800脉冲
///
const double Mmpp2 = 0.25;
const double RLen = 120 * 3.14;
///
/// 拉伸前 大辊直径
///
const double RLenBeforeStretching = 800 * 3.14;
///
/// 1脉冲 = ? mm
///
public double Mmpp { get; set; } = 0.0943;
///
/// 膜速度 m/min
///
public double FilmVelocity { get; set; } = 23;
///
/// 拉伸前膜速度 m/min
///
public double FilmVelocityBeforeStretching { get; set; } = 10;
///
/// 拉伸前膜长 m
///
public double FilmLengthBeforeStretching { get; set; }
///
/// 膜长 m
///
public double FilmLength { get; set; }
///
/// 运转中
///
public bool IsRunning { get; set; } = true;
///
/// 机架总长 mm
///
public int TotalLength { get; set; } = 3000;
PlcLink plcLink;
Random random;
public GageAD()
{
curve = new CurveCollection();
plcLink = new PlcLink();
plcLink.Init();
Load();
random = new Random();
}
public int GetAD(int mm)
{
if (mm < 0)
mm = 0;
else if (mm >= datas_horizontal.Count())
mm = datas_horizontal.Count() - 1;
int ad = datas_horizontal[mm];
ad += (int)(ad * (random.NextDouble() * 0.01 - 0.005));
return ad;
}
DateTime dtlast = DateTime.MinValue;
public void OnPoll(DateTime now)
{
if (dtlast == DateTime.MinValue)
{
dtlast = now;
return;
}
if (IsRunning)
{
double min = (now - dtlast).TotalMinutes;
FilmLength += min * FilmVelocity;
FilmLengthBeforeStretching += min * FilmLengthBeforeStretching;
}
dtlast = now;
}
public UInt16 GetInput()
{
UInt16 istatus = 0x0fff;
double p = FilmLength * 1000 % RLen;
if(p