Jump to content
  • 0

The most basic usage question - Digital In


kevin vannorsdel

Question

I want to programmatically read the value from Digital input pin 0 ... I dont need any fancy recording or logging or triggering... I just want to query pin 0 and see if it is high or low.

How is something this simple done?  Not sure why I cannot find something this simple as an example or in the docs.  I am probably overlooking it. 

 

Thanks!

Link to comment
Share on other sites

7 answers to this question

Recommended Posts

  • 0

@attila,  are you saying the digital-io functions can be used on pins 0-23 of the digital discovery?

 

I don't think you are saying that but I am not sure exactly what you are saying...   can you please clarify?   I have not yet found an example for basic reading of the digital input pins 0-23 in any of the example directories...

 

 

Edited by kevin vannorsdel
Link to comment
Share on other sites

  • 0

The documentation in the SDK pdf is not very clear but I believe this works:

def read_din_pin(handle, dio_pin):

     val = ctypes.c_uint32()

     dwf.FDwfDigitalIOStatus(handle)

     dwf.FDwfDigitalIOInputStatus(handle, ctypes.byref(val))

     return (val.value >> dio_pin) & 1

 

I wish I understood what this function does:

     dwf.FDwfDigitalIOStatus(handle)

 

I also dont understand why        dwf.FDwfDigitalIOInputStatus()   returns a 32 bit value  - when there are a total of 40 pins in the digital discovery.  Shouldnt I need to use the 64 bit function? 

I also dont understand why I am using an IO funciton here to read the "input" pins.   I thought the IO functions were for the IO pins 24 -> 39

 So many questions.

Link to comment
Share on other sites

  • 0

Hi @kevin vannorsdel

Originally in this product the DIOs were intended for slower operations in StaticIO and Pattern Generator, and the DIN lines for high resolution Logic Analyzer.
You can use the FDwfDigitalIOInputStatus64 to retrieve 64bit value in which the 16 least significant bits are the DIO 24:39 an the following 24 are for DIN 0:23 I prepared this in case there will be need for it but you are the first one asking for. The FDwfDigitalIOInputStatus returns 32bit value with DIO 24:39 and DIN 0:15

image.png

Link to comment
Share on other sites

  • 0

OK this code seems to work-  wow...   finally.  -  Thank you!

 

def read_din_pin(handle, dio_pin):

    val = ctypes.c_longlong()

    dwf.FDwfDigitalIOStatus(handle)

    dwf.FDwfDigitalIOInputStatus64(handle, ctypes.byref(val))

    return (val.value >> 16+dio_pin) & 1

Edited by kevin vannorsdel
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...