Driver development with NI DAQ

Dear Axel,

May I ask a question regarding the development of a new driver?

The Driver Writer AI has helped me generate a driver for the NI 6218 DAQ device, which provides both analog input (AI) and analog output (AO) functionality. I’ve placed the main.py file in the SweepMe! public folder at:
C:\Users\Public\Documents\SweepMe!\CustomDevices\Logger-NI_6218
The driver folder name follows the structure as specified:
Type of the Module-Manufacturer_Instrument Model>

However, I do not find the corresponding control panel with the AO voltage in the Logger tab (as shown in the attached photo).

Since this device supports both AI and AO—unlike the existing MCC DAQ module, which supports only AI—should I create a new module type specifically for DAQ instruments with combined AI/AO capabilities?

Many thanks,

Shun-Tsung


1 Like

Hello Shun-Tsung,

I am happy to see that you are testing our driver writer AI! However, as it is still work in progress, it seems that the created driver code does not work immediately.

In your SweepMe! screenshot, you can see that the driver description in the bottom still says “MCC High-Speed Multifunction DAQ”, which means that your driver was not correctly loaded and the GUI of the previous driver is still shown. Please open the debug widget (by pressing F2) to see if any error logs were produced.

Best,
Franz

1 Like

Hello Franz,

Thank you for your prompt response. I’ve attached the debug information.

If the driver is loaded correctly, should the analog output item appear in the “Parameters” section?

Many thanks,

Shun-Tsung

1 Like

The debug shows a “ModuleNotFoundError: No module named ‘nidaqmx’”
It seems your driver requires the nidaqmx Python library, which you can also see in your driver code in line 3-4.
In our wiki, you can find an article on how to add external libraries to your SweepMe! driver: External libraries and dependencies - SweepMe! Wiki

You are right, when the driver is loaded correctly, your AI Channel, AO Channel, and Sample rate items should appear in the GUI

1 Like

Hi Franz,

Thank you very much for your reply. I am trying to create the library using the LibraryBuilder2. and still have some problems with it as shown in the attached photos. May you kindly give me some suggestions about this, please? The required modules can be downloaded but cannot be installed properly.

Many thanks,

Shun-Tsung



1 Like

Hello Franz,

Driver Writer AI helped me identify the issue and pointed out that the essential distutils module has been removed in Python 3.12, which I had installed.

Following the suggestion, I installed the Python 3.11, and it seems that nidaqmx has been successfully installed. However, there are still some issues when loading the NI 6218 driver as shown in the attached photo.

Best,

Shun-Tsung

2 Likes

Hello,

The magic number error could indicate a mismatch between the Python version you used with the LibraryBuilder2 (3.11) and the version used in SweepMe! (3.9). Please rerun the LibraryBuilder2 using Python 3.9 (64 Bit).

1 Like

Hi Franz,

Thank you very much for the suggestion. I have successfully loaded the NI 6218 driver! However I found that the AO voltage cannot be controlled in the logger module. I have now used the SMU module instead for the AO voltage control.
The SMU-NI_6218 driver can be loaded successfully but the Sweep mode and Sweep value cannot be tuned. Moreover there are 2 AOs in NI_6218, which should be controlled individually. Any suggestions, please?

The NI_6218 was not connected when testing the driver. Will the Sweep mode and value be adjustable when it is connected?

Many thanks,

Shun-Tsung

1 Like

Great to hear that you can now load your driver!
To enable the GUI elements, you must first add them to your driver in the set_GUIparameter function. You can find a detailed description in our wiki: Driver Programming - SweepMe! Wiki

For devices with multiple channels that can be controlled individually, add the Channel parameter and let your driver control only one. Then, in your SweepMe! setting, you can add multiple instances of the same driver, each with a different channel selected.

1 Like

Hi Franz,

Thank you for the information. The sweep mode and value fields are still greyed out and cannot be adjusted.

I went back to check the library build for Sweep Me! itself and found that some components may not have been installed correctly. This might explain why the Library.zip file, which Sweep Me can identify, is not being automatically generated in the libs_39_64 folder. Could this also be the reason why the SMU-NI_6218 driver isn’t functioning properly?

Many thanks,

Shun-Tsung

1 Like

If you encounter any issues with a driver, the first thing you can check is the debug log, which can be opened by pressing “F2”. Here, you can find more detailed descriptions of any errors that occur. If a library import is not working, it should be displayed in this location.
If you are unsure about the meaning of an error, you can also copy it to the ChatGPT - SweepMe! Driver Writer

To enable the GUI Input fields, you must edit the set_GUIparameter function in your driver. The returned dictionary denotes which GUI elements are activated. The keywords for the standard input fields are described here: Driver Programming - SweepMe! Wiki

We will look into the the Library Builder issue and update you here :wrench:

1 Like

We have fixed the issue in Library Builder 2. Please download the newest version from the dashboard and run it again with the nidaqmx library.

2 Likes

Hi Franz,

Thank you very much for the updates.

I am still testing the driver for the NI USB-6218, where both analog outputs (AO) are intended to be used. I believe the issue related to the PackageNotFoundError stems from SweepMe! always prioritizing the Python environment installed on the user’s PC—even though I explicitly set the Python path within the driver.

To confirm this, I uninstalled the local Python installation from my PC, and after that, SweepMe! was able to successfully load the embedded Python environment created by Library Builder 2.

Additionally, I noticed that the init.py file was missing from SweepMe!'s version of the nidaqmx package. I copied this file from another working nidaqmx installation and modified it as follows with the suggestions from Driver Writer AI:

Originally written like this (source of the error)

import importlib.metadata

version = importlib.metadata.version(name)

Changed to this

version = “0.6.6”

The Debug Widget shows:
SweepMe! version 1.5.7.4

Time: 27.6.2025 15:36:57
Message: Not loaded: Device Class SMU-NI_USB_6218_dual_AO
Python Error:
Traceback (most recent call last):
File “DeviceClassManager.py”, line 348, in load_main_file
File “imp.py”, line 171, in load_source
File “”, line 711, in _load
File “”, line 680, in _load_unlocked
File “”, line 850, in exec_module
File “”, line 228, in call_with_frames_removed
File “C:\Users\Public\Documents\SweepMe!\CustomDevices\SMU-NI_USB_6218_dual_AO\main.py”, line 23, in
import nidaqmx
File "C:\Users\SHUNTS~1\AppData\Local\Temp\embedded.tsis7kmd.zip\shibokensupport_feature
.py", line 142, in import
File "nidaqmx_init
.py", line 12, in
File “importlib\metadata.py”, line 569, in version
File “importlib\metadata.py”, line 542, in distribution
File “importlib\metadata.py”, line 196, in from_name
importlib.metadata.PackageNotFoundError: nidaqmx

Finally, after the revision, the nidaqmx module can be successfully loaded, although the correct output voltage has not yet been achieved."

Many thanks,

Shun-Tsung

1 Like

Hello Shun-Tsung,

thanks for reporting the issue with LibraryBuilder2 and the missing init.py file. We will have a look at it.

Why the correct voltage is not yet applied, is difficult to say, but is now probably related to the correct use of the functions of the nidaqmx package. Often, it also helps to run a first minimal example in a pure python environment until functions works as expected. Then, it is just copy&paste to fill the SweepMe! driver structure. For this purpose, we also provide the package pysweepme that allows to load SweepMe! drivers in python environments. Here, we recommend to use the Python 3.9 environment that you also use to run the LibraryBuilder2.

Here are some furthers hints:

  • If you like to cover multiple functions of the NI DAQ device in SweepMe!, you can also write multiple drivers, e.g. a driver for the Logger module to cover the input channels and a driver for the Switch module to cover the output channels.

  • Instead of using the SMU module I recommend to use the Switch module. It is the perfect choice for all devices that do not match any specialized instrument module like SMU, LockIn, Monochromator etc. In your case, you just need to rename your driver from “SMU-…” to “Switch-…”. After a restart SweepMe! your driver will be now listed as Switch driver and can be loaded with the Switch module. As the Switch module also comes with a Parameter box, your parameters will be shown just like in the SMU module, but the Switch module will be more clean for your purpose as all the other SMU specific options are not shown. Switch and Logger are therefore our general-purpose modules that can be used whenever an instrument does not match the other instrument modules.

  • It is possible to contribute instrument driver to our repository to make them available to other users. In this case, we will also do a final check before merging the code.
    https://github.com/SweepMe/instrument-drivers
    If this is interesting for you, please contact us at contact@sweep-me.net and we can guide you through the process.

  • If you feel it would be better if we pro-actively help you with the design and and the revision of the driver, you can make use of our professional services where we support our users to get their perfect driver. In this case also feel free to write to contact@sweep-me.net

  • A driver that might be similar to yours is the one for the Labjack. Maybe have a look at it to find some inspiration:
    instrument-drivers/src/Switch-Labjack_T-Series-TTL/main.py at main · SweepMe/instrument-drivers · GitHub

Thanks and best
Axel

1 Like

Hi Shun-Tsung,

short update: we have updated our Library Builder server settings and now it should be possible to build nidaqmx correctly without any manual adaptions. It looks like it requires to be shipped with some metadata that have not been added automatically so far.

Thanks and best
Axel