Error: cannot convert 'HardwareSerial' to const char*'

Hello,

i have to use a library which hase the following function declaration:

void fb_bus_open(const char* serialPort);

and i call it using Arduino IDE 2.2.x like this:

fb_bus_open(Serial2);

But when compiling i get hte following error message:
"error: cannot convert 'HardwareSerial' to 'const char*'
fb_bus_open(Serial2);"
The problem is that i cannot modify the function void fb_bus_open(const char* serialPort);.
So please if there is any other solution i will appreciate any help.
Thanks

Is fb_bus_open() for a PC, intended to open a port like "COM22:"?

Post a link to the library.

@jremington yes.
I cannot prvide a link because the library is not online.
Some workmate have wrote it many years ago and is not working anymore to ask him.
@Delta_G , you have right, but the problem is, that this function is calling another function and the other function is calling another too.
I am using two libraries, one is C-based and the other is C++ based, so i wrote another function in C which call the C++.
I think i have solved the problem "at least no compiler failure right now"
I used void fb_bus_open(struct Stream* serialPort); and in Arduino IDE fb_bus_open(&Serial2).
Thank you for quick riply

I will try to copy the function and its related:

void fb_bus_open(const char* serialPort)
{
    ModbusMaster_begin(SERVER_ID, serialPort);
    ModbusMaster_clearTransmitBuffer();
    //modbusData.begin(SERVER_ID, &serialPort);
    //modbusData.clearTransmitBuffer();

}

The other function :

void ModbusMaster_begin(uint8_t slave, struct Stream* serial){
    modbusData.begin(slave, serial);
}

The last one:

void ModbusMaster::begin(uint8_t slave, Stream* serial)
{
//  txBuffer = (uint16_t*) calloc(ku8MaxBufferSize, sizeof(uint16_t));
  _u8MBSlave = slave;
  _serial = serial;
  //_serial = &serial;
  _u8TransmitBufferIndex = 0;
  u16TransmitBufferLength = 0;
  
#if __MODBUSMASTER_DEBUG__
  pinMode(__MODBUSMASTER_DEBUG_PIN_A__, OUTPUT);
  pinMode(__MODBUSMASTER_DEBUG_PIN_B__, OUTPUT);
#endif
}

_serial is a private member from type: Stream*
I hope that would help

The code you commented out would probably work, if the function argument were the address of the serial port object. One of your mistakes was to change the argument to char *.

it's possible that the library is doing some magic mapping from the provided const char onto a real stream object.
But we can't see the code.

either provide it as ZIP or just get rid of it and use another Modbus Library.
I suggest the ModbusMaster by DocWalker which can be installed with the library manager.

@noiasca
thank you for your suggestion.
I am already using that library, but i have to modify it to work with the Fieldbus library which i have.
In other words, i have to modify the fieldbus library because the ModbusMaster library is C++ based and the fieldbus library is C based.
I will try to zip the library and post it here
Fieldbuslib.zip (15,0 KB)
ModbusMaster.zip (266,5 KB)
The both libraries as zip

and the Arduino Sketch you are working on?

@noiasca
There is no such a Sketch.
I just wrote some code line and tried to call the two functions:

fb_bus_open(struct Stream* serialPort);
get_fbtype(FIELDBUSTYPES* fbtype);

I just compiled the both libraries without any function call first, there was no error messages.
Then i tried to use the library and write some code to test it with the hardware i have.
You can choose an example from ModbusMaster library and build on it, that is what i will do.

post it. I will not invest time and redo what you have on you screen, just to find out you have something different

post your sketch. which gives you the error you described in #6

@noiasca
The Sketch you wanted:

#include <ModbusMaster.h>
#include <fieldbus_functions.h>

// Instantiate ModbusMaster object
ModbusMaster mbus;

// Other declarations...
fb_errval result1, result2, result3;
fieldbusinfo fbinfo;
unsigned char inbytes[3] = {0};

void setup()
{
  // use Serial (port 0); initialize Modbus communication baud rate
  Serial.begin(9600);

  Serial2.begin(9600, SERIAL_8N1, 18, 17);

  // communicate with Modbus slave ID 2 over Serial (port 0)
  mbus.begin(2, &Serial);


}

void loop() {

    fb_bus_open(&Serial2);
    // Assign a value to fbType
    enum fieldbustypes fbType = FIELDBUS_ETHERCAT;

    // Use fbType in the get_status function
    result1 = get_status(fbType, inbytes);

    // Use fbType in other functions as needed
    result2 = get_fbinfo(&fbinfo, fbType);
    result3 = get_fbtype(&fbType);

    if (result1 == fb_err_ok) {
        // Successfully got the status, use the data in 'inbytes'
        Serial.print(inbytes[0]);
        Serial.println(inbytes[1]);
    } else {
        // Handle the error
        Serial.print("Failure by getting status!!!");
        Serial.println(result1);
    }
    if (result2 == fb_err_ok) {
        // Successfully got the status, use the data in 'inbytes'
        Serial.println(fbinfo.fi_serno);
        for(int i = 0; i < 8; i++){
          Serial.print(fbinfo.fi_fw[i]);
        }
        Serial.println();
        Serial.println(fbinfo.fi_hw);
        for(int j = 0; j < 6; j++){
          Serial.print(fbinfo.fi_macaddr[j]);
        }
        Serial.println();
    } else {
        // Handle the error
        Serial.print("Failure by getting infos!!!");
        Serial.println(result1);
    }

    delay(500);
}

Also post the exact, complete error message, not an interpretation of it.

@gfvalvo

Q #΄(�a��j1)�����Guru Meditation Error: Core 1 panic'ed (IllegalInstruction). Exception was unhandled.
Memory dump at 0x420017a8: 00004a65 a1004136 fe25fa28
Core 1 register dump:
PC : 0x420017ae PS : 0x00060c30 A0 : 0x82001c9d A1 : 0x3fcebd40
A2 : 0x000003e7 A3 : 0x02080072 A4 : 0x3fc94ec8 A5 : 0x00000001
A6 : 0x00060820 A7 : 0x00000001 A8 : 0x820017ab A9 : 0x3fcebd20
A10 : 0x000000e2 A11 : 0x000003e7 A12 : 0x00000001 A13 : 0x00000001
A14 : 0x02cf1aa8 A15 : 0x00ffffff SAR : 0x0000000a EXCCAUSE: 0x00000000
EXCVADDR: 0x00000000 LBEG : 0x42001890 LEND : 0x420018a3 LCOUNT : 0x00000000

Backtrace: 0x420017ab:0x3fcebd40 0x42001c9a:0x3fcebd60 0x420023c2:0x3fcebd80 0x420016aa:0x3fcebda0 0x42003495:0x3fcebdc0

According to ESP Exception Decoder:
it likely means that the pointer used to access the data is either not initialized or has been corrupted.
the first parameter of 'get_status'.

Read this: IllegalInstruction. You have multiple functions that violate the last bullet point.

@gfvalvo Thank you for your reply.
I have corrected that but that was not the main problem.

Then the next step is to instrument the code with debug prints and go through line-by-line, step-by-step until you discover exactly where the illegal instruction is attempted.

@gfvalvo Thank you.
I found the illegal instruction and solve it.
It was due to a wrong call for an enum.
The fieldbus library i am using is written in C and based on libmodbus library, but libmodbus is somehow not working for ESP32 (i.e. Arduino IDE) so i had to work with ModbusMaster library which is written in C++.
Somehow i could modify a copy of the fieldbus library so it can call the methode from ModbusMaster and compile it with no error finaly.
I tried to use RS232 Hardware to establish a connection and try the library but without success.
I think (almost sur) that my modification for the fieldbus is not 100% true.

Hello,

since a wihle i am trying to connect my ESP32 to a netX slave using Arduino IDE 2.x and a Fieldbus Library which i had to modify it to work with the ModbusMaster library, but without success.
I am writting here and hope to get some help from you with that.
My coding skil is not advanced that is why i need help.
Please if someone know or has tried some fieldbus library with Arduino IDE can guide me to it or help me modify the library i have correcrtly.
The fieldbus library i have is written in C and the ModbusMaster library is written in C++.
I am using the RS232 interface.

I think you are using "Fieldbus" as a generic term, and not a specific protocol. What you are actually using is Modbus protocol.

There are many examples of how to use Modbus Master libraries on Arduino.

Are you sure about that? Modbus is typically used with RS485.

Please provide a link to the datasheet.

Thank you @bobcousins for your reply.
I will be using the Ethercat protocol with NIC 50-RE/EC from Hilscher
And yes you are wright, Modbus is used with RS485 but also with RS232 and i made success using it.

It states that this module uses Ethernet but it can be modified to use Ethercat too.
I am connecting my ESP32 to this module using MAX232 (RS232).