Create hexadecimal number [modbus ID] to byte array

I need to select different ids in the dashboard and convert this value to be accepted in Buffer.from

I'm leaving an example of what I'm trying to build. Help !!!

[{"id":"47900d60d1fbef96","type":"tab","label":"Flow 2","disabled":false,"info":"","env":[]},{"id":"5cf9d039738398cc","type":"ui_numeric","z":"47900d60d1fbef96","name":"","label":"SKC","tooltip":"","group":"3dc07bebff5ec3b0","order":5,"width":0,"height":0,"wrap":false,"passthru":true,"topic":"topic","topicType":"msg","format":"{{value}}","min":0,"max":"60","step":1,"className":"","x":110,"y":300,"wires":[["25d8a1558e512ad3","e03221954e62f7a6"]]},{"id":"2a1512923ac74818","type":"function","z":"47900d60d1fbef96","name":"Hex p/ Automatico","func":"//How to create this variable for each number chosen in the \"SKC\" dasbooard, and inject it into Buffer.from?\n//Ex: SKC = 5 -> \n// var id = msg.topic\n//msg.payload = Buffer.from([\"id\",0x41,0x00...]);\nmsg.payload = Buffer.from([??,0x41,0x06,0x00,0x00,0xA9,0xFD]);\nreturn msg;\n","outputs":1,"noerr":2,"initialize":"","finalize":"","libs":[],"x":510,"y":340,"wires":[["f784b0e82c8e2337"]]},{"id":"d53357dcd44a173c","type":"function","z":"47900d60d1fbef96","name":"Hex p/ Manual","func":"//How to create this variable for each number chosen in the \"SKC\" dasbooard, and inject it into Buffer.from?\n//Ex: SKC = 5 -> \n// var id = msg.topic\n//msg.payload = Buffer.from([\"id\",0x41,0x06...]);\nmsg.payload = Buffer.from([??, 0x41, 0x16, 0x00, 0x00, 0xA8, 0x38]);\nreturn msg;\n","outputs":1,"noerr":2,"initialize":"","finalize":"","libs":[],"x":500,"y":240,"wires":[["f784b0e82c8e2337"]]},{"id":"f784b0e82c8e2337","type":"tcp out","z":"47900d60d1fbef96","name":"Enviar dados p/ SKC","host":"192.168.108.42","port":"5300","beserver":"client","base64":false,"end":false,"tls":"","x":780,"y":280,"wires":[]},{"id":"e03221954e62f7a6","type":"ui_button","z":"47900d60d1fbef96","name":"","group":"3dc07bebff5ec3b0","order":2,"width":0,"height":0,"passthru":false,"label":"Automatico","tooltip":"","color":"","bgcolor":"","className":"","icon":"","payload":"","payloadType":"str","topic":"topic","topicType":"msg","x":290,"y":340,"wires":[["2a1512923ac74818"]]},{"id":"18b74170981789be","type":"comment","z":"47900d60d1fbef96","name":"ID Modbus","info":"","x":100,"y":240,"wires":[]},{"id":"25d8a1558e512ad3","type":"ui_button","z":"47900d60d1fbef96","name":"","group":"3dc07bebff5ec3b0","order":1,"width":0,"height":0,"passthru":false,"label":"Manual","tooltip":"","color":"","bgcolor":"","className":"","icon":"","payload":"","payloadType":"str","topic":"topic","topicType":"msg","x":280,"y":240,"wires":[["d53357dcd44a173c"]]},{"id":"3dc07bebff5ec3b0","type":"ui_group","name":"Teste","tab":"a055df2d1f664f7f","order":1,"disp":true,"width":"6","collapse":false,"className":""},{"id":"a055df2d1f664f7f","type":"ui_tab","name":"Teste","icon":"dashboard","disabled":false,"hidden":false}]

Get it resolved this way.

[{"id":"e05ceaf7947a5ec7","type":"tab","label":"Flow 3","disabled":false,"info":"","env":[]},{"id":"8ef8f309955fae09","type":"ui_button","z":"e05ceaf7947a5ec7","name":"","group":"82e02d9557fd1079","order":2,"width":0,"height":0,"passthru":false,"label":"Manual","tooltip":"","color":"","bgcolor":"","className":"","icon":"","payload":"trigger","payloadType":"str","topic":"control","topicType":"str","x":300,"y":200,"wires":[["5a36dad6882f1418"]]},{"id":"71055843d79b13fc","type":"ui_text_input","z":"e05ceaf7947a5ec7","name":"Nº SKC: ","label":"Nº SKC: ","tooltip":"","group":"82e02d9557fd1079","order":1,"width":0,"height":0,"passthru":true,"mode":"text","delay":"100","topic":"","sendOnBlur":true,"className":"","topicType":"str","x":300,"y":160,"wires":[["5a36dad6882f1418","d27436d797e8d50c","7f8f325fb7663feb","5221b21b4921c1ab","eb3c3ecf5bc1056d","8fbca6f987544874"]]},{"id":"5a36dad6882f1418","type":"q-gate","z":"e05ceaf7947a5ec7","name":"","controlTopic":"control","defaultState":"queueing","openCmd":"open","closeCmd":"close","toggleCmd":"toggle","queueCmd":"queue","defaultCmd":"default","triggerCmd":"trigger","flushCmd":"flush","resetCmd":"reset","peekCmd":"","dropCmd":"","statusCmd":"","maxQueueLength":"1","keepNewest":true,"qToggle":false,"persist":false,"storeName":"memory","x":530,"y":160,"wires":[["7f961ac730f8ec7b"]]},{"id":"7f961ac730f8ec7b","type":"function","z":"e05ceaf7947a5ec7","name":"Hex p/ Manual","func":"msg.oldPayload = msg.payload;\nvar noSpaces = msg.payload.replace(/ /g, '');// remove spaces\n//msg.payload = Buffer.from(noSpaces, \"hex\"); //convert to buffer\nmsg.payload = Buffer.from([noSpaces, 0x41, 0x16, 0x00, 0x00, 0xA8, 0x38]);\nreturn msg;\n","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":720,"y":160,"wires":[["9c3cd2f179af5fe9","37fb01c5a68c176b"]]},{"id":"9c3cd2f179af5fe9","type":"tcp out","z":"e05ceaf7947a5ec7","name":"Input SKC","host":"192.168.108.42","port":"5300","beserver":"client","base64":false,"end":false,"tls":"","x":1010,"y":240,"wires":[]},{"id":"d19b919c422e775b","type":"function","z":"e05ceaf7947a5ec7","name":"Hex p/ Automatico","func":"msg.oldPayload = msg.payload;\nvar noSpaces = msg.payload.replace(/ /g, '');// remove spaces\n//msg.payload = Buffer.from(noSpaces, \"hex\"); //convert to buffer\nmsg.payload = Buffer.from([noSpaces,0x41,0x06,0x00,0x00,0xA9,0xFD]);\nreturn msg;\n","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":730,"y":240,"wires":[["9c3cd2f179af5fe9","37fb01c5a68c176b"]]},{"id":"4344ddeb35aae653","type":"function","z":"e05ceaf7947a5ec7","name":"Go to Zero","func":"msg.oldPayload = msg.payload;\nvar noSpaces = msg.payload.replace(/ /g, '');// remove spaces\n//msg.payload = Buffer.from(noSpaces, \"hex\"); //convert to buffer\nmsg.payload = Buffer.from([noSpaces,0x41,0xA3,0x00,0x00,0xB9,0xDE]);\nreturn msg;\n","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":710,"y":300,"wires":[["9c3cd2f179af5fe9","37fb01c5a68c176b"]]},{"id":"88840b4fcc2ace8e","type":"function","z":"e05ceaf7947a5ec7","name":"Reset","func":"msg.oldPayload = msg.payload;\nvar noSpaces = msg.payload.replace(/ /g, '');// remove spaces\n//msg.payload = Buffer.from(noSpaces, \"hex\"); //convert to buffer\nmsg.payload = Buffer.from([noSpaces,0x41,0x05,0x00,0x00,0x59,0xFD]);\nreturn msg;\n","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":690,"y":360,"wires":[["9c3cd2f179af5fe9","37fb01c5a68c176b"]]},{"id":"c97da270b6265081","type":"function","z":"e05ceaf7947a5ec7","name":"Global IN","func":"msg.oldPayload = msg.payload;\nvar noSpaces = msg.payload.replace(/ /g, '');// remove spaces\n//msg.payload = Buffer.from(noSpaces, \"hex\"); //convert to buffer\nmsg.payload = Buffer.from([noSpaces,0x41,0xA3,0x03,0xDE,0x39,0x76]);\nreturn msg;\n","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":700,"y":420,"wires":[["9c3cd2f179af5fe9","37fb01c5a68c176b"]]},{"id":"d27436d797e8d50c","type":"q-gate","z":"e05ceaf7947a5ec7","name":"","controlTopic":"control","defaultState":"queueing","openCmd":"open","closeCmd":"close","toggleCmd":"toggle","queueCmd":"queue","defaultCmd":"default","triggerCmd":"trigger","flushCmd":"flush","resetCmd":"reset","peekCmd":"","dropCmd":"","statusCmd":"","maxQueueLength":"1","keepNewest":true,"qToggle":false,"persist":false,"x":530,"y":240,"wires":[["d19b919c422e775b"]]},{"id":"37fb01c5a68c176b","type":"debug","z":"e05ceaf7947a5ec7","name":"debug 3","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":1020,"y":160,"wires":[]},{"id":"7f8f325fb7663feb","type":"q-gate","z":"e05ceaf7947a5ec7","name":"","controlTopic":"control","defaultState":"queueing","openCmd":"open","closeCmd":"close","toggleCmd":"toggle","queueCmd":"queue","defaultCmd":"default","triggerCmd":"trigger","flushCmd":"flush","resetCmd":"reset","peekCmd":"","dropCmd":"","statusCmd":"","maxQueueLength":"1","keepNewest":true,"qToggle":false,"persist":false,"x":530,"y":300,"wires":[["4344ddeb35aae653"]]},{"id":"0098d77d0242ab02","type":"ui_button","z":"e05ceaf7947a5ec7","name":"","group":"82e02d9557fd1079","order":3,"width":0,"height":0,"passthru":false,"label":"Automatico","tooltip":"","color":"","bgcolor":"","className":"","icon":"","payload":"trigger","payloadType":"str","topic":"control","topicType":"str","x":310,"y":240,"wires":[["d27436d797e8d50c"]]},{"id":"3c044cb36ca68de9","type":"ui_button","z":"e05ceaf7947a5ec7","name":"","group":"82e02d9557fd1079","order":4,"width":0,"height":0,"passthru":false,"label":"Go to Zero","tooltip":"","color":"","bgcolor":"","className":"","icon":"","payload":"trigger","payloadType":"str","topic":"control","topicType":"str","x":310,"y":300,"wires":[["7f8f325fb7663feb"]]},{"id":"b898506498185678","type":"ui_button","z":"e05ceaf7947a5ec7","name":"","group":"82e02d9557fd1079","order":5,"width":0,"height":0,"passthru":false,"label":"Reset","tooltip":"","color":"","bgcolor":"","className":"","icon":"","payload":"trigger","payloadType":"str","topic":"control","topicType":"str","x":290,"y":360,"wires":[["5221b21b4921c1ab"]]},{"id":"5221b21b4921c1ab","type":"q-gate","z":"e05ceaf7947a5ec7","name":"","controlTopic":"control","defaultState":"queueing","openCmd":"open","closeCmd":"close","toggleCmd":"toggle","queueCmd":"queue","defaultCmd":"default","triggerCmd":"trigger","flushCmd":"flush","resetCmd":"reset","peekCmd":"","dropCmd":"","statusCmd":"","maxQueueLength":"1","keepNewest":true,"qToggle":false,"persist":false,"x":530,"y":360,"wires":[["88840b4fcc2ace8e"]]},{"id":"eb3c3ecf5bc1056d","type":"q-gate","z":"e05ceaf7947a5ec7","name":"","controlTopic":"control","defaultState":"queueing","openCmd":"open","closeCmd":"close","toggleCmd":"toggle","queueCmd":"queue","defaultCmd":"default","triggerCmd":"trigger","flushCmd":"flush","resetCmd":"reset","peekCmd":"","dropCmd":"","statusCmd":"","maxQueueLength":"1","keepNewest":true,"qToggle":false,"persist":false,"x":530,"y":420,"wires":[["c97da270b6265081"]]},{"id":"d16ed591e8a9b2d9","type":"ui_button","z":"e05ceaf7947a5ec7","name":"","group":"82e02d9557fd1079","order":6,"width":0,"height":0,"passthru":false,"label":"Global IN","tooltip":"","color":"","bgcolor":"","className":"","icon":"","payload":"trigger","payloadType":"str","topic":"control","topicType":"str","x":300,"y":420,"wires":[["eb3c3ecf5bc1056d"]]},{"id":"7b937b9990199b69","type":"tcp out","z":"e05ceaf7947a5ec7","name":"Enviar dados p/ SKC","host":"192.168.108.42","port":"5300","beserver":"client","base64":false,"end":false,"tls":"","x":800,"y":540,"wires":[]},{"id":"8fbca6f987544874","type":"function","z":"e05ceaf7947a5ec7","name":"Hex p/ Status Gerais","func":"msg.oldPayload = msg.payload;\nvar noSpaces = msg.payload.replace(/ /g, '');// remove spaces\n//msg.payload = Buffer.from(noSpaces, \"hex\"); //convert to buffer\nmsg.payload = Buffer.from([noSpaces,0x64,0x00,0x00,0x00,0x42,0xF0]);\nreturn msg;\n","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":540,"y":540,"wires":[["7b937b9990199b69"]]},{"id":"84987833ffd84ec8","type":"comment","z":"e05ceaf7947a5ec7","name":"Status Completo SKC","info":"","x":540,"y":500,"wires":[]},{"id":"a84fbb877c5c059f","type":"debug","z":"e05ceaf7947a5ec7","name":"debug 4","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":780,"y":600,"wires":[]},{"id":"feb1f53c8e915e9d","type":"inject","z":"e05ceaf7947a5ec7","name":"Atualizar cada 10 s","props":[],"repeat":"10","crontab":"","once":true,"onceDelay":"10","topic":"","x":100,"y":160,"wires":[["71055843d79b13fc"]]},{"id":"82e02d9557fd1079","type":"ui_group","name":"Funções","tab":"a055df2d1f664f7f","order":2,"disp":true,"width":"6","collapse":false,"className":""},{"id":"a055df2d1f664f7f","type":"ui_tab","name":"Layout_Montagem","icon":"dashboard","disabled":false,"hidden":false}]

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.