Looking for function that can use for my application

Hi,

My application is using "OPCOM II" using analog input ( the product picture below)


so the problem that i facing is got any function can hold for 10 sec after 10 sec the data come in 2 sec then turn to low for 2 sec again keep repeat untill 21 micrometer then hold for 10 sec again.
is quite complicated for this if need the documentaion i can provide. thanks

you may consider changing the category from creating nodes to general may be ?

Alright thanks

This should be doable, I think. However, don't you want to use RS232 or CAN in this case? I had a quick look at the communication protocol, and you should be able to get your values without the need to evaluate the analogue output signal of the device.

Hi Rko,

Cause i using analog input then output is digital.
so what i want to do is inside node-red how i can hold the time.

If you insist :upside_down_face:
Maybe this can help you to get started:

[{"id":"e66d771bcb7c4b32","type":"tab","label":"Flow 2","disabled":false,"info":"","env":[]},{"id":"08aa9d0a21111192","type":"function","z":"e66d771bcb7c4b32","name":"prepare signal","func":"let counter = flow.get(\"counter\");\nif (flow.get(\"max_counter\") == counter) {\n    counter = 0;\n    flow.set(\"signal\",[]);\n}\n\n\nmsg.payload = counter;\nflow.set(\"counter\",counter+1);\n\n\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":340,"y":280,"wires":[["054782a3b1688c9f"]]},{"id":"3ead352eb63d2559","type":"inject","z":"e66d771bcb7c4b32","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"0.5","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":150,"y":280,"wires":[["08aa9d0a21111192"]]},{"id":"0b4cdfa60c096959","type":"inject","z":"e66d771bcb7c4b32","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":true,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":150,"y":100,"wires":[["d29b898db6b34483"]]},{"id":"d29b898db6b34483","type":"change","z":"e66d771bcb7c4b32","name":"","rules":[{"t":"set","p":"counter","pt":"flow","to":"0","tot":"num"},{"t":"set","p":"delta_t","pt":"flow","to":"0.5","tot":"num"},{"t":"set","p":"sq_length","pt":"flow","to":"30","tot":"num"},{"t":"set","p":"max_counter","pt":"flow","to":"$flowContext(\"sq_length\")/$flowContext(\"delta_t\")","tot":"jsonata"},{"t":"set","p":"signal","pt":"flow","to":"[]","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":340,"y":100,"wires":[[]]},{"id":"054782a3b1688c9f","type":"switch","z":"e66d771bcb7c4b32","name":"","property":"counter","propertyType":"flow","rules":[{"t":"lte","v":"4/$flowContext(\"delta_t\")","vt":"jsonata"},{"t":"lte","v":"(6)/$flowContext(\"delta_t\")","vt":"jsonata"},{"t":"lte","v":"(8)/$flowContext(\"delta_t\")","vt":"jsonata"},{"t":"lte","v":"(10)/$flowContext(\"delta_t\")","vt":"jsonata"},{"t":"lte","v":"(12)/$flowContext(\"delta_t\")","vt":"jsonata"},{"t":"lte","v":"(14)/$flowContext(\"delta_t\")","vt":"jsonata"},{"t":"lte","v":"(16)/$flowContext(\"delta_t\")","vt":"jsonata"},{"t":"lte","v":"(18)/$flowContext(\"delta_t\")","vt":"jsonata"},{"t":"lte","v":"(20)/$flowContext(\"delta_t\")","vt":"jsonata"},{"t":"lte","v":"(24)/$flowContext(\"delta_t\")","vt":"jsonata"},{"t":"lte","v":"(28)/$flowContext(\"delta_t\")","vt":"jsonata"},{"t":"lte","v":"(30)/$flowContext(\"delta_t\")","vt":"jsonata"}],"checkall":"false","repair":false,"outputs":12,"x":510,"y":280,"wires":[["ffda99b8bdbfe671"],["855e69f5dd59b6c3"],["ae8cb837f6d410e4"],["89ab8fa714e79880"],["1d384bf5925aa3ee"],["ec560c0f26405ac5"],["0ac2105bcb782e8f"],["5b18ad87443704c0"],["922ad6d8e8b24a72"],["76300d885a4707f1"],["957afefbfbc5a7b3"],["2b236af8712e8a7f"]],"outputLabels":["start sq","zero","4 um","zero","6 um","zero","14 um","zero","21 um","zero","end sq","zero"]},{"id":"ffda99b8bdbfe671","type":"change","z":"e66d771bcb7c4b32","name":"20","rules":[{"t":"set","p":"payload","pt":"msg","to":"20","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":770,"y":60,"wires":[["4f058d25c55fe079"]]},{"id":"855e69f5dd59b6c3","type":"change","z":"e66d771bcb7c4b32","name":"0","rules":[{"t":"set","p":"payload","pt":"msg","to":"0","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":770,"y":100,"wires":[["4f058d25c55fe079"]]},{"id":"ae8cb837f6d410e4","type":"change","z":"e66d771bcb7c4b32","name":"4 um","rules":[{"t":"set","p":"payload","pt":"msg","to":"18","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":770,"y":140,"wires":[["4f058d25c55fe079"]]},{"id":"89ab8fa714e79880","type":"change","z":"e66d771bcb7c4b32","name":"0","rules":[{"t":"set","p":"payload","pt":"msg","to":"0","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":770,"y":180,"wires":[["4f058d25c55fe079"]]},{"id":"1d384bf5925aa3ee","type":"change","z":"e66d771bcb7c4b32","name":"6 um","rules":[{"t":"set","p":"payload","pt":"msg","to":"14","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":770,"y":220,"wires":[["4f058d25c55fe079"]]},{"id":"ec560c0f26405ac5","type":"change","z":"e66d771bcb7c4b32","name":"0","rules":[{"t":"set","p":"payload","pt":"msg","to":"0","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":770,"y":260,"wires":[["4f058d25c55fe079"]]},{"id":"0ac2105bcb782e8f","type":"change","z":"e66d771bcb7c4b32","name":"14 um","rules":[{"t":"set","p":"payload","pt":"msg","to":"8","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":770,"y":300,"wires":[["4f058d25c55fe079"]]},{"id":"5b18ad87443704c0","type":"change","z":"e66d771bcb7c4b32","name":"0","rules":[{"t":"set","p":"payload","pt":"msg","to":"0","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":770,"y":340,"wires":[["4f058d25c55fe079"]]},{"id":"922ad6d8e8b24a72","type":"change","z":"e66d771bcb7c4b32","name":"21 um","rules":[{"t":"set","p":"payload","pt":"msg","to":"6","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":770,"y":380,"wires":[["4f058d25c55fe079"]]},{"id":"76300d885a4707f1","type":"change","z":"e66d771bcb7c4b32","name":"0","rules":[{"t":"set","p":"payload","pt":"msg","to":"0","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":770,"y":420,"wires":[["4f058d25c55fe079"]]},{"id":"957afefbfbc5a7b3","type":"change","z":"e66d771bcb7c4b32","name":"20","rules":[{"t":"set","p":"payload","pt":"msg","to":"20","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":770,"y":460,"wires":[["4f058d25c55fe079","21e0192ea84ecd34"]]},{"id":"2b236af8712e8a7f","type":"change","z":"e66d771bcb7c4b32","name":"0","rules":[{"t":"set","p":"payload","pt":"msg","to":"0","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":770,"y":500,"wires":[["4f058d25c55fe079"]]},{"id":"4f058d25c55fe079","type":"function","z":"e66d771bcb7c4b32","name":"store signal","func":"flow.get(\"signal\").push(msg.payload);\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1090,"y":280,"wires":[["2fb0dfa0369d7bee"]]},{"id":"20cee89dbe661ebd","type":"function","z":"e66d771bcb7c4b32","name":"get results","func":"msg.payload = {\n    \"4um\": flow.get(\"signal\")[7 / flow.get(\"delta_t\")],\n    \"6um\": flow.get(\"signal\")[11 / flow.get(\"delta_t\")],\n    \"14um\": flow.get(\"signal\")[15 / flow.get(\"delta_t\")],\n    \"21um\": flow.get(\"signal\")[19 / flow.get(\"delta_t\")],\n     };\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1290,"y":460,"wires":[["9ad8cc173b78b1f8"]]},{"id":"9ad8cc173b78b1f8","type":"debug","z":"e66d771bcb7c4b32","name":"results","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":1430,"y":460,"wires":[]},{"id":"21e0192ea84ecd34","type":"delay","z":"e66d771bcb7c4b32","name":"","pauseType":"rate","timeout":"5","timeoutUnits":"seconds","rate":"1","nbRateUnits":"10","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":true,"allowrate":false,"outputs":1,"x":1100,"y":460,"wires":[["20cee89dbe661ebd"]]},{"id":"2fb0dfa0369d7bee","type":"debug","z":"e66d771bcb7c4b32","name":"signal","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":1250,"y":280,"wires":[]}]

Assumptions:

  • the time difference delta_t between values is 0.5 s (interval)
  • the index of the array element can then be calculated by duration since the sequence started divided by delta_t (see function node get results).

What you could try next: Automatically detect sequence start (20 mA, 0 mA, 20 mA pattern).

Hi Rko,

Thanks for your flow is quite good, just i got some questions. (shown on below this picture)
On the output you can see when 1 sec it give me 2 output.


now after i add a delay but, now i only received 1 output 1 sec but i want 2 output but not sure how to make it. the second picture is the correct timing just that the output is wrong.

Hi @kelvin, you're welcome!

I was wondering how many signal values you'll get from your analogue input device. In the flow above I set delta_t to 0.5 s (two values per second). If you want to change this to 1 s you have to set the delta_t in the change node (upper left corner) to 1:

Due to the limitations of the inject node (and for the sake of simplicity) you have to also change this in the inject node manually:

Your approach with the limit is a bit more complex but should also work:
If you want to limit the signal with a delay (as shown in your last screenshot), just put it before the prepare signal node. However, the index calculation depends on delta_t so we should dynamically set the rate limit. This can be done through msg.rate. So the flow would look this:

[{"id":"e66d771bcb7c4b32","type":"tab","label":"Flow 2","disabled":false,"info":"","env":[]},{"id":"08aa9d0a21111192","type":"function","z":"e66d771bcb7c4b32","name":"prepare signal","func":"// don't allow message to control the interval to go through \nif(!msg.rate){\n    let counter = flow.get(\"counter\");\n    if (flow.get(\"max_counter\") == counter) {\n        counter = 0;\n        flow.set(\"signal\",[]);\n    }\n\n\n    msg.payload = counter;\n    flow.set(\"counter\",counter+1);\n\n\n\n    return msg;\n}else{\n    node.warn(\"set signal interval to: \"+msg.rate+\" ms\");\n}","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":560,"y":360,"wires":[["054782a3b1688c9f"]]},{"id":"3ead352eb63d2559","type":"inject","z":"e66d771bcb7c4b32","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"0.5","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":150,"y":360,"wires":[["70ddf3a1b6f2fd7e"]]},{"id":"0b4cdfa60c096959","type":"inject","z":"e66d771bcb7c4b32","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":true,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":150,"y":80,"wires":[["d29b898db6b34483"]]},{"id":"d29b898db6b34483","type":"change","z":"e66d771bcb7c4b32","name":"","rules":[{"t":"set","p":"counter","pt":"flow","to":"0","tot":"num"},{"t":"set","p":"delta_t","pt":"flow","to":"1","tot":"num"},{"t":"set","p":"sq_length","pt":"flow","to":"30","tot":"num"},{"t":"set","p":"max_counter","pt":"flow","to":"$flowContext(\"sq_length\")/$flowContext(\"delta_t\")","tot":"jsonata"},{"t":"set","p":"signal","pt":"flow","to":"[]","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":340,"y":80,"wires":[["6674d1eb1bc45299"]]},{"id":"054782a3b1688c9f","type":"switch","z":"e66d771bcb7c4b32","name":"","property":"counter","propertyType":"flow","rules":[{"t":"lte","v":"4/$flowContext(\"delta_t\")","vt":"jsonata"},{"t":"lte","v":"(6)/$flowContext(\"delta_t\")","vt":"jsonata"},{"t":"lte","v":"(8)/$flowContext(\"delta_t\")","vt":"jsonata"},{"t":"lte","v":"(10)/$flowContext(\"delta_t\")","vt":"jsonata"},{"t":"lte","v":"(12)/$flowContext(\"delta_t\")","vt":"jsonata"},{"t":"lte","v":"(14)/$flowContext(\"delta_t\")","vt":"jsonata"},{"t":"lte","v":"(16)/$flowContext(\"delta_t\")","vt":"jsonata"},{"t":"lte","v":"(18)/$flowContext(\"delta_t\")","vt":"jsonata"},{"t":"lte","v":"(20)/$flowContext(\"delta_t\")","vt":"jsonata"},{"t":"lte","v":"(24)/$flowContext(\"delta_t\")","vt":"jsonata"},{"t":"lte","v":"(28)/$flowContext(\"delta_t\")","vt":"jsonata"},{"t":"lte","v":"(30)/$flowContext(\"delta_t\")","vt":"jsonata"}],"checkall":"false","repair":false,"outputs":12,"x":730,"y":360,"wires":[["ffda99b8bdbfe671"],["855e69f5dd59b6c3"],["ae8cb837f6d410e4"],["89ab8fa714e79880"],["1d384bf5925aa3ee"],["ec560c0f26405ac5"],["0ac2105bcb782e8f"],["5b18ad87443704c0"],["922ad6d8e8b24a72"],["76300d885a4707f1"],["957afefbfbc5a7b3"],["2b236af8712e8a7f"]],"outputLabels":["start sq","zero","4 um","zero","6 um","zero","14 um","zero","21 um","zero","end sq","zero"]},{"id":"ffda99b8bdbfe671","type":"change","z":"e66d771bcb7c4b32","name":"20","rules":[{"t":"set","p":"payload","pt":"msg","to":"20","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":990,"y":140,"wires":[["4f058d25c55fe079"]]},{"id":"855e69f5dd59b6c3","type":"change","z":"e66d771bcb7c4b32","name":"0","rules":[{"t":"set","p":"payload","pt":"msg","to":"0","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":990,"y":180,"wires":[["4f058d25c55fe079"]]},{"id":"ae8cb837f6d410e4","type":"change","z":"e66d771bcb7c4b32","name":"4 um","rules":[{"t":"set","p":"payload","pt":"msg","to":"18","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":990,"y":220,"wires":[["4f058d25c55fe079"]]},{"id":"89ab8fa714e79880","type":"change","z":"e66d771bcb7c4b32","name":"0","rules":[{"t":"set","p":"payload","pt":"msg","to":"0","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":990,"y":260,"wires":[["4f058d25c55fe079"]]},{"id":"1d384bf5925aa3ee","type":"change","z":"e66d771bcb7c4b32","name":"6 um","rules":[{"t":"set","p":"payload","pt":"msg","to":"14","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":990,"y":300,"wires":[["4f058d25c55fe079"]]},{"id":"ec560c0f26405ac5","type":"change","z":"e66d771bcb7c4b32","name":"0","rules":[{"t":"set","p":"payload","pt":"msg","to":"0","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":990,"y":340,"wires":[["4f058d25c55fe079"]]},{"id":"0ac2105bcb782e8f","type":"change","z":"e66d771bcb7c4b32","name":"14 um","rules":[{"t":"set","p":"payload","pt":"msg","to":"8","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":990,"y":380,"wires":[["4f058d25c55fe079"]]},{"id":"5b18ad87443704c0","type":"change","z":"e66d771bcb7c4b32","name":"0","rules":[{"t":"set","p":"payload","pt":"msg","to":"0","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":990,"y":420,"wires":[["4f058d25c55fe079"]]},{"id":"922ad6d8e8b24a72","type":"change","z":"e66d771bcb7c4b32","name":"21 um","rules":[{"t":"set","p":"payload","pt":"msg","to":"6","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":990,"y":460,"wires":[["4f058d25c55fe079"]]},{"id":"76300d885a4707f1","type":"change","z":"e66d771bcb7c4b32","name":"0","rules":[{"t":"set","p":"payload","pt":"msg","to":"0","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":990,"y":500,"wires":[["4f058d25c55fe079"]]},{"id":"957afefbfbc5a7b3","type":"change","z":"e66d771bcb7c4b32","name":"20","rules":[{"t":"set","p":"payload","pt":"msg","to":"20","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":990,"y":540,"wires":[["21e0192ea84ecd34","4f058d25c55fe079"]]},{"id":"2b236af8712e8a7f","type":"change","z":"e66d771bcb7c4b32","name":"0","rules":[{"t":"set","p":"payload","pt":"msg","to":"0","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":990,"y":580,"wires":[["4f058d25c55fe079"]]},{"id":"4f058d25c55fe079","type":"function","z":"e66d771bcb7c4b32","name":"store signal","func":"flow.get(\"signal\").push(msg.payload);\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1330,"y":400,"wires":[["2fb0dfa0369d7bee"]]},{"id":"20cee89dbe661ebd","type":"function","z":"e66d771bcb7c4b32","name":"get results","func":"msg.payload = {\n    \"4um\": flow.get(\"signal\")[7 / flow.get(\"delta_t\")],\n    \"6um\": flow.get(\"signal\")[11 / flow.get(\"delta_t\")],\n    \"14um\": flow.get(\"signal\")[15 / flow.get(\"delta_t\")],\n    \"21um\": flow.get(\"signal\")[19 / flow.get(\"delta_t\")],\n     };\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1510,"y":580,"wires":[["9ad8cc173b78b1f8"]]},{"id":"9ad8cc173b78b1f8","type":"debug","z":"e66d771bcb7c4b32","name":"results","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":1650,"y":580,"wires":[]},{"id":"21e0192ea84ecd34","type":"delay","z":"e66d771bcb7c4b32","name":"","pauseType":"rate","timeout":"5","timeoutUnits":"seconds","rate":"1","nbRateUnits":"10","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":true,"allowrate":false,"outputs":1,"x":1320,"y":580,"wires":[["20cee89dbe661ebd"]]},{"id":"2fb0dfa0369d7bee","type":"debug","z":"e66d771bcb7c4b32","name":"signal","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":1650,"y":400,"wires":[]},{"id":"6674d1eb1bc45299","type":"change","z":"e66d771bcb7c4b32","name":"","rules":[{"t":"set","p":"rate","pt":"msg","to":"$flowContext(\"delta_t\")*1000","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":550,"y":80,"wires":[["70ddf3a1b6f2fd7e"]]},{"id":"70ddf3a1b6f2fd7e","type":"delay","z":"e66d771bcb7c4b32","name":"","pauseType":"rate","timeout":"5","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":true,"allowrate":true,"outputs":1,"x":370,"y":360,"wires":[["08aa9d0a21111192"]]}]

Hi @rko ,

Thanks for very helpful :blush:
total we have 4 but with this only 1 but the flow i will separate them accordingly so sounld be fine.

Actually i got 1 question can i convert Csv file then push the data to Excel file is it possible?

I'm glad it helped. Could you mark the post with the latest flow as solution?

As for csv/excel, I would create another post. Also it is always good to mention what you have tried so far and at which step you ran into problems.

So should i reply here or wait for your post then i post my question there?

Sorry, YOU should create a separate post.