为云台控制的按钮关联CStageButton类变量,并在对话框初始化时从INI文件中读取云台参数信息,并设置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("使用字节数","字节数",8,"./stage.ini"); //获得云台协议使用的字节数
m_ActoinCount = GetPrivateProfileInt("控制项","控制数",13,"./stage.ini"); //获得云台的控制动作数
m_pData = new unsigned char[m_ActoinCount][MAXNUM];
m_Port = GetPrivateProfileInt("端口设置","端口号",1,"./stage.ini"); //获得端口号
GetPrivateProfileString("端口设置","环境设置","9600,n,8,1",
m_Setting.GetBuffer(0),MAX_PATH,"./stage.ini"); //获得环境设置
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] = "字节";
itoa(i+1,var,10);
itoa(j+1,buff,10);
strcat(section,buff);
data = GetPrivateProfileInt(var,section,0,"./stage.ini"); //获得各个按钮的字节数
m_pData[i][j] = data;
}
}
m_Com.SetSettings(m_Setting); //设置端口信息,并打开端口
m_Com.SetOutBufferSize(512); //设置输出缓冲区大小
m_Com.SetCommPort(m_Port); //设置端口号
m_Com.SetSThreshold(0); //设置传输缓冲区允许的最小字符
m_Com.SetPortOpen(TRUE); //打开串口