-
Notifications
You must be signed in to change notification settings - Fork 948
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
Slave ID for request not verified when accepting response #60
Comments
pyModbus version: 1.3.2 I am also seeing same problem. Problem is not checking slave id, but real problem is it does not able to reach code where it checks slave id and throw exception before that. In this scenario server fails in CRC check of package and throw exception (as it try to parse message as request and CRC is for response). Location: transaction.py file ModbusRtuFramer->processIncomingPacket(self, data, callback). It will fail in self.checkFrame() method as it will take request as from client, and try to calculate CRC as request.
|
@picarro-cvala please share more information on your setup , the client used ,the modbus device you are trying to control etc |
@dhoomakethu I have one client (master) and two server (salves) connected using serial. My client and server is configure for RTU. |
@picarro-cvala is that a sync client or async client? And are both the slaves connected on the same serial port ? Please share your client code on how you are communicating with the slave devices. |
@dhoomakethu yes server and client are sync. and yes both slaves are connected on the same serial port. I notice there is one thread for same problem on stack over flow too: Client code:
|
@picarro-cvala if you are using pymodbus sync server to represent your slave, You do not have to have two instances running , you can create multiple slaves on the same server with a slave store dict, something like this.
|
@dhoomakethu our use case is different, slave are different HW. And server are running on individual HW. And over modbus we control individual HW. Do you think, in our case we need to use async server? |
Technically that should work, but you will have to make sure your serial line terminations are well in place for the serial lines to work. Your client code deals only with one slave in a while loop do you have another client which does the read transactions for the another slave as well or are you using the same client to transact with the other client. If you are using two clients , You will have to make sure only one client access the serial line at a time as per the modbus/rs485 specs. otherwise the result is unpredictable something in the lines of what you are seeing here. Using an async client is also advisable if you are running repeated transaction at a set interval . |
@dhoomakethu do you mean by async will work? |
@picarro-cvala see my comment above |
@dhoomakethu I have added some more code as below for slave 2. but problem is reproducible if we talk with just one slave and 2nd slave will report error. I am not using two client. only one client. Agree with you, if more than one client talks on RTU it will be unpredictable behavior. import sys com_setting = {"port": "COM2", "baudrate": 9600, "timeout": 3} while True: #Second slave read
client.close() |
@picarro-cvala I believe the problem is with the servers , could you please post your server code here (for both servers) ? |
@dhoomakethu yes, error is at server side. In my first message I have describe problem and it is at server side. Also shared exact method where this problem will happen. I think any server example code will work to reproduce problem, for example "https://pymodbus.readthedocs.io/en/latest/examples/synchronous-server.html". Just make one change that give slave id and make context as below: #1 for slave 1 and 2 for slave 2 Problem Location: transaction.py file ModbusRtuFramer->processIncomingPacket(self, data, callback). It will fail in self.checkFrame() method as it will assume response for other slave as request from client, and try to calculate CRC as request. #-----------------------------------------------------------------------#
|
@picarro-cvala Could you please use |
@dhoomakethu sure I will try to use dev branch. Meanwhile can you please share code changes for this issue in dev branch (I would like to do code change walk through). |
@piccaro-cvala please refer the commit 5f0d2ed |
@dhoomakethu I did code walk through, and I think change looks good. I will try to use dev branch and verify on real master and slave environment. |
@dhoomakethu I tested dev branch on real HW and looks good. But I see one problem in the fix. With this commit you are overwriting one existing functionality, which is I think for master request message. File name: sync.py method ModbusBaseRequestHandler.execute(). With implemented change it will never go into execute method and it will not go into NoSuchSlaveException exception case where it throw exception if slave is missing and ignore_missing_slaves is false.
|
@dhoomakethu above comment was mine. By mistakenly I posted comment with my teammate account. |
@picarro-cvala those line become irrelevant now, the modbus exception code
The changes are specifically meant for RTU slaves/servers. If you a ModbusTcpServer, you will still see the modbus error being returned. For RTU's we just don't send any response in line with the specs. |
@dhoomakethu sounds good. I have one more question: By any chance do you know when this bug fix will be releasing? |
@picarro-cvala as soon as #209 is closed. |
@dhoomakethu just request: if it will take more than one week, then it is possible to create patch for this fix? |
@picarro-cvala there is not definite timeline , I can create pre-release on github if you would like that. If you want to have it on PyPI then you will have to wait till all the action items are closed |
@picarro-cvala There is a new pre release available 1.4.0rc2 both on PyPI and Github with the fix to this issue. I will close this issue as of now, Please feel free to re-open if you still think the issue is not fixed. Sorry for the delay with the release. |
@dhoomakethu Sounds good. |
It appears that the validation process is not checking that the slave id in the request matches the slave id in the response. For a synchronous client a response from a rogue device should not be considered a valid response when reading coils/holding/input/discrete registers.
Edit: oops, referring to server code.
The text was updated successfully, but these errors were encountered: