免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1953 | 回复: 0
打印 上一主题 下一主题

[应用] cgi 读写串口 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2015-06-10 17:27 |只看该作者 |倒序浏览
#include <stdio.h>  
#include <string.h>  
#include <sys/types.h>  
#include <sys/stat.h>  
#include <fcntl.h>  
#include <linux/input.h>
#include<stdlib.h>
#include<error.h>
#include<unistd.h>
#include<sys/select.h>
#include<time.h>
#include<termios.h>

typedef struct  
{  
  char name[32];  
  char value[32];  
}entry;  
char *uartc;  
void getValue(char *value,char *line,char flag)  
{   
   int i=0,j=0;  
   for(i=0;( (line[i]) && (line[i] != flag));i++)  
       {value[i] = line[i];}  
   value[i] = '\0';   
   if(line[i])  ++i;  
   while(line[j++] = line[i++]);      
}  
int main(int argc, char **argv)  
{  
   
    unsigned int count = 0;  
    int fduart= -1;  
    entry get;  
       
        char buf[3] ="456";
  //      char bufread[255];
//        memset(buf,0,sizeof(buf));
        
        int i ;
        void delay(int seconds){
                clock_t start = clock();
                clock_t lay = (clock_t)seconds * CLOCKS_PER_SEC;
                while((clock()-start)< lay);
        }
       
       
    printf("Content-type : text/html\n\n");  
    printf("<html>\n<head><title>LED CGI PROGRAM</title></head>\n");  
    printf("<body>\n");     
      
    usleep(500*1000);  
        struct termios tio;
         printf("try to open \n");
    fduart = open("/dev/ttySAC1",O_RDWR|O_NOCTTY | O_NDELAY);  
     
    if(fduart<0)  
     {   
       printf("Error:Can't open /dev/ttySAC1\n");  

      
       return -1;  
     }   
     printf("open success 6-10\n");
         tio.c_cflag = B115200 | CS8 | CREAD | CLOCAL ;
         tcsetattr(fduart,TCSANOW,&tio);
         
    uartc = (char *)getenv("QUERY_STRING");  
    getValue(get.name, uartc,'=');  
    getValue(get.value,uartc,'&');  
   printf("<br><center>Your input value is <b> %c </b> </center>",get.value[0]);
       
   while(1){
  
    write(fduart,buf,strlen(buf));   
    printf("write buf = %s \n",buf);

    //read(fduart,bufread,sizeof(bufread));
   // printf("read bufread = %s \n", bufread);
}
    close(fduart);  
    printf("</body>\n<html>");  
  
   return 0;  
}  
为啥只有在死循环的情况下,串口1才可以接收数据??求解
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP