Commit cf90d102 by John Donnal

added setuptools installation

parent 23e5630c
*~
*.pyc
__pycache__
*egg-info
\ No newline at end of file
This module supports LabJack Data Acquisition Devices
It has been tested with the U3-HV (https://labjack.com/products/u3)
Installation:
(see https://labjack.com/support/software/examples/ud/labjackpython)
The release provided on this page does not support Python3.
1.) Clone the LabJack repository
git clone https://github.com/labjack/LabJackPython.git
2.) Install the package
$> cd LabJackPython
$> sudo python3 setup.py install
3.) Clone the Exodriver package
git clone https://github.com/labjack/exodriver.git
4.) Install dependencies and the package
$> cd exodriver
$> sudo apt-get install libusb-1.0.0-dev build-essential
$> sudo ./install.sh
5.) Confirm packages are installed correctly
$> python3
>>> import u3
--should not be any errors --
<Ctrl-D to exit>
LabJack Documentation:
See: https://labjack.com/support/datasheets/u3/low-level-function-reference
Also from python CLI:
$> python3
>>> import u3
>>> help(u3) # overview of all modules
>>> help(u3.U3) #specific help for U3 commands
[Main]
name = LabJack
exec_cmd = /home/jdonnal/labjack-module/u3_module.py
[Arguments]
rate = 3000
channels = 0,1,2,15
[Inputs]
[Outputs]
output=/ljtest/lj1
[Main]
name=LabJack1
description=U3 data
keep=1w
path=/ljtest/lj1
datatype=float32
decimate=yes
[Element1]
name = AccelX
[Element2]
name = AccelY
[Element3]
name = AccelZ
[Element4]
name = signal
#!/usr/bin/env python
from setuptools import setup, find_packages
PROJECT = 'LabJack Joule Module'
# Change docs/sphinx/conf.py too!
try:
long_description = open('README', 'rt').read()
except IOError:
long_description = ''
setup(
name=PROJECT,
version='0.5', # versioneer.get_version(),
#cmdclass=versioneer.get_cmdclass(),
description='Use the LabJack U3 with Joule',
long_description=long_description,
author='John Donnal',
author_email='donnal@usna.edu',
url='https://git.wattsworth.net/wattsworth/labjack-module.git',
download_url='[none]',
classifiers=['Programming Language :: Python',
'Environment :: Console',
],
platforms=['Any'],
scripts=[],
provides=[],
install_requires=['numpy',
'joule'],
namespace_packages=[],
packages=find_packages(),
include_package_data=True,
entry_points={
'console_scripts': [
'labjack_u3 = u3_module:main',
],
},
zip_safe=False,
)
......@@ -4,8 +4,10 @@ from joule.utils.time import now as time_now
from joule.client import ReaderModule
import asyncio
import numpy as np
import pdb
import u3
import LabJackPython
import time
import traceback
import sys
......@@ -13,59 +15,80 @@ 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
grp = parser.add_argument_group("module",
"module specific arguments")
#--rate
grp.add_argument("--rate", type=float, required=True,
help="sample rate in Hz")
#--channels
grp.add_argument("--channels")
async def run(self, parsed_args, output):
channels = [int(x) for x in parsed_args.channels.split(',')]
rate = parsed_args.rate
data_ts_inc = 1e6 / rate
self.stop_requested = False
# 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):
device = self._setup_u3(channels, parsed_args.rate)
device.streamStart()
for chunk in device.streamData():
if(self.stop_requested):
break
if(chunk is None):
print ("LabJack did not return data, exiting")
break
if(chunk['errors']!=0 or chunk['missed']!=0):
sys.stderr.write("errors: %d, missed: %d\n" % (
r['errors'],r['missed']))
chunk['errors'],chunk['missed']))
(data_ts, block) = self.build_block(r,data_ts)
(data_ts, block) = self.build_block(chunk,data_ts,
data_ts_inc,
channels)
await output.write(block)
await asyncio.sleep(.01)
device.streamStop()
device.close()
except LabJackPython.LabJackException as e:
print("LabJack Error: "+str(e))
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
def build_block(self,r,data_ts,data_ts_inc,channels):
data = [r['AIN%d'%c] for c in channels]
rows = len(data[0])
block = np.empty((rows,len(channels)+1))
top_ts = data_ts + rows * 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
block = np.vstack((ts,*data)).T
return (top_ts, block)
def _setup_u3(self, channels, rate):
device = u3.U3()
device.configU3()
# set all IO channels to analog signals
device.configIO(FIOAnalog=0xFF, EIOAnalog=0xFF)
if __name__ == "__main__":
#single ended measurements
gnd_channels = [31 for x in channels]
device.streamConfig(NumChannels=len(channels),
PChannels=channels,
NChannels=gnd_channels,
ScanFrequency=rate,
SamplesPerPacket=25)
return device
def main():
r = U3Reader()
r.start()
if __name__ == "__main__":
main()
#!/usr/bin/python3
import u3
import pdb
import traceback
def 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