#include <wiringSerial.h>
#include <wiringPi.h>
#include <stdio.h>
#include <unistd.h>
#include <string.h>
int mian()
{
int fd;
char cmd[128] ={'\0'};
int nread;
wiringPiSetup();
fd= serialOpen("/dev/ttyAMA0",9600);
while(1)
{
nread=read(fd,cmd,sizeof(cmd));
if(strlen(cmd)==0)
{
printf("chaoshi\n");
continue;
}
if(strstr(cmd,"open") !=NULL)
{
printf("open light\n");
}
if(strstr(cmd,"close") !=NULL)
{
printf("close light\n");
}
memset(cmd,sizeof(cmd)/sizeof(char));
}
return 0;
}
语音识别模块