logo elektroda
logo elektroda
X
logo elektroda

Simulation of an ASCII driver in Node-Red: Creation of a flow that generates random numbers

phaksi 540 1
ADVERTISEMENT
Treść została przetłumaczona polish » english Zobacz oryginalną wersję tematu
  • #1 19043760
    phaksi
    Level 2  
    A warm welcome, I apologise in advance if the topic is not in the section it should be.

    I have a problem with creating a working flow-a. Namely, I would like to "simulate" in node-red a driver that understands commands by ASCII and returns a response, e.g. I send in ASCII the symbol A<CR> , node-red returns me a string where the beginning is always the same and the last three positions are random numbers in the range 000-999. Example: device_1_14_11_197<CR> , another example: device_1_14_11_043<CR> .

    I send a different symbol, e.g. B<CR> , node-red is supposed to reply: device_1_14_9347558130<CR> lub device_1_14_0003259735<CR>

    As you can see, the second answer looks similar to the first, however, here there are more random numbers.

    Node-red is running on an RPi4, I have communication via a usb-uart adapter. With the uart I am connected to the raspberry, the usb I have to the PC as a COM port, the preview and communication via COM I have through the Hercules program from HW group.

    Could you please send some flow or somehow guide me on the subject?
    Regards


    _________EDIT

    After a few hours of tedious work, reading the internet, I managed to partially solve the problem, however it is a half way solution, but does not satisfy me 100%

    Code: Javascript
    Log in, to see the code


    It's hard to explain what's going on with the whole program at the moment, but it's not working as I'd like. Overall it works poorly, maybe someone can take a look and tell me what is wrong? Generally now no matter what I type as a query node-red responds for both values/queries at the same time, even if I only type A or B as a query.... Is there anything that can be done about this, or throw it into a corner? Maybe my thinking is incorrect, maybe something needs to be done differently? I have no idea......
    Do you have a problem with Raspberry? Ask question. Visit our forum Raspberry.
  • ADVERTISEMENT
  • #2 19099566
    xury
    Automation specialist
    I just cut out the function block and inject and the programme seems to work fine.
    Injecting A only answers A, injecting B only answers B.
ADVERTISEMENT