444 lines
14 KiB
C#
444 lines
14 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using System.Threading;
|
|
using System.Diagnostics;
|
|
using System.Reflection;
|
|
|
|
namespace CoreUnit.PowerMeter
|
|
{
|
|
public abstract class PowerMeterUnit
|
|
{
|
|
#region PowerMeterUnitParam, PowerMeterUnitAverageParam 선언
|
|
public Dictionary<int, string> statusText;
|
|
private object m_LockObject = new object();
|
|
|
|
public class PowerMeterUnitParam
|
|
{
|
|
int m_deviceNo;
|
|
int m_channel;
|
|
int m_streamMode;
|
|
string m_serialNo;
|
|
|
|
public int DeviceNo
|
|
{
|
|
set { m_deviceNo = value; }
|
|
get { return m_deviceNo; }
|
|
}
|
|
public string SerialNo
|
|
{
|
|
set { m_serialNo = value; }
|
|
get { return m_serialNo; }
|
|
}
|
|
public int Channel
|
|
{
|
|
set { m_channel = value; }
|
|
get { return m_channel; }
|
|
}
|
|
|
|
public int StreamMode
|
|
{
|
|
set { m_streamMode = value; }
|
|
get { return m_streamMode; }
|
|
}
|
|
public PowerMeterUnitParam()
|
|
{
|
|
m_deviceNo = 1000;
|
|
m_channel = 0;
|
|
m_streamMode = 1;
|
|
}
|
|
}
|
|
public class PowerMeterIPUnitParam //LJB
|
|
{
|
|
private string m_sIP;
|
|
public string IP
|
|
{
|
|
get { lock (this) { return m_sIP; } }
|
|
set { lock (this) { m_sIP = value; } }
|
|
}
|
|
private int m_PortNo;
|
|
public int PortNo
|
|
{
|
|
get { lock (this) { return m_PortNo; } }
|
|
set { lock (this) { m_PortNo = value; } }
|
|
}
|
|
private int m_EqpNo;
|
|
public int EQPNo
|
|
{
|
|
get { lock (this) { return m_EqpNo; } }
|
|
set { lock (this) { m_EqpNo = value; } }
|
|
}
|
|
|
|
}
|
|
public class PowerMeterUnitAverageParam
|
|
{
|
|
// 평균값 산출 관련
|
|
double m_readingStartTime, m_readingEndTime, m_samplingTime, m_readingTime;
|
|
int m_samplingCnt, m_samplingIter;
|
|
double m_rawData, m_averageData, m_peakData, m_beforeTimeStamp;
|
|
public double ReadingTime
|
|
{
|
|
get { return m_readingTime; }
|
|
set { m_readingTime = value; }
|
|
}
|
|
public double ReadingStartTime
|
|
{
|
|
get { return m_readingStartTime; }
|
|
set { m_readingStartTime = value; }
|
|
}
|
|
public double ReadingEndTime
|
|
{
|
|
get { return m_readingEndTime; }
|
|
set { m_readingEndTime = value; }
|
|
}
|
|
public double SamplingTime
|
|
{
|
|
get { return m_samplingTime; }
|
|
set { m_samplingTime = value; }
|
|
}
|
|
public int SamplingCnt
|
|
{
|
|
get { return m_samplingCnt; }
|
|
set { m_samplingCnt = value; }
|
|
}
|
|
public double RawData
|
|
{
|
|
get { return m_rawData; }
|
|
set { m_rawData = value; }
|
|
}
|
|
public int SamplingIter
|
|
{
|
|
get { return m_samplingIter; }
|
|
set { m_samplingIter = value; }
|
|
}
|
|
public double AverageData
|
|
{
|
|
get { return m_averageData; }
|
|
set { m_averageData = value; }
|
|
}
|
|
public double PeakData
|
|
{
|
|
get { return m_peakData; }
|
|
set { m_peakData = value; }
|
|
}
|
|
public double BeforeTimeStamp
|
|
{
|
|
get { return m_beforeTimeStamp; }
|
|
set { m_beforeTimeStamp = value; }
|
|
}
|
|
public List<double> rawDataList = new List<double>();
|
|
public List<double> AverageDataList = new List<double>();
|
|
|
|
}
|
|
protected PowerMeterUnitParam m_powerMeterUnitParam = null;
|
|
protected PowerMeterUnitAverageParam m_powerMeterUnitAverageParam = null;
|
|
|
|
protected PowerMeterIPUnitParam m_powerMeterIPUnitParam = null; //LJB
|
|
|
|
public void SetPowerMeterIP(string ip , int num)
|
|
{
|
|
m_powerMeterIPUnitParam.IP = ip;
|
|
m_powerMeterIPUnitParam.EQPNo = num + 1;
|
|
|
|
}
|
|
#endregion PowerMeterUnitParam, PowerMeterUnitAverageParam 선언 완료
|
|
|
|
#region PowerMeter 초기 변수 및 초기 함수 선언
|
|
// dll 파일 추가
|
|
public OphirLMMeasurementLib.CoLMMeasurement m_ophir;
|
|
|
|
protected string m_serialNo;
|
|
|
|
//PRIMES Data 변수 선언 2023-11-15 JJS
|
|
public string p_RemainingCapacity = null;
|
|
public string p_MeasuredEnergy = null;
|
|
public string p_MeasuredPower = null;
|
|
public string p_MeasuredTime = null;
|
|
public string p_AbsorberTemp = null;
|
|
public string p_Housing1Temp = null;
|
|
public string p_Housing2Temp = null;
|
|
public string p_Housing3Temp = null;
|
|
public string p_MaxCapacity = null;
|
|
public string p_MinEnergy = null;
|
|
public string p_MinIrradiationTime = null;
|
|
public string p_MaxIrradiationTime = null;
|
|
public string p_MaxPower = null;
|
|
|
|
public byte[] p_Status = new byte[2];
|
|
public byte[] p_ReadData = new byte[82];
|
|
|
|
#region 2.1. Status. Primes 전용
|
|
//Shutter Status bit. JJS
|
|
public bool Status_ShutterOpen
|
|
{
|
|
get { lock (m_LockObject) { return (p_Status[1] & 0x01) != 0 ? true : false; } }
|
|
}
|
|
public bool Status_ShutterClose
|
|
{
|
|
get { lock (m_LockObject) { return (p_Status[1] & 0x02) != 0 ? true : false; } }
|
|
}
|
|
public bool Status_ShutterMoving
|
|
{
|
|
get { lock (m_LockObject) { return (p_Status[1] & 0x04) != 0 ? true : false; } }
|
|
}
|
|
public bool Status_ShutterTimeOut
|
|
{
|
|
get { lock (m_LockObject) { return (p_Status[1] & 0x08) != 0 ? true : false; } }
|
|
}
|
|
public bool Status_ShutterSensorError
|
|
{
|
|
get { lock (m_LockObject) { return (p_Status[1] & 0x10) != 0 ? true : false; } }
|
|
}
|
|
|
|
// PMM Status Bit. JJS
|
|
public bool Status_PMM_Ready
|
|
{
|
|
get { lock (m_LockObject) { return (p_Status[0] & 0x01) != 0 ? true : false; } }
|
|
}
|
|
public bool Status_PMM_Run
|
|
{
|
|
get { lock (m_LockObject) { return (p_Status[0] & 0x02) != 0 ? true : false; } }
|
|
}
|
|
public bool Status_PMM_Finish
|
|
{
|
|
get { lock (m_LockObject) { return (p_Status[0] & 0x04) != 0 ? true : false; } }
|
|
}
|
|
public bool Status_PMM_AbsorberTooHot
|
|
{
|
|
get { lock (m_LockObject) { return (p_Status[0] & 0x08) != 0 ? true : false; } }
|
|
}
|
|
public bool Status_PMM_Idle
|
|
{
|
|
get { lock (m_LockObject) { return (p_Status[0] & 0x10) != 0 ? true : false; } }
|
|
}
|
|
public bool Status_PMM_IrradiationFail
|
|
{
|
|
get { lock (m_LockObject) { return (p_Status[0] & 0x20) != 0 ? true : false; } }
|
|
}
|
|
public bool Status_PMM_StartAcknowledged
|
|
{
|
|
get { lock (m_LockObject) { return (p_Status[0] & 0x40) != 0 ? true : false; } }
|
|
}
|
|
public bool Status_PMM_ShutterAcknowledged
|
|
{
|
|
get { lock (m_LockObject) { return (p_Status[0] & 0x80) != 0 ? true : false; } }
|
|
}
|
|
|
|
#endregion Status
|
|
|
|
#region 2.2. PMM 제어 Primes 전용
|
|
/// <summary>
|
|
/// Do open shutter.
|
|
/// </summary>
|
|
public virtual void ShutterOpen()
|
|
{
|
|
|
|
}
|
|
|
|
/// <summary>
|
|
/// Do close shutter.
|
|
/// </summary>
|
|
public virtual void ShutterClose()
|
|
{
|
|
|
|
}
|
|
|
|
/// <summary>
|
|
/// Start Measurement. 1초 이내 측정해야함.
|
|
/// </summary>
|
|
public virtual void MeasureStart()
|
|
{
|
|
|
|
}
|
|
|
|
/// <summary>
|
|
/// Set the PMM to the initial state.<br/>
|
|
/// IDLE bit is activeted. JJS
|
|
/// </summary>
|
|
public virtual void ResetPMM()
|
|
{
|
|
|
|
}
|
|
|
|
// Primes Powermeter 전용
|
|
public virtual string GetIP()
|
|
{
|
|
return "";
|
|
}
|
|
|
|
public virtual bool IsConnect()
|
|
{
|
|
|
|
return false;
|
|
}
|
|
public virtual void LaserShot()
|
|
{
|
|
|
|
}
|
|
|
|
public virtual void MeasureResult()
|
|
{
|
|
|
|
}
|
|
#endregion PMM 제어
|
|
|
|
// Initialize measured data from the current displayed data
|
|
public string timestampStr = null;
|
|
public string measurementStr = null;
|
|
public string statusStr = null;
|
|
public string xPositionStr = null;
|
|
public string yPositionStr = null;
|
|
public string sizeStr = null;
|
|
public string frequencyStr = null;
|
|
public string errorStr = null;
|
|
|
|
// EtherNet/IP
|
|
public PowerMeterUnit()
|
|
{
|
|
m_powerMeterUnitParam = new PowerMeterUnitParam();
|
|
m_powerMeterUnitAverageParam = new PowerMeterUnitAverageParam();
|
|
m_powerMeterIPUnitParam = new PowerMeterIPUnitParam();
|
|
}
|
|
|
|
public void SetInit()
|
|
{
|
|
m_powerMeterUnitParam = new PowerMeterUnitParam();
|
|
m_powerMeterUnitAverageParam = new PowerMeterUnitAverageParam();
|
|
m_powerMeterIPUnitParam = new PowerMeterIPUnitParam();
|
|
}
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
public PowerMeterUnitAverageParam PowerMeterAverageUnit
|
|
{
|
|
get { return m_powerMeterUnitAverageParam; }
|
|
set { m_powerMeterUnitAverageParam = value; }
|
|
}
|
|
|
|
#region PowerMeter 연결 함수 선언
|
|
public abstract void OpenUSB();
|
|
public abstract void OpenIP(string IP);
|
|
public abstract void CloseUSB();
|
|
public abstract void CloseIP();
|
|
public abstract void CloseWindow();
|
|
public abstract void ResetUSB();
|
|
#endregion
|
|
|
|
#region PowerMeter 동작 함수 선언
|
|
public abstract void StatusBox();
|
|
|
|
public abstract void SelectStreamMode(int mode, int frequency);
|
|
|
|
public abstract void StartStream();
|
|
|
|
public abstract void StopStream();
|
|
|
|
public abstract bool BeRightDevice(string serialNo);
|
|
|
|
public abstract void ReadData(int idx = 0, int channel = 0);
|
|
|
|
public abstract string GetStatus(int index);
|
|
|
|
public abstract void WakeSensor();
|
|
|
|
|
|
#endregion
|
|
|
|
#region 평균 값 구하기 함수 선언
|
|
public void AverageModeSet(double readingTime, double samplingTime)
|
|
{
|
|
if (samplingTime != 0)
|
|
{
|
|
PowerMeterAverageUnit.RawData = 0;
|
|
PowerMeterAverageUnit.SamplingIter = 0;
|
|
PowerMeterAverageUnit.rawDataList = new List<double>();
|
|
PowerMeterAverageUnit.AverageDataList = new List<double>();
|
|
double temp;
|
|
double.TryParse(timestampStr, out temp);
|
|
PowerMeterAverageUnit.ReadingStartTime = temp;
|
|
PowerMeterAverageUnit.ReadingEndTime = PowerMeterAverageUnit.ReadingStartTime + readingTime; // 추가. 시간시간
|
|
PowerMeterAverageUnit.ReadingTime = readingTime;
|
|
PowerMeterAverageUnit.SamplingTime = samplingTime;
|
|
PowerMeterAverageUnit.BeforeTimeStamp = temp;
|
|
}
|
|
}
|
|
public void AddRawData()
|
|
{
|
|
double temp = 0;
|
|
double.TryParse(measurementStr, out temp);
|
|
PowerMeterAverageUnit.RawData = temp;
|
|
PowerMeterAverageUnit.rawDataList.Add(temp);
|
|
|
|
}
|
|
public void SetAverageData(double Time)
|
|
{
|
|
// Reading 시간의 1/2~ 5/6 시간 구간.
|
|
double startTiming = 0.5, endTiming = 0.83333;
|
|
double averageStartTime = PowerMeterAverageUnit.ReadingStartTime + PowerMeterAverageUnit.ReadingTime * startTiming;
|
|
double averageEndTime = PowerMeterAverageUnit.ReadingStartTime + PowerMeterAverageUnit.ReadingTime * endTiming;
|
|
|
|
if (averageStartTime <= Time && Time <= averageEndTime + 70)
|
|
{
|
|
// cFlag : currentFlag / bFlag = beforeFlag / sFlag = startFlag
|
|
int cFlag = (int)((Time - PowerMeterAverageUnit.ReadingStartTime) / PowerMeterAverageUnit.SamplingTime);
|
|
int bFlag = (int)((PowerMeterAverageUnit.BeforeTimeStamp - PowerMeterAverageUnit.ReadingStartTime) / PowerMeterAverageUnit.SamplingTime);
|
|
int sFlag = (int)((averageStartTime - PowerMeterAverageUnit.ReadingStartTime) / PowerMeterAverageUnit.SamplingTime);
|
|
|
|
int generalSamplingCnt = (int)((endTiming - startTiming) * PowerMeterAverageUnit.ReadingTime / PowerMeterAverageUnit.SamplingTime);
|
|
|
|
if (cFlag != bFlag)
|
|
{
|
|
double temp = 0;
|
|
double.TryParse(measurementStr, out temp);
|
|
|
|
PowerMeterAverageUnit.AverageDataList.Add(temp);
|
|
}
|
|
|
|
if (cFlag - sFlag == generalSamplingCnt)
|
|
{
|
|
PowerMeterAverageUnit.AverageData = SolveMedian(PowerMeterAverageUnit.AverageDataList);
|
|
PowerMeterAverageUnit.PeakData = SolvePeak(PowerMeterAverageUnit.AverageDataList);
|
|
|
|
// 강제 Int형으로 인한 데이터 손실 고려.
|
|
PowerMeterAverageUnit.SamplingCnt = PowerMeterAverageUnit.AverageDataList.Count;
|
|
}
|
|
|
|
PowerMeterAverageUnit.BeforeTimeStamp = Time;
|
|
}
|
|
else
|
|
{
|
|
}
|
|
}
|
|
public double SolveMedian(List<double> list)
|
|
{
|
|
double sum = 0, sol = 0;
|
|
|
|
for (int i = 0; i < list.Count; i++)
|
|
{
|
|
sum = sum + list[i];
|
|
}
|
|
sol = (double)(sum / list.Count);
|
|
|
|
|
|
return sol;
|
|
}
|
|
public double SolvePeak(List<double> list)
|
|
{
|
|
double sol = -1000;
|
|
|
|
for (int i = 0; i < list.Count; i++)
|
|
{
|
|
sol = Math.Max(sol, list[i]);
|
|
}
|
|
|
|
return sol;
|
|
}
|
|
#endregion
|
|
}
|
|
}
|