Using Serial1 with USB disconnected

Posted on
  • As I understand it, if the USB is disconnected, the console will be moved to Serial1. How do I keep that from happening? I need the USB to have the console on it when plugged in, but serial 1 must be usable whether or not USB is plugged in, and I need to be able to plug in the USB while the system is running for maintenance.

    I remember a thread about this this weekend, but I can't seem to find it to see your response.

  • Well, I've just checked up on the logic for this, and it's:

    • When USB is plugged in, change console device to be USB
    • When USB is unplugged, if the console device is USB, change it to Serial1

    Unfortunately there's no callback for when USB is connected or disconnected, so it might be best to just do something like:

    setInterval(function() {
      if (process.env.CONSOLE=="Serial1") setConsole(LoopbackA);
    }, 1000);
    
  • Okay, cool. Good to know what exactly the logic is.
    So all I need to do is use something like that to shove the console off serial1, and I should be good to go, and I can safely put my desk lamp controller back together the way I'd planned to.

  • Can this cause problems when Serial1 is used for other purposes, e.g. to connect a WLAN module?

    What happens on console.logs, when another device is attached via USART to Serial1 ? Is the console.log string data then being sent to the device which is attached?

  • Yes, that could cause you issues when the device is started when not connected to USB... It'll automatically move to Serial1 and while you can send data, no responses will be received by the data handler.

    Also, as you say any calls to console.log will go right out to the device. In the onInit function you could try forcing the console on to USB with USB.setConsole...

  • Thank you. I'll try that tomorrow morning.

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

Using Serial1 with USB disconnected

Posted by Avatar for DrAzzy @DrAzzy

Actions