JavaScript: How to write to multiple outputs - Printable Version +- Virtuino Forum (https://virtuino.com/forum) +-- Forum: Virtuino (https://virtuino.com/forum/forumdisplay.php?fid=1) +--- Forum: Virtuino IoT (https://virtuino.com/forum/forumdisplay.php?fid=2) +--- Thread: JavaScript: How to write to multiple outputs (/showthread.php?tid=1246) |
JavaScript: How to write to multiple outputs - chris - 03-25-2023 Is there any way to send values to multiple outputs using a Java Script? RE: JavaScript: How to write to multiple outputs - iliaslamprou - 03-25-2023 Hi, You have to include the messages for each ouput tag inside an array like the example below: [{"tag":"outputTag1","value":'+ value1+'},{"tag":"outputTag2","value":'+ value2+'}]
the better way is to create a json message for each tag first and store them to variables like the example below //... code result1 = '{"tag":"outputTag1", "value":'+ value1+ '}; //..code result2 = '{"tag":"outputTag2", "value":'+ value2+ '}; //..code result3 = '{"tag":"outputTag3", "value":'+ value3+ '}; result = [result1, result2, result2] This is a completed example. Create three tags: inputTag - V0 (Script runner tag) outputTag1 -V1 outputTag2 - V2 Code: //--- Copy values from Virtuino Variables to JavaScript variables RE: JavaScript: How to write to multiple outputs - Dkyndt - 04-11-2023 Hi, I'm trying to convert a selector switch to multiple Modbus outputs. I can see that the javascript seems to work when I compile, however, the data is not sent to the Modbus Logo. This is my code. The outputs themselves do work towards the Modbus Logo. see also attached screenshot. Code: //--- Copy values from Virtuino Variables to JavaScript variables RE: JavaScript: How to write to multiple outputs - iliaslamprou - 04-12-2023 Hi, you can check if it works using the emulator first. Just replace the modbus with the emulator output variables This correction is better in case the input value is not in range 1..3 Code: if (BranderModus == 1) { I don't know why it happens. I have checked your script. It works fine. You have to post more information about this issue. RE: JavaScript: How to write to multiple outputs - Dkyndt - 04-13-2023 The code indeed works. I had to close the software and reopen it. |