-
Notifications
You must be signed in to change notification settings - Fork 195
ESP32 MODBUS RTU Question #94
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
The thing is that i have more continously running tasks because there are a lot of devices on the bus.
I need that vTaskDelay(5); because the modbus is busy if the function takes the semaphore and try to write or read immidiatelly. But this non blocking callback thing is a little bit hacky for me because i have to write separate callback for every interact inside tasks |
Hello. Thanks. Modbus::ResultCode err;
bool resCallback(Modbus::ResultCode event, uint16_t, void*) {
err = event;
}
Modbus::ResultCode readSync(uint16_t start, uint16_t num, uint16_t* buf) {
xSemaphoreTake(xMutex, portMAX_DELAY);
if (mb.slave())
return Modbus::EX_GENERAL_FAILURE; // Normally is impossible situation
mb.readHreg(Address, start, buf, num, resCallback);
while (mb.slave()) {
//vTaskDelay(1); // Probably it'll be reasonable in some cases
mb.task();
}
Modbus::ResultCode res = err;
xSemaphoreGive(xMutex);
return res;
}
void main() {
//..
if (readSync(..) == Modbus::EX_SUCCESS) {
//ok
} else {
//error
}
//..
} |
Thank you for the response. I modified the default timeout to 5ms. |
So in theory i could do something like this:
BTW: How do you color the the text between code tags? :D |
I think so.
'```c' |
Take a look new example |
Thank you. Example is not found. I have two continous loops in separate cores in separate tasks. This is okay because the semaphore takes care of busy bus thing but on the thermos task i want to write to the thermoses sometimes. And if the semaphore is on the thermos task and the same tasks in an other function tries to take the semaphore and write to it it will not happen. Is it?
|
Two task read example doing virtually required thing. |
In the example you did this:
inside the
It will let one address out if |
Normally if you always access |
Thank you. I'm currently thinking to integrate this to the whole project. I have several mistakes in the code regarding modbus communication. I have to fill these holes in first. I will respond back with the tests as soon as i can! I really appreciate your help. |
Wen the esp boots up, it will check the bus for "expanders". The idea is that it would write or read something for each expander on the bus, and if it is responding back with success, it would save its address. I did the following for this:
This function is called on setup. I used your example for the writeSync function. If i write this buffer at startup:
So this line: Using the example like this:
|
Okay, if i write anything with this readSync or writeSync i get Error E4, wich is a timeout. Does not matter if i increase the default timeout, i always get this error but the modules do what the esp told them to do. |
Can i get the raw response with this somehow? |
Okay the problem is that the expander module is responding back much faster than the esp can recognize it. The response comes less than 1ms. How can i avoid that? |
I tried to debug it with a windows software called Multiway. On the software i can see the response from the slave module. It is responding back nicely. The esp gets a 228 error for some reason wich is E4 timeout. On an oscilloscope i can see that the response coming back less than 1ms. |
|
Thank you for the response! I will read it carefully. |
Thank you for all your help. Everything seems perfect. The syncron example is really good and straightforward. The last problem was at my hardware level. I managed to kill my rs485 chip. 👍 Currently this syncron example is the easyest and cleanest way for me! |
Hi! First of all this is an amazing lib and thank you for all of this.
Is it possible to be blocking reads and writes all the time? Instead of callback return the result right away?
Currently i'm using it like this:
As you can probably see i have to wait
while (mb.slave()){mb.task();}
.Instead i would do something like this:
The text was updated successfully, but these errors were encountered: