« Close

Datasheets and User Guides

App Notes

Software & Driver - DAC# (16-bit): IOType=38,39

Table DAC 16 bit Command Response

DAC# (16-bit), 3 Command Bytes: 
0 IOType = 38, 39
1 Value LSB
2 Value MSB
0 Response Bytes: 

This IOType controls a single analog output.

  • Value: 0=Minimum, 65535=Maximum.



I need help on using stream mode ’d.streamData(convert = False).next()’ on U6 device parallel with ‘d.getFeedback( u6.DAC16( DACaddress, DACout ) )’, where DACaddres = int(1) and DACout = int(x) where x is number between 0 and 65500, and of course d = u6.U6().I’m developing an application that samples the microphone signal with 44000Hz. Therefore I use stream mode configuration. Every 27ms stream mode returns 1200 samples. I use multi-threading with 3 threads. First thread is for reading AIN0 channel (in stream mode), second in for some calculations on the read data, and the third is for writing on DAC1. First thread is driving the second one by passing signal values using Queue. The second thread is driving the third one by passing one value also using Queue. If I’m using only first two threads everything works OK, but when I implement the third thread I get some error (approximately after 1 minute). So my question is: can I use stream mode reading in one thread and getFeedback command to write on DAC1 in another? Is there any other way how to realize stream mode reading and write to DAC parallel?


Below is pseudo code where I get error in the write thread.



def read(out_q,d):

                d = d


                while running:

                               reading = device.streamData(convert = False).next()

                               data = copy.deepcopy(reading)




def calculation(in_q, out_qqq):

                while running:

data = in_q.get()

                                realdata1 = device.processStreamData(data['result'])

                               ……calculate SPL_MAIN value….. (One value each 27ms)



def write(in_qqq,in_qdac,d):

                d = d

                MAX_DAC = 65000

DACaddress = 1

                while running:

                               DACout = in_qqq.get()

                               if DACout < 0:

                                               d.getFeedback( u6.DAC16( DACaddress, 0 ) )

                               if DACout > MAX_DAC:

                                               d.getFeedback( u6.DAC16( DACaddress, MAX_DAC) )


                                               d.getFeedback( u6.DAC16( DACaddress, DACout ) )

                d.getFeedback( u6.DAC16( DACaddress, 0 ) )


q = Queue.Queue()

qqq = Queue.Queue()


thr_read = Thread(target=read, args=(q,d),kwargs={})

thr_calculation = Thread(target=calculation, args=(q,qqq,d), kwargs={})

thr_write = Thread(target=write, args=(qqq,d),kwargs={})










You are most likely running into stream buffer overflow errors.  Your DAC call will block/stall streamData calls as only one USB communications can happen at a time for thread safety, and causing delays in your stream read loop at fast data rates can lead to stream buffer overflows. You will need to limit your DAC calls while streaming to prevent this, so put delays (sleeps) between your DAC writes and see if that helps.

pintolipar@gmail.com's picture


Problem is regarding U6 device, stream mode multichannel reading in PYTHON (Linux).

I’m using U6 device for reading ADC, reading and writing FIOs and writing on one DAC. Up to now I’ve been reading only one analogue input (ch1) in a stream mode at sampling frequency 48 kHz. Everything works fine up to a point when I configure U6 device to read multiple channels. I know that U6 channel reading is multiplexed, so scanning frequency should be set correctly.

So here is simplified code, just to explain the problem I get.

d = u6.U6()


d.streamConfig( NumChannels = 2, ChannelNumbers = [ 0, 1 ], ChannelOptions = [ 0, 0 ], SettlingFactor = 1, ResolutionIndex = 1, ScanFrequency = 12000)



except Exception:





count = 0

while count < 10:

                reading = d.streamData(convert = False).next()

                realdata = d.processStreamData(reading['result'])

                data1 = realdata['AIN0']

                data2 = realdata['AIN1']

                print data1[0:5]

                print data2[0:5]

                print '\n'

                count += 1




I use U6 to read microphone signal. If I configure d.streamConfig() to read only one channel (one microphone) I get proper values. But when configure two or four channels, the problem appears. Values in all channels are almost the same and they are totally incorrect. Configuring one channel, first 5 values looks something like:

[0.001710138258204097, 0.001710138258204097, 0.002026007950917119, 0.002026007950917119, 0.001710138258204097]


Configuring two channels [0,1] I get something like:

[-0.1770376501190185, -0.1767218418935954, -0.1767218418935954, -0.1773534583444416, -0.1776692665698647]

[-0.1767218418935954, -0.1770376501190185, -0.1770376501190185, -0.1770376501190185, -0.1773534583444416]


Bout channels are connected on the same microphone, so I should get values in same range as I get it if I’m reading only one channel. Whenever I run the program, I get same numbers in two or more channel reading configuration.Besides, it’s not logical to get only negative values when reading sound pressure!

What I’m doing wrong here? It must be something with settings or drivers I’m using, because in your application LJstreamUD two channel reading works just fine!

LabJack Support's picture

Codewise nothing jumps out as being wrong except for the streamStop call in your exception handler is missing parenthesis. With your AIN0 and AIN1 connection from the same microphone, and only streaming only AIN0 are you seeing the 0.0017 or -0.177 readings. I'm just checking if the multiple connections are causing the difference in the readings regardless of the number of channels being streamed. Also, what is your streamConfig call when streaming one channel?

pintolipar@gmail.com's picture

Thanks for d.streamStop comment. That part of the code was not working OK and I didn’t see parenthesis is missing :).

AIN0 and AIN1 are connected on the same microphone. If I configure only AIN0 I get right values in rage of -+0.002. My one channel configuration is:

d.streamConfig( NumChannels = 1, ChannelNumbers = [ 0], ChannelOptions = [ 0], SettlingFactor = 1, ResolutionIndex = 1, ScanFrequency = 12000)

When configure AIN0 and AIN1 values should be almost the same (comparing AIN0 and AIN1) and should be in rage of -+0.002 (when the sound level in low). But instead I get constant values of -0.177 in a return python list.

If I connect U6 to LJstreamUD and configure 2 channel reading, it works OK. 4 channels reading in LJstreamUD also works OK.

LabJack Support's picture

Try the latest LabJackPython on GitHub and see if that helps:


I found a bug when using a U6-Pro and the processStreamData method where is was using the high-resolution calibration constants by mistake when converting the voltage. If you are using a U6-Pro, then this might be what you are seeing and the issue was fixed a while ago in the UD driver (what LJStreamUD is using).

pintolipar@gmail.com's picture

After a month of hard work I was able to find a solution for the mentioned problem. As you said, the problem lay in a calibration function ‘getAinVoltCalibrated’.  When I was using C code example ‘u6Stram’ and configuring multi-channel stream, same problem occur as in the case of Python. So I rewrite calibration procedure in C code (found formula on your website), and now I get correct data.

I have also update drivers from mentioned webpage, but the problem remains. Therefore I make new shared library ‘LJfun.so’ which include ‘u6.c’ and ‘u6stream.c’ functions and make a link to ‘liblabjackusb.so.2.5.3’ shared library. I also make a python library ‘PyLJlib’ with all functions I need to communicate with U6 device. Please check ‘getAinVoltCalibrated’ and remove bug for other users. I assume Python ‘U6’ library also uses same ‘getAinVoltCalibrated’.

So if there is someone with the same problem, I can give him mine solution. My email is [email protected]

LabJack Support's picture

The Python and C/C++ code to calibrate binary to analog voltage differ a little. Looking at the C/C++ function getAinVoltCalibrated, for streaming it should work correctly when passing a resolutionIndex < 8 to getAinVoltCalibrated, otherwise it tries to use high resolution calibration constants. Keep in mind also when using the getAinVoltCalibrated(C)/binaryToCalibratedAnalogVoltage(Python), you need to set the correct gain for the proper calibration constant to be applied.

What does your code for applying the calibration constants look like?