Skip to content

Commit

Permalink
Merge pull request #11 from microdaq/1.4.0v
Browse files Browse the repository at this point in the history
### API changes
#### Rename package name and MLink class
- `py_mlink ` package change  to `microdaq`
- `MLink `class name change  to `Device`

New

    import microdaq
    mdaq = microdaq.Device(ip='10.10.1.1')

Old

    from py_mlink import PyMLink
    mdaq = PyMLink.MLink('10.10.1.1')


#### Exceptions
The `MLinkError` exception is throw only as a result of the MLink library call.\
The `ValueError` exception is throw as a result of parameter pre-check before calling MLink library. 

#### Rename parameters

- `pwm_module` -> `module` in pwm_init, pwm_write methods
- `encoder` -> `module` in enc_init, enc_read methods
- `led_id` -> `led` in led_write method

#### Fixes
- Fix missing parameter in `ao_scan_trigger_encoder`

### Other

- Prepare installation script and package structure to be distributed over `pip` manager
- Add more examples
- Add tests for API integration (for contributors). Introduction of pytest
- Update README to me more friendly for new users

### Related issues
Closes #4
Closes #8
  • Loading branch information
witczenko committed Dec 1, 2020
2 parents 7c2cd26 + 3b672c8 commit b69252e
Show file tree
Hide file tree
Showing 58 changed files with 1,651 additions and 1,365 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
__pycache__/
.idea/
.pytest_cache/
.vscode/
assets/
4 changes: 2 additions & 2 deletions LICENSE → LICENSE.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
BSD 3-Clause License
### BSD 3-Clause License

Copyright (c) 2018, Embedded Solutions
Copyright (c) 2018-2020, Embedded Solutions
All rights reserved.

Redistribution and use in source and binary forms, with or without
Expand Down
150 changes: 142 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,150 @@
# PyMLink
# Microdaq

This package allows users to use data acquisition under MicroDAQ hardware with Python2.6/2.7.
It provides an interface between the MLink driver and Python.
The package works with Windows x86/x64, Linux x86/x64, MacOS x64 and EABI ARM machines.
This package allows users to use data acquisition under MicroDAQ hardware
with Python2.7 and Python 3. It provides an interface between the MLink driver
and Python application. The package works with Windows x86/x64, Linux x86/x64, MacOS x64
and EABI ARM machines.

## Installation

To install this package:<br />
1. Open install directory.<br />
2. Run `pip install .` (if Linux/MacOS, admin privileges required)
`pip install microdaq`

If already installed, upgrading could be done by\
`pip install microdaq --upgrade `

## Examples

Sample programs are located in `examples` directory. In order to run them,
connect MicroDAQ device to your computer and run chosen script without any
additional steps. For example: `python exmaples/ai-demo.py`

Scripts from **'examples/complex'** require additional packages to work.\
They could be installed via `pip install -r requirements/examples.txt` command.

<br>

##### LED control example
Turn on and turn off LED 1.

import time
import microdaq

mdaq = microdaq.Device(ip='10.10.1.1')
mdaq.led_write(led=1, state=True)
time.sleep(1.0)
mdaq.led_write(led=1, state=False)

<br>

##### Analog input
Read analog input channels 1 and 2.

import microdaq

mdaq = microdaq.Device(ip='10.10.1.1')
data = mdaq.ai_read(channels=[1, 2], ai_range=[-10, 10])

for i, volt in enumerate(data):
print('Channel[%d]: %f V' % (i, volt))

<br>

##### Continuous data acquisition
Read analog input from channel 1, 100 kHz sampling period for a 0.1 second.
Expected 10 000 samples.

import microdaq

mdaq = microdaq.Device("10.10.1.1")
mdaq.ai_scan_init(
channels=[1],
ai_range=[-10, 10],
is_differential=[False],
rate=100000,
duration=0.1)
data = mdaq.ai_scan(
scan_count=10000,
timeout=True)

for sample in data:
print('%f V' % sample)
<br>

##### Analog output
Set 1.0V and 2.0V to analog output channels 1 and 2 respectively.
Used range 0-5 volts.

import microdaq

mdaq = microdaq.Device(ip='10.10.1.1')
mdaq.ao_write(
channels=[1, 2],
ao_range=microdaq.AORange.AO_5V_UNI,
data=[1.0, 2.0])
<br>

##### PWM
Generate PWM signal on two channels A and B (PWM module 1).\
![PWM](https://user-images.githubusercontent.com/6242229/98869909-bf57b500-2472-11eb-8047-2876c57fb702.png)

import microdaq

mdaq = microdaq.Device(ip='10.10.1.1')
mdaq.pwm_init(module=1, period=1000)
mdaq.pwm_write(module=1, duty_a=25, duty_b=50)

<br>

##### Encoder
Read encoder position.

import time
import microdaq

mdaq = microdaq.Device(ip='10.10.1.1')
mdaq.enc_init(module=1, init_value=0)

for i in range(30):
time.sleep(0.1)
enc = mdaq.enc_read(module=1)
print('position: %d\tdir: %d' % (enc[0], enc[1]))


<br>


##### DSP with Scilab XCOS model
Load and run application generated by MicroDAQ Toolbox for Scilab.\
Toolbox available is here: https://atoms.scilab.org/toolboxes/microdaq/1.2.2

Application overview:\
![signal-model-view](https://user-images.githubusercontent.com/6242229/98870068-02198d00-2473-11eb-9988-56724c48a123.jpg)

import os
import microdaq

mdaq = microdaq.Device(ip='10.10.1.1')

model = os.path.join("resources", "signal-model.out")
mdaq.dsp_init(dsp_application=model, rate=100, duration=-1)
mdaq.dsp_start()

print("DSP is running: %s" % mdaq.dsp_is_done())
mdaq.dsp_stop()
print("DSP is running: %s" % mdaq.dsp_is_done())

<br>

## Tests
This sections is meant to be for package's developers/contributors. Tests for API
layer which does not required connected MicroDAQ device could be triggered by
`pytest tests/test_api.py`.

Additional requirements needed:\
`pip install -r requirements/tests.txt`

## License

The BSD license.
The BSD license. For more information read **LICENSE.md** file.
18 changes: 0 additions & 18 deletions demos/ai-demo.py

This file was deleted.

18 changes: 0 additions & 18 deletions demos/ao-demo.py

This file was deleted.

27 changes: 0 additions & 27 deletions demos/ao-trig.py

This file was deleted.

35 changes: 0 additions & 35 deletions demos/dio-demo.py

This file was deleted.

25 changes: 0 additions & 25 deletions demos/led-demo.py

This file was deleted.

60 changes: 0 additions & 60 deletions demos/scope-fft-demo_py3.py

This file was deleted.

27 changes: 0 additions & 27 deletions demos/utils-demo.py

This file was deleted.

0 comments on commit b69252e

Please sign in to comment.