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

Added fixes to snap7/client.py read_area function to allow for Counter and Timer Reads #121

Merged
merged 2 commits into from
May 31, 2019

Conversation

ghost
Copy link

@ghost ghost commented May 27, 2019

No description provided.

@codecov-io
Copy link

codecov-io commented May 27, 2019

Codecov Report

Merging #121 into master will increase coverage by 0.24%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #121      +/-   ##
==========================================
+ Coverage   78.67%   78.91%   +0.24%     
==========================================
  Files          15       15              
  Lines        2068     2092      +24     
==========================================
+ Hits         1627     1651      +24     
  Misses        441      441
Impacted Files Coverage Δ
test/test_client.py 87.79% <100%> (+0.59%) ⬆️
snap7/client.py 84.24% <100%> (+0.44%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update a6db134...0470f0e. Read the comment docs.

@gijzelaerr gijzelaerr self-requested a review May 27, 2019 11:48
@gijzelaerr
Copy link
Owner

hi @JKelly-Mevex ! Thanks for your PR! Do you think it is possible to modify the test suite so it covers the conditions using the simulator?

@ghost
Copy link
Author

ghost commented May 27, 2019 via email

@gijzelaerr
Copy link
Owner

Currently, the fullupload client function is completely untested:

https://github.com/gijzelaerr/python-snap7/blob/master/test/test_client.py#L534

What would be amazingly perfect if there is an extra test function just like the other unit tests in that file that would verify that each condition in the condition you added work as intented.

You can run the test suite with for example nosetests.

@ghost
Copy link
Author

ghost commented May 27, 2019 via email

@ghost
Copy link
Author

ghost commented May 28, 2019 via email

@gijzelaerr
Copy link
Owner

During test initialisation

https://github.com/gijzelaerr/python-snap7/blob/master/test/test_client.py#L29

bin/snap7-server.py is started in a different process. This script is nothing more than a server emulator, which is part of the snap7 library.

https://github.com/gijzelaerr/python-snap7/blob/master/snap7/bin/snap7-server.py

@ghost
Copy link
Author

ghost commented May 28, 2019 via email

@gijzelaerr
Copy link
Owner

Sorry but i don't see any image in the github web interface.

@ghost
Copy link
Author

ghost commented May 28, 2019 via email

@ghost
Copy link
Author

ghost commented May 28, 2019

Sorry, the image is not working here so I am cutting the terminal output below:

Warning (from warnings module):
  File "/usr/lib/python3.6/subprocess.py", line 766
    ResourceWarning, source=self)
ResourceWarning: subprocess 25690 is still running
.s.ss..ssss.ss.........s.ERROR:snap7.common:b'CPU : Item not available'
......E.........ERROR:snap7.common:b'CLI : Cannot change this param now'
.E.ERROR:snap7.common:b'CPU : Function not authorized for current protection level'
...E...
======================================================================
ERROR: test_get_plc_time (__main__.TestClient)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/jkelly/Development/Python/python-snap7/test/test_client.py", line 449, in test_get_plc_time
    self.assertEqual(datetime.now().replace(microsecond=0), self.client.get_plc_datetime())
AttributeError: 'Client' object has no attribute 'get_plc_datetime'

======================================================================
ERROR: test_set_plc_datetime (__main__.TestClient)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/jkelly/Development/Python/python-snap7/test/test_client.py", line 453, in test_set_plc_datetime
    self.client.set_plc_datetime(new_dt)
AttributeError: 'Client' object has no attribute 'set_plc_datetime'

======================================================================
ERROR: tearDownClass (__main__.TestClient)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/jkelly/Development/Python/python-snap7/test/test_client.py", line 37, in tearDownClass
    kill(cls.server_pid, 1)
ProcessLookupError: [Errno 3] No such process

----------------------------------------------------------------------
Ran 50 tests in 2.585s

FAILED (errors=3, skipped=10)

@gijzelaerr
Copy link
Owner

how do you run the test suite on what platform? Do you use a virtualenv?

this works for me on OSX:

$ brew install snap7
$ cd somewhere/python-snap7
$ virtualenv -p python3 .venv
$ .venv/bin/pip install -e .
$ .venv/bin/pip install nose
$ source .venv/bin/activate
$ ./run_tests

I'm confused by the missing set_plc_datetime function, since it should be there. Sure you didn't modify the source?:

gijs@bloempot:~/Work/python-snap7 (master)
λ  grep set_plc_datetime snap7 -R
snap7/client.py:    def set_plc_datetime(self, dt):

@ghost
Copy link
Author

ghost commented May 28, 2019

I am running this on Linux. I'll double check that this is pointing towards the latest and greatest untouched code. I might roll a virtual environment as well to save some hassle. I'll get back to you on this.

@ghost
Copy link
Author

ghost commented May 29, 2019

I got the virtual environment setup as per your instructions above. The first time I executed ./run_tests.sh, I
received a bunch of errors related to a missing mock module. I had to do a "pip install mock". Once this was done, I got the following results. Please check this over to see if this seems ok to you. Once I get your ok then I will try to author a test for the read_area function.

(.venv) jkelly@pop-os:~/Development/Python/python-snap7$ ./run_tests.sh 
...S..................
----------------------------------------------------------------------
Ran 22 tests in 3.218s

OK (SKIP=1)
...................
----------------------------------------------------------------------
Ran 19 tests in 2.664s

OK
INFO:snap7.server:creating server
INFO:snap7.server:setting event callback
INFO:snap7.server:registering area 5, index 1, size 100
INFO:snap7.server:registering area 1, index 1, size 100
INFO:snap7.server:setting server TCP port to 1102
INFO:snap7.server:starting server on 0.0.0.0:1102
INFO:snap7.server:callback event: 2019-05-29 02:42:31 Server started
INFO:snap7.server:callback event: 2019-05-29 02:42:31 Server started
INFO:root:2019-05-29 02:42:31 Server started
INFO:snap7.server:callback event: 2019-05-29 02:42:33 [127.0.0.1] Client added
INFO:snap7.server:callback event: 2019-05-29 02:42:33 [127.0.0.1] Client added
INFO:snap7.server:callback event: 2019-05-29 02:42:33 [127.0.0.1] The client requires a PDU size of 480 bytes
INFO:snap7.server:callback event: 2019-05-29 02:42:33 [127.0.0.1] The client requires a PDU size of 480 bytes
INFO:snap7.server:callback event: 2019-05-29 02:42:33 [127.0.0.1] Write request, Area : PA, Start : 1, Size : 1 --> OK
INFO:snap7.server:callback event: 2019-05-29 02:42:33 [127.0.0.1] Write request, Area : PA, Start : 1, Size : 1 --> OK
INFO:snap7.server:callback event: 2019-05-29 02:42:33 [127.0.0.1] Read request, Area : PA, Start : 1, Size : 1 --> OK
INFO:snap7.server:callback event: 2019-05-29 02:42:33 [127.0.0.1] Read request, Area : PA, Start : 1, Size : 1 --> OK
INFO:snap7.server:callback event: 2019-05-29 02:42:33 [127.0.0.1] Client disconnected by peer
INFO:snap7.server:callback event: 2019-05-29 02:42:33 [127.0.0.1] Client disconnected by peer
.INFO:snap7.server:callback event: 2019-05-29 02:42:33 [127.0.0.1] Client added
INFO:snap7.server:callback event: 2019-05-29 02:42:33 [127.0.0.1] Client added
INFO:snap7.server:callback event: 2019-05-29 02:42:33 [127.0.0.1] The client requires a PDU size of 480 bytes
INFO:snap7.server:callback event: 2019-05-29 02:42:33 [127.0.0.1] The client requires a PDU size of 480 bytes
S.INFO:snap7.server:callback event: 2019-05-29 02:42:33 [127.0.0.1] Client disconnected by peer
INFO:snap7.server:callback event: 2019-05-29 02:42:33 [127.0.0.1] Client disconnected by peer
INFO:snap7.server:callback event: 2019-05-29 02:42:33 [127.0.0.1] Client added
INFO:snap7.server:callback event: 2019-05-29 02:42:33 [127.0.0.1] Client added
INFO:snap7.server:callback event: 2019-05-29 02:42:33 [127.0.0.1] The client requires a PDU size of 480 bytes
INFO:snap7.server:callback event: 2019-05-29 02:42:33 [127.0.0.1] The client requires a PDU size of 480 bytes
SS.INFO:snap7.server:callback event: 2019-05-29 02:42:33 [127.0.0.1] Client disconnected by peer
INFO:snap7.server:callback event: 2019-05-29 02:42:33 [127.0.0.1] Client disconnected by peer
INFO:snap7.server:callback event: 2019-05-29 02:42:33 [127.0.0.1] Client added
INFO:snap7.server:callback event: 2019-05-29 02:42:33 [127.0.0.1] Client added
INFO:snap7.server:callback event: 2019-05-29 02:42:33 [127.0.0.1] The client requires a PDU size of 480 bytes
INFO:snap7.server:callback event: 2019-05-29 02:42:33 [127.0.0.1] The client requires a PDU size of 480 bytes
INFO:snap7.server:callback event: 2019-05-29 02:42:33 [127.0.0.1] CPU Control request : Memory compress --> OK
INFO:snap7.server:callback event: 2019-05-29 02:42:33 [127.0.0.1] CPU Control request : Memory compress --> OK
.INFO:snap7.server:callback event: 2019-05-29 02:42:33 [127.0.0.1] Client disconnected by peer
INFO:snap7.server:callback event: 2019-05-29 02:42:33 [127.0.0.1] Client disconnected by peer
INFO:snap7.server:callback event: 2019-05-29 02:42:33 [127.0.0.1] Client added
INFO:snap7.server:callback event: 2019-05-29 02:42:33 [127.0.0.1] Client added
INFO:snap7.server:callback event: 2019-05-29 02:42:33 [127.0.0.1] The client requires a PDU size of 480 bytes
INFO:snap7.server:callback event: 2019-05-29 02:42:33 [127.0.0.1] The client requires a PDU size of 480 bytes
INFO:snap7.server:callback event: 2019-05-29 02:42:33 [127.0.0.1] Block info requested DB 1 --> OK
INFO:snap7.server:callback event: 2019-05-29 02:42:33 [127.0.0.1] Block info requested DB 1 --> OK
INFO:snap7.server:callback event: 2019-05-29 02:42:33 [127.0.0.1] Read request, Area : DB1, Start : 0, Size : 100 --> OK
INFO:snap7.server:callback event: 2019-05-29 02:42:33 [127.0.0.1] Read request, Area : DB1, Start : 0, Size : 100 --> OK
INFO:snap7.server:callback event: 2019-05-29 02:42:33 [127.0.0.1] Client disconnected by peer
SSSS.INFO:snap7.server:callback event: 2019-05-29 02:42:33 [127.0.0.1] Client disconnected by peer
INFO:snap7.server:callback event: 2019-05-29 02:42:33 [127.0.0.1] Client added
INFO:snap7.server:callback event: 2019-05-29 02:42:33 [127.0.0.1] Client added
INFO:snap7.server:callback event: 2019-05-29 02:42:33 [127.0.0.1] The client requires a PDU size of 480 bytes
INFO:snap7.server:callback event: 2019-05-29 02:42:33 [127.0.0.1] The client requires a PDU size of 480 bytes
INFO:snap7.server:callback event: 2019-05-29 02:42:33 [127.0.0.1] Write request, Area : DB1, Start : 0, Size : 4 --> OK
INFO:snap7.server:callback event: 2019-05-29 02:42:33 [127.0.0.1] Write request, Area : DB1, Start : 0, Size : 4 --> OK
SS.INFO:snap7.server:callback event: 2019-05-29 02:42:33 [127.0.0.1] Client disconnected by peer
INFO:snap7.server:callback event: 2019-05-29 02:42:33 [127.0.0.1] Client disconnected by peer
INFO:snap7.server:callback event: 2019-05-29 02:42:33 [127.0.0.1] Client added
INFO:snap7.server:callback event: 2019-05-29 02:42:33 [127.0.0.1] Client added
INFO:snap7.server:callback event: 2019-05-29 02:42:33 [127.0.0.1] The client requires a PDU size of 480 bytes
INFO:snap7.server:callback event: 2019-05-29 02:42:33 [127.0.0.1] The client requires a PDU size of 480 bytes
INFO:snap7.server:callback event: 2019-05-29 02:42:33 [127.0.0.1] Client disconnected by peer
INFO:snap7.server:callback event: 2019-05-29 02:42:33 [127.0.0.1] Client disconnected by peer
INFO:root:2019-05-29 02:42:33 [127.0.0.1] Client added
INFO:root:2019-05-29 02:42:33 [127.0.0.1] The client requires a PDU size of 480 bytes
INFO:root:2019-05-29 02:42:33 [127.0.0.1] Write request, Area : PA, Start : 1, Size : 1 --> OK
INFO:root:2019-05-29 02:42:33 [127.0.0.1] Read request, Area : PA, Start : 1, Size : 1 --> OK
INFO:root:2019-05-29 02:42:33 [127.0.0.1] Client disconnected by peer
INFO:root:2019-05-29 02:42:33 [127.0.0.1] Client added
INFO:root:2019-05-29 02:42:33 [127.0.0.1] The client requires a PDU size of 480 bytes
INFO:root:2019-05-29 02:42:33 [127.0.0.1] Client disconnected by peer
INFO:root:2019-05-29 02:42:33 [127.0.0.1] Client added
INFO:root:2019-05-29 02:42:33 [127.0.0.1] The client requires a PDU size of 480 bytes
INFO:root:2019-05-29 02:42:33 [127.0.0.1] Client disconnected by peer
INFO:root:2019-05-29 02:42:33 [127.0.0.1] Client added
INFO:root:2019-05-29 02:42:33 [127.0.0.1] The client requires a PDU size of 480 bytes
INFO:root:2019-05-29 02:42:33 [127.0.0.1] CPU Control request : Memory compress --> OK
INFO:root:2019-05-29 02:42:33 [127.0.0.1] Client disconnected by peer
INFO:root:2019-05-29 02:42:33 [127.0.0.1] Client added
INFO:root:2019-05-29 02:42:33 [127.0.0.1] The client requires a PDU size of 480 bytes
INFO:root:2019-05-29 02:42:33 [127.0.0.1] Block info requested DB 1 --> OK
INFO:root:2019-05-29 02:42:33 [127.0.0.1] Read request, Area : DB1, Start : 0, Size : 100 --> OK
INFO:root:2019-05-29 02:42:33 [127.0.0.1] Client disconnected by peer
INFO:root:2019-05-29 02:42:33 [127.0.0.1] Client added
INFO:root:2019-05-29 02:42:33 [127.0.0.1] The client requires a PDU size of 480 bytes
INFO:root:2019-05-29 02:42:33 [127.0.0.1] Write request, Area : DB1, Start : 0, Size : 4 --> OK
INFO:root:2019-05-29 02:42:33 [127.0.0.1] Client disconnected by peer
INFO:root:2019-05-29 02:42:33 [127.0.0.1] Client added
INFO:root:2019-05-29 02:42:33 [127.0.0.1] The client requires a PDU size of 480 bytes
INFO:root:2019-05-29 02:42:33 [127.0.0.1] Client disconnected by peer
.INFO:snap7.server:callback event: 2019-05-29 02:42:33 [127.0.0.1] Client added
INFO:snap7.server:callback event: 2019-05-29 02:42:33 [127.0.0.1] Client added
INFO:snap7.server:callback event: 2019-05-29 02:42:33 [127.0.0.1] The client requires a PDU size of 480 bytes
INFO:snap7.server:callback event: 2019-05-29 02:42:33 [127.0.0.1] The client requires a PDU size of 480 bytes
.INFO:snap7.server:callback event: 2019-05-29 02:42:33 [127.0.0.1] Client disconnected by peer
INFO:snap7.server:callback event: 2019-05-29 02:42:33 [127.0.0.1] Client disconnected by peer
INFO:snap7.server:callback event: 2019-05-29 02:42:33 [127.0.0.1] Client added
INFO:snap7.server:callback event: 2019-05-29 02:42:33 [127.0.0.1] Client added
INFO:snap7.server:callback event: 2019-05-29 02:42:33 [127.0.0.1] The client requires a PDU size of 480 bytes
INFO:snap7.server:callback event: 2019-05-29 02:42:33 [127.0.0.1] The client requires a PDU size of 480 bytes
INFO:snap7.server:callback event: 2019-05-29 02:42:33 [127.0.0.1] Security request : Clear session password --> OK
INFO:snap7.server:callback event: 2019-05-29 02:42:33 [127.0.0.1] Security request : Clear session password --> OK
.INFO:snap7.server:callback event: 2019-05-29 02:42:33 [127.0.0.1] Client disconnected by peer
INFO:snap7.server:callback event: 2019-05-29 02:42:33 [127.0.0.1] Client disconnected by peer
INFO:snap7.server:callback event: 2019-05-29 02:42:33 [127.0.0.1] Client added
INFO:snap7.server:callback event: 2019-05-29 02:42:33 [127.0.0.1] Client added
INFO:snap7.server:callback event: 2019-05-29 02:42:33 [127.0.0.1] The client requires a PDU size of 480 bytes
INFO:snap7.server:callback event: 2019-05-29 02:42:33 [127.0.0.1] The client requires a PDU size of 480 bytes
INFO:snap7.server:callback event: 2019-05-29 02:42:33 [127.0.0.1] CPU Control request : Memory compress --> OK
INFO:snap7.server:callback event: 2019-05-29 02:42:33 [127.0.0.1] CPU Control request : Memory compress --> OK
.INFO:snap7.server:callback event: 2019-05-29 02:42:33 [127.0.0.1] Client disconnected by peer
INFO:snap7.server:callback event: 2019-05-29 02:42:33 [127.0.0.1] Client disconnected by peer
INFO:snap7.server:callback event: 2019-05-29 02:42:33 [127.0.0.1] Client added
INFO:snap7.server:callback event: 2019-05-29 02:42:33 [127.0.0.1] Client added
INFO:snap7.server:callback event: 2019-05-29 02:42:33 [127.0.0.1] The client requires a PDU size of 480 bytes
INFO:snap7.server:callback event: 2019-05-29 02:42:33 [127.0.0.1] The client requires a PDU size of 480 bytes
INFO:snap7.server:callback event: 2019-05-29 02:42:33 [127.0.0.1] Block info requested DB 1 --> OK
INFO:snap7.server:callback event: 2019-05-29 02:42:33 [127.0.0.1] Block info requested DB 1 --> OK
INFO:snap7.server:callback event: 2019-05-29 02:42:33 [127.0.0.1] Read request, Area : DB1, Start : 0, Size : 100 --> OK
INFO:snap7.server:callback event: 2019-05-29 02:42:33 [127.0.0.1] Read request, Area : DB1, Start : 0, Size : 100 --> OK
.INFO:snap7.server:callback event: 2019-05-29 02:42:33 [127.0.0.1] Client disconnected by peer
INFO:snap7.server:callback event: 2019-05-29 02:42:33 [127.0.0.1] Client disconnected by peer
INFO:snap7.server:callback event: 2019-05-29 02:42:33 [127.0.0.1] Client added
INFO:snap7.server:callback event: 2019-05-29 02:42:33 [127.0.0.1] Client added
INFO:snap7.server:callback event: 2019-05-29 02:42:33 [127.0.0.1] The client requires a PDU size of 480 bytes
INFO:snap7.server:callback event: 2019-05-29 02:42:33 [127.0.0.1] The client requires a PDU size of 480 bytes
INFO:snap7.server:callback event: 2019-05-29 02:42:33 [127.0.0.1] Write request, Area : DB1, Start : 0, Size : 40 --> OK
INFO:snap7.server:callback event: 2019-05-29 02:42:33 [127.0.0.1] Write request, Area : DB1, Start : 0, Size : 40 --> OK
INFO:snap7.server:callback event: 2019-05-29 02:42:33 [127.0.0.1] Read request, Area : DB1, Start : 0, Size : 40 --> OK
INFO:snap7.server:callback event: 2019-05-29 02:42:33 [127.0.0.1] Read request, Area : DB1, Start : 0, Size : 40 --> OK
.INFO:snap7.server:callback event: 2019-05-29 02:42:33 [127.0.0.1] Client disconnected by peer
INFO:snap7.server:callback event: 2019-05-29 02:42:33 [127.0.0.1] Client disconnected by peer
INFO:snap7.server:callback event: 2019-05-29 02:42:33 [127.0.0.1] Client added
INFO:snap7.server:callback event: 2019-05-29 02:42:33 [127.0.0.1] Client added
INFO:snap7.server:callback event: 2019-05-29 02:42:33 [127.0.0.1] The client requires a PDU size of 480 bytes
INFO:snap7.server:callback event: 2019-05-29 02:42:33 [127.0.0.1] The client requires a PDU size of 480 bytes
INFO:snap7.server:callback event: 2019-05-29 02:42:33 [127.0.0.1] Write request, Area : DB1, Start : 0, Size : 40 --> OK
INFO:snap7.server:callback event: 2019-05-29 02:42:33 [127.0.0.1] Write request, Area : DB1, Start : 0, Size : 40 --> OK
.INFO:snap7.server:callback event: 2019-05-29 02:42:33 [127.0.0.1] Client disconnected by peer
INFO:snap7.server:callback event: 2019-05-29 02:42:33 [127.0.0.1] Client disconnected by peer
INFO:snap7.server:callback event: 2019-05-29 02:42:33 [127.0.0.1] Client added
INFO:snap7.server:callback event: 2019-05-29 02:42:33 [127.0.0.1] Client added
INFO:snap7.server:callback event: 2019-05-29 02:42:33 [127.0.0.1] The client requires a PDU size of 480 bytes
INFO:snap7.server:callback event: 2019-05-29 02:42:33 [127.0.0.1] The client requires a PDU size of 480 bytes
.INFO:snap7.server:callback event: 2019-05-29 02:42:33 [127.0.0.1] Client disconnected by peer
INFO:snap7.server:callback event: 2019-05-29 02:42:33 [127.0.0.1] Client disconnected by peer
INFO:snap7.server:callback event: 2019-05-29 02:42:33 [127.0.0.1] Client added
INFO:snap7.server:callback event: 2019-05-29 02:42:33 [127.0.0.1] Client added
INFO:snap7.server:callback event: 2019-05-29 02:42:33 [127.0.0.1] The client requires a PDU size of 480 bytes
INFO:snap7.server:callback event: 2019-05-29 02:42:33 [127.0.0.1] The client requires a PDU size of 480 bytes
S.INFO:snap7.server:callback event: 2019-05-29 02:42:33 [127.0.0.1] Client disconnected by peer
INFO:snap7.server:callback event: 2019-05-29 02:42:33 [127.0.0.1] Client disconnected by peer
INFO:snap7.server:callback event: 2019-05-29 02:42:33 [127.0.0.1] Client added
INFO:snap7.server:callback event: 2019-05-29 02:42:33 [127.0.0.1] Client added
INFO:snap7.server:callback event: 2019-05-29 02:42:33 [127.0.0.1] The client requires a PDU size of 480 bytes
INFO:snap7.server:callback event: 2019-05-29 02:42:33 [127.0.0.1] The client requires a PDU size of 480 bytes
INFO:snap7.server:callback event: 2019-05-29 02:42:33 [127.0.0.1] Block info requested DB 1 --> OK
INFO:snap7.server:callback event: 2019-05-29 02:42:33 [127.0.0.1] Block info requested DB 1 --> OK
INFO:snap7.server:callback event: 2019-05-29 02:42:33 [127.0.0.1] Block info requested DB 10 --> NOT AVAILABLE
INFO:snap7.server:callback event: 2019-05-29 02:42:33 [127.0.0.1] Block info requested DB 10 --> NOT AVAILABLE
.INFO:snap7.server:callback event: 2019-05-29 02:42:33 [127.0.0.1] Client disconnected by peer
INFO:snap7.server:callback event: 2019-05-29 02:42:33 [127.0.0.1] Client disconnected by peer
INFO:snap7.server:callback event: 2019-05-29 02:42:33 [127.0.0.1] Client added
INFO:snap7.server:callback event: 2019-05-29 02:42:33 [127.0.0.1] Client added
INFO:snap7.server:callback event: 2019-05-29 02:42:33 [127.0.0.1] The client requires a PDU size of 480 bytes
INFO:snap7.server:callback event: 2019-05-29 02:42:33 [127.0.0.1] The client requires a PDU size of 480 bytes
.INFO:snap7.server:callback event: 2019-05-29 02:42:33 [127.0.0.1] Client disconnected by peer
INFO:snap7.server:callback event: 2019-05-29 02:42:33 [127.0.0.1] Client disconnected by peer
INFO:snap7.server:callback event: 2019-05-29 02:42:33 [127.0.0.1] Client added
INFO:snap7.server:callback event: 2019-05-29 02:42:33 [127.0.0.1] Client added
INFO:snap7.server:callback event: 2019-05-29 02:42:33 [127.0.0.1] The client requires a PDU size of 480 bytes
INFO:snap7.server:callback event: 2019-05-29 02:42:33 [127.0.0.1] The client requires a PDU size of 480 bytes
INFO:snap7.server:callback event: 2019-05-29 02:42:33 [127.0.0.1] Read SZL request, ID:0x001c INDEX:0x0000 --> OK
INFO:snap7.server:callback event: 2019-05-29 02:42:33 [127.0.0.1] Read SZL request, ID:0x001c INDEX:0x0000 --> OK
.INFO:snap7.server:callback event: 2019-05-29 02:42:33 [127.0.0.1] Client disconnected by peer
INFO:snap7.server:callback event: 2019-05-29 02:42:33 [127.0.0.1] Client disconnected by peer
INFO:snap7.server:callback event: 2019-05-29 02:42:33 [127.0.0.1] Client added
INFO:snap7.server:callback event: 2019-05-29 02:42:33 [127.0.0.1] Client added
INFO:snap7.server:callback event: 2019-05-29 02:42:33 [127.0.0.1] The client requires a PDU size of 480 bytes
INFO:snap7.server:callback event: 2019-05-29 02:42:33 [127.0.0.1] The client requires a PDU size of 480 bytes
INFO:snap7.server:callback event: 2019-05-29 02:42:33 [127.0.0.1] Read SZL request, ID:0x0424 INDEX:0x0000 --> OK
INFO:snap7.server:callback event: 2019-05-29 02:42:33 [127.0.0.1] Read SZL request, ID:0x0424 INDEX:0x0000 --> OK
.INFO:snap7.server:callback event: 2019-05-29 02:42:33 [127.0.0.1] Client disconnected by peer
INFO:snap7.server:callback event: 2019-05-29 02:42:33 [127.0.0.1] Client disconnected by peer
INFO:snap7.server:callback event: 2019-05-29 02:42:33 [127.0.0.1] Client added
INFO:snap7.server:callback event: 2019-05-29 02:42:33 [127.0.0.1] Client added
INFO:snap7.server:callback event: 2019-05-29 02:42:33 [127.0.0.1] The client requires a PDU size of 480 bytes
INFO:snap7.server:callback event: 2019-05-29 02:42:33 [127.0.0.1] The client requires a PDU size of 480 bytes
.INFO:snap7.server:callback event: 2019-05-29 02:42:33 [127.0.0.1] Client disconnected by peer
INFO:snap7.server:callback event: 2019-05-29 02:42:33 [127.0.0.1] Client disconnected by peer
INFO:snap7.server:callback event: 2019-05-29 02:42:33 [127.0.0.1] Client added
INFO:snap7.server:callback event: 2019-05-29 02:42:33 [127.0.0.1] Client added
INFO:snap7.server:callback event: 2019-05-29 02:42:33 [127.0.0.1] The client requires a PDU size of 480 bytes
INFO:snap7.server:callback event: 2019-05-29 02:42:33 [127.0.0.1] The client requires a PDU size of 480 bytes
.INFO:snap7.server:callback event: 2019-05-29 02:42:33 [127.0.0.1] Client disconnected by peer
INFO:snap7.server:callback event: 2019-05-29 02:42:33 [127.0.0.1] Client disconnected by peer
INFO:snap7.server:callback event: 2019-05-29 02:42:33 [127.0.0.1] Client added
INFO:snap7.server:callback event: 2019-05-29 02:42:33 [127.0.0.1] Client added
INFO:snap7.server:callback event: 2019-05-29 02:42:33 [127.0.0.1] The client requires a PDU size of 480 bytes
INFO:snap7.server:callback event: 2019-05-29 02:42:33 [127.0.0.1] The client requires a PDU size of 480 bytes
INFO:snap7.server:callback event: 2019-05-29 02:42:33 [127.0.0.1] System clock read requested
INFO:snap7.server:callback event: 2019-05-29 02:42:33 [127.0.0.1] System clock read requested
.INFO:snap7.server:callback event: 2019-05-29 02:42:33 [127.0.0.1] Client disconnected by peer
INFO:snap7.server:callback event: 2019-05-29 02:42:33 [127.0.0.1] Client disconnected by peer
INFO:snap7.server:callback event: 2019-05-29 02:42:33 [127.0.0.1] Client added
INFO:snap7.server:callback event: 2019-05-29 02:42:33 [127.0.0.1] Client added
INFO:snap7.server:callback event: 2019-05-29 02:42:33 [127.0.0.1] The client requires a PDU size of 480 bytes
INFO:snap7.server:callback event: 2019-05-29 02:42:33 [127.0.0.1] The client requires a PDU size of 480 bytes
INFO:snap7.server:callback event: 2019-05-29 02:42:33 [127.0.0.1] Block list requested --> OK
INFO:snap7.server:callback event: 2019-05-29 02:42:33 [127.0.0.1] Block list requested --> OK
.INFO:snap7.server:callback event: 2019-05-29 02:42:33 [127.0.0.1] Client disconnected by peer
INFO:snap7.server:callback event: 2019-05-29 02:42:33 [127.0.0.1] Client disconnected by peer
INFO:snap7.server:callback event: 2019-05-29 02:42:33 [127.0.0.1] Client added
INFO:snap7.server:callback event: 2019-05-29 02:42:33 [127.0.0.1] Client added
INFO:snap7.server:callback event: 2019-05-29 02:42:33 [127.0.0.1] The client requires a PDU size of 480 bytes
INFO:snap7.server:callback event: 2019-05-29 02:42:33 [127.0.0.1] The client requires a PDU size of 480 bytes
INFO:snap7.server:callback event: 2019-05-29 02:42:33 [127.0.0.1] Block of type DB list requested (start sequence) --> OK
INFO:snap7.server:callback event: 2019-05-29 02:42:33 [127.0.0.1] Block of type DB list requested (start sequence) --> OK
.INFO:snap7.server:callback event: 2019-05-29 02:42:33 [127.0.0.1] Client disconnected by peer
INFO:snap7.server:callback event: 2019-05-29 02:42:33 [127.0.0.1] Client disconnected by peer
INFO:snap7.server:callback event: 2019-05-29 02:42:33 [127.0.0.1] Client added
INFO:snap7.server:callback event: 2019-05-29 02:42:33 [127.0.0.1] Client added
INFO:snap7.server:callback event: 2019-05-29 02:42:33 [127.0.0.1] The client requires a PDU size of 480 bytes
INFO:snap7.server:callback event: 2019-05-29 02:42:33 [127.0.0.1] The client requires a PDU size of 480 bytes
INFO:snap7.server:callback event: 2019-05-29 02:42:33 [127.0.0.1] CPU Control request : Cold START --> OK
INFO:snap7.server:callback event: 2019-05-29 02:42:33 [127.0.0.1] CPU Control request : Cold START --> OK
INFO:snap7.server:callback event: 2019-05-29 02:42:33 [127.0.0.1] Client disconnected by peer
.INFO:snap7.server:callback event: 2019-05-29 02:42:33 [127.0.0.1] Client disconnected by peer
INFO:snap7.server:callback event: 2019-05-29 02:42:33 [127.0.0.1] Client added
INFO:snap7.server:callback event: 2019-05-29 02:42:33 [127.0.0.1] Client added
INFO:snap7.server:callback event: 2019-05-29 02:42:33 [127.0.0.1] The client requires a PDU size of 480 bytes
INFO:snap7.server:callback event: 2019-05-29 02:42:33 [127.0.0.1] The client requires a PDU size of 480 bytes
INFO:snap7.server:callback event: 2019-05-29 02:42:33 [127.0.0.1] CPU Control request : Warm START --> OK
INFO:snap7.server:callback event: 2019-05-29 02:42:33 [127.0.0.1] CPU Control request : Warm START --> OK
.INFO:snap7.server:callback event: 2019-05-29 02:42:33 [127.0.0.1] Client disconnected by peer
INFO:snap7.server:callback event: 2019-05-29 02:42:33 [127.0.0.1] Client disconnected by peer
INFO:snap7.server:callback event: 2019-05-29 02:42:33 [127.0.0.1] Client added
INFO:snap7.server:callback event: 2019-05-29 02:42:33 [127.0.0.1] Client added
INFO:snap7.server:callback event: 2019-05-29 02:42:33 [127.0.0.1] The client requires a PDU size of 480 bytes
INFO:snap7.server:callback event: 2019-05-29 02:42:33 [127.0.0.1] The client requires a PDU size of 480 bytes
INFO:snap7.server:callback event: 2019-05-29 02:42:33 [127.0.0.1] CPU Control request : STOP --> OK
INFO:snap7.server:callback event: 2019-05-29 02:42:33 [127.0.0.1] CPU Control request : STOP --> OK
.INFO:snap7.server:callback event: 2019-05-29 02:42:33 [127.0.0.1] Client disconnected by peer
INFO:snap7.server:callback event: 2019-05-29 02:42:33 [127.0.0.1] Client disconnected by peer
INFO:snap7.server:callback event: 2019-05-29 02:42:33 [127.0.0.1] Client added
INFO:snap7.server:callback event: 2019-05-29 02:42:33 [127.0.0.1] Client added
INFO:snap7.server:callback event: 2019-05-29 02:42:33 [127.0.0.1] The client requires a PDU size of 480 bytes
INFO:snap7.server:callback event: 2019-05-29 02:42:33 [127.0.0.1] The client requires a PDU size of 480 bytes
INFO:snap7.server:callback event: 2019-05-29 02:42:33 [127.0.0.1] Read request, Area : DB1, Start : 1, Size : 1 --> OK
INFO:snap7.server:callback event: 2019-05-29 02:42:33 [127.0.0.1] Read request, Area : DB1, Start : 1, Size : 1 --> OK
.INFO:snap7.server:callback event: 2019-05-29 02:42:33 [127.0.0.1] Client disconnected by peer
INFO:snap7.server:callback event: 2019-05-29 02:42:33 [127.0.0.1] Client disconnected by peer
INFO:snap7.server:callback event: 2019-05-29 02:42:33 [127.0.0.1] Client added
INFO:snap7.server:callback event: 2019-05-29 02:42:33 [127.0.0.1] Client added
INFO:snap7.server:callback event: 2019-05-29 02:42:33 [127.0.0.1] The client requires a PDU size of 480 bytes
INFO:snap7.server:callback event: 2019-05-29 02:42:33 [127.0.0.1] The client requires a PDU size of 480 bytes
INFO:snap7.server:callback event: 2019-05-29 02:42:33 [127.0.0.1] Write request, Area : DB1, Start : 0, Size : 4 --> OK
INFO:snap7.server:callback event: 2019-05-29 02:42:33 [127.0.0.1] Write request, Area : DB1, Start : 0, Size : 4 --> OK
INFO:snap7.server:callback event: 2019-05-29 02:42:33 [127.0.0.1] Write request, Area : DB1, Start : 4, Size : 4 --> OK
INFO:snap7.server:callback event: 2019-05-29 02:42:33 [127.0.0.1] Write request, Area : DB1, Start : 4, Size : 4 --> OK
INFO:snap7.server:callback event: 2019-05-29 02:42:33 [127.0.0.1] Write request, Area : DB1, Start : 8, Size : 2 --> OK
INFO:snap7.server:callback event: 2019-05-29 02:42:33 [127.0.0.1] Write request, Area : DB1, Start : 8, Size : 2 --> OK
INFO:snap7.server:callback event: 2019-05-29 02:42:33 [127.0.0.1] Read request, Area : DB1, Start : 0, Size : 4 --> OK
INFO:snap7.server:callback event: 2019-05-29 02:42:33 [127.0.0.1] Read request, Area : DB1, Start : 0, Size : 4 --> OK
INFO:snap7.server:callback event: 2019-05-29 02:42:33 [127.0.0.1] Read request, Area : DB1, Start : 4, Size : 4 --> OK
INFO:snap7.server:callback event: 2019-05-29 02:42:33 [127.0.0.1] Read request, Area : DB1, Start : 4, Size : 4 --> OK
INFO:snap7.server:callback event: 2019-05-29 02:42:33 [127.0.0.1] Read request, Area : DB1, Start : 8, Size : 2 --> OK
INFO:snap7.server:callback event: 2019-05-29 02:42:33 [127.0.0.1] Read request, Area : DB1, Start : 8, Size : 2 --> OK
.INFO:snap7.server:callback event: 2019-05-29 02:42:33 [127.0.0.1] Client disconnected by peer
INFO:snap7.server:callback event: 2019-05-29 02:42:33 [127.0.0.1] Client disconnected by peer
INFO:snap7.server:callback event: 2019-05-29 02:42:33 [127.0.0.1] Client added
INFO:snap7.server:callback event: 2019-05-29 02:42:33 [127.0.0.1] Client added
INFO:snap7.server:callback event: 2019-05-29 02:42:33 [127.0.0.1] The client requires a PDU size of 480 bytes
INFO:snap7.server:callback event: 2019-05-29 02:42:33 [127.0.0.1] The client requires a PDU size of 480 bytes
.INFO:snap7.server:callback event: 2019-05-29 02:42:33 [127.0.0.1] Client disconnected by peer
INFO:snap7.server:callback event: 2019-05-29 02:42:33 [127.0.0.1] Client disconnected by peer
INFO:snap7.server:callback event: 2019-05-29 02:42:33 [127.0.0.1] Client added
INFO:snap7.server:callback event: 2019-05-29 02:42:33 [127.0.0.1] Client added
INFO:snap7.server:callback event: 2019-05-29 02:42:33 [127.0.0.1] The client requires a PDU size of 480 bytes
INFO:snap7.server:callback event: 2019-05-29 02:42:33 [127.0.0.1] The client requires a PDU size of 480 bytes
.INFO:snap7.server:callback event: 2019-05-29 02:42:33 [127.0.0.1] Client disconnected by peer
INFO:snap7.server:callback event: 2019-05-29 02:42:33 [127.0.0.1] Client disconnected by peer
INFO:snap7.server:callback event: 2019-05-29 02:42:33 [127.0.0.1] Client added
INFO:snap7.server:callback event: 2019-05-29 02:42:33 [127.0.0.1] Client added
INFO:snap7.server:callback event: 2019-05-29 02:42:33 [127.0.0.1] The client requires a PDU size of 480 bytes
INFO:snap7.server:callback event: 2019-05-29 02:42:33 [127.0.0.1] The client requires a PDU size of 480 bytes
.INFO:snap7.server:callback event: 2019-05-29 02:42:33 [127.0.0.1] Client disconnected by peer
INFO:snap7.server:callback event: 2019-05-29 02:42:33 [127.0.0.1] Client disconnected by peer
INFO:snap7.server:callback event: 2019-05-29 02:42:33 [127.0.0.1] Client added
INFO:snap7.server:callback event: 2019-05-29 02:42:33 [127.0.0.1] Client added
INFO:snap7.server:callback event: 2019-05-29 02:42:33 [127.0.0.1] The client requires a PDU size of 480 bytes
INFO:snap7.server:callback event: 2019-05-29 02:42:33 [127.0.0.1] The client requires a PDU size of 480 bytes
INFO:snap7.server:callback event: 2019-05-29 02:42:33 [127.0.0.1] System clock write requested
INFO:snap7.server:callback event: 2019-05-29 02:42:33 [127.0.0.1] System clock write requested
.INFO:snap7.server:callback event: 2019-05-29 02:42:33 [127.0.0.1] Client disconnected by peer
INFO:snap7.server:callback event: 2019-05-29 02:42:33 [127.0.0.1] Client disconnected by peer
INFO:snap7.server:callback event: 2019-05-29 02:42:33 [127.0.0.1] Client added
INFO:snap7.server:callback event: 2019-05-29 02:42:33 [127.0.0.1] Client added
INFO:snap7.server:callback event: 2019-05-29 02:42:33 [127.0.0.1] The client requires a PDU size of 480 bytes
INFO:snap7.server:callback event: 2019-05-29 02:42:33 [127.0.0.1] The client requires a PDU size of 480 bytes
INFO:snap7.server:callback event: 2019-05-29 02:42:33 [127.0.0.1] Security request : Set session password --> OK
INFO:snap7.server:callback event: 2019-05-29 02:42:33 [127.0.0.1] Security request : Set session password --> OK
.INFO:snap7.server:callback event: 2019-05-29 02:42:33 [127.0.0.1] Client disconnected by peer
INFO:snap7.server:callback event: 2019-05-29 02:42:33 [127.0.0.1] Client disconnected by peer
INFO:snap7.server:callback event: 2019-05-29 02:42:33 [127.0.0.1] Client added
INFO:snap7.server:callback event: 2019-05-29 02:42:33 [127.0.0.1] Client added
INFO:snap7.server:callback event: 2019-05-29 02:42:33 [127.0.0.1] The client requires a PDU size of 480 bytes
INFO:snap7.server:callback event: 2019-05-29 02:42:33 [127.0.0.1] The client requires a PDU size of 480 bytes
INFO:snap7.server:callback event: 2019-05-29 02:42:33 [127.0.0.1] Block upload requested --> NOT PERFORMED (due to invalid security level)
INFO:snap7.server:callback event: 2019-05-29 02:42:33 [127.0.0.1] Block upload requested --> NOT PERFORMED (due to invalid security level)
.INFO:snap7.server:callback event: 2019-05-29 02:42:33 [127.0.0.1] Client disconnected by peer
INFO:snap7.server:callback event: 2019-05-29 02:42:33 [127.0.0.1] Client disconnected by peer
INFO:snap7.server:callback event: 2019-05-29 02:42:33 [127.0.0.1] Client added
INFO:snap7.server:callback event: 2019-05-29 02:42:33 [127.0.0.1] Client added
INFO:snap7.server:callback event: 2019-05-29 02:42:33 [127.0.0.1] The client requires a PDU size of 480 bytes
INFO:snap7.server:callback event: 2019-05-29 02:42:33 [127.0.0.1] The client requires a PDU size of 480 bytes
INFO:snap7.server:callback event: 2019-05-29 02:42:33 [127.0.0.1] Write request, Area : DB1, Start : 1, Size : 1 --> OK
INFO:snap7.server:callback event: 2019-05-29 02:42:33 [127.0.0.1] Write request, Area : DB1, Start : 1, Size : 1 --> OK
.INFO:snap7.server:callback event: 2019-05-29 02:42:33 [127.0.0.1] Client disconnected by peer
INFO:snap7.server:callback event: 2019-05-29 02:42:33 [127.0.0.1] Client disconnected by peer
INFO:snap7.server:callback event: 2019-05-29 02:42:33 [127.0.0.1] Client added
INFO:snap7.server:callback event: 2019-05-29 02:42:33 [127.0.0.1] Client added
INFO:snap7.server:callback event: 2019-05-29 02:42:33 [127.0.0.1] The client requires a PDU size of 480 bytes
INFO:snap7.server:callback event: 2019-05-29 02:42:33 [127.0.0.1] The client requires a PDU size of 480 bytes
.INFO:snap7.server:callback event: 2019-05-29 02:42:33 [127.0.0.1] Client disconnected by peer
...
----------------------------------------------------------------------
Ran 50 tests in 2.339s

OK (SKIP=10)
..............
----------------------------------------------------------------------
Ran 14 tests in 0.185s

OK
(.venv) jkelly@pop-os:~/Development/Python/python-snap7$ 

@gijzelaerr
Copy link
Owner

Yes, that looks fine. The verbose logging comes from the server.

@ghost
Copy link
Author

ghost commented May 29, 2019

Ok. I have not authored a unittest before so will read up on it as it's something I should learn anyway.
I'll take a stab at getting this done this week.

@gijzelaerr
Copy link
Owner

It is not hard, just have a look at the other unit tests. Just calling the function without errors is already a great start. Thanks for looking into this.

@ghost
Copy link
Author

ghost commented May 29, 2019

Looking at the already existing test for read_area, it would seem that I just need to add two extra cases: 1 for a counter and one for a timer. Seem correct to you? (Existing unmodified test below)

def test_read_area(self):
area = snap7.snap7types.areas.DB
dbnumber = 1
amount = 1
start = 1
self.client.read_area(area, dbnumber, start, amount)

@gijzelaerr
Copy link
Owner

Note that we are testing the full_upload wrapper function.

Sorry i don't have time left to look at this now.

@ghost
Copy link
Author

ghost commented May 29, 2019

One final question. I made changes to the read_area function however you want me to write a test for the full_upload function? Please confirm.

@gijzelaerr
Copy link
Owner

You have modifed the full_upload() function of python-snap7. that function calls, read_area but that is an implementation detail. Please add a test that calls full_upload(). The test itself should call the full_upload() function multiple times, each braching into each if condition.

thanks

@ghost
Copy link
Author

ghost commented May 29, 2019

Sorry, I see what is going on now. You had me confused for a bit there. So, looking in Github at the file differences, the display in misleading. If you look at the line numbers in the affected code, it jumps from 179 to 250. At first glance, it gives the impression that the code change occurred in full_upload. If you click on the blue expand buttons and expand it out, you will see that my code changes were actually in the read_area function.

@gijzelaerr
Copy link
Owner

Well spotted! You are rights, sorry about that. I hope you know enough now :)

@ghost
Copy link
Author

ghost commented May 29, 2019

I'm going to still keep on learning about the unit tests so perhaps I can contribute in the future more. If you still want a test authored for full_upload, I am willing to take a stab at it. Did you want me to test the extra conditions in read_area now to test for both counter and timer reads?

@gijzelaerr
Copy link
Owner

any contributions are welcome! I'm just the maintainer of this project but have not used it for a while. I'm just coordinating the PR's for the benefit of the world :)

…ounters and timers. Updated test_client to test both reading and writing to timers and counters

in read_area and write_area.
@ghost
Copy link
Author

ghost commented May 31, 2019

I made changes to both read_area and write_area now. I have tested my changes on a real plc and they are working now (timers and counters). I also updated the server file to create timer and counter areas and have modified the tests for read_area and write_area to test for DB's, CT's, and TM's. I might take a stab at the full upload test at a later date.

@gijzelaerr
Copy link
Owner

looking good! thanks!!

@gijzelaerr gijzelaerr merged commit 4660357 into gijzelaerr:master May 31, 2019
@ghost
Copy link
Author

ghost commented May 31, 2019

No problem. I'll try to test some more when I can and get coverage on some of the missing tests.

@gijzelaerr gijzelaerr added this to the 0.11 milestone Apr 16, 2020
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.

2 participants