Motion Control and Motor Drives

cancel
Showing results for 
Search instead for 
Did you mean: 

How to call the National Instruments flexmotion32.dll from C

How to call the National Instruments flexmotion32.dll from C#? This is the particular Dll function that is giving me a headache:

FLEXFUNC flex_read_port_rtn (BOARD, u8 port, u16 FAR *portData);

Is there anything special I have to do to call this function since the DLL wants a pointer to an u16 FAR?

What exactly does FAR mean and what are the implications when calling from C#? Can I ignore FAR and just use a reference to an ushort (Uint16)? I have had success calling flex_set_port and changing the state of output bits. I�ve also successfully used the DllImport to communicate with the PCI-GPIB board using the National Instruments gpib-32.dll.

Here�s what I�ve tried so far, that always cause portDat
a to return �69� when the bit is ON or OFF.

Method 1:
// Read I/O Port
[DllImport("c:/WINNT/system32/FlexMotion32.dll",
EntryPoint="flex_read_port_rtn")]
static extern int flex_read_port_rtn(byte boardID, byte port,
[MarshalAs(UnmanagedType.LPArray)] uint[] portData);

�In the CdigitalIO object I have the following method:

public int readBitState(digInputNames index)
{
ushort[] portData = new ushort[1];
portData[0] = 0;
byte boardID = 1; //Motion card ID

//Make call to the Flexmotion32.dll function
status = flex_read_port_rtn(inputBit.boardID, inputBit.port, portData);
}



I now run the program with all the bits on port 1 off except for bit 0. When I run the program the port data comes back as �69� regardless of whether the input is ON or OFF.

Method 2:
// Read I/O Port
[DllImport("c:/WINNT/system32/FlexMotion32.dll",
EntryPoint="flex_read_port_rtn")]
static extern int flex_read_port_rtn(byte boardID, byte port,
ref ushort portData);

Same
problem, I get portData as �69�.

Any suggestions would be greatly appreciation.
0 Kudos
Message 1 of 2
(5,151 Views)
The second method you are using is the appropriate way to call the function. If your port is not changing, then it is probably because you haven't set your port direction properly. If you are trying to write to a DIO port, you must first configure its direction for output and if you are trying toread from it, you must first configure it for input. You can use the flex_set_port_direction function.
Message 2 of 2
(5,151 Views)