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
dcbd876e
Commit
dcbd876e
authored
2 years ago
by
Rolf Niepraschk
Browse files
Options
Downloads
Patches
Plain Diff
...
parent
b3a06b94
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
+34
-18
34 additions, 18 deletions
DevHub/ce3-preset.py
DevHub/devhub-simple.py
+2
-1
2 additions, 1 deletion
DevHub/devhub-simple.py
with
36 additions
and
19 deletions
DevHub/ce3-preset.py
+
34
−
18
View file @
dcbd876e
#!/usr/bin/env python3
# Rolf Niepraschk, Rolf.Niepraschk@ptb.de, 2023-03-0
8
# Rolf Niepraschk, Rolf.Niepraschk@ptb.de, 2023-03-0
9
import
s
ocket
,
signal
,
sys
,
time
import
json
import
s
ys
,
requests
import
json
# debug!
DEVHUB_URL
=
'
http://localhost:9009/
'
HTTP_HEADER
=
'
Content-Type: application/json
'
DEVHUB_HOST
=
'
i75419
'
# 'localhost'
DEVHUB_PORT
=
9009
DEVHUB_URL
=
'
http://{}:{}/
'
.
format
(
DEVHUB_HOST
,
DEVHUB_PORT
)
LAN_RS232_HOST
=
'
e75491
'
LAN_RS232_TIMEOUT
=
10000
# ms
DATA_TEMPLATE
=
{
'
Action
'
:
'
TCP
'
,
'
Host
'
:
LAN_RS232_HOST
}
CORVUS_EOL
=
'
\r
'
CORVUS_GETPOS
=
'
pos{EOL}
'
.
format
(
EOL
=
CORVUS_EOL
)
#CORVUS_MOVEREL = "clean\r1.2 sv\r0.0 0.0 -8 r\r1 getpitch\r"
CORVUS_MOVEREL
=
'
clean{EOL}{VEL} sv{EOL}0.0 0.0 {DIST} r{EOL}1 getpitch{EOL}
'
CONTROLER_HOST
=
'
e75463
'
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
}
'
DV1
'
:
{
'
Port
'
:
10001
,
'
Index
'
:
0
,
'
Velocity
'
:
1.2
},
'
DV2
'
:
{
'
Port
'
:
10001
,
'
Index
'
:
1
,
'
Velocity
'
:
1.2
},
'
DVG1
'
:
{
'
Port
'
:
10003
,
'
Index
'
:
0
,
'
Velocity
'
:
1.2
}
}
PROMPT
=
'
J/N ?
'
...
...
@@ -52,36 +59,45 @@ def y_n_input(prompt, true_chars):
def
is_movement_needed
(
n
,
pos
):
x
=
False
print
(
'
Position des Ventils {}: {}mm
'
.
format
(
n
,
pos
))
print
(
'
Position des Ventils
»
{}
«
: {}mm
'
.
format
(
n
,
pos
))
if
pos
!=
0
:
corr
=
-
pos
print
(
'
Soll Ventil {} um {}mm zur Nullposition gefahren werden?
'
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.
'
print
(
'
Ventil »
{}
«
ist bereits auf Nullposition. Es ist nichts zu tun.
'
.
format
(
n
))
print
()
return
x
def
call_devhub
(
data
):
response
=
requests
.
post
(
DEVHUB_URL
,
json
=
data
)
return
response
.
json
()
def
get_pos
(
n
):
port
=
VALVE
[
n
][
'
Port
'
]
idx
=
VALVE
[
n
][
'
Index
'
]
d
=
DATA_TEMPLATE
.
copy
()
d
[
'
Timeout
'
]
=
LAN_RS232_TIMEOUT
d
[
'
Port
'
]
=
port
d
[
'
Value
'
]
=
'
xyz
'
+
str
(
idx
)
# TODO: devhub-Kommunikation
pos
=
8
d
[
'
Value
'
]
=
CORVUS_GETPOS
print
(
'
==> get_pos:
'
+
json
.
dumps
(
d
))
res
=
call_devhub
(
d
)
a
=
res
[
'
_x
'
].
split
()
print
(
'
==> result:
'
+
a
[
idx
])
pos
=
8
return
pos
def
move_rel
(
n
,
dist
):
port
=
VALVE
[
n
][
'
Port
'
]
idx
=
VALVE
[
n
][
'
Index
'
]
vel
=
VALVE
[
n
][
'
Velocity
'
]
d
=
DATA_TEMPLATE
.
copy
()
d
[
'
Port
'
]
=
port
d
[
'
Value
'
]
=
'
uvw
'
+
str
(
dist
)
d
[
'
Value
'
]
=
CORVUS_MOVEREL
.
format
(
EOL
=
CORVUS_EOL
,
VEL
=
vel
,
DIST
=
dist
)
# TODO: devhub-Kommunikation
# res = call_devhub(d)
print
(
'
==> move:
'
+
json
.
dumps
(
d
))
pos
=
0
return
pos
...
...
This diff is collapsed.
Click to expand it.
DevHub/devhub-simple.py
+
2
−
1
View file @
dcbd876e
...
...
@@ -6,6 +6,7 @@ import sys, requests
LAN_RS232_HOST
=
'
e75491
'
LAN_RS232_PORT
=
10001
LAN_RS232_TIMEOUT
=
10000
# ms
CORVUS_EOL
=
'
\r
'
CORVUS_GETPOS
=
'
pos
'
+
CORVUS_EOL
...
...
@@ -15,7 +16,7 @@ DEVHUB_PORT = 9009
DEVHUB_URL
=
'
http://{}:{}/
'
.
format
(
DEVHUB_HOST
,
DEVHUB_PORT
)
DEVHUB_DATA
=
{
'
Action
'
:
'
TCP
'
,
'
Host
'
:
LAN_RS232_HOST
,
'
Timeout
'
:
10000
,
'
Action
'
:
'
TCP
'
,
'
Host
'
:
LAN_RS232_HOST
,
'
Timeout
'
:
LAN_RS232_TIMEOUT
,
'
Port
'
:
LAN_RS232_PORT
,
'
Value
'
:
CORVUS_GETPOS
}
...
...
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