Menu

Add serialPort.read()

devnull
2024-01-17
2024-01-19
  • devnull

    devnull - 2024-01-17

    Would love to have a function which should only read a single byte from the serialPort object, alternative to .readAll()
    But maybe you designed in a way that user code needs to take care of the buffering?

     
  • Stefan Zieker

    Stefan Zieker - 2024-01-18

    Yes, the user has to take care of it. What I usually do is this:

    var g_storedReceivedData = Array();
    
    function dataReceivedSlot(data)
    {
        //Save the received data.
        g_storedReceivedData = g_storedReceivedData.concat(data);
    
        //Do something with data
    
      }
    
     

    Last edit: Stefan Zieker 2024-01-18
  • devnull

    devnull - 2024-01-19

    Agreed, i do it the same way, but using push

    for (var i=0; i < data.lenght; i++) {
      rxbuffer.push(data[i]);
    }
    

    My hope hereby is that it more similar to a pipe. As the call to the sub is async, it might be that other subs reading from the buffer at the same time.

     

Anonymous
Anonymous

Add attachments
Cancel