Skip to content
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

Merged
merged 20 commits into from
Feb 17, 2021

Conversation

chrisbeardy
Copy link
Collaborator

No description provided.

@chrisbeardy
Copy link
Collaborator Author

The tests are failing for the new sub-commands tests, they are failing with a:

pyads.pyads_ex.ADSError: ADSError: parameter size not correct (1797).

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:

iTest: ARRAY [0..1400] OF INT;
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()

@chrisbeardy
Copy link
Collaborator Author

parameter size not correct suggests that the test server is not correctly storing the size between reads/writes of the test variables?

I don't know if @pylipp or @bdcoyle have any thoughts? I can't remember who added the intial read/write list functionailty?

@stlehmann
Copy link
Owner

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
2 variables: Frame too long: 31>26
3 variables: OK
4 variables: OK
5 variables: KeyError: 1702101505
6 variables: KeyError: 1702101505

@stlehmann
Copy link
Owner

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.

pyads/pyads/testserver.py

Lines 494 to 499 in 0c93dfe

elif index_group == constants.ADSIGRP_SUMUP_READ:
# Could be improved to handle variable length requests
response_value = struct.pack(
"<IIIIBB4sB", 0, 0, 0, 1, 1, 2,
("test" + "\x00").encode("utf-8"), 0
)

@chrisbeardy
Copy link
Collaborator Author

Ok, I'll give that a go

@bdcoyle
Copy link
Contributor

bdcoyle commented Feb 16, 2021

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.

https://github.com/stlehmann/ADS/blob/d0804bc4edc68851c75f982e0aebc7c2386b0a29/AdsLib/AmsConnection.cpp#L244-L248

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

@stlehmann
Copy link
Owner

@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.

@chrisbeardy
Copy link
Collaborator Author

@stlehmann that would be great if possible

@coveralls
Copy link

Pull Request Test Coverage Report for Build 629

  • 23 of 23 (100.0%) changed or added relevant lines in 2 files are covered.
  • 1 unchanged line in 1 file lost coverage.
  • Overall coverage increased (+0.009%) to 94.458%

Files with Coverage Reduction New Missed Lines %
pyads/pyads_ex.py 1 90.3%
Totals Coverage Status
Change from base Build 609: 0.009%
Covered Lines: 1125
Relevant Lines: 1191

💛 - Coveralls

@coveralls
Copy link

coveralls commented Feb 17, 2021

Pull Request Test Coverage Report for Build 630

  • 23 of 23 (100.0%) changed or added relevant lines in 2 files are covered.
  • 1 unchanged line in 1 file lost coverage.
  • Overall coverage increased (+0.009%) to 94.458%

Files with Coverage Reduction New Missed Lines %
pyads/pyads_ex.py 1 90.3%
Totals Coverage Status
Change from base Build 609: 0.009%
Covered Lines: 1125
Relevant Lines: 1191

💛 - Coveralls

@stlehmann
Copy link
Owner

@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):
Copy link
Owner

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?

Copy link
Collaborator Author

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.

Copy link
Collaborator Author

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?

Copy link
Owner

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 :)

@chrisbeardy
Copy link
Collaborator Author

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.

@stlehmann
Copy link
Owner

The rebase-button of PyCharm was so tempting 😞

@stlehmann stlehmann merged commit b19cbd3 into stlehmann:master Feb 17, 2021
@chrisbeardy chrisbeardy deleted the split_read_write branch February 17, 2021 15:05
@chrisbeardy
Copy link
Collaborator Author

@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.

Actually when you merge a PR in GitHub, do you get the option to rebase it then?

@stlehmann
Copy link
Owner

Might be. I think the problem was that I did a rebase in between.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants