串列埠應用程式設計

2021-06-27 16:38:06 字數 1981 閱讀 6829

#include  #include  /*標準輸入輸出定義*/

#include /*標準函式庫定義*/

#include /*unix 標準函式定義*/

#include #include #include /*檔案控制定義*/

#include /*ppsix 終端控制定義*/

#include /*錯誤號定義*/

#include #include #include #include #include #include #include #define false 0

#define true 1

#define com1 "/dev/ttysac1"

#define com2 "/dev/ttysac2"

#define com3 "/dev/ttysac3"

#define inftim -1

int speed_arr=;

int name_arr =;

pthread_mutex_t mutex_rx_thread =pthread_mutex_initializer;

pthread_cond_t cond_rx_thread =pthread_cond_initializer;

//設定資料位,停止位,校驗位

int set_parity(int fd,int databits,int stopbits,int parity)

options.c_cflag &= ~csize;

//設定資料位

switch (databits)

//設定奇偶校驗

switch (parity)

// 設定停止位

switch (stopbits)

//set input parity option

if ((parity != 'n')&&(parity != 'n'))

options.c_iflag |= inpck;

options.c_cc[vtime] = 5; // 0.5 seconds

options.c_cc[vmin] = 1;

options.c_cflag &= ~hupcl;

options.c_iflag &= ~inpck;

options.c_iflag |= ignbrk;

options.c_iflag &= ~icrnl;

options.c_iflag &= ~ixon;

options.c_lflag &= ~iexten;

options.c_lflag &= ~echok;

options.c_lflag &= ~echoctl;

options.c_lflag &= ~echoke;

options.c_oflag &= ~onlcr;

//重新整理

tcflush(fd,tciflush);

if (tcsetattr(fd,tcsanow,&options) != 0)

return (true);

}//設定波特率

int set_speed(int fd,int speed)

else if (len>0)}}

}} //loge("out the while loop"); }}

int main(int argc, char **argv)

printf("init serial success!!\r\n");

byte_write=write(fd,msg,strlen(msg));

printf("byte wirte :%d\r\n",byte_write);

/* ret=pthread_create(&thread_id,null,(void*)rx_thread,(int*)&fd);

if(ret!=0)

*/ return 0;

}

Linux串列埠應用程式設計

常見的資料通訊的基本方式可分為並行通訊與序列通訊兩種。1.並行通訊是指利用多條資料傳輸線將乙個字資料的各位元位同時傳送。它的特點是傳輸速度快,適用於傳輸距離短且傳輸速度較高的通訊。2.序列通訊是指利用一條傳輸線將資料以位元位為單位順序傳送。特點是通訊 線路簡單,利用簡單的線纜就可實現通訊,降低成本,...

IAP 應用程式設計

1 檢查是否需要對第二部分 進行更新 2 如果不需要更新則轉到4 3 執行更新操作 4 跳轉到第二部分 執行 第一部分 必須通過其它手段,如jtag或isp燒入 第二部分 可以使用第一部分 iap功能燒入,也可以和第一部分 一道燒入,以後需要程式更新是再通過第一部分iap 更新。對於stm32來說,...

嵌入式Linux串列埠應用程式設計之串列埠讀寫

2013 08 27 在配置完串列埠的相關屬性後,就可以對串列埠進行開啟和讀寫操作了。它所使用的函式和普通檔案的讀寫函式一樣,都是open write 和read 它們之間區別的只是串列埠是乙個終端裝置,因此在選擇函式的具體引數時會有一些區別。另外,這裡會用到一些附加的函式,用於測試終端裝置的連線情...