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
@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
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
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.
#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);
}
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'.
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.
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.
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).