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.


Photo

Change multiple digital outs simultaneouslyd


  • Please log in to reply
4 replies to this topic

#1 mikelwrnc

mikelwrnc
  • Members
  • 17 posts

Posted 08 July 2015 - 11:10 AM

I'm using the labjack to send 8-bit messages to my EEG amplifier. I have FIO0-7 & GND wired to a DB-9 cable. When I use the python interface and do something like:

commands = []
for bit_num in range(8):
    commands.append(u3.BitStateWrite(bit_num,1))
d.getFeedback(commands)

I'm seeing (on the EEG side) slight delays in when those bits are actually switched on. It's only a millisecond or two between the first and last being set, but long enough that my eeg sees the output as multiple messages instead of a single 8-bit message. Is there any way to have it so that all the bits are written simultaneously, or at least much faster?



#2 LabJack Support

LabJack Support
  • Admin
  • 8677 posts

Posted 08 July 2015 - 11:19 AM

You will want to use the PortStateWrite class/command which can set all digital I/O simultaneously in one command/response:

 

PortStateWrite class: https://github.com/l...src/u3.py#L2218

PortStateWrite low-level: http://labjack.com/s...-guide/5.2.5.10



#3 mikelwrnc

mikelwrnc
  • Members
  • 17 posts

Posted 08 July 2015 - 01:05 PM

Thanks for replying so rapidly!

 

Unfortunately, I ran into a bit of trouble. It seems that PortStateWrite isn't able to set the state of FIO0-3. I can set FIO4-7 just fine, and I can also use BitStateWrite on FIO0-3 just fine. Any thoughts? Here's some code demonstrating what I'm experiencing:


>>> import u3
>>> d = u3.U3()
>>> d.debug = True
>>>
>>> #make sure we're starting at zero
... d.getFeedback(u3.PortStateWrite(State = [0,0,0]))
Sent:  [0x18, 0xf8, 0x4, 0x0, 0x18, 0x3, 0x0, 0x1b, 0xff, 0xff, 0xff, 0x0, 0x0, 0x0]
Response:  [0xfa, 0xf8, 0x2, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0]
[None]
>>> d.getFeedback(u3.PortStateRead())
Sent:  [0x14, 0xf8, 0x1, 0x0, 0x1a, 0x0, 0x0, 0x1a]
Response:  [0xfb, 0xf8, 0x3, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0]
[{'CIO': 0, 'FIO': 0, 'EIO': 0}]
>>> #yup, all zero
...
>>> #try to set FIO0
... d.getFeedback(u3.PortStateWrite(State = [int('00000001',2),0,0]))
Sent:  [0x19, 0xf8, 0x4, 0x0, 0x19, 0x3, 0x0, 0x1b, 0xff, 0xff, 0xff, 0x1, 0x0, 0x0]
Response:  [0xfa, 0xf8, 0x2, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0]
[None]
>>> d.getFeedback(u3.PortStateRead())
Sent:  [0x14, 0xf8, 0x1, 0x0, 0x1a, 0x0, 0x0, 0x1a]
Response:  [0xfb, 0xf8, 0x3, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0]
[{'CIO': 0, 'FIO': 0, 'EIO': 0}]
>>> #failure
...
>>> #try to set FIO2
... d.getFeedback(u3.PortStateWrite(State = [int('00000100',2),0,0]))
Sent:  [0x1c, 0xf8, 0x4, 0x0, 0x1c, 0x3, 0x0, 0x1b, 0xff, 0xff, 0xff, 0x4, 0x0, 0x0]
Response:  [0xfa, 0xf8, 0x2, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0]
[None]
>>> d.getFeedback(u3.PortStateRead())
Sent:  [0x14, 0xf8, 0x1, 0x0, 0x1a, 0x0, 0x0, 0x1a]
Response:  [0xfb, 0xf8, 0x3, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0]
[{'CIO': 0, 'FIO': 0, 'EIO': 0}]
>>> #failure
...
>>> #try to set FIO4
... d.getFeedback(u3.PortStateWrite(State = [int('00010000',2),0,0]))
Sent:  [0x28, 0xf8, 0x4, 0x0, 0x28, 0x3, 0x0, 0x1b, 0xff, 0xff, 0xff, 0x10, 0x0, 0x0]
Response:  [0xfa, 0xf8, 0x2, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0]
[None]
>>> d.getFeedback(u3.PortStateRead())
Sent:  [0x14, 0xf8, 0x1, 0x0, 0x1a, 0x0, 0x0, 0x1a]
Response:  [0xc, 0xf8, 0x3, 0x0, 0x10, 0x0, 0x0, 0x0, 0x0, 0x10, 0x0, 0x0]
[{'CIO': 0, 'FIO': 16, 'EIO': 0}]
>>> #success!
...
>>> #set all back to zero
... d.getFeedback(u3.PortStateWrite(State = [0,0,0])) #set back to zero
Sent:  [0x18, 0xf8, 0x4, 0x0, 0x18, 0x3, 0x0, 0x1b, 0xff, 0xff, 0xff, 0x0, 0x0, 0x0]
Response:  [0xfa, 0xf8, 0x2, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0]
[None]
>>> d.getFeedback(u3.BitStateWrite(0,1))
Sent:  [0x86, 0xf8, 0x2, 0x0, 0x8b, 0x0, 0x0, 0xb, 0x80, 0x0]
Response:  [0xfa, 0xf8, 0x2, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0]
[None]
>>> #yup, all zero
...
>>> #try BitStateWrite with FIO0
... d.getFeedback(u3.BitStateWrite(0,1))
Sent:  [0x86, 0xf8, 0x2, 0x0, 0x8b, 0x0, 0x0, 0xb, 0x80, 0x0]
Response:  [0xfa, 0xf8, 0x2, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0]
[None]
>>> d.getFeedback(u3.PortStateRead())
Sent:  [0x14, 0xf8, 0x1, 0x0, 0x1a, 0x0, 0x0, 0x1a]
Response:  [0xfc, 0xf8, 0x3, 0x0, 0x1, 0x0, 0x0, 0x0, 0x0, 0x1, 0x0, 0x0]
[{'CIO': 0, 'FIO': 1, 'EIO': 0}]
>>> #success!


#4 LabJack Support

LabJack Support
  • Admin
  • 8677 posts

Posted 08 July 2015 - 02:38 PM

I don't see this issue with our latest U3 firmware. Perhaps you are running older firmware which has an issue with PortStateWrite and FIO0-3. You can check what your current firmware version is with the following commands:

import u3
d=u3.U3()
print d.configU3()["FirmwareVersion"]

The latest version is 1.46 (beta is 1.49). Make sure you are running the latest firmware and see if that helps. You can find firmware files and firmware upgrading programs here (on Windows LJSelfUpgrade should already be installed):

 

http://labjack.com/support/firmware

 

If that isn't the issue, if FIO0-3 are analog inputs then PortStateWrite can't set the lines and PortStateRead will read them as zeroes. Make sure FIO0-3 are configured for digital I/O beforehand. For example:

#Set all FIOs to digital I/O
d.configIO(FIOAnalog=0)


#5 mikelwrnc

mikelwrnc
  • Members
  • 17 posts

Posted 09 July 2015 - 06:46 AM

Ah, I was indeed using an older firmware and updating to the latest fixes the issue. Thanks!




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users