[C++-sig] Need to supply (char*) argument

Bill Davy Bill at SynectixLtd.com
Fri Apr 11 10:11:50 CEST 2008


Sorry if this is a bit simple but any help welcome.

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:

typedef unsigned __int8  u8;
typedef unsigned __int16 u16;

typedef int ErrorT;

class ViperUsbC
    {
    public:
    // snip snip
       ErrorT 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.

~*""*~.,,.~*""*~.,,~*""*~.,,.~*""*~.,,~*""*~.,,.~*""*~.,,.~*""*~.,

Privileged/Confidential information may be contained in this message. If you
are not the addressee indicated in this message (or responsible for delivery
of the message to such person), you may not copy or deliver this message to
anyone. In such case, you should destroy this message, and please notify us
immediately. Please advise immediately if you or your employer does not
consent to Internet e-mail for messages of this kind.

Opinions, conclusions and other information expressed in this message are
not given or endorsed by my firm or employer unless otherwise indicated by
an authorised representative independent of this message.

Although we utilise the most up to date virus checking procedures you should
carry out your own virus check before opening any attachment. We accept no
liability for any loss or damage which may be caused by software viruses.

~*""*~.,,.~*""*~.,,~*""*~.,,.~*""*~.,,~*""*~.,,.~*""*~.,,.~*""*~.,

Bill Davy, Synectix Limited, 12 King Alfred Way, Cheltenham, GL52 6QP,
England
Registered Office: as above Registered in England and Wales No 2946363
Telephone: +44 (0)1242 254411, Mobile: +44 (0)7866 451568, Fax: +44 (0)1242
256611

Work: mailto:Bill at SynectixLtd.com

Home: mailto:Bill at XchelSys.co.uk

Web: http://www.synectixltd.com/


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/cplusplus-sig/attachments/20080411/d24099d4/attachment.htm>


More information about the Cplusplus-sig mailing list