Lab 1 - CAN communication basics
Time: 60–90 minutes
Hardware: None (uses MockCANDriver)
Learning objectives
After completing this lab you will be able to:
- Describe CAN identifier and payload fields
- Send and receive classic CAN frames in TypeScript
- Apply a software acceptance filter by CAN ID
- Log matched frames for debugging
Prerequisites
- Node.js 18+
- Completed Getting started or equivalent
- Repository built:
npm ci && npm run build
Tasks
-
Open
starter/lab.tsand read the frame definitions. -
Implement
acceptFrame()so only ID0x200is logged. -
Run your code:
npx tsx labs/lab-01-can-basics/starter/lab.ts -
Confirm output shows one
MATCHline andLAB01_MATCHED=1. -
(Optional) Change
FILTER_IDand predict how many frames match before running.
Concepts
| Term | Meaning |
|---|---|
| CAN ID | 11-bit (standard) or 29-bit (extended) address |
| DLC | Data length - up to 8 bytes on classic CAN |
| Payload | Data bytes carried in the frame |
| Filter | Rule that selects which frames an application handles |
Stretch goals
- Log extended frames (
extended: true) separately. - Add a mask filter (accept IDs
0x200–0x2FF). - Connect two
VirtualCANPortpeers on the same interface name.
Check your work
Compare against solution/lab.ts or run the automated verifier:
npm run test:labs
Related documentation
- CAN concepts
@embedded32/canREADME