©2005 ge fanuc automation, inc. all rights reserved pacsystems training programmer’s toolkit

22
©2005 GE Fanuc Automation, Inc. All Rights Reserved PACSystems Training Programmer’s Toolkit

Upload: noah-freeman

Post on 24-Dec-2015

217 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: ©2005 GE Fanuc Automation, Inc. All Rights Reserved PACSystems Training Programmer’s Toolkit

©2005 GE Fanuc Automation, Inc.All Rights Reserved

PACSystems

Training

Programmer’s

Toolkit

Page 2: ©2005 GE Fanuc Automation, Inc. All Rights Reserved PACSystems Training Programmer’s Toolkit

©2005 GE Fanuc Automation, Inc.All Rights Reserved

New 32 bit C-Programmer's Toolkit Overview Series 90-70 C-Toolkit vs. PACSystem RX7i C-Toolkit Steps for Developing a C application for the RX7i Steps for migrating an existing Series 90-70 C-Toolkit application intoPAC RX7i Active Sessions

Demos ‘Hands on’

Page 3: ©2005 GE Fanuc Automation, Inc. All Rights Reserved PACSystems Training Programmer’s Toolkit

©2005 GE Fanuc Automation, Inc.All Rights Reserved

New 32 bit C-Programmer's Toolkit Overview

New C-Toolkit supports:

C Blocks (Does not support C Programs) C global, static and local/automatic variables Retentive and non-retentive variables Subset of Standard C Library functions PLC Interface functions and macros which:

- Access user memory - Carry out miscellaneous PLC functions such as service requests- Read/Write memory from some modules on the bus- Access and generate PLC faults

Page 4: ©2005 GE Fanuc Automation, Inc. All Rights Reserved PACSystems Training Programmer’s Toolkit

©2005 GE Fanuc Automation, Inc.All Rights Reserved

Series 90-70 C-Toolkit vs. PACSystem RX7i C-Toolkit

Series 90-70 functionality with the following changes...

PACSystem C-Toolkit uses 32 bit C code generation vs. 16 bit

C Blocks can be as large as all of 'user space' (10 MB) vs. 64K

Uses GNU C compiler vs. Microsoft Compiler 

PLC Read/Write memory functions required instead of macros

for writing to Discrete memory if overrides and transitions are

to be respected

Set of non-standard C library routines (Microsoft specific) are

not supported for this release

Changes to interface on some PLC C functions (ex. Bus

read/write functions instead of VME read/write functions)

Page 5: ©2005 GE Fanuc Automation, Inc. All Rights Reserved PACSystems Training Programmer’s Toolkit

©2005 GE Fanuc Automation, Inc.All Rights Reserved

Series 90-70 C-Toolkit vs. PACSystem RX7i C-Toolkit

Series 90-70 functionality with the following changes... (cont.)

Serial Read/Write functions instead of printf function

Miscellaneous (retentive/non-retentive syntax, GefMain() start

location, int type is 32 bit vs. 16 bit etc. )

C Standalone programs are not supported in this release.

C Debugger on PLC is not provided on RX7i 1st release

Cygwin C Debugger available for PC debugging

Page 6: ©2005 GE Fanuc Automation, Inc. All Rights Reserved PACSystems Training Programmer’s Toolkit

©2005 GE Fanuc Automation, Inc.All Rights Reserved

Steps for Developing a C application for the RX7i

1. Install C-Toolkit

2. Develop C Code for C Block

3. Compile C Code

4. Import C Block into Logic Developer PLC

5. Call C Block from LD Logic

6. Store and Execute C Block on the PLC

Page 7: ©2005 GE Fanuc Automation, Inc. All Rights Reserved PACSystems Training Programmer’s Toolkit

©2005 GE Fanuc Automation, Inc.All Rights Reserved

Process Diagram

Use Editor ofChoice to write C

block

/* myCFile.c */#include <stdio.h>#include <Pend1PLC.h>int glob1 = 1;char glob2[] = "string";int glob3;int glob4;int GefMain(int *x1, int *y1){ /*write x1 to %Q1 as double */ WritePlcDword(Q_MEM, 1, *x1) ; if (*y1 == *x1) return OK; else return ERROR;}

Use DOS command lineenvironment to compile andlink C block for Pendulumusing GNU compiler/linker:c:\compileCPACRX7imyCFile

Install C Toolkitwhich installs the

GNU compiler andGEF header fileson the user's PC

User Receives CToolkit which

includes CD andDocumentation

myCFile.gefElf in ELF format:text: GefMain() WritePlcDword() ; etc.data: glob1=1read-only data: "string"bss: glob3, glob4

Import myCFile.gefElf intothe programmer folder.

Programmer produces a CBlock file ready for downloadto PLC

PLC File Storage:/Root - [] Ram -[] target1 -[] logic -[]myProgram -[] myLadder -[]C Block file.LOG

C Run-TimeLibrary (remove

some funcs suchas malloc())

Pendulum TargetLibrary (headers

only - code locatedin Pendulum FW)

Load into usermemory

Execution

Installation

Compile in Cygwin (freeware) environment as aconsole application linked with PendulumTarget Library stubs which can be modified bythe user to simulate PLC activity. Use debuggerto debug code.

Develop C block

Compile/Debug for Simulation

Compile for PLC Import to programmer andstore to PLC

Store Module into PLC Memory

From the Programmer:- Put PLC in Run mode- Enable the C Block- C Block Runs each sweep it is enabled- Output (ENO) from C Block is determined by the return value from the C Block.

System SharedLibrary:WritePlcDword() ;

myCFile module stored in PLC memory:

0x00003000: GefMain()0x0000300C: WritePlcDword() ;0x00003131: glob1=10x00003135: glob2 = "string"0x00003178: glob3=00x0000317c: glob4 =00x00003198: glob1=1 (copy)

Pendulum TargetStub Library

Page 8: ©2005 GE Fanuc Automation, Inc. All Rights Reserved PACSystems Training Programmer’s Toolkit

©2005 GE Fanuc Automation, Inc.All Rights Reserved

Step 1 : Install the C-Toolkit

Page 9: ©2005 GE Fanuc Automation, Inc. All Rights Reserved PACSystems Training Programmer’s Toolkit

©2005 GE Fanuc Automation, Inc.All Rights Reserved

Step 2 : Develop C Code for C Block

1. The user develops a C Block using an editor of choice (CodeWright, Microsoft Visual Studio, NotePad etc.).

2. In order to use the Target Library functions and macros, the user must use the following line at top of the C file: #include <PACRX7iPlc.h>

3. In order to use the C Run-Time Library functions, the user must include one of more of the following files as appropriate at the top of the C file:

#include <stdio.h> /* Input/Output */#include <math.h> /* Math */#include <stdlib.h> /* Math, Data Conversion, Search */#include <string.h> /* String Manipulation, Internationalization */#include <time.h> /* Time */#include <ctype.h> /* Character Classification and Conversion */#include<GefCLib.h> /* non-standard C functions provided for compatibility with the 90-70.

Only a small subset of functions are supported in Release 1 */

Page 10: ©2005 GE Fanuc Automation, Inc. All Rights Reserved PACSystems Training Programmer’s Toolkit

©2005 GE Fanuc Automation, Inc.All Rights Reserved

4. After including the appropriate header files, the user writes their C block using library calls as needed to implement the desired functionality. The user’s C Block file or set of C Block files must have one and only one function titled “GefMain” to act as the entry point. A short example is shown below:

/* myCFile.c */#include <stdio.h>#include <PACRX7iPlc.h>int status;int status2 = 1;char failMessage[] = “Failure in myCFile”;int failCount = 0; int GefMain(int *x1, int *y1){ if (*x1 != 0) { RW(10) = *x1; /*write x1 to %R10 as word */ return GEF_EXECUTION_OK; } else { status = GEF_EXECUTION_ERROR; status2 = failCount; failCount++; return status; }}

Step 2 : Develop C Code for C Block(cont.)

Page 11: ©2005 GE Fanuc Automation, Inc. All Rights Reserved PACSystems Training Programmer’s Toolkit

©2005 GE Fanuc Automation, Inc.All Rights Reserved

Step 3 : Compile C Code

After developing a C Block as described in the previous step, the C Block must be compiled to create a relocatable object file that can be loaded into the PLC.

Open a DOS box either directly or by double clicking on the PACSystems(tm) C Toolkit icon on their desktop and then navigates to the project directory containing the C block file.

For a C file called “myCFile” the user runs the compiler by typing in: compileCPACRX7i myCFile

If there are errors or warnings, they are noted on the screen. The file is placed in a subdirectory under the user’s project directory called “plc” so that it is clear which file is intended for download to the PLC.

Page 12: ©2005 GE Fanuc Automation, Inc. All Rights Reserved PACSystems Training Programmer’s Toolkit

©2005 GE Fanuc Automation, Inc.All Rights Reserved

Step 4 : Import C Block into Logic Developer PLC

1) Right click on the Program Blocks element under Logic.

2) Select Add C Block

3) Navigate to the location of the *.gefElf file and select the file

4) Access properties of the C Block to set up the correct number of

input/output parameters.

5) Use a Call instruction in the ladder

6) Provide the name of the C Block to the Call instruction.

7) Provide reference memory locations for each of the inputs and

outputs of the C Block.

Page 13: ©2005 GE Fanuc Automation, Inc. All Rights Reserved PACSystems Training Programmer’s Toolkit

©2005 GE Fanuc Automation, Inc.All Rights Reserved

The input parameters to the main block (x1 and y1) are derived from the input/output parameters in the ladder program that calls the C Block. Input parameters are always passed as pointers. An example is shown below:  

For this example, x1 points to the memory location of %R1 and y1 points to the memory location of %R2. The least significant bit of the main function return value determines the output of the myCBlk CALL function block.

 

Step 5 : Call C Block in LD Code

Page 14: ©2005 GE Fanuc Automation, Inc. All Rights Reserved PACSystems Training Programmer’s Toolkit

©2005 GE Fanuc Automation, Inc.All Rights Reserved

Step 6 : Store and Execute C Block on the PLC

Using the programmer to Run the C Block:

1) Go online with the PLC.

2) Store the program to the PLC

3) Put the PLC in Run mode

4) Enable the Call to the C Block

Page 15: ©2005 GE Fanuc Automation, Inc. All Rights Reserved PACSystems Training Programmer’s Toolkit

©2005 GE Fanuc Automation, Inc.All Rights Reserved

Step 7 : Debugging C Blocks

Two Options…

On PLC

Use serial port write functions to output messages and data values at strategic points in the C Block.

Reserve reference memory locations as indicators of C Block operation

On PC Create C Test driver code that calls the C Block.  For example: int main(int argc, char *argv[])

{    initCBlock(); /* creates ref memory and initializes pointers to that memory*/    GefMain(&RB(8,0), &Ib(1000), &Mb(500)); /* calling main passing pointers                                               to %R8, %I1000 and %M500 and                                               passing a constant parameter */    return 0;}

Page 16: ©2005 GE Fanuc Automation, Inc. All Rights Reserved PACSystems Training Programmer’s Toolkit

©2005 GE Fanuc Automation, Inc.All Rights Reserved

Add code to the PLC C stub functions to simulate the desired PLC behavior.

Compile C Block for the PC using the following command: 

compileCDebugPACRX7i myCProgram 

Run the Cygwin debugger using the following command:

debugPACRX7i pc\myCProgram.exe 

This will bring up a Windows based debugger that allows setting break points,

single step, view and change memory, etc. 

The application can also be run at the DOS prompt with the following command:

runPACRX7i pc\myCProgram.exe  Debugging in this case would require the use of printf to indicate program flow and

state.

Step 7 : Debugging C Blocks

On PC (cont.)

Page 17: ©2005 GE Fanuc Automation, Inc. All Rights Reserved PACSystems Training Programmer’s Toolkit

©2005 GE Fanuc Automation, Inc.All Rights Reserved

Steps for migrating an existing Series 90-70 C-Toolkit application intoPAC RX7i

1)  Change main() to GefMain().

2)  Analyze Discrete macros IB, QB, etc for cases where they write

to user memory.  Change these to their corresponding write

function such as WritePlcByte().  If the macro reads from user

memory, change the macro so that the second letter is lower

case (for example IB() to Ib()) or use the appropriate read

function (for ex. ReadPlcByte).

3) Analyze the use of pointers that could write to discrete user

memory.  For these cases, write to discrete user memory using

the function PlcMemCopy. 

Page 18: ©2005 GE Fanuc Automation, Inc. All Rights Reserved PACSystems Training Programmer’s Toolkit

©2005 GE Fanuc Automation, Inc.All Rights Reserved

Steps for migrating an existing Series 90-70 C-Toolkit application intoPAC RX7i (cont.)

4) Convert any PLC C functions that have changed between the 90-

70 and RX7i (a table will be provided with user documentation)

5) Modify code that uses non-Standard C library functions to use

Standard C library functions if possible or write code to do the

same function.

6) Analyze code for cases where the application assumed

uninitialized non-static variables were being set to 0 on a stop to

run transition and add code to initialize these variables.

Page 19: ©2005 GE Fanuc Automation, Inc. All Rights Reserved PACSystems Training Programmer’s Toolkit

©2005 GE Fanuc Automation, Inc.All Rights Reserved

Demo

#include "copyright.h" /******************************************************************************`ModuleName fahr_to_Celsius.c*******************************************************************************/ /* `IncludeFiles */#include <stdio.h>#include <stdlib.h>#include "PACRX7iPlc.h" /* Constants / #defines *//* Structures and typedefs *//* Declarations for Global variables *//* Routines */ int GefMain (T_REAL32 *fahrenheitTemp, /* Input Param 1 */ T_REAL32 *celsiusTemp) /* Output Param 1 */{ /* C Block retrieves the Fahrenheit temperature to convert from */ /* the incoming parameter, and stores the calculated Celsius */ /* temperature in the output parameter. */  *celsiusTemp = (5.0/9.0) * (*fahrenheitTemp - 32.0);  return GEF_EXECUTION_OK;}

Page 20: ©2005 GE Fanuc Automation, Inc. All Rights Reserved PACSystems Training Programmer’s Toolkit

©2005 GE Fanuc Automation, Inc.All Rights Reserved

Demo

compileCPACrx7i f_2_c

Page 21: ©2005 GE Fanuc Automation, Inc. All Rights Reserved PACSystems Training Programmer’s Toolkit

©2005 GE Fanuc Automation, Inc.All Rights Reserved

#include "copyright.h" /******************************************************************************`ModuleName ctkCBlockTest.c` This file uses all C Run Time and Target Library functions supported` by the C Toolkit to test that all the supported functions can` be compiled. *******************************************************************************/ /* `IncludeFiles */#include <stdio.h>#include <stdlib.h>#include "PACRX7iPlc.h" /* Constants / #defines */ #define COOLANT_TEMP_HIGH_WARNING 10000#define COOLEAN_TEMP_ERROR_CODE 1/* Structures and typedefs */

/* Declarations for Global variables */ T_BOOLEAN coolantFaultLogged = FALSE;char coolantFaultString[] = "Coolant Temp too high.";

/* Routines */

int GefMain (T_REAL32 *fahrenheitTemp, /* Input Param 1 */ T_REAL32 *coolantTemp, /* Input Param 2 */ T_REAL32 *celsiusTemp) /* Output Param 1 */{

 

Exercise

Page 22: ©2005 GE Fanuc Automation, Inc. All Rights Reserved PACSystems Training Programmer’s Toolkit

©2005 GE Fanuc Automation, Inc.All Rights Reserved

T_WORD errorCode;T_INT32 funcCallResult;   /* C Block retrieves the Fahrenheit temperature to convert from */ /* the incoming parameter, and stores the calculated Celsius */ /* temperature in the output parameter. */  *celsiusTemp = (5.0/9.0) * (*fahrenheitTemp - 32.0);  /* Use some Macros to write to reference memory. */  RW(55) = 6943; AIW(1) = 2278; AQW(5) = 2278;   /* Log a user specified application fault in the PLC fault table. */  if (*coolantTemp >= COOLANT_TEMP_HIGH_WARNING) { *coolantTemp = 0.0; if (!coolantFaultLogged) { errorCode = COOLEAN_TEMP_ERROR_CODE; funcCallResult = PLCC_gen_alarm (errorCode, coolantFaultString); coolantFaultLogged = TRUE; } } return GEF_EXECUTION_OK;}

 

Exercise