Prev: Time Delay NN with Early Stopping (Validation)
Next: it is not possible to apply an anonymous function
From: Thomas on 22 Apr 2010 22:02 I am trying to create a Matlab structure to mach with the nested-c structure and pass this Matlab structure to the C function. ----- The following structure is defined in the C Header ----- typedef struct myC_FrmBlkCluster { unsigned short XMIT_PL0; unsigned short XMIT_PL12; unsigned short XMIT_PL24; unsigned short XMIT_INP0; unsigned short XMIT_INP12; unsigned short XMIT_INP24; } myC_FrmBlkCluster_t; typedef struct myC_FrmBlk { unsigned int m_uColumnCount; unsigned short m_uBurstCount; unsigned short m_uClusterCount; unsigned short m_uResetConfig; FrameBlockCluster_t m_ClusterConfig[32]; <<--!! unsigned short m_uFrameBlockAddress; } myC_FrmBlk_t; ---- The C function ----- cfunction(myC_FrmBlk_t &myASICFrameBlock) I am trying to create a Matlab structure to mach with the nested-c structure so that I can pass this Matlab structure to the C function. (1)>> mlb_FrmBlkCluster= libstruct('myC_FrmBlkCluster') (2)>> get(mlb_FrmBlkCluster) %% looks no problem XMIT_PL0: 0 XMIT_PL12: 0 XMIT_PL24: 0 XMIT_INP0: 0 XMIT_INP12: 0 XMIT_INP24: 0 (3)>> mlb_FrmBlkTMP= libstruct('myC_FrmBlk') (4)>> get(mlb_FrmBlkTMP) m_uColumnCount: 0 m_uBurstCount: 0 m_uClusterCount: 0 m_uResetConfig: 0 m_ClusterConfig: [] <---- why do I get [] Here!! m_uFrameBlockAddress: 0 [Q1] Why is "m_ClusterConfig" in step 4 empty?? Shoul it be a 32 structures inside?? [Q2] How do I create a Matlab structure to mach with this nested-C structure??
From: Philip Borghesani on 26 Apr 2010 11:36 There is little support for arrays of structures with libstruct and no support for a nested array of structure type. Your choices are to create a mex file to access this structure or to flatten the array to multiple variables. Copy and modify your header file or create a prototype file with loadlibrary(...,'mfilename','name') and modify that to add multiple FrameBlockCluster_t variables to myC_FrmBlk: If you add the correct number of variables the c code does not need to be modified. > typedef struct myC_FrmBlkCluster > { > unsigned short XMIT_PL0; > unsigned short XMIT_PL12; > unsigned short XMIT_PL24; > unsigned short XMIT_INP0; > unsigned short XMIT_INP12; > unsigned short XMIT_INP24; > } myC_FrmBlkCluster_t; > > typedef struct myC_FrmBlk > { > unsigned int m_uColumnCount; > unsigned short m_uBurstCount; > unsigned short m_uClusterCount; > unsigned short m_uResetConfig; FrameBlockCluster_t m_ClusterConfig0; FrameBlockCluster_t m_ClusterConfig1; .... FrameBlockCluster_t m_ClusterConfigN; > unsigned short m_uFrameBlockAddress; > } myC_FrmBlk_t; > Be carefull this line: cfunction(myC_FrmBlk_t &myASICFrameBlock) suggests to me you are programming in c++ and are letting C++ features (a reference) slip into your interface. Phil
From: Thomas on 26 Apr 2010 13:15
Hello Phil: Thank you so much for your time and advice. I flat the array and it works properly. "Philip Borghesani" <philip_borghesani(a)mathworks.spam> wrote in message <hr4bt9$pcp$1(a)fred.mathworks.com>... > There is little support for arrays of structures with libstruct and no support for a nested array of structure type. Your choices > are to create a mex file to access this structure or to flatten the array to multiple variables. Copy and modify your header file > or create a prototype file with loadlibrary(...,'mfilename','name') and modify that to add multiple FrameBlockCluster_t variables to > myC_FrmBlk: If you add the correct number of variables the c code does not need to be modified. > > > > typedef struct myC_FrmBlkCluster > > { > > unsigned short XMIT_PL0; > > unsigned short XMIT_PL12; > > unsigned short XMIT_PL24; > > unsigned short XMIT_INP0; > > unsigned short XMIT_INP12; > > unsigned short XMIT_INP24; > > } myC_FrmBlkCluster_t; > > > > typedef struct myC_FrmBlk > > { > > unsigned int m_uColumnCount; > > unsigned short m_uBurstCount; > > unsigned short m_uClusterCount; > > unsigned short m_uResetConfig; > FrameBlockCluster_t m_ClusterConfig0; > FrameBlockCluster_t m_ClusterConfig1; > ... > FrameBlockCluster_t m_ClusterConfigN; > > > unsigned short m_uFrameBlockAddress; > > } myC_FrmBlk_t; > > > > Be carefull this line: > cfunction(myC_FrmBlk_t &myASICFrameBlock) > suggests to me you are programming in c++ and are letting C++ features (a reference) slip into your interface. > > > Phil > |