You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

47 lines
1.6 KiB

1 year ago
  1. # USB-CAN Analyzer Linux Support
  2. This is a small C program that dumps the CAN traffic for one these adapters:
  3. ![alt text](USB-CAN.jpg)
  4. These adapters can be found everywhere on Ebay nowadays, but there is no official Linux support. Only a Windows binary file [stored directly on GitHub](https://github.com/SeeedDocument/USB-CAN_Analyzer).
  5. When plugged in, it will show something like this:
  6. ```
  7. Bus 002 Device 006: ID 1a86:7523 QinHeng Electronics HL-340 USB-Serial adapter
  8. ```
  9. And the whole thing is actually a USB to serial converter, for which Linux will provide the 'ch341-uart' driver and create a new /dev/ttyUSB device. So this program simply implements part of that serial protocol.
  10. ## Build
  11. `canusb.c` can be compile just by running `make` or with:
  12. ```
  13. $ gcc canusb.c -o canusb
  14. ```
  15. ## Usage
  16. ```
  17. $ ./canusb -h
  18. Usage: ./canusb <options>
  19. Options:
  20. -h Display this help and exit.
  21. -t Print TTY/serial traffic debugging info on stderr.
  22. -d DEVICE Use TTY DEVICE.
  23. -s SPEED Set CAN SPEED in bps.
  24. -b BAUDRATE Set TTY/serial BAUDRATE (default: 2000000).
  25. -i ID Inject using ID (specified as hex string).
  26. -j DATA CAN DATA to inject (specified as hex string).
  27. -n COUNT Terminate after COUNT frames (default: infinite).
  28. -g MS Inject sleep gap in MS milliseconds (default: 200 ms).
  29. -m MODE Inject payload MODE (0 = random, 1 = incremental, 2 = fixed).
  30. ```
  31. ## Example commands:
  32. ```
  33. # dump CAN bus traffic from 1 Mbit CAN bus
  34. $ ./canusb -t -d /dev/ttyUSB0 -s 1000000 -t
  35. # send the bytes 0xBEEE from ID 005 on at 1 Mbit CAN bus
  36. $ ./canusb -d /dev/ttyUSB0 -s 1000000 -t -i 5 -j BEEE
  37. ```