• No, it's not in the data stream. The code snipped I copied from you is in a function that's called on a setInterval(), called long after I know I've received all the data. That error occurs on the console.log() of the attempt to dump the whole array.

    I assume the CTRL-C was some interrupt or something going on in the microcontroller when it encounters a fatal memory error. I assume that because I've seen that exact message so many times while I was coding up my data processing code (which allocates memory). But none of that processing code is in use right now, only the attempt to dump data.

    So I have to issue a correction, embarrassingly. The dumpArray() doesn't strictly allocate memory (as in new XXX()), but it creates a string that it appends the entire buffer to, and returns that string (to be printed to console). So there's absolutely another big buffer allocation going on when I try to dump the data.

    My problem is that if I just loop through the array, and console.log() each byte, I get newlines after each byte:
    0xb0
    0x63
    0x20
    ...and so on. It becomes unreadable. Any ideas on how to print to the console without the newline?

  • 'Any ideas on how to print to the console without the newline?'

    Not off hand. I've usually built new strings just concatenating each byte, then console.log() say 32 bytes at a time generating a table. I've done some code stripping the leading '0x' let me see if I can locate that snippet. . . .

    EDIT: (truncate the leading '0x')

    https://www.w3schools.com/jsref/jsref_pa­rseint.asp
    https://www.w3schools.com/jsref/tryit.as­p?filename=tryjsref_parseint
    var byte = 0x??;
    parseInt( byte, 16 );

    build a columnar table of hex values

      for( var j=0; j<bytes; j++ ) {
    
        var decbyte = sread[j];
        //var schar = String.fromCharCode( decbyte );
        var soutcvrt = parseInt( decbyte, 16 );
        soutequiv+= " ";
        soutequiv+= ( j == nNumSepHexBytes ) ? " " : "";    // Separate each eight byte block
        soutequiv+= soutcvrt;
    
    //  08 52 ff ff ff ff ff ff   31 32 33 61 00 ff ff ff
    

    substitute a period marker for known value

    soutequiv+= "|";
      for( var k=0; k<bytes; k++ ) {
    
        var decbyte = sread[k];
        if( decbyte == 255 ) decbyte = 46;  // . Period marker
        var schar = ( decbyte > dASCIICtrlCharEnd ) ? String.fromCharCode( decbyte ) : " ";
    
        if( bDebugPrint ) {
          if( decbyte == 0 ) {
            console.log( "[L242] schar [ " + schar + " ]" );
          }
          if( sChar == "00" ) {
            console.log( "[L242] schar [ " + schar + " ]" );
          }
        }
    
        soutequiv+= ( k == nNumSepHexBytes ) ? " " : "";    // Separate each eight byte block
        soutequiv+= schar;
      }
    soutequiv+= "|";
    
        if( bDebugPrint ) {
    
        console.log( "[L120] str read " + sread );
        console.log( "[L121] " + sread.toString() );
    
        // https://www.w3schools.com/jsref/jsref_fr­omcharcode.asp
        // var str = String.fromCharCode(sread);
    
        // https://stackoverflow.com/questions/4014­2324/how-to-convert-an-array-of-characte­r-codes-to-string-in-javascript
    
        // https://developer.mozilla.org/en-US/docs­/Web/JavaScript/Reference/Global_Objects­/Function/apply
    
        var str = String.fromCharCode.apply(null,sread);
        console.log( "[L126] " + str );
        }
    

    end EDIT



    Here is a similar issue (Ctrl+C error) and explanation with setInterval():

    http://forum.espruino.com/conversations/­321778/

About

Avatar for Robin @Robin started