Understanding CAN Frames
CAN (Controller Area Network) communication uses frames to transmit data. Each frame is identified by a CAN ID and contains up to 8 bytes of data. Data fields within a frame are defined by their byte position, bit position, and bit length, allowing for precise extraction of values from the CAN frame payload.Naming Conventions
While not mandatory, it is recommended to adopt the following naming conventions for clarity and usability:- Write Operations: Prefix names with
control.to indicate that the field is used for controlling the device. - Read Operations: Prefix names with
measure.to signify that the field is used for measurement purposes. - Fault and Warning Fields: Use the prefixes
fault.orwarning.for fields that monitor faults or warnings. This helps in generating appropriate Telegram notifications and alerts for the system.
Required Parameters
Each register in the address map must include the following parameters:The CAN identifier for the frame containing this data field. The canId can be specified as a decimal integer or as a hexadecimal string (prefixed with
0x).Example: 100 or "0x64"The starting byte position within the CAN frame data payload (0-7).Options:
0 - 7The starting bit position within the start byte (0-7).Options:
0 - 7The total number of bits for this data field (1-64).Options:
1 - 64A unique name for the data field, representing the measurement point read from or written to the CAN device.Example:
measure.ports.port1.voltageThe data type of the value.Options:
int8 | uint8 | int16 | uint16 | int32 | uint32 | float32 | string32 | int64 | uint64 | float64Optional Parameters
These parameters are not necessary for every entry but can be included as needed:The scaling factor to apply to the CAN data field’s return value or the value being written.Example:
0.1The offset to apply to the CAN data field’s return value or the value being written.Example:
10The direction of the power or current flow on a port of the device. When the direction is set to
output,
the register value will be inverted.Options: input | outputThe minimum value of the register. For write register, setting the minimum value prevents you from
writing a value lower than the minimum value. The control command will be blocked by the Power Platform.Example:
0The maximum value of the register. For write register, setting the maximum value prevents you from
writing a value higher than the maximum value. The control command will be blocked by the Power Platform.Example:
10Indicates if mapping should be applied to the return value or the value being written.Example:
Specifies the byte order notation.Options:
little | bigExpression Registers
In addition to standard CAN data fields, you can define optional expression registers. An expression register computes a value from other registers in the address map using a specified operator and operands, rather than reading directly from the device. Each expression register requires the following parameters:A unique name for the expression register.Example:
measure.ports.port2.powerThe operator used to evaluate the expression.Options:
+ | - | * | / | > | < | >= | <= | == | != | containsA pipe-separated (
|) list of register names to use as operands. All referenced registers must exist in the address map itself.Example: measure.ports.port2.voltage|measure.ports.port2.currentAll registers referenced in the operands must exist in the address map itself.
Saving the Address Map
By following the naming conventions and adding all the required and optional parameters to each CAN data field, you have created a complete address map for the controller to communicate and interact with the device. The final JSON file should be saved with a unique name and a.json extension. For example, canbus_address_map.json.
Example
canbus_address_map.json