Commit 58052a8c authored by Kuldeep Singh Dhaka's avatar Kuldeep Singh Dhaka

Changes for libbox0 v0.3.0

TODO: Check all example and generate appropriate outputs
parent ad5e30b7
......@@ -32,12 +32,18 @@
"# open DIO (digital Input/Output) module\n",
"dio = Box0.dio(dev)\n",
"\n",
"# Prepare for basic operations (read, write, toggle etc..)\n",
"Box0.basic_prepare(dio)\n",
"\n",
"# initalize the pin\n",
"pin0 = Box0.pin(dio, 0)\n",
"Box0.output(pin0)\n",
"Box0.low(pin0)\n",
"Box0.enable(pin0)\n",
"\n",
"# Start basic mode (things will come into effect)\n",
"Box0.basic_start(dio)\n",
"\n",
"#TODO: catch SIGINT (InterruptException)\n",
"# not working: http://stackoverflow.com/questions/20831290\n",
"# if not caught, module is not closed, it will require kernel restart\n",
......@@ -46,6 +52,9 @@
" sleep(.5)\n",
"end\n",
"\n",
"# Stop in basic mode\n",
"Box0.basic_stop(dio)\n",
"\n",
"Box0.close(dio)\n",
"Box0.close(dev)"
]
......
......@@ -1927,12 +1927,12 @@
"aout0 = Box0.aout(dev)\n",
"\n",
"# prepare AIN0\n",
"Box0.static_prepare(ain0)\n",
"Box0.set(Box0.chan_seq(ain0), Array{UInt8}([0, 1]))\n",
"Box0.set(Box0.speed(ain0), 100000)\n",
"Box0.snapshot_prepare(ain0)\n",
"Box0.chan_seq_set(ain0, Array{Cuint}([0, 1]))\n",
"Box0.bitsize_speed_set(ain0, Cuint(12), Culong(100000))\n",
"\n",
"# prepare AOUT0\n",
"Box0.static_prepare(aout0)\n",
"Box0.snapshot_prepare(aout0)\n",
"\n",
"# generate voltage, read voltage, calculate current and store the result\n",
"# AIN0.CH0 = AOUT0.CH0 = generated signal\n",
......@@ -1948,16 +1948,16 @@
"\n",
"for i in range(1, SAMPLES)\n",
" if aout0_running\n",
" Box0.static_stop(aout0)\n",
" Box0.snapshot_stop(aout0)\n",
" end\n",
" \n",
" # output \"v\" value on AOUT0.CH0\n",
" Box0.static_start(aout0, Array(voltages[i:i]))\n",
" Box0.snapshot_start(aout0, Array(voltages[i:i]))\n",
" aout0_running = true\n",
" \n",
" # read back AIN.CH0 and AIN0.CH1\n",
" readed_data = Array{Float32}(SAMPLES)\n",
" Box0.static_start(ain0, readed_data)\n",
" Box0.snapshot_start(ain0, readed_data)\n",
" \n",
" # do the calculation\n",
" ch0 = mean(readed_data[1:2:length(readed_data)])\n",
......@@ -1971,7 +1971,7 @@
"\n",
"# stop if AOUT0 running\n",
"if aout0_running\n",
" Box0.static_stop(aout0)\n",
" Box0.snapshot_stop(aout0)\n",
"end\n",
"\n",
"# close the resources\n",
......
......@@ -38,7 +38,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.5.1"
"version": "3.5.2"
}
},
"nbformat": 4,
......
......@@ -145,7 +145,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.5.1"
"version": "3.5.2"
}
},
"nbformat": 4,
......
......@@ -91,7 +91,7 @@
"\"use strict\";\n",
"\n",
"var express = require('express')\n",
"var box0 = require('box0')\n",
"var box0 = require('../lib/box0')\n",
"var util = require('util')\n",
"\n",
"var dev = box0.usb.open_supported()\n",
......@@ -127,14 +127,14 @@
"\n",
" res.json({\n",
" name: dio0.header.name,\n",
" count: dio0.count.value,\n",
" count: dio0.pin_count,\n",
" ref: {low, high}\n",
" })\n",
"})\n",
"\n",
"app.param('pin', function(req, res, next, pin) {\n",
" var pin_value = parseInt(pin)\n",
" if (pin_value >= 0 && pin_value < dio0.count.value) {\n",
" if (pin_value >= 0 && pin_value < dio0.pin_count) {\n",
" req.pin = pin_value\n",
" next()\n",
" return\n",
......@@ -146,8 +146,10 @@
"app.get('/dio/0/:pin', function (req, res) {\n",
" handle_exception(res, function () {\n",
" var pin = req.pin\n",
" var name = (pin < dio0.label.values.length) ?\n",
" dio0.label.values[pin] : 'CH' + pin\n",
" var name = dio0.label.pin[pin]\n",
" if (name == null) {\n",
" name = 'CH' + pin\n",
" }\n",
"\n",
" var value = dio0.value_get(pin)\n",
" var dir = dio0.dir_get(pin)\n",
......@@ -246,10 +248,13 @@
"\n",
"app.listen(3000, function () {\n",
" console.log('Listening on port 3000!')\n",
" dio0.basic_prepare()\n",
" dio0.basic_start()\n",
"})\n",
"\n",
"process.on('SIGINT', function() {\n",
" console.log(\"\\nGracefully shutting down from SIGINT (Ctrl+C)\")\n",
" dio0.basic_stop()\n",
" dio0.close()\n",
" dev.close()\n",
" process.exit(1)\n",
......
......@@ -143,7 +143,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.5.1"
"version": "3.5.2"
}
},
"nbformat": 4,
......
......@@ -33,12 +33,16 @@
"# open DIO (digital Input/Output) module\n",
"dio = dev.dio()\n",
"\n",
"dio.basic_prepare()\n",
"\n",
"# initalize the pin\n",
"pin0 = dio.pin(0)\n",
"pin0.output()\n",
"pin0.low()\n",
"pin0.enable()\n",
"\n",
"dio.basic_start()\n",
"\n",
"try:\n",
" # perform a loop and toggle the pin 2 times per second\n",
" while True:\n",
......@@ -48,6 +52,8 @@
" # user want to exit\n",
" pass\n",
"\n",
"dio.basic_close()\n",
"\n",
"# close the resources\n",
"dio.close()\n",
"dev.close()"
......@@ -70,7 +76,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.5.1"
"version": "3.5.2"
}
},
"nbformat": 4,
......
......@@ -72,16 +72,12 @@
"#\n",
"\n",
"import box0\n",
"import box0.misc.box0v5.ps as ps\n",
"\n",
"# python2 raw_input and python3 input\n",
"try: input = raw_input\n",
"except: pass\n",
"\n",
"box0_dev = box0.usb.open_supported()\n",
"\n",
"# extract libusb device handle since box0v5.ps API require it\n",
"dev = box0.usb.libusb_device_handle(box0_dev)\n",
"dev = box0.usb.open_supported()\n",
"\n",
"print(\"Welcome! please enter a command:\")\n",
"print(\" b - [both] digital supply enable and analog supply enable\")\n",
......@@ -92,23 +88,23 @@
"print(\" e - [exit] exit the program\")\n",
"\n",
"#turn both supply off\n",
"ps.en_set(dev, ps.ANALOG | ps.DIGITAL, 0)\n",
"dev.ps_en_set(dev.PS_ANALOG | dev.PS_DIGITAL, 0)\n",
"\n",
"try:\n",
" while True:\n",
" c = input(\"> \")\n",
" if c == \"b\":\n",
" ps.en_set(dev, ps.ANALOG | ps.DIGITAL, ps.ANALOG | ps.DIGITAL)\n",
" dev.ps_en_set(dev.PS_ANALOG | dev.PS_DIGITAL, dev.PS_ANALOG | dev.PS_DIGITAL)\n",
" elif c == \"a\":\n",
" ps.en_set(dev, ps.ANALOG, ps.ANALOG)\n",
" dev.ps_en_set(dev.PS_ANALOG, dev.PS_ANALOG)\n",
" elif c == \"d\":\n",
" ps.en_set(dev, ps.DIGITAL, ps.DIGITAL)\n",
" dev.ps_en_set(dev.PS_DIGITAL, dev.PS_DIGITAL)\n",
" elif c == \"n\":\n",
" ps.en_set(dev, ps.ANALOG | ps.DIGITAL, 0)\n",
" dev.ps_en_set(dev.PS_ANALOG | dev.PS_DIGITAL, 0)\n",
" elif c == \"s\":\n",
" mask = ps.en_get(dev)\n",
" print(\"Analog: \" + (\"Enabled\" if mask & ps.ANALOG else \"Disabled\"))\n",
" print(\"Digital: \" + (\"Enabled\" if mask & ps.DIGITAL else \"Disabled\"))\n",
" mask = dev.ps_en_get()\n",
" print(\"Analog: \" + (\"Enabled\" if mask & dev.PS_ANALOG else \"Disabled\"))\n",
" print(\"Digital: \" + (\"Enabled\" if mask & dev.PS_DIGITAL else \"Disabled\"))\n",
" elif c == \"e\":\n",
" break;\n",
" else:\n",
......@@ -116,11 +112,10 @@
"except KeyboardInterrupt: pass\n",
"\n",
"#turn all supply off\n",
"ps.en_set(dev, ps.ANALOG | ps.DIGITAL, 0)\n",
"dev.ps_en_set(dev.PS_ANALOG | dev.PS_DIGITAL, 0)\n",
"\n",
"#close device\n",
"dev = None\n",
"del box0_dev"
"del dev"
]
},
{
......@@ -133,18 +128,18 @@
"\n",
"| Name | Value |\n",
"|---------------------|\n",
"|PS_EN_GET | 0x01 |\n",
"|PS_EN_SET | 0x02 |\n",
"|PS_OC_GET | 0x03 |\n",
"|PS_OC_ACK | 0x04 |\n",
"|PS_EN_GET | 201 |\n",
"|PS_EN_SET | 202 |\n",
"|PS_OC_GET | 203 |\n",
"|PS_OC_ACK | 204 |\n",
"\n",
"\n",
"## Read enable value\n",
"| bmRequestType | Host ← Device, Device, Vendor |\n",
"|---------------|---------------------------------|\n",
"| bRequest | 0xFF |\n",
"| bRequest | PS_EN_GET |\n",
"| wValue | 0x0000 |\n",
"| wIndex | HIGH8(0) LOW8(PS_EN_GET) |\n",
"| wIndex | 0x0000 |\n",
"| wLength | 0x0001 |\n",
"| Data | BIT0 = Analog, BIT1 = Digital |\n",
"\n",
......@@ -155,9 +150,9 @@
"\n",
"| bmRequestType | Host → Device, Device, Vendor |\n",
"|---------------|-------------------------------|\n",
"| bRequest | 0xFF |\n",
"| bRequest | PS_EN_SET |\n",
"| wValue | HIGH8(mask) LOW8(value) |\n",
"| wIndex | HIGH8(0) LOW8(PS_EN_SET) |\n",
"| wIndex | 0x0000 |\n",
"| wLength | 0x0000 |\n",
"| Data | None |\n",
"\n",
......@@ -168,9 +163,9 @@
"\n",
"| bmRequestType | Host ← Device, Device, Vendor |\n",
"|---------------|---------------------------------|\n",
"| bRequest | 0xFF |\n",
"| bRequest | PS_OC_GET |\n",
"| wValue | 0x0000 |\n",
"| wIndex | HIGH8(0) LOW8(PS_OC_GET) |\n",
"| wIndex | 0x0000 |\n",
"| wLength | 0x0001 |\n",
"| Data | BIT0 = Analog, BIT1 = Digital |\n",
"\n",
......@@ -181,9 +176,9 @@
"\n",
"| bmRequestType | Host → Device, Device, Vendor |\n",
"|---------------|-------------------------------|\n",
"| bRequest | 0xFF |\n",
"| bRequest | PS_OC_ACK |\n",
"| wValue | HIGH8(0) LOW8(value) |\n",
"| wIndex | HIGH8(0) LOW8(PS_OC_ACK) |\n",
"| wIndex | 0x0000 |\n",
"| wLength | 0x0000 |\n",
"| Data | None |\n",
"\n",
......@@ -210,8 +205,8 @@
"import usb.util\n",
"from usb.util import CTRL_IN, CTRL_OUT, CTRL_RECIPIENT_DEVICE, CTRL_TYPE_VENDOR\n",
"\n",
"BOX0V5_PS_EN_GET = 0x01\n",
"BOX0V5_PS_EN_SET = 0x02\n",
"BOX0V5_PS_EN_GET = 201\n",
"BOX0V5_PS_EN_SET = 202\n",
"\n",
"POWER_ANALOG = 0x01\n",
"POWER_DIGITAL = 0x02\n",
......@@ -249,7 +244,7 @@
" if analog: value |= POWER_ANALOG\n",
" if digital: value |= POWER_DIGITAL\n",
" wValue = (mask << 8) | value\n",
" dev.ctrl_transfer(bmReqType, 0xFF, wValue, BOX0V5_PS_EN_SET)\n",
" dev.ctrl_transfer(bmReqType, BOX0V5_PS_EN_SET, wValue)\n",
"\n",
"def power_supply_get(dev):\n",
" \"\"\"\n",
......@@ -258,7 +253,7 @@
" return a tuple (<analog-supply>, <digital-supply>)\n",
" \"\"\"\n",
" bmReqType = CTRL_IN | CTRL_RECIPIENT_DEVICE | CTRL_TYPE_VENDOR\n",
" data = dev.ctrl_transfer(bmReqType, 0xFF, 0, BOX0V5_PS_EN_GET, 1)\n",
" data = dev.ctrl_transfer(bmReqType, BOX0V5_PS_EN_GET, 0, 0, 1)\n",
" analog = (data[0] & POWER_ANALOG) != 0x00\n",
" digital = (data[0] & POWER_DIGITAL) != 0x00\n",
" return analog, digital\n",
......@@ -311,7 +306,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.5.1"
"version": "3.5.2"
}
},
"nbformat": 4,
......
This diff is collapsed.
This diff is collapsed.
......@@ -9,7 +9,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 1,
"metadata": {
"collapsed": true
},
......@@ -20,6 +20,7 @@
"import time\n",
"\n",
"# When 1000 samples are output at 100KS/s, the generate waveform is of 100Hz\n",
"SAMPLE_BITSIZE = 12\n",
"SAMPLE_SPEED = 100000 # 100KS/s\n",
"SAMPLE_COUNT = 1000\n",
"\n",
......@@ -32,9 +33,9 @@
"aout = dev.aout()\n",
"\n",
"# Prepare for static mode\n",
"aout.static_prepare()\n",
"aout.speed.current = SAMPLE_SPEED\n",
"aout.static_start(y)\n",
"aout.snapshot_prepare()\n",
"aout.bitsize_speed_set(SAMPLE_BITSIZE, SAMPLE_SPEED)\n",
"aout.snapshot_start(y)\n",
"\n",
"# wait for the user to ask for exit\n",
"try:\n",
......@@ -44,7 +45,7 @@
" pass\n",
"\n",
"# Return all the resources\n",
"aout.static_stop()\n",
"aout.snapshot_stop()\n",
"aout.close()\n",
"dev.close()"
]
......@@ -82,7 +83,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.5.1"
"version": "3.5.2"
}
},
"nbformat": 4,
......
......@@ -18,7 +18,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 1,
"metadata": {
"collapsed": true
},
......@@ -31,25 +31,27 @@
"dev = box0.usb.open_supported()\n",
"pwm = dev.pwm()\n",
"\n",
"pwm.output_prepare()\n",
"\n",
"# Increment count every 1/1000 second, count upto 250 and toggle when reach at 150\n",
"# effectively giving a 4Hz with 50% duty cycle output on channel 0\n",
"# So, LED will blink 4 per second!\n",
"pwm.speed.current = 1000\n",
"pwm.period = 250\n",
"pwm.width[0] = 125\n",
"pwm.speed_set(1000)\n",
"pwm.period_set(250)\n",
"pwm.width_set(0, 125)\n",
"\n",
"# Start generating!\n",
"pwm.start()\n",
"pwm.output_start()\n",
"\n",
"# Wait till we are not asked to exit\n",
"try:\n",
"\twhile True:\n",
"\t\ttime.sleep(0.1)\n",
" while True:\n",
" time.sleep(0.1)\n",
"except KeyboardInterrupt:\n",
"\tpass\n",
" pass\n",
"\n",
"# give back all the required resources\n",
"pwm.stop()\n",
"pwm.output_stop()\n",
"pwm.close()\n",
"dev.close()\n"
]
......@@ -71,7 +73,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.5.1"
"version": "3.5.2"
}
},
"nbformat": 4,
......
......@@ -53,12 +53,12 @@
"aout0 = dev.aout()\n",
"\n",
"# prepare AIN0\n",
"ain0.static_prepare()\n",
"ain0.chan_seq.current = [0, 1]\n",
"ain0.speed.current = 100000\n",
"ain0.snapshot_prepare()\n",
"ain0.chan_seq_set([0, 1])\n",
"ain0.bitsize_speed_set(12, 100000)\n",
"\n",
"# prepare AOUT0\n",
"aout0.static_prepare()\n",
"aout0.snapshot_prepare()\n",
"\n",
"# generate voltage, read voltage, calculate current and store the result\n",
"# AIN0.CH0 = AOUT0.CH0 = generated signal\n",
......@@ -74,15 +74,15 @@
"\n",
"for i in range(SAMPLES):\n",
" if aout0_running:\n",
" aout0.static_stop()\n",
" aout0.snapshot_stop()\n",
" \n",
" # output \"v\" value on AOUT0.CH0\n",
" aout0.static_start(voltages[i:(i+1)])\n",
" aout0.snapshot_start(voltages[i:(i+1)])\n",
" aout0_running = True\n",
" \n",
" # read back AIN0.CH0 and AIN0.CH1\n",
" readed_data = np.empty(SAMPLES)\n",
" ain0.static_start(readed_data)\n",
" ain0.snapshot_start(readed_data)\n",
" \n",
" # do the calculation\n",
" ch0 = np.mean(readed_data[0::2])\n",
......@@ -95,7 +95,7 @@
"\n",
"# stop if AOUT0 running\n",
"if aout0_running:\n",
" aout0.static_stop()\n",
" aout0.snapshot_stop()\n",
"\n",
"# close the resources\n",
"ain0.close()\n",
......@@ -135,7 +135,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.5.1"
"version": "3.5.2"
}
},
"nbformat": 4,
......
......@@ -806,7 +806,7 @@
}
],
"source": [
"%matplotlib notebook\n",
"#~ %matplotlib notebook\n",
"import box0\n",
"import numpy as np\n",
"import matplotlib.pyplot as plt\n",
......@@ -820,13 +820,11 @@
"\n",
"# prepare resources\n",
"\n",
"ain0.static_prepare()\n",
"ain0.bitsize.current = 12\n",
"ain0.chan_seq.current = [0, 1]\n",
"ain0.snapshot_prepare()\n",
"ain0.chan_seq_set([0, 1])\n",
"\n",
"aout0.static_prepare()\n",
"aout0.bitsize.current = 12\n",
"aout0.chan_seq.current = [0]\n",
"aout0.snapshot_prepare()\n",
"aout0.chan_seq_set([0])\n",
"\n",
"FREQ = range(100, 5000, 100)\n",
"\n",
......@@ -847,11 +845,11 @@
" global aout0\n",
"\n",
" # try to stop aout0 from last run\n",
" try: aout0.static_stop()\n",
" try: aout0.snapshot_stop()\n",
" except: pass\n",
"\n",
" # calculate the actual frequency that can be generated\n",
" count, speed = aout0.static_calc(freq, 12)\n",
" count, speed = aout0.snapshot_calc(freq, 12)\n",
" freq = float(speed) / float(count)\n",
"\n",
" # generate a sine wave\n",
......@@ -859,8 +857,8 @@
" y = np.sin(x) * INPUT_AMPLITUDE\n",
"\n",
" # set the configuration to module\n",
" aout0.speed.current = speed\n",
" aout0.static_start(y)\n",
" aout0.bitsize_speed_set(12, speed)\n",
" aout0.snapshot_start(y)\n",
"\n",
" return freq\n",
"\n",
......@@ -908,9 +906,9 @@
"\n",
" # retrive data\n",
" sampling_freq, sample_count = get_best_speed_and_count(freq)\n",
" ain0.speed.current = sampling_freq\n",
" ain0.bitsize_speed_set(12, sampling_freq)\n",
" data = np.empty(sample_count)\n",
" ain0.static_start(data)\n",
" ain0.snapshot_start(data)\n",
"\n",
" # process the data\n",
" t = np.linspace(0.0, float(sample_count) / sampling_freq, sample_count, endpoint=False)\n",
......@@ -985,7 +983,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.5.1"
"version": "3.5.2"
}
},
"nbformat": 4,
......
......@@ -17,7 +17,7 @@
},
{
"cell_type": "code",
"execution_count": 3,
"execution_count": 1,
"metadata": {
"collapsed": false
},
......@@ -26,23 +26,23 @@
"name": "stdout",
"output_type": "stream",
"text": [
"[ 0.05800781 0.05961914 0.0628418 0.0628418 0.05800781 0.05478516\n",
" 0.05317383 0.05639648 0.05800781 0.05639648 0.0515625 0.04995117\n",
" 0.04833984 0.04511719 0.03383789 0.02900391 0.00966797 0.01289062\n",
" 0.01450195 0.00644531 0.00966797 0.0112793 0.01289062 0.01450195\n",
" 0.01289062 0.00805664 0.00805664 0.00644531 -0.01450195 -0.01450195\n",
" -0.01772461 -0.03706055 -0.03222656 -0.02900391 -0.03706055 -0.03222656\n",
" -0.03061523 -0.03383789 -0.03222656 -0.03222656 -0.03544922 -0.03544922\n",
" -0.03544922 -0.03383789 -0.03222656 -0.02900391 -0.02739258 -0.02739258\n",
" -0.02416992 -0.02255859 -0.02255859 -0.02255859 -0.02255859 -0.02255859\n",
" -0.02094727 -0.02094727 -0.01933594 -0.01772461 -0.01450195 -0.01289062\n",
" -0.01289062 -0.01289062 -0.01289062 -0.01450195 -0.01289062 -0.01450195\n",
" -0.01611328 -0.01289062 -0.01450195 -0.0112793 -0.0112793 -0.0112793\n",
" -0.00966797 -0.00805664 -0.00805664 -0.00805664 -0.00644531 -0.00966797\n",
" -0.00483398 -0.00161133 -0.00644531 -0.00644531 -0.00483398 0.00161133\n",
" 0.00161133 -0.00161133 -0.00322266 0. 0.00483398 0.00483398\n",
" 0.00161133 0. 0.00483398 0.00805664 0.00805664 0.00483398\n",
" 0.00322266 0.00644531 0.0112793 0.0112793 ]\n"
"[ 0.0112793 0.0112793 0.0112793 0.0112793 0.0112793 0.0112793\n",
" 0.0112793 0.0112793 0.01289062 0.0112793 0.0112793 0.0112793\n",
" 0.0112793 0.0112793 0.0112793 0.0112793 0.0112793 0.0112793\n",
" 0.0112793 0.0112793 0.0112793 0.01289062 0.0112793 0.0112793\n",
" 0.0112793 0.0112793 0.0112793 0.0112793 0.01289062 0.0112793\n",
" 0.0112793 0.0112793 0.01289062 0.0112793 0.0112793 0.01289062\n",
" 0.0112793 0.0112793 0.0112793 0.0112793 0.0112793 0.0112793\n",
" 0.0112793 0.0112793 0.0112793 0.0112793 0.0112793 0.0112793\n",
" 0.0112793 0.0112793 0.0112793 0.0112793 0.0112793 0.0112793\n",
" 0.0112793 0.0112793 0.0112793 0.0112793 0.0112793 0.0112793\n",
" 0.0112793 0.0112793 0.0112793 0.0112793 0.0112793 0.0112793\n",
" 0.0112793 0.0112793 0.0112793 0.0112793 0.0112793 0.0112793\n",
" 0.0112793 0.0112793 0.0112793 0.0112793 0.0112793 0.0112793\n",
" 0.0112793 0.0112793 0.0112793 0.0112793 0.0112793 0.0112793\n",
" 0.0112793 0.0112793 0.0112793 0.0112793 0.0112793 0.0112793\n",
" 0.0112793 0.0112793 0.0112793 0.0112793 0.0112793 0.0112793\n",
" 0.0112793 0.0112793 0.0112793 0.0112793 ]\n"
]
}
],
......@@ -54,22 +54,19 @@
"\n",
"ain = dev.ain()\n",
"\n",
"# We will read data in static mode\n",
"# static mode: A snapshot of the signal is captured\n",
"ain.static_prepare()\n",
"# We will read data in snapshot mode\n",
"# snapshot mode: A snapshot of the signal is captured\n",
"ain.snapshot_prepare()\n",
"\n",
"# Set the current speed (10KS/S)\n",
"ain.speed.current = 10000\n",
"\n",
"# Set the current resoultion (12bit)\n",
"ain.bitsize.current = 12\n",
"# Set the current speed (10KS/S) and resolution (12bit)\n",
"ain.bitsize_speed_set(12, 10000)\n",
"\n",
"# Capture data from Channels [Channel Sequence] = (0)\n",
"ain.chan_seq.current = [0]\n",
"ain.chan_seq_set([0])\n",
"\n",
"# Capture 100 samples\n",
"data = np.empty(100, dtype=np.float64)\n",
"ain.static_start(data)\n",
"ain.snapshot_start(data)\n",
"\n",
"# print the captured data \\o/\n",
"print(data)\n",
......@@ -96,7 +93,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.5.1"
"version": "3.5.2"
}
},
"nbformat": 4,
......
......@@ -66,6 +66,7 @@
"\n",
"dev = box0.usb.open_supported()\n",
"i2c = dev.i2c()\n",
"i2c.master_prepare()\n",
"drv = Mcp342x(i2c, Mcp342x.FLOAT, Mcp342x.FLOAT) # Adr0 and Adr1 lines are is Floating\n",
"\n",
"# read data\n",
......@@ -103,7 +104,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.5.1"
"version": "3.5.2"
}
},
"nbformat": 4,
......
......@@ -57,12 +57,12 @@
"aout0 = dev.aout()\n",
"\n",
"# prepare AIN0\n",
"ain0.static_prepare()\n",
"ain0.chan_seq.current = [0, 1, 2, 3]\n",
"ain0.speed.current = 100000\n",
"ain0.snapshot_prepare()\n",
"ain0.chan_seq_set([0, 1, 2, 3])\n",
"ain0.bitsize_speed_set(12, 100000)\n",
"\n",
"# prepare AOUT0\n",
"aout0.static_prepare()\n",
"aout0.snapshot_prepare()\n",
"\n",
"# generate voltage, read voltage, calculate current and store the result\n",
"# AIN0.CH0 = Voltage across Red led\n",
......@@ -90,15 +90,15 @@
"\n",
"for i in range(SAMPLES):\n",
" if aout0_running:\n",
" aout0.static_stop()\n",
" aout0.snapshot_stop()\n",
" \n",
" # output \"v\" value on AOUT0.CH0\n",
" aout0.static_start(voltages[i:(i+1)])\n",
" aout0.snapshot_start(voltages[i:(i+1)])\n",
" aout0_running = True\n",
" \n",
" # read back AIN0.CH0 and AIN0.CH1\n",
" readed_data = np.empty(1000)\n",
" ain0.static_start(readed_data)\n",
" ain0.snapshot_start(readed_data)\n",
" \n",
" # do the calculation\n",
" ch0 = np.mean(readed_data[0::4])\n",
......@@ -116,7 +116,7 @@
" \n",
"# stop if AOUT0 running\n",
"if aout0_running:\n",
" aout0.static_stop()\n",
" aout0.snapshot_stop()\n",
"\n",
"# close the resources\n",
"ain0.close()\n",
......@@ -161,7 +161,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.5.1"
"version": "3.5.2"
}
},
"nbformat": 4,
......
......@@ -826,33 +826,31 @@
"\n",
"# prepare the resources\n",
"\n",
"ain0.static_prepare()\n",
"ain0.chan_seq.current = [0, 1, 2, 3]\n",
"ain0.speed.current = 100000 # 100KSPS\n",
"ain0.bitsize.current = 12\n",
"ain0.snapshot_prepare()\n",
"ain0.chan_seq_set([0, 1, 2, 3])\n",
"ain0.bitsize_speed_set(12, 100000) # 100KSPS\n",
"\n",
"aout0.static_prepare()\n",
"aout0.chan_seq.current = [0, 1]\n",
"aout0.speed.current = 100000 # 100KSPS\n",
"aout0.bitsize.current = 12\n",
"aout0.snapshot_prepare()\n",
"aout0.chan_seq_set([0, 1])\n",
"aout0.bitsize_speed_set(12, 100000) # 100KSPS\n",
"\n",
"def set_voltage(ch0, ch1):\n",
" \"\"\"Set voltage on AOUT0 pin\"\"\"\n",
" global aout0\n",
"\n",
" # try to stop aout0 (from previous start)\n",
" try: aout0.static_stop()\n",
" try: aout0.snapshot_stop()\n",
" except: pass\n",
"\n",
" data = np.array([ch0, ch1])\n",
" aout0.static_start(data)\n",
" aout0.snapshot_start(data)\n",