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)
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);
^
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;
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? …
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.
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