Serial/usb output

Posted on
  • Hi Gordon,

    I don't want to hijack a thread. I create a new one with your statement:

    "One other thing that could be an issue is that if you have Espruino powered from a computer, the computer connects to it via USB but stops reading data after a few characters have been sent. This means that if you're using print/console.log then after a while Espruino will stop working as it's waiting for the computer to read the data it's printing. If you either run a terminal app, or connect Espruino to a USB power supply, it'll be fine though."

    Is this proven ? If yes that's very vey important to know and should be included in the documentation of console.log.

    Is this also true in general for all uarts? Lets say a serial device (LCD or transmission module) crashes or disconnects. Is it then a question of time that espruino crashes too, because of buffering and waiting?

    I do not know of such a behavior on the arduino side.

    For me it looks like a trap that should be considered as a bug.

    Sacha

  • There's a big discussion about this on GitHub where I give the reasons for this - I've already changed the documentation for console.log and it'll be in 1v62's reference - although it's been in the troubleshooting page since it existed :)

    The issue doesn't exist for Serial devices, it's just USB.

    On USB there's flow control, so if the computer is connected but isn't reading, Espruino can't write. AFAIK there's no way to tell the difference between a computer that's not looking at the serial port, and one that is looking but is too busy to read character data. Arduino may lose character data if your PC isn't reading it fast enough but IMO that's really bad behaviour and we shouldn't copy it.

    It's not such an issue for normal Arduino, where you're limited to 38400 baud (or whatever the link to the FTDI chip usually is), but on Espruino it's pretty easy to send a lot of data over USB very quickly, and it's entirely likely that it will spend time waiting for the PC to read it, so would then throw that data away when it shouldn't.

    Sure, you could detect if it sat waiting for ~1 sec and throw the data away, but having your software inexplicably stop working for 1 second and then start working is pretty bad behaviour which people would complain about too.

    Anyway, I've spent ages trying to explain the pros and cons on the bug linked above...

  • Thanks for the answer. I unterstand.

    Sacha

  • It´s realy not a problem at all. When usb is not connected the console points to serial1 where the output is not blocking.

    Sacha

  • Maybe it's a daft question, but just to double check - when Espruino is powered via USB with a mobile charger or a USB battery then it's like USB was not connected? Meaning it's not blocking, right?

  • Absolutely - the only problem is when you're connected to an actual computer and that computer is on.

  • Cool. Turns out it's just a storm in a teacup then.

  • You'd think - but people get very upset about it :)

    I think if you've just spent an hour trying to find out why it happens, you get very annoyed and think it shouldn't do that. I just need to make sure it's documented everywhere someone might look!

  • Exactly.

    Also it may be a good idea to specifically say that it happens ONLY when there is a USB cable connected to a PC which is not listening (i.e. not when running on batteries or mains). It really looks bad otherwise, like you couldn't use espruino in standalone mode.

    EDIT: never mind, it's already there :)

  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview
About

Serial/usb output

Posted by Avatar for Sacha @Sacha

Actions