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 @@ ...@@ -32,12 +32,18 @@
"# open DIO (digital Input/Output) module\n", "# open DIO (digital Input/Output) module\n",
"dio = Box0.dio(dev)\n", "dio = Box0.dio(dev)\n",
"\n", "\n",
"# Prepare for basic operations (read, write, toggle etc..)\n",
"Box0.basic_prepare(dio)\n",
"\n",
"# initalize the pin\n", "# initalize the pin\n",
"pin0 = Box0.pin(dio, 0)\n", "pin0 = Box0.pin(dio, 0)\n",
"Box0.output(pin0)\n", "Box0.output(pin0)\n",
"Box0.low(pin0)\n", "Box0.low(pin0)\n",
"Box0.enable(pin0)\n", "Box0.enable(pin0)\n",
"\n", "\n",
"# Start basic mode (things will come into effect)\n",
"Box0.basic_start(dio)\n",
"\n",
"#TODO: catch SIGINT (InterruptException)\n", "#TODO: catch SIGINT (InterruptException)\n",
"# not working: http://stackoverflow.com/questions/20831290\n", "# not working: http://stackoverflow.com/questions/20831290\n",
"# if not caught, module is not closed, it will require kernel restart\n", "# if not caught, module is not closed, it will require kernel restart\n",
...@@ -46,6 +52,9 @@ ...@@ -46,6 +52,9 @@
" sleep(.5)\n", " sleep(.5)\n",
"end\n", "end\n",
"\n", "\n",
"# Stop in basic mode\n",
"Box0.basic_stop(dio)\n",
"\n",
"Box0.close(dio)\n", "Box0.close(dio)\n",
"Box0.close(dev)" "Box0.close(dev)"
] ]
......
...@@ -1927,12 +1927,12 @@ ...@@ -1927,12 +1927,12 @@
"aout0 = Box0.aout(dev)\n", "aout0 = Box0.aout(dev)\n",
"\n", "\n",
"# prepare AIN0\n", "# prepare AIN0\n",
"Box0.static_prepare(ain0)\n", "Box0.snapshot_prepare(ain0)\n",
"Box0.set(Box0.chan_seq(ain0), Array{UInt8}([0, 1]))\n", "Box0.chan_seq_set(ain0, Array{Cuint}([0, 1]))\n",
"Box0.set(Box0.speed(ain0), 100000)\n", "Box0.bitsize_speed_set(ain0, Cuint(12), Culong(100000))\n",
"\n", "\n",
"# prepare AOUT0\n", "# prepare AOUT0\n",
"Box0.static_prepare(aout0)\n", "Box0.snapshot_prepare(aout0)\n",
"\n", "\n",
"# generate voltage, read voltage, calculate current and store the result\n", "# generate voltage, read voltage, calculate current and store the result\n",
"# AIN0.CH0 = AOUT0.CH0 = generated signal\n", "# AIN0.CH0 = AOUT0.CH0 = generated signal\n",
...@@ -1948,16 +1948,16 @@ ...@@ -1948,16 +1948,16 @@
"\n", "\n",
"for i in range(1, SAMPLES)\n", "for i in range(1, SAMPLES)\n",
" if aout0_running\n", " if aout0_running\n",
" Box0.static_stop(aout0)\n", " Box0.snapshot_stop(aout0)\n",
" end\n", " end\n",
" \n", " \n",
" # output \"v\" value on AOUT0.CH0\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", " aout0_running = true\n",
" \n", " \n",
" # read back AIN.CH0 and AIN0.CH1\n", " # read back AIN.CH0 and AIN0.CH1\n",
" readed_data = Array{Float32}(SAMPLES)\n", " readed_data = Array{Float32}(SAMPLES)\n",
" Box0.static_start(ain0, readed_data)\n", " Box0.snapshot_start(ain0, readed_data)\n",
" \n", " \n",
" # do the calculation\n", " # do the calculation\n",
" ch0 = mean(readed_data[1:2:length(readed_data)])\n", " ch0 = mean(readed_data[1:2:length(readed_data)])\n",
...@@ -1971,7 +1971,7 @@ ...@@ -1971,7 +1971,7 @@
"\n", "\n",
"# stop if AOUT0 running\n", "# stop if AOUT0 running\n",
"if aout0_running\n", "if aout0_running\n",
" Box0.static_stop(aout0)\n", " Box0.snapshot_stop(aout0)\n",
"end\n", "end\n",
"\n", "\n",
"# close the resources\n", "# close the resources\n",
......
...@@ -38,7 +38,7 @@ ...@@ -38,7 +38,7 @@
"name": "python", "name": "python",
"nbconvert_exporter": "python", "nbconvert_exporter": "python",
"pygments_lexer": "ipython3", "pygments_lexer": "ipython3",
"version": "3.5.1" "version": "3.5.2"
} }
}, },
"nbformat": 4, "nbformat": 4,
......
...@@ -145,7 +145,7 @@ ...@@ -145,7 +145,7 @@
"name": "python", "name": "python",
"nbconvert_exporter": "python", "nbconvert_exporter": "python",
"pygments_lexer": "ipython3", "pygments_lexer": "ipython3",
"version": "3.5.1" "version": "3.5.2"
} }
}, },
"nbformat": 4, "nbformat": 4,
......
...@@ -91,7 +91,7 @@ ...@@ -91,7 +91,7 @@
"\"use strict\";\n", "\"use strict\";\n",
"\n", "\n",
"var express = require('express')\n", "var express = require('express')\n",
"var box0 = require('box0')\n", "var box0 = require('../lib/box0')\n",
"var util = require('util')\n", "var util = require('util')\n",
"\n", "\n",
"var dev = box0.usb.open_supported()\n", "var dev = box0.usb.open_supported()\n",
...@@ -127,14 +127,14 @@ ...@@ -127,14 +127,14 @@
"\n", "\n",
" res.json({\n", " res.json({\n",
" name: dio0.header.name,\n", " name: dio0.header.name,\n",
" count: dio0.count.value,\n", " count: dio0.pin_count,\n",
" ref: {low, high}\n", " ref: {low, high}\n",
" })\n", " })\n",
"})\n", "})\n",
"\n", "\n",
"app.param('pin', function(req, res, next, pin) {\n", "app.param('pin', function(req, res, next, pin) {\n",
" var pin_value = parseInt(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", " req.pin = pin_value\n",
" next()\n", " next()\n",
" return\n", " return\n",
...@@ -146,8 +146,10 @@ ...@@ -146,8 +146,10 @@
"app.get('/dio/0/:pin', function (req, res) {\n", "app.get('/dio/0/:pin', function (req, res) {\n",
" handle_exception(res, function () {\n", " handle_exception(res, function () {\n",
" var pin = req.pin\n", " var pin = req.pin\n",
" var name = (pin < dio0.label.values.length) ?\n", " var name = dio0.label.pin[pin]\n",
" dio0.label.values[pin] : 'CH' + pin\n", " if (name == null) {\n",
" name = 'CH' + pin\n",
" }\n",
"\n", "\n",
" var value = dio0.value_get(pin)\n", " var value = dio0.value_get(pin)\n",
" var dir = dio0.dir_get(pin)\n", " var dir = dio0.dir_get(pin)\n",
...@@ -246,10 +248,13 @@ ...@@ -246,10 +248,13 @@
"\n", "\n",
"app.listen(3000, function () {\n", "app.listen(3000, function () {\n",
" console.log('Listening on port 3000!')\n", " console.log('Listening on port 3000!')\n",
" dio0.basic_prepare()\n",
" dio0.basic_start()\n",
"})\n", "})\n",
"\n", "\n",
"process.on('SIGINT', function() {\n", "process.on('SIGINT', function() {\n",
" console.log(\"\\nGracefully shutting down from SIGINT (Ctrl+C)\")\n", " console.log(\"\\nGracefully shutting down from SIGINT (Ctrl+C)\")\n",
" dio0.basic_stop()\n",
" dio0.close()\n", " dio0.close()\n",
" dev.close()\n", " dev.close()\n",
" process.exit(1)\n", " process.exit(1)\n",
......
...@@ -143,7 +143,7 @@ ...@@ -143,7 +143,7 @@
"name": "python", "name": "python",
"nbconvert_exporter": "python", "nbconvert_exporter": "python",
"pygments_lexer": "ipython3", "pygments_lexer": "ipython3",
"version": "3.5.1" "version": "3.5.2"
} }
}, },
"nbformat": 4, "nbformat": 4,
......
...@@ -33,12 +33,16 @@ ...@@ -33,12 +33,16 @@
"# open DIO (digital Input/Output) module\n", "# open DIO (digital Input/Output) module\n",
"dio = dev.dio()\n", "dio = dev.dio()\n",
"\n", "\n",
"dio.basic_prepare()\n",
"\n",
"# initalize the pin\n", "# initalize the pin\n",
"pin0 = dio.pin(0)\n", "pin0 = dio.pin(0)\n",
"pin0.output()\n", "pin0.output()\n",
"pin0.low()\n", "pin0.low()\n",
"pin0.enable()\n", "pin0.enable()\n",
"\n", "\n",
"dio.basic_start()\n",
"\n",
"try:\n", "try:\n",
" # perform a loop and toggle the pin 2 times per second\n", " # perform a loop and toggle the pin 2 times per second\n",
" while True:\n", " while True:\n",
...@@ -48,6 +52,8 @@ ...@@ -48,6 +52,8 @@
" # user want to exit\n", " # user want to exit\n",
" pass\n", " pass\n",
"\n", "\n",
"dio.basic_close()\n",
"\n",
"# close the resources\n", "# close the resources\n",
"dio.close()\n", "dio.close()\n",
"dev.close()" "dev.close()"
...@@ -70,7 +76,7 @@ ...@@ -70,7 +76,7 @@
"name": "python", "name": "python",
"nbconvert_exporter": "python", "nbconvert_exporter": "python",
"pygments_lexer": "ipython3", "pygments_lexer": "ipython3",
"version": "3.5.1" "version": "3.5.2"
} }
}, },
"nbformat": 4, "nbformat": 4,
......
...@@ -72,16 +72,12 @@ ...@@ -72,16 +72,12 @@
"#\n", "#\n",
"\n", "\n",
"import box0\n", "import box0\n",
"import box0.misc.box0v5.ps as ps\n",
"\n", "\n",
"# python2 raw_input and python3 input\n", "# python2 raw_input and python3 input\n",
"try: input = raw_input\n", "try: input = raw_input\n",
"except: pass\n", "except: pass\n",
"\n", "\n",
"box0_dev = box0.usb.open_supported()\n", "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",
"\n", "\n",
"print(\"Welcome! please enter a command:\")\n", "print(\"Welcome! please enter a command:\")\n",
"print(\" b - [both] digital supply enable and analog supply enable\")\n", "print(\" b - [both] digital supply enable and analog supply enable\")\n",
...@@ -92,23 +88,23 @@ ...@@ -92,23 +88,23 @@
"print(\" e - [exit] exit the program\")\n", "print(\" e - [exit] exit the program\")\n",
"\n", "\n",
"#turn both supply off\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", "\n",
"try:\n", "try:\n",
" while True:\n", " while True:\n",
" c = input(\"> \")\n", " c = input(\"> \")\n",
" if c == \"b\":\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", " 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", " 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", " 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", " elif c == \"s\":\n",
" mask = ps.en_get(dev)\n", " mask = dev.ps_en_get()\n",
" print(\"Analog: \" + (\"Enabled\" if mask & ps.ANALOG else \"Disabled\"))\n", " print(\"Analog: \" + (\"Enabled\" if mask & dev.PS_ANALOG else \"Disabled\"))\n",
" print(\"Digital: \" + (\"Enabled\" if mask & ps.DIGITAL else \"Disabled\"))\n", " print(\"Digital: \" + (\"Enabled\" if mask & dev.PS_DIGITAL else \"Disabled\"))\n",
" elif c == \"e\":\n", " elif c == \"e\":\n",
" break;\n", " break;\n",
" else:\n", " else:\n",
...@@ -116,11 +112,10 @@ ...@@ -116,11 +112,10 @@
"except KeyboardInterrupt: pass\n", "except KeyboardInterrupt: pass\n",
"\n", "\n",
"#turn all supply off\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", "\n",
"#close device\n", "#close device\n",
"dev = None\n", "del dev"
"del box0_dev"
] ]
}, },
{ {
...@@ -133,18 +128,18 @@ ...@@ -133,18 +128,18 @@
"\n", "\n",
"| Name | Value |\n", "| Name | Value |\n",
"|---------------------|\n", "|---------------------|\n",
"|PS_EN_GET | 0x01 |\n", "|PS_EN_GET | 201 |\n",
"|PS_EN_SET | 0x02 |\n", "|PS_EN_SET | 202 |\n",
"|PS_OC_GET | 0x03 |\n", "|PS_OC_GET | 203 |\n",
"|PS_OC_ACK | 0x04 |\n", "|PS_OC_ACK | 204 |\n",
"\n", "\n",
"\n", "\n",
"## Read enable value\n", "## Read enable value\n",
"| bmRequestType | Host ← Device, Device, Vendor |\n", "| bmRequestType | Host ← Device, Device, Vendor |\n",
"|---------------|---------------------------------|\n", "|---------------|---------------------------------|\n",
"| bRequest | 0xFF |\n", "| bRequest | PS_EN_GET |\n",
"| wValue | 0x0000 |\n", "| wValue | 0x0000 |\n",
"| wIndex | HIGH8(0) LOW8(PS_EN_GET) |\n", "| wIndex | 0x0000 |\n",
"| wLength | 0x0001 |\n", "| wLength | 0x0001 |\n",
"| Data | BIT0 = Analog, BIT1 = Digital |\n", "| Data | BIT0 = Analog, BIT1 = Digital |\n",
"\n", "\n",
...@@ -155,9 +150,9 @@ ...@@ -155,9 +150,9 @@
"\n", "\n",
"| bmRequestType | Host → Device, Device, Vendor |\n", "| bmRequestType | Host → Device, Device, Vendor |\n",
"|---------------|-------------------------------|\n", "|---------------|-------------------------------|\n",
"| bRequest | 0xFF |\n", "| bRequest | PS_EN_SET |\n",
"| wValue | HIGH8(mask) LOW8(value) |\n", "| wValue | HIGH8(mask) LOW8(value) |\n",
"| wIndex | HIGH8(0) LOW8(PS_EN_SET) |\n", "| wIndex | 0x0000 |\n",
"| wLength | 0x0000 |\n", "| wLength | 0x0000 |\n",
"| Data | None |\n", "| Data | None |\n",
"\n", "\n",
...@@ -168,9 +163,9 @@ ...@@ -168,9 +163,9 @@
"\n", "\n",
"| bmRequestType | Host ← Device, Device, Vendor |\n", "| bmRequestType | Host ← Device, Device, Vendor |\n",
"|---------------|---------------------------------|\n", "|---------------|---------------------------------|\n",
"| bRequest | 0xFF |\n", "| bRequest | PS_OC_GET |\n",
"| wValue | 0x0000 |\n", "| wValue | 0x0000 |\n",
"| wIndex | HIGH8(0) LOW8(PS_OC_GET) |\n", "| wIndex | 0x0000 |\n",
"| wLength | 0x0001 |\n", "| wLength | 0x0001 |\n",
"| Data | BIT0 = Analog, BIT1 = Digital |\n", "| Data | BIT0 = Analog, BIT1 = Digital |\n",
"\n", "\n",
...@@ -181,9 +176,9 @@ ...@@ -181,9 +176,9 @@
"\n", "\n",
"| bmRequestType | Host → Device, Device, Vendor |\n", "| bmRequestType | Host → Device, Device, Vendor |\n",
"|---------------|-------------------------------|\n", "|---------------|-------------------------------|\n",
"| bRequest | 0xFF |\n", "| bRequest | PS_OC_ACK |\n",
"| wValue | HIGH8(0) LOW8(value) |\n", "| wValue | HIGH8(0) LOW8(value) |\n",
"| wIndex | HIGH8(0) LOW8(PS_OC_ACK) |\n", "| wIndex | 0x0000 |\n",
"| wLength | 0x0000 |\n", "| wLength | 0x0000 |\n",
"| Data | None |\n", "| Data | None |\n",
"\n", "\n",
...@@ -210,8 +205,8 @@ ...@@ -210,8 +205,8 @@
"import usb.util\n", "import usb.util\n",
"from usb.util import CTRL_IN, CTRL_OUT, CTRL_RECIPIENT_DEVICE, CTRL_TYPE_VENDOR\n", "from usb.util import CTRL_IN, CTRL_OUT, CTRL_RECIPIENT_DEVICE, CTRL_TYPE_VENDOR\n",
"\n", "\n",
"BOX0V5_PS_EN_GET = 0x01\n", "BOX0V5_PS_EN_GET = 201\n",
"BOX0V5_PS_EN_SET = 0x02\n", "BOX0V5_PS_EN_SET = 202\n",
"\n", "\n",
"POWER_ANALOG = 0x01\n", "POWER_ANALOG = 0x01\n",
"POWER_DIGITAL = 0x02\n", "POWER_DIGITAL = 0x02\n",
...@@ -249,7 +244,7 @@ ...@@ -249,7 +244,7 @@
" if analog: value |= POWER_ANALOG\n", " if analog: value |= POWER_ANALOG\n",
" if digital: value |= POWER_DIGITAL\n", " if digital: value |= POWER_DIGITAL\n",
" wValue = (mask << 8) | value\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", "\n",
"def power_supply_get(dev):\n", "def power_supply_get(dev):\n",
" \"\"\"\n", " \"\"\"\n",
...@@ -258,7 +253,7 @@ ...@@ -258,7 +253,7 @@
" return a tuple (<analog-supply>, <digital-supply>)\n", " return a tuple (<analog-supply>, <digital-supply>)\n",
" \"\"\"\n", " \"\"\"\n",
" bmReqType = CTRL_IN | CTRL_RECIPIENT_DEVICE | CTRL_TYPE_VENDOR\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", " analog = (data[0] & POWER_ANALOG) != 0x00\n",
" digital = (data[0] & POWER_DIGITAL) != 0x00\n", " digital = (data[0] & POWER_DIGITAL) != 0x00\n",
" return analog, digital\n", " return analog, digital\n",
...@@ -311,7 +306,7 @@ ...@@ -311,7 +306,7 @@
"name": "python", "name": "python",
"nbconvert_exporter": "python", "nbconvert_exporter": "python",
"pygments_lexer": "ipython3", "pygments_lexer": "ipython3",
"version": "3.5.1" "version": "3.5.2"
} }
}, },
"nbformat": 4, "nbformat": 4,
......
This diff is collapsed.
This diff is collapsed.
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": 1,
"metadata": { "metadata": {
"collapsed": true "collapsed": true
}, },
...@@ -20,6 +20,7 @@ ...@@ -20,6 +20,7 @@
"import time\n", "import time\n",
"\n", "\n",
"# When 1000 samples are output at 100KS/s, the generate waveform is of 100Hz\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_SPEED = 100000 # 100KS/s\n",
"SAMPLE_COUNT = 1000\n", "SAMPLE_COUNT = 1000\n",
"\n", "\n",
...@@ -32,9 +33,9 @@ ...@@ -32,9 +33,9 @@
"aout = dev.aout()\n", "aout = dev.aout()\n",
"\n", "\n",
"# Prepare for static mode\n", "# Prepare for static mode\n",
"aout.static_prepare()\n", "aout.snapshot_prepare()\n",
"aout.speed.current = SAMPLE_SPEED\n", "aout.bitsize_speed_set(SAMPLE_BITSIZE, SAMPLE_SPEED)\n",
"aout.static_start(y)\n", "aout.snapshot_start(y)\n",
"\n", "\n",
"# wait for the user to ask for exit\n", "# wait for the user to ask for exit\n",
"try:\n", "try:\n",
...@@ -44,7 +45,7 @@ ...@@ -44,7 +45,7 @@
" pass\n", " pass\n",
"\n", "\n",
"# Return all the resources\n", "# Return all the resources\n",
"aout.static_stop()\n", "aout.snapshot_stop()\n",
"aout.close()\n", "aout.close()\n",
"dev.close()" "dev.close()"
] ]
...@@ -82,7 +83,7 @@ ...@@ -82,7 +83,7 @@
"name": "python", "name": "python",
"nbconvert_exporter": "python", "nbconvert_exporter": "python",
"pygments_lexer": "ipython3", "pygments_lexer": "ipython3",
"version": "3.5.1" "version": "3.5.2"
} }
}, },
"nbformat": 4, "nbformat": 4,
......
...@@ -18,7 +18,7 @@ ...@@ -18,7 +18,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": 1,
"metadata": { "metadata": {
"collapsed": true "collapsed": true
}, },
...@@ -31,25 +31,27 @@ ...@@ -31,25 +31,27 @@
"dev = box0.usb.open_supported()\n", "dev = box0.usb.open_supported()\n",
"pwm = dev.pwm()\n", "pwm = dev.pwm()\n",
"\n", "\n",
"pwm.output_prepare()\n",
"\n",
"# Increment count every 1/1000 second, count upto 250 and toggle when reach at 150\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", "# effectively giving a 4Hz with 50% duty cycle output on channel 0\n",
"# So, LED will blink 4 per second!\n", "# So, LED will blink 4 per second!\n",
"pwm.speed.current = 1000\n", "pwm.speed_set(1000)\n",
"pwm.period = 250\n", "pwm.period_set(250)\n",
"pwm.width[0] = 125\n", "pwm.width_set(0, 125)\n",
"\n", "\n",
"# Start generating!\n", "# Start generating!\n",
"pwm.start()\n", "pwm.output_start()\n",
"\n", "\n",
"# Wait till we are not asked to exit\n", "# Wait till we are not asked to exit\n",
"try:\n", "try:\n",
"\twhile True:\n", " while True:\n",
"\t\ttime.sleep(0.1)\n", " time.sleep(0.1)\n",
"except KeyboardInterrupt:\n", "except KeyboardInterrupt:\n",
"\tpass\n", " pass\n",
"\n", "\n",
"# give back all the required resources\n", "# give back all the required resources\n",
"pwm.stop()\n", "pwm.output_stop()\n",
"pwm.close()\n", "pwm.close()\n",
"dev.close()\n" "dev.close()\n"
] ]
...@@ -71,7 +73,7 @@ ...@@ -71,7 +73,7 @@
"name": "python", "name": "python",
"nbconvert_exporter": "python", "nbconvert_exporter": "python",
"pygments_lexer": "ipython3", "pygments_lexer": "ipython3",
"version": "3.5.1" "version": "3.5.2"
} }
}, },
"nbformat": 4, "nbformat": 4,
......
...@@ -53,12 +53,12 @@ ...@@ -53,12 +53,12 @@
"aout0 = dev.aout()\n", "aout0 = dev.aout()\n",
"\n", "\n",
"# prepare AIN0\n", "# prepare AIN0\n",
"ain0.static_prepare()\n", "ain0.snapshot_prepare()\n",
"ain0.chan_seq.current = [0, 1]\n", "ain0.chan_seq_set([0, 1])\n",
"ain0.speed.current = 100000\n", "ain0.bitsize_speed_set(12, 100000)\n",
"\n", "\n",
"# prepare AOUT0\n", "# prepare AOUT0\n",
"aout0.static_prepare()\n", "aout0.snapshot_prepare()\n",
"\n", "\n",
"# generate voltage, read voltage, calculate current and store the result\n", "# generate voltage, read voltage, calculate current and store the result\n",
"# AIN0.CH0 = AOUT0.CH0 = generated signal\n", "# AIN0.CH0 = AOUT0.CH0 = generated signal\n",
...@@ -74,15 +74,15 @@ ...@@ -74,15 +74,15 @@
"\n", "\n",
"for i in range(SAMPLES):\n", "for i in range(SAMPLES):\n",
" if aout0_running:\n", " if aout0_running:\n",
" aout0.static_stop()\n", " aout0.snapshot_stop()\n",
" \n", " \n",
" # output \"v\" value on AOUT0.CH0\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", " aout0_running = True\n",
" \n", " \n",
" # read back AIN0.CH0 and AIN0.CH1\n", " # read back AIN0.CH0 and AIN0.CH1\n",
" readed_data = np.empty(SAMPLES)\n", " readed_data = np.empty(SAMPLES)\n",
" ain0.static_start(readed_data)\n", " ain0.snapshot_start(readed_data)\n",
" \n", " \n",
" # do the calculation\n", " # do the calculation\n",
" ch0 = np.mean(readed_data[0::2])\n", " ch0 = np.mean(readed_data[0::2])\n",
...@@ -95,7 +95,7 @@ ...@@ -95,7 +95,7 @@
"\n", "\n",
"# stop if AOUT0 running\n", "# stop if AOUT0 running\n",
"if aout0_running:\n", "if aout0_running:\n",
" aout0.static_stop()\n", " aout0.snapshot_stop()\n",
"\n", "\n",
"# close the resources\n", "# close the resources\n",
"ain0.close()\n", "ain0.close()\n",
...@@ -135,7 +135,7 @@ ...@@ -135,7 +135,7 @@
"name": "python", "name": "python",
"nbconvert_exporter": "python", "nbconvert_exporter": "python",
"pygments_lexer": "ipython3", "pygments_lexer": "ipython3",
"version": "3.5.1" "version": "3.5.2"
} }
}, },
"nbformat": 4, "nbformat": 4,
......
...@@ -806,7 +806,7 @@ ...@@ -806,7 +806,7 @@
} }
], ],
"source": [ "source": [
"%matplotlib notebook\n", "#~ %matplotlib notebook\n",
"import box0\n", "import box0\n",
"import numpy as np\n", "import numpy as np\n",
"import matplotlib.pyplot as plt\n", "import matplotlib.pyplot as plt\n",
...@@ -820,13 +820,11 @@ ...@@ -820,13 +820,11 @@
"\n", "\n",
"# prepare resources\n", "# prepare resources\n",
"\n", "\n",
"ain0.static_prepare()\n", "ain0.snapshot_prepare()\n",
"ain0.bitsize.current = 12\n", "ain0.chan_seq_set([0, 1])\n",
"ain0.chan_seq.current = [0, 1]\n",
"\n", "\n",
"aout0.static_prepare()\n", "aout0.snapshot_prepare()\n",
"aout0.bitsize.current = 12\n", "aout0.chan_seq_set([0])\n",
"aout0.chan_seq.current = [0]\n",
"\n", "\n",
"FREQ = range(100, 5000, 100)\n",