using MMCE_Test;
|
using System;
|
|
namespace SHARP_CLAS_UI
|
{
|
public class IO_Manager
|
{
|
public IO_Manager()
|
{
|
|
}
|
|
public bool Set_Output(OutputData data, bool check)
|
{
|
try
|
{
|
OutputAxis axis;
|
|
string[] names = Enum.GetNames(typeof(OutputAxis));
|
|
int slave = (int)data / 32;
|
int row = (int)data % 32;
|
|
Enum.TryParse(names[slave], out axis);
|
|
if (0 <= row && row < 32)
|
{
|
uint Offset = 0;
|
byte bit_offset = 0;
|
|
Offset = (uint)row / 8;
|
bit_offset = BitConverter.GetBytes(row % 8)[0];
|
|
NMCSDKLib.MC_STATUS mc;
|
mc = NMCSDKLib.MC_IO_WRITE_BIT(0, (ushort)axis, Offset, bit_offset, check);
|
|
if (mc == NMCSDKLib.MC_STATUS.MC_OK)
|
return true;
|
else
|
throw new Exception($"BoardID : {0}, AxisID : {axis}, " + mc.ToString());
|
}
|
else
|
throw new Exception($"BoardID : {0}, AxisID : {axis}, bit({row}) range over.");
|
}
|
catch (Exception ex)
|
{
|
return false;
|
}
|
}
|
|
public bool Get_Output(OutputData data)
|
{
|
try
|
{
|
OutputAxis axis;
|
bool check = false;
|
|
string[] names = Enum.GetNames(typeof(OutputAxis));
|
|
int slave = (int)data / 32;
|
int row = (int)data % 32;
|
|
Enum.TryParse(names[slave], out axis);
|
|
if (0 <= row && row < 32)
|
{
|
uint Offset = 0;
|
byte bit_offset = 0;
|
|
Offset = (uint)row / 8;
|
bit_offset = BitConverter.GetBytes(row % 8)[0];
|
|
NMCSDKLib.MC_STATUS mc;
|
mc = NMCSDKLib.MC_IO_READ_BIT(0, (ushort)axis, 0, Offset, bit_offset, ref check);
|
|
if (mc == NMCSDKLib.MC_STATUS.MC_OK)
|
{
|
return check;
|
}
|
else
|
throw new Exception($"BoardID : {0}, AxisID : {axis}, " + mc.ToString());
|
}
|
else
|
throw new Exception($"BoardID : {0}, AxisID : {axis}, bit({row}) range over.");
|
}
|
catch (Exception ex)
|
{
|
return false;
|
}
|
}
|
|
public bool Try_Get_Output(OutputData data, out bool check)
|
{
|
check = false;
|
|
try
|
{
|
OutputAxis axis;
|
|
string[] names = Enum.GetNames(typeof(OutputAxis));
|
|
int slave = (int)data / 32;
|
int row = (int)data % 32;
|
|
Enum.TryParse(names[slave], out axis);
|
if (0 <= row && row < 32)
|
{
|
uint Offset = 0;
|
byte bit_offset = 0;
|
|
Offset = (uint)row / 8;
|
bit_offset = BitConverter.GetBytes(row % 8)[0];
|
|
NMCSDKLib.MC_STATUS mc;
|
mc = NMCSDKLib.MC_IO_READ_BIT(0, (ushort)axis, 0, Offset, bit_offset, ref check);
|
|
if (mc == NMCSDKLib.MC_STATUS.MC_OK)
|
{
|
return true;
|
}
|
else
|
throw new Exception($"BoardID : {0}, AxisID : {axis}, " + mc.ToString());
|
}
|
else
|
throw new Exception($"BoardID : {0}, AxisID : {axis}, bit({row}) range over.");
|
}
|
catch (Exception ex)
|
{
|
return false;
|
}
|
}
|
|
//Input은 B접.
|
public bool Get_Input(InputData data)
|
{
|
try
|
{
|
InputAxis axis;
|
|
bool check = false;
|
|
string[] names = Enum.GetNames(typeof(InputAxis));
|
|
int slave = (int)data / 32;
|
int row = (int)data % 32;
|
|
Enum.TryParse(names[slave], out axis);
|
|
if (0 <= row && row < 32)
|
{
|
uint Offset = 0;
|
byte bit_offset = 0;
|
|
Offset = (uint)row / 8;
|
bit_offset = BitConverter.GetBytes(row % 8)[0];
|
|
NMCSDKLib.MC_STATUS mc;
|
mc = NMCSDKLib.MC_IO_READ_BIT(0, (ushort)axis, 1, Offset, bit_offset, ref check);
|
|
if (mc == NMCSDKLib.MC_STATUS.MC_OK)
|
{
|
return !check;
|
}
|
else
|
throw new Exception($"BoardID : {0}, AxisID : {axis}, " + mc.ToString());
|
}
|
else
|
throw new Exception($"BoardID : {0}, AxisID : {axis}, bit({row}) range over.");
|
}
|
catch (Exception ex)
|
{
|
return false;
|
}
|
}
|
|
//Input은 B접.
|
public bool Try_Get_Input(InputData data, out bool check)
|
{
|
check = false;
|
|
try
|
{
|
InputData axis;
|
|
string[] names = Enum.GetNames(typeof(InputData));
|
|
int slave = (int)data / 32;
|
int row = (int)data % 32;
|
|
Enum.TryParse(names[slave], out axis);
|
|
if (0 <= row && row < 32)
|
{
|
uint Offset = 0;
|
byte bit_offset = 0;
|
|
Offset = (uint)row / 8;
|
bit_offset = BitConverter.GetBytes(row % 8)[0];
|
|
NMCSDKLib.MC_STATUS mc;
|
mc = NMCSDKLib.MC_IO_READ_BIT(0, (ushort)axis, 1, Offset, bit_offset, ref check);
|
|
check = !check;
|
if (mc == NMCSDKLib.MC_STATUS.MC_OK)
|
{
|
return true;
|
}
|
else
|
throw new Exception($"BoardID : {0}, AxisID : {axis}, " + mc.ToString());
|
}
|
else
|
throw new Exception($"BoardID : {0}, AxisID : {axis}, bit({row}) range over.");
|
}
|
catch (Exception ex)
|
{
|
return false;
|
}
|
}
|
}
|
}
|