LTT Source에 들어가는 Module Dll
장정호
2020-12-15 dd4a016ef8fc5cae0cbd336a5bdec4651b1d87c1
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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
using log4net;
using System;
using System.Collections.Generic;
using System.IO.Ports;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
 
namespace DIT.Framework.Module._01_SerialModules
{
    /// <summary>
    /// Model : IVC 3000 , 3100 Module
    /// Home : www.isvt.co.kr
    /// </summary>
    class IVC3000 : SerialModule
    {
        private enum Read_Cmd
        {
            SystemPressure,
            ThrottleValvePos,
            MFCFlow,
            MFCOpen,
            MFCSetFlow,
            MFCRange,
            State,
        }
 
        /// <summary>
        /// Exception Log
        /// </summary>
        private ILog ExceptionLog = LogManager.GetLogger("IVC3000_Exception");
 
        /// <summary>
        /// Exception Log를 기록하기 위한 메서드
        /// </summary>
        /// <param name="msg">Error Message</param>
        private void WriteExceptionLog(string msg)
        {
            if (UseExceptionLog)
                ExceptionLog.Debug(msg);
        }
 
        /// <summary>
        /// System Pressure (atm)
        /// </summary>
        public string Pressure { get { return pressure; } private set { pressure = value; } }
        private string pressure;
 
        /// <summary>
        /// Throttle Vavle Current Point
        /// </summary>
        public string VlvPos { get { return vlvPos; } private set { vlvPos = value; } }
        private string vlvPos;
 
        /// <summary>
        /// MFC Flow Range
        /// </summary>
        public string MFCRange { get { return mfcRange; } private set { mfcRange = value; } }
        private string mfcRange;
 
        /// <summary>
        /// MFC Set Flow
        /// </summary>
        public string MFCSetFlow { get { return mfcSetFlow; } private set { mfcSetFlow = value; } }
        private string mfcSetFlow;
 
        /// <summary>
        /// MFC Current Flow
        /// </summary>
        public string MFCFlow { get { return mfcFlow; } private set { mfcFlow = value; } }
        private string mfcFlow;
 
        /// <summary>
        /// MFC Open State
        /// </summary>
        public bool MFCOpen { get { return mfcOpen; } private set { mfcOpen = value; } }
        private bool mfcOpen;
 
        /// <summary>
        /// Autonics_PMC_2HS의 생성자.
        /// </summary>
        /// <param name="PortName"> Port이름 ex)COM6, COM13 </param>
        /// <param name="BaudRate"> 전송속도 ex)4800, 9600, 19200 </param>
        /// <param name="DataBits"> 바이트 당 데이터 비트의 표준길이 ex)5, 6, 7, 8 </param>
        /// <param name="Parity">패리티 검사 프로토콜 ex)Ports.Parity.None </param>
        /// <param name="StopBits">비트당 정지비트의 표준 개수 ex)Ports.StopBits.One </param>
        /// <param name="Handshake">직렬 전송을 위한 핸드셰이킹 ex)Ports.Handshake.None</param>
        public IVC3000(string PortName, int BaudRate, int DataBits = 8, Parity Parity = Parity.None, StopBits StopBits = StopBits.One, Handshake Handshake = Handshake.None)
            : base(PortName, BaudRate, DataBits, Parity, StopBits, Handshake)
        {
            Pressure = "0";
            VlvPos = "0";
            MFCRange = "0";
            MFCSetFlow = "0";
            MFCFlow = "0";
            MFCOpen = false;
        }
 
        /// <summary>
        /// Serial에서 받은 명령어 처리 메서드
        /// </summary>
        /// <param name="recvData">Recv받은 Data</param>
        private void OnRecvData(Read_Cmd ReadCmd, byte[] recvData)
        {
            try
            {
                string str = Encoding.ASCII.GetString(recvData);
 
                switch (ReadCmd)
                {
                    case Read_Cmd.SystemPressure:
                        string[] _sSplitPressue = str.Replace("+", "\r").Split('P');
                        Pressure = (Convert.ToDouble(_sSplitPressue[1]) * 10).ToString();
                        break;
                    case Read_Cmd.ThrottleValvePos:
                        string[] _sSplitVlvPos = str.Replace("+", "\r").Split('V');
                        VlvPos = (Convert.ToDouble(_sSplitVlvPos[1])).ToString();
                        break;
                    case Read_Cmd.MFCFlow:
                        string[] sSplitMFCFlow = str.Split('+');
                        MFCFlow = (int.Parse(MFCRange) * Convert.ToDouble(sSplitMFCFlow[1]) / 100).ToString();
                        break;
                    case Read_Cmd.MFCOpen:
                        MFCOpen = str.Substring(2, 1) == "1" ? true : false;
                        break;
                    case Read_Cmd.MFCSetFlow:
                        MFCSetFlow = (int.Parse(MFCRange) * double.Parse(str.Split('+')[1]) / 100).ToString();
                        break;
                    case Read_Cmd.MFCRange:
                        MFCRange = str.Split('+')[1];
                        break;
                    default:
                        break;
                }
            }
            catch(Exception e)
            {
                WriteExceptionLog(e.Message);
            }
        }
 
        /// <summary>
        /// System Pressure(atm) Request 
        /// </summary>
        public void Request_SystemPressure()
        {
            try
            {
                byte[] cmd = Encoding.ASCII.GetBytes($"R5{CR}");
 
                byte[] recvData = SendWaitData(cmd);
 
                if (recvData == null)
                    return;
 
                OnRecvData(Read_Cmd.SystemPressure, recvData);
            }
            catch (Exception e)
            {
                WriteExceptionLog(e.Message);
            }
        }
 
        /// <summary>
        /// Throttle Valve Position Request
        /// </summary>
        public void Request_ThrottleValvePos()
        {
            try
            {
                byte[] cmd = Encoding.ASCII.GetBytes($"R6{CR}");
 
                byte[] recvData = SendWaitData(cmd);
 
                if (recvData == null)
                    return;
 
                OnRecvData(Read_Cmd.ThrottleValvePos, recvData);
            }
            catch (Exception e)
            {
                WriteExceptionLog(e.Message);
            }
        }
 
        /// <summary>
        /// MFC Current Flow Request
        /// </summary>
        public void Request_MFCFlow()
        {
            try
            {
                byte[] cmd = Encoding.ASCII.GetBytes($"R61{CR}");
 
                byte[] recvData = SendWaitData(cmd);
 
                if (recvData == null)
                    return;
 
                OnRecvData(Read_Cmd.MFCFlow, recvData);
            }
            catch (Exception e)
            {
                WriteExceptionLog(e.Message);
            }
        }
 
        /// <summary>
        /// MFC Open State Request
        /// </summary>
        public void Request_MFCOpen()
        {
            try
            {
                byte[] cmd = Encoding.ASCII.GetBytes($"R69{CR}");
 
                byte[] recvData = SendWaitData(cmd);
 
                if (recvData == null)
                    return;
 
                OnRecvData(Read_Cmd.MFCOpen, recvData);
            }
            catch (Exception e)
            {
                WriteExceptionLog(e.Message);
            }
        }
 
        /// <summary>
        /// MFC Set Flow Request
        /// </summary>
        public void Request_MFCSet()
        {
            try
            {
                byte[] cmd = Encoding.ASCII.GetBytes($"R65{CR}");
 
                byte[] recvData = SendWaitData(cmd);
 
                if (recvData == null)
                    return;
 
                OnRecvData(Read_Cmd.MFCSetFlow, recvData);
            }
            catch (Exception e)
            {
                WriteExceptionLog(e.Message);
            }
        }
 
        /// <summary>
        /// MFC Flow Range Request
        /// </summary>
        public void Request_MFCRange()
        {
            try
            {
                byte[] cmd = Encoding.ASCII.GetBytes($"R70{CR}");
 
                byte[] recvData = SendWaitData(cmd);
 
                if (recvData == null)
                    return;
 
                OnRecvData(Read_Cmd.MFCRange, recvData);
            }
            catch (Exception e)
            {
                WriteExceptionLog(e.Message);
            }
        }
        
        /// <summary>
        /// Throttle Valve Set Pos 명령어
        /// </summary>
        /// <param name="Pos">Point</param>
        public void SetValvePos(string Pos)
        {
            try
            {
                int pos = 0;
                int.TryParse(Pos, out pos);
 
                SET_ThrottleVlvPointType(1, 0);
                SET_ThrottleVlvPoint(1, pos);
                RUN_ThrottleVlvPoint(1);
            }
            catch (Exception e)
            {
                WriteExceptionLog(e.Message);
            }
        }
 
        /// <summary>
        /// Throttle Valve Set - Point에 대한 Type
        /// </summary>
        /// <param name="iCh">Chanel 1 ~ 5</param>
        /// <param name="Type"> 0 : Position, 1 : Pressure</param>
        public void SET_ThrottleVlvPointType(int iCh, int Type)
        {
            try
            {
                SendData($"T{iCh}{Type}{CR}");
            }
            catch (Exception e)
            {
                WriteExceptionLog(e.Message);
            }
        }
 
        /// <summary>
        /// Throttle Valve Set Point iCh
        /// </summary>
        /// <param name="iCh">Chanel 1 ~ 5</param>
        /// <param name="Point">Set Point 1 ~ 100</param>
        public void SET_ThrottleVlvPoint(int iCh, int Point)
        {
            SendData($"S{iCh}{Point}{CR}");
        }
 
        /// <summary>
        /// Throttle Vavle Run iCh
        /// </summary>
        /// <param name="iCh">Chanel 1 ~ 5</param>
        public void RUN_ThrottleVlvPoint(int iCh)
        {
            SendData($"D{iCh}{CR}");
        }
 
        /// <summary>
        /// MFC Open 명령어
        /// </summary>
        /// <param name="open"></param>
        public void RUN_MFCOpen(bool open)
        {
            SET_MFCType(5, 2);
 
            SET_MFCValveOpen(1, open);
        }
 
        /// <summary>
        /// MFC Type Set
        /// </summary>
        /// <param name="iCh">Chanel 5 ~ 8</param>
        /// <param name="Type">1 : SCCM, 2 : SLM</param>
        public void SET_MFCType(int iCh, int Type)
        {
            SendData($"W{iCh} {Type}{CR}");
        }
 
        /// <summary>
        /// SET MFC Valve Open
        /// </summary>
        /// <param name="iCh">Chanel 1 ~ 4 </param>
        /// <param name="open">true : Oepn, False : Close</param>
        public void SET_MFCValveOpen(int iCh, bool open)
        {
            string sopen = open ? "1" : "0";
 
            SendData($"L{iCh}{sopen}{CR}");
        }
    }
}