node-red-contrib-seeed-canbus
Version:
Node-RED nodes for Gimbal
140 lines (119 loc) • 4.06 kB
HTML
<script type="text/html" data-template-name="can-write">
<div class="form-row">
<label for="node-input-name">
<i class="fa fa-tag"></i>
<span>Name</span>
</label>
<input type="text" id="node-input-name" />
</div>
<div class="form-row">
<label for="node-input-client">
<i class="fa fa-globe"></i>
<span>Client</span>
</label>
<input type="text" id="node-input-client" />
</div>
</script>
<script type="text/javascript">
RED.nodes.registerType("can-write", {
category: "CAN Bus",
color: "#A6D996",
defaults: {
name: { value: "" },
client: {
type: "can-config",
required: true,
label: RED._("can-config"),
},
},
inputs: 1,
outputs: 1,
icon: "font-awesome/fa-paper-plane",
paletteLabel: "CAN write",
label: function () {
return this.name || "CAN write";
},
oneditprepare: function () {},
oneditsave: function () {},
});
</script>
<script type="text/markdown" data-help-name="can-write">
# CAN Write
This node sends CAN bus frames and receives the corresponding response frames using SocketCAN.
## Overview
The CAN Write node allows you to send command frames to CAN bus devices and receive their response frames. It's particularly useful for querying device status, sending control commands, and monitoring responses from CAN bus devices.
## Configuration
- **Name**: Optional name for the node
- **Client**: Select the CAN bus configuration to use (must be configured in a CAN-config node)
## Input
The input supports two formats:
### Format 1: String Format (Recommended)
A string in the format: `ID#DATA` where ID is the CAN identifier in hexadecimal and DATA is dot-separated hex bytes.
Example: `141#c1.0a.64.00.00.00.00.00`
### Format 2: Object Format
An object with the following structure:
```json
{
"id": "141",
"data": ["A4", "00", "2C", "01", "50", "46", "00", "00"]
}
```
Where:
- **id**: The CAN identifier as a string (in hexadecimal without 0x prefix)
- **data**: Array of data bytes in hexadecimal (without 0x prefix)
## Output
The node outputs an object with the following structure:
```json
{
"payload": "141#90.00.AB.02.3C.4C.91.49",
"details": {
"id": "141",
"data": ["90", "00", "AB", "02", "3C", "4C", "91", "49"],
"raw": "90.00.AB.02.3C.4C.91.49"
},
"timestamp": 1632048172456,
"topic": "can-response"
}
```
Where:
- **payload**: String in the format `ID#DATA`
- **details**: Object containing detailed information:
- **id**: The CAN identifier (same as request)
- **data**: Array of response bytes in hexadecimal
- **raw**: Dot-separated string of the response bytes
- **timestamp**: Time when the response was received
- **topic**: Set to "can-response"
### Example
Request (Input string):
```
141#90.00.00.00.00.00.00.00
```
Response (Output):
```json
{
"payload": "141#90.00.AB.02.3C.4C.91.49",
"details": {
"id": "141",
"data": ["90", "00", "AB", "02", "3C", "4C", "91", "49"],
"raw": "90.00.AB.02.3C.4C.91.49"
},
"timestamp": 1632048172456,
"topic": "can-response"
}
```
## Response Handling
The node waits for a response from the CAN device and automatically filters response frames to ensure you receive the relevant response to your specific command.
## Timeout
If no response is received within the configured timeout period, the node will output an error message.
## Error Handling
The node will report errors in the following cases:
- Invalid input format
- CAN bus communication error
- Response timeout
## Notes
- All hexadecimal values should be provided without the "0x" prefix
- The node uses SocketCAN for direct CAN bus communication
- The data must be exactly 8 hexadecimal bytes
- Not all CAN frames will generate a response; some are one-way commands
- The string format `ID#DATA` is compatible with the CAN Read node output
</script>