Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
E
ebpfCAT
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Martin Teichmann
ebpfCAT
Commits
100a0f2d
Commit
100a0f2d
authored
11 months ago
by
Martin Teichmann
Browse files
Options
Downloads
Patches
Plain Diff
add examples to documentation
parent
7e86056f
No related branches found
No related tags found
No related merge requests found
Pipeline
#135471
passed
11 months ago
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
ebpfcat/ethercat.rst
+6
-2
6 additions, 2 deletions
ebpfcat/ethercat.rst
examples/ethercat.py
+29
-0
29 additions, 0 deletions
examples/ethercat.py
with
35 additions
and
2 deletions
ebpfcat/ethercat.rst
+
6
−
2
View file @
100a0f2d
...
...
@@ -17,14 +17,14 @@ we need to use await, which can only be done in an async function::
async def main():
master = FastEtherCat("eth0")
await master.connect()
await master.
scan_bus
()
print('Number of terminals:',
await master.
count
()
)
asyncio.run(main())
Next we create an object for each terminal that we want to use. As an example,
take some Beckhoff output terminal::
from ebpfcat.terminals import EL4104
, Generic
from ebpfcat.terminals import EL4104
out = EL4104(master)
...
...
@@ -62,6 +62,10 @@ output a value like so::
ao.value = 5 # set the value on the terminal
For reference, here is a complete code example:
.. literalinclude:: /examples/ethercat.py
Writing a device
----------------
...
...
This diff is collapsed.
Click to expand it.
examples/ethercat.py
0 → 100644
+
29
−
0
View file @
100a0f2d
"""
A simple example of an EtherCat control
this is only an illustrative example to be read. It will not work unless
you happen to have an EtherCat setup where a Beckhoff EL4101 terminal is
the second terminal in the line.
"""
import
asyncio
from
ebpfcat.ebpfcat
import
FastEtherCat
,
SyncGroup
from
ebpfcat.devices
import
AnalogOutput
from
ebpfcat.terminals
import
EL4104
async
def
main
():
master
=
FastEtherCat
(
"
eth0
"
)
await
master
.
connect
()
print
(
"
Number of terminals:
"
,
await
master
.
count
())
out
=
EL4104
(
master
)
await
out
.
initialize
(
-
2
,
20
)
ao
=
AnalogOutput
(
out
.
ch2_value
)
# use channel 1 of terminal "out"
sg
=
SyncGroup
(
master
,
[
ao
])
# this sync group only contains one terminal
task
=
sg
.
start
()
# start operating the terminals
for
i
in
range
(
10
):
# we would measure an increasing value on the terminal output
ao
.
value
=
i
await
asyncio
.
sleep
(
0.1
)
task
.
cancel
()
# stop the sync group
asyncio
.
run
(
main
())
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment