천호석
2022-06-17 4de9ea98e13449174aa2cd09c8351fc0e978f44a
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
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
    }
}