Commit 23e5630c by John Donnal

initial commit

parents
Showing with 100 additions and 0 deletions
*~
*.pyc
__pycache__
#!/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()
#!/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()
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment