Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Pass through pointer to ECAT address
#1
Hi,

I'm working on an EtherCAT network, which may change in the future, and so am setting up my code to adapt to this. I'm using the "new PDO mapping name format" and the ability to set aliases on EtherCAT hardware to give consistent macro names, generated to ECATMap.pmh and .h.

Part of my network involves setting up amplifiers for motors. I want to pass through the appropriate ECAT addresses to set up for instance Motor[x].pDac or Motor[x].pAmpEnable, but using the macro names (rather that ECAT[0].IO[xxxx]) to protect from future mapping changes. However I have not been able to achieve this.

I have been using subprograms in a .pmc file, shown below. C1_Slot1_...is an example of the naming system I'm using, and is defined in ECATMap.pmh.

Code:
open subprog SetupMotors(void)
return;
// --------------------User Code Goes Here------------------------

sub: GetECATInfo(&FaultIO, &EnableIO, &DacIO)
switch (motorID)
{
    case 1:
         FaultIO = C1_Slot1_Inputs_EL1008_0002_6000_1_Input.a;
         EnableIO = C1_Slot1_Inputs_EL1008_0002_6010_1_Input.a;
         DacIO = C1_Slot1_Inputs_EL1008_0002_6020_1_Input.a;
         break;
    case 2:
         FaultIO = C2_Slot1_Inputs_EL1008_0005_6000_1_Input.a;
         EnableIO = C2_Slot1_Inputs_EL1008_0005_6010_1_Input.a;
         DacIO = C2_Slot1_Inputs_EL1008_0005_6020_1_Input.a;            
         break;
}

return;


sub: SetupMotorEtherCAT(void)
local lFaultIO;
local lEnableIO;
local lDacIO;

callsub sub.GetECATInfo(&lFaultIO, &lEnableIO, &lDacIO)

Motor[motorID].pDac = lDacIO;
Motor[motorID].pAmpEnable = lEnableIO;
Motor[motorID].pAmpFault = lFaultIO;

return;

close

Is there a neat way to go about it? I have tried doing this in C, but also no luck. I need to do this for lots of settings and motors, without changing the structure of existing code, keeping this information passed through a second subprogram.

Thanks,
markr
Reply
#2
As far as I can tell, this should work. Can you share the calling program?
Reply
#3
I've just made this as a test project, the calling program is simply a one line plc.
Code:
open plc 1

call SetupMotors.SetupMotorEtherCAT();

disable plc 1
close

The error message is
"C:...\setup motors.pmc(33,1) : Error : ( error #31) invalid data : Motor[P8196].pDac = L2"
Line 33 is Motor[motorID].pDac = lDacIO;
Reply
#4
An argument for a structure index must be an integer constant or local L-variable only (not a P-variable).
Reply
#5
Yep that fixes it, thank you!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)