How can I detect which baudrate a virtual COM port is set to?

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
2
down vote

favorite












I would like my software running on Leonardo to behave differently depending on the baudrate of the USB Serial set by the PC. For example, I want to make a smart USB to UART converter which performs some processing of the data it transmits. It would be much more elegant to set the UART baudrate to whatever value the PC is requesting on USB side, rather than hardcoding a value.



AFAIK 32u4 chip is used as a USB to UART converter on Mega, where it supports different baudrates, so this should be doable.



I also have a Teensy 3.2 board, so if anyone knows how to detect the baudrate on this board I'm also interested.







share|improve this question
























    up vote
    2
    down vote

    favorite












    I would like my software running on Leonardo to behave differently depending on the baudrate of the USB Serial set by the PC. For example, I want to make a smart USB to UART converter which performs some processing of the data it transmits. It would be much more elegant to set the UART baudrate to whatever value the PC is requesting on USB side, rather than hardcoding a value.



    AFAIK 32u4 chip is used as a USB to UART converter on Mega, where it supports different baudrates, so this should be doable.



    I also have a Teensy 3.2 board, so if anyone knows how to detect the baudrate on this board I'm also interested.







    share|improve this question






















      up vote
      2
      down vote

      favorite









      up vote
      2
      down vote

      favorite











      I would like my software running on Leonardo to behave differently depending on the baudrate of the USB Serial set by the PC. For example, I want to make a smart USB to UART converter which performs some processing of the data it transmits. It would be much more elegant to set the UART baudrate to whatever value the PC is requesting on USB side, rather than hardcoding a value.



      AFAIK 32u4 chip is used as a USB to UART converter on Mega, where it supports different baudrates, so this should be doable.



      I also have a Teensy 3.2 board, so if anyone knows how to detect the baudrate on this board I'm also interested.







      share|improve this question












      I would like my software running on Leonardo to behave differently depending on the baudrate of the USB Serial set by the PC. For example, I want to make a smart USB to UART converter which performs some processing of the data it transmits. It would be much more elegant to set the UART baudrate to whatever value the PC is requesting on USB side, rather than hardcoding a value.



      AFAIK 32u4 chip is used as a USB to UART converter on Mega, where it supports different baudrates, so this should be doable.



      I also have a Teensy 3.2 board, so if anyone knows how to detect the baudrate on this board I'm also interested.









      share|improve this question











      share|improve this question




      share|improve this question










      asked Aug 29 at 20:21









      Dmitry Grigoryev

      855318




      855318




















          1 Answer
          1






          active

          oldest

          votes

















          up vote
          6
          down vote



          accepted










          From looking at the source it appears that on 32u4 based boards Serial includes extra methods to access the settings from the USB host:



          see: https://github.com/arduino/ArduinoCore-avr/blob/b7c607663fecc232e598f2c0acf419ceb0b7078c/cores/arduino/USBAPI.h#L129



          From USBAPI.h:



          // These return the settings specified by the USB host for the
          // serial port. These aren't really used, but are offered here
          // in case a sketch wants to act on these settings.
          uint32_t baud();
          uint8_t stopbits();
          uint8_t paritytype();
          uint8_t numbits();
          bool dtr();
          bool rts();





          share|improve this answer
















          • 1




            I tried it out. On Leonardo, Serial.baud() works right after the serial has started, inside setup. On Teensy, Serial.baud() seems to return 0 inside setup, so I wait inside loop until a non-zero value is returned.
            – Dmitry Grigoryev
            Aug 30 at 7:19










          Your Answer





          StackExchange.ifUsing("editor", function ()
          return StackExchange.using("schematics", function ()
          StackExchange.schematics.init();
          );
          , "cicuitlab");

          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "540"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          convertImagesToLinks: false,
          noModals: false,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          bindNavPrevention: true,
          postfix: "",
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













           

          draft saved


          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2farduino.stackexchange.com%2fquestions%2f55718%2fhow-can-i-detect-which-baudrate-a-virtual-com-port-is-set-to%23new-answer', 'question_page');

          );

          Post as a guest






























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes








          up vote
          6
          down vote



          accepted










          From looking at the source it appears that on 32u4 based boards Serial includes extra methods to access the settings from the USB host:



          see: https://github.com/arduino/ArduinoCore-avr/blob/b7c607663fecc232e598f2c0acf419ceb0b7078c/cores/arduino/USBAPI.h#L129



          From USBAPI.h:



          // These return the settings specified by the USB host for the
          // serial port. These aren't really used, but are offered here
          // in case a sketch wants to act on these settings.
          uint32_t baud();
          uint8_t stopbits();
          uint8_t paritytype();
          uint8_t numbits();
          bool dtr();
          bool rts();





          share|improve this answer
















          • 1




            I tried it out. On Leonardo, Serial.baud() works right after the serial has started, inside setup. On Teensy, Serial.baud() seems to return 0 inside setup, so I wait inside loop until a non-zero value is returned.
            – Dmitry Grigoryev
            Aug 30 at 7:19














          up vote
          6
          down vote



          accepted










          From looking at the source it appears that on 32u4 based boards Serial includes extra methods to access the settings from the USB host:



          see: https://github.com/arduino/ArduinoCore-avr/blob/b7c607663fecc232e598f2c0acf419ceb0b7078c/cores/arduino/USBAPI.h#L129



          From USBAPI.h:



          // These return the settings specified by the USB host for the
          // serial port. These aren't really used, but are offered here
          // in case a sketch wants to act on these settings.
          uint32_t baud();
          uint8_t stopbits();
          uint8_t paritytype();
          uint8_t numbits();
          bool dtr();
          bool rts();





          share|improve this answer
















          • 1




            I tried it out. On Leonardo, Serial.baud() works right after the serial has started, inside setup. On Teensy, Serial.baud() seems to return 0 inside setup, so I wait inside loop until a non-zero value is returned.
            – Dmitry Grigoryev
            Aug 30 at 7:19












          up vote
          6
          down vote



          accepted







          up vote
          6
          down vote



          accepted






          From looking at the source it appears that on 32u4 based boards Serial includes extra methods to access the settings from the USB host:



          see: https://github.com/arduino/ArduinoCore-avr/blob/b7c607663fecc232e598f2c0acf419ceb0b7078c/cores/arduino/USBAPI.h#L129



          From USBAPI.h:



          // These return the settings specified by the USB host for the
          // serial port. These aren't really used, but are offered here
          // in case a sketch wants to act on these settings.
          uint32_t baud();
          uint8_t stopbits();
          uint8_t paritytype();
          uint8_t numbits();
          bool dtr();
          bool rts();





          share|improve this answer












          From looking at the source it appears that on 32u4 based boards Serial includes extra methods to access the settings from the USB host:



          see: https://github.com/arduino/ArduinoCore-avr/blob/b7c607663fecc232e598f2c0acf419ceb0b7078c/cores/arduino/USBAPI.h#L129



          From USBAPI.h:



          // These return the settings specified by the USB host for the
          // serial port. These aren't really used, but are offered here
          // in case a sketch wants to act on these settings.
          uint32_t baud();
          uint8_t stopbits();
          uint8_t paritytype();
          uint8_t numbits();
          bool dtr();
          bool rts();






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Aug 29 at 21:14









          Craig

          1,645410




          1,645410







          • 1




            I tried it out. On Leonardo, Serial.baud() works right after the serial has started, inside setup. On Teensy, Serial.baud() seems to return 0 inside setup, so I wait inside loop until a non-zero value is returned.
            – Dmitry Grigoryev
            Aug 30 at 7:19












          • 1




            I tried it out. On Leonardo, Serial.baud() works right after the serial has started, inside setup. On Teensy, Serial.baud() seems to return 0 inside setup, so I wait inside loop until a non-zero value is returned.
            – Dmitry Grigoryev
            Aug 30 at 7:19







          1




          1




          I tried it out. On Leonardo, Serial.baud() works right after the serial has started, inside setup. On Teensy, Serial.baud() seems to return 0 inside setup, so I wait inside loop until a non-zero value is returned.
          – Dmitry Grigoryev
          Aug 30 at 7:19




          I tried it out. On Leonardo, Serial.baud() works right after the serial has started, inside setup. On Teensy, Serial.baud() seems to return 0 inside setup, so I wait inside loop until a non-zero value is returned.
          – Dmitry Grigoryev
          Aug 30 at 7:19

















           

          draft saved


          draft discarded















































           


          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2farduino.stackexchange.com%2fquestions%2f55718%2fhow-can-i-detect-which-baudrate-a-virtual-com-port-is-set-to%23new-answer', 'question_page');

          );

          Post as a guest













































































          Comments

          Popular posts from this blog

          Long meetings (6-7 hours a day): Being “babysat” by supervisor

          Is the Concept of Multiple Fantasy Races Scientifically Flawed? [closed]

          Confectionery