01-19-2023 05:24 PM
uint32 mxfASCBRxSamplingRead ( HMXF_BUFFER buffer,
// allocate buffer
if (rc == MAXT_SUCCESS)
{
rc = mxfRxSamplingBufferAlloc(channel, (UInt64)rxBufferSize, out sampBuf, IntPtr.Zero);
if (rc == MAXT_ERROR_BUFFER_ALLOCATED)
rc = mxfRxSamplingBufferGet(channel, out sampBuf);
}
// Host allocation
if (rc == MAXT_SUCCESS)
{
try
{
rxBuffer = Marshal.AllocHGlobal((int)rxBufferSize);
}
catch (OutOfMemoryException)
{
rc = MAXT_ERROR_MEM;
}
}
// Read and display recv records (1000 times)
while ((rc == MAXT_SUCCESS) && (c < 1000))
{
rc = mxfASCBRxSamplingRead(sampBuf, MXF_RXSAMPLING_FLAG_DEFAULT, 0, rxBufferSize, out msgCount, out byteCount, rxBuffer);
if ((rc == MAXT_SUCCESS) && (msgCount != 0))
{
p = rxBuffer;
for (i = 0; i < (Int32)msgCount; i++)
{
rec = (MXF_ASCB_SAMPREC)Marshal.PtrToStructure(p, typeof(MXF_ASCB_SAMPREC));
/* Extract Data, Log and Display Here */
rc = mxfASCBNextSamplingRecordPtrGet(p, out p);
}
}
}
Solved! Go to Solution.
01-19-2023 05:32 PM
The vendor has the API documentation and the installation files available on their website, so clearly not protected by NDA. I am therefore attaching the DLL and the .net node to this post for anyone who wants to try to crack this nut.
01-20-2023 08:02 AM
Disclaimer: I have very little experience with C#
The documentation says the methode expects a void* https://www.maxt.com/mxf/group__group___rx_sampling.html#gad8126b455c79d5faf31f575f63a2e78a
I imagine you can create the target object and pass a pointer to it to the library.
Stackoverflow says it works like this https://stackoverflow.com/questions/17339928/c-sharp-how-to-convert-object-to-intptr-and-back
So in LabVIEW
Maybe you can work with that.
01-20-2023 12:38 PM
That looks great!
I'm having an issue making the System.Runtime.InteropServices constructor. When I select that assembly in the constructor, I get no public classes that can be created. Any ideas what is causing that? I'm running 32 bit LV for this project.
01-20-2023 01:03 PM
@ChrisLudwig wrote:
That looks great!
I'm having an issue making the System.Runtime.InteropServices constructor. When I select that assembly in the constructor, I get no public classes that can be created. Any ideas what is causing that? I'm running 32 bit LV for this project.
That's not the assembly. "mscorlib" is the assembly, "System.Runtime.InteropServices" is the namespace within that assembly.
01-23-2023 02:29 PM
I follow now. Thanks for all the help. The code in the box is what I put together to go from the IntPtr back to LV data. Let me know if that looks wrong. Thanks again for all the help.
01-23-2023 05:51 PM - edited 01-23-2023 05:51 PM
I can’t comment on the actual correctness but if I haven’t miscounted something you create in total 7 refnums each time you run this code, that represent a .Net object and never close them. That will cause new memory to be allocated that is never freed! A classical memory leak!
01-24-2023 05:32 AM
Do you need to do the Alloc? I thought the Constructor allocated memory for itself?