Motion Control and Motor Drives

cancel
Showing results for 
Search instead for 
Did you mean: 

How do I run an example NI-Motion C file in Visual Studio?

I am trying to run 1D Straight Line Move.c, which I found in

C:\Program Files\National Instruments\NI-Motion\Documentation\Examples\NI-Motion Help\C

 

I want to use it run a stepper motor.  Setup is at the bottom.  I attached my files.

 

I created an empty C++ project. (Although I eventually want to create a .exe file from this project so I'll have change project type) 

I added

1D Straight Line Move.c

NIMCExample.c

flexcomp.h

flexmotn.h

MotnCnst.h

MotnErr.h

nimcBasicTypes.h

NIMCExample.h

NIMCExampleData.h
FlexMS32.lib

 

I changed 1D Straight Line Move.c so that velocity, acceleration, deceleration matched the values in MAX.  I can run the motor in MAX.  Yesterday it ran using 1D Straight Line Move.c, but I unplugged it because the stepper motor gets hot.  And today it doesn't work.

 

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.

 

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

 

0 Kudos
Message 1 of 4
(7,548 Views)

Hi random,

 

I have a few questions for you.  You mentioned that the code you compiled successfully and ran the motor once, I assume that you made no additional changes to the code?  Does the motor still run successfully in MAX?  Lastly, when did you see the errors occur, during build or when running it?  Thanks!

Cole R.
National Instruments
Software Engineer
0 Kudos
Message 2 of 4
(7,534 Views)

I finially just call the ni.com support line yesterday.  The Applications Engineer said he would have to recreate the error on his end then debug from there, so he'll get back to me.  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.

 

I still works in MAX.

 

The errors happen during run time.  I commented all but a line of a flex function and I still got the error.  I put in break points with the uncommented code and it appears that when the main function returns the errors are thrown. 

0 Kudos
Message 3 of 4
(7,531 Views)

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.

0 Kudos
Message 4 of 4
(7,443 Views)