Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
Python-Beispiele
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
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
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
vaclab
Python-Beispiele
Commits
f58cb0e2
Commit
f58cb0e2
authored
2 years ago
by
Rolf Niepraschk
Browse files
Options
Downloads
Patches
Plain Diff
DevHub examples
parent
7b714036
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
DevHub/ce3-preset.py
+109
-0
109 additions, 0 deletions
DevHub/ce3-preset.py
DevHub/devhub-simple.py
+15
-0
15 additions, 0 deletions
DevHub/devhub-simple.py
with
124 additions
and
0 deletions
DevHub/ce3-preset.py
0 → 100755
+
109
−
0
View file @
f58cb0e2
#!/usr/bin/env python3
# Rolf Niepraschk, Rolf.Niepraschk@ptb.de, 2023-03-08
import
socket
,
signal
,
sys
,
time
import
json
CONTROLER_HOST
=
'
e75463
'
CONTROLER_PORT_V1_V2
=
'
10001
'
CONTROLER_PORT_V3_V4
=
'
10003
'
DEVHUB_URL
=
'
http://localhost:9009/
'
HTTP_HEADER
=
'
Content-Type: application/json
'
DATA_TEMPLATE
=
{
'
Action
'
:
'
TCP
'
,
'
Host
'
:
CONTROLER_HOST
}
VALVE
=
{
'
V1
'
:
{
'
Port
'
:
10001
,
'
Index
'
:
0
},
'
V2
'
:
{
'
Port
'
:
10001
,
'
Index
'
:
1
},
'
V3
'
:
{
'
Port
'
:
10003
,
'
Index
'
:
0
},
'
V4
'
:
{
'
Port
'
:
10003
,
'
Index
'
:
1
}
}
PROMPT
=
'
J/N ?
'
def
_find_getch
():
# https://stackoverflow.com/questions/510357/how-to-read-a-single-character-from-the-user
try
:
import
termios
except
ImportError
:
# Non-POSIX. Return msvcrt's (Windows') getch.
import
msvcrt
return
msvcrt
.
getch
# POSIX system. Create and return a getch that manipulates the tty.
import
sys
,
tty
def
_getch
():
fd
=
sys
.
stdin
.
fileno
()
old_settings
=
termios
.
tcgetattr
(
fd
)
try
:
tty
.
setraw
(
fd
)
ch
=
sys
.
stdin
.
read
(
1
)
finally
:
termios
.
tcsetattr
(
fd
,
termios
.
TCSADRAIN
,
old_settings
)
return
ch
return
_getch
getch
=
_find_getch
()
def
y_n_input
(
prompt
,
true_chars
):
print
(
prompt
,
end
=
''
,
flush
=
True
)
x
=
getch
()
return
x
in
true_chars
def
is_movement_needed
(
n
,
pos
):
x
=
False
print
(
'
Position des Ventils {}: {}mm
'
.
format
(
n
,
pos
))
if
pos
!=
0
:
corr
=
-
pos
print
(
'
Soll Ventil {} um {}mm zur Nullposition gefahren werden?
'
.
format
(
n
,
corr
))
x
=
y_n_input
(
PROMPT
,
[
'
j
'
,
'
J
'
])
else
:
print
(
'
{} ist bereits auf Nullposition. Es ist nichts zu tun.
'
.
format
(
n
))
print
()
return
x
def
get_pos
(
n
):
port
=
VALVE
[
n
][
'
Port
'
]
idx
=
VALVE
[
n
][
'
Index
'
]
d
=
DATA_TEMPLATE
.
copy
()
d
[
'
Port
'
]
=
port
d
[
'
Value
'
]
=
'
xyz
'
+
str
(
idx
)
# TODO: devhub-Kommunikation
pos
=
8
print
(
'
==> get_pos:
'
+
json
.
dumps
(
d
))
return
pos
def
move_rel
(
n
,
dist
):
port
=
VALVE
[
n
][
'
Port
'
]
idx
=
VALVE
[
n
][
'
Index
'
]
d
=
DATA_TEMPLATE
.
copy
()
d
[
'
Port
'
]
=
port
d
[
'
Value
'
]
=
'
uvw
'
+
str
(
dist
)
# TODO: devhub-Kommunikation
print
(
'
==> move:
'
+
json
.
dumps
(
d
))
pos
=
0
return
pos
print
(
'
\n
'
)
###print(json.dumps(DATA_TEMPLATE))
print
(
'
=
'
*
64
)
for
name
in
VALVE
:
pos
=
get_pos
(
name
)
mov
=
is_movement_needed
(
name
,
pos
)
if
mov
:
print
(
'
\n
Ventil {} wird um {}mm bewegt ...
'
.
format
(
name
,
-
pos
))
res
=
move_rel
(
name
,
-
pos
)
print
(
'
Resultat: {}mm
'
.
format
(
res
))
print
(
'
=
'
*
64
)
print
(
'
\n
Ende!
'
)
sys
.
exit
(
0
)
This diff is collapsed.
Click to expand it.
DevHub/devhub-simple.py
0 → 100755
+
15
−
0
View file @
f58cb0e2
#!/usr/bin/env python3
# Rolf Niepraschk, Rolf.Niepraschk@ptb.de, 2023-03-08
import
socket
,
signal
,
sys
,
time
import
json
DEVHUB_URL
=
'
http://localhost:9009/
'
HTTP_HEADER
=
'
Content-Type: application/json
'
DATA_TEMPLATE
=
{
'
Action
'
:
'
TCP
'
,
'
Host
'
:
CONTROLER_HOST
}
print
(
'
\n
Ende!
'
)
sys
.
exit
(
0
)
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