LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

In labview 64bit, Use PostLVUserEvent with user data cluster, unhandled exception occured.

My labview is Labview 2009 64 bit, I use PostLVUserEvent to post message with cluster data to labview. The following is  the struct in dll:

 

typedef struct {
    int32 dimSize;
    uInt8 elt[1];
} TD1DINT8;
typedef TD1DINT8 **TD1DINT8Hdl;

typedef struct{
   int32       interruptSource;
   TD1DINT8Hdl portData;
}DIInterruptData, *PDIInterruptData, **HDIInterruptData;

 

In labview, the DIInterruptData corresponds to a cluster, in which there are a int32 integer and a uint8 array. 

It works well in labview 32bit. But in labview 64bit, unhanlded exception occured. why?

 

0 Kudos
Message 1 of 5
(2,879 Views)

Hi,

     please attach the VI you have tried.Then it will be more easy to suggest a solution.

----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Thanks as kudos only:)
0 Kudos
Message 2 of 5
(2,875 Views)

Thank you very much for your rapid answer. The attachment is the vi.

0 Kudos
Message 3 of 5
(2,867 Views)

The following is c++ code which calls PostLVUserEvent.

void BDAQCALL DiInterruptHandler::DiSnapEvent(void * sender, DiSnapEventArgs * args)
{
   PDIInterruptData eventData;
   Int32 startPort = m_owner->GetStartPort();
   Int32 portCount = m_owner->GetPortCount();

   //Allocate cluster pointer
   eventData = (PDIInterruptData)DSNewPtr(sizeof(DIInterruptData));
   eventData->interruptSource = args->SrcNum;

   //Allocate 1D array handle
   eventData->portData = (TD1DINT8Hdl)DSNewHandle(sizeof((*(eventData->portData))->dimSize) + portCount
      * sizeof((*(eventData->portData))->elt[0]));

   (*(eventData->portData))->dimSize = portCount;

   for (Int32 i = 0; i < portCount; ++i )
   {
      (*(eventData->portData))->elt[i] = args->PortData[(i + startPort) % args->Length];
   }
   PostLVUserEvent(*m_eventRef, (void*)eventData);

   //Clear array handle and cluster pointer
   DSDisposeHandle(eventData->portData);
   DSDisposePtr(eventData);
}

0 Kudos
Message 4 of 5
(2,866 Views)

Most likely the problem is alignment!

 

When declaring the data structures you should use the LabVIEW macros like this and make sure that you leave the alignment in the project settings to be the compiler default ones:

 

......

#include "lv_prolog.h"
typedef struct {
    int32 dimSize;
    uInt8 elt[1];
} TD1DINT8;
typedef TD1DINT8 **TD1DINT8Hdl;

typedef struct{
   int32       interruptSource;
   TD1DINT8Hdl portData;
}DIInterruptData, *PDIInterruptData, **HDIInterruptData;
#include "lv_epilog.h"

........

 

And the callback code could be somewhat improved in this way:

 

void BDAQCALL DiInterruptHandler::smileyvery-happy:iSnapEvent(void * sender, DiSnapEventArgs * args)
{
   DIInterruptData eventData;
   Int32 startPort = m_owner->GetStartPort();
   Int32 portCount = m_owner->GetPortCount();

   eventData.interruptSource = args->SrcNum;

   //Allocate 1D array handle
   eventData.portData = (TD1DINT8Hdl)DSNewHandle(sizeof(int32) + portCount);

   (*(eventData.portData))->dimSize = portCount;

   for (Int32 i = 0; i < portCount; ++i )
   {
      (*(eventData.portData))->elt[i] = args->PortData[(i + startPort) % args->Length];
   }
   PostLVUserEvent(*m_eventRef, &eventData);

   //Clear array handle
   DSDisposeHandle(eventData.portData);
}

 

Rolf Kalbermatter
My Blog
0 Kudos
Message 5 of 5
(2,695 Views)