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
7a01a6a3
Commit
7a01a6a3
authored
2 years ago
by
Rolf Niepraschk
Browse files
Options
Downloads
Patches
Plain Diff
Ctrl+C-Handling robuster
parent
6f791337
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
Prologix/combi-test.py
+11
-15
11 additions, 15 deletions
Prologix/combi-test.py
with
11 additions
and
15 deletions
Prologix/combi-test.py
+
11
−
15
View file @
7a01a6a3
#!/usr/bin/env python3
# Rolf Niepraschk, Rolf.Niepraschk@ptb.de, 2022-11-2
8
# Rolf Niepraschk, Rolf.Niepraschk@ptb.de, 2022-11-2
9
import
socket
,
signal
,
sys
,
re
,
time
PROLOGIX_IP
=
'
172.30.54.71
'
PROLOGIX_PORT
=
1234
SOCKET_TIMEOUT
=
10
# s
SOCKET_TIMEOUT
=
10
# s
DEVICE_TIMEOUT
=
3000
# ms (max. 3000)
HP34401A_ADR
=
22
KEITHLEY2700_ADR
=
6
...
...
@@ -126,17 +126,13 @@ def read_voltage():
return
data
else
:
return
''
ctrl_c_pressed
=
False
def
ctrl_c_handler
(
signal
,
frame
):
sock
.
close
()
print
(
'
\n
Ende!
'
)
sys
.
exit
(
0
)
def
ctrl_c_off
():
signal
.
signal
(
signal
.
SIGINT
,
signal
.
SIG_IGN
)
# ignore keyboard interrupt
def
ctrl_c_on
():
signal
.
signal
(
signal
.
SIGINT
,
ctrl_c_handler
)
# allow keyboard interrupt
global
ctrl_c_pressed
ctrl_c_pressed
=
True
# Behandlung von KeyboardInterrupt (Ctrl+C) mit eigener Funktion
signal
.
signal
(
signal
.
SIGINT
,
ctrl_c_handler
)
# ===================================================================
...
...
@@ -146,15 +142,15 @@ init_voltage()
init_temperature
()
while
True
:
ctrl_c_off
()
print
(
'
{}: >>>{}<<<
'
.
format
(
'
Spannung
'
,
read_voltage
()))
print
(
'
{}: >>>{}<<<
'
.
format
(
'
Temperatur
'
,
read_temperature
()))
ctrl_c_on
()
print
()
if
ctrl_c_pressed
:
# nur unterbrechen, wenn Kommunikation komplett
break
time
.
sleep
(.
5
)
sock
.
close
()
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