2026-01-26 18:56:53 +09:00

334 lines
10 KiB
C#

using Hermes;
using PAIX_NMF_DEV;
using System;
namespace AuroraIO.Vendor.PAIX
{
public class PAIXIO : IOUnit
{
short[] nDIPinStatus = new short[128];
short[] nDOPinStatus = new short[128];
int nDOPinCount = 0;
int nDIPinCount = 0;
short m_nDevNo = 0;
bool m_bDevConnect = false;
NMF.TNMF_ALL_STS tAllStatus = new NMF.TNMF_ALL_STS(); // 전체상태 구조체
NMF.TNMF_COMPO tDiCompo = new NMF.TNMF_COMPO(); // 장치구성정보 구조체
NMF.TNMF_COMPO tDoCompo = new NMF.TNMF_COMPO(); // 장치구성정보 구조체
//public enum ePDIAddress
//{
// EMOSwitchFront,
// EMOSwitchBack,
// DoorLockOpen1 = 4,
// DoorLockOpen2,
// DoorLockOpen3,
// DoorLockOpen4,
// DoorLockCloseMonitoring = 10,
// StartSwitch = 12,
// ResetSwitch,
// ModeKeyAuto,
// ModeKeyMaint,
// PanelTempAlarm,
// L2MotorMCOn = 19,
// FanAlarm5 = 21,
// FanAlarm6,
// FanAlarm7,
// FanAlarm8,
// MainN2Alarm = 30,
// MainCDAAlarm,
// DICount
//}
//public enum ePDOAddress
//{
// TowerLampREDOn,
// TowerLampYELLOWOn,
// TowerLampGREENOn,
// TowerLampBLUEOn,
// BuzzerOn,
// LaserOnLampOn,
// WorkLEDOn,
// ResetSwitchLamp = 9,
// SafetyDoorRelease = 11,
// ModeKeySolOn = 13,
// ChillerRemoteOn = 15,
// SeamWeldingOpticAirKnifeSol,
// SeamWeldingN2BlowSol = 18,
// DOCount
//}
//public enum ePCDIAddress
//{
// CLAMP_LEFT_FW_CY = 2,
// CLAMP_LEFT_BW_CY = 3,
// CLAMP_FRONT_FW_CY = 8,
// CLAMP_FRONT_BW_CY = 9,
// CLAMP_TOP_UP_CY = 17,
// CLAMP_TOP_DOWN_CY = 18,
// LASER_Ready = 25,
// LASER_Emission_On,
// LASER_Alarm,
// LASER_Warning,
// SCANNER_Laser_Enable,
// DICount
//}
//public enum ePCDOAddress
//{
// LASER_Pilot_Laser = 20,
// LASER_Emission_Enable,
// LASER_Alarm_Reset,
// CLAMP_LEFT_FW_SOL,
// CLAMP_LEFT_BW_SOL,
// CLAMP_FRONT_FW_SOL,
// CLAMP_FRONT_BW_SOL,
// CLAMP_TOP_UP_SOL,
// CLAMP_TOP_DOWN_SOL,
// SCANNER_Laser_Enable_Request = 29,
// DOCount
//}
//public enum ePTDIAddress
//{
// SUCTION_UP_CY = 2,
// SUCTION_DOWN_CY = 3,
// LASER_READY = 25,
// PROG_ACTIVE,
// PROG_COMPLETE,
// PILOT_LASER_IS_ON,
// LASER_WARNING_LAMP_IS_ON,
// DICount
//}
//public enum ePTDOAddress
//{
// LASER_READY_ENABLE = 19,
// PROG_BIT_0,
// PROG_BIT_1,
// PROG_BIT_2,
// PSTART_STATICAL,
// FAULT_EXE,
// PILOT_LASER_ON,
// SUCTION_UP_SOL = 30,
// SUCTION_DOWN_SOL,
// DOCount
//}
public override int Open(string iP)
{
string[] strIP = iP.Split('.');
short nRet;
short[] nIP = new short[4];
nIP[0] = Convert.ToInt16(strIP[0]);
nIP[1] = Convert.ToInt16(strIP[1]);
nIP[2] = Convert.ToInt16(strIP[2]);
m_nDevNo = Convert.ToInt16(strIP[3]);
//여기서 DIIP인지 DOIP인지 알수있는 방법이 없음.. 우선 아래처럼 해놓고 고민해보자
//string m_type = strIP[4];
//switch(m_type)
//{
// case "DI":
// m_nDiDevNo = Convert.ToInt16(strIP[3]);
// m_nDevNo = m_nDiDevNo;
// break;
// case "DO":
// m_nDoDevNo = Convert.ToInt16(strIP[3]);
// m_nDevNo = m_nDoDevNo;
// break;
//}
try {
//네트워크 연결 확인
nRet = NMF.nmf_PingCheck(m_nDevNo, nIP[0], nIP[1], nIP[2], 200);
if (nRet != 0) {
Log.E($"Ping Check Error DevNo : {m_nDevNo}, Error : {nRet}");
return E1.ARGUMENT;
}
// 장치 연결
nRet = NMF.nmf_Connect(m_nDevNo, nIP[0], nIP[1], nIP[2]);
if (nRet != 0) {
Log.E($"Connect Error DevNo : {m_nDevNo}, Error : {nRet}");
return E1.ARGUMENT;
}
m_bDevConnect = true;
return E1.OK;
} catch (Exception e) {
return E1.ARGUMENT;
}
}
public override void Close()
{
if (m_bDevConnect) {
NMF.nmf_Disconnect(m_nDevNo);
NMF.nmf_Disconnect(m_nDevNo);
m_bDevConnect = false;
}
}
public override int Initialize()
{
short nRet;
// 연결된 장치의 구성정보를 확인합니다.
try {
nRet = NMF.nmf_GetCompo(m_nDevNo, out tDiCompo);
nRet = NMF.nmf_GetCompo(m_nDevNo, out tDoCompo);
if (nRet == 0) {
//tCompo로 확인하는 코드 구현 필요
}
//LoadIOTable();
return E1.OK;
} catch (Exception e) {
return E1.ARGUMENT;
}
}
public override void Instance(string mappingFolder)
{
IOMappingFolder = mappingFolder;
//LoadIOTable();
}
public override bool IsConnected()
{
return m_bDevConnect;
}
public override int GetDICount()
{
try {
nDIPinCount = tDiCompo.nCntBrd[(int)NMF.Enmf_BoardType.nmf_btDI16] * 16 + tDiCompo.nCntBrd[(int)NMF.Enmf_BoardType.nmf_btDI8] * 8;
//nDIPinCount = 128;
return nDIPinCount;
} catch (Exception e) {
return E1.ARGUMENT;
}
}
public override int GetDOCount()
{
try {
nDOPinCount = tDoCompo.nCntBrd[(int)NMF.Enmf_BoardType.nmf_btDO16] * 16 + tDoCompo.nCntBrd[(int)NMF.Enmf_BoardType.nmf_btDO8] * 8;
//nDOPinCount = 128;
return nDOPinCount;
} catch (Exception e) {
return E1.ARGUMENT;
}
}
public override int GetAICount()
{
return 0;
}
public override int GetAOCount()
{
return 0;
}
public override int GetDoArray(ref bool[] array)
{
try {
short nRet;
//배열 개수가 128개로 고정되어 있을 듯
nRet = NMF.nmf_DOGet(m_nDevNo, nDOPinStatus);
array = new bool[nDOPinStatus.Length];
// nPinStatus 배열의 값을 bool 배열로 변환
for (int i = 0; i < nDOPinStatus.Length; i++) {
array[i] = nDOPinStatus[i] == 1;
}
return E1.OK;
} catch (Exception e) {
return E1.ARGUMENT;
}
}
public override int GetDiArray(ref bool[] array)
{
try {
short nRet;
//배열 개수가 128개로 고정되어 있을 듯
nRet = NMF.nmf_DIGet(m_nDevNo, nDIPinStatus);
array = new bool[nDIPinStatus.Length];
// nPinStatus 배열의 값을 bool 배열로 변환
for (int i = 0; i < nDIPinStatus.Length; i++) {
array[i] = nDIPinStatus[i] == 1;
}
return E1.OK;
} catch (Exception e) {
return E1.ARGUMENT;
}
}
public override int ReadDoBit(int index, ref bool bit)
{
try {
bool[] arrDI = new bool[128];
GetDoArray(ref arrDI);
bit = Convert.ToBoolean(arrDI[index]);
return E1.OK;
} catch (Exception e) {
return E1.ARGUMENT;
}
}
public override int ReadDiBit(int index, ref bool bit)
{
try {
bool[] arrDI = new bool[128];
GetDiArray(ref arrDI);
bit = Convert.ToBoolean(arrDI[index]);
return E1.OK;
} catch (Exception e) {
return E1.ARGUMENT;
}
}
public override bool ReadDoBit(int index)
{
try {
//PAIX는 Bit 1개 정보를 받아오는 API가 없음.. 전체 상태 받아와서 넘겨주자
bool[] arrDO = new bool[128];
GetDoArray(ref arrDO);
return Convert.ToBoolean(arrDO[index]);
} catch (Exception e) {
return false;
}
}
public override bool ReadDiBit(int index)
{
try {
//PAIX는 Bit 1개 정보를 받아오는 API가 없음.. 전체 상태 받아와서 넘겨주자
bool[] arrDI = new bool[128];
GetDiArray(ref arrDI);
return Convert.ToBoolean(arrDI[index]);
} catch (Exception e) {
return false;
}
}
public override int WriteDoBit(int index, bool bit)
{
try {
short data = Convert.ToInt16(bit);
short nPinNo = Convert.ToInt16(index);
int nRet = (int)NMF.nmf_DOSetPin(m_nDevNo, nPinNo, data);
if (nRet != 0) {
Log.E(string.Format($"Fail to WriteDoBit : {nRet}"));
return nRet;
}
return 0;
} catch (Exception e) {
return E1.ARGUMENT;
}
}
public override void ClearList()
{
ListDI.Clear();
ListDO.Clear();
}
}
}