Ubuntu14.04下對Kvaser PCIEcan 4xHS 的配置使用
阿新 • • 發佈:2018-11-01
1.配置說明
1.1 型號匹配
工控機中使用的就是這款Kvaser PCIEcan 4xHS的PCI板卡,詳細資訊點選官網連結
1.2驅動下載:驅動程式和SDK
1.3安裝驅動:官網安裝教程
1.解壓:tar -xvzf linuxcan.tar.gz
2.下載核心標頭檔案:sudo apt-get install build-essential
3.cd linuxcan
4.make
5.安裝所有的驅動程式sudo make install
1.4測試驅動安裝是否成功
1.cd canlib/examples
2.由於工控機使用的是PCI板卡,所以需要掛載操作sudo modprobe pciefd
3.
./listChannels
4.通道載入完成效果:
2.測試CAN收發
2.1 測試程式(SDK中)
#include <canlib.h> #include <stdio.h> int main(void) { canHandle hnd; canInitializeLibrary(); hnd = canOpenChannel(0, canOPEN_EXCLUSIVE); if (hnd < 0) { char msg[64]; canGetErrorText((canStatus)hnd, msg, sizeof(msg)); fprintf(stderr, "canOpenChannel failed (%s)\n", msg); exit(1); } canSetBusParams(hnd, canBITRATE_500K, 0, 0, 0, 0, 0); canSetBusOutputControl(hnd, canDRIVER_NORMAL); canBusOn(hnd); canWrite(hnd, 123, "HELLO!", 6, 0); canWriteSync(hnd, 500); canBusOff(hnd); canClose(hnd); return 0; }
2.2 硬體接線
(CANL位)工控機端的Ch1通道:2引腳–Kavaser2引腳
(CANL位)工控機端的Ch1通道:7引腳–Kavaser7引腳
特別特別注意:必須要連線終端電阻,否則會產生Bit Error,在2與7引腳中並聯2個終端電阻,然後再接Kavaser。
2.3 測試結果
在另外一臺PC端使用BUSMASTER軟體可以觀察到報文資訊。