Digital I/O

cancel
Showing results for 
Search instead for 
Did you mean: 

Stream writing digital output in python with nidaqmx

Hello,

I am using a NI PCIe-6321 to write digital commands to external hardware. I need a stream writer running in the background while my python code does something else. I seem to have the stream writer working (timing works out), but my external hardware doesn't change. I think the device is writing the wrong type (integers) when the task needs booleans, and I'm not sure why that isn't automatically converted in DigitalSingleChannelWriter.write_many_sample_port_byte.

 

Please advise what data type I need to send to the device in order for digital stream writing to be effective - or whatever I'm doing wrong here. Basic code just to run the stream writer is below.

screenshot.PNG

Many thanks!

0 Kudos
Message 1 of 4
(1,840 Views)

Hello,

 

I am guessing this is an issue with your external hardware, but you can use an oscilloscope to check if the output is really being changed or not. As far as I can see, your code should work, but I don't think there is a way to write a list of booleans to a port, only one at a time. You should be able to use byte or uint32 instead of uint16, as long as the input commands and write_many_sample_port have the same format, and it shouldnt be functionally different than using booleans.

 

Also, I have a setup similar to yours (I need the stream_writer to write output continuously without gaps while there are other python threads running, one of which needs to load new data into the DAQ's buffer while the task is running). Does your application feed new commands into the stream_writer or does it just have to repeatedly make the same pattern?

0 Kudos
Message 2 of 4
(1,706 Views)

Hey, I finally got this figured out - because I was sending digital commands, I had to give the commands as powers of 2 (even tho we specify which digital line receives the commands...). So like digital line 3 needed a command of '8' not '1' in order for it to open and then close the valve I was using to test the system. If you want to see my final code lmk

 

My system does not feed new commands through during the task, I just open a new task each iteration of a loop and close it at the end, but I think what you're asking should be possible - if you set your buffer to be very small, you should be able to change the value using the callback while the task is open, like they do here: Solved: Continuous write analog voltage NI cDAQ 9178 with callbacks - NI Community

 

 

0 Kudos
Message 3 of 4
(1,697 Views)

O, I see now you were using line3, that makes sense then (8 is 1000 in binary, so the "1" shows up at line3 while line0:2 and all others stay "0"). Thanks for your response, I found a similar solution earlier, and I have continuous output working (both with using a callback function and alternatively with regeneration turned on). I can also update the data when the task is running, so it is possible like you said (although my bufsize is larger on scale of a million or more, and my output rate is 1 MHz). Now I need to figure out all the timing and buffering so I can change data while the task is running without introducing any gaps in output. Thanks again.

0 Kudos
Message 4 of 4
(1,682 Views)