Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't push data to eeprom #65

Closed
VadalTheGod opened this issue Mar 17, 2023 · 2 comments · Fixed by #66
Closed

Can't push data to eeprom #65

VadalTheGod opened this issue Mar 17, 2023 · 2 comments · Fixed by #66

Comments

@VadalTheGod
Copy link

Describe the bug
I'm correctly connect with eeprom but when i'm trying to push data into it it doesn't work.

To Reproduce
I think there's problem with eeUAWrite function in ftd2xx.py file where casting function works wrong

Expected behavior
Correctly casting types and pushing data to eeprom

Logs
File "/usr/local/lib/python3.9/dist-packages/ftd2xx/ftd2xx.py", line 577, in eeUAWrite call_ft(_ft.FT_EE_UAWrite, self.handle, buf, len(data)) File "/usr/local/lib/python3.9/dist-packages/ftd2xx/ftd2xx.py", line 131, in call_ft status = function(*args) ctypes.ArgumentError: argument 2: <class 'TypeError'>: expected LP_c_ubyte instance instead of c_char_Array_97

Desktop (please complete the following information):

  • OS: Linux
  • OS Version: Debian 11 Bullseye
  • Python Version: 3.9.2
  • FTDI driver version: newest FTD2XX

Additional context
I found a solution. It works correctly.
Original code look like:
def eeUAWrite(self, data: bytes) -> None: """Write data to the EEPROM user area. data must be a string with appropriate byte values""" buf = c.create_string_buffer(data) call_ft(_ft.FT_EE_UAWrite, self.handle, ptr, len(data))
I change second line as below:
def eeUAWrite(self, data: bytes) -> None: """Write data to the EEPROM user area. data must be a string with appropriate byte values""" ptr = c.cast(c.c_char_p(data),c.POINTER(c.c_ubyte)) call_ft(_ft.FT_EE_UAWrite, self.handle, ptr, len(data))

@snmishra
Copy link
Collaborator

@VadalTheGod Looks like you're right. Could you try if the following works:

def eeUAWrite(self, data: bytes) -> None:
    """Write data to the EEPROM user area. data must be a bytes object with
    appropriate byte values"""
    buf = (c.c_ubyte*len(data)).from_buffer_copy(data)
    call_ft(_ft.FT_EE_UAWrite, self.handle, buf, len(data))

@VadalTheGod
Copy link
Author

Sorry, that i haven't answered for a long time. I checked your code and it works correctly.

snmishra added a commit that referenced this issue Mar 28, 2023
snmishra added a commit that referenced this issue Apr 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants