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.


U3 with two counters running at the same time

U3 Counters

  • Please log in to reply
1 reply to this topic

#1 DavidRS

  • Members
  • 1 posts

Posted 07 October 2014 - 05:08 AM


I am trying to use the U3 counters. I would like to be able to get both counting at the same time, which is proving difficult.

I am using python 2.7. The LJControlPanel says the unit has the latest f/w.


The code I am trying to run is:


    d = u3.U3()     # Get the 
    #print d.config()
    d.setDefaults()     # Put everything back to factory default
    #d.debug = True
    LED_delay = 1.0
    LEDloop = 0
    lastGUIcounter = GUIcounter
    exittest = 0
    #d.configIO(FIOAnalog = 15)
    start_time = time.time()
    LEDnext_time = start_time + LED_delay
    print temperatureC(d)
    mains_on_off( d, 0 )       # Off to start with
    #d.configIO(NumberOfTimersEnabled = 2)
    d.configIO(EnableCounter0=1, TimerCounterPinOffset = 4 )
    d.configIO(EnableCounter1=1, TimerCounterPinOffset = 5 )        
    #d.configIO(EnableTimer0=0, TimerCounterPinOffset = 6 )        
    #d.configIO(EnableTimer1=0, TimerCounterPinOffset = 7 )        
    print "Starting Loop"
    while ExitNow == 0:
        current_time = float( time.time() )
        if current_time > LEDnext_time: 
            count0 = d.getFeedback(u3.Counter0(Reset = False))
            print count0
            count1 = d.getFeedback(u3.Counter1(Reset = False))
            print count1      
            LEDnext_time += LED_delay
            LEDloop += 1
            #print LEDloop
            #print LEDnext_time
            loopCounter += 1
            print loopCounter
            # check GUI is still running, exit if it is not
        if GUIcounter > lastGUIcounter:
            lastGUIcounter = GUIcounter
            exittest = 0
            exittest += 1
        if exittest > 10:
            ExitNow = 1     # give up
    print "mainloop() exit"
The error I get is:
Starting Loop
Exception in thread Thread-2:
Traceback (most recent call last):
  File "c:\python27\lib\threading.py", line 810, in __bootstrap_inner
  File "c:\python27\lib\threading.py", line 763, in run
    self.__target(*self.__args, **self.__kwargs)
  File "ST230.py", line 91, in mainloop
    count0 = d.getFeedback(u3.Counter0(Reset = False))
  File "c:\python27\lib\site-packages\u3.py", line 754, in getFeedback
    raise LowlevelErrorException("\nThis Command\n    %s\nreturned an error:\n    %s" %  (culprit , lowlevelErrorToString(rcvBuffer[6])))
This Command
    <u3.Counter0( Reset = False )>
returned an error:
If I use one counter at a time, it works fine.
Any ideas?
Thanks & Regards


#2 LabJack Support

LabJack Support
  • Admin
  • 8677 posts

Posted 07 October 2014 - 12:00 PM

When enabling multiple counters with configIO, you need to do it in one call otherwise the second call overwrites the first call's settings. In your case, Counter1 is being enabled on FIO5 and since counter0 is not being set in that call it is defaulted to disabled. Try a call like this instead to enable the counters:

#Enable both counters starting at FIO4 (Counter0 on FIO4, Counter1 on FIO5)
d.configIO(EnableCounter0=1, EnableCounter1=1, TimerCounterPinOffset = 4)

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users