Skip to content
Snippets Groups Projects
Commit dcbd876e authored by Rolf Niepraschk's avatar Rolf Niepraschk
Browse files

...

parent b3a06b94
No related branches found
No related tags found
No related merge requests found
#!/usr/bin/env python3
# Rolf Niepraschk, Rolf.Niepraschk@ptb.de, 2023-03-08
# Rolf Niepraschk, Rolf.Niepraschk@ptb.de, 2023-03-09
import socket, signal, sys, time
import json
import sys, 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
......
......@@ -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
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment