configmath.c

来自「采用MINIGUI开发的一套GUI界面」· C语言 代码 · 共 692 行 · 第 1/2 页

C
692
字号

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
#include <pwd.h>
#include <math.h>
#include <minigui/common.h>
#include <minigui/minigui.h>
#include <minigui/gdi.h>
#include <minigui/window.h>
#include <minigui/control.h>
#include <sys/types.h>
#include <sys/shm.h>
#include <sys/ipc.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include "common.h"
#include "configmath.h"


// 当前通道的组态信息
int  ReadMathInfo(HWND hDlg,int id2)
{
	int id;
	int value;
  	unsigned char str[20];
	unsigned char str_resource[20];
	//设置初始值
	id=id2;
//id= (math_focus_bn-MATH_BN1+1+math_bn_page*12)+math_chan_sum;
if(id>gchannum) return 0;

  	sprintf(str_resource,"MATH%d",(id-ai_chan_sum+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);
	GetValueFromEtcFile("system.conf", str_resource,"Formation",str,30);  
	sprintf(channel_conf[id].formation,"%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);
	


	SetDlgItemText(hDlg, ME_NAME,channel_conf[id].name);
   	SetDlgItemText(hDlg, ME_DESC,channel_conf[id].desc);
	SendDlgItemMessage(hDlg,MB_ENABLE,CB_SETCURSEL,channel_conf[id].enable,0);
	SendDlgItemMessage(hDlg,MB_METHOD,CB_SETCURSEL,channel_hist[id].record_type,0);
	SendDlgItemMessage(hDlg,MB_SPEED,CB_SETCURSEL,channel_conf[id].interval,0);
	SetDlgItemText(hDlg, ME_UNIT,channel_conf[id].unit);

	SetDlgItemText(hDlg, ME_FORM,channel_conf[id].formation);
	
sprintf(str,"%0.2f",channel_conf[id].low);
  	SetDlgItemText(hDlg, ME_LOW,str);
sprintf(str,"%0.2f",channel_conf[id].high);
  	SetDlgItemText(hDlg, ME_HIGH,str );
sprintf(str,"%0.2f",channel_conf[id].hh_alarm);
  	SetDlgItemText(hDlg, ME_SET1,str);
sprintf(str,"%0.2f",channel_conf[id].h_alarm);
  	SetDlgItemText(hDlg, ME_SET2,str );
sprintf(str,"%0.2f",channel_conf[id].ll_alarm);
  	SetDlgItemText(hDlg, ME_SET3,str);
sprintf(str,"%0.2f",channel_conf[id].ll_alarm);
  	SetDlgItemText(hDlg, ME_SET4,str);

SetValue(MA_Y1_JOB1,channel_conf[id].line1_job1);
SetValue(MA_Y2_JOB1,channel_conf[id].line2_job1);
SetValue(MA_Y3_JOB1,channel_conf[id].line3_job1);
SetValue(MA_Y4_JOB1,channel_conf[id].line4_job1);
SetValue(MA_Y1_JOB2,channel_conf[id].line1_job2);
SetValue(MA_Y2_JOB2,channel_conf[id].line2_job2);
SetValue(MA_Y3_JOB2,channel_conf[id].line3_job2);
SetValue(MA_Y4_JOB2,channel_conf[id].line4_job2);
SetValue(MB_DELAY1,channel_conf[id].hh_relay);
SetValue(MB_DELAY2,channel_conf[id].h_relay);
SetValue(MB_DELAY3,channel_conf[id].l_relay);
SetValue(MB_DELAY4,channel_conf[id].ll_relay);

return 1;
}

//保存当前通道的组态信息
int  WriteMathInfo(HWND hDlg,int id2)
{
int id;
int p;
int box_index;
unsigned char str[20];
id=id2;
if(id>gchannum) return 0;

     GetDlgItemText(hDlg,ME_NAME,str,4);
     sprintf(channel_conf[id].name,str);
	 
     GetDlgItemText(hDlg,ME_DESC,str,16);
     sprintf(channel_conf[id].desc,str);
	 
	  GetDlgItemText(hDlg,ME_UNIT,str,6);
     sprintf(channel_conf[id].unit,str);	 

	box_index=SendDlgItemMessage(hDlg,MB_METHOD,CB_GETCURSEL,0,0);
	channel_hist[id].record_type=box_index;

	box_index=SendDlgItemMessage(hDlg,MB_METHOD,CB_GETCURSEL,0,0);
	channel_conf[id].enable=box_index;

	box_index=SendDlgItemMessage(hDlg,MB_SPEED,CB_GETCURSEL,0,0);
	channel_conf[id].interval=box_index;
	

 
  channel_conf[id].low= atof(GetDlgItemText2(hDlg,ME_LOW,&p));
  channel_conf[id].high= atof(GetDlgItemText2(hDlg,ME_HIGH,&p));


channel_conf[id].hh_alarm= atof(GetDlgItemText2(hDlg,ME_SET1,&p));
channel_conf[id].h_alarm= atof(GetDlgItemText2(hDlg,ME_SET2,&p));
channel_conf[id].l_alarm= atof(GetDlgItemText2(hDlg,ME_SET3,&p));
channel_conf[id].ll_alarm= atof(GetDlgItemText2(hDlg,ME_SET4 ,&p));

channel_conf[id].line1_job1= SendDlgItemMessage(hDlg,MA_Y1_JOB1,CB_GETCURSEL,0,0);
channel_conf[id].line2_job1= SendDlgItemMessage(hDlg,MA_Y2_JOB1,CB_GETCURSEL,0,0);
channel_conf[id].line3_job1= SendDlgItemMessage(hDlg,MA_Y3_JOB1,CB_GETCURSEL,0,0);
channel_conf[id].line4_job1= SendDlgItemMessage(hDlg,MA_Y4_JOB1,CB_GETCURSEL,0,0);

channel_conf[id].line1_job2= SendDlgItemMessage(hDlg,MA_Y1_JOB1,CB_GETCURSEL,0,0);
channel_conf[id].line2_job2= SendDlgItemMessage(hDlg,MA_Y2_JOB2,CB_GETCURSEL,0,0);
channel_conf[id].line3_job2= SendDlgItemMessage(hDlg,MA_Y3_JOB2,CB_GETCURSEL,0,0);
channel_conf[id].line4_job2= SendDlgItemMessage(hDlg,MA_Y4_JOB2,CB_GETCURSEL,0,0);


channel_conf[id].hh_relay= SendDlgItemMessage(hDlg,MB_DELAY1,CB_GETCURSEL,0,0);
channel_conf[id].h_relay= SendDlgItemMessage(hDlg,MB_DELAY2 ,CB_GETCURSEL,0,0);
channel_conf[id].l_relay= SendDlgItemMessage(hDlg,MB_DELAY3 ,CB_GETCURSEL,0,0);
channel_conf[id].ll_relay= SendDlgItemMessage(hDlg,MB_DELAY4,CB_GETCURSEL,0,0);

//存入文件
//SetValueToEtcFile("system.conf","AI1","name",name);

return 1;
}
//下边按钮的右移操作,响应通道递增情况下组态

int ShiftMathRight(HWND hDlg,int math_focus_bn)
{
int i;
int id;
int pagemax;
	unsigned char str_num[10];
id= (math_focus_bn-MATH_BN1+math_bn_page*12)+ai_chan_sum;
	//保存本通道的信息
	WriteMathInfo(hDlg,id);
			//更换到下一通道的信息
		SendMessage(GetDlgItem(hDlg,math_focus_bn), BM_SETSTATE , 0 ,0);
		pagemax=math_chan_sum/12;
		math_focus_bn++;	
		id=(math_focus_bn-MATH_BN1+math_bn_page*12);//现在的值
		if(id>math_chan_sum)//当右移时候大于最大值
			{
			math_focus_bn=MATH_BN1;
			math_bn_page=0;
				for(i=0;i<12;i++){	
					if((pagemax>0)||((i<=math_chan_sum%12)&&(pagemax==0)))
						sprintf(str_num,"%d",(i+1+math_bn_page*12));
					else sprintf(str_num," " );
			 	SetDlgItemText(hDlg, (MATH_BN1+i),str_num );
			 	}
			}
			
		if(math_focus_bn>MATH_BN12)		
			{
				math_focus_bn=MATH_BN1;
				math_bn_page++;	
				if(math_bn_page>math_chan_sum/12)math_bn_page=0;
				for(i=0;i<12;i++){	
					if((math_bn_page==pagemax)&&(i>math_chan_sum%12))
						sprintf(str_num," " );
					else
						sprintf(str_num,"%d",(i+1+math_bn_page*12));
			 	SetDlgItemText(hDlg, (MATH_BN1+i),str_num );
			 	}					
			}

	
		SendMessage(GetDlgItem(hDlg,math_focus_bn), BM_SETSTATE , BST_PUSHED ,0);
		bfresh_conf=1;
			sprintf(topinfo,"组态数学通道  MATH%d   ",(math_focus_bn-MATH_BN1+1));			
id= (math_focus_bn-MATH_BN1+math_bn_page*12)+ai_chan_sum;
    ReadMathInfo( hDlg,id);
	return math_focus_bn;
}	

int ShiftMathLeft(HWND hDlg,int math_focus_bn)
{
int i;
int id;
	unsigned char str_num[10];
id= (math_focus_bn-MATH_BN1+math_bn_page*12)+ai_chan_sum;
	//保存本通道的信息
	WriteMathInfo(hDlg,id);
			//更换到下一通道的信息
    	SendMessage(GetDlgItem(hDlg,math_focus_bn), BM_SETSTATE , 0 ,0);
			math_focus_bn--;			
			if(math_focus_bn<MATH_BN1)
				{
				math_bn_page--;
				if(math_bn_page<0){math_bn_page=math_chan_sum/12;
								math_focus_bn=math_chan_sum%12+MATH_BN1;	
								}	
				else math_focus_bn=MATH_BN12;
				for(i=0;i<12;i++){					
			 		if(i<=(math_focus_bn-MATH_BN1))sprintf(str_num,"%d",(i+1+math_bn_page*12));
					else sprintf(str_num," ");
			 	SetDlgItemText(hDlg, (MATH_BN1+i),str_num );
				}		
			}
			 SendMessage(GetDlgItem(hDlg,math_focus_bn), BM_SETSTATE , BST_PUSHED ,0);
			bfresh_conf=1;
			sprintf(topinfo,"组态数学通道  MATH%d   ",(math_focus_bn-MATH_BN1+1));			
id= (math_focus_bn-MATH_BN1+math_bn_page*12)+ai_chan_sum;
    ReadMathInfo( hDlg,id);
	return math_focus_bn;
}	

 void MATHDialogInit(HWND hDlg)
 {
 	int i,j;
	unsigned char str[10];
	HWND old_button_focus_h,hChildWnd_math[11];
	static const unsigned char  *math_stat [] = {"启动",	"关闭"};
	static const unsigned char * method [] = { "实时","平均","最小","最大","关闭"};
const  unsigned char *math_set[]={"2000","1800","200","100"};
	static const unsigned char * event_type [] = {"HH","H","L", "LL","No", };
	static const unsigned char * offset [] = {"关闭 ","启用"};   
const   unsigned char *math_job1[]={
"开始记录","停止记录",
"记录报警","记录事件",
"不动作"
};  
const   unsigned char *math_job2[]={
"启动DO","启动AO","启动DO",
"启动定时器","启动计数器","启动累加器",
"不动作"
};  
const   unsigned char *speed[]={
	"1秒","2秒" ,"5秒","10秒","30秒","60秒","120秒"
};	
/*
  SetDlgItemText(hDlg, ME_DESC,"数学运算通道" );
	SetDlgItemText(hDlg, ME_UNIT,"默认" );
	SetDlgItemText(hDlg, ME_LOW,"0.0" );	
	SetDlgItemText(hDlg, ME_HIGH,"1000.0" );	
*/		
      for(i=0;i<4;i++)
      	{
	 sprintf(str,math_set[i]);
	 SetDlgItemText(hDlg, ME_SET1+i,str);
      	}
	  
	for(j=0;j<2;j++)
		SendMessage(GetDlgItem(hDlg,MB_ENABLE),CB_ADDSTRING,0,(LPARAM)math_stat[j]) ;
	for(j=0;j<3;j++)
		SendMessage(GetDlgItem(hDlg,MB_METHOD),CB_ADDSTRING,0,(LPARAM)method[j]) ;
	for(j=0;j<5;j++)
		SendMessage(GetDlgItem(hDlg,MB_SPEED),CB_ADDSTRING,0,(LPARAM)speed[j]) ;
	for(i=0;i<4;i++)
		{
        		for(j=0;j<5;j++){
        		SendMessage(GetDlgItem(hDlg,MB_TYPE1+i),CB_ADDSTRING,0,(LPARAM)event_type[j]) ;
        		}	
		}
 	for(i=0;i<4;i++)
 		{
			for(j=0;j<2;j++){
			SendMessage(GetDlgItem(hDlg,MB_DELAY1+i),CB_ADDSTRING,0,(LPARAM)offset[j]) ;
			}
 		}
      for(i=0;i<4;i++)
      	{
         for(j=0;j<5;j++)
         {
	   sprintf(str,math_job1[j]);
          SendMessage(GetDlgItem(hDlg,MA_Y1_JOB1+i),CB_ADDSTRING,0, (LPARAM)str) ;
      	  }
      	}	  
  	  
      for(i=0;i<4;i++)
      	{
         for(j=0;j<7;j++)
         {
	   sprintf(str,math_job2[j]);
          SendMessage(GetDlgItem(hDlg,MA_Y1_JOB2+i),CB_ADDSTRING,0, (LPARAM)str) ;
      	  }
      	}	  

	SendDlgItemMessage(hDlg,MB_TYPE1,CB_SETCURSEL,0,0);
	SendDlgItemMessage(hDlg,MB_TYPE2,CB_SETCURSEL,1,0);
	SendDlgItemMessage(hDlg,MB_TYPE3,CB_SETCURSEL,2,0);
	SendDlgItemMessage(hDlg,MB_TYPE4,CB_SETCURSEL,3,0);		

		
}

int  MATHDialogProc (HWND hDlg, int message, WPARAM wParam, LPARAM lParam)
{ 
 static int ctrl_math_id;//按键ID号或者是文本焦点号码
    static int index;
    static int num ;
    static  BOOL flag_entered;

  int id ;
  int i;//按纽循环用
  int len;
  
  int nc ;
  unsigned char str_num[10];
	 id= LOWORD (wParam);//控件编号
	 nc=HIWORD(wParam);  //控件通知码		
  switch (message) 
  	{
  	   case MSG_INITDIALOG:
	   	MATHDialogInit( hDlg);
		str_num[0]='\0';
		math_bn_page=0;
		SendMessage(GetDlgItem(hDlg,MATH_BN1), BM_SETSTATE , BST_PUSHED ,0);

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?