⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 caution.c.svn-base

📁 接受modbus rtu协议的数据,报警应用程序.
💻 SVN-BASE
字号:
/******************************************************************************
 *
 * Copyright (c) 2008 Shanghai IS Software
 *
 * All rights reserved
 *
 * $Revision$
 *
 * $LastChangedBy$
 *
 * $LastChangedData$
 *
 * Description:
 *
 * Revision History:
 * 2008/09/3 14:33 by lcj
 * #1.created
 *
 *****************************************************************************/
#include "md/md_manager.h"
#include "md/md_info.h"
#include "md/md_reg.h"


#include "caution/caution.h"

unsigned int C_port,C_addr;
unsigned int C_reg_addr,C_reg_max_value_1,C_reg_max_value_2,C_reg_min_value_1,C_reg_min_value_2;

char * trim(char *str)
{
	int len,i = 0;
	char *p = str;

	while ( (' ' == *p) || ('\t' == *p) )
		p++;
	len = strlen(p);

	while ( len > 0 )
	{
		if((' ' == p[len-1])||('\t' == p[len-1])||('\n' == p[len-1])||('\r' == p[len-1]))
			len--;
		else 
			break;
	}

	*(p+len) = '\0';

	return p;
}

void do_string(char *str)
{
	int len,i,j;
	char *pstr = str;
	char *delim = "[]\t ";
	char *p;
	char file_data[MAX_CONF_DATA][MAX_CONF];
	
	len = strlen(pstr);
	if ( ((*pstr) != '[') || (pstr[len-1] != ']') )
	{
		printf("config file error!\n");
		exit(0);
	}
	
	i = 0;
	strcpy(file_data[i++],strtok(pstr,delim));
	while ( p = strtok(NULL,delim))
	{
		strcpy(file_data[i++],p);
	}
	
	sscanf(file_data[0],"%x",&C_port);
	sscanf(file_data[1],"%x",&C_addr);
	sscanf(file_data[2],"%x",&C_reg_addr);
	sscanf(file_data[3],"%x",&C_reg_max_value_1);
	sscanf(file_data[4],"%x",&C_reg_max_value_2);
	sscanf(file_data[5],"%x",&C_reg_min_value_1);
	sscanf(file_data[6],"%x",&C_reg_min_value_2);


	return ;
	
} 


void func1(void)
{
	printf("The Valude is more than 0x%x!\n",C_reg_max_value_1);
}
void func2(void)
{
	printf("The Value is more than 0x%x!\n",C_reg_max_value_2);

}
void func3(void)
{
	printf("The Value is little than 0x%x!\n",C_reg_min_value_1);

}
void func4(void)
{
	
	printf("The Value is little than 0x%x!\n",C_reg_min_value_2);
	
}
	
int main(int argc,char **argv)
{
	int flag,ret = 0;
	FILE *pFILE;
	char *pline;
	char PLINE[MAX_CONFIGDATA];
	MD_info * info;
	MD_reg_info * reg_info;
	unsigned short result;

	flag = 0;

	ret = init_MD_manager(2,5,500);
	if ( ret )
	{
		pFILE = fopen(CONFIG,"r");
		if ( NULL == pFILE )
		{
			printf(" open config file error!\n");
			exit(0);
		}
	
		while ( pline = fgets(PLINE,MAX_CONFIGDATA - 1 ,pFILE) )
		{
			pline = trim(pline);
			if ( strlen(pline) < 3 )
				continue;
			if ( '#' == *pline )
				continue;

			do_string(pline);

			info = get_MD_info(C_port,C_addr);
			if ( info )
			{
				reg_info =(MD_reg_info *) get_reg_info(info,C_reg_addr);
				if ( reg_info )
				{
					if ( reg_info->status == MD_STATUS_NORMAL )
					{
						flag = 1;
						get_MD_reg_value(info,C_reg_addr,&result);
					}
					else 
					{
						printf("The Vlaue is Not Set!\n");
						exit(0);
					}
				}
			}

			if ( flag )
			{	
				if ( result >= C_reg_max_value_1 )
					func1();
				else if  ( result >= C_reg_max_value_2 )
					func2();
				else if ( result <= C_reg_min_value_1 )
					func3();
				else if( result <= C_reg_min_value_2 )
					func4();
			}
			else 
			{
				printf("Share Memory Error!\n");
				exit(0);
			}
		}
	}

	return ret;	
}
 

⌨️ 快捷键说明

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