using log4net;
|
using System;
|
using System.Collections.Generic;
|
using System.IO.Ports;
|
using System.Linq;
|
using System.Text;
|
using System.Threading.Tasks;
|
|
namespace DIT.Framework.Module._01_SerialModules
|
{
|
/// <summary>
|
/// Model : IVC 3000 , 3100 Module
|
/// Home : www.isvt.co.kr
|
/// </summary>
|
class IVC3000 : SerialModule
|
{
|
private enum Read_Cmd
|
{
|
SystemPressure,
|
ThrottleValvePos,
|
MFCFlow,
|
MFCOpen,
|
MFCSetFlow,
|
MFCRange,
|
State,
|
}
|
|
/// <summary>
|
/// Exception Log
|
/// </summary>
|
private ILog ExceptionLog = LogManager.GetLogger("IVC3000_Exception");
|
|
/// <summary>
|
/// Exception Log를 기록하기 위한 메서드
|
/// </summary>
|
/// <param name="msg">Error Message</param>
|
private void WriteExceptionLog(string msg)
|
{
|
if (UseExceptionLog)
|
ExceptionLog.Debug(msg);
|
}
|
|
/// <summary>
|
/// System Pressure (atm)
|
/// </summary>
|
public string Pressure { get { return pressure; } private set { pressure = value; } }
|
private string pressure;
|
|
/// <summary>
|
/// Throttle Vavle Current Point
|
/// </summary>
|
public string VlvPos { get { return vlvPos; } private set { vlvPos = value; } }
|
private string vlvPos;
|
|
/// <summary>
|
/// MFC Flow Range
|
/// </summary>
|
public string MFCRange { get { return mfcRange; } private set { mfcRange = value; } }
|
private string mfcRange;
|
|
/// <summary>
|
/// MFC Set Flow
|
/// </summary>
|
public string MFCSetFlow { get { return mfcSetFlow; } private set { mfcSetFlow = value; } }
|
private string mfcSetFlow;
|
|
/// <summary>
|
/// MFC Current Flow
|
/// </summary>
|
public string MFCFlow { get { return mfcFlow; } private set { mfcFlow = value; } }
|
private string mfcFlow;
|
|
/// <summary>
|
/// MFC Open State
|
/// </summary>
|
public bool MFCOpen { get { return mfcOpen; } private set { mfcOpen = value; } }
|
private bool mfcOpen;
|
|
/// <summary>
|
/// Autonics_PMC_2HS의 생성자.
|
/// </summary>
|
/// <param name="PortName"> Port이름 ex)COM6, COM13 </param>
|
/// <param name="BaudRate"> 전송속도 ex)4800, 9600, 19200 </param>
|
/// <param name="DataBits"> 바이트 당 데이터 비트의 표준길이 ex)5, 6, 7, 8 </param>
|
/// <param name="Parity">패리티 검사 프로토콜 ex)Ports.Parity.None </param>
|
/// <param name="StopBits">비트당 정지비트의 표준 개수 ex)Ports.StopBits.One </param>
|
/// <param name="Handshake">직렬 전송을 위한 핸드셰이킹 ex)Ports.Handshake.None</param>
|
public IVC3000(string PortName, int BaudRate, int DataBits = 8, Parity Parity = Parity.None, StopBits StopBits = StopBits.One, Handshake Handshake = Handshake.None)
|
: base(PortName, BaudRate, DataBits, Parity, StopBits, Handshake)
|
{
|
Pressure = "0";
|
VlvPos = "0";
|
MFCRange = "0";
|
MFCSetFlow = "0";
|
MFCFlow = "0";
|
MFCOpen = false;
|
}
|
|
/// <summary>
|
/// Serial에서 받은 명령어 처리 메서드
|
/// </summary>
|
/// <param name="recvData">Recv받은 Data</param>
|
private void OnRecvData(Read_Cmd ReadCmd, byte[] recvData)
|
{
|
try
|
{
|
string str = Encoding.ASCII.GetString(recvData);
|
|
switch (ReadCmd)
|
{
|
case Read_Cmd.SystemPressure:
|
string[] _sSplitPressue = str.Replace("+", "\r").Split('P');
|
Pressure = (Convert.ToDouble(_sSplitPressue[1]) * 10).ToString();
|
break;
|
case Read_Cmd.ThrottleValvePos:
|
string[] _sSplitVlvPos = str.Replace("+", "\r").Split('V');
|
VlvPos = (Convert.ToDouble(_sSplitVlvPos[1])).ToString();
|
break;
|
case Read_Cmd.MFCFlow:
|
string[] sSplitMFCFlow = str.Split('+');
|
MFCFlow = (int.Parse(MFCRange) * Convert.ToDouble(sSplitMFCFlow[1]) / 100).ToString();
|
break;
|
case Read_Cmd.MFCOpen:
|
MFCOpen = str.Substring(2, 1) == "1" ? true : false;
|
break;
|
case Read_Cmd.MFCSetFlow:
|
MFCSetFlow = (int.Parse(MFCRange) * double.Parse(str.Split('+')[1]) / 100).ToString();
|
break;
|
case Read_Cmd.MFCRange:
|
MFCRange = str.Split('+')[1];
|
break;
|
default:
|
break;
|
}
|
}
|
catch(Exception e)
|
{
|
WriteExceptionLog(e.Message);
|
}
|
}
|
|
/// <summary>
|
/// System Pressure(atm) Request
|
/// </summary>
|
public void Request_SystemPressure()
|
{
|
try
|
{
|
byte[] cmd = Encoding.ASCII.GetBytes($"R5{CR}");
|
|
byte[] recvData = SendWaitData(cmd);
|
|
if (recvData == null)
|
return;
|
|
OnRecvData(Read_Cmd.SystemPressure, recvData);
|
}
|
catch (Exception e)
|
{
|
WriteExceptionLog(e.Message);
|
}
|
}
|
|
/// <summary>
|
/// Throttle Valve Position Request
|
/// </summary>
|
public void Request_ThrottleValvePos()
|
{
|
try
|
{
|
byte[] cmd = Encoding.ASCII.GetBytes($"R6{CR}");
|
|
byte[] recvData = SendWaitData(cmd);
|
|
if (recvData == null)
|
return;
|
|
OnRecvData(Read_Cmd.ThrottleValvePos, recvData);
|
}
|
catch (Exception e)
|
{
|
WriteExceptionLog(e.Message);
|
}
|
}
|
|
/// <summary>
|
/// MFC Current Flow Request
|
/// </summary>
|
public void Request_MFCFlow()
|
{
|
try
|
{
|
byte[] cmd = Encoding.ASCII.GetBytes($"R61{CR}");
|
|
byte[] recvData = SendWaitData(cmd);
|
|
if (recvData == null)
|
return;
|
|
OnRecvData(Read_Cmd.MFCFlow, recvData);
|
}
|
catch (Exception e)
|
{
|
WriteExceptionLog(e.Message);
|
}
|
}
|
|
/// <summary>
|
/// MFC Open State Request
|
/// </summary>
|
public void Request_MFCOpen()
|
{
|
try
|
{
|
byte[] cmd = Encoding.ASCII.GetBytes($"R69{CR}");
|
|
byte[] recvData = SendWaitData(cmd);
|
|
if (recvData == null)
|
return;
|
|
OnRecvData(Read_Cmd.MFCOpen, recvData);
|
}
|
catch (Exception e)
|
{
|
WriteExceptionLog(e.Message);
|
}
|
}
|
|
/// <summary>
|
/// MFC Set Flow Request
|
/// </summary>
|
public void Request_MFCSet()
|
{
|
try
|
{
|
byte[] cmd = Encoding.ASCII.GetBytes($"R65{CR}");
|
|
byte[] recvData = SendWaitData(cmd);
|
|
if (recvData == null)
|
return;
|
|
OnRecvData(Read_Cmd.MFCSetFlow, recvData);
|
}
|
catch (Exception e)
|
{
|
WriteExceptionLog(e.Message);
|
}
|
}
|
|
/// <summary>
|
/// MFC Flow Range Request
|
/// </summary>
|
public void Request_MFCRange()
|
{
|
try
|
{
|
byte[] cmd = Encoding.ASCII.GetBytes($"R70{CR}");
|
|
byte[] recvData = SendWaitData(cmd);
|
|
if (recvData == null)
|
return;
|
|
OnRecvData(Read_Cmd.MFCRange, recvData);
|
}
|
catch (Exception e)
|
{
|
WriteExceptionLog(e.Message);
|
}
|
}
|
|
/// <summary>
|
/// Throttle Valve Set Pos 명령어
|
/// </summary>
|
/// <param name="Pos">Point</param>
|
public void SetValvePos(string Pos)
|
{
|
try
|
{
|
int pos = 0;
|
int.TryParse(Pos, out pos);
|
|
SET_ThrottleVlvPointType(1, 0);
|
SET_ThrottleVlvPoint(1, pos);
|
RUN_ThrottleVlvPoint(1);
|
}
|
catch (Exception e)
|
{
|
WriteExceptionLog(e.Message);
|
}
|
}
|
|
/// <summary>
|
/// Throttle Valve Set - Point에 대한 Type
|
/// </summary>
|
/// <param name="iCh">Chanel 1 ~ 5</param>
|
/// <param name="Type"> 0 : Position, 1 : Pressure</param>
|
public void SET_ThrottleVlvPointType(int iCh, int Type)
|
{
|
try
|
{
|
SendData($"T{iCh}{Type}{CR}");
|
}
|
catch (Exception e)
|
{
|
WriteExceptionLog(e.Message);
|
}
|
}
|
|
/// <summary>
|
/// Throttle Valve Set Point iCh
|
/// </summary>
|
/// <param name="iCh">Chanel 1 ~ 5</param>
|
/// <param name="Point">Set Point 1 ~ 100</param>
|
public void SET_ThrottleVlvPoint(int iCh, int Point)
|
{
|
SendData($"S{iCh}{Point}{CR}");
|
}
|
|
/// <summary>
|
/// Throttle Vavle Run iCh
|
/// </summary>
|
/// <param name="iCh">Chanel 1 ~ 5</param>
|
public void RUN_ThrottleVlvPoint(int iCh)
|
{
|
SendData($"D{iCh}{CR}");
|
}
|
|
/// <summary>
|
/// MFC Open 명령어
|
/// </summary>
|
/// <param name="open"></param>
|
public void RUN_MFCOpen(bool open)
|
{
|
SET_MFCType(5, 2);
|
|
SET_MFCValveOpen(1, open);
|
}
|
|
/// <summary>
|
/// MFC Type Set
|
/// </summary>
|
/// <param name="iCh">Chanel 5 ~ 8</param>
|
/// <param name="Type">1 : SCCM, 2 : SLM</param>
|
public void SET_MFCType(int iCh, int Type)
|
{
|
SendData($"W{iCh} {Type}{CR}");
|
}
|
|
/// <summary>
|
/// SET MFC Valve Open
|
/// </summary>
|
/// <param name="iCh">Chanel 1 ~ 4 </param>
|
/// <param name="open">true : Oepn, False : Close</param>
|
public void SET_MFCValveOpen(int iCh, bool open)
|
{
|
string sopen = open ? "1" : "0";
|
|
SendData($"L{iCh}{sopen}{CR}");
|
}
|
}
|
}
|