資源簡介
本代碼使用C語言實現串口數據發送、接收,代碼帶詳細注解,便于初學者理解,只需要編譯就可直接使用。
代碼片段和文件信息
#include?????
#include?????
#include?????
#include???
#include?????
#include??????
#include????
#include?????
#include??
???
#define?UARTBUFF?512?
int?UartOpen(char*?port)??
{???
int?fd?=?-1;
fd?=?open(?port?O_RDWR|O_NOCTTY|O_NDELAY);??
????if?(fd?0)??
????{??
????????perror(“Can‘t?Open?Serial?Port“);??
????????return?-1;??
????}??
?????//恢復串口為阻塞狀態?????????????????????????????????
????if(fcntl(fd?F_SETFL?0)?0)??
????{??
????????printf(“fcntl?failed!\n“);??
????????return?-1;??
????}???????
????
//測試是否為終端設備??????
????if(0?==?isatty(fd))??
????{??
????????printf(“standard?input?is?not?a?terminal?device\n“);??
????????return(-1);??
????}??
?????????????
return?fd;??
}??
//關閉串口并返回串口設備文件描述?
void?UartClose(int?fd)??
{??
????close(fd);??
}??
???
int?UartSet(int?fdint?speedint?flow_ctrlint?databitsint?stopbitschar?parity)??
{??????
????
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件????????8336??2018-01-24?13:37??uart.c
- 上一篇:C語言版詞頻分析器
- 下一篇:數據結構題集(C語言版)答案
評論
共有 條評論