Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 4 of 4

Thread: Advantage of HardareSerial over Serial?

  1. #1
    Junior Member
    Join Date
    Oct 2016
    Posts
    17

    Advantage of HardareSerial over Serial?

    Hi, Is here any advantage using HardwareSerial over just using the straight SerialN I only need standard 8N1 and I can assign the pins to the alt serial posts as needed. Thanks.
    Teensy3.6 I have ethernet and 4 serial ports working, mostly just curious.

    #define RS232B Serial1
    //HardwareSerial RS232B = HardwareSerial(); // Set up for using secondary Serial 1 pins 26&27

  2. #2
    Senior Member+ KurtE's Avatar
    Join Date
    Jan 2014
    Posts
    8,464
    Serial1 is simply defined as an instance of HardwareSerial, so I don't see any benefit.

    If you wish to lose the c++ stuff, then you can go directly to the code that it calls in serial1.c, which is the C interface.

    If you look in HardwareSerial.h you will see the C++ class simply calls off to the C functions. However you will of course lose the Stream/Print capabilities that the C++ code inherits from.

  3. #3
    Junior Member
    Join Date
    Oct 2016
    Posts
    17
    Thanks for the data. Happy New Year!

  4. #4
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    23,734
    In the very early days of Teensy, which was also fairly early in the history of Arduino before any official Arduino board had more than 1 serial port and none had native USB (Arduino Duemilanove was new on the market, Arduino Uno & Mega didn't exist yet), the earliest versions of Teensyduino recommended creating your own name for the hardware serial port. At the time, Teensy and Sanguino where the only Arduino compatible products with more than 1 way to communicate with "serial", and there just wasn't a firm convention on how to deal with such things.

    When Arduino Mega appeared on the market, and the convention of Serial1, Serial2, Serial3 for the other ports became the norm.

    At Kurt explained, there's really no difference. Even now, if you *really* want to create your own instance of the C++ object, you can. But it's ultimately still the same code.

    Years ago I updated the examples and documentation to recommend the now well-established names. But perhaps there's still some of that old code or info somewhere?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •