-
Notifications
You must be signed in to change notification settings - Fork 100
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
51 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,53 @@ | ||
Quickstart | ||
---------- | ||
|
||
.. important:: | ||
|
||
You need to create routes on your client pc and on your target plc via TwinCAT **before | ||
any communication can take place**. If you are on Windows you can use the TwinCAT router. | ||
For Linux systems the route is created automatically on the client-side. For the target-side | ||
you can use :py:func:`.add_route_to_plc`. | ||
|
||
.. code:: python | ||
>>> import pyads | ||
>>> # create some constants for connection | ||
>>> CLIENT_NETID = "192.168.1.10.1.1" | ||
>>> CLIENT_IP = "192.168.1.10" | ||
>>> TARGET_IP = "192.168.1.11" | ||
>>> TARGET_USERNAME = "Administrator" | ||
>>> TARGET_PASSWORD = "1" | ||
>>> ROUTE_NAME = "route-to-my-plc" | ||
>>> # add a new route to the target plc | ||
>>> pyads.add_route_to_plc( | ||
>>> CLIENT_NETID, CLIENT_IP, TARGET_IP, TARGET_USERNAME, TARGET_PASSWORD, | ||
>>> route_name=ROUTE_NAME | ||
>>> ) | ||
>>> # connect to plc and open connection | ||
>>> # route is added automatically to client on Linux, on Windows use the TwinCAT router | ||
>>> plc = pyads.Connection('127.0.0.1.1.1', pyads.PORT_SPS1) | ||
>>> plc.open() | ||
>>> # check the connection state | ||
>>> plc.read_state() | ||
(0, 5) | ||
>>> # read int value by name | ||
>>> i = plc.read_by_name("GVL.int_val") | ||
>>> # write int value by name | ||
>>> plc.write_by_name("GVL.real_val", 42.0) | ||
>>> # create a symbol that automatically updates to the plc value | ||
>>> real_val = plc.get_symbol("GVL.real_val", auto_update=True) | ||
>>> print(real_val.value) | ||
42.0 | ||
>>> real_val.value = 5.0 | ||
>>> print(plc.read_by_name("GVL.real_val")) | ||
5.0 | ||
>>> # close connection | ||
>>> plc.close() |