using MMCE_Test;
|
using System;
|
using System.Collections;
|
using System.Linq;
|
|
namespace SHARP_CLAS_UI
|
{
|
public class DI : Slave
|
{
|
#region Enum
|
#endregion
|
|
#region Property
|
public ushort Channel_Size { get; private set; }
|
|
public bool[] Status { get; private set; }
|
|
public uint Offset { get; private set; }
|
|
private uint datasize { get; set; }
|
#endregion
|
|
#region Construct
|
public DI(ushort Board_Id, ushort Device_Id, ushort Channel_Size, uint Offset = 0)
|
: base(Board_Id, Device_Id)
|
{
|
this.Channel_Size = Channel_Size;
|
this.Offset = Offset;
|
this.Status = new bool[Channel_Size];
|
this.datasize = (uint)Channel_Size / 8;
|
}
|
#endregion
|
|
#region Function
|
//B접이라 들어오는거랑 반대로.
|
public bool Get_Input()
|
{
|
try
|
{
|
byte[] recvdata = new byte[datasize];
|
NMCSDKLib.MC_STATUS mc;
|
mc = NMCSDKLib.MC_IO_READ(Board_Id, Device_Id, 1, Offset, datasize, recvdata);
|
if (mc == NMCSDKLib.MC_STATUS.MC_OK)
|
{
|
BitArray inputs = new BitArray(recvdata);
|
bool[] data;
|
data = new bool[inputs.Count];
|
int i = 0;
|
foreach (bool input in inputs)
|
{
|
data[i] = !input;
|
i++;
|
}
|
|
Array.Copy(data, Status, Status.Count());
|
return true;
|
}
|
else
|
{
|
throw new Exception($"BoardID : {Board_Id}, AxisID : {Device_Id}, " + mc.ToString());
|
}
|
}
|
catch (Exception ex)
|
{
|
//WriteExceptionLog(MethodBase.GetCurrentMethod().Name, ex);
|
return false;
|
}
|
}
|
#endregion
|
}
|
}
|