嵌入式linux支援條碼槍

2021-06-28 23:31:11 字數 2406 閱讀 9197

最近乙個專案裡面需要用到usb介面條碼槍裝置。

市面上通用的usb條碼槍都是標準usb介面,不需要驅動,usb條碼槍得到的資料會向usb鍵盤一樣處理。

通過dmesg命令檢視你的linux是否支援條碼槍,另外支援的話插入條碼槍可以在輸入裝置中找到他對映的虛擬裝置。

通過命令檢視你linux裡面的裝置:cat /proc/bus/input/devices,通過裡面的資料分析出你的條碼槍中對應的虛擬裝置。

然後通過讀取/dev/input/event*裡面的資料來獲取條碼槍掃瞄的資料。

linux系統通過結構體struct input_event儲存輸入資料,具體數值定義可以在linux標頭檔案linux/input.h中找到

struct input_event ;
支援條碼槍的demo**如下

/*

* bacode.c

* * created on: 2015-3-3

* author: hp

*/#include #include #include #include #include #include #include #include #include #include #include#define kbd_device "/dev/input/event"

static char devicename[128];

#define dev_info "/proc/bus/input/devices"

static int fd_reader = -1;

static int usedev = 0;

static int getusbdevice(char *buf)

return -1;

} if (null == (p = strstr(buf, "handlers=")))

if (null != (p = strstr(p, "event")))

return -1;

}static int readonedevice(int fd)

else

} buf[cnt++] = ch;

tmp = ch;

if (cnt >= 1023)

} return -1;

}static int initbarcodedevice(void)

if (num < 0)

printf("used max dev:%d num:%d\n", usedev, num);

snprintf(devicename, sizeof(devicename), "%s%d", kbd_device, num);

printf("devicename:%s\n", devicename);

}static int fd_reader = -1;

static unsigned char lowbarchar = ;

static unsigned char upperbarchar = ', //14-27

'\0', '\0', 'a', 's', 'd', 'f', 'g', 'h', 'j', 'k', 'l', ':', '"', '~',//28-41

'\0', '|', 'z', 'x', 'c', 'v', 'b', 'n', 'm', '<', '>', '?'

};static int openbarcodereader(void)

fd_reader = open(devicename, o_rdonly | o_nonblock);

return fd_reader;

}static int closebarcodereader(void)

return 0;

}static void msleep(int msec)

int readerisready(void)

fd_zero(&fds);

fd_set(fd_reader, &fds);

if (select(fd_reader+1, &fds, null, null, &timeout) < 0)

return fd_isset(fd_reader, &fds);

}int tmpgetucode(void)

if (read_bytes >= sizeof(struct input_event) && 0 == (read_bytes % sizeof(struct input_event))) else

if (ev_key == ev[i].type && ev[i].value)

}} msleep(30);

} if (barcodebuf[0])

printf("barcode:%s\n",barcodebuf);

}int main(void)

}

ssl證書 嵌入式裝置 嵌入式裝置支援https

2.openssl 1.0.1i.tar.gz 一 一般編譯 沒有ssl支援 1.配置如下 2.把它複製到開發板 usr sbin目錄 然後複製下列檔案 3.放置網頁檔案 4.測試 default 2 main default 2 main host localhost default 2 main...

嵌入式 linux 編譯

第二次換了編譯環境編譯時又提示 make 3 drivers video console vgacon.o 錯誤 1 在網上搜尋結果 根據資訊的大概意思是關於vga的支援問題,在這裡我直接把關於vga的配置選項去掉不選,即 在執行 make menuconfig 配置時 不選vga 驅動。devic...

linux嵌入式開發

我的環境 主機 ubuntu 64位 開發板 mini2440 6 makefile檔案修改 在 opt friendlyarm mini2440 linux 2.6.29下執行 sudo vi.makefile 搜尋arm linux得到乙個結果 cross compile?arm linux 然...