Motion Control and Motor Drives

cancel
Showing results for 
Search instead for 
Did you mean: 

How do you change the PID parameters in Matlab via a DLL?

Here is a brief as to what I am doing:

    -I am using a PCI-7342 board to control two axes via MID-7652 box.

    -I have created a DLL in C, which contains the flex_load_pid_parameters() function.

    -This DLL is called from my Matlab program.

 

In the past, I created a program in C, which I initialised a PID struct and filled in all fields I then passed this struct to either the flex_load_pid_parameters() or I passed a value to the flex_load_single_pid_parameter() function and the PID values updated without a problem. My code looked something like this:

 

 

int ChangePIDFunction (PID myPIDstruct)

{

     int iErr;

     unsigned char ucBoardID=1, ucAxisNumber=1;

 

     iErr = flex_load_pid_parameters(ucBoardID, ucAxisNumber, &myPIDstruct, 0xFF);

 

     return iErr;

}

 

 

 

Now I am using DLLs and the syntax in my C code is correct, I have had it proofread and checked many times. I call the DLL from Matlab using the calllib() function into which I pass the completed struct. The C function in the DLL is exactly the same (except for the DLL part in the function header line) and looks something like this:

 

 

extern "C" __declspec(dllexport) int ChangePIDFunction (PID myPIDstruct)

{

     int iErr;

     unsigned char ucBoardID=1, ucAxisNumber=1;

 

     iErr = flex_load_pid_parameters(ucBoardID, ucAxisNumber, &myPIDstruct, 0xFF);

 

     return iErr;

}

 

 

And my Matlab code looks like this:

 

ReturnedValue = calllib('myDLLName', 'ChangePIDFunction', myPIDstruct)

 

 

However, when it reaches the flex_load_pid_parameters line in my DLL, I get an error message in the main Matlab window: "Error using calllib. Array must be numeric or logical or a pointer to one"

 

 

I know I can change the PID values in MAX but I need to keep this away from a user in order to prevent them from messing things up. I don't have access to LabView because it would mean spending a lot of money on a license when I already have a paid-for Matlab license.

 

Can someone please help me overcome this problem?

 

0 Kudos
Message 1 of 3
(5,281 Views)

Hi,

 

I've had a really good search through our documentation and website but there's no previous record of that error code. However, a quick google search turned up lots of things on MatLab user groups and the MathWorks forums.

 

MatWork's official stance is that the PCI 7342 is not supported in MatLab. They have a list of supported hardware here:
https://www.mathworks.co.uk/products/daq/supported/ni-daqmx.html#PCI

0 Kudos
Message 2 of 3
(5,215 Views)

Ok, thanks very much for your help.

0 Kudos
Message 3 of 3
(5,210 Views)