Motion Control and Motor Drives

cancel
Showing results for 
Search instead for 
Did you mean: 

Flexmotion dll interface in .NET 4.0

I have a working solution for an older configuration that needs upgrading to a new PC target. The old configuration uses Flexmotion.dll (NI-Max version 7.0.0) to interface to a PCI-7344 motion controller running in .NET 2.0 on a Windows XP PC. New configuration is to upgrade to .NET 4.0 running on a Windows 7 (32 bit) PC. I installed the latest version of Flexmotion / ni-motion drivers (NI-Max version 8.5.1) and the driver is successfully communicating to the device for configuration through NI-Max. For the .NET programmatic interface I get an error when attempting to load the Flexmotion.dll:

 

System.BadImageFormatException: An attempt was made to load a program with an incorrect format. (Exception from HRESULT: 0x8007000B)

 

Example function declaration is as follows:

 

    <DllImport("FlexMotion32.dll", _

           Entrypoint:="flex_clear_pu_status", SetLastError:=True, CharSet:=CharSet.Unicode, _

           ExactSpelling:=True, CallingConvention:=CallingConvention.StdCall)> _

    Friend Function flex_clear_pu_status(ByVal BoardID As Short) As Integer

    End Function

 

Is the Flexmotion.dll interface to the ni-motion driver not compatible with .NET 4.0? Is there some way I can get the Flexmotion.dll to properly load? I though it was just a standard Win32 API.

 

0 Kudos
Message 1 of 4
(6,325 Views)

Hi MBrand, I get the same error, then I've build a wrapper like this :

 

++++++

class myFlexMotion_Wrapper_Class
{
[DllImport("FlexMotion32.dll")]
public static extern int flex_read_csr_rtn(Byte boardID, out UInt16 csr);
[DllImport("FlexMotion32.dll")]
public static extern int flex_check_move_complete_status(Byte boardID, Byte axisOrVectorSpace, UInt16 axisOrVSMap, out UInt16 moveComplete);
[DllImport("FlexMotion32.dll")]
public static extern int flex_read_error_msg_rtn(Byte boardID, out UInt16 commandID, out UInt16 resourceID, out Int32 errorCode);
[DllImport("FlexMotion32.dll")]
public static extern int flex_get_error_description(UInt16 descriptionType, Int32 errorCode, UInt16 commandID, UInt16 resourceID, [MarshalAs(UnmanagedType.LPArray)] byte[] charArray, out UInt32 sizeOfArray);
[DllImport("FlexMotion32.dll")]
public static extern int flex_set_op_mode(Byte boardID, Byte axisOrVectorSpace, UInt16 operationMode);
[DllImport("FlexMotion32.dll")]
public static extern int flex_reset_pos(Byte boardID, Byte axis, Int32 position1, Int32 position2, Byte inputVector);
[DllImport("FlexMotion32.dll")]
public static extern int flex_read_pos_rtn(Byte boardID, Byte axis, out int position);
[DllImport("FlexMotion32.dll")]
public static extern int flex_start(Byte boardID, Byte axisOrVectorSpace, UInt16 axisOrVSMap);
[DllImport("FlexMotion32.dll")]
public static extern int flex_stop_motion(Byte boardID, Byte axisOrVectorSpace, UInt16 stopType, UInt16 axisOrVSMap);
[DllImport("FlexMotion32.dll")]
public static extern int flex_configure_buffer(Byte boardID, Byte buffer, Byte resource, UInt16 bufferType, Int32 bufferSize, UInt32 totalPoints, UInt16 oldDataStop, double requestedInterval, out double actualInterval);
[DllImport("FlexMotion32.dll")]
public static extern int flex_write_buffer(Byte boardID, Byte buffer, UInt32 numberOfPoints, UInt16 regenerationMode, [MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 2)] Int32[] data, Byte inputVector);
[DllImport("FlexMotion32.dll")]
public static extern int flex_clear_buffer(Byte boardID, Byte buffer);
//by LIUK
[DllImport("FlexMotion32.dll")]
public static extern int flex_clear_pu_status(Byte boardID);

//Variables for motion control
Byte boardID; // Board Identification number
Byte axis; // Axis Number
Byte buffer = 1; // Buffer number
UInt16 moveComplete; // Move Complete status flag
UInt16 csr; // Communication Status Register
Int32 bufferSize = 100;
UInt32 numberOfPoints = 100;
double requestedInterval, actualInterval;
int currentPosition; // Current Position in counts or steps
Int32[] data = new Int32[100]; // Position array for buffered move

//Variables for error checking
UInt16 commandID;
UInt16 resourceID;
Int32 errorCode;
Int32 err;
byte[] charArray = new byte[500]; // Character Array containing the error message
UInt32 sizeOfArray = 500; // Size of the error message array, default to 256 for Marshalling

//Motion Constants Used
UInt16 NIMC_ABSOLUTE_POSITION = 0;
UInt16 NIMC_ABSOLUTE_CONTOURING = 5;
UInt16 NIMC_POSITION_DATA = 2;
UInt16 NIMC_NO_CHANGE = 0;
UInt16 NIMC_DECEL_STOP = 0;
UInt16 NIMC_MODAL_ERROR_MSG = 0x40;
UInt16 NIMC_POWER_UP_RESET = 32;

}

 

+++++++

 

I don't get the error, but some funcions doesn't work fine... 😞

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

I'm still working on this.. 

0 Kudos
Message 3 of 4
(5,231 Views)

LukeYZF71,

 

Which functions don't work properly? Have you referenced the arguments you are sending with the function guide ot make sure everything is copasetic there?

 

The function help can be found here: http://zone.ni.com/reference/en-XX/help/372134F-01/TOC95.htm

 

--------------------------------------
0 Kudos
Message 4 of 4
(5,200 Views)