正文

主窗體設計(25)

Visual C++項目開發(fā)案例全程實錄(第2版) 作者:明日科技


 

為云臺控制的按鈕關聯(lián)CStageButton類變量,并在對話框初始化時從INI文件中讀取云臺參數(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;   //對焦減

m_ReLen.m_Type       = ctReLen;  //對焦增

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"); //獲得云臺協(xié)議使用的字節(jié)數(shù)

m_ActoinCount = GetPrivateProfileInt("控制項","控制數(shù)",13,"./stage.ini"); //獲得云臺的控制動作數(shù)

m_pData = new  unsigned char[m_ActoinCount][MAXNUM];

m_Port = GetPrivateProfileInt("端口設置","端口號",1,"./stage.ini"); //獲得端口號

GetPrivateProfileString("端口設置","環(huán)境設置","9600,n,8,1", 

m_Setting.GetBuffer(0),MAX_PATH,"./stage.ini"); //獲得環(huán)境設置

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"); //獲得各個按鈕的字節(jié)數(shù)

m_pData[i][j] = data;

}

}

m_Com.SetSettings(m_Setting); //設置端口信息,并打開端口

m_Com.SetOutBufferSize(512); //設置輸出緩沖區(qū)大小

m_Com.SetCommPort(m_Port); //設置端口號

m_Com.SetSThreshold(0);  //設置傳輸緩沖區(qū)允許的最小字符

m_Com.SetPortOpen(TRUE);  //打開串口


上一章目錄下一章

Copyright ? 讀書網(wǎng) www.afriseller.com 2005-2020, All Rights Reserved.
鄂ICP備15019699號 鄂公網(wǎng)安備 42010302001612號