-
Notifications
You must be signed in to change notification settings - Fork 986
How to implement a custom server that can be busy? #2620
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
Modbus do not have a busy flag, please explain which message/flag you are referring to ? |
Thanks for your quick answer! I am referring to Line 114 in 0b94011
In my assumption this tells the client, that the device is busy an the client should retry later. This is also stated in several modbus descriptions like https://www.simplymodbus.ca/exceptions.htm
|
Yes, but that is received as an exception response, not a normal response. BUT the pymodbus server do not use this exception response. If you receive that from the device in your datastore-client, you should pass it on...which is not very easy. It is something that is not foreseen in the current server implementation. If you just need to wait the only option is a wait_for with timeout. |
The server context or datastores are designed to respond immediately, delays are not permitted. Also datastores are not designed to return anything but a value (or False in the validate function), so your point of attack seems wrong. Did you look at the trace functions they allow you to generate/modify responses as you please, that in combination with the datastore might solve your problem. But of course if you need the server to work differently Pull Requests are always welcome. |
Thanks a lot, this is pointing in the right direction. I set up tracing like in your example. For testing purposes I just want to return an Exception for all incoming requests. My tracing function looks like this def my_trace_pdu(self, sending: bool, pdu: ModbusPDU) -> ModbusPDU:
"""Do dummy trace."""
txt = "REQUEST pdu" if sending else "RESPONSE pdu"
print(f"---> {txt}: {pdu}")
if sending:
return ExceptionResponse(function_code=pdu.function_code, exception_code=ExceptionResponse.SLAVE_BUSY, transaction=pdu.transaction_id)
return pdu The server log looks good I think:
But the client doesn't seem to get the Exception number:
notice 133 / 6 vs 133 / 0 Can you tell what I am doing wrong here? |
Did you check the ExceptionCode. |
Closing as this is not a pymodbus problem. |
Hi,
in my project, I have custom contexts that communicate with external hardware. Therefore I derive from
ModbusSparseDataBlock
and overwritevalidate
,setValues
andgetValues
with my business logic.For example I have a coil that takes several seconds to process data on the external hardware. A response look like this even the device is busy.
Now my question is how to use busy flag that the client gets the according response that the device is currently busy? If I use a lock the response would timeout because the lock cannot be acquired in time.
Thank you very much for this project!
The text was updated successfully, but these errors were encountered: