{"id":34941425,"url":"https://github.com/jokeyser/plain-matlab-ni-daqmx-examples","last_synced_at":"2026-05-22T15:41:54.457Z","repository":{"id":211292067,"uuid":"728734482","full_name":"JoKeyser/Plain-Matlab-NI-DAQmx-examples","owner":"JoKeyser","description":"Examples how to use National Instruments (NI) DAQ cards in Matlab, without the Data Acquisition toolbox","archived":false,"fork":false,"pushed_at":"2024-02-13T10:27:18.000Z","size":415,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2024-02-13T12:40:02.537Z","etag":null,"topics":["daqmx","matlab","ni"],"latest_commit_sha":null,"homepage":"","language":"MATLAB","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/JoKeyser.png","metadata":{"files":{"readme":"README.md","changelog":"changelog.md","contributing":null,"funding":null,"license":"LICENSES/BSD-2-Clause.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2023-12-07T15:21:26.000Z","updated_at":"2023-12-07T16:52:53.000Z","dependencies_parsed_at":"2024-02-13T12:51:26.557Z","dependency_job_id":null,"html_url":"https://github.com/JoKeyser/Plain-Matlab-NI-DAQmx-examples","commit_stats":null,"previous_names":["jokeyser/plain-matlab-ni-daqmx-examples"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/JoKeyser/Plain-Matlab-NI-DAQmx-examples","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JoKeyser%2FPlain-Matlab-NI-DAQmx-examples","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JoKeyser%2FPlain-Matlab-NI-DAQmx-examples/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JoKeyser%2FPlain-Matlab-NI-DAQmx-examples/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JoKeyser%2FPlain-Matlab-NI-DAQmx-examples/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/JoKeyser","download_url":"https://codeload.github.com/JoKeyser/Plain-Matlab-NI-DAQmx-examples/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JoKeyser%2FPlain-Matlab-NI-DAQmx-examples/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28058688,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-12-26T02:00:06.189Z","response_time":55,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["daqmx","matlab","ni"],"created_at":"2025-12-26T19:11:08.752Z","updated_at":"2025-12-26T19:11:10.201Z","avatar_url":"https://github.com/JoKeyser.png","language":"MATLAB","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003c!--\nSPDX-FileCopyrightText: 2005 Jens Roesner, 2023-2024 Johannes Keyser\n\nSPDX-License-Identifier: CC0-1.0\n--\u003e\n\n# Plain Matlab NI-DAQmx examples\n\nExamples how to use a National Instruments (NI) DAQ card with plain Matlab, _without_ the Data Acquisition Toolbox.\n\n## Who is this for?\n\nFor anyone who wants to use their NI input/output cards with Matlab (via the NI-DAQmx driver).\n\nFurther, the examples illustrate some very basic steps on how to use Matlab's powerful function of importing dll files.\n\n## Current status and roadmap\n\nSo far, this project contains the files and descriptions by Jens Roesner and Nathan Tomlin.\n\nThe next steps are to improve the documentation, remove/improve any redundant/outdated code, and generalize the code to run on Linux.\n\n## Installation\n\n- FIXME: Add links for Windows and MacOS?\n- FIXME: Merge advice from Jens and Nathan.\n\n### Driver installation\n\nFollow the NI's instructions to install the DAQmx driver for your platform.\n\n- For Linux, follow [Installing NI Drivers and Software on Linux](https://www.ni.com/docs/en-US/bundle/ni-platform-on-linux-desktop/page/installing-ni-drivers-and-software-on-linux-desktop.html).\n  For example on Ubuntu, once you installed/configured the NI repo, you should be able to `sudo apt install ni-daqmx` (and the recommended `ni-hwcfg-utility`).\n  After installation, run `sudo dkms autoinstall` and reboot.\n\nYou can check the installation with the _Hardware Configuration Utility_ (on Linux, run `ni-hwcfg-utility`):\nThe utility should have discovered your NI device(s) and list them without indication of errors.\n\n### Advice from Jens Roesner:\n\nStart by loading the NI dll: `funclist = loadlibrary('nicaiu.dll', 'nidaqmx.h', 'alias', 'myni')`\n\n(You can choose any alias as long as it is a legal variable name.)\n\nIf your version of Matlab is too old to provide the `loadlibrary` function directly, download it here: \u003chttp://www.codeproject.com/dll/MatlabGenericDll.asp?df=100\u0026forumid=26247\u0026exp=0\u0026select=972623\u003e.\nAfter importing, you see the list of available functions.\nYou can also display them by `libfunctionsview('myni')`.\nThat's basically it.\nBy using the National Instruments NI-DAQmx C Reference manual and libfunctionsview(\\'myni\\') you have access to those functions.\nOne special thing you need to keep in mind is the fact that pointers work differently in Matlab than in C.\nThis problem can be solved by using the Matlab function `libpointer`.\nSometimes Matlab does not require a pointer when C would.\nBut I found that it does not hurt to specify a pointer in this case.\nWhether Matlab expects a pointer can be seen in the output created by `libfunctionsview('myni')`.\n\n### Advice from Nathan Tomlin:\n\nI had no header file (`.h`) on my computer, so I had to download NIDAQ from the NI website, I got this version: `nidaq910f0_downloader.exe`.\n\nAfter installing, the C help files were then in:  \n`C:\\Program Files\\National Instruments\\NI-DAQ\\docs\\cdaqmx.chm`  \nand the header file in:  \n`C:\\Program Files\\National Instruments\\NI-DAQ\\DAQmx ANSI C Dev\\include`.\n\nI copied the files `nicaiu.dll` and `nidaqmx.h` files to my working directory, but you can also just add their paths to the code.\n\n## Usage\n\nThe general syntax for calling DAQmx functions is:\n\n```matlab\n[outputarguments] = calllib(alias, NIDAQmx_functionname, inputarguments)\n```\n\n### Overview of scripts\n\nThe following examples were written by Jens Roesner, featuring simple analog input (AI); advanced, synchronous AI; and simple analog output (AO):\n\n- [NImess.m](NImess.m): Triggered and untriggered, synchronized or unsynchronized AI.\n- [NIsetAO.m](NIsetAO.m): Simple AO\n- [NIsetAOwave2.m](NIsetAOwave2.m): Wave Output AO\n- [NIconstants.m](NIconstants.m): List of constants defined by NI.\n\nThese following examples were written by Nathan Tomlin:\n\n- [daqmx_examples.m](daqmx_examples.m): Showcases how to use the functions below.\n- [DAQmxCheckError.m](DAQmxCheckError.m): Checks for errors from the NI driver.\n- [DAQmxCreateAIVoltageChan.m](DAQmxCreateAIVoltageChan.m): Creates a task and adds analog input channel(s) to the task.\n- [DAQmxCreateDIChan.m](DAQmxCreateDIChan.m): FIXME: Claims to create a task and add digital output line(s) to the task (but probably means INPUT lines?)\n- [DAQmxCreateDOChan.m](DAQmxCreateDOChan.m): Creates a task and adds digital output line(s) to the task.\n- [DAQmxReadAnalogF64.m](DAQmxReadAnalogF64.m): Reads analog inputs from previously set up task.\n- [DAQmxReadDigitalLines.m](DAQmxReadDigitalLines.m): Reads digital inputs from previously set up task.\n- [DAQmxWriteDigitalLines.m](DAQmxWriteDigitalLines.m): Writes digital outputs from previously set up task.\n\n## Known limitations and issues\n\nThe scripts in this project are based on Matlab's [`loadlibrary()`](https://mathworks.com/help/matlab/ref/loadlibrary.html) and [`calllib()`](https://mathworks.com/help/matlab/ref/calllib.html), which have [known limitations](https://mathworks.com/help/matlab/matlab_external/limitations-to-shared-library-support.html).\n\n- FIXME: Matlab's missing support of library functions to work with _function pointers_ means that callbacks are impossible, right?\n\nSome known issues are tracked in file [known_issues.md](known_issues.md).\n\n## Compatibility\n\nThere are no guarantees that this code will work with your hardware or software.\n\n- Jens Roesner wrote his initial examples in 2005 for NI's M-Series cards.\n- Nathan Tomlin tested his code on Matlab 7.8.0 (R2009a) on Windows XP with a NI PCI 6220 board.\n- Johannes Keyser is testing this code on Matlab 9.7.0 (R2019b) with a [PCIe-6321 card (X-Series)](https://www.ni.com/en-us/support/model.pcie-6321.html), connected to a [BNC-2110 terminal block](https://www.ni.com/en-us/support/model.bnc-2110.html).\n\n## Alternatives\n\nThe code in this project may not be up to your requirements.\n\n- If you're running Matlab on Windows:\n   - You probably should get the (commercially licensed) [Matlab Data Acquisition Toolbox](http://www.mathworks.com/products/daq/) to access many NI cards (and from other manufacturers) seamlessly from within Matlab.\n   - Also have a look at the project [SWC-Advanced-Microscopy/MATLAB_DAQmx_examples](https://github.com/SWC-Advanced-Microscopy/MATLAB_DAQmx_examples).\n- If you're running Linux or MacOS, you may use another language that is officially supported by NI, like [C or Python](https://github.com/ni).\n\n## Previous work and further resources\n\nThis project is based on code by Jens Roesner (2005) and Nathan Tomlin (2010).\nFor some \"historical context\": Jens Roesner's code pre-dates the widespread support by Matlab's Data Acquisition Toolbox.\n\n- Jens Roesner's code is available at \u003chttps://www.jensroesner.com/work/matlab/index.html\u003e.\n- Nathan Tomlin's code is available at \u003chttps://mathworks.com/matlabcentral/fileexchange/27609-daqmx-examples\u003e.\n- You can also check [this thread started by Jens Roesner in the NI forum](https://forums.ni.com/t5/Multifunction-DAQ/Use-M-Series-cards-with-DAQmx-in-Matlab/m-p/185232).\n- Chen \u0026 Li (2012) describe their _NiMex_ toolbox, a MEX wrapper around NI-DAQmx, capable of using callbacks.\n  Unfortunately, it's unclear where this code can be found?\n  Chen, Y., \u0026 Li, X. (2012).\n  A Method to Improve the Interacting between MATLAB and NI-DAQmx.\n  _Energy Procedia, 17, 1945–1952._\n  \u003chttps://doi.org/10.1016/j.egypro.2012.02.337\u003e\n\n### Further information\n\n- The [NI-DAQmx C Reference Help](https://www.ni.com/docs/en-US/bundle/ni-daqmx-c-api-ref/page/cdaqmx/help_file_title.html) describes the NI-DAQmx library functions, which you can use with NI data acquisition and switch devices to develop instrumentation, acquisition, and control applications.\n\n## Authors\n\n- Jens Roesner (`jens.roesner -at- gmx.de`, [link to personal website](https://www.jensroesner.com/work/matlab/))\n- Nathan Tomlin (`nathan.a.tomlin -at- gmail.com`, [link to Mathworks community profile](https://mathworks.com/matlabcentral/profile/authors/1252890))\n- Johannes Keyser (so far, only editorial work; [link to Mathworks community profile](https://mathworks.com/matlabcentral/profile/authors/2267277))\n\n## Contributing\n\nThis project is shared as-is, with the hope to be useful.\n\nIf you find a problem, or you would like to add features, the easiest way is to open an issue or a pull request on GitHub, at \u003chttps://github.com/JoKeyser/Plain-Matlab-NI-DAQmx-examples\u003e.\n\n## Licensing\n\nJens Roesner retro-actively licensed his code under GPL-3.0-or-later, via personal communication with Johannes Keyser.\n\nNathan Tomlin based his code on Jens Roesner's code and licensed it under the BSD-2-Clause license.\n\nThe documentation files are licensed under CC0-1.0.\n\nTo clarify the licensing of each file, this repository is [REUSE compliant](https://reuse.software/).\nFor the legal texts, see folder [LICENSES](LICENSES).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjokeyser%2Fplain-matlab-ni-daqmx-examples","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjokeyser%2Fplain-matlab-ni-daqmx-examples","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjokeyser%2Fplain-matlab-ni-daqmx-examples/lists"}