Hi all,
This will be my first post so I'll try to do everything by the book.
I'm working on a project that will make a conversion from canbus to modbus TCP. I'm almost finished but I was wondering about one thing. Would it be posible to detect a failure on the canbus. With other words, would it be possible to detect if bytes stopped coming in. For me this is important because I would like to set the modbus output registers to 0 when there are no canbus frames coming in. This is mainly a safety issue.
Below I included the nodes from the canbus side. I use the node-red-contrib-socketcan plugin to proces the can frames.
[
{
"id": "bcd75a93ad2fa670",
"type": "tab",
"label": "Flow 1",
"disabled": false,
"info": "",
"env": []
},
{
"id": "0c7ef33bd1b8be2c",
"type": "socketcan-out",
"z": "bcd75a93ad2fa670",
"name": "CAN Bus in",
"config": "c9a5916d.73411",
"x": 310,
"y": 420,
"wires": [
[
"1cc9a6d5f7438318"
]
]
},
{
"id": "1cc9a6d5f7438318",
"type": "switch",
"z": "bcd75a93ad2fa670",
"name": "Filter CAN ID",
"property": "payload.canid",
"propertyType": "msg",
"rules": [
{
"t": "eq",
"v": "403105268",
"vt": "num"
},
{
"t": "eq",
"v": "288",
"vt": "num"
}
],
"checkall": "true",
"repair": false,
"outputs": 2,
"x": 550,
"y": 420,
"wires": [
[
"27cfc314f4ef45ef",
"9f2e84a8a62b1cd2"
],
[
"d04083c7b3816a61"
]
]
},
{
"id": "d04083c7b3816a61",
"type": "function",
"z": "bcd75a93ad2fa670",
"name": "Array parser",
"func": "\n\nreturn [\n{payload:msg.payload.data[0]},\n];",
"outputs": 3,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 370,
"y": 560,
"wires": [
[
"816a16f996853301"
],
[],
[]
]
},
{
"id": "816a16f996853301",
"type": "debug",
"z": "bcd75a93ad2fa670",
"name": "",
"active": true,
"tosidebar": false,
"console": false,
"tostatus": true,
"complete": "payload",
"targetType": "msg",
"x": 670,
"y": 520,
"wires": []
},
{
"id": "7479d6b23b914e70",
"type": "comment",
"z": "bcd75a93ad2fa670",
"name": "CAN ID 403105268 (0x1806e5f4)",
"info": "",
"x": 770,
"y": 160,
"wires": []
},
{
"id": "a345b535a950510d",
"type": "comment",
"z": "bcd75a93ad2fa670",
"name": "CAN ID 288 (0x120)",
"info": "",
"x": 310,
"y": 500,
"wires": []
},
{
"id": "27cfc314f4ef45ef",
"type": "function",
"z": "bcd75a93ad2fa670",
"name": "function 3",
"func": "var chargevoltage = [msg.payload.data[1],msg.payload.data[0]];\nvar buff = new Buffer(chargevoltage);\nmsg.payload = buff.readInt16LE(0);\n\nreturn msg;",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 380,
"y": 240,
"wires": [
[
"eb535b22c047d464"
]
]
},
{
"id": "eb535b22c047d464",
"type": "debug",
"z": "bcd75a93ad2fa670",
"name": "Charge voltage",
"active": true,
"tosidebar": false,
"console": false,
"tostatus": true,
"complete": "payload",
"targetType": "msg",
"statusVal": "payload",
"statusType": "auto",
"x": 600,
"y": 220,
"wires": []
},
{
"id": "9f2e84a8a62b1cd2",
"type": "function",
"z": "bcd75a93ad2fa670",
"name": "function 4",
"func": "var chargecurrent = [msg.payload.data[3],msg.payload.data[2]];\nvar buff = new Buffer(chargecurrent);\nmsg.payload = buff.readInt16LE(0);\n\nreturn msg;",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 420,
"y": 300,
"wires": [
[
"58361673de0d69a3"
]
]
},
{
"id": "58361673de0d69a3",
"type": "debug",
"z": "bcd75a93ad2fa670",
"name": "Charge current",
"active": true,
"tosidebar": false,
"console": false,
"tostatus": true,
"complete": "payload",
"targetType": "msg",
"statusVal": "payload",
"statusType": "auto",
"x": 640,
"y": 280,
"wires": []
},
{
"id": "c9a5916d.73411",
"type": "socketcan-config",
"interface": "can0"
}
]
I would love to hear your feedback.
Greeting, Marco