Serial.begin config options

Is there a way to pass the equivalent value as the #define variable.
Example:
SERIAL_7E1 is equal to 0x24
If I have the statment
Serial.begin(baudrate,0x24)
instead of
Serial.begin(baudrate, SERIAL_7E1)
it fails to compile with an error invalid conversion from 'int' to 'SerialConfig' [-fpermissive]
I need to pass a number instead of the label SERIAL_...
Example code:

byte SetMachineSerialParameters(byte machineNumber) {
  // Converts machine serial settings into proper code for bits, parity, stop bits
  byte params = 0x06;                                             // Start off with 8 Bits
  if (machineBits[machineNumber][0] == 55) {                      // 7 Bits
    params = 0x04;
  }
  if (machineParity[machineNumber][0] == 69) {                    // even parity value
    params = params | 0x20;
  } else {
    if (machineParity[machineNumber][0] == 79) {                  // odd parity value 
      params = params | 0x30;
    }
  }
  if (machineStopBits[machineNumber][0] == 50) {                  // 2 Stopbit
    params = params | 0x08;
  }
  return params;    
}

Then elsewhere I do
Serial.begin(baudrate, byte bitparams);

This fails to compile but used to a year ago.

Using the same IDE (1.8.19) and ESP8266 board version (2.74)

Thanks
Richard

One of the libraries has changed.

Is there a way to pass a number instead of the label?

Thanks

Where you found this?

HardwareSerial.h

According to HardwareSerial.h, you can pass the number instead of "SERIAL_7E1" macro.
Please show all the code where you encountering with a error.

If I have a statement
Serial.begin(9600, 0x24);
it will fail compile with an error
loader:149:36: error: invalid conversion from 'int' to 'SerialConfig' [-fpermissive]
Serial.begin(1200, 0x24);
^
if I try to pass a byte variable (serialParams) I get
loader:749:38: error: invalid conversion from 'byte {aka unsigned char}' to 'SerialConfig' [-fpermissive]
Serial.begin(baudrate, serialParams);
^

Richard

What is your board?
This code compiles fine for Arduino Uno:

void setup() {
 Serial.begin(9600,0x24);
}

void loop() { }

ESP8266 Boards (2.7.4)
NodeMCU 1.0 (ESP-12E module)

This is the same libraries, IDE, files that compiles in the past. Dunno why it fails now

for ESP8266 the config SERIAL_7E1 is not the number

You seen the wrong HardwareSerial.h file.
See this:

The settings like SERIAL_7E1 are elements of the enum

enum SerialConfig {
    SERIAL_5N1 = UART_5N1,
    SERIAL_6N1 = UART_6N1,
    SERIAL_7N1 = UART_7N1,
....

It can't be directly replaced with number.

I see what it says but this worked before.
I had commented out code because the number created didnt make sense... Now it does.
Heres the commented code that I replaced with the code above:

  params = params | ((machineBits[machineNumber][0] - 55 ) << 2); // Sets bits value
  if (machineParity[machineNumber][0] == 69) {                    // even parity value
    params = params | 0x0a;
  } else {
    if (machineParity[machineNumber][0] == 79) {                  // odd parity value 
      params = params | 0x0b;
    } else {
      params = params | 0x08;                                     // no parity is 0x00
    }
  }
  if (machineStopBits[machineNumber][0] == 49) {                  // 1 Stopbit
    params = params | 0x10;
  } else {
    params = params | 0x30;                                       // 2 stopbits
  }
  return params;

In the C++ each enum has it own independent type. You need casting your number from int to enum like this:

Serial.begin(9600, static_cast<SerialConfig>(0x24));

But you need first to calculate correct values from this file, because it can be incompatible with old HardwareSerial values, used in your old code:

So the library was changed. You can use old version library or rewrite your code for new one.

Thank you.
Ill check which library was used... The ESP library could of been updated in my IDE but I dont remember doing that.

Arduino IDE updated libraries and hardware cores automatically, if you setup corresponding options.

This was in ESP8266 ver 2.0.0
Thank you for all your help

Richard

Please mark thread as solved when you test the code

But why would anyone want to put a cryptic number that you can’t maintain and is subject to evolution independently of your code instead of the official published API which makes this readable? …

that makes no sense at all

The number comes from machine config files that differ in settings and are setup by ordinary users thru an easy to use and understand interface. Why would someone take away the ability to send the value that is ultimately passed to the function? That makes no sense to me. Now instead of a few lines of code I would have to rewrite the user interface and add many more lines that are unnecessary.

Richard

This has to be done precisely because the program was originally written incorrectly - using numerical values ​​instead of configuration macros.
If the first author had used system constants for configuration settings, nothing would have to be rewritten when changing the library