Beispiel #1
0
/**
*@breif  main()
*/
int main(int argc, char *argv[])
{
 int fd;
 int nread;
 char buff[512];
 char *dev ="/dev/ttyACM0";
 char recchr[512];
 int device, c;

 sleep(1);
 fd = OpenDev(dev);

 if (fd>0){
      set_speed(fd,9600);
 }
 else{
  printf("Can't Open Serial Port!\n");
  exit(0);
 }

 if (set_Parity(fd,8,1,'N')== FALSE)
  {
     printf("Set Parity Error\n");
      exit(1);
   }
//   while(1)
//   {
        scanf("%s",recchr) ;
   write(fd, "c", 1);
   write(fd, "\"\n", 2);
	printf("发完!\n");
//   }
     close(fd);
     exit(0);
}
Beispiel #2
0
 /** 
 *@breif     main() 
 */  
 int main(int argc, char **argv)  
 {  
     int fd;  
     int nread;  
     char buff[512];  
     char *dev ="/dev/ttty0";  
     fd = OpenDev(dev);  
     if (fd>0)  
     set_speed(fd,19200);  
     else  
         {  
         printf("Can't Open Serial Port!\n");  
         exit(0);  
         }  
   if (set_Parity(fd,8,1,'N')== FALSE)  
   {  
     printf("Set Parity Error\n");  
     exit(1);  
   }  
   while(1)  
     {  
         while((nread = read(fd,buff,512))>0)  
         {  
             printf("\nLen %d\n",nread);  
             buff[nread+1]='\0';  
             printf("\n%s",buff);  
         }  
     }  
     //close(fd);  
     //exit(0);  
 }  
int main(int argc, char **argv) {
    int fd;
    int nread;
    char *ptr = argv[2];
    char *dev = argv[1]; //maybe "/dev/ttyS0";

    if (argc < 3) {
        printf("pls usage %s /dev/ttyS[n] your_message.\n", argv[1]);
        exit(EXIT_FAILURE);
    }

    if ((fd = open(dev, O_RDWR)) == -1) {
        perror("open");
        exit(EXIT_FAILURE);
    }

    set_speed(fd, 19200);

    if (set_Parity(fd, 8, 1, 'N') == FALSE) {
        printf("Set Parity Error\n");
        exit(EXIT_FAILURE);
    }

    if (write(fd, ptr, strlen(ptr)) < 0) {
        perror("write");
        exit(EXIT_FAILURE);
    }

    printf("pls check the tty data\n");
    close(fd);
    exit(EXIT_SUCCESS);
}
Beispiel #4
0
int main(int argc, char **argv)
{
	int fd;
	int nread;
    int speedcom;
	char buff[512];
    time_t nowtime;
    time(&nowtime);
	printf("%s",asctime(gmtime(&nowtime)));
    //char command[100] = {0x01, 0x03, 0x00, 0x40, 0x00, 0x18, 0x44, 0x14};
    char *command = argv[3];
	fd = OpenDev(argv[2]);
    printf("fd: %u\n", fd);
    printf("open tty: %s\n", argv[2]);
	if (fd>0) {
        speedcom = ascii_to_integer(argv[1]);
        printf("speedcom: %d\n", speedcom);
        set_speed(fd,speedcom);
        printf("open fd: %u\n", fd);
    }
	else {
    	printf("Can't Open Serial Port!\n");
		exit(0);
	}
    if (set_Parity(fd,8,1,'N')== FALSE) {
        printf("Set Parity Error\n");
        exit(1);
    }
    //ioctl(fd, RS4851_C30, 1);
    //printf("writting command: %s\n", command);
    //write(fd, command, sizeof(command));
    //usleep(10000);
    while(1) {  
        //ioctl(fd,RS4851_C30,1);
        //printf("writting command: %s\n", command);
        //write(fd, command, 8);
        //usleep(500000);
        //ioctl(fd,RS4851_C30,0);
   		//usleep(500000);
        //while((nread = read(fd,buff,512))>0)
   		//{
      	//  printf("\nLen %d\n",nread);
      	//  buff[nread+1]='\0';
      	//  printf("\n%s",buff);
        //}
        
        while(nread = read(fd,buff,512)) {
      	    buff[nread+1]='\0';
            //printf("printf %s\n", buff);
            //write(1,  buff, nread);
            //write(fd, buff, nread);
   	 	}
  	}
    close(fd);
    exit(0);
}
Beispiel #5
0
int Uart_Init(char *Dev)					//打开串口 设置波特率115200 数据位8 两个结束位 奇偶校验位
{
	int fd;
	if((fd = OpenDev(Dev)) > 0)
	{
		//set_speed(fd, 115200);
		set_speed(fd, 9600);
		if (set_Parity(fd,8,2,'N')== -1)
		  {
			printf("Set Parity Error\n");
			return -1;
		}
		else return fd;
	}
	else
	{
		return -1;	
	}
	
}
Beispiel #6
0
int openserial(char port[], int speed, int databits, int parity, int stopbits )
{
  int fd;
 // printf("open %s\n", port);
  fd = open(port, O_RDWR);
  if(fd == -1)
  {
    perror("serialport error\n");
    return -1;
  }
  else
  {
    printf("open ");
    printf("%s",ttyname(fd));
    printf(" succesfully\n");
    set_speed(fd, speed);
    set_Parity(fd, databits, parity, stopbits); 
    return fd;
  }  
}
Beispiel #7
0
//-------------------------------------------------------------------------
//串口初始化	参数:设备名,波特率,数据位,停止位,校验位
//-------------------------------------------------------------------------
int serial_init(int Dev, int speed, int databits, int stopbits, int parity)
{

	static int serial_fd;
	
	//打开串口设备
	serial_fd = OpenDev(Dev);

	if(serial_fd > 0)
		set_speed(serial_fd, speed);		//设置波特率
	else
	{
		printf("Can't Open Serial Port!\n");
		exit(0);
	}
	//恢复串口未阻塞状态
	if (fcntl(serial_fd, F_SETFL, O_NONBLOCK) < 0)
	{
		printf("fcntl failed!\n");
		exit(0);
	}

	//检查是否是终端设备
#if 1	//如果屏蔽下面这段代码,在串口输入时不会有回显的情况,调用下面这段代码时会出现回显现象。
	if(isatty(STDIN_FILENO)==0)
	{
		printf("standard input is not a terminal device\n");
	}
	else
		printf("isatty success!\n");
#endif
	//设置串口参数
	if(set_Parity(serial_fd, databits, parity, stopbits) == FALSE)
	{
		printf("Set parity Error\n");
		exit(1);
	}
	
	return serial_fd;
}
int main(int argc,char* argv[])
{
	
	if(argc != 3)
	{
		printf("缺少参数:error!\n");
		exit(0);
	}
	 
 	
//*********打开串口并设置波特率*********	
	
	char *dev  = (char*)argv[2]; //串口

	int fd = OpenDev(dev);           //打开串口函数
    if(fd<0)
    {
    	close(fd);
        return FALSE;
    }

	int set_res=set_speed(fd,9600);          //设置串口

    if(set_res==FALSE)
    {
    	close(fd);
       return FALSE;
    }

	if (set_Parity(fd,8,1,'N') == FALSE)
	{
		   close(fd);
           return FALSE;
	}

	//***********从文件中读出指令*************** 

	char order1[8]={0x01,0x03,0x00,0x01,0x00,0x01,0xd5,0xca};
	char order2[8]={0x01,0x03,0x03,0x00,0x00,0x01,0x84,0x4e};
	char order3[18]={0x7E,0x32,0x30,0x30,0x31,0x39,0x30,0x38,0x41,
	0x30,0x30,0x30,0x30,0x46,0x44,0x39,0x41,0x0D};
	char order4[8]={0x01,0x03,0x06,0x06,0x00,0x01,0x84,0x82};
	//char order4[8]={0x01,0x04,0x00,0x04,0x00,0x01,0x70,0x0b};
    
    int result =0;
    int flag = atoi(argv[1]);
    int send_res;
    int recv_length = 7;
   	char total_buff[1024];
    if(flag ==1)
	{
  		send_res=Send_order(fd,order1,8);
		Recv_data(fd,total_buff,recv_length);//读取串口数据
		if(total_buff[2]==0x2 & total_buff[3]==0x0 & total_buff[4]==0x1)
		{
			
			result =flag;
			
		}
    }
    if(flag ==2)
	{
  		send_res=Send_order(fd,order2,8);
	    Recv_data(fd,total_buff,recv_length);//读取串口数据
    	if(total_buff[2]==0x2 & total_buff[3]==0x0 & total_buff[4]==0x1)
		{
			
			result =flag;
			
		}
    }
    if(flag ==3)
	{
  		send_res=Send_order(fd,order3,18);
		Recv_data(fd,total_buff,recv_length);//读取串口数据
		if(total_buff[0]== 0x7E )
		{
			result =flag;
		}
    }
	if(flag ==4)
	{
  		send_res=Send_order(fd,order4,8);
		Recv_data(fd,total_buff,recv_length);//读取串口数据
		if(total_buff[2]==0x2 & total_buff[4]==0x1 )
		{
			result =flag;
		}
    }
    
    //*********发送命令************** 

	if(send_res==FALSE)
 	{
		close(fd);
		return FALSE;
	}

  
	
	int j;
	for (j = 0 ; j < recv_length; j++)
	{       
		printf("%02X  ", (unsigned char)total_buff[j]);
	}            

	printf("\n");
		
	close(fd);
	return result;

}
Beispiel #9
0
void send_buff(int id,char *ag,int n,char *fla)
{




    int fd;
    char *dev = "/dev/ttyS1";
	fd = OpenDev(dev); 
	set_speed(fd,9600); 
	if (set_Parity(fd,8,1,'N' )== -1)
 	{ 
	printf("Set Parity Errorn"); 
	exit (0); 
	} 
	char buf[4096]="\0";
    char flag[4096]="\0";
    strcat(flag,fla);
    printf("flag==%s\n",flag);
	strcat(ag,"&");
	strcat(buf,ag);
	ag=buf;
	printf("ag=%s\n",ag);
	int t=0;
	char c='1';
	int j=0;
    int res;
    int i;
	c=ag[j];
  

/*  

	char buff[4096]="\0";
	int jj;
	int ii;
	char fh=';';
	printf("buf======%s,,flag=====%s\n",buf,flag);
	for(jj=0;'&'!=buf[jj]&&jj<20;jj++)
	{
		for(ii=0;';'!=buff[ii]Z;ii++,jj++)
		{
			buff[ii]=buf[jj];
			printf("~~~~~buff[%d]=========%c\n",ii,buff[ii]);
		}
		printf("~~~~~jj====%d\n",jj);
		strcat(flag,buff);
		printf("for  jj  flag===%s\n",flag);
		uart_send(fd,flag);
		flag[5]='\0';
	}


*/
 			
	while('&'!=c)
	{
         while(';'!=c)
		{
			send_buf[t]=c;
        	t++;
  			j++;
			c=ag[j];
		}
        send_buf[t]=c;
		res=-1;
		  i=0;
		//int flag_break=0;
    	do
		{
      		
			printf("in  send_buff    buff====%s\n",send_buf);
			if(i==0)
			strcat(flag,send_buf);
			
			printf("in  send_buff    flag====%s\n",flag);
            res = uart_send(fd,flag);
      		sleep(3);
      		if(i == 5)
      		exit(0);//
			 i++;
      		
     	}while(res<0);
		t=0;
        j++;
        c=ag[j];
        bzero(send_buf,sizeof(send_buf));
  		//bzero(flag,sizeof(flag));
		sprintf(flag,"\0");
		strcat(flag,fla);
	}	




    close(fd);
}
Beispiel #10
0
int main(int argc, const char *argv[])
{
	int fd;
	char uart_dev[128];
	//fd = open("/dev/ttyUSB1", O_RDWR|O_NOCTTY | O_NDELAY);
	if(argc==2){
		fd = open(argv[1], O_RDWR);
		printf("Use the uart_dev:%s\n",argv[1]);
	}else{
		fd = open(UART_DEV, O_RDWR);
	}
	if (-1 == fd) {
		perror("[ERR]open device "UART_DEV);
		return -1;
	} else {
		printf("[OK]open device %s.\n",UART_DEV);
	}
	printf("setting speed...\n");
	set_speed(fd, BUAD);
	printf("setting Parity...\n");
	set_Parity(fd, 8, 1, 'N');
	char buffer[1024] = "ls\n";
	//int Length = 10;
	int nByte;
	printf("Ready to write(send) to uart,please INPUT string and ENTER\n");
	scanf("%s",buffer);
	printf("write data...\n");
	//nByte = write(fd, buffer, Length);
	nByte = write(fd, buffer, strlen(buffer)+1);
	printf("\nwrite end,send length %d byte(s).\n",nByte);
#if ONLY_SEND_TEST
	printf("开始发送测试,一直发送字符串abcd,CTRL-C终止\n");
	int a_writetest[1]={0b10101010};
	while(1){
		write(fd,a_writetest,1);
	}
#endif
	int Len = 1024;
	char buf[1024];
	int readByte;
	int i;
	while (1) {
		//for(i=0;i<7000000;i++);
		printf("reading data...\n");
		readByte = read(fd, buf, 1);
		//tcflush(fd,TCIOFLUSH); 
		if (readByte <= 0){
			//printf("len=%d,read=%s\n",readByte, buf);
			printf("read over.len=%d\n",readByte);
			tcflush(fd,TCIOFLUSH); 
			break;
		}
		printf("len=%d,返回:%s\n", readByte,buf);
		//sleep(1);
	}
	int status=0;
	status= close(fd);
	printf("close status return: %d\n",status);

	return 0;
}
Beispiel #11
0
/**
*@breif 	main()
*/
int main(int argc, char **argv)
{
	int fd;
	int nwrite,nread;
	char buff[512],temp[16];
	char buff3[3]  = {"aaa"};
	char *dev ="/dev/ttyS0",*dev1 ="/dev/ttyS1",*dev2 ="/dev/ttyS2",*dev3 ="/dev/ttyS3", *dev4="/dev/ttyS4";
	
	
	memset(buff,'A',512);
	
	if(argc>=2)
	{
		if(*argv[1]=='1')
		{
			fd = OpenDev(dev1);
			tcgetattr( fd,&old_options);
			if (fd>0)
		    	set_speed(fd,115200);
			else
			{
				printf("Can't Open Serial Port 1!\n");
				exit(0);
			}
		  if (set_Parity(fd,8,1,'N')== FALSE)
		  {
		    printf("Set Parity Error\n");
		    exit(1);
		  }
		
		  nwrite = write(fd,buff,512);
		  
		  printf("\nSent %d Bytes\n\n",nwrite);
		  tcsetattr(fd,TCSANOW,&old_options);
		  sleep(1);  // make sure all bytes are sent out. or we'll have to wait for 30 seconds.
		  close(fd);
		}
		else if(*argv[1]=='2')
		{
			fd = OpenDev(dev2);
			tcgetattr( fd,&old_options);
			if (fd>0)
		    	set_speed(fd,115200);
			else
			{
				printf("Can't Open Serial Port 2!\n");
				exit(0);
			}
		  if (set_Parity(fd,8,1,'N')== FALSE)
		  {
		    printf("Set Parity Error\n");
		    exit(1);
		  }
		
		  nwrite = write(fd,buff,512);
		  
		  printf("\nSent %d Bytes\n\n",nwrite);
		  tcsetattr(fd,TCSANOW,&old_options);	
		  sleep(1);  // make sure all bytes are sent out. or we'll have to wait for 30 seconds.	  
		  close(fd);
		}
		else if(*argv[1]=='3')
		{
			fd = OpenDev(dev3);
			tcgetattr( fd,&old_options);
			if (fd>0)
		    	set_speed(fd,115200);
			else
			{
				printf("Can't Open Serial Port 3!\n");
				exit(0);
			}
		  if (set_Parity(fd,8,1,'N')== FALSE)
		  {
		    printf("Set Parity Error\n");
		    exit(1);
		  }
		
		  nwrite = write(fd,buff,512);
		  
		  printf("\nSent %d Bytes\n\n",nwrite);
		  tcsetattr(fd,TCSANOW,&old_options);
		  sleep(1);  // make sure all bytes are sent out. or we'll have to wait for 30 seconds.
		  close(fd);
		}
                else if(*argv[1]=='4')
		  {
		    fd = OpenDev(dev4);
		    tcgetattr( fd,&old_options);
		    if (fd>0)
		      set_speed(fd,115200);
		    else
		      {
			printf("Can't Open Serial Port 4!\n");
			exit(0);
		      }
		    if (set_Parity(fd,8,1,'N')== FALSE)
		      {
			printf("Set Parity Error\n");
			exit(1);
		      }

		    nwrite = write(fd,buff,512);

		    printf("\nSent %d Bytes\n\n",nwrite);
		    tcsetattr(fd,TCSANOW,&old_options);
		    sleep(1);  // make sure all bytes are sent out. or we'll have to wait for 30 seconds.
		    close(fd);
		  }
		else
		{
			fd = OpenDev(dev);
			tcgetattr( fd,&old_options);
			if (fd>0)
		    	set_speed(fd,115200);
			else
			{
				printf("Can't Open Serial Port 0!\n");
				exit(0);
			}
		  if (set_Parity(fd,8,1,'N')== FALSE)
		  {
		    printf("Set Parity Error\n");
		    exit(1);
		  }
		
		  nwrite = write(fd,buff,512);
		  
		  printf("\nSent %d Bytes\n\n",nwrite);
		  tcsetattr(fd,TCSANOW,&old_options);
		  sleep(1);  // make sure all bytes are sent out. or we'll have to wait for 30 seconds.
		  close(fd);
		}		
	}
	else
	{
		fd = OpenDev(dev);
		tcgetattr( fd,&old_options);
		if (fd < 0)
		{
			printf("Can't Open Serial Port 0!\n");
			exit(0);
		}
	  if (set_Parity(fd,8,1,'N')== FALSE)
	  {
	    printf("Set Parity Error\n");
	    exit(1);
	  }
	
	  nwrite = write(fd,buff,512);
	  
	  printf("\nSent %d Bytes\n\n",nwrite);
	  tcsetattr(fd,TCSANOW,&old_options);
	  sleep(1);  // make sure all bytes are sent out. or we'll have to wait for 30 seconds.
	  close(fd);
	}
		   
  return 0;
}
Beispiel #12
0
int main(int argc, char **argv)
{
    int fd;
    int nread;
    int nwrite;
    int n=0;
    int i=0;
    char buffer[15];
    char devname_head[10] = "/dev/";
    char dev_name[20];

     if(argc < 2)
    {
      printf("Please input './test_uart ttySx'\n");
      exit(1);
    }
    else
    {
        strcpy(dev_name, devname_head);
        strcat(dev_name, argv[1]);
    }

    fd = open(dev_name, O_RDWR);
    if(fd < 0)
    {
        perror("error to open /dev/ttySx\n");
        exit(1);
    }


    if (fd > 0)
    {
        set_speed(fd,115200);
    }
    else
    {
        printf("Can't Open Serial Port!\n");

        exit(0);
    }

      if (set_Parity(fd,8,1,'N') == FALSE)
      {
        printf("Set Parity Error\n");

        exit(1);
      }

    printf("\nWelcome to uart_test\n\n");

   memset(buffer,0,sizeof(buffer));

   char test[15] = "hello world";

   nwrite = write(fd,test,strlen(test));
    if(nwrite < 0)
    {
        printf("write error\n");
    }

   printf("Send test data------>%s\n",test);

      while(1)
      {
        nread = read(fd,&buffer[n],1);
        if(nread < 0)
        {
            printf("read error\n");
        }

        printf("read char is -> %c \n",buffer[n]);

           if (strlen(buffer) == strlen(test))
           {
               printf("Read Test Data finished,Read Test Data is------->%s\n",buffer);

            memset(buffer,0,sizeof(buffer));
            printf("Send test data again------>%s\n",test);

            write(fd,test,strlen(test));
            n=0;
            sleep(1);

            continue;
        }
       n++;
    }
}
Beispiel #13
0
int main()
{
	    int i,j,k,m=0;

         int fd;

         int nread;

         char tempbuff[37];


         char *dev  = "/dev/ttyS0"; //串口1
	start:
         fd = OpenDev(dev);

         set_speed(fd,57600);

         if (set_Parity(fd,8,1,'N') == FALSE)  {

                   printf("Set Parity Error\n");

                   //return -1;

         }
	
	   iniconnect();

         while (1) //循环读取数据

         {  

               if((nread = read(fd, tempbuff, 37))>0)

               {

                            //printf("\nLen %d\n",nread);

                    //printf("%s",tempbuff);
					//printf("%c\n",tempbuff[1]);
					for(m=0;tempbuff[m]!='#';m++);
						m++;
					if(tempbuff[m]=='@')
					{
						m++;
						for(i=0;i<16;i++)
							str2[23+i]=tempbuff[m++];
						str2[39]='\'';
						str2[40]=',';
						str2[41]='\'';
						
						for(j=0;j<17;j++)
							str2[42+j]=tempbuff[m++];
						str2[59]='\'';
						str2[60]=')';
						str2[61]='\0';
						printf("%s\n",str2);
						if(strlen(str2)!=61)
							goto start;
						mysql_query(&connection,str2);
					}
					
					else if(tempbuff[m]=='$')
					{
						m++;
						for(i=0;i<16;i++)
							str3[24+i]=tempbuff[m++];
						str3[40]='\'';
						str3[41]=',';
						str3[42]='\'';
						
						for(j=0;j<17;j++)
							str3[43+j]=tempbuff[m++];
						str3[60]='\'';
						str3[61]=')';
						str3[62]='\0';
						printf("%s\n",str3);
						if(strlen(str3)!=62)
							goto start;
						mysql_query(&connection,str3);
					}
					
					else if(tempbuff[m]=='%')
					{
						m++;
						for(i=0;i<16;i++)
							str4[25+i]=tempbuff[m++];
						str4[41]='\'';
					    str4[42]=',';
					    str4[43]='\'';
					    
					    for(j=0;j<17;j++)
					    	str4[44+j]=tempbuff[m++];
					    str4[61]='\'';
					    str4[62]=')';
					    str4[63]='\0';
					    printf("%s\n",str4);
						if(strlen(str4)!=63)
							goto start;
					    mysql_query(&connection,str4);
					}
					
					else if(tempbuff[m]=='^')
					{
						m++;
						for(i=0;i<16;i++)
							str5[25+i]=tempbuff[m++];
						str5[41]='\'';
						str5[42]=',';
						str5[43]='\'';
						
						for(j=0;j<17;j++)
							str5[44+j]=tempbuff[m++];
						str5[61]='\'';
						str5[62]=')';
						str5[63]='\0';
						printf("%s\n",str5);
						if(strlen(str5)!=63)
							goto start;
						mysql_query(&connection,str5);
					}
						
						
					else{
					
				   		for(i=0;i<16;i++)
    					str1[18+i]=tempbuff[m++];
	    				str1[34]='\'';
	    				str1[35]=',';
	    				str1[36]='\'';
	    		
	    				for(j=0;j<8;j++)
	    					str1[37+j]=tempbuff[m++];
	    				str1[45]='\'';
	    				str1[46]=',';
	    				str1[47]='\'';
	    		
	    				for(k=0;k<10;k++)
	    					str1[48+k]=tempbuff[m++];
	    	    
	    	    			str1[58]='\'';
	    	    			str1[59]=')';
	    	    			str1[60]='\0';
	    	    		printf("%s\n",str1);
				if(strlen(str1)!=60)
					goto start;
	    	    		mysql_query(&connection,str1);
					}
    	    		
    	    		

              }
			
			

                            
         }

         //return buff;

         close(fd);
         return 0;



         //close(fd); 

         // exit (0);
}
Beispiel #14
0
/*
description:   Input ctronl thread main function
arglist:       none
retvalue:      none
author:        Tony.Zhang
createdate:    2006/12/05
finishdate:    2006/12/05
modification description:(include author date and reason)
	author:		JayChen
	date:		2007/11/22
	reason:		combine sendkeytokonq() and sendkeypress() into SendKey()
*/
int main(int argc, char * argv[])
{	 
	/*variable define for panel input*/
	struct timeval     timeout;    			//timeout
	fd_set 			   com_set;            		//fd_set for select fd
	int 			   yalv;                  		//loop counter
	size_t 			   read_bytes;         		//how many bytes were read
	struct input_event ev[64]; 			//the events (up to 64 at once)
	int 			   maxfd=-1;              		//max file device
	char               panename[50];
	char			   usbname[50];
	//QTime              panelcalt;                      //calculate interval time
	//int                paneltime;
	int                qtkey1, qtkey2;
	int                i,tempkey;                      //temp use
	char               *cversion=NULL;
	char               cmdBuf[1024];                   //read buf
	int                rcvBytes;                       //read counter
	struct termios     opt;                            //com option setting
	char               *comname = "/dev/ttyS0";        //com device name

	/*keymaplib function*/
	char 	           usbmaplibname[] = "/zapp/keymaplib/libusbmap.so";
	char               panelmaplibname[] = "/zapp/keymaplib/libpanelmap.so";
	char               irmaplibname[] = "/zapp/keymaplib/libirmap.so";
	char 		       usbmapfuncname[] = "usbkey_convert";
	char               panelmapfuncname[] = "pkey_convert";
	char               irmapfuncname[] = "irkey_convert";
	char 		       *perror=0;
      
	if( argv[1] && !strcmp(argv[1], "-a")  )
	{
		ZDaemonize();
	} 

	init();

	/*getting input control version*/
	cversion=getenv("KONQ_INPUTCTRL_VER");     
	if(cversion)
		version=(atoi(cversion))<<4;
	printf("****current input control version=%d ****\n",version>>4);

	/*loading libirmap.so*/
	pirhandle=dlopen(irmaplibname, RTLD_LAZY);
	perror = dlerror();
	if(perror) {
		printf("open libirmap error:%s\n",perror);
	}
	else
		irmapfunction=(int (*)(int,int,int,int *,int *))dlsym(pirhandle,irmapfuncname);

	/*loading libpanelmap.so*/
	ppanelhandle=dlopen(panelmaplibname, RTLD_LAZY);
	perror = dlerror();
	if(perror) {
		printf("open libpanelmap error:%s\n",perror);
	}
	else
		panelmapfunction=(int (*)(int,int,int,int *,int *))dlsym(ppanelhandle,panelmapfuncname);

	/*loading libusbmap.so*/
	pusbhandle=dlopen(usbmaplibname, RTLD_LAZY);
	perror = dlerror();
	if(perror) {
		printf("open libusbmap error:%s\n",perror);
	}
	else
		usbmapfunction=(int (*)(int,int,int,int *,int *))dlsym(pusbhandle,usbmapfuncname);

	/*start monitor state from zqdevice*/
	// add by Joe
	Z_THREAD stateListener;
	ZUtilStartThread(&stateListener, "SentKeyState_Thread", NULL, receiveStateFromZQ);

	/*reday device*/ 
	if(version) 
		readydevice(&maxfd,usbname,panename,50);
	else {
		/*open com device && initial*/
		comfd = open( comname, O_RDWR | O_NOCTTY | O_NDELAY );
		if ( comfd == -1 )
		{
			printf("Can not find IR remote input device!\n");
		}
		opt.c_cflag = B9600 | CRTSCTS | CS8 | CLOCAL | CREAD;
		tcsetattr( comfd, TCSAFLUSH, &opt );

		set_speed( comfd, 9600 );
		if (set_Parity( comfd, 8, 1, 'N'  ) == 0)
		{
			close( comfd );
			comfd=-1;
			printf("ZInputctrl set_Parity fail!....\n");
		}
		/*ready other device*/
		readydevicev0(&maxfd,usbname,panename,50);
	}
	//panelcalt.start();

	/*Input control main loop*/
	while(1)
	{
		qtkey1 = 0;
		qtkey2 = 0;

		if(version&&maxfd==-1){
			readydevice(&maxfd,usbname,panename,50); 
			if(maxfd==-1){
				sleep(5);
				continue;
			}
		}

		FD_ZERO(&com_set);
		if(comfd!=-1)
			FD_SET(comfd,&com_set);
		if(usbkbfd!=-1)
			FD_SET(usbkbfd,&com_set);
		if(panefd!=-1)
			FD_SET(panefd,&com_set);
		timeout.tv_sec = 5;
		timeout.tv_usec = 0 ;

		i=select(maxfd+1, &com_set,NULL,NULL, &timeout );

		if(i == -1)
			continue;
		if(!i)
		{
/*			if(usbkbfd == -1)
			{
				if(version)
					finddevice(panename,usbname,"al1input","HID Keyboard Device",50);
				else
					finddevice(panename,usbname,"al1kbd","HID Keyboard Device",50);
				if(usbname[0])
					usbkbfd = open(usbname, O_RDONLY);
				if(usbkbfd!=-1)
				{
					maxfd=Max(maxfd,usbkbfd);
					printf("Have found usb keyboard %s!\n",usbname);
				}

			}
*/			continue;
		}

		if( comfd!=-1&&FD_ISSET(comfd, &com_set) )
		{
			memset(cmdBuf,0,1024);
			if(( rcvBytes = read( comfd, cmdBuf, 1024) ) > 0 )
			{
				for(i=0;i<rcvBytes;i++)
				{
					tempkey=(int)cmdBuf[i]; 
					printf("serial port have received rawkey=%d .....\n",tempkey);
					if(irmapfunction){
						irmapfunction(comfd,tempkey,0,&qtkey1,&qtkey2);
						SendKey(qtkey1 ,qtkey2);
					}
				}//end for(i=0;i<rcvBytes;i++)
			}//end if(( rcvBytes = read( com_fd, cmdBuf, 1024 ) ) > 0 )
		}//end if( FD_ISSET(com_fd, &com_set) )

		/*process for panel input*/
		else if( panefd!=-1&&FD_ISSET(panefd, &com_set) )
		{  
			read_bytes = read(panefd, ev, sizeof(struct input_event) * 64);
			if (read_bytes < (int) sizeof(struct input_event))
			{
				printf("panel input  read error!\n");
				continue;
			}

			for (yalv = 0; yalv < (int) (read_bytes / sizeof(struct input_event)); yalv++)
			{
				//printf("\npanel received code=%d ,value=%d \n",ev[yalv].code,ev[yalv].value);
				if( ev[yalv].type != EV_KEY ){
					//printf("\ntype is not EV_KEY\n");
					continue;
				}

				if(!panelmapfunction)
					break;
				if(!panelmapfunction(panefd,ev[yalv].code,version+ev[yalv].value,&qtkey1,&qtkey2))
				{
					//paneltime=panelcalt.elapsed();
					// printf("\npanel received paneltime=%d\n");
					//if(paneltime>400){
					SendKey(qtkey1 ,qtkey2);
					//}
					//panelcalt.start();
				}
			}

		}//end else if( FD_ISSET(panefd, &com_set) )

		/*process for usb keyboard input*/
		else if( usbkbfd!=-1&&FD_ISSET(usbkbfd, &com_set) ) 
		{
			if(usbkbfd==-1)
				continue;
			if(USBKeyboardParse(usbkbfd))
			{
				close(usbkbfd);
				usbkbfd=-1;
			}
		}
	}//end while
	uninit();
	return 0;
}
int main(int argc,char* argv[])
{
	
	if(argc != 3)
	{
		printf("缺少参数:error!\n");
		exit(0);
	}
	 
 	
	//*********打开串口并设置波特率*********	
	
	char *dev = (char*)argv[2]; //串口

	int fd = OpenDev(dev);           //打开串口函数
    if(fd<0)
    {
   	    close(fd);
        return FALSE;
    }

	int set_res=set_speed(fd,9600);          //设置串口

	if(set_res==FALSE)
 	{
 		close(fd);
   		return FALSE;
  	}

	if (set_Parity(fd,8,1,'N') == FALSE)
	{
		close(fd);
		return FALSE;
	}

	//***********从文件中读出指令*************** 
	int temperature = atoi(argv[1]);
	
	set_temperature(temperature);
	
    //*********发送命令************** 
	int send_res = Send_order(fd,outcommand,24);

	if(send_res==FALSE)
 	{
 		close(fd);
   		return FALSE;
	}

    char total_buff[1024];
	int length = Recv_data(fd,total_buff);//读取串口数据
	printf("接收数据长度为:%d\n",length);
	
	int j;//显示接收到的字符
    FILE *stream;
	stream = fopen("receiveinfo","w+");
	for (j = 0 ; j < length; j++)
	{       
		printf("%02X  ", total_buff[j]);
		fprintf(stream, "%02X", total_buff[j]);	
	}    
	fclose(stream);           
	printf("\n");  

	close(fd);
	return 0;

}