• That is strange... It does all look fine... Can you still get it to crash if you remove the I2C code? For instance by just using an array instead of i2c.readFrom? And if you add console.log statements, where does it actually hang?

    While I'd like to fix this properly, one way around it might be to pre-allocate all the data you need in a Uint8Array - or do you specifically need a string? The following should work...

    var outval = new Uint8Array(bytes);
    var offset = 0;
    while (bytes > 0) {
            var b=64;
            if (bytes >= 64) {
                bytes-=64;
            } else {
                b=bytes;
                bytes=0;
            }
            outval.set(this.i2c.readFrom(0x50|i2ca,b), offset);
            offset += b;
        }
    

    The return type could be handy - however trying to do a 3500 byte I2C read in one go may fail anyway, because IIRC I2C data is stored on the stack before being put into an array and there may well not be 3500 bytes of free stack space available...

About

Avatar for Gordon @Gordon started