SWIG/C++
Matthieu Brucher
matthieu.brucher at gmail.com
Thu Apr 10 11:24:24 EDT 2008
Hi,
The error is generated because you are asking for a u8*, but the buffer is
not a u8*, perhaps a char* or even a void*. If you change the method
signature to either char* or void*, it may work like you want it to ;)
Matthieu
2008/4/10, Bill Davy <Bill at synectixltd.com>:
>
> Is there a better place to post such questions?
>
> Anyway, in the hope it is something simple, I would appreciate some help.
>
> I am adding some C++ code to Python. From Python I want to be able to
> read
> data from a target device, over USB. My software does all the hard work
> and
> I have a class:
>
> class ViperUsbC
> {
> public:
> // snip snip
> ERROR_T ReadSlaveMemory(u8 Slave, u16 Offset, u8* pData, u16
> Length);
> // Snip,snip
> };
>
> I use swigwin-1.3.34 to wrap it into a module called SHIP.
>
> In Python, I have:
>
> import SHIP
> ViperUsb = SHIP.ViperUsbC()
> Slave =7
> Offset = 0
> Length = 64
> Buffer = 'a' * Length
> print "type(Buffer)=%s" % type(Buffer)
> print "len(Buffer)=%s" % len(Buffer)
> Result = ViperUsb.ReadSlaveMemory(Slave, Offset, Buffer, Length);
>
> That fails with:
>
> type(Buffer)=<type 'str'>
> len(Buffer)=64
>
> Traceback (most recent call last):
> File "H:\Husky\HostPC\V1\SHIP\test1.py", line 1970, in -toplevel-
> ViperTests()
> File "H:\Husky\HostPC\V1\SHIP\test1.py", line 1884, in ViperTests
> Result = ViperUsb.ReadSlaveMemory(Slave, Offset, Buffer, Length);
> File "H:\Husky\HostPC\V1\SHIP\Release\SHIP.py", line 1757, in
> ReadSlaveMemory
> def ReadSlaveMemory(*args): return
> _SHIP.ViperUsbC_ReadSlaveMemory(*args)
> TypeError: in method 'ViperUsbC_ReadSlaveMemory', argument 4 of type 'u8
> *'
>
>
> How do I provide a buffer into which to read the data? It would not be
> intolerable to provide another layer using %extend, but I feel sure this
> should be automagic.
>
> Thanks in advance
> Bill
>
> PS This is a very small part of a much larger project so I cannot supply
> complete source code.
>
>
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
--
French PhD student
Website : http://matthieu-brucher.developpez.com/
Blogs : http://matt.eifelle.com and http://blog.developpez.com/?blog=92
LinkedIn : http://www.linkedin.com/in/matthieubrucher
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20080410/b85f3c60/attachment-0001.html>
More information about the Python-list
mailing list