#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <pthread.h>
#include <wiringPi.h>
#include <wiringSerial.h>
#include <stdlib.h>
#include <unistd.h>
int fd;
void *sendHandler()
{
char *sendBuf;
sendBuf = (char *)malloc(32*sizeof(char));
while(1){
memset(sendBuf,'\0',32);
scanf("%s",sendBuf);
while(*sendBuf){
serialPutchar(fd,*sendBuf++);
}
}
}
void *revHandler()
{
while(1){
while(serialDataAvail(fd)){
printf("%c",serialGetchar(fd));
fflush(stdout);
}
}
}
int main()
{
pthread_t idSend;
pthread_t idRev;
fd = serialOpen("/dev/ttyS5",115200);
if(fd<0){
printf("open serail failed\n");
return 1;
}
pthread_create(&idSend,NULL,sendHandler,NULL);
pthread_create(&idRev,NULL,revHandler,NULL);
wiringPiSetup();
while(1){
sleep(10);
}
printf("\n");
return 0;
}
H616基于wiringPi的串口开发
最新推荐文章于 2024-06-09 17:57:01 发布