部分代码借鉴地址:https://blog.youkuaiyun.com/wangqingchuan92/article/details/73497354/ 谢谢!
1.创建线程在线程内进行串口之间的收发
void CREAT_pthread(void)
{
pthread_t t0;
//创建线程1
if(pthread_create(&t0, NULL, print_a, NULL) == -1){
puts("fail to create pthread t0");
exit(1);
}else
{
printf("\n\nt0 create success!!!");
}
}
遇到的问题:在一开始创建线程的时候,调用了pthread_join()函数,主线程需要等子线程完成操作后才会执行。由于子线程是电视开机后一直在执行,随时会接收数据发送数据,因此导致主线程没办法执行,电视死机没办法正常操作。
// 等待线程结束
void * result;
if(pthread_join(t0, &result) == -1){
puts("fail to recollect t0");
//exit(1);
}
if(pthread_join(t1, &result) == -1){
puts("fail to recollect t1");
// exit(1);
}
2.打开串口
int OpenDev(char *Dev)
{
int fd = open(Dev,O_RDWR | O_NOCTTY | O_NONBLOCK);
if(-1 == fd)
{
per