configai.c
来自「采用MINIGUI开发的一套GUI界面」· C语言 代码 · 共 793 行 · 第 1/2 页
C
793 行
//SendMessage(gMainWnd,MSG_PAINT,0,0);
EndDialog (hDlg, 0);
}
}
break;
case MSG_CLOSE:
bai_dlg=0;
EndDialog (hDlg, 0);
break;
}
return DefaultDialogProc (hDlg, message, wParam, lParam);
}
void DlgConfAi(HWND hWnd)
{
bai_dlg = 1;
DlgDigitalAi.controls = CtrlDigitalAi;
DialogBoxIndirectParam (&DlgDigitalAi, hWnd, EventAiDialogProc, 0L);
}
void ConfAiInit(HWND hDlg)
{
int i;
int id;
int j;
unsigned char str[20];
const unsigned char *ai_set[]={"2000","1800","200","100"};
unsigned char *method[]={
"关闭","实时","平均","最小",
"最大"};
const unsigned char *ai_job1[]={
"开始记录","停止记录",
"记录报警","记录事件",
"启动蜂鸣","不动作"
};
const unsigned char *ai_job2[]={
"启动DO","关闭DO","DO程序",
"启动定时器1","关闭定时器1",
"启动定时器2","关闭定时器2",
"启动定时器3","关闭定时器3",
"启动定时器4","关闭定时器4",
"启动定时器5","关闭定时器5",
"启动定时器6","关闭定时器6",
"启动计数器1","关闭计数器1",
"启动计数器2","关闭计数器2",
"启动计数器3","关闭计数器3",
"启动计数器4","关闭计数器4",
"启动计数器5","关闭计数器5",
"启动计数器6","关闭计数器6",
"启动累加器","关闭累加器",
"报告登陆",
"不动作"
};
const unsigned char *speed[]={
"1秒","2秒" ,"5秒","10秒","30秒","60秒","120秒"
};
unsigned char *Hysteresls[]={
"关闭","启用"
};
for(i=0;i<4;i++)
{
sprintf(str,ai_set[i]);
SetDlgItemText(hDlg, AI_EDIT_SET1+i,str);
}
for(i=0;i<5;i++)
{
sprintf(str,method[i]);
SendMessage(GetDlgItem(hDlg,AI_BOX_METHOD),CB_ADDSTRING,0, (LPARAM)str) ;
}
for(i=0;i<7;i++)
{
sprintf(str,speed[i]);
SendMessage(GetDlgItem(hDlg,AI_BOX_SPEED),CB_ADDSTRING,0, (LPARAM)str) ;
}
for(i=0;i<4;i++)
{
for(j=0;j<7;j++)
{
sprintf(str,str_inittype[j]);
SendMessage(GetDlgItem(hDlg,AI_BOX_TYPE1+i),CB_ADDSTRING,0, (LPARAM)str) ;
}
}
for(i=0;i<4;i++)
{
for(j=0;j<6;j++)
{
sprintf(str,ai_job1[j]);
SendMessage(GetDlgItem(hDlg,AI_BOX_JOB11+i),CB_ADDSTRING,0, (LPARAM)str) ;
}
}
for(i=0;i<4;i++)
{
for(j=0;j<31;j++)
{
sprintf(str,ai_job2[j]);
SendMessage(GetDlgItem(hDlg,AI_BOX_JOB21+i),CB_ADDSTRING,0, (LPARAM)str) ;
}
}
for(i=0;i<4;i++)
{
for(j=0;j<2;j++)
{
sprintf(str,Hysteresls[j]);
SendMessage(GetDlgItem(hDlg,AI_BOX_RELAY1+i),CB_ADDSTRING,0, (LPARAM)str) ;
}
}
ai_id=0; //ai 配置页面,满12加1
id=ai_id;
focus_ai_bn=AI_BN1+id%12; //AI_BN1;
ai_bn_page=id/12;
ReadChanConf( hDlg);
}
/* 通道变量初始化
使用
*/
void ReadChanConf( HWND hWnd)
{
HDC hdc;
unsigned char str_resource[10];
unsigned char str_goal[10];
unsigned char str[10];
int value;
int id;
gal_pixel rect_color_back;
gal_pixel barcolor;
bzero(str,sizeof(str_resource));
//从文件中得到初始模拟和数学通道总数
GetIntValueFromEtcFile("system.conf", "MATH","Number",&value);
math_chan_sum=value;
GetIntValueFromEtcFile("system.conf", "AI","Number",&value);
ai_chan_sum=value;
gchannum=ai_chan_sum+math_chan_sum;
gchanpage_sum=(gchannum/PCHAN_MAX)+1;//总共页面数
gchanpage=1;//默认为第一个数字显示1个页面
//建立历史文件目录
hdc=GetClientDC(hWnd) ;
for (id=0;id<ai_chan_sum;id++)
{ //给显示块赋值颜色,TAG,unit
printf(channel_disp[id].data,"test");
channel_disp[id].color_old=RGB2Pixel(hdc,30,128,(id%7)*64);
channel_disp[id].color= channel_disp[id].color_old;
// channel_disp[id].color= PIXEL_darkblue ;//;//曲线颜色
sprintf(str_resource,"AI%d",(id+1));
GetValueFromEtcFile("system.conf", str_resource,"Name",str,20);
bzero(channel_conf[id].name,sizeof(channel_conf[id].name));
sprintf(channel_conf[id].name,"%s",str);
GetValueFromEtcFile("system.conf", str_resource,"Desc",str,20);
sprintf(channel_conf[id].desc,"%s",str);
GetValueFromEtcFile("system.conf", str_resource,"Unit",str,20);
bzero(channel_conf[id].unit,sizeof(channel_conf[id].unit));
sprintf(channel_conf[id].unit,"%s",str);
GetIntValueFromEtcFile("system.conf", str_resource,"LogMethod",&value);
channel_hist[id].record_type=value;
GetIntValueFromEtcFile("system.conf", str_resource,"LogSpeed",&value);
channel_conf[id].interval=value;
if(id==1)printf(" read .conf interval is %d \n",value);
GetValueFromEtcFile("system.conf", str_resource,"ZeroPoint",str,20);
channel_conf[id].offset=atof(str);
GetValueFromEtcFile("system.conf", str_resource,"Gain",str,20);
channel_conf[id].gain=atof(str);
GetValueFromEtcFile("system.conf", str_resource,"RangeLow",str,20);
channel_conf[id].low=atof(str);
GetValueFromEtcFile("system.conf", str_resource,"RangeHigh",str,20);
channel_conf[id].high=atof(str);
GetValueFromEtcFile("system.conf", str_resource,"AlertHH",str,20);
channel_conf[id].hh_alarm=atof(str);
GetValueFromEtcFile("system.conf", str_resource,"AlertH",str,20);
channel_conf[id].h_alarm=atof(str);
GetValueFromEtcFile("system.conf", str_resource,"AlertL",str,20);
channel_conf[id].l_alarm=atof(str);
GetValueFromEtcFile("system.conf", str_resource,"AlertLL",str,20);
channel_conf[id].ll_alarm=atof(str);
GetIntValueFromEtcFile("system.conf", str_resource,"ScaleHigh",&value);
channel_conf[id].h_limit=value;
GetIntValueFromEtcFile("system.conf", str_resource,"ScaleLow",&value);
channel_conf[id].l_limit=value;
channel_conf[id].hh_enabled=1;
channel_conf[id].h_enabled=1;
channel_conf[id].l_enabled=1;
channel_conf[id].ll_enabled=1;
SetupHistoryFile(id);//0通道 AI1
//开关机时重建历史记录索引
//初始化一下刚开始的值
channel_conf[id].ipv=2000;
channel_conf[id].dot=1;
}
ReleaseDC(hdc);
}
//当前通道的组态信息
int DispChanConf(HWND hDlg)
{
int id;
unsigned char str[20];
id= (focus_ai_bn-AI_BN1+ai_bn_page*12); //设置初始值
SetDlgItemText(hDlg, AI_EDIT_NAME,channel_conf[id].name);
SetDlgItemText(hDlg, AI_EDIT_DESC,channel_conf[id].desc);
SendDlgItemMessage(hDlg,AI_BOX_METHOD,CB_SETCURSEL,channel_hist[id].record_type,0);
SendDlgItemMessage(hDlg,AI_BOX_SPEED,CB_SETCURSEL,channel_conf[id].interval,0);
//将float 转换成字符串
sprintf(str,"%0.2f",channel_conf[id].offset);//等同于gcvt(channel_conf[id].offset,20,str);
SetDlgItemText(hDlg, AI_EDIT_OFFSET,str);
sprintf(str,"%0.2f",channel_conf[id].gain);
SetDlgItemText(hDlg, AI_EDIT_GAIN,str);
sprintf(str,"%0.2f",channel_conf[id].low);
SetDlgItemText(hDlg, AI_EDIT_LOW,str);
sprintf(str,"%0.2f",channel_conf[id].high);
SetDlgItemText(hDlg, AI_EDIT_HIGH,str );
sprintf(str,"%0.2f",channel_conf[id].hh_alarm);
SetDlgItemText(hDlg, AI_EDIT_SET1,str);
sprintf(str,"%0.2f",channel_conf[id].h_alarm);
SetDlgItemText(hDlg, AI_EDIT_SET2,str );
sprintf(str,"%0.2f",channel_conf[id].l_alarm);
SetDlgItemText(hDlg, AI_EDIT_SET3,str);
sprintf(str,"%0.2f",channel_conf[id].ll_alarm);
SetDlgItemText(hDlg, AI_EDIT_SET4,str);
SetValue(AI_BOX_JOB11,channel_conf[id].line1_job1);
SetValue(AI_BOX_JOB12,channel_conf[id].line2_job1);
SetValue(AI_BOX_JOB13,channel_conf[id].line3_job1);
SetValue(AI_BOX_JOB14,channel_conf[id].line4_job1);
SetValue(AI_BOX_JOB21,channel_conf[id].line1_job2);
SetValue(AI_BOX_JOB22,channel_conf[id].line2_job2);
SetValue(AI_BOX_JOB23,channel_conf[id].line3_job2);
SetValue(AI_BOX_JOB24,channel_conf[id].line4_job2);
SetValue(AI_BOX_RELAY1,channel_conf[id].hh_relay);
SetValue(AI_BOX_RELAY2,channel_conf[id].h_relay);
SetValue(AI_BOX_RELAY3,channel_conf[id].l_relay);
SetValue(AI_BOX_RELAY4,channel_conf[id].ll_relay);
return 1;
}
//保存当前通道的组态信息
int WriteChanInfo(HWND hDlg)
{
int id;
int p;
int box_index;
unsigned char str[20];
id= (focus_ai_bn-AI_BN1+ai_bn_page*12);
if(id>gchannum) return 0;
ai_id=id;
GetDlgItemText(hDlg,AI_EDIT_NAME,str,4);
sprintf(channel_conf[id].name,str);
GetDlgItemText(hDlg,AI_EDIT_DESC,str,16);
sprintf(channel_conf[id].desc,str);
box_index=SendDlgItemMessage(hDlg,AI_BOX_METHOD,CB_GETCURSEL,0,0);
channel_hist[id].record_type=box_index;
printf("record type=%d\n",box_index);
box_index=SendDlgItemMessage(hDlg,AI_BOX_SPEED,CB_GETCURSEL,0,0);
channel_conf[id].interval=box_index;
//当记录方式有通道启动与关闭更换时
//若存在本通道的历史文件则
//更新索引,否则建立历史文件
channel_conf[id].offset= atof(GetDlgItemText2(hDlg,AI_EDIT_OFFSET,&p));
channel_conf[id].gain= atof(GetDlgItemText2(hDlg,AI_EDIT_GAIN,&p));
channel_conf[id].low= atof(GetDlgItemText2(hDlg,AI_EDIT_LOW,&p));
channel_conf[id].high= atof(GetDlgItemText2(hDlg,AI_EDIT_HIGH,&p));
channel_conf[id].hh_alarm= atof(GetDlgItemText2(hDlg,AI_EDIT_SET1,&p));
channel_conf[id].h_alarm= atof(GetDlgItemText2(hDlg,AI_EDIT_SET2,&p));
channel_conf[id].l_alarm= atof(GetDlgItemText2(hDlg,AI_EDIT_SET3,&p));
channel_conf[id].ll_alarm= atof(GetDlgItemText2(hDlg,AI_EDIT_SET4 ,&p));
channel_conf[id].line1_job1= SendDlgItemMessage(hDlg,AI_BOX_JOB11,CB_GETCURSEL,0,0);
channel_conf[id].line2_job1= SendDlgItemMessage(hDlg,AI_BOX_JOB12,CB_GETCURSEL,0,0);
channel_conf[id].line3_job1= SendDlgItemMessage(hDlg,AI_BOX_JOB13,CB_GETCURSEL,0,0);
channel_conf[id].line4_job1= SendDlgItemMessage(hDlg,AI_BOX_JOB14,CB_GETCURSEL,0,0);
channel_conf[id].line1_job2= SendDlgItemMessage(hDlg,AI_BOX_JOB21,CB_GETCURSEL,0,0);
channel_conf[id].line2_job2= SendDlgItemMessage(hDlg,AI_BOX_JOB22,CB_GETCURSEL,0,0);
channel_conf[id].line3_job2= SendDlgItemMessage(hDlg,AI_BOX_JOB23,CB_GETCURSEL,0,0);
channel_conf[id].line4_job2= SendDlgItemMessage(hDlg,AI_BOX_JOB24,CB_GETCURSEL,0,0);
channel_conf[id].hh_relay= SendDlgItemMessage(hDlg,AI_BOX_RELAY1,CB_GETCURSEL,0,0);
channel_conf[id].h_relay= SendDlgItemMessage(hDlg,AI_BOX_RELAY2 ,CB_GETCURSEL,0,0);
channel_conf[id].l_relay= SendDlgItemMessage(hDlg,AI_BOX_RELAY3 ,CB_GETCURSEL,0,0);
channel_conf[id].ll_relay= SendDlgItemMessage(hDlg,AI_BOX_RELAY4,CB_GETCURSEL,0,0);
return 1;
}
//存入文件
void SaveAiData(HWND hDlg)
{
int first_id;
int i;
int p;
int box_index;
unsigned char str_resource[10];
unsigned char str_goal[10];
int id;
int j;
bzero(str_resource,sizeof(str_resource));
first_id=0;
for(id=first_id;id<first_id+ai_chan_sum;id++)
{
sprintf(str_resource,"AI%d",(id+1));
sprintf(str_goal,"%d",channel_conf[id].name);
SetValueToEtcFile("system.conf",str_resource,"Name",str_goal);
sprintf(str_goal,"%d",channel_conf[id].desc);
SetValueToEtcFile("system.conf",str_resource,"Desc",str_goal);
// sprintf(str_goal,"%d",channel_conf[id].enable);
// SetValueToEtcFile("system.conf",str_resource,"Enable",str_goal);
sprintf(str_goal,"%d",channel_conf[id].interval);
SetValueToEtcFile("system.conf",str_resource,"LogSpeed",str_goal);
sprintf(str_goal,"%d",channel_hist[id].record_type);
SetValueToEtcFile("system.conf",str_resource,"LogMethod",str_goal);
sprintf(str_goal,"%d",channel_conf[id].formation);
SetValueToEtcFile("system.conf",str_resource,"Formation",str_goal);
sprintf(str_goal,"%d",channel_conf[id].unit);
SetValueToEtcFile("system.conf",str_resource,"Unit",str_goal);
sprintf(str_goal,"%d",channel_conf[id].low);
SetValueToEtcFile("system.conf",str_resource,"RangeLow",str_goal);
sprintf(str_goal,"%d",channel_conf[id].high);
SetValueToEtcFile("system.conf",str_resource,"RangeHigh",str_goal);
sprintf(str_goal,"%d",channel_conf[id].h_alarm);
SetValueToEtcFile("system.conf",str_resource,"AlertH",str_goal);
sprintf(str_goal,"%d",channel_conf[id].hh_alarm);
SetValueToEtcFile("system.conf",str_resource,"AlertHH",str_goal);
sprintf(str_goal,"%d",channel_conf[id].ll_alarm);
SetValueToEtcFile("system.conf",str_resource,"AlertLL",str_goal);
sprintf(str_goal,"%d",channel_conf[id].l_alarm);
SetValueToEtcFile("system.conf",str_resource,"AlertL",str_goal);
sprintf(str_goal,"%d",channel_conf[id].line1_job1);
SetValueToEtcFile("system.conf",str_resource,"Job11",str_goal);
sprintf(str_goal,"%d",channel_conf[id].line2_job1);
SetValueToEtcFile("system.conf",str_resource,"Job12",str_goal);
sprintf(str_goal,"%d",channel_conf[id].line3_job1);
SetValueToEtcFile("system.conf",str_resource,"Job13",str_goal);
sprintf(str_goal,"%d",channel_conf[id].line4_job1);
SetValueToEtcFile("system.conf",str_resource,"Job14",str_goal);
sprintf(str_goal,"%d",channel_conf[id].line1_job2);
SetValueToEtcFile("system.conf",str_resource,"Job21",str_goal);
sprintf(str_goal,"%d",channel_conf[id].line2_job2);
SetValueToEtcFile("system.conf",str_resource,"Job22",str_goal);
sprintf(str_goal,"%d",channel_conf[id].line3_job2);
SetValueToEtcFile("system.conf",str_resource,"Job23",str_goal);
sprintf(str_goal,"%d",channel_conf[id].line4_job2);
SetValueToEtcFile("system.conf",str_resource,"Job24",str_goal);
sprintf(str_goal,"%d",channel_conf[id].hh_relay);
SetValueToEtcFile("system.conf",str_resource,"Offset1",str_goal);
sprintf(str_goal,"%d",channel_conf[id].h_relay);
SetValueToEtcFile("system.conf",str_resource,"Offset2",str_goal);
sprintf(str_goal,"%d",channel_conf[id].l_relay);
SetValueToEtcFile("system.conf",str_resource,"Offset3",str_goal);
sprintf(str_goal,"%d",channel_conf[id].ll_relay);
SetValueToEtcFile("system.conf",str_resource,"Offset4",str_goal);
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?