Issue #5 resolved

BitBang - first retrieval of bb.port does not return correct value

Anonymous created an issue

Here's my code:

Python 2.7.1+ (r271:86832, Apr 11 2011, 18:05:24) [GCC 4.5.2] on linux2 Type "help", "copyright", "credits" or "license" for more information.

from pylibftdi import BitBangDevice bb = BitBangDevice() bb.port = 0x02 bb.port 2

(closed)

Then, ran Python again:

from pylibftdi import BitBangDevice bb = BitBangDevice() bb.port 0

Shouldn't bb.port still return 2?

Regards,

Levy

Comments (3)

  1. Anonymous

    Sorry, didnt check the preview. Here's the code again:

    >>> from pylibftdi import BitBangDevice
    >>> bb = BitBangDevice()
    >>> bb.port = 0x02
    >>> bb.port
    2
    [exit]
    

    Then I ran this:

    >>> from pylibftdi import BitBangDevice
    >>> bb = BitBangDevice()
    >>> bb.port
    0
    >>>
    
  2. Ben Bass repo owner

    Thanks for your report. I'm not convinced it's a problem though; creating a new BitBangDevice performs an 'open' operation on the device, which resets its state.

    In hardware terms, reading the port should give the value of inputs to the device rather than the last value written. I added the internal port latch behaviour (so reading it gives the last value written) to support / allow augmented assignment operations (which would require a read-modify-write) such as:

        bb.port ^= 1  # toggle bit zero
    

    I'll do some further work to confirm this is the case. There may be scope for adding an option to not re-initialise the device and try and pull the configuration out of it instead, but I'm not sure whether this is possible or not.

  3. Ben Bass repo owner

    The behaviour of reading 'port' has changed in the recent 0.9 release, which always gives the actual value read from the pins of the device for input pins.

    Reading the value of output pins doesn't make much logical sense, and the defined behaviour (that they report what was most recently written to them) is supported purely for read-modify-write operations within the process. Not planning to change that.

    Marking as resolved for now.

  4. Log in to comment