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

📄 meter.c

📁 采用MINIGUI开发的一套GUI界面
💻 C
字号:
#include     <stdio.h>        /*标准输入输出定义*/
#include     <stdlib.h>       /*标准函数库定义*/
#include     <unistd.h>       /*Unix 标准函数定义*/
#include     <sys/times.h>  
#include     <sys/types.h>  

#include     <sys/stat.h>   
#include     <sys/ioctl.h>  
#include <minigui/common.h>
#include <minigui/minigui.h>
#include <minigui/gdi.h>
#include <minigui/window.h>
#include <minigui/control.h>

#include     <fcntl.h>        /*文件控制定义*/
#include     <string.h>
#include     <termios.h>      /*PPSIX 终端控制定义*/
#include     <unistd.h>  
#include     <errno.h>        /*错误号定义*/
#include     <pthread.h>
#include     <math.h>         /*数学函数定义*/
#include     "meter.h"
#include     "serial.h"
#include     "common.h"   
         typedef struct{
            int length;
            int addr;
            }BREAKSTR;
         BREAKSTR *pbreakstr;

/*仅仅在METER.C中用到的全局变量*/
      int temp_n;	  //using : printf the receive string one by one 
      int comspeed;//全局变量,在接收线程中用

           //when define the thread
      
      int gdev_type;   //用于2个线程间参数传递
      int gdev_addr;
      unsigned char *gdev_cmd;
/*仅仅在METER.C中用到的函数*/




 struct Type_data buf_Acquic;
const int ascii[16]={0x30,0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39,0x41,0x42,0x43,0x44,0x45,0x46};
unsigned char RR[]={0x52,0x52};
unsigned char RD[]={0x52,0x44};
unsigned char RE[]={0x52,0x45};
unsigned char W1[]={0x57,0x31};
unsigned char W2[]={0x57,0x32};
unsigned char WW[]={0x23,0x23};
int comspeed;//全局变量,在接收线程中用   

const int BoudrateArrray[]={9600 , 4800 , 38400,  19200, 2400,  1200,  300};
const int  MeterTypeDataLength[]={8,10,8,16,8,8};


static unsigned char Type1[] = {0x40,0x30,0x30,0x52,0x44,0x31,0x37,0x0D};
static unsigned char Type2[] = {0x40,0x30,0x30,0x52,0x44,0xCD,0xAB,0x37,0x31,0x0D};
const int  CommandLen[]={8,10,16,8,8};
static unsigned char Type3[] = {0x3A,0x30,0x30,0x30,0x33,0x30,0x33,0x30,0x30,0x30,0x30,0x30,0x31,0x46,0x39,0x0D};


//    WP-R协议的仪表格式,查询仪表类型的09命令
static unsigned char Type4[] = {0x01,0x09,0x00,0x00,0x00,0x00,0xdd,0xcb};
static unsigned char Type5[] = {0x80,0x80,0x52,0x00,0x00,0x00,0x52,0x00};
static unsigned char  *pType[] = {Type1,Type2,Type3,Type4,Type5};
static unsigned char Test[] = {0x40,0x30,0x31,0x52,0x44,0x31,0x37,0x0D};



/*use for crc16*/

/* CRC16 高位字节值表 */
const unsigned char auchCRCHi[] = {
0x00, 0x0C1, 0x81, 0x40, 0x01, 0x0C0, 0x80, 0x41, 0x01, 0x0C0,
0x80, 0x41, 0x00, 0x0C1, 0x81, 0x40, 0x01, 0x0C0, 0x80, 0x41,
0x00, 0x0C1, 0x81, 0x40, 0x00, 0x0C1, 0x81, 0x40, 0x01, 0x0C0,
0x80, 0x41, 0x01, 0x0C0, 0x80, 0x41, 0x00, 0x0C1, 0x81, 0x40,
0x00, 0x0C1, 0x81, 0x40, 0x01, 0x0C0, 0x80, 0x41, 0x00, 0x0C1,
0x81, 0x40, 0x01, 0x0C0, 0x80, 0x41, 0x01, 0x0C0, 0x80, 0x41,
0x00, 0x0C1, 0x81, 0x40, 0x01, 0x0C0, 0x80, 0x41, 0x00, 0x0C1,
0x81, 0x40, 0x00, 0x0C1, 0x81, 0x40, 0x01, 0x0C0, 0x80, 0x41,
0x00, 0x0C1, 0x81, 0x40, 0x01, 0x0C0, 0x80, 0x41, 0x01, 0x0C0,
0x80, 0x41, 0x00, 0x0C1, 0x81, 0x40, 0x00, 0x0C1, 0x81, 0x40,
0x01, 0x0C0, 0x80, 0x41, 0x01, 0x0C0, 0x80, 0x41, 0x00, 0x0C1,
0x81, 0x40, 0x01, 0x0C0, 0x80, 0x41, 0x00, 0x0C1, 0x81, 0x40,
0x00, 0x0C1, 0x81, 0x40, 0x01, 0x0C0, 0x80, 0x41, 0x01, 0x0C0,
0x80, 0x41, 0x00, 0x0C1, 0x81, 0x40, 0x00, 0x0C1, 0x81, 0x40,
0x01, 0x0C0, 0x80, 0x41, 0x00, 0x0C1, 0x81, 0x40, 0x01, 0x0C0,
0x80, 0x41, 0x01, 0x0C0, 0x80, 0x41, 0x00, 0x0C1, 0x81, 0x40,
0x00, 0x0C1, 0x81, 0x40, 0x01, 0x0C0, 0x80, 0x41, 0x01, 0x0C0,
0x80, 0x41, 0x00, 0x0C1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41,
0x00, 0x0C1, 0x81, 0x40, 0x00, 0x0C1, 0x81, 0x40, 0x01, 0xC0,
0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41,
0x01, 0x0C0, 0x80, 0x41, 0x00, 0x0C1, 0x81, 0x40, 0x01, 0x0C0,
0x80, 0x41, 0x00, 0x0C1, 0x81, 0x40, 0x00, 0x0C1, 0x81, 0x40,
0x01, 0x0C0, 0x80, 0x41, 0x01, 0x0C0, 0x80, 0x41, 0x00, 0x0C1,
0x81, 0x40, 0x00, 0x0C1, 0x81, 0x40, 0x01, 0x0C0, 0x80, 0x41,
0x00, 0x0C1, 0x81, 0x40, 0x01, 0x0C0, 0x80, 0x41, 0x01, 0x0C0,
0x80, 0x41, 0x00, 0x0C1, 0x81, 0x40
};
/* CRC16低位字节值表 */
const unsigned char auchCRCLo[] = {
0x00,0x0C0, 0x0C1, 0x01, 0x0C3, 0x03, 0x02, 0x0C2, 0x0C6, 0x06, 
0x07, 0xC7, 0x05, 0x0C5, 0x0C4, 0x04, 0x0CC, 0x0C, 0x0D, 0x0CD,
0x0F, 0x0CF, 0x0CE, 0x0E, 0x0A, 0x0CA, 0x0CB, 0x0B, 0x0C9, 0x09,
0x08, 0x0C8, 0x0D8, 0x18, 0x19, 0x0D9, 0x1B, 0x0DB, 0x0DA, 0x1A,
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, 0x5C,
0x5D, 0x9D, 0x5F, 0x9F, 0x9E, 0x5E, 0x5A, 0x9A, 0x9B, 0x5B,
0x99, 0x59, 0x58, 0x98,0x88, 0x48, 0x49, 0x89, 0x4B, 0x8B,
0x8A, 0x4A, 0x4E, 0x8E, 0x8F, 0x4F, 0x8D, 0x4D, 0x4C, 0x8C,
0x44, 0x84, 0x85, 0x45, 0x87, 0x47, 0x46, 0x86, 0x82, 0x42,
0x43, 0x83, 0x41, 0x81, 0x80, 0x40

};

    
	//define the thread array
           //when define the thread
 //global 

//全局变量:波特率comspeed
//接收到的字符长度

/**************************Test*********************************/
void Comminit(void) 
{ 
    int fdcom;
    int i,SendLen,RecvLen;
    int ret;
    	struct termios termios_cur;    
	SEND_DATA_STRU  sendcmd3;
	   portinfo_t portinfo ={ 
	         '0',                              /* print prompt after receiving*/ 
	         4800,                           /* baudrate: 9600*/ 
	         '8',                              /* databit: 8*/ 
	         '0',                              /* debug: off*/ 
	         '0',                              /* echo: off*/ 
	         '2',                              /* flow control: software*/ 
	         '0',                              /* default tty: COM1*/ 
	         '0',                              /* parity: none*/ 
	         '1',                              /* stopbit: 1*/ 
	          0                              /* reserved*/ 
	    };   	
	comspeed=portinfo.baudrate;   
    	fdcom = PortOpen(&portinfo);    
     	Commfd2=fdcom;
    	if(fdcom<0)
	{ 
        printf("Error: open serial port error.\n"); 
        exit(1); 
    	}  
	else
  	 PortSet(fdcom, &portinfo);   
	 devices_registed=0;
} 
struct Type_data Acquic ( unsigned char *type, unsigned char *num )    //鍙傛暟涓哄瀷鍙峰拰搴忓彿,鍙

⌨️ 快捷键说明

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