Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
CardioBrainSignals
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
Model registry
Operate
Environments
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
Pavle Boškoski
CardioBrainSignals
Commits
a9e5e8ca
Commit
a9e5e8ca
authored
5 years ago
by
Pavle Boškoski
Browse files
Options
Downloads
Patches
Plain Diff
Put in separate thread
parent
11cf290c
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
README.md
+4
-0
4 additions, 0 deletions
README.md
cardiobrain/comm.py
+24
-1
24 additions, 1 deletion
cardiobrain/comm.py
with
28 additions
and
1 deletion
README.md
+
4
−
0
View file @
a9e5e8ca
...
...
@@ -11,4 +11,8 @@ Everything is available in the `cardiobrain` folder.
## Usage
```
python
import
cardiobrain
as
cb
dev
=
cb
.
CardioBrain
(
dev
=
'
/dev/ttyUSB0
'
,
baud
=
112500
)
dev
.
startDAQ
()
dev
.
stopDAQ
()
dev
.
storeFile
()
```
This diff is collapsed.
Click to expand it.
cardiobrain/comm.py
+
24
−
1
View file @
a9e5e8ca
import
serial
as
ser
import
threading
class
CardioBrain
(
object
):
...
...
@@ -8,6 +9,8 @@ class CardioBrain(object):
:param baud: Baud rate for the serial communication
"""
self
.
s
=
ser
.
Serial
(
'
/dev/ttyUSB0
'
,
112500
)
self
.
__active
=
False
self
.
thr
=
threading
.
Thread
(
target
=
__readSignals
,
args
=
(
self
))
def
close
(
self
):
...
...
@@ -23,8 +26,28 @@ class CardioBrain(object):
return
True
def
__readSignals
(
self
):
while
self
.
__active
:
self
.
data
=
self
.
s
.
read
(
42
)
self
.
__parseData
(
self
)
def
__parseData
(
self
):
r
=
re
.
compile
(
b
'
(?P<header>
\xa5\xa5\xa5
)(?P<payload>.{3})
'
)
m
=
r
.
match
(
self
.
data
)
if
not
m
:
self
.
__active
=
False
raise
Exception
(
'
Wrong data frame %s
'
%
self
.
data
)
return
def
readAll
(
self
):
self
.
data
=
self
.
s
.
readall
()
self
.
__active
=
True
self
.
thr
.
start
()
def
stopRead
(
self
):
self
.
__active
=
False
def
startDaq
(
self
):
self
.
s
.
write
((
'
a
'
*
5
).
encode
())
...
...
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