Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updating plugins using nidaqmx and not PyDAQmx #6

Open
jerlfan opened this issue Dec 8, 2023 · 4 comments
Open

Updating plugins using nidaqmx and not PyDAQmx #6

jerlfan opened this issue Dec 8, 2023 · 4 comments

Comments

@jerlfan
Copy link

jerlfan commented Dec 8, 2023

Hi guys,
I am actually working on the update of the plugin to replace PyDAQmx by nidaqmx (from NI).
The current state of the work can be find on my fork : https://github.com/jerlfan/pymodaq_plugins_daqmx
I created daqmx-ni wrapper using nidaqmx (in hardware) to replace daqmx that uses PyDAQmx
If you can have a look on what I have done at this stage, I would be grateful. It is not fuly tested I have to implement the reading methods (see below)

To finish the work I am actually facing one problem:
reading procedure is much simpler with nidaqmx (no needs to use ctype, or byref...): i.e. task.read(Nsamples, Readout time) and it is independant from the channel type. The time is defined elsewhere (task.timing).
I will start by implementing the counter channels and I would your advices.
There is two ways to use it:
1- we feed a clock to the counter. Usually you use another counter channel for that (Aurore's way). It is really good for short time but you loose a counter channel :-( (at least on the NI board we have in the Lab, I have a USB6341).
2- You can simply use a "machine clock". This is where I may need help. I propose the following solution:
init=time.perf_counter()
task.start()
while time.perf_counter()-init <=Acquisition_time:
pass
counts=task.read()
print(counts)
task.stop()

What do you think? I think it is not really elegant. So sugestions are welcomed!

I will then create a daq_viewer_0D counter-fast and counter-slow.

Cheers

@seb5g
Copy link
Contributor

seb5g commented Dec 8, 2023

concerning the timing, you can use a timer:
https://docs.python.org/fr/3/library/threading.html?highlight=timer#threading.Timer
this will call a callback (function) when the timer has finished its count down.
Otherwise I would suggest you put you functionnality into a separated thread but then it is probably the same as the threading.Timer class

@jerlfan
Copy link
Author

jerlfan commented Dec 8, 2023

Thanks,

threading.Timer seems indeed to be exactly what I want. However, I don't understand where I can find the count_value returned by the function I used:

def read():
return task.read()
t=threadig.Timer(2,read)
t.start()

From this code I have no output. There is probably something I miss.

@seb5g
Copy link
Contributor

seb5g commented Dec 8, 2023

Well for sure your async function won't return directly the counts, but the timer callback (self._ready) will be the one reading the counts and you can notify the user using two methods: polling the self.ready boolean or asking it to provide a method signature (callback) to notify a external program (for instance a pymodaq plugin).

class blabla:
    def __init__(self):
        self.task = Task(...)
        self.ready = False
        self.counts: int = None
        self.callback = None

    def _ready(self):
        self._ready = True
        self.counts = self.task.read()
        if self.callback is not None:
            self.callback(self.counts)

    def get_counts(self, dtime: float, callback = None):
        self.ready = False
        self.callback = callback
        t = threading.Timer(dtime, self._ready)
        t.start()

If you want a blocking function, then just write what you did before maybe inserting a sleep time in the while loop

@loicguilmard
Copy link

hello @jerlfan
You should check the last PR : nidaqmx PR
There is no counter but there is task management with the NI python librairy and scalable GroupParameter, and importing toml to GroupParameter in the pluging ParameterTree.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants