2.1 Function of "plcOpen"


When system power on, PLC task will execute "plcOpen" and "plcOpen" initializes I/O, flag and variable to prevent malfunction. In this section, the PlcBlock structure is passed using the index &plc  (because PlcBlock defines the communication structure between NC and PLC). The format is as follows:

void PLCAPI plcOpen(struct Status &sts, struct PlcBlock &plc, unsigned short *PlcData, long *LongPlcData)

{

.

.

}


&sts is a pointer to Status Internal Data Structure. We can fetch data of Status by this pointer. For example: To fetch Manual on or off status by sts.state0.bManual.


&plc is pointer of PLC Block Internal Data Structure. We can fetch data of PLC Block by this pointer. For example: To fetch X axial positive limit by plc.spi0.bit.xplmt.


*PlcData is PLC data array address of machine parameter, and it needs declare a variable to save address. For example:

static unsigned short *para;


*LongPlcData is long data arry address of machine parameter, and it needs declare a variable to save address. For example:

static long *longPara;


As mention, this function is using to initialize I/O, flag and variable. In order to avoid misoperation of the auxiliary system during power-on, the important output point must be set to 1 or 0 according to the planning of the auxiliary device. Examples are as follows: (The run signal of inverter is turn off, flag of inverter is idle and spindle speed must zero when power on. We can set the initial output, flag and variable in this function.)

define inverterRun (plc.gdo[0].bit.bit00) //Output 0 is inverter run signal

                                         //1: turn on

                                         //0: turn off

int inverterFlag;  //inverter flag

int inverterSpeed; //inverter speed

enum{IDLE=0, START, FINISH};

void PLCAPI plcOpen(struct Status &sts, struct PlcBlock &plc, unsigned short *PlcData, long *LongPlcData){

 inverterRun = 0;

 inverterFlag = IDLE;

 inverterSpeed = 0;

}


Usually, flow control can not exist in this function.