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

WriteDigitalLines on __del__ causing mafunction #60

Open
o7-machinehum opened this issue Apr 15, 2020 · 0 comments
Open

WriteDigitalLines on __del__ causing mafunction #60

o7-machinehum opened this issue Apr 15, 2020 · 0 comments

Comments

@o7-machinehum
Copy link

o7-machinehum commented Apr 15, 2020

I want to but a quick command to drop the output in the case of program termination, however this is causing an exception.

Windows 10, Python 3.7.3

python ni.py

Exception ignored in: <function DO.__del__ at 0x000001BF19B26378>
Traceback (most recent call last):
  File "ni.py", line 20, in __del__
  File "ni.py", line 27, in low
  File "<string>", line 3, in WriteDigitalLines
  File "<string>", line 2, in function
  File "C:\ProgramData\Anaconda3\lib\site-packages\PyDAQmx\DAQmxFunctions.py", line 57, in mafunction
ctypes.ArgumentError: argument 6: <class 'ImportError'>: sys.meta_path is None, Python is likely shutting down
import PyDAQmx
from PyDAQmx import Task
import numpy as np
import time
import pdb
import weakref

high = np.array([1], dtype=np.uint8)
low  = np.array([0], dtype=np.uint8)
 
# Simple class that can be used to control one Digital output line
class DO:
    def __init__(self, card, lines):
        self.task = Task()
        self.task.CreateDOChan('/{}/port0/{}'.format(card, lines), 
            "", PyDAQmx.DAQmx_Val_ChanForAllLines)
        self.task.StartTask()
    
    def __del__(self):
        self.low()
        self.task.StopTask()
    
    def high(self):    
        self.task.WriteDigitalLines(1, 1, 10.0, PyDAQmx.DAQmx_Val_GroupByChannel, high, None, None)

    def low(self): 
        self.task.WriteDigitalLines(1, 1, 10.0, PyDAQmx.DAQmx_Val_GroupByChannel, low, None, None)


if __name__ == '__main__':
    dig_0 = DO('cDAQ1Mod1', 'line0') 
    dig_0.high()
    time.sleep(5) 
    dig_0.low()
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

1 participant