為云臺(tái)控制的按鈕關(guān)聯(lián)CStageButton類變量,并在對(duì)話框初始化時(shí)從INI文件中讀取云臺(tái)參數(shù)信息,并設(shè)置Com端口。代碼如下:
m_ButtonUp.m_Type = ctUp; //向上
m_ButtonDown.m_Type = ctDown; //向下
m_ButtonLeft.m_Type = ctLeft; //向左
m_ButtonRight.m_Type = ctRight; //向右
m_InFoci.m_Type = ctInFoci; //聚焦減
m_ReFoci.m_Type = ctReFoci; //聚焦增
m_InLen.m_Type = ctInLen; //對(duì)焦減
m_ReLen.m_Type = ctReLen; //對(duì)焦增
m_InAperture.m_Type = ctInAperture; //光圈減
m_ReAperture.m_Type = ctReAperture; //光圈增
m_InBrush.m_Type = ctInBrush; //畫筆減
m_ReBrush.m_Type = ctReBrush; //畫筆增
m_Len = GetPrivateProfileInt("使用字節(jié)數(shù)","字節(jié)數(shù)",8,"./stage.ini"); //獲得云臺(tái)協(xié)議使用的字節(jié)數(shù)
m_ActoinCount = GetPrivateProfileInt("控制項(xiàng)","控制數(shù)",13,"./stage.ini"); //獲得云臺(tái)的控制動(dòng)作數(shù)
m_pData = new unsigned char[m_ActoinCount][MAXNUM];
m_Port = GetPrivateProfileInt("端口設(shè)置","端口號(hào)",1,"./stage.ini"); //獲得端口號(hào)
GetPrivateProfileString("端口設(shè)置","環(huán)境設(shè)置","9600,n,8,1",
m_Setting.GetBuffer(0),MAX_PATH,"./stage.ini"); //獲得環(huán)境設(shè)置
int data;
char buff[20] = {0};
char var[20] = {0};
for (int i = 0 ; i<m_ActoinCount ; i++)
{
for (int j = 0 ; j <m_Len; j++)
{
char section[20] = "字節(jié)";
itoa(i+1,var,10);
itoa(j+1,buff,10);
strcat(section,buff);
data = GetPrivateProfileInt(var,section,0,"./stage.ini"); //獲得各個(gè)按鈕的字節(jié)數(shù)
m_pData[i][j] = data;
}
}
m_Com.SetSettings(m_Setting); //設(shè)置端口信息,并打開端口
m_Com.SetOutBufferSize(512); //設(shè)置輸出緩沖區(qū)大小
m_Com.SetCommPort(m_Port); //設(shè)置端口號(hào)
m_Com.SetSThreshold(0); //設(shè)置傳輸緩沖區(qū)允許的最小字符
m_Com.SetPortOpen(TRUE); //打開串口