libftdi Archives

Subject: Re: python ftdi.read_data

From: Chris Zeh <chris.w.zeh@xxxxxxxxx>
To: libftdi@xxxxxxxxxxxxxxxxxxxxxxx
Date: Thu, 19 Jan 2012 14:07:33 -0700
Hi Lazarus,

It's been awhile since I've worked with the libftdi library using
Python, and I think there might have been some SWIG changes since last
I used it, but have a look at this message from the mailinglist:
http://developer.intra2net.com/mailarchive/html/libftdi/2011/msg00154.html

At that time, you were required to create a pointer wrapper in order
to do reads from the device, like so:
#Read the Pins (Bitbang mode)
pins = ftdi.new_charp()
ret = ftdi.ftdi_read_pins(ftdic,pins)
print ftdi.charp_value(pins)

I vaguely remember seeing a message from someone who really knew SWIG
well and may have revamped the Python stuff. So, hope that helps, but
it may be completely irrelevant at this time :-)


Best regards,
Chris




On Thu, Jan 19, 2012 at 1:54 PM, Lazarus Longitudis <Lazarus-Long@xxxxxx> wrote:
>  Hi,
>
>  Maybee I call the function wrong.
>  Anyone with an example - the python examples do not include a read...
>  If I do:
>  new_data =3D ftdi.read_data(ftdic, wrote)
>  I get a seg fault....
>
>
>  best regards,
>  Lazarus
> -------- Original-Nachricht --------
>> Datum: Wed, 18 Jan 2012 14:05:36 +0100
>> Von: "Lazarus Longitudis" <Lazarus-Long@xxxxxx>
>> An: libftdi@xxxxxxxxxxxxxxxxxxxxxxx
>> Betreff: python ftdi.read_data
>
>>
>>  Hi,
>>
>>  I am working with the current git code.
>>  Was trying to use the python wrapper, it works mostly but the
>> ftdi.read_data call seems to be messed up.
>>
>>  Python says the function requires only two arguments, the context and an
>> integer, obviously the target buffer pointer is missing.
>>
>>  I have compared the swig generated ftdi_wrap.c against 0.19 and it is
>> clear to see that the parameter parsing is broken here.
>>
>>  any ideas?
>>
>>  0.19:
>>    if (!PyArg_ParseTuple(args,(char
>> *)"OOO:ftdi_read_data",&obj0,&obj1,&obj2)) SWIG_fail;
>>    res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_ftdi_context, 0 |  0 );
>>    if (!SWIG_IsOK(res1)) {
>>      SWIG_exception_fail(SWIG_ArgError(res1), "in method '"
>> "ftdi_read_data" "', argument " "1"" of type '" "struct ftdi_context *""'");
>>    }
>>    arg1 = (struct ftdi_context *)(argp1);
>>    res2 = SWIG_AsCharPtrAndSize(obj1, &buf2, NULL, &alloc2);
>>    if (!SWIG_IsOK(res2)) {
>>      SWIG_exception_fail(SWIG_ArgError(res2), "in method '"
>> "ftdi_read_data" "', argument " "2"" of type '" "unsigned char *""'");
>>    }
>>    arg2 = (unsigned char *)(buf2);
>>    ecode3 = SWIG_AsVal_int(obj2, &val3);
>>    if (!SWIG_IsOK(ecode3)) {
>>      SWIG_exception_fail(SWIG_ArgError(ecode3), "in method '"
>> "ftdi_read_data" "', argument " "3"" of type '" "int""'");
>>    }
>>    arg3 = (int)(val3);
>>    result = (int)ftdi_read_data(arg1,arg2,arg3);
>>    resultobj = SWIG_From_int((int)(result));
>>    return resultobj;
>>
>>  git:
>>    arg2 = &temp2;
>>    if (!PyArg_ParseTuple(args,(char *)"OO:read_data",&obj0,&obj1))
>> SWIG_fail;
>>    res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_ftdi_context, 0 |  0 );
>>    if (!SWIG_IsOK(res1)) {
>>      SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "read_data"
>> "', argument " "1"" of type '" "struct ftdi_context *""'");
>>    }
>>    arg1 = (struct ftdi_context *)(argp1);
>>    ecode3 = SWIG_AsVal_int(obj1, &val3);
>>    if (!SWIG_IsOK(ecode3)) {
>>      SWIG_exception_fail(SWIG_ArgError(ecode3), "in method '" "read_data"
>> "', argument " "3"" of type '" "int""'");
>>    }
>>    arg3 = (int)(val3);
>>    result = (int)ftdi_read_data(arg1,arg2,arg3);
>>    resultobj = SWIG_From_int((int)(result));
>>    if (SWIG_IsTmpObj(res2)) {
>>      resultobj = SWIG_Python_AppendOutput(resultobj,
>> SWIG_From_char((*arg2)));
>>    } else {
>>      int new_flags = SWIG_IsNewObj(res2) ? (SWIG_POINTER_OWN |  0 ) :  0 ;
>>      resultobj = SWIG_Python_AppendOutput(resultobj,
>> SWIG_NewPointerObj((void*)(arg2), SWIGTYPE_p_unsigned_char, new_flags));
>>    }
>>    return resultobj;
>>  fail:
>>
>> --
>> Empfehlen Sie GMX DSL Ihren Freunden und Bekannten und wir
>> belohnen Sie mit bis zu 50,- Euro! https://freundschaftswerbung.gmx.de
>>
>> --
>> libftdi - see http://www.intra2net.com/en/developer/libftdi for details.
>> To unsubscribe send a mail to libftdi+unsubscribe@xxxxxxxxxxxxxxxxxxxxxxx
>>
>>
>
> --
> Empfehlen Sie GMX DSL Ihren Freunden und Bekannten und wir
> belohnen Sie mit bis zu 50,- Euro! https://freundschaftswerbung.gmx.de
>
> --
> libftdi - see http://www.intra2net.com/en/developer/libftdi for details.
> To unsubscribe send a mail to libftdi+unsubscribe@xxxxxxxxxxxxxxxxxxxxxxx
>

--
libftdi - see http://www.intra2net.com/en/developer/libftdi for details.
To unsubscribe send a mail to libftdi+unsubscribe@xxxxxxxxxxxxxxxxxxxxxxx

Current Thread