發表文章

RS232 read write ..

file1: with select #include <pthread.h> #include <stdio.h> #include <termios.h> #include <fcntl.h> #include <string.h> #include <sys/select.h> #define BUFFER_SIZE 100 char* Message="Hello1 Hello2 Hello3 Hello4 Hello5 Hello6 Hello7 Hello8 Hello9 Hello10"; char incomingBuffer[BUFFER_SIZE]; int fd1; int fd2; void* ReaderThread(void* object) {      int total=0;      int expected=strlen(Message);      struct timeval timeOut;      fd_set fdSet;      int maxFdp=0;      printf("Waiting for data on serial ports\r\n");      while(total<expected)     {           timeOut.tv_sec=0;           timeOut.tv_usec=1000000; // Every 100 ms            FD_ZERO(&fdSet);           FD_SET(fd1, &fdSet);      ...

RS232 baudrate setting

#include <stdio.h> #include <string.h> #include <unistd.h> #include <fcntl.h> #include <errno.h> #include <termios.h> int fd=-1; int getbaud(int fd) {      struct termios termAttr;      int inputSpeed = -1;      speed_t baudRate;      tcgetattr(fd, &termAttr);      /* Get the input speed. */      baudRate = cfgetispeed(&termAttr);      switch (baudRate)      {           case B0: inputSpeed = 0; break;           case B50: inputSpeed = 50; break;           case B110: inputSpeed = 110; break;           case B134: inputSpeed = 134; break;           case B150: inputSpeed = 150; break;           case B20...

shell 指令備忘

shell 指令 1. locate      locate tmp | more      尋找檔名有 tmp 的檔案.      如果跑出來一大堆的結果, 那可以使用 more 來將輸出的東西分頁暫停. 2. find      find . -name "*.tmp"      尋找目前目錄及其子目錄, 副檔名為 tmp 的檔案.      find . -name "*.tmp" -exec rm {} \;      同上, 但找到後執行刪除動作.      英文句點代表現行目錄, 當然也可以改成其他的目錄. 3. grep      尋找的是檔案內容是否含有某些字串.      grep Linux *      找目前目錄(不含子目錄)所有含有 Linux 字串的檔案      grep -r Linux *      同上, 但會連子目錄也去找           grep & locate 組合使用           locate tmp | grep Linux 只找含有 Linux 字串的 tmp 檔案.           locate tmp | grep doc 同理, 要找 tmp 的相關說明檔時, 就可以這樣使用.           locate tmp | ...

gettimeofday sample code

#include < sys/time.h > #include < stdio.h > int main() {   struct timeval tv, tv2;   unsigned long long start_utime, end_utime;   gettimeofday(&tv,NULL);   start_utime = tv.tv_sec * 1000000 + tv.tv_usec;     usleep(1000);   gettimeofday(&tv2,NULL);   end_utime = tv2.tv_sec * 1000000 + tv2.tv_usec;     printf(" runtime = %llu\n", end_utime - start_utime ); }

Thumbs.db

圖片
Thumbs.db 是隱藏檔及系統檔屬性的。 Thumbs.db 其實是檔案總管所自動建立的縮圖快取檔案,只要你使用檔案總管的縮圖檢視模式並瀏覽至有多媒體檔案(列如圖像、影片…之類的檔案)存在的資料夾 Windows 便會自行建立該檔,以加速你下次再瀏覽此資料夾時縮圖顯示的速度,而如果你電腦中多媒體檔案不少的話這個 Thumbs.db 檔案佔用的空間相對的也就相當驚人。 要讓 Winodws 別建立 Thumbs.db 最有效的方法就是停止建立縮圖快取,可以透過「 控制台\資料夾選項\檢視 」設定中勾選「 不要快取縮圖 」來讓 Windows 停止建立縮圖快取。 利用 bat 檔,一次刪掉所有的  Thumbs.db,如下 for %%d in (C D E F G H I J K L M N O P Q R S T U V W X Y Z) do del /s /q /f %%d:\Thumbs.db

Linux 終端機下的彩色顯示: 有那些顏色可以選擇呢?

圖片
#!/bin/bash # 顯示 ANSI 的彩色 # esc="\033[" echo -n " _ _ _ _ _40 _ _ _ 41_ _ _ _42 _ _ _ 43" echo "_ _ _ 44_ _ _ _45 _ _ _ 46_ _ _ _47 _" for fore in 30 31 32 33 34 35 36 37; do     line1="$fore "     line2=" "     for back in 40 41 42 43 44 45 46 47; do         line1="${line1}${esc}${back};${fore}m Normal ${esc}0m"         line2="${line2}${esc}${back};${fore};1m Bold ${esc}0m"     done     echo -e "$line1\n$line2" done 前景的顏色號碼是在左邊那一排,背景的則是在上方。 如果你要粗體的字元和高亮度就在參數裏加一個 " 1 " ,所以前景是白色而背景是藍色就成了 "37;44; 1 "。 整個的 ANSI 顏色選擇序列就是 esc[ 3 7 ; 4 4 ; 1 m 註: 背景不可以是高亮度,所以黃色(高亮度的棕色)只能用來作前景。這是硬體上的限制。 顏色代碼: 0 - 黑色 4 - 藍色   3# 是背景顏色 1 - 紅色 5 - 粉紅色 4# 是前景顏色 2 - 綠色 6 - 青色 3 - 黃色 7 - 白色   ;1 是粗體和高亮度

Linux C 函數參考

Linux C 函數參考 http://www.cs.nctu.edu.tw/~yslin/library/linuxc/main.htm