EmulationIO.cs
3.2 KB
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
using System.Collections.Generic;
namespace TSA_V.DeviceLibrary
{
internal class EmulationIO : IOBase
{
/// <summary>
/// 所有DI状态
/// </summary>
public bool[] DIstate = new bool[128];
/// <summary>
/// 所有DO状态
/// </summary>
public bool[] DOstate = new bool[128];
public override void CloseAllConnection()
{
}
public override void CloseAllDO()
{
}
public override void ConnectionIP(string kNDIP, ushort kNDPort)
{
for(int i = 0; i < DIstate.Length; i++)
{
DIstate[i] = false ;
}
for (int i = 0; i < DOstate.Length; i++)
{
DOstate[i] = false;
}
}
public override void ConnectionKND(List<string> dIODeviceNameList)
{
}
private bool WriteDO(int index,bool v)
{
if(DOstate.Length>index)
{
DOstate[index] = v;
return true;
}
return false;
}
public override void WriteSingleDO(string deviceName, byte slaveId, ushort index, IO_VALUE value, int time)
{
WriteDO(index, value == IO_VALUE.HIGH);
}
public override bool IsConnection(string kNDIP)
{
return true ;
}
public override void WriteSingleDO(string deviceName, byte slaveId, ushort index, IO_VALUE value)
{
WriteDO(index, value == IO_VALUE.HIGH);
}
public override IO_VALUE GetDIValue(string deviceName, byte slaveID, ushort v)
{
if (v < DIstate.Length)
return DIstate[v] ? IO_VALUE.HIGH : IO_VALUE.LOW;
else
return IO_VALUE.LOW;
}
public override IO_VALUE GetDOValue(string deviceName, byte slaveID, ushort v)
{
if (v < DOstate.Length)
return DOstate[v] ? IO_VALUE.HIGH : IO_VALUE.LOW;
else
return IO_VALUE.LOW;
}
public override IO_VALUE GetIOValue(ConfigIO configIO)
{
if (configIO.ProType.Equals(ConfigItemType.DI))
{
if (configIO.IOIndex < DIstate.Length)
return DIstate[configIO.IOIndex] ? IO_VALUE.HIGH : IO_VALUE.LOW;
else
return IO_VALUE.LOW;
}
else
{
if (configIO.IOIndex < DOstate.Length)
return DOstate[configIO.IOIndex] ? IO_VALUE.HIGH : IO_VALUE.LOW;
else
return IO_VALUE.LOW;
}
}
public override void ReadAllDI(string deviceName, byte slaveId)
{
}
public override void ReadAllDO(string deviceName, byte slaveId)
{
}
public override void WriteSingleDI(string deviceName, byte slaveId, ushort index, IO_VALUE value)
{
if (DIstate.Length > index)
{
DIstate[index] = value.Equals(IO_VALUE.HIGH);
}
}
}
}