-
Notifications
You must be signed in to change notification settings - Fork 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
Split read write by list into max-ads-sub-comands chunks #200
Conversation
The tests are failing for the new sub-commands tests, they are failing with a:
I submitted the PR still as I can't work out why the testserver is returning this, so would appreciate some help? I have tested with an actual PLC, and the new code works as expected but just not in the test with the testserver. The spliting of lists function works so what is actually being passed into adsSumRead is what is expected so I can only see that there is an issue with the testserver not responding as expected? The code I used to test with the PLC is here: I just set up an array in MAIN:
import pyads
import time
plc = pyads.Connection("169.254.198.195.1.1", 851)
plc.open()
now = time.time()
test_array = {f"MAIN.iTest[{i}]": i for i in range(0, 1401)}
plc.write_list_by_name(test_array)
print(plc.read_list_by_name(test_array))
test_array = {f"MAIN.iTest[{i}]": 0 for i in range(0, 1401)}
plc.write_list_by_name(test_array)
print("First Written: " + str(time.time() - now))
test_array = {f"MAIN.iTest[{i}]": i for i in range(0, 1401)}
plc.write_list_by_name(test_array)
test_array = {f"MAIN.iTest[{i}]": 0 for i in range(0, 1401)}
plc.write_list_by_name(test_array)
print("Second Written: " + str(time.time() - now))
test_array = {f"MAIN.iTest[{i}]": i for i in range(0, 1401)}
plc.write_list_by_name(test_array, ads_sub_commands=1401)
test_array = {f"MAIN.iTest[{i}]": 0 for i in range(0, 1401)}
plc.write_list_by_name(test_array, ads_sub_commands=1401)
print("Third Written: " + str(time.time() - now))
test_array = {f"MAIN.iTest[{i}]": i for i in range(0, 1401)}
plc.write_list_by_name(test_array, ads_sub_commands=2)
test_array = {f"MAIN.iTest[{i}]": 0 for i in range(0, 1401)}
plc.write_list_by_name(test_array, ads_sub_commands=2)
print("Fourth Written: " + str(time.time() - now))
test_array = [f"MAIN.iTest[{i}]" for i in range(0, 1400)]
print(plc.read_list_by_name(test_array, ads_sub_commands=1))
print("Second Read: " + str(time.time() - now))
plc.close() |
That really seems to be a bug or limitation of the testserver. It can only handle 3 or 4 variables on AdsSumRead. 1 variable: Warning: Frame too long: 31>17 |
I actually don't know what's happening here exactly but it seems the SUMUP_READ is limited to return 3 values: 1, 2 and "test". So you might want to adjust your test to read 6 variables and split by 3. Lines 494 to 499 in 0c93dfe
|
Ok, I'll give that a go |
Sorry for the slow response. I remember when writing the tests for the sum read/write I was also getting the 'Warning: Frame Too Long'. It seems to come from AdsLib (AmsConnection.cpp) but I couldn't work out why. Since it was working when I tested on an actual PLC, I made the hardcoded response within the limit as mentioned above for the purpose of the testserver |
@chrisbeardy I'll take a deeper dive in the sum read handling on the testserver and will try to make it work with variable length and datatypes. So you might not need to change your tests at all. |
@stlehmann that would be great if possible |
Testserver: SUMUP_READ and SUMUP_WRITE with variable length
Pull Request Test Coverage Report for Build 629
💛 - Coveralls |
Pull Request Test Coverage Report for Build 630
💛 - Coveralls |
@chrisbeardy thanks for this PR and sorry for the mess with the commits. Actually I wanted to rebase on master but this didn't work out so well. |
@@ -561,6 +561,61 @@ def test_bytes_from_dict(self): | |||
with self.assertRaises(KeyError): | |||
pyads.bytes_from_dict(OrderedDict(), structure_def) | |||
|
|||
def test_dict_slice_generator(self): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we remove the test slice generators as they are not used?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do you mean just remove the tests? as the functons are still used in the read/write_list_by name functions in ads.py.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
even though the tests for the read/write_list test_read_list_ads_sub_commands
technically cover the usage of the _slice_generators, I would argue as they are standalone functions, it is still important to test them with tests spefic to test those standalone functions?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah sorry I didn't see that these are tests. I thought it to be a generator for some test data so I looked if they are called anywhere in the code which was not the case. Alright then all is set and I shall merge this PR :)
I always struggle with rebasing a PR in GitHub! Half the time I end up creating a new PR. Thanks for the great work on pyads and others on some of the latest features. It's allowing me to build a really powerful front end for a machine I'm working on now which would have been not as easy otherwise. |
The rebase-button of PyCharm was so tempting 😞 |
Actually when you merge a PR in GitHub, do you get the option to rebase it then? |
Might be. I think the problem was that I did a rebase in between. |
No description provided.