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
c4667891
Commit
c4667891
authored
2 years ago
by
Rolf Niepraschk
Browse files
Options
Downloads
Patches
Plain Diff
Erklärungen
parent
8f63f0a7
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
DevHub/devhub-simple.py
+20
-18
20 additions, 18 deletions
DevHub/devhub-simple.py
with
20 additions
and
18 deletions
DevHub/devhub-simple.py
+
20
−
18
View file @
c4667891
...
...
@@ -15,18 +15,12 @@ DEVHUB_HOST = 'localhost' # 'localhost'
DEVHUB_PORT
=
9009
DEVHUB_URL
=
'
http://{}:{}/
'
.
format
(
DEVHUB_HOST
,
DEVHUB_PORT
)
devhub_data
=
{
'
Action
'
:
'
TCP
'
,
'
Host
'
:
LAN_RS232_HOST
,
'
Port
'
:
LAN_RS232_PORT
,
'
Timeout
'
:
LAN_RS232_TIMEOUT
,
'
Value
'
:
CORVUS_GETPOS
,
'
PostProcessing
'
:
[
'
var Result = _.extractCorvusArray(_x)[1];
'
]
}
"""
Zum PostProcessing: Parameter ist ein String-Array. Jeder String wird als
JavaScript-Code interpretiert. Über die spezielle Variable
"
_
"
hat man Zugriff
auf vordefinierte Funktionen, wie in diesem Beispiel
"
extractCorvusArray
"
. Ihre
Definition findet man in der Datei
"
resources/j/add-CORVUS.js
"
.
Zum PostProcessing (JAVASCRIPT): Parameter ist ein String-Array. Jeder String
wird als JavaScript-Code interpretiert. Über die spezielle Variable
"
_
"
hat
man Zugriff auf vordefinierte Funktionen, wie in diesem Beispiel
"
extractCorvusArray
"
. Ihre Definition findet man in der Datei
"
resources/js/add-CORVUS.js
"
.
Die folgende Abfrage gibt einen ungefähren Überblick, an welchen Stellen der
Datenbankdokumente
"
PostProcessing
"
verwendet wird:
...
...
@@ -38,8 +32,18 @@ Die Schlüsselworte "PostScript" (für Closure-Code) und "PostScriptPy"
(für Python-Code) haben eine ähnliche Funktion wie
"
PostProcessing
"
.
"""
print
()
print
(
'
=
'
*
78
)
print
(
'
\n
*** JSON-Auftrag an DEVHUB ***
'
)
print
(
'
*** Postprocessing per JAVASCRIPT-Code ***
'
)
devhub_data
=
{
'
Action
'
:
'
TCP
'
,
'
Host
'
:
LAN_RS232_HOST
,
'
Port
'
:
LAN_RS232_PORT
,
'
Timeout
'
:
LAN_RS232_TIMEOUT
,
'
Value
'
:
CORVUS_GETPOS
,
'
PostProcessing
'
:
[
'
var Result = _.extractCorvusArray(_x)[1];
'
]
}
print
(
devhub_data
)
response
=
requests
.
post
(
DEVHUB_URL
,
json
=
devhub_data
)
...
...
@@ -49,6 +53,8 @@ data = response.json() # erzeugt aus JSON eine Dictionary-Variable
print
(
'
\n
*** JSON-Antwort von DEVHUB ***
'
)
print
(
data
)
# enthält die Angaben des JSON-Auftrags ergänzt um die Antwortdaten wie
# "_x", "_t_start", "_t_stop", "req-id" und ggf. "Result" aus dem Postprocessing.
print
(
'
\n
*** Rohdaten der Geräteantwort ***
'
)
print
(
data
.
get
(
'
_x
'
))
...
...
@@ -56,21 +62,17 @@ print(data.get('_x'))
print
(
'
\n
*** Ergebnis des Postprocessings (Position Motor 2, Index 1) ***
'
)
print
(
data
.
get
(
'
Result
'
))
print
()
print
(
'
=
'
*
78
)
print
(
'
*** Postprocessing per Python-Code ***
'
)
devhub_data
=
{
'
Action
'
:
'
TCP
'
,
'
Host
'
:
LAN_RS232_HOST
,
'
Port
'
:
LAN_RS232_PORT
,
'
Timeout
'
:
LAN_RS232_TIMEOUT
,
'
Value
'
:
CORVUS_GETPOS
,
'
PostScriptPy
'
:
'
print(json.dumps({
"
Result
"
: 17 })
'
}
print
(
'
\n
*** JSON-Auftrag an DEVHUB ***
'
)
print
(
'
*** Postprocessing per Python-Code ***
'
)
devhub_data
=
{
'
Action
'
:
'
TCP
'
,
'
Host
'
:
LAN_RS232_HOST
,
'
Port
'
:
LAN_RS232_PORT
,
'
Timeout
'
:
LAN_RS232_TIMEOUT
,
'
Value
'
:
CORVUS_GETPOS
,
'
PostScriptPy
'
:
'
corvus
'
,
'
PostScriptInput
'
:
{
'
Index
'
:
1
}
}
print
(
devhub_data
)
response
=
requests
.
post
(
DEVHUB_URL
,
json
=
devhub_data
)
data
=
response
.
json
()
...
...
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