SWIG & PYTHON : Failure in array_class

View: New views
2 Messages — Rating Filter:   Alert me  

SWIG & PYTHON : Failure in array_class

by Manu13 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hello,

I use array_class with success to declare buffer in Python and fill it it within C dll. Then I'm able to read values in my Python code.
Upgradding my code, i'm encountering a pb since few days. When I declare a new array_class object in Python (pReadingBufferLong = CommIP.longArray(iReadingBufferSize) ). Python fails and displays the "Python exe encounter a pb and need to close..." windows famous message.

I have got 2 globals arrays (2000 bytes and 20 bytes)
Then I used to 2 local arrays to get values transmitted by an another computer via my C dll. Pythons fails when the second arrays is declared :(

This is a part of the code and my configuration.

Is anyone meet the same problem or use array_class with success and notice any error in my  code implementation?

MaNu





 in CommIP.i:
%include "carrays.i"    // array_function not used
%array_class(S8, byteArray);
%array_class(S16, shortArray);
%array_class(S32, longArray);
%array_class(S64, longlongArray);

in ***.py :
def GetBufferPositionMsg(iIndex, PositionMsg, bUDP = False):
   
    global COMIPbck_SizeBufferUDP
    global COMIPbck_SizeBufferTCP
    global COMIPbck_PosMessage
    iBufferSize = COMIPbck_SizeBufferTCP
       
    #1- Get element size
    iElemSizeLong = ctypes.sizeof(ctypes.c_long)
   
    #2- convert pReadingBuffer in a raw data buffer (char*)
    pReadingBufferLong0 = CommIP.byteArray(iBufferSize)
    pRawDataBufferLong = CommIP.cdata(pReadingBufferLong0, iBufferSize)
   
    #3- Get raw data (from COMMIP dll)
    iDataSizeInByte = CommIP.commIP_getBufferDataTCP(pRawDataBufferLong, iIndex, 0)
   
    #4- copy data in appropriate buffer
    iReadingBufferSize = iDataSizeInByte/iElemSizeLong
    pReadingBufferLong = CommIP.longArray(iReadingBufferSize)
   CommIP.memmove(pReadingBufferLong, pRawDataBufferLong)
   
    #5- read value
    PositionMsg.iLenght          = pReadingBufferLong[0]
    PositionMsg.lIndex           = pReadingBufferLong[1]            

   
    return 1
#end GetBufferPositionMsg

Configuration :
Python 2.6
Boaconstructor 0.6.1
SWIG 1.3.40
OS Windows XP SP3

Re: SWIG & PYTHON : Failure in array_class

by Manu13 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Manu13 wrote:
 
   #4- copy data in appropriate buffer
    iReadingBufferSize = iDataSizeInByte/iElemSizeLong
    pReadingBufferLong = CommIP.longArray(iReadingBufferSize)
   CommIP.memmove(pReadingBufferLong, pRawDataBufferLong)
   
PB SOLVED,
source and destination buffers wasn't of the same size and cause side effects when I created arrays