Jump to content

As of July 17, 2015, the LabJack forums here at forums.labjack.com are shut down. New registrations, topics, and replies are disabled. All forums are in a read-only state for archive purposes.

Please visit our current forums at labjack.com/forums to view and make new posts. To post on the current forums, use your labjack.com login account. Your old LabJack forums login credentials have been retired. There are no longer separate logins for labjack.com and LabJack forums.


streamStop failed

  • Please log in to reply
1 reply to this topic

#1 ferryard

  • Members
  • 3 posts

Posted 08 October 2014 - 09:13 PM

Hello, I am new in using Labjack U3, I tried to make a stream data program using labjack python. Here is my code :

o_file = "data_log.csv"

import u3
import time

d = u3.U3()

try: d.streamStop()
except: pass

d.streamConfig(PChannels = [0], NChannels = [31], SamplesPerPacket = 1)

def MeasureData():
		for r in d.streamData():
			if r is not None:
				if r['errors'] or r['numPackets'] != d.packetsPerRequest or r['missed']:
					print "error : errors = %s, numpackets = %d, missed = %s" %(r['errors'],r['numPackets'],r['missed'])
	return r

def PrintData(r):
	chans = r['AIN0']
	for c in chans:
		print chans

loop = 0

	start = time.time()
	while loop < 10:
		with open(o_file, 'a') as f:
			f.write("%.4d %.2f s\n" %(loop, time.time() - start))


The data stream run well, but at the end of run, when the python reachs d.streamStop() it returns :


if results[2] != 0:

IndexError: list index out of range

As a result, I must unplugged and the plugged the LabJack if I want to run the same code.


Can anyone tell me why this might happen? Any suggestions how to solve this problem?


Thank you

#2 LabJack Support

LabJack Support
  • Admin
  • 8677 posts

Posted 09 October 2014 - 12:56 PM

You will need to set the ScanFrequency for your stream as demonstrated in the streamTest.py example. If you don't set this, the function configures an invalid scan rate (4,000,000Hz) which is causing problems on the U3 though it doesn't return an error code.


So configure your stream like this:

#Configures a scan rate (frequency) of 1000Hz (sample rate (50K Max) = NumChannels * ScanFrequency = 1000)
d.streamConfig(NumChannels = 1, PChannels = [0], NChannels = [31], SamplesPerPacket = 1, ScanFrequency=1000)

Note to set your scan frequency to 1-50,000Hz for a one channel scan. For faster rates you will need to set SamplesPerPacket = 25 or let it default to 25 by not setting it. This is needed for the best USB throughput.

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users