Presentation is loading. Please wait.

Presentation is loading. Please wait.

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

Similar presentations


Presentation on theme: "©2005 GE Fanuc Automation, Inc. All Rights Reserved PACSystems Training Programmer’s Toolkit."— Presentation transcript:

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

2 ©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 into PAC RX7i  Active Sessions  Demos  ‘Hands on’

3 ©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

4 ©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)

5 ©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 1 st release  Cygwin C Debugger available for PC debugging

6 ©2005 GE Fanuc Automation, Inc. All Rights Reserved Steps for Developing a C application for the RX7i  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

7 ©2005 GE Fanuc Automation, Inc. All Rights Reserved Process Diagram

8 ©2005 GE Fanuc Automation, Inc. All Rights Reserved Step 1 : Install the C-Toolkit

9 ©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 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 /* Input/Output */ #include /* Math */ #include /* Math, Data Conversion, Search */ #include /* String Manipulation, Internationalization */ #include /* Time */ #include /* Character Classification and Conversion */ #include /* non-standard C functions provided for compatibility with the 90-70. Only a small subset of functions are supported in Release 1 */

10 ©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 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.)

11 ©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.

12 ©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.

13 ©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

14 ©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

15 ©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; }

16 ©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.)

17 ©2005 GE Fanuc Automation, Inc. All Rights Reserved Steps for migrating an existing Series 90-70 C-Toolkit application into PAC 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.

18 ©2005 GE Fanuc Automation, Inc. All Rights Reserved Steps for migrating an existing Series 90-70 C-Toolkit application into PAC 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.

19 ©2005 GE Fanuc Automation, Inc. All Rights Reserved Demo #include "copyright.h" /****************************************************************************** `ModuleName fahr_to_Celsius.c *******************************************************************************/ /* `IncludeFiles */ #include #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; }

20 ©2005 GE Fanuc Automation, Inc. All Rights Reserved Demo compileCPACrx7i f_2_c

21 ©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 #include #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

22 ©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


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

Similar presentations


Ads by Google