Jump to content

Limitha

Members
  • Posts

    4
  • Joined

  • Last visited

Posts posted by Limitha

  1. Hi @attila

    I tried modifying the Digital_io.py code as shown,

     

    from ctypes import *
    from dwfconstants import *
    import sys
    import random
    import pandas as pd

    dwf = cdll.dwf

    hdwf = c_int()
    dwRead = c_uint32()
    iDevId = c_int()
    iDevRev = c_int()
    hzSys = c_double()
    devicename = create_string_buffer(64)
    serialnum = create_string_buffer(16)  
        
    dwf.FDwfEnum(c_int(0), byref(hdwf))
    print("Number of Devices: "+str(hdwf.value))

    dwf.FDwfEnumDeviceName (c_int(hdwf.value-1), devicename)
    dwf.FDwfEnumSN (c_int(hdwf.value-1), serialnum)
    dwf.FDwfEnumDeviceType (c_int(hdwf.value-1), byref(iDevId), byref(iDevRev))
    print("------------------------------")
    print("Device "+str(hdwf.value-1)+" : ")
    print("\tName: \'" + str(devicename.value) + "' " + str(serialnum.value))
    print("\tID: " + str(iDevId.value) + " rev: " + str(iDevRev.value))

    print("Opening first device")
    dwf.FDwfDeviceOpen(c_int(-1), byref(hdwf))

    if hdwf.value == hdwfNone.value:
        print("failed to open device")
        szerr = create_string_buffer(512)
        dwf.FDwfGetLastErrorMsg(szerr)
        print(str(szerr.value))
        quit()

    dwf.FDwfAnalogIOChannelNodeSet(hdwf, c_int(0), c_int(0), c_double(1.8))

    dwf.FDwfDigitalOutInternalClockInfo(hdwf, byref(hzSys))
    print("Internal frequency is " + str(hzSys.value/1e6)+" MHz")

    # enable output/mask on 8 LSB IO pins, from DIO 0 to 7
    pin_status = c_uint32()  
      
    # On DD the DIO-0 represents 24, 1 -> 25, 2 -> 26, 3 -> 27, 4 -> 28...
    # Here for 28 it is the 5 bit which is set by 10000
    pin=0x0010

    dwf.FDwfDigitalIOOutputEnableSet(hdwf, c_int(pin)) 
    dwf.FDwfDigitalIOOutputEnableGet(hdwf, byref(pin_status))
    print("Pin value is " + bin(pin_status.value)[2:])

    for i in range(int(hzSys.value)):
        data = str(random.randint(0, 50))
        # set value on enabled IO pins
        dwf.FDwfDigitalIOOutputSet(hdwf, c_int(int(data))) 
        
    dwf.FDwfDigitalOutConfigure(hdwf, c_int(1))  

    # fetch digital IO information from the device           
    dwf.FDwfDigitalIOStatus(hdwf) 
    # read state of all pins, regardless of output enable
    dwf.FDwfDigitalIOInputStatus(hdwf, byref(dwRead)) 

    #print(dwRead as bitfield (32 digits, removing 0b at the front)
    print("Digital IO Pins: ", bin(dwRead.value)[2:].zfill(16))

    dwf.FDwfDeviceClose(hdwf)

     

    I guess the frequency is limited in this case yeah? So if I need to get a higher frequency I need to use the out configuration?

     

    Regards,

    Limitha 

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

×
×
  • Create New...