Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
wattsworth
/
labjack-module
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
23e5630c
authored
Feb 19, 2018
by
John Donnal
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
initial commit
parents
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
100 additions
and
0 deletions
.gitignore
u3_module.py
u3_reader.py
.gitignore
0 → 100644
View file @
23e5630c
*~
*.pyc
__pycache__
u3_module.py
0 → 100755
View file @
23e5630c
#!/usr/bin/python3
from
joule.utils.time
import
now
as
time_now
from
joule.client
import
ReaderModule
import
asyncio
import
numpy
as
np
import
u3
import
time
import
traceback
import
sys
class
U3Reader
(
ReaderModule
):
"Read data from U3 LabJack"
def
__init__
(
self
):
super
(
U3Reader
,
self
)
.
__init__
(
"LabJack U3 Reader"
)
self
.
description
=
"collect data from a U3 device"
self
.
help
=
"collects 3 channels @ 5KHz"
self
.
data_ts_inc
=
1e6
/
5000.0
# 5KHz sampling
self
.
stop_requested
=
False
# configure U3
self
.
device
=
u3
.
U3
()
self
.
device
.
configU3
()
self
.
device
.
streamConfig
(
NumChannels
=
3
,
PChannels
=
[
0
,
1
,
2
],
NChannels
=
[
31
,
31
,
31
],
ScanFrequency
=
5000
,
SamplesPerPacket
=
25
)
#secs_per_req = (25*self.device.packetsPerRequest/3.0)/5000.0
#self.sleep_time = 0.75*secs.per_req
def
custom_args
(
self
,
parser
):
pass
async
def
run
(
self
,
parsed_args
,
output
):
# set up timestamps
data_ts
=
int
(
time
.
time
()
*
1e6
)
try
:
self
.
device
.
streamStart
()
while
(
not
self
.
stop_requested
):
r
=
next
(
self
.
device
.
streamData
())
if
(
r
[
'errors'
]
!=
0
or
r
[
'missed'
]
!=
0
):
sys
.
stderr
.
write
(
"errors:
%
d, missed:
%
d
\n
"
%
(
r
[
'errors'
],
r
[
'missed'
]))
(
data_ts
,
block
)
=
self
.
build_block
(
r
,
data_ts
)
await
output
.
write
(
block
)
except
:
print
(
""
.
join
(
i
for
i
in
traceback
.
format_exc
()))
finally
:
self
.
device
.
streamStop
()
self
.
device
.
close
()
def
build_block
(
self
,
r
,
data_ts
):
rows
=
len
(
r
[
'AIN0'
])
block
=
np
.
empty
((
rows
,
4
))
top_ts
=
data_ts
+
rows
*
self
.
data_ts_inc
ts
=
np
.
array
(
np
.
linspace
(
data_ts
,
top_ts
,
rows
,
endpoint
=
False
),
dtype
=
np
.
uint64
)
block
=
np
.
vstack
((
ts
,
r
[
'AIN0'
],
r
[
'AIN1'
],
r
[
'AIN2'
]))
.
T
return
(
top_ts
,
block
)
if
__name__
==
"__main__"
:
r
=
U3Reader
()
r
.
start
()
u3_reader.py
0 → 100755
View file @
23e5630c
#!/usr/bin/python3
import
u3
import
pdb
import
traceback
def
main
():
d
=
u3
.
U3
()
d
.
configU3
()
d
.
streamConfig
(
NumChannels
=
3
,
PChannels
=
[
0
,
1
,
2
],
NChannels
=
[
31
,
31
,
31
],
ScanFrequency
=
5000
)
try
:
d
.
streamStart
()
for
r
in
d
.
streamData
():
for
x
in
r
[
"AIN0"
]:
print
(
x
)
except
:
print
(
""
.
join
(
i
for
i
in
traceback
.
format_exc
()))
finally
:
d
.
streamStop
()
d
.
close
()
if
__name__
==
"__main__"
:
main
()
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment