Linux下串列埠通訊詳解(下)讀寫串列埠及關閉串列埠

2021-08-21 04:32:19 字數 1292 閱讀 6905

#include

ssize_t read(

int fd,

void *buf,

size_t count);

*buf:緩衝區,讀取的資料會被放到這個緩衝區中去

count:請求讀取的位元組數,讀上來的資料儲存在緩衝區buf中,同時檔案的當前讀寫位置向後移。

nread=read(fd,buff,

8);//讀串列埠

printf(

"nread=%d,%s\n",nread,buff);

nread=read(fd,buff,

8);//讀串列埠

printf(

"nread=%d,%s\n",nread,buff);

nread=read(fd,buff,

8);//讀串列埠

printf(

"nread=%d,%s\n",nread,buff);

printf

("nread=%d,%s\n"

,nread,buff);

while(

1)

#include

#include

intmain

(void)

write(stdout_fileno,buf,n);

return

0;

}

#include

ssize_t write(

int fd,

const

void *buf,

size_t count);

#include

intclose

(int fd)

;

nread=read(fd,buff,

8);//讀串列埠

printf(

"nread=%d,%s\n",nread,buff);

nread=read(fd,buff,

8);//讀串列埠

printf(

"nread=%d,%s\n",nread,buff);

nread=read(fd,buff,

8);//讀串列埠

printf(

"nread=%d,%s\n",nread,buff);

Linux下串列埠通訊詳解(下)讀寫串列埠及關閉串列埠

這一篇將要把讀寫串列埠及串列埠關閉的操作詳細介紹一下。讀串列埠就是接收串列埠資料,通過read來實現。read函式原型 include ssize t read int fd,void buf,size t count 引數說明 如下兩句 即可 nread read fd,buff,8 讀串列埠 p...

Linux下串列埠通訊

1.開啟串列埠 與其他的關於裝置程式設計的方法一樣,在linux下,操作 控制串列埠也是通過操作起裝置檔案進行的。在linux下,串列埠的裝置檔案是 dev ttys0或 dev ttys1等。因此要讀寫串列埠,我們首先要開啟串列埠 char dev dev ttys0 串列埠1 int fd op...

linux 下串列埠通訊

include include include include include include include include include define baudrate b115200 baud rate 115200 define device dev ttyama0 define size...