07-16-2012 10:38 AM
Is there a C version that does what the MAX 1-D Interactive does? Or a solution to the problem below.
I got the MAX 1-D Interactive to work with my stepper motor. The hardware setup is at the bottom.
I am trying to write a C program in Visual Studio 2010 to control a stepper motor. I found an example program called 1D Straight Line Move.c in
C:\Program Files\National Instruments\NI-Motion\Documentation\Examples\NI-Motion Help\C
I copied the example file and the needed .h, .c and .lib files into a Visual Studio project. I changed the velocity, acceleration, and deceleration to match the values in the MAX 1-D Interactive. The solution builds, but when I run it I get the following error message
Run-Time Check Failure #0 - The value of ESP was not properly saved across a function call. This is usually a result of calling a function declared with one calling convention with a function pointer declared with a different calling convention.
Setup:
I am running the latest NI Motion Software.
PXI-7334 connected to UMI-7774 using I/O Motion cable
UMI-7774 connected to P70360 Stepper Driver using control cable
P70360 Stepper Driver connected to NEMA 23 (T21NRLC) using Orange (A-), Black (A), Yellow (B-), Red (B)
NEMA 23 is powered by 120V AC power supply
P70360 Stepper Driver is set using DIP Switches (I tried to use the P7000 software tool that came with it, but it never found the driver):
S1: 1
S2-1: Off
S2-2: On
S2-3: On
S2-4: On
S2-5: Off
S2-6: Off
S2-7: Off
S2-8: Off
S2-9: Off
S2-10: On
S2-11: On
S2-9: Off
07-16-2012 12:26 PM
When the error pops up I can hit Break or Continue. If I hit continue, the motor does run.
Running it a second time, I also get an error that the stack value around errorCode got corrupted.
It works but why do I see the errors?
07-17-2012 05:51 PM
Hi Random837461,
Are you using Visual C++ MFC? Also, were you able to get the orginal example working? This error is most likely the result of an incorrect parameter and/or pointer specification.
Best Regards,
07-18-2012 08:20 AM
No I am not using Visual C++ MFC. I am using an empty C++ project in Microsoft Visual Studio 2010. Although I eventually want to create a .exe file from this project so I'll have change project type.
The motor runs using MAX to control it.
It did run using the 1D Straight Line Move.c project, but it gave me the below errors. That night I unplugged it because the stepper motor gets hot. The next day MAX still moves the motor but the 1D Straight Line Move.c project doesn’t and I still get the errors below.
I am getting two errors: (I was getting the same errors yesterday)
Run-Time Check Failure #2 - Stack around the variable 'errorCode' was corrupted.
Run-Time Check Failure #0 - The value of ESP was not properly saved across a function call. This is usually a result of calling a function declared with one calling convention with a function pointer declared with a different calling convention.
I think the errors come from using the functions in flexmotn.h. The functions look like they are being used correctly, but I can't find where they are defined. They are probably defined in FlexMS32.lib.
I attached the files I am using.
I haven’t tried any of the other examples. 1D Straight Line Move.c looks like the simplest and closest to what I want to do.
07-19-2012 05:23 PM
HI,
I sounds like we have everything setup correctly on the hardware end. Additionally, I was able to run the code successfully in LabWindows CVI so I think we need to narrow the issue down.
What function call is the error occurring at? Also, is the error occurring only at the first call or is it on every call?
Finally, in Visual Studio 2010, the Run-Time Check Failure #0 error appears to be a known error (see this link).
Let me know if the other examples work.
07-20-2012 12:51 PM
I finially just call the ni.com support line yesterday. The Applications Engineer is trying to recreate the problem. I'll still answer your questions encase you already have an answer or for the next person with the same problem.
I got the code working again. I have two motors; one on axis 1 and one on axis 2. I checked that the code on both then the next day when I went back to the motor on axis 1 I forgot to change the axis number back to one. The errors still happen but the motor now runs.
The errors happen during run time. I added break points to the code and it looks like the main function returns then throws the error. I added a printf then getchar right before the return and it showed the same thing that main returns then errors. I commented all but a line of a flex function and I still got the errors.
07-20-2012 01:02 PM
I looked into that error and I am not sure it fits my case. I have __cdecl (/Gd) as my default calling convention. I do have /RTCs compiler option enabled. I don't think I am using a function that contains parameters that are larger than 64 kilobytes (KB). I do have parameters that are less than an int, so this error might have something to do with it. It also doesn't specify a solution or work around.
07-20-2012 01:05 PM
Also when I run their steps to reproduce, the error didn't show up.
09-04-2012 10:21 AM
Hi,
The solution to this problem has been added to the following KnowledgeBase article: Why Do I Get a Run-Time Error when Running the NI-Motion C Examples in Microsoft Visual Studio? Thank you for pointing this issue out to us and for your assitance in the troubleshooting phase.