Measurement Studio for VC++

cancel
Showing results for 
Search instead for 
Did you mean: 

Why does my CIN run once, but gets a memory error the second time?

My CIN2 accepts a 3X3 matrix and does martix multiplication with a 3X1 matrix. The 3X1 matrix is defined in CIN2 using C code. CIN2 sends 3 correct values back to Labview. CIN2 works only the first time its executed. The second time that I run the VI CIN1 runs ok but CIN2 gets the following error The instruction at "0X008acd6b" referenced memory at "0X12345678". The memory could not be "read". I can see I have some type of memory problem, but nothing I've tried has helped. What do you think is wrong with CIN2?
Download All
0 Kudos
Message 1 of 8
(4,270 Views)
I just looked at your program very briefly. I'm always a little wary of malloc commands in a CIN. You are not allocating a great deal of memory, you might just want to declare thos arrays as local variables. If you are going to use malloc, make sure you check for null pointers. Besides that, make sure that when you get results back, that the results make sense. If they don't, it might mean that you are not referencing LV variables correctly, or that you have some alignment issues (LV uses struct packing of 1 and it is sometimes a factor)
0 Kudos
Message 2 of 8
(4,270 Views)
Thank You for taking the time to help me. Do I have to initialize these local variables in any special way?
0 Kudos
Message 5 of 8
(4,270 Views)
Like any other variable, you should make sure that you put something in before taking something out. Nothing special about using function local varaibles in LabVIEW CINs though.
0 Kudos
Message 6 of 8
(4,270 Views)
Aaron, I've put my CIN code into a DLL using Visual C++ ver6. I then call it from LabVIEW 6 using a Library Call Function. The function call executes, but I don't get the correct values returned from my function. How can I use the Visual C++ debugger to troubleshoot my code when I call it from LabView? I've tried to set Labview.exe as the Executable for debug session in the Project Settings->Debug and gave it the working directory and path to my dll. I can't set breakpoints to stop and look at my code. I don't know what's missing. Thank's in advance
0 Kudos
Message 7 of 8
(4,270 Views)
The method described in this KB always worked for me. It refers to using TestStand, but the same works for LabVIEW:

http://digital.ni.com/public.nsf/3efedde4322fef19862567740067f3cc/52f5bb7ae7f5a409862569ee0073ac53?OpenDocument
0 Kudos
Message 8 of 8
(4,270 Views)
Chuy,

I would strongly suggest you consider DLLs in VC++ for future code development. CINs were used in the days when LabVIEW didn't support DLLs; besides they are very hard to use and debug (as you've probably noticed).
With DLLs, you can accomplish the same tasks as with CINs and even more, and they are easier to debug and link to.

Just my 2 cents.

Azucena
0 Kudos
Message 3 of 8
(4,270 Views)
Thanks for your suggestion. I will try to put my code into DLL's and use that method.
0 Kudos
Message 4 of 8
(4,270 Views)