這可以在不需要連CA-210的情況之下,讓軟體可以執行並且進入量測畫面相關的部份(若使用Ca210real則一定要有儀器才可以連線,否則程式會停止執行)方便Demo展示以及加快debug速度,但是唯一無法利用這個類別進行debug的功能,就是nits追縱量測。
Ca210sim .h
#ifndef CA210SIM_H
#define CA210SIM_H
#include "CA210.h"
class Ca210sim : public Ca210
{
Bullet* m_pIProbe;
//simulation setup dialog item
SynMode m_syncMode;
DisPlay m_displayMode;
DisDigits m_displayDigits;
AvgMode m_averageMide;
BrigUnit m_brightnessUnit;
CalStand m_calStandard;
CaState m_caState;
CaState m_caStateTemp;
CString str;
CString ImpsbStr;
//////////////////////////////////////////////////////////////////////////
void MsgFrmt(CException* , const CString&, const CString&){};
void MsgFrmt(const CString&){};
public:
Ca210sim();
virtual ~Ca210sim();
public:
const CaState CalZero();
const CaState Measure();
void LinkMemory();
const MsrAiState MsrAI(const float& MsrDeviation = 0.0513); //any constant value
void SetOnline(const BOOL& b = TRUE);
const BOOL isOnline() const { return m_caState == CA_Offline ? FALSE : TRUE; };
const CString GetLcmSize();
const CString GetChData();
const Bullet GetMsrData();
//for setup Dialog Value
const float GetRangeColor1() const;
const float GetRangeColor2() const;
const float GetRangeFAM() const;
void SetChId(const LPCTSTR &) { };
const CString GetChId() const { return "SimCh"; };
const CString GetChId(const long &) const { return "SimCh"; };
void SetChNo(const long &) { };
const CString GetChStrNo() { return "0"; };
const long GetChNo() const { return 0; };
const CString GetProb() const { return "8115678"; };
const CString GetDeviceType() const { return "SimCA-210"; };
const CString GetCaVersion() const { return "Simulator"; };
const CString GetRefProbe() const;
const CString GetCalProbe() const;
const CString GetCalMode() const;
const CString GetRefLv() const;
const CString GetRefSx() const;
const CString GetRefSy() const;
//for setup dialog combo box ItemString
const CString GetSynMode (const SynMode&) const;
const CString GetDisplayMode (const DisPlay&) const;
const CString GetDisplayDigits(const DisDigits&) const;
const CString GetAvgingMode (const AvgMode&) const;
const CString GetBrigUnit (const BrigUnit&) const;
const CString GetCalStandard (const CalStand&) const;
//Get and Set of CA-SDK
void SetSynMode (const SynMode&); const float GetSynMode() const;
void SetDisplayMode (const DisPlay&); const long GetDisplayMode() const;
void SetDisplayDigits(const DisDigits&); const long GetDisplayDigits() const;
void SetAvgingMode (const AvgMode&); const long GetAvgingMode() const;
void SetBrigUnit (const BrigUnit&); const long GetBrigUnit() const;
void SetCalStandard (const CalStand&); const long GetCalStandard() const;
#ifdef _CA210DEBUG
const CString getSetupValue() const;
void debugMessageBox(const CString&) const;
#endif
private: //for setup CA-SDK parameter
const float chooseSynMode (const SynMode&) const;
const int chooseDisplayMode (const DisPlay&) const;
const int chooseDisplayDigits(const DisDigits&) const;
const int chooseAvgingMode (const AvgMode&) const;
const int chooseBrigUnit (const BrigUnit&) const;
const int chooseCalStandard (const CalStand&) const;
};
#endif
Ca210sim .cpp
模擬抓值
量測這一個動作主要就是將量測值「生」出來。在此使用rand()生出這些值,所生出來的值只是模擬動作,並不能取代量測的動作,因為,不管你現在是什麼畫面,值都會差不多。
const CaState Ca210sim::Measure()
{
CaState Mode = m_caState;
if(isOnline())
{
// Make Data for m_pIProbe;
srand(time(NULL));
m_pIProbe->i(VluK_Lv, (rand()%100000)/100.0); //%3.2f
m_pIProbe->i(VluK_Sx, (rand()%10000 +1)/10000.0); //%1.4f
m_pIProbe->i(VluK_Sy, (rand()%10000 +1)/10000.0); //%1.4f
m_pIProbe->i(VluK_T, rand()%1000);//%3d
m_pIProbe->i(VluK_Duv, (rand()%100000)/10000); //%1.4f
m_pIProbe->i(VluK_Du, (rand()%100000)/10000.0); //%1.4f
m_pIProbe->i(VluK_Dv, (rand()%100000)/10000.0); //%1.4f
m_pIProbe->i(VluK_X, (rand()%100000)/100.0); //%3.2f
m_pIProbe->i(VluK_Y, (rand()%100000)/100.0); //%3.2f
m_pIProbe->i(VluK_Z, (rand()%100000)/100.0); //%3.2f
}
return Mode;
}
自動抓值量測
為了互動上的設計,出現了一種自己判斷目前是否可以抓值的程式段,降低使用者使用時操作的IO設備以及降低操作人手。
const MsrAiState Ca210sim::MsrAI(const 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->oFlt(VluK_X);
YFristValue = m_pIProbe->oFlt(VluK_Y);
ZFristValue = m_pIProbe->oFlt(VluK_Z);
Measure();
//誤差取絕對值
deltaX = ((XFristValue-m_pIProbe->oFlt(VluK_X))>=0) ? XFristValue - m_pIProbe->oFlt(VluK_X) : m_pIProbe->oFlt(VluK_X) - XFristValue;
deltaY = ((YFristValue-m_pIProbe->oFlt(VluK_Y))>=0) ? YFristValue - m_pIProbe->oFlt(VluK_Y) : m_pIProbe->oFlt(VluK_Y) - YFristValue;
deltaZ = ((ZFristValue-m_pIProbe->oFlt(VluK_Z))>=0) ? ZFristValue - m_pIProbe->oFlt(VluK_Z) : m_pIProbe->oFlt(VluK_Z) - ZFristValue;
deltaAll = deltaX * deltaY * deltaZ;
if (deltaAll < MsrDeviation ) return MA_InDeviation;
else return MA_OutDeviation;
}
else
return MA_nonMsr;
}
沒有留言:
張貼留言