- 论坛徽章:
- 0
|
#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才可以接收数据??求解 |
|