1

Hello I tried to program EEPROM FTDI with using a FTDI library -> https://github.com/snmishra/ftd2xx/blob/master/ftd2xx/ftd2xx.py and D2XX FTDI Programming Guide

def eeProgram(self, progdata=None, *args, **kwds):
    if progdata is None:
       progdata = _ft.ft_program_data(**kwds)
    progdata.Signature1 = _ft.DWORD(0)
    progdata.Signature2 = _ft.DWORD(0xffffffff)
    progdata.Version = _ft.DWORD(2)
    call_ft(_ft.FT_EE_Program, self.handle, progdata)
    return None

I created instance to FTD2XX(Object)

handler = _ft.FT_HANDLE()
call_ft(_ft.FT_Open, 0, c.byref(handler))
device = FTD2XX(handler)

And call a function eeProgram

 device.eeProgram(0,0xffffffff,2,"FTDI","FT")
 device.close()

After that i got error:

Traceback (most recent call last):
  File "ftd2xx.py", line 678, in <module>    
    device.eeProgram(0,0xffffffff,2,"FTDI","FT")
  File "ftd2xx.py", line 573, in eeProgram
    progdata.Signature1 = _ft.DWORD(0)
AttributeError: 'int' object has no attribute 'Signature1'

I can connect and communicate with device via python but that function doesn't work. Anyone know what I should do to program a device with that function?

  • What do you get when you print `progdata` – Nick is tired Dec 12 '17 at 08:17
  • Please fix the indentation! – mrCarnivore Dec 12 '17 at 08:18
  • i got `0` when i call print before init progdata.Signature1, @mrCarnivore, fixed now –  Dec 12 '17 at 08:22
  • @pazucj: See my answer. Everything fits together... – mrCarnivore Dec 12 '17 at 08:25
  • What do you actually want these arguments to represent? We can't tell from your non-working code what the working code should do. – tripleee Dec 12 '17 at 08:51
  • These arguments shows a device info, Signature 1 and 2 are static and should be 0 and 0xffffffff, Version is a version of my device (I have device number =2). I could program a device configuration, I should add some others parameters like this progdata.`Description = _ft.STRING('Description Device')` –  Dec 12 '17 at 09:50

1 Answers1

2

As the error message shows: progdata is an int.

device.eeProgram(0,0xffffffff,2,"FTDI","FT")

First argument of eeProgram is progdata and it clearly is an int and not a class that might have a method or attribute Signature.

Caveat: The first argument is the 0, since device is the self? argument from the function definition. So you need to change the 0 to a class instance of whatever class eeProgram is a method of.

mrCarnivore
  • 4,638
  • 2
  • 12
  • 29
  • 2
    Maybe point out even more explicitly that the first argument 0 is what gets bound to the `progdata` keyword in the method call. – tripleee Dec 12 '17 at 08:26
  • When I call `device.eeProgram(None,0,0xffffffff,2,"FTDI","FT") ` i got function error after `call_ft` –  Dec 12 '17 at 08:34
  • I don't have idea how I could call function succesfully :( –  Dec 12 '17 at 08:42
  • @tripleee: Thanks for the hint I have extended my answer. – mrCarnivore Dec 12 '17 at 08:47
  • eeProgram is a function of class FTD2XX(object) , I called that function device.eeProgram, u write that I should call like this ? `device.eeProgram(device,0,0xffffffff,2,"FTDI","FT")` When I compile a program, the error isn't show but when I try to catch exception when it fails it shows me that function fails –  Dec 12 '17 at 09:27
  • I don't think we are in a position to tell you what to do, this just explains what's causing the error. I'm *guessing* the parameters you are trying to pass in are "the program" which should be written to the device, but if I'm reading this correctly, those should be `kwargs` i.e. something like `device.eeProgram(Signature1=0, Signature2=0xffffffff, Version=2, ick="FTDI", poo="FT")` where obviously we have no idea what the valid keywords are. – tripleee Dec 12 '17 at 09:49
  • Maybe see also https://stackoverflow.com/questions/1419046/python-normal-arguments-vs-keyword-arguments – tripleee Dec 12 '17 at 09:55
  • Also I guess `progdata` is never really necessary -- it looks like `device.eeProgram(progdata={'ick': 'poo'})` is basically equivalent to `device.eeProgram(ick="poo")` – tripleee Dec 12 '17 at 10:01
  • It would be easily if that program was mine, In just tried to check how this program works. In the description of topic i put a github link to this project. Maybe it explain You how it should works. Im learning python so I can't answer to all questions... –  Dec 12 '17 at 10:08
  • @pazucj: If at all this would be a topic for another question. – mrCarnivore Dec 12 '17 at 10:10
  • @tripleee, when I replaced function to def eeProgram(self, Sig1 = 0, Sig2 = 0xffffffff, Vr = 2, Man = 'FTDI', ManId = 'FT', Desc = 'FTxxxxx2', progdata=None, *args, **kwds)` and called it `device.eeProgram()` now I have error from Device = "INVALID_PARAMETER" , before i didnt get that error –  Dec 12 '17 at 11:56
  • No, don't change the `def`, change how you call it. – tripleee Dec 12 '17 at 11:57
  • @tripleee `device.eeProgram(progdata = {'Signature1': '0x00000000', 'Signature2': '0xffffffff', 'Version': '2', 'Manufacture': 'FTDI', 'ManufactureId': 'FT', 'Description': 'FTxxxx2' })` gets error `AttributeError: 'dict' object has no attribute 'Signature1' ` device.eeProgram(Signature1 = '0x00000000', Signature2 = '0xffffffff', Version = '2', Manufacture = 'FTDI', ManufactureId = 'FT', Description = 'FTxxxxx2' ) `returns `progdata = _ft.ft_program_data(**kwds) TypeError: an integer is required `but when I put `device` as 1st parameter call it returns failed function in catch exception –  Dec 12 '17 at 12:35
  • The final one otherwise looks correct; why do you pass strings? Like it says, it wants and expects an integer. `device.eeProgram(Signature1 = 0x00000000, Signature2 =0xffffffff, Version = 2, Manufacture = 'FTDI', ManufactureId = 'FT', Description = 'FTxxxxx2')` (though generally, the convention is to omit the spaces around the equals signs in this context). – tripleee Dec 12 '17 at 12:38
  • Hmmm, I guess if you want to pass `progdata = ` it should be something else, probably a `prog_data` structure you initialized previously. Sorry for the red herring. But this is just tangential commentary; focus on the previous comment if you are still struggling. – tripleee Dec 12 '17 at 12:41
  • my mistake sorry, when I compile code with fixed strings on signatures and version it returns invalid parameter and failed function : –  Dec 12 '17 at 12:52
  • progdata was initialized in eeProgdata, but structure program_data is initialized in other file in that project and shows: `class ft_program_data(Structure): pass ft_program_data._fields_ = [ # ftd2xx.h 417 ('Signature1', DWORD), ('Signature2', DWORD), ('Version', DWORD), ('VendorId', WORD), ('ProductId', WORD), ('Manufacturer', STRING), ('ManufacturerId', STRING), ('Description', STRING), ..... ]` –  Dec 12 '17 at 12:58