Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
U
Urumbu
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
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
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Neil Gershenfeld
Urumbu
Commits
1c50d96d
Commit
1c50d96d
authored
May 1, 2021
by
Neil Gershenfeld
Browse files
Options
Downloads
Patches
Plain Diff
wip
parent
a0d8851c
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
serialtimetest/serialtimetest.2.multi.py
+64
-0
64 additions, 0 deletions
serialtimetest/serialtimetest.2.multi.py
serialtimetest/serialtimetest.2.threads.py
+12
-16
12 additions, 16 deletions
serialtimetest/serialtimetest.2.threads.py
with
76 additions
and
16 deletions
serialtimetest/serialtimetest.2.multi.py
0 → 100644
+
64
−
0
View file @
1c50d96d
#
# serialtimetest.2.multi.py
# serial speed time test, two ports, multiprocessing version
#
# Neil Gershenfeld 4/30/21
# This work may be reproduced, modified, distributed,
# performed, and displayed for any purpose, but must
# acknowledge this project. Copyright is retained and
# must be preserved. The work is provided as is; no
# warranty is provided, and users accept all liability.
#
import
serial
,
sys
,
time
,
signal
,
multiprocessing
if
(
len
(
sys
.
argv
)
!=
5
):
print
(
"
command line: serialtest.2.multi.py port1 port2 speed delay
"
)
sys
.
exit
()
device1
=
sys
.
argv
[
1
]
device2
=
sys
.
argv
[
2
]
baud
=
int
(
sys
.
argv
[
3
])
delay
=
float
(
sys
.
argv
[
4
])
print
(
'
open
'
+
device1
+
'
at
'
+
str
(
baud
)
+
'
delay
'
+
str
(
delay
))
port0
=
serial
.
Serial
(
device1
,
baudrate
=
baud
,
timeout
=
0
)
print
(
'
open
'
+
device2
+
'
at
'
+
str
(
baud
)
+
'
delay
'
+
str
(
delay
))
port1
=
serial
.
Serial
(
device2
,
baudrate
=
baud
,
timeout
=
0
)
msg
=
b
"
\x00
"
ports
=
[
port0
,
port1
]
evt
=
multiprocessing
.
Event
()
#
# worker event handler
#
def
worker
(
id
,
evt
):
while
(
1
):
while
(
1
):
if
(
evt
.
is_set
()):
break
ports
[
id
].
write
(
msg
)
while
(
1
):
if
(
not
evt
.
is_set
()):
break
ports
[
id
].
write
(
msg
)
#
# alarm event handler
#
def
handler
(
signum
,
stack
):
if
(
evt
.
is_set
()):
evt
.
clear
()
else
:
evt
.
set
()
#
# start workers
#
p0
=
multiprocessing
.
Process
(
target
=
worker
,
args
=
(
0
,
evt
,))
p0
.
start
()
p1
=
multiprocessing
.
Process
(
target
=
worker
,
args
=
(
1
,
evt
,))
p1
.
start
()
#
# start alarm
#
signal
.
signal
(
signal
.
SIGALRM
,
handler
)
signal
.
setitimer
(
signal
.
ITIMER_REAL
,
1
,
delay
)
#
# wait for alarms
#
while
(
1
):
0
This diff is collapsed.
Click to expand it.
serialtimetest/serialtimetest.2.threads.py
+
12
−
16
View file @
1c50d96d
...
...
@@ -9,45 +9,41 @@
# must be preserved. The work is provided as is; no
# warranty is provided, and users accept all liability.
#
import
sys
,
time
,
signal
,
threading
delay
=
0.2
'''
import serial,sys,time,signal
import
serial
,
sys
,
time
,
signal
,
threading
if
(
len
(
sys
.
argv
)
!=
5
):
print(
"
command line: serialtest.2.py port1 port2 speed delay
"
)
print
(
"
command line: serialtest.2.
threads.
py port1 port2 speed delay
"
)
sys
.
exit
()
device1
=
sys
.
argv
[
1
]
device2
=
sys
.
argv
[
2
]
baud
=
int
(
sys
.
argv
[
3
])
delay
=
float
(
sys
.
argv
[
4
])
print
(
'
open
'
+
device1
+
'
at
'
+
str
(
baud
)
+
'
delay
'
+
str
(
delay
))
port
1
= serial.Serial(device1,baudrate=baud,timeout=0)
port
0
=
serial
.
Serial
(
device1
,
baudrate
=
baud
,
timeout
=
0
)
print
(
'
open
'
+
device2
+
'
at
'
+
str
(
baud
)
+
'
delay
'
+
str
(
delay
))
port2 = serial.Serial(device2,baudrate=baud,timeout=0)
'''
msg0
=
b
"
\x00
"
msg1
=
b
"
\xff
"
port1
=
serial
.
Serial
(
device2
,
baudrate
=
baud
,
timeout
=
0
)
msg
=
b
"
\x00
"
flag
=
0
ports
=
[
port0
,
port1
]
#
# thread handler
#
def
fn
(
id
):
global
v
global
v
,
ports
,
msg
while
(
1
):
#
# wait for flag to be raised
#
while
(
1
):
if
(
flag
!=
0
):
print
(
1
,
id
)
break
ports
[
id
].
write
(
msg
)
#
# wait for flag to be lowered
#
while
(
1
):
if
(
flag
==
0
):
print
(
0
,
id
)
break
ports
[
id
].
write
(
msg
)
#
# alarm handler
#
...
...
@@ -60,10 +56,10 @@ def handler(signum,stack):
#
# start threads
#
t1
=
threading
.
Thread
(
target
=
fn
,
args
=
(
'
t1
'
,))
t0
=
threading
.
Thread
(
target
=
fn
,
args
=
(
0
,))
t0
.
start
()
t1
=
threading
.
Thread
(
target
=
fn
,
args
=
(
1
,))
t1
.
start
()
t2
=
threading
.
Thread
(
target
=
fn
,
args
=
(
'
t2
'
,))
t2
.
start
()
#
# start alarm
#
...
...
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
sign in
to comment