-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathCA210real.cpp
665 lines (595 loc) · 16.6 KB
/
CA210real.cpp
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
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
#include "stdafx.h"
#include "Ca210real.h"
#include <cstdlib>
#include <ctime>
#ifdef _CA210DEBUG
#define DebugCode( code_fragment ) { code_fragment }
#else
#define DebugCode( code_fragment )
#endif
//虛擬函數的初始化,還是要初始父類別指標,所以連線函數必須移走,不可以放在共同的部份!
//不然就是做一個共同的基礎類別。
Ca210real::Ca210real():
ImpsbStr("1. 按「Prt Scm鍵」抓下目前的螢幕,並開小畫家貼上,另存成圖檔\n2. Mail給此程式設計者,詳細描述使用過程並將圖檔存成附件\n這是尚未預測到出現的問題。(應該不會發生的那種。)"),
m_pICa200(0), m_pICa(0), m_pIProbe(0), m_pIProbeInfo(0), m_pIMemory(0)
{
DebugCode( DBugModeBox("TRUE of Ca210real()"); )
if (initCreatCa200())
if (initConnectCa210())
if (initAttachCa())
if (initAttchProbe())
m_caState = CA_not_yet_ZeroCal;
}
Ca210real::~Ca210real()
{
DebugCode( DBugModeBox("TRUE of ~Ca210real()"); )
if (isOnline())
SetOnline(FALSE);
m_pIMemory->DetachDispatch(); delete m_pIMemory;
m_pIProbeInfo->DetachDispatch(); delete m_pIProbeInfo;
m_pIProbe->DetachDispatch(); delete m_pIProbe;
m_pICa->DetachDispatch(); delete m_pICa;
m_pICa200->ReleaseDispatch(); delete m_pICa200;
}
const BOOL Ca210real::initCreatCa200()
{
try
{
if (m_pICa200 == 0)
m_pICa200 = new ICa200();
m_pICa200->CreateDispatch("CA200Srvr.Ca200.1");
return TRUE;
}
catch (CException* e)
{
MsgFrmt(e, "CreatCa200();出問題", "1. 檢查USB線和量筒\n2. 按確定");
m_pICa200->ReleaseDispatch();
return FALSE;
}
}
const BOOL Ca210real::initConnectCa210()
{
try
{
m_pICa200->m_bAutoRelease = TRUE;
m_pICa200->AutoConnect();
return TRUE;
}
catch (CException* e)
{
MsgFrmt(e, "LPDISPATCH pICa = m_pICa200->ConnectCa210();出問題", ImpsbStr);
m_pICa200->ReleaseDispatch();
return FALSE;
}
}
const BOOL Ca210real::initAttachCa()
{
try
{
if (m_pICa == 0)
m_pICa = new ICa();
LPDISPATCH pICa(0);
pICa = m_pICa200->GetSingleCa();
m_pICa->AttachDispatch(pICa);
return TRUE;
}
catch (CException* e)
{
MsgFrmt(e, "LPDISPATCH pICa = m_pICa200->GetSingleCa();出問題", ImpsbStr);
m_pICa200->ReleaseDispatch();
return FALSE;
}
}
const BOOL Ca210real::initAttchProbe()
{
try
{
if (m_pIProbe == 0) m_pIProbe = new IProbe();
if (m_pIProbeInfo == 0) m_pIProbeInfo = new IProbeInfo();
LPDISPATCH pIProbe(0);
pIProbe = m_pICa->GetSingleProbe();
m_pIProbe->AttachDispatch(pIProbe);
m_pIProbeInfo->AttachDispatch(pIProbe);
return TRUE;
}
catch (CException* e)
{
MsgFrmt(e, "LPDISPATCH pIProbe = m_pICa->GetSingleProbe();出問題", ImpsbStr);
m_pICa->DetachDispatch();
m_pICa200->ReleaseDispatch();
return FALSE;
}
}
const CaState Ca210real::CalZero()
{
/*
連線 實機
caes 11 執行ZeroCal
例外處理:
給MessageBox
再執行ZeroCal
default 回傳FALSE 無法執行
*/
if (isOnline())
{
DebugCode( DBugModeBox("TRUE of CalZero()"); )
int flag(0);
do
{
try
{
m_pICa->CalZero();
flag = 0;
}
catch (CException* e)
{
if (flag < 1)
MsgFrmt(e,"將套筒還沒轉至0-Cal就執行Zero Cal", "1. 將量測筒轉至0-Cal檔。\n2. 按「確定」");
else
MsgFrmt("1. 將量測筒轉至0-Cal檔。\n2. 按「確定」");
SetOnline();
flag++;
}
} while (flag);
return m_caState = CA_ZeroCalMode;
}
else
{
DebugCode( DBugModeBox("CalZero() Offline."); )
return m_caState = CA_Offline;
}
}
void Ca210real::LinkMemory()
{
if (isOnline())
{
DebugCode( DBugModeBox("TRUE of LinkMemory()"); )
try
{
if (m_pIMemory == 0)
m_pIMemory = new IMemory();
LPDISPATCH pMemory(0);
pMemory = m_pICa->GetMemory();
m_pIMemory->AttachDispatch(pMemory);
}
catch (CException* e)
{
MsgFrmt(e, "LinkMemory(pMemory);出問題", ImpsbStr);
}
}
DebugCode( else{ DBugModeBox("FALSE of LinkMemory()"); } )
}
const CaState Ca210real::Measure()
{
CaState Mode = m_caState;
if(isOnline())
{
DebugCode( DBugModeBox("TRUE of Measure()"); )
int flag = 0;
do
{
try
{
m_pICa->Measure(0);
//已經ZeroCal,檢查檔位是否正確
if (m_pIProbe->GetLv() < 0.01)
Mode = CA_ZeroCalMode; //is0-Cal檔
else
Mode = CA_MsrMode; //已ZeroCal, 檔位正確
flag = 0;
}
catch (CException* e)
{
//MsrError
SetOnline();
if (m_caState == CA_not_yet_ZeroCal) //還沒ZeroCal
{
if (CalZero() == CA_Offline)
Mode = CA_Offline;
++flag;
}
else
{
TCHAR buf[255];
e->GetErrorMessage(buf, 255);
++flag;
if (flag > 10)
//重覆太多次,導致類當機的情況。
break;
else
//在這不做任何動作,重覆執行迴圈內的東西。
continue;
}
}
} while (flag);
}
return Mode;
}
const MsrAiState Ca210real::MsrAI(const float& MsrDeviation)
{
DebugCode( DBugModeBox("TRUE of MsrAI(float MsrDeviation)"); )
//第一筆資料暫存空間 //宣告誤差值計算空間
float XFristValue = 0.0, deltaX = 0.0,
YFristValue = 0.0, deltaY = 0.0,
ZFristValue = 0.0, deltaZ = 0.0, deltaAll;
if ( Measure() == CA_MsrMode )
{
//抓參考值
XFristValue = m_pIProbe->GetX();
YFristValue = m_pIProbe->GetY();
ZFristValue = m_pIProbe->GetZ();
if ( Measure() == CA_MsrMode )
{
//誤差取絕對值
deltaX = ((XFristValue-m_pIProbe->GetX()) >= 0) ? XFristValue - m_pIProbe->GetX() : m_pIProbe->GetX() - XFristValue;
deltaY = ((YFristValue-m_pIProbe->GetY()) >= 0) ? YFristValue - m_pIProbe->GetY() : m_pIProbe->GetY() - YFristValue;
deltaZ = ((ZFristValue-m_pIProbe->GetZ()) >= 0) ? ZFristValue - m_pIProbe->GetZ() : m_pIProbe->GetZ() - ZFristValue;
deltaAll = deltaX * deltaY * deltaZ;
if (deltaAll < MsrDeviation ) return MA_InDeviation;//門檻值內
else return MA_OutDeviation;//門檻值外
}
else
return MA_nonMsr;
}
else
return MA_nonMsr;
//無效量測,可能是沒連線之類的
}
void Ca210real::SetOnline(const BOOL& isOnline)
{
DebugCode( DBugModeBox("TRUE of SetOnline(BOOL isOnline)"); )
try
{
m_pICa->SetRemoteMode(isOnline);
}
catch (CException* e)
{
MsgFrmt(e, "連線/離線出問題", ImpsbStr);
}
if (isOnline == FALSE)
{
m_caStateTemp = m_caState;
m_caState = CA_Offline;
}
else
m_caState = m_caStateTemp; //真的沒問題嗎?
}
const CString Ca210real::GetLcmSize()
{
if(isOnline())
{
DebugCode( DBugModeBox("TRUE of GetLcmSize()"); )
try
{
if (m_LCMsize.IsEmpty())
m_LCMsize.Format("%s", m_pIMemory->GetChannelID().Left(2));
}
catch (CException* e)
{
MsgFrmt(e, "模組尺寸大小設定出問題", ImpsbStr);
m_LCMsize.Format("-1");
}
}
else
m_LCMsize.Format("-1");
return m_LCMsize;
}
const CString Ca210real::GetChData()// const
{
CString temp;
if(isOnline())
{
try
{
DebugCode(
CString str;
str.Format("%s of GetChData()", m_Online ? "TRUE" : "FALSE");
DBugModeBox(str);
)
temp.Format("%ld - %s", m_pIMemory->GetChannelNO(), m_pIMemory->GetChannelID());
}
catch (CException* e)
{
MsgFrmt(e, "從CA-210抓Channel的資料出來出問題", ImpsbStr);
}
}
else
temp.Format("已離線 - 無頻道");
return temp;
}
const Bullet Ca210real::GetMsrData()
{
if (isOnline())
{
DebugCode( DBugModeBox("TRUE of GetMsrData()"); )
try
{
m_blt.i(VluK_Lv, m_pIProbe->GetLv());
m_blt.i(VluK_Sx, m_pIProbe->GetSx());
m_blt.i(VluK_Sy, m_pIProbe->GetSy());
m_blt.i(VluK_T, m_pIProbe->GetT());
m_blt.i(VluK_Duv, m_pIProbe->GetDuv());
m_blt.i(VluK_Du, m_pIProbe->GetUd());
m_blt.i(VluK_Dv, m_pIProbe->GetVd());
m_blt.i(VluK_X, m_pIProbe->GetX());
m_blt.i(VluK_Y, m_pIProbe->GetY());
m_blt.i(VluK_Z, m_pIProbe->GetZ());
}
catch (CException* e)
{
MsgFrmt(e, "從CA-210讀取量測值出問題", ImpsbStr);
}
}
return m_blt;
}
//////////////////////////////////////////////////////////////////////////
const float Ca210real::GetRangeColor1() const
{
float clr1, clr2;
m_pICa->GetAnalogRange(&clr1, &clr2);
return clr1;
}
const float Ca210real::GetRangeColor2() const
{
float clr1, clr2;
m_pICa->GetAnalogRange(&clr1, &clr2);
return clr2;
}
const float Ca210real::GetRangeFAM() const
{
float FMA;
m_pICa->GetFMAAnalogRange(&FMA);
return FMA;
}
const CString Ca210real::GetRefSx() const
{
float Lv, Sx, Sy;
m_pIMemory->GetReferenceColor(m_pIProbe->GetId(), &Sx, &Sy, &Lv);
CString strSx;
strSx.Format("%1.4f", Sx);
return strSx;
}
const CString Ca210real::GetRefSy() const
{
float Lv, Sx, Sy;
m_pIMemory->GetReferenceColor(m_pIProbe->GetId(), &Sx, &Sy, &Lv);
CString strSy;
strSy.Format("%1.4f", Sy);
return strSy;
}
const CString Ca210real::GetRefLv() const
{
float Lv, Sx, Sy;
m_pIMemory->GetReferenceColor(m_pIProbe->GetId(), &Sx, &Sy, &Lv);
CString strLv;
strLv.Format("%f", Lv);
return strLv;
}
const CString Ca210real::GetRefProbe() const
{
long CalProbe, RefProbe, CalMode;
m_pIMemory->GetMemoryStatus(m_pIProbe->GetNumber(), &CalProbe, &RefProbe, &CalMode);
CString str;
str.Format("%ld", RefProbe);
return str;
}
const CString Ca210real::GetCalProbe() const
{
long CalProbe, RefProbe, CalMode;
m_pIMemory->GetMemoryStatus(m_pIProbe->GetNumber(), &CalProbe, &RefProbe, &CalMode);
CString str;
str.Format("%ld", CalProbe);
return str;
}
const CString Ca210real::GetCalMode() const
{
long CalProbe, RefProbe, CalMode;
m_pIMemory->GetMemoryStatus(m_pIProbe->GetNumber(), &CalProbe, &RefProbe, &CalMode);
CString str;
str.Format("%ld", CalMode);
return str;
}
//////////////////////////////////////////////////////////////////////////
void Ca210real::SetSynMode(const SynMode& SmType)
{
m_pICa->SetSyncMode(chooseSynMode(SmType));
}
const float Ca210real::chooseSynMode(const SynMode& SmType) const
{
switch(SmType)
{
case SM_NTSC: return 0.0;
case SM_PAL: return 1.0;
case SM_EXT: return 2.0;
case SM_UNIV: return 3.0;
case SM_INT: return 4.0;
default: return -1.0;
}
}
const CString Ca210real::GetSynMode(const SynMode& SmType) const
{
switch(SmType)
{
case SM_NTSC: return "NTSC";
case SM_PAL: return "PAL";
case SM_EXT: return "EXT";
case SM_UNIV: return "UNIV";
case SM_INT: return "INT";
default: return "No this Mode";
}
}
const float Ca210real::GetSynMode() const
{
return m_pICa->GetSyncMode();
}
//////////////////////////////////////////////////////////////////////////
void Ca210real::SetDisplayMode(const DisPlay& DpType)
{
m_pICa->SetDisplayMode(chooseDisplayMode(DpType));
}
const int Ca210real::chooseDisplayMode(const DisPlay& DpType) const
{
return (int)DpType;
}
const CString Ca210real::GetDisplayMode(const DisPlay& DpType) const
{
switch(DpType)
{
case DP_Lvxy: return "xyLv";
case DP_duvT: return "duvTLv"; //return "duvT";
case DP_Analyzer_NoDisplay: return "RGB"; //return "Analyzer mode";
case DP_Analyzer_Gstand: return "RGB(G)"; //return "Analyzer mode(G)";
case DP_Analyzer_Rstand: return "RGB(R)"; //return "Analyzer mode(R)";
case DP_dudv: return "u'v'Lv'"; //return "u'v'";
case DP_FMA: return "FMA";
case DP_XYZ: return "XYZ";
case DP_JEITA: return "JEITA";
default: return "No this Mode";
}
}
const long Ca210real::GetDisplayMode() const
{
return m_pICa->GetDisplayMode();
}
//////////////////////////////////////////////////////////////////////////
void Ca210real::SetDisplayDigits(const DisDigits& DdType)
{
m_pICa->SetDisplayDigits(chooseDisplayDigits(DdType));
}
const int Ca210real::chooseDisplayDigits(const DisDigits& DdType) const
{
switch(DdType)
{
case DD_3DisDigits: return 0;
case DD_4DisDigits: return 1;
default: return -1;
}
}
const CString Ca210real::GetDisplayDigits(const DisDigits& DdType) const
{
switch(DdType)
{
case DD_3DisDigits: return "3";
case DD_4DisDigits: return "4";
default: return "Out of SPEC";
}
}
const long Ca210real::GetDisplayDigits() const
{
return m_pICa->GetDisplayDigits();
}
//////////////////////////////////////////////////////////////////////////
void Ca210real::SetAvgingMode(const AvgMode& AmType)
{
m_pICa->SetAveragingMode(chooseAvgingMode(AmType));
}
const int Ca210real::chooseAvgingMode(const AvgMode& AmType) const
{
switch(AmType)
{
case AM_SLOW: return 0;
case AM_FAST: return 1;
case AM_AUTO: return 2;
default: return -1;
}
}
const CString Ca210real::GetAvgingMode(const AvgMode& AmType) const
{
switch(AmType)
{
case AM_SLOW: return "Slow";
case AM_FAST: return "Fast";
case AM_AUTO: return "Auto";
default: return "No this Mode";
}
}
const long Ca210real::GetAvgingMode() const
{
return m_pICa->GetAveragingMode();
}
//////////////////////////////////////////////////////////////////////////
void Ca210real::SetBrigUnit(const BrigUnit& BuType)
{
m_pICa->SetBrightnessUnit(chooseBrigUnit(BuType));
}
const int Ca210real::chooseBrigUnit(const BrigUnit& BuType) const
{
switch(BuType)
{
case BU_fL: return 0;
case BU_cdm2: return 1;
default: return -1;
}
}
const CString Ca210real::GetBrigUnit(const BrigUnit& BuType) const
{
switch(BuType)
{
case BU_fL: return "fL";
case BU_cdm2: return "cd/m2";
default: return "No this Unit";
}
}
const long Ca210real::GetBrigUnit() const
{
return m_pICa->GetBrightnessUnit();
}
//////////////////////////////////////////////////////////////////////////
void Ca210real::SetCalStandard(const CalStand& CsType)
{
m_pICa->SetCalStandard(chooseCalStandard(CsType));
}
const int Ca210real::chooseCalStandard(const CalStand& CsType) const
{
switch(CsType)
{
case CS_6500K: return 1;
case CS_9300K: return 2;
default: return -1;
}
}
const CString Ca210real::GetCalStandard(const CalStand& CsType) const
{
switch(CsType)
{
case CS_6500K: return "6500K";
case CS_9300K: return "9300K";
default: return "Out of SPEC";
}
}
const long Ca210real::GetCalStandard() const
{
return m_pICa->GetCalStandard();
}
//////////////////////////////////////////////////////////////////////////
//設定警告標示的標準格式
void Ca210real::MsgFrmt(CException* e, const CString& mean, const CString& steps)
{
CString str;
TCHAR buf[255];
e->GetErrorMessage(buf, 255);
str.Format("糟糕!!!出現ERROR!!!\n\n原廠錯誤訊息:\n%s\n\n看不懂沒關係,意思就是:\n「%s」\n\n你只要做:\n%s", buf, mean, steps);
AfxMessageBox(str);
}
void Ca210real::MsgFrmt(const CString& steps)
{
CString str;
str.Format("你發呆嗎?\n%s", steps);
AfxMessageBox(str);
}
//////////////////////////////////////////////////////////////////////////
//debug function
#ifdef _CA210DEBUG
CString Ca210real::GetSetupValue() const
{
CString str;
str.Format("連線:%d, 實機:%d, ZeroCal了沒:%d", m_Online, m_isTrue, m_isZeroCal);
return str;
}
void Ca210real::debugMessageBox(const CString& str) const
{
CString strTemp;
strTemp.Format("%s\n%s模式, %s", str, m_isTrue?"真實":"模擬", m_Online?"連線":"離線");
AfxMessageBox(strTemp);
}
#endif