Your function code 2- works , as I've just done the same experiment.
var buf = Buffer.from([0xaa, 0x3f, 0x00, 0x00, 0xf0, 0x11]);
msg.payload = buf;
return msg;
Code of my flow
[
{
"id": "4a65bd5989e6e48a",
"type": "tab",
"label": "流程 1",
"disabled": false,
"info": "",
"env": []
},
{
"id": "deb4b3071092f4b4",
"type": "serial-port",
"serialport": "/dev/ttyS4",
"serialbaud": "9600",
"databits": "8",
"parity": "none",
"stopbits": "1",
"waitfor": "",
"dtr": "none",
"rts": "none",
"cts": "none",
"dsr": "none",
"newline": "1",
"bin": "false",
"out": "time",
"addchar": "",
"responsetimeout": "10000"
},
{
"id": "d4aee0b6830813cf",
"type": "serial out",
"z": "4a65bd5989e6e48a",
"name": "",
"serial": "deb4b3071092f4b4",
"x": 400,
"y": 320,
"wires": []
},
{
"id": "f0a90340ad0b821f",
"type": "debug",
"z": "4a65bd5989e6e48a",
"name": "debug 1",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "false",
"statusVal": "",
"statusType": "auto",
"x": 440,
"y": 220,
"wires": []
},
{
"id": "daab7c3dfd21638b",
"type": "function",
"z": "4a65bd5989e6e48a",
"name": "function 1",
"func": "var buf = Buffer.from([0xaa, 0x3f, 0x00, 0x00, 0xf0, 0x11]);\nmsg.payload = buf;\nreturn msg;",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 220,
"y": 280,
"wires": [
[
"f0a90340ad0b821f",
"d4aee0b6830813cf"
]
]
},
{
"id": "782bddc5e8783cf7",
"type": "inject",
"z": "4a65bd5989e6e48a",
"name": "",
"props": [
{
"p": "payload"
},
{
"p": "topic",
"vt": "str"
}
],
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "",
"payload": "",
"payloadType": "date",
"x": 150,
"y": 200,
"wires": [
[
"daab7c3dfd21638b"
]
]
}
]
