This project is a basic macOS CAN messaging utility. It allows you to receive and send CAN traffic on a Macintosh using the CANable CAN bus peripheral device. While its current form serves as more of CAN bus monitor and simple message sender, it can serve as a starting point for more sophisticated features as the need arises.
You'll need to have another device connected to your CAN bus that can transmit and receive messages. Examples are a Raspberry Pi with a CAN hat, a BeagleBone, a Linux or Windows machine with a suitable CAN adapter attached and configured.
- Build the project. The project builds under Xcode 12.x, but Xcode 11.x should work too.
- Run the
macCANable
app. - Plug in a CANable adapter connected to a working CAN bus.
- Select the desired CANable “usbmodem” port associated with the CANable adapter.
- Select the desired bit rate (the default is 500 kbps).
- Click the “Open” button. It becomes a "Close" button for when you want to close the port.
- Received messages are displayed in the "Receiption" text field. Use the "Clear" button to clear old data.
- To transmit, configure "Transmission "data settings and click the "Send" button.
You can also plug in two CANable adapters to your Mac, opening new windows for each adapter. You'll need to make the necessary physical CAN connections so that they can all talk.
Reference: https://github.com/normaldotcom/cantact-fw
O
- Open channelC
- Close channelS0
- Set bitrate to 10 kbpsS1
- Set bitrate to 20 kbpsS2
- Set bitrate to 50 kbpsS3
- Set bitrate to 100 kbpsS4
- Set bitrate to 125 kbpsS5
- Set bitrate to 250 kbpsS6
- Set bitrate to 500 kbpsS7
- Set bitrate to 750 kbpsS8
- Set bitrate to 1 MbpsM0
- Set mode to normal mode (default)M1
- Set mode to silent modeA0
- Disable automatic retransmissionA1
- Enable automatic retransmission (default)TIIIIIIIILDD...
- Transmit data frame (Extended ID) [ID, length, data]tIIILDD...
- Transmit data frame (Standard ID) [ID, length, data]RIIIIIIIIL
- Transmit remote frame (Extended ID) [ID, length]rIIIL
- Transmit remote frame (Standard ID) [ID, length]V
- Returns firmware version and remote path as a string
NOTE: The CAN channel must be closed when making speed and mode changes.
TX:
To close channel, set rate to 500 kbps, open channel, send 123#11.22.33.44.55.66.77.88
:
C
S6
O
t12381122334455667788
RX:
The receipt of 321#DE.AD.BE.EF
gives
t3214DEADBEEF
The project is set up as a multi-document application. This was done to allow for multiple windows
to be open, each with its own CANable connection. Although the Document
class is currently is its
default template state, a future version of the applications may offer the ability to save and restore
configurations as well as captured CAN receptions.
The main view controller is augmented by a companion "logic" class that offloads the business logic from the view controller.
Cocoa-bindings are used to manage the data exchanges of the port "bit rate" and the "Transmission" message "DLC" popup menus.
Integration with the ORSSerialPort
package is a bit tricky, especially when it comes to managing
multiple and simultaneous serial port instances. The ORSSerialPortDelegate
methods along with
Cocoa notifications are used to keep everything in order. There's probably a better way, but this works
for now.