455 lines
14 KiB
C#
455 lines
14 KiB
C#
using Aurora.Api;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
|
|
namespace AuroraIO
|
|
{
|
|
public class InfoIO
|
|
{
|
|
public const int WAIT_FOR_INTERLOCK_TIMEOUT = 1;
|
|
public const int WAIT_FOR_SENSOR_TIMEOUT = 2;
|
|
public const int DISABLE_TO_SET_IO = 3;
|
|
|
|
public enum IoType
|
|
{
|
|
DI,
|
|
DO,
|
|
AI,
|
|
AO,
|
|
EnumSize
|
|
}
|
|
public enum ActiveLevelType
|
|
{
|
|
High,
|
|
Low,
|
|
EnumSize
|
|
}
|
|
|
|
public enum InfoName
|
|
{
|
|
Index,
|
|
Address,
|
|
Description,
|
|
ID,
|
|
EnumSize
|
|
}
|
|
|
|
public enum eReactiveLayerStateType //ReactiveLayer 상태
|
|
{
|
|
IDLE, //초기화 전
|
|
READY, //초기화 후
|
|
RUN,
|
|
PAUSE,//일시 정지
|
|
HEAVYALARM, //Heavy Alarm
|
|
LIGHTALARM
|
|
};
|
|
public enum eReactiveLayerOperationType //ReactiveLayer 운전 모드
|
|
{
|
|
None,
|
|
Manual,
|
|
SemiAuto,
|
|
DryRun,
|
|
Auto
|
|
};
|
|
|
|
/// <summary>
|
|
/// index 번호
|
|
/// </summary>
|
|
int index = 0;
|
|
public int Index {
|
|
get { lock (this) { return index; } }
|
|
set { lock (this) { index = value; } }
|
|
}
|
|
|
|
/// <summary>
|
|
/// 전장에서 사용하는 넘버링
|
|
/// </summary>
|
|
string address = string.Empty;
|
|
public string Address {
|
|
get { lock (this) { return address; } }
|
|
set { lock (this) { address = value; } }
|
|
}
|
|
|
|
/// <summary>
|
|
/// IO name
|
|
/// </summary>
|
|
string id = string.Empty;
|
|
public string ID {
|
|
get { lock (this) { return id; } }
|
|
set { lock (this) { id = value; } }
|
|
}
|
|
|
|
/// <summary>
|
|
/// IO Description
|
|
/// </summary>
|
|
string description = string.Empty;
|
|
public string Description {
|
|
get { lock (this) { return description; } }
|
|
set { lock (this) { description = value; } }
|
|
}
|
|
///// <summary>
|
|
///// DO High 설정을 위해 필요한 조건
|
|
///// </summary>
|
|
//List<ConditionInfo> highNecCond = new List<ConditionInfo>();
|
|
//public List<ConditionInfo> HighNecCond
|
|
//{
|
|
// get { lock (this) { return highNecCond; } }
|
|
// set { lock (this) { highNecCond = value; } }
|
|
//}
|
|
///// <summary>
|
|
///// DO low 설정을 위해 필요한 조건
|
|
///// </summary>
|
|
//List<ConditionInfo> lowhNecCond = new List<ConditionInfo>();
|
|
//public List<ConditionInfo> LowhNecCond
|
|
//{
|
|
// get { lock (this) { return lowhNecCond; } }
|
|
// set { lock (this) { lowhNecCond = value; } }
|
|
//}
|
|
///// <summary>
|
|
///// DO High 설정시 DI 센서 입력
|
|
///// </summary>
|
|
//List<ConditionInfo> highSensor = new List<ConditionInfo>();
|
|
//public List<ConditionInfo> HighSensor
|
|
//{
|
|
// get { lock (this) { return highSensor; } }
|
|
// set { lock (this) { highSensor = value; } }
|
|
//}
|
|
///// <summary>
|
|
///// DO High 설정시 DI 센서 입력
|
|
///// </summary>
|
|
//List<ConditionInfo> lowSensor = new List<ConditionInfo>();
|
|
//public List<ConditionInfo> LowSensor
|
|
//{
|
|
// get { lock (this) { return lowSensor; } }
|
|
// set { lock (this) { lowSensor = value; } }
|
|
//}
|
|
//public int waitInterlockTimeout = 0;
|
|
//public int WaitInterlockTimeout
|
|
//{
|
|
// get { lock (this) { return waitInterlockTimeout; } }
|
|
// set { lock (this) { waitInterlockTimeout = value; } }
|
|
//}
|
|
//public int waitSensorTimeout = 0;
|
|
//public int WaitSensorTimeout
|
|
//{
|
|
// get { lock (this) { return waitSensorTimeout; } }
|
|
// set { lock (this) { waitSensorTimeout = value; } }
|
|
//}
|
|
|
|
///// <summary>
|
|
///// DI High 시에 설정할 DO
|
|
///// </summary>
|
|
//List<ConditionInfo> highSufCond = new List<ConditionInfo>();
|
|
//public List<ConditionInfo> HighSufCond
|
|
//{
|
|
// get { lock (this) { return highSufCond; } }
|
|
// set { lock (this) { highSufCond = value; } }
|
|
//}
|
|
///// <summary>
|
|
///// DI low 시에 설정할 DO
|
|
///// </summary>
|
|
//List<ConditionInfo> lowSufCond = new List<ConditionInfo>();
|
|
//public List<ConditionInfo> LowSufCond
|
|
//{
|
|
// get { lock (this) { return lowSufCond; } }
|
|
// set { lock (this) { lowSufCond = value; } }
|
|
//}
|
|
public List<ConditionInfo> GetConditionList(string conditions)
|
|
{
|
|
List<ConditionInfo> necConds = new List<ConditionInfo>();
|
|
|
|
char[] separator = { '&', '|' };
|
|
string[] condition = conditions.Split(separator);
|
|
|
|
|
|
for (int i = 0; i < condition.Length; i++) {
|
|
|
|
if (condition[i].Contains('_')) {
|
|
string[] cond = condition[i].Split('_');
|
|
|
|
if (cond.Length != (int)ConditionInfo.ConditionInfoName.EnumSize) {
|
|
throw new Exception("IO Condition Data Length wrong!!");
|
|
}
|
|
|
|
int index = 0;
|
|
string temp = cond[index++];
|
|
ConditionInfo.eConditionType condType =
|
|
temp == ConditionInfo.eConditionType.DI.ToString() ? ConditionInfo.eConditionType.DI :
|
|
temp == ConditionInfo.eConditionType.DO.ToString() ? ConditionInfo.eConditionType.DO :
|
|
temp == ConditionInfo.eConditionType.AI.ToString() ? ConditionInfo.eConditionType.AI :
|
|
temp == ConditionInfo.eConditionType.AO.ToString() ? ConditionInfo.eConditionType.AI : ConditionInfo.eConditionType.STATE;
|
|
|
|
temp = cond[index++];
|
|
int ioNumber = -1;
|
|
eReactiveLayerStateType machineState = eReactiveLayerStateType.IDLE;
|
|
if (condType == ConditionInfo.eConditionType.STATE) {
|
|
machineState = temp == eReactiveLayerStateType.IDLE.ToString() ? eReactiveLayerStateType.IDLE :
|
|
temp == eReactiveLayerStateType.RUN.ToString() ? eReactiveLayerStateType.RUN :
|
|
temp == eReactiveLayerStateType.HEAVYALARM.ToString() ? eReactiveLayerStateType.HEAVYALARM :
|
|
temp == eReactiveLayerStateType.LIGHTALARM.ToString() ? eReactiveLayerStateType.LIGHTALARM :
|
|
temp == eReactiveLayerStateType.PAUSE.ToString() ? eReactiveLayerStateType.PAUSE : eReactiveLayerStateType.READY;
|
|
} else {
|
|
ioNumber = int.Parse(temp);
|
|
}
|
|
|
|
temp = cond[index++];
|
|
bool logic = bool.Parse(temp);
|
|
|
|
ConditionInfo necCond = new ConditionInfo(condType, machineState, ioNumber, logic);
|
|
necConds.Add(necCond);
|
|
}
|
|
|
|
}
|
|
|
|
return necConds;
|
|
}
|
|
|
|
public class ConditionInfo
|
|
{
|
|
public enum ConditionInfoName
|
|
{
|
|
ConditionType,
|
|
LogicType,
|
|
ioNumber,
|
|
EnumSize,
|
|
}
|
|
public enum eMachineStateType
|
|
{
|
|
IDLE, //초기화 전
|
|
READY, //초기화 후
|
|
RUN,
|
|
PAUSE,//일시 정지
|
|
HEAVYALARM, //Heavy Alarm
|
|
LIGHTALARM
|
|
}
|
|
public enum eConditionType { DI, DO, AI, AO, STATE }
|
|
|
|
eConditionType conditionType = eConditionType.STATE;
|
|
public eConditionType ConditionType {
|
|
get { lock (this) { return conditionType; } }
|
|
set { lock (this) { conditionType = value; } }
|
|
}
|
|
|
|
bool logicType = true;
|
|
public bool LogicType {
|
|
get { lock (this) { return logicType; } }
|
|
set { lock (this) { logicType = value; } }
|
|
}
|
|
public eReactiveLayerStateType machineState = eReactiveLayerStateType.IDLE;
|
|
public eReactiveLayerStateType MachineState {
|
|
get { lock (this) { return machineState; } }
|
|
set { lock (this) { machineState = value; } }
|
|
}
|
|
public int ioNumber = -1;
|
|
public int IoNumber {
|
|
get { lock (this) { return ioNumber; } }
|
|
set { lock (this) { ioNumber = value; } }
|
|
}
|
|
|
|
|
|
public ConditionInfo(eConditionType type, eReactiveLayerStateType state, int no, bool logic)
|
|
{
|
|
conditionType = type;
|
|
ioNumber = no;
|
|
machineState = state;
|
|
logicType = logic;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
public bool ConvertIOInfo(params string[] data)
|
|
{
|
|
try {
|
|
bool rv = false;
|
|
|
|
if (data.Length != (int)InfoName.EnumSize) {
|
|
throw new Exception("IO Data Length wrong!!");
|
|
}
|
|
|
|
int index = 0;
|
|
|
|
Index = int.Parse(data[index++]);
|
|
Address = data[index++];
|
|
ID = data[index++];
|
|
description = data[index++];
|
|
|
|
//string temp = data[index++];
|
|
//IoType iotype =
|
|
// temp == IoType.DI.ToString() ? IoType.DI :
|
|
// temp == IoType.DO.ToString() ? IoType.DO :
|
|
// temp == IoType.AI.ToString() ? IoType.AI : IoType.AO;
|
|
//IOType = iotype;
|
|
|
|
//temp = data[index++];
|
|
//ActiveLevelType activeLevel = temp == ActiveLevelType.High.ToString() ? ActiveLevelType.High : ActiveLevelType.Low;
|
|
//ActiveLevel = activeLevel;
|
|
|
|
//BoardNo = int.Parse(data[index++]);
|
|
//Description = data[index++];
|
|
|
|
//HighNecCond = GetConditionList(data[index++]);
|
|
//LowhNecCond = GetConditionList(data[index++]);
|
|
//HighSensor = GetConditionList(data[index++]);
|
|
//LowSensor = GetConditionList(data[index++]);
|
|
//WaitInterlockTimeout = int.Parse(data[index++]);
|
|
//WaitSensorTimeout = int.Parse(data[index++]);
|
|
//HighSufCond = GetConditionList(data[index++]);
|
|
//LowSufCond = GetConditionList(data[index++]);
|
|
|
|
rv = true;
|
|
|
|
return rv;
|
|
} catch {
|
|
throw;
|
|
}
|
|
|
|
}
|
|
}
|
|
|
|
public abstract class IOUnit
|
|
{
|
|
protected Logger Log = new Logger("IO_Unit");
|
|
protected IConnConfig _connConfig;
|
|
|
|
string ioMappingFolder = "";
|
|
public string IOMappingFolder {
|
|
get { lock (this) { return ioMappingFolder; } }
|
|
set { lock (this) { ioMappingFolder = value; } }
|
|
}
|
|
List<InfoIO> lstDI = new List<InfoIO>();
|
|
public List<InfoIO> ListDI {
|
|
get { lock (this) { return lstDI; } }
|
|
}
|
|
|
|
List<InfoIO> lstDO = new List<InfoIO>();
|
|
public List<InfoIO> ListDO {
|
|
get { lock (this) { return lstDO; } }
|
|
}
|
|
|
|
List<InfoIO> lstAI = new List<InfoIO>();
|
|
public List<InfoIO> ListAI {
|
|
get { lock (this) { return lstAI; } }
|
|
}
|
|
|
|
List<InfoIO> lstAO = new List<InfoIO>();
|
|
|
|
public List<InfoIO> ListAO {
|
|
get { lock (this) { return lstAO; } }
|
|
}
|
|
|
|
#region 추상함수 선언
|
|
public abstract int Open(string iP);
|
|
public abstract void Close();
|
|
public abstract int Initialize();
|
|
public abstract void Instance(string mappingFolder);
|
|
public abstract bool IsConnected();
|
|
|
|
public abstract int GetDICount();
|
|
public abstract int GetDOCount();
|
|
public abstract int GetAICount();
|
|
public abstract int GetAOCount();
|
|
public abstract int GetDoArray(ref bool[] array);
|
|
public abstract int GetDiArray(ref bool[] array);
|
|
|
|
public abstract int ReadDoBit(int index, ref bool bit);
|
|
public abstract int ReadDiBit(int index, ref bool bit);
|
|
public abstract bool ReadDoBit(int index);
|
|
|
|
public abstract bool ReadDiBit(int index);
|
|
public abstract int WriteDoBit(int index, bool bit);
|
|
public abstract void ClearList();
|
|
#endregion
|
|
|
|
public int GetDiIndex(string id)
|
|
{
|
|
int index = -1;
|
|
foreach (InfoIO io in ListDI) {
|
|
if (io.ID == id) {
|
|
return io.Index;
|
|
}
|
|
}
|
|
return index;
|
|
}
|
|
|
|
|
|
|
|
public int GetDoIndex(string id)
|
|
{
|
|
int index = -1;
|
|
foreach (InfoIO io in ListDO) {
|
|
if (io.ID == id) {
|
|
return io.Index;
|
|
}
|
|
}
|
|
|
|
return index;
|
|
}
|
|
|
|
|
|
public int GetAiIndex(string id)
|
|
{
|
|
int index = -1;
|
|
foreach (InfoIO io in ListAI) {
|
|
if (io.ID == id) {
|
|
return io.Index;
|
|
}
|
|
}
|
|
|
|
return index;
|
|
}
|
|
|
|
public int GetAoIndex(string id)
|
|
{
|
|
int index = -1;
|
|
foreach (InfoIO io in ListAO) {
|
|
if (io.ID == id) {
|
|
return io.Index;
|
|
}
|
|
}
|
|
|
|
return index;
|
|
}
|
|
|
|
public string GetDiID(int index)
|
|
{
|
|
return ListDI[index].ID;
|
|
}
|
|
public string GetDOID(int index)
|
|
{
|
|
return ListDO[index].ID;
|
|
}
|
|
public string GetAiID(int index)
|
|
{
|
|
return ListAI[index].ID;
|
|
}
|
|
public string GetAoID(int index)
|
|
{
|
|
return ListAO[index].ID;
|
|
}
|
|
public void InterruptCallbackFunction(int nModuleNo, uint uFlag)
|
|
{
|
|
uint uValue = 0;
|
|
|
|
int inputCounts = ListDI.Count;
|
|
|
|
CAXD.AxdiReadInportBit(nModuleNo, (int)uFlag, ref uValue);
|
|
|
|
if (uValue == 1) {
|
|
//Rising Edge
|
|
|
|
} else {
|
|
//Falling Edge
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
}
|