-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from microdaq/dev
PyMLink 1.1v
- Loading branch information
Showing
10 changed files
with
449 additions
and
297 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,18 @@ | ||
# Analog inputs demo | ||
# Analog input demo | ||
# visit site www.microdaq.org | ||
# author Witczenko | ||
# email witczenko@gmail.com | ||
# Embedded-solutions, November 2017 | ||
|
||
from py_mlink import PyMLink | ||
|
||
try: | ||
# Create MLink object, connect to MicroDAQ device | ||
pml = PyMLink.MLink('10.10.1.1') | ||
# Create MLink object, connect to MicroDAQ device | ||
mdaq = PyMLink.MLink('10.10.1.1') | ||
|
||
# Choose channels to read eg. 1..8 | ||
channels = [ch for ch in range(1, 9)] | ||
# Read data from channels 1..4, input range from -10V to 10V, single ended | ||
data = mdaq.ai_read([1, 2, 3, 4], [-10, 10], False) | ||
|
||
# Read data | ||
data = pml.ai_read(channels) | ||
# Print data | ||
for i, volt in enumerate(data): | ||
print 'Channel[%d]: %f V' % (i, volt) | ||
|
||
# Print data | ||
i = 0 | ||
for ch in channels: | ||
print 'Channel[%d]: %f V' % (ch, data[i]) | ||
i += 1 | ||
|
||
except PyMLink.MLinkError, errval: | ||
print "Error:", errval | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,18 @@ | ||
# Analog outputs demo | ||
# Analog output demo | ||
# visit site www.microdaq.org | ||
# author Witczenko | ||
# email witczenko@gmail.com | ||
# Embedded-solutions, November 2017 | ||
|
||
from py_mlink import PyMLink | ||
|
||
try: | ||
# Create MLink object, connect to MicroDAQ device | ||
pml = PyMLink.MLink('10.10.1.1') | ||
# Create MLink object, connect to MicroDAQ device | ||
mdaq = PyMLink.MLink('10.10.1.1') | ||
|
||
# Choose channels to write eg. 1..4 | ||
channels = [ch for ch in range(1, 5)] | ||
# Set values | ||
channels_voltage = [0.5, 1, 1.5, 2] | ||
# Choose channels to write eg. 1..4 | ||
ch = [1, 2, 3, 4] | ||
# Set values | ||
ch_voltage = [0.5, 1, 1.5, 2] | ||
|
||
# Set analog outputs | ||
pml.ao_write(channels, channels_voltage) | ||
# Set analog outputs, output range from 0V to 5V | ||
mdaq.ao_write(ch, [0, 5], ch_voltage) | ||
|
||
except PyMLink.MLinkError, errval: | ||
print "Error:", errval | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,29 @@ | ||
# Digital I/O demo | ||
# visit site www.microdaq.org | ||
# author Witczenko | ||
# email witczenko@gmail.com | ||
# Embedded-solutions, November 2017 | ||
|
||
from py_mlink import PyMLink | ||
|
||
try: | ||
# Create MLink object, connect to MicroDAQ device | ||
pml = PyMLink.MLink('10.10.1.1') | ||
|
||
# Configure Digital I/O | ||
# Disable all functions: encoder, pwm, uart | ||
for i in range(1, 7): | ||
pml.dio_func(i, False) | ||
|
||
# Set first 8 I/O to input mode | ||
pml.dio_dir(1, False) | ||
# Set next 8 I/O to output mode | ||
pml.dio_dir(2, True) | ||
|
||
# Choose channels to read eg. 1..8 | ||
channels_in = [ch for ch in range(1, 9)] | ||
# Choose channels to write eg. 9..16 | ||
channels_out = [ch for ch in range(9, 17)] | ||
channels_out_data = [True for state in range(8)] | ||
|
||
# Read data | ||
data_in = pml.dio_read(channels_in) | ||
# Set data | ||
pml.dio_write(channels_out, channels_out_data) | ||
|
||
# Print data | ||
i = 0 | ||
for ch in channels_in: | ||
print 'DI[%d]: %d' % (ch, data_in[i]) | ||
i += 1 | ||
|
||
except PyMLink.MLinkError, errval: | ||
print "Error:", errval | ||
# Create MLink object, connect to MicroDAQ device | ||
mdaq = PyMLink.MLink('10.10.1.2') | ||
|
||
# Configure Digital I/O, disable all functions: encoder, pwm, uart | ||
for i in range(1, 7): | ||
mdaq.dio_func(i, False) | ||
|
||
# Choose channels to be digital input | ||
DI = [1, 2, 3, 4, 5, 6, 7, 8] | ||
|
||
# Choose channels to be digital output | ||
DO = [9, 10, 11, 12, 13, 14, 15, 16] | ||
DO_state = [True for state in range(8)] | ||
|
||
# Read DI states | ||
di_state = mdaq.dio_read(DI) | ||
# Set DO states | ||
mdaq.dio_write(DO, DO_state) | ||
|
||
# Print data | ||
for i, di in enumerate(di_state): | ||
print 'DI[%d]: %d' % (i, di) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,24 @@ | ||
# LED demo | ||
# visit site www.microdaq.org | ||
# author Witczenko | ||
# email witczenko@gmail.com | ||
# Embedded-solutions, November 2017 | ||
|
||
from py_mlink import PyMLink | ||
import time | ||
|
||
try: | ||
# Create MLink object, connect to MicroDAQ device | ||
pml = PyMLink.MLink('10.10.1.1') | ||
# Create MLink object, connect to MicroDAQ device | ||
mdaq = PyMLink.MLink('10.10.1.1') | ||
|
||
# turn on LED 1 | ||
pml.led_write(1, True) | ||
# turn on LED 2 | ||
pml.led_write(2, True) | ||
# turn on LED 1 | ||
mdaq.led_write(1, True) | ||
# turn on LED 2 | ||
mdaq.led_write(2, True) | ||
|
||
# wait a second | ||
time.sleep(1.0) | ||
# wait a second | ||
time.sleep(1.0) | ||
|
||
# turn off LED 1 | ||
pml.led_write(1, False) | ||
# turn off LED 2 | ||
pml.led_write(2, False) | ||
# turn off LED 1 | ||
mdaq.led_write(1, False) | ||
# turn off LED 2 | ||
mdaq.led_write(2, False) | ||
|
||
except PyMLink.MLinkError, errval: | ||
print "Error:", errval | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# Utils demo | ||
# visit site www.microdaq.org | ||
# Embedded-solutions, November 2017 | ||
|
||
from py_mlink import PyMLink | ||
|
||
# Print documentation e.g: | ||
print PyMLink.MLink.__doc__ | ||
print PyMLink.MLink.ai_scan_init.__doc__ | ||
|
||
# Connect to MicroDAQ device without worrying about connection timeout (maintain_connection=True) | ||
# this option has slightly less performance | ||
mdaq = PyMLink.MLink('10.10.1.1', maintain_connection=True) | ||
|
||
# Print model name of connected MicroDAQ device | ||
mdaq.hw_info() | ||
|
||
# Catch MLink errors | ||
try: | ||
mdaq.ai_read(99, [-10, 10], False) | ||
except PyMLink.MLinkError, errval: | ||
print "Error:", errval | ||
|
||
# Close connection | ||
mdaq.disconnect() | ||
|
Oops, something went wrong.