Home

SINUMERIK 840D C-PLC Programming

image

Contents

1. Preset values of user data pset_udt c TIME Areas overwritten through initialization also overwrite the signal data saved CS7DLIB ensures functions are called during start up and restored for this purpose User test functions during power up u_test_f c Fig 3 13 Initialization of off line test environment Siemens AG 1995 All Rights Reserved 6FC5297 3AB60 FB FB 3 25 3 C Block Programming 3 2 7 Termination procedure 03 96 Automatic CS7DLIB e saves the signals of S7 objects in file releases S7 systemresources again BILD3 14 DS4 Shutdown User options User can insert his own routines for program termination in file user_shd c e g for plausibility checks for status analysis for defined setting of I O signals for saving user managed system states Call is organized and executed by CSDLIB in termination phase No further operations requiring cyclic operation and or process image transfer are possible Fig 3 14 Overview of program termination routines It is particularly advisable in test operation to examine and save certain data and states when the program is terminated You can insert the functions required for this purpose in file user_shd c CS7DLIB calls this file in the termination phase An analysis procedure using debug points may be included in these routines if required 6FC5297 3AB60 3 26 Siemens AG 1995 All Rights Reserved FB FB
2. user_ini c e user_cyc c user_alt c time_alt c dely_alt c wdog_alt c user_err c Start up Free cycle Process alarm level Time of day alarm level Delay alarm level Time alarm level Error handling on the PLC user_cfg c pset_udt c usim_ini c uviewini c e u_test_f c user_sim c user_glb c user_shd c alt_hook c User configuration data Presetting of user data Registration of simulation objects Registration of visualization objects User test functions during power up User simulation routine Initialized debug pointers to S7 objects User shutdown routine Preparation for alarm levels rund c gp840d c Rotary table control Basic program extensions dsp_demo c rund_tst c Demo for registration of visualization objects Machine simulation for rotary table example Fig 3 4 Overview of source files of example project Library of CS7DLIB Borland format C frame for runtime levels C files in which user inserts his routines for supporting the off line test run only in development environment with CS7DLIB package C programs of demo project identical for PLC Demo routines to support test run only in development environment with CS7DLIB package The functions for test support of CS7DLIB which are available on the PC but not on the S7 side can be found in header file cs7_dlib h Siemens AG 1995 All Rights Reserved FB FB 6FC5297 3A
3. As an alternative to programming with STEP 7 it is possible to generate high level language applications in the ANSI C language for the integrated PLC of the SINUMERIK 840D machine tool control system The development environment described below which is based on Borland C for DOS and the CS7DLIB library allows this type of program to be developed and subjected to preliminary tests on the PC in off line operation Borland C CS7DLIB Integrated development environment Multi file and multi window editor Powerful project manager Integrated symbolic debugger High speed turnaround times Develop and test PLC programs on the PC and then prepare for PLC load and perform final test S 4 4 Bild_1 1 DS4 Fig 1 1 Runtime system on the PC with S7 objects DBs flags process image C calls for handling S7 objects syntax based on STEP 7 Connections for Test routines Simulation routines Visualization routines Prepared functions symbols and structures for off line test in conjunction with the Borland debugger Visualization and manipulation of S7 objects Features for visualizing signals with signal names Automatic saving and restoration of signals and test scenarios Testing without hardware using simulation objects created by user Tools for generating and loading C blocks for the integrated PL
4. In addition applications for the off line test environment can be extended see Section 3 2 Off line program development Incorporation of C On the PLC a C program block is called from the standard basic program The program blocks standard basic PLC program contains power up and initialization routines establishes the connection to the NCK machine control panel and operator panels and detects error and operational messages The basic program can be fully parameterized and controlled with C functions For a detailed description of the basic program functionality please refer to References PLCGP Description of Functions Standard Machine On the PLC a control program AB_START OBJ and ABMAIN OB4J is responsible for C block call management and branches into the various runtime levels of the C block depending on which STEP 7 runtime level has issued the call see Fig 1 2 Call interface for the C block The basic PLC program and the call management are not generally changed This runtime environment is simulated on the PC by the CS7DLIB library and Borland IDE see Fig 1 1 Development of C PLC programs with Borland C and CS7DLIB Branching to the various runtime levels can be controlled via the simulation see Section 3 2 Off line program development Program bodies are available for the possible runtime levels These serve as call shells for the C application A C program file gp840d c header gp840d h is supplied and offe
5. BHGDisp 2 Row bhgdisp ChrArray E_R 76 4 Convert var2 Addr 8 DataType 32 StringAddr 3 Digits A_W 113 6 bhgdisp_ret Error cycle 0 Siemens AG 1995 All Rights Reserved 6FC5297 3AB60 FB FB 4 21 4 C Call Interface for the Basic PLC Program 4 22 break default cycle 1 break Miscellaneous function for converting float to long VOID F2L FLOAT value P_USHORT pointer Cast pointer and generate return value 03 96 pointer USHORT value return pointer 0x10000UL pointer l 6FC5297 3AB60 Siemens AG 1995 All Rights Reserved FB FB 03 96 4 C Call Interface for the Basic PLC Program 4 2 9 POS_AX positioning of linear and rotary axes Function description Parameters Return parameters Programming example The POS_AX function can be used to traverse NC axes which have been defined in machine data as concurrent axes from the PLC During normal operation these axes can also be traversed using the JOG keys The POS_AX function calls up basic program block FC15 For a description of FC15 please refer to References PLCGP Description of Functions Standard Machine Table 4 19 Parameters for POS_AX Signal Type Value range Remarks 753535355 pStatt 2 VKE_TYPE o es IC VKETYPE 0 absolute 1 incremental__ Inch VKE_TYPE 0 mmi inch 1 handwheeloveray Pos F
6. Description of Functions Standard Machine Table 4 14 Parameters for ASUP Signat Tpe __ Value range Remarks S VKELTYPE fie eel UWORD No of NC channel UWORD Interrupt no Table 4 15 Return parameters for ASUP Signal Type Vauerange Remarks OoOO VKE TYPE 1 adive O vKE YPE Ts ASUP terminated PO VKE TYPE O3 StartErr VKE_TYPE 1 Interrupt number not assigned Programming example for ASUP VOID Bsp_ASUP ASUP_STAT asup_ret asup_ret ASUP E_R 77 5 Start 1 ChanNo EB_R 72 IntNo A_W 112 7 asup_ret Activ A_W 112 6 asup_ret Done A_W 112 5 asup_ret Error A_W 112 4 asup_ret StartErr 6FC5297 3AB60 Siemens AG 1995 All Rights Reserved FB FB 03 96 4 C Call Interface for the Basic PLC Program 4 2 7 AL_MSG error messages and operational messages Function description The AL_MSG function evaluates the signals entered in DB 2 and displays them as incoming and outgoing error messages and operational messages on the MMC The AL_MSG function calls basic function block FC10 For a description of FC10 please refer to References PLCGP Description of Functions Standard Machine Parameters Table 4 16 Parameters for AL_MSG Signat _ Type_ Value range Remarks S ToUserlF VKE_TYPE 1 Transfer of signals to application interface each cycle VKE TYPE S amp Y 1 Error message ackn
7. 4 C Call Interface for the Basic PLC Program MW_W 100 getgud_ret State if E_R 73 5 Address for source src 0 type TYP_BYTE src 0 count 4 DB_TEST J src 0 dbNo src 0 offset DB_TEST_OFS_GETGUD 4 Overwrite source with value DD_W dbtest src 0 offset 2UL Supply values for variable addressing unit 0 0 column 0 0 line 0 0 1 PLC cycle delay for put_start if getgud_ret Done if cycle Put start VRE TRUE else cycle 1 else cycle 0 put_ret PUT put_start Req T NumVar amp getgud_ret VarToken Addr unit Unit volumn Column line Line sre j RD A_W 112 2 put_ret Error A_W 112 3 put_ret Done MW_W 102 put_ret State Siemens AG 1995 All Rights Reserved 6FC5297 3AB60 FB FB 4 17 4 C Call Interface for the Basic PLC Program 03 96 4 2 6 ASUP start asynchronous subroutines Function description Parameters Return parameters Programming example 4 18 The ASUP function can be used to initiate any functions on the NC In order to be started from the PLC an ASUP must be selected and configured by an NC program An ASUP which has been prepared in this way can be started at any time from the PLC The ASUP calls up basic function block FC9 For a description of FC9 please refer to References PLCGP
8. All Rights Reserved Order No 6FC5297 3AB60 Printed in the Federal Republic of Germany Remarks A Cc Other functions not described in this documentation might be executable in the control This does not however represent an obligation to supply such functions with a new control or when servicing We have checked that the contents of this document correspond to the hardware and software described Nonetheless differences might exist and therefore we cannot guarantee that they are completely identical The information contained in this document is however reviewed regularly and any necessary changes will be included in the next edition We welcome suggestions for improvement Subject to change without prior notice Siemens Aktiengesellschaft 03 96 Contents Contents Page OVGNVIOW A T TT O A i cee vantenwevae cudave si evaubeds cdshvesdenuute dh AT 1 1 Components and Installation ccccceeeeeeeee cence cece ee eeeeeeee ee nnnnanannnnnnnnnnnnnannnnnnnnnn nenn nnmnnn enmana 2 1 2 1 Development environment for PC cccceeeeceeseeneeeeeseneeeteceeeeesendeseeendeeseeeeeentiaetes 2 3 2 2 Development environment for PLC 2444400ssssnsnnnnennnennnnnnnnnnnnnnannnnnnnnnnnn nn 2 5 2 3 Overview of directory Structure iss iiini ii ti ei ai nennen Liei 2 7 2 4 HardWare s 22 4 ee nee anal 2 8 2 5 System resources of the PLE nn nein sinn na 2 8 C Block Programming nsuursnnnn
9. Process CALLS ee DB xy Applicati interrupt SFC 63 Cuser k oe OB40 i application i BILD_4 1 DS4 Fig 4 1 Structure of 840D standard basic program for details about function blocks shown with unbroken lines refer to References PLCGP Description of Functions Standard Machine C functions for accessing NCK functionality are available for the C extensions blocks with broken lines The C program file gp840d c header gp840d h provides the C programmer with access to NCK functionality The functions from gp840d c represent a call interface of the basic PLC program This call interface supplies the corresponding basic program block with transfer parameters calls the block and transfers the return values back to the C function i e the basic program block is always processed In chronological terms the C function is processed before the basic program block and therefore also receives transmits values first Owing to this mechanism the return values of the C functions do not become valid until one cycle has elapsed after initiation of the function To ensure however that the C function does not return any invalid values all return values are set to 0 when a function is activated positive edge at start input Note A basic program block may only be called once per cycle if the C interface is in use For a description of the basic PLC program please refer to References PLCGP Description of Functions Standard Machine 6FC5297
10. adr 0 offset mpfpath Write string for mpfpath DS_W dbtest adr 1 offset mpfprog pi_ret PI E_R 77 1 Req PI_SELECT PIService T Unit adr Addr var WVar A_w 113 0 pi_ret Error A_W 113 1 pi_ret Done MW_W 104 pi_ret State break PI_CONFIG case 2 var 0 1 Classification 6FC5297 3AB60 4 13 4 C Call Interface for the Basic PLC Program 4 14 pi_ret PI E_R 77 1 A_W 113 A_W 113 MW_W 104 break default break PI_CONFIG 1 adr var 0 pi_ret Error 1 pi_ret Done pi_ret State 03 96 Req PIService Unit Addr WVar Miscellaneous function for writing a string to a data block VOID UBYTE DS_W USHORT BYTE i str_len S7_DB_HANDLE db byteOffset value Write string identifier to db DB_W db byteof Write string if str_len str_len DB_W db byteof Write user da for 1 0 i lt s DB_W db 6FC5297 3AB60 fset Ox0E length to db strlen value MAX_STR_LEN fset l str len ta to db ty lens i byteOffset 2 gt MAX_STR_LEN value i Siemens AG 1995 All Rights Reserved FB FB 03 96 4 C Call Interface for the Basic PLC Program 4 2 5 GETGUD read GUD variable Function description The GETGUD function can be used to r
11. o 0000 0 BILD_3 6 DS4 Invert bit from 0 gt 1 Spacebar Spacebar Invert bit from 1 gt 0 y MCP test B 60 0 Bit 0 Bit 1 Bit2 Bit 3 Bit 4 Bit 5 Bit 6 BIt7 EETA o MCP test _ O 0000 2 0 Increment DB byte Decrement DB byte Increment by 1 Pos1 DB object B 60 0 Increment by 16 Ctrl Pos1 Increment by 128 Shift Pos1 Bit 0 Bit 1 Bit 2 Bit 3 Bit 4 Bit 5 Bit 6 Bit 7 S 20000 0 6FC5297 3AB60 Decrement by 16 Ctrl End Decrement by 128 Shift End Decrement by 1 End DB object oO B 60 0 ig 3 6 Operator control of visualization objects o 0000 0 Bit 0 Bit 1 Bit 2 Bit 3 Bit 4 Bit 5 Bit 6 Bit 7 3 19 3 C Block Programming 03 96 3 2 4 User defined visualization objects There are certain typical displays with a particular meaning which recur frequently in projects In this case it is worth the extra effort of assigning texts once to the signals and registering corresponding symbolic displays You can do this quickly and easily by using the template in the example file dsp_demo c Copy the relevant template into your application and change it In this way you can create a means for controlling and monitoring your application which you can activat
12. 3AB60 Siemens AG 1995 All Rights Reserved 4 2 FB FB 03 96 4 C Call Interface for the Basic PLC Program 4 2 Description of the C functions 4 2 1 RUN_UP start up function Function description During start up the NCK and the PLC are synchronized and the data blocks for the NCK PLC application interface are generated in accordance with the NCK configuration stored in the machine data The RUN_UP function calls up the main function block FB1 For a description of FB1 please refer to References PLCGP Description of Functions Standard Machine Parameters Table 4 1 Parameters for RUN_UP Signat Type Value range Remarks DD 0 no MCP exists MCP 1In S7_POINTER 10 0 to 1120 0 or Start address for the input MCP2In F0 0 to F248 0 signals of the machine control panel MCP1Out S7_POINTER Q0 0 to Q120 0 or Start address for the MCP2Out F0 0 to F248 0 output signals of the machine control panel MCP1StatSend S7_POINTER Q0 0 to Q124 0 Start address for the status MCP2StatSend F0 0 to F252 0 or doubleword for sending to DBn DBX0 0 to the machine control panel DBXm 0 DW 16 08000000 time out expired else 0 MCP1StatRec S7_POINTER Q0 0 to Q124 0 Start address for the status MCP2StatRec F0 0 to F252 0 or doubleword for receiving DBn DBX0 0 to from the machine control DBXm 0 panel DW 16 00040000 time out expired else 0 MCP2BusAdr machine control panel MCP1Timeout ULONG Recommended Cyclical sign of life MCP2Timeout 70
13. Determine data block handle OPN_DB Determine data block address pointer access ADR_DB Determine data block length LNG_DB Read from DB bit byte word DWORD Write to DB bit byte word DWORD Siemens AG 1995 All Rights Reserved 6FC5297 3AB60 FB FB 3 3 3 C Block Programming Timer functions 03 96 Performance can be improved by directly accessing the data blocks via pointers which can be used to address any block No range or write protection checks are performed however so that the user must assure consistency data structure and in particular non violation of range limits The S7 specific byte order Big Endian must be observed see Fig 3 1 SIMATIC byte order S7 data are always stored with the highest order byte at the lowest address Data block pointers are determined by means of the ADR_DB function SIMATIC S7 offers the programmer 5 different types of timer each type with its own characteristics e The pulse timer is set to the specified value by a positive edge at logic input rlo This value is counted down to 0 in the specified clock cycle The logic output return value of function remains at 1 as long as the timer value is higher than 0 A rlo input value of 0 resets a pulse timer e The timer with extended pulse is set to the specified value by a positive edge at logic input rlo This value to counted down to 0 in the specified clock cycle The logic output return value of function remains
14. Users Guide Vol Il 80C166 C Cross Compiler Users Guide 1993 Tasking Software B V IMMCO SINUMERIK FM NC SINUMERIK 840D Operator s Guide 1994 SIEMENS AG IPLCGP SINUMERIK FM NC SINUMERIK 840D Description of Functions Basic Machine Part 1 P3 Basic PLC Program 1994 SIEMENS AG IBC3 Borland C 3 1 C Development Package IS7 SIMATIC STEP 7 USER MANUAL 1994 SIEMENS AG HITEX TELEMON 167 User Manual HITEX System Development Gesellschaft fur angewandte Informatik mbH D 76229 Karlsruhe Germany Siemens AG 1995 All Rights Reserved 6FC5297 3AB60 FB FB B 1 Index C block generation block generator 3 33 compiler linker 3 33 symbol file 3 33 C block location alternating buffer off 3 37 alternating buffer on 3 36 general information 3 36 C functions AL_MSG 4 19 ASUP 4 18 BHGDisp 4 20 GET 4 6 GETGUD 4 15 MCP_IFM 4 28 MCP_IFT 4 29 PART_AX 4 24 PI 4 12 POS_AX 4 23 PUT 4 9 RUN_UP 4 3 SpinCtrl 4 26 YDelta 4 25 C library bit memory functions 3 3 counter functions 3 4 data block functions 3 3 process image functions 3 2 timer functions 3 4 C project structure 2 7 data types 3 8 error messages Siemens AG 1995 All Rights Reserved FB FB 6FC5297 3AB60 C block 5 5 C library 5 6 linker locater 5 6 example project rotary table 5 8 execution level source files 3 13 load C block 3 35 load C program 3 38 load PLC basic program 3 38 local data OB1 5 2 OB10 5 2 OB100 5 4 OB20 5 3 OB35 5 3 OB40
15. block DB70 with the tool rddbbplc exe On this basis the code and data segments of the application are assigned to the appropriate memory areas The memory areas and data pages are defined automatically by the bs_addr exe tool according to the PLC type and the area sizes specified for the code and data segments when control file abmain bat is called The data and code segments for the application are allocated to different memory areas depending on whether or not an alternating buffer is used to load the block on the PLC Locating with When the alternating buffer is active the code section is switched over alternating buffer alternately The data section is permanently located at the end of the C block activated area see Fig 3 21 Allocation of C memory with active alternating buffer 6FC5297 3AB60 Siemens AG 1995 All Rights Reserved 3 36 FB FB 03 96 Locating with alternating buffer deactivated o Code section 1 CODE 64k Free memory Code section 2 CODE 64k Free memory Data section DATA 32k Fig 3 21 RMQQQOQQQVLY RMQQQQQQAVL RMQQQQQQQAL RMQQQOQQQQAL ASSISA ASSISA RMQQQOQQQVL RMQQQQQQQV RMQQQOQQQQVLY RMQQQOQQQQVLY RMQQQOQQQQAL RMQQQOQQQQA RMQQQOQQQQA RMQQQOQQQQA RMQQQOQQQQA RMQQQOQQQQA RMQQQOQQQQA RMQQQQQQQALY ASSISA RMQQQOQQQQALY RMQQQOQQQQAL RMQQQQQQQVL RMQQQOQQQALY RMQQQOQQQAL Uys ip Uggs if Us Lif Uggs hi Uggs if Lt if Uggs if Uggs if Uys if Uys if U
16. data area BILD_3 2 DS4 Data types are generally linked to function calls and thelr prototypes In files cs7cllb h and cs7dllb h The call types can be copied fom there into your own program Data types may never be changed Fig 3 2 Overview of data types Siemens AG 1995 All Rights Reserved 6FC5297 3AB60 FB FB 3 9 3 C Block Programming 03 96 3 1 3 Constants Classification of In order to parameterize functions or obtain function results you require a constants variety of constants These are divided into 2 groups e Constants for control or status signals parameters and return values Examples of these are the logic constants VKE_TRUE and VKE_FALSE execution level IDs and STD_APPL_START_ID or transfer parameters to the system The constants are in sys_inc data_def datatype datatype h e Identifiers for visualizing S7 objects Each S7 object has an identifier for bit display or for numerical display in some cases see Section 3 2 4 User defined visualization objects The constants are in sys_inc data_def sys_objd h 3 1 4 Runtime environment and standard program structure A C application comprises the basic cycle a range of event driven or time based runtime levels as well as an initialization phase The initialization phase is executed once before cyclic operation commences processing of the basic cycle is then initiated or if applicable processing of the event driven or time based levels
17. e in the shutdown phase and permits clean up and saving operations to be performed e alt_hook c is used to preprocess the alarm processing operation Prior to execution of the alarm functions the test system branches into the appropriate hooks Here the user has the opportunity to enter presettings if required The following source code files belong to the example project demo project they are not therefore an integral part of CS7DLIB and can be omitted or replaced by user files In these files you will find a range of principles for the application of system facilities It is therefore worthwhile copying code sequences from these files into your own applications and adapting them to your own requirements 6FC5297 3AB60 Siemens AG 1995 All Rights Reserved FB FB 03 96 3 C Block Programming e rund_tst c contains an example user program for testing the rotary table positioning function You will find both user defined visualization objects as well as the user simulation routine in this file e dsp_demo c demonstrates the initialization and registration of many standard visualization objects Use this file as a basis for your own visualization objects The value types to be specified are identified by comments so that you can incorporate your requirements in the same way as in a form The following diagram provides you with an overview of the files concerned plus brief comments CS7DUB UB BILD_3 4 DS4
18. e Open the example project Set a breakpoint in the file RUND C by pressing CTRL F8 toggle breakpoint in the program line with the sequence if start in function VOID Rotary Table VOID Then start the program with CTRL F8 e After the program has been started it will be interrupted at this line the line being highlighted by a coloured background You can now analyse execution of the program using the debug functions Single Step Watch Inspect 6FC5297 3AB60 Siemens AG 1995 All Rights Reserved FB FB 03 96 3 C Block Programming aluate modify rl Call stack Ctrl F3 Tessie breakpoint Ctr1 F8 To r een So Signale von Nahtstelle NCK lt gt PLC 3 static Variablen fuer Ablaufsteuerung static 3 Start mit M26 7 lt amp amp lt lt if lt Start gt Einlesesperre erweiterte M gt PE e SE Ablaufkette aktiv return BILD3 17 DS4 Fig 3 17 Inspect function Example e Select file user_glb c in the project window and open the associated editor Display process image window by pressing the Return key e Inthe editor window position the cursor on the C pointer p_dbg_inputs which contains the reference to the area of the process input image e Open the associated Inspect window by selecting menu item Debug Inspect e To obtain a clearer display of the process input image mark the line with the symbol s7_proc_image in the window you have jus
19. enabled AS314 ON_PLC_C_USER_MEM SIZE Oto7 0to7 64 KB AS315 ON_PLC_C_USER_MEM SIZE 0to14 0 to 14 64 KB Example for PLC memory allocation ON_PLC_USER_MEM_SIZE ON_PLC_C_USER_MEM_SIZE 1 4 This results in the following PLC memory allocation Siemens AG 1995 All Rights Reserved 6FC5297 3AB60 FB FB 3 35 3 C Block Programming 03 96 00000H PLC op sys Start address of STEP 7 block area depends on PLC type STEP 7 memory End address of STEP 7 block area depends on machine data Free memory ON_PLC_USER_MEM SIZE Start address of C block area depends on machine data ON_PLC_C_USER_MEM SIZE Miiiiitiiiitit SSA RMQQQAQOQQQQQQQQALE RMQQQAQOQQQQQQIQQALE RMQQQQQOQQQQQQQALE RMQQQOAIQQQQQQQIQQALE RMQQQAQOAQQQQQQIQAAVE RMQQQAQOQQIQQQQIAAVE RMQQQAQOQQQQQOIQALE RMQQQAQOQQQQQOIQAVE RMQQQAQQQQQQQOIAAVE RMQQQAQOQQQQQOQIIALE RMQQQAQOQQQQQQQQALE RMQQQAQOQQQQQQIQIQAVE RMQQQAQOQQQQQQIQAAVE RMQQQAQOQQQQQOQQQAVE RMQQQAQQQQQQQQIQIQAVE RMQQQAQOQQQQQQIQQAVE C memory III TT II I hs II IH spss Uy sss s II I shh III spss II IH spss II It shh II It shh II IH sss II II hs II IH LU III Uy shh Oy Ahh II IH I IIIR a Oy shh Uy shh Uy hh End address of BILD3 20 DS4 C block area depends on PLC type Fig 3 20 PLC memory allocation Locating the C block The start address of the C block area is read from communication data
20. files of C166 development system C166 Special Stack Frame Library Programs of Borland development system Header files of Borland development system Library files of Borland development system Project file make files etc C source files System header files User header files OBJ and EXE files Borland Generated binary files C166 CS7DLIB library user libraries if applicable Project documentation Generating and loading tools MPI drivers PLC basic program On line monitor e C166 path development system for the C166 processor which is required in order to generate the code executed on the PLC e Borland path development system Borland C with which the C user programs are developed with the support of the CS7DLIB e Project path directory for the current project Each project should be set up as a separate directory tree command new_prj see Section 2 1 Development environment for PC e Tool path tools for starting up and testing the C user programs on the PLC MPI drivers C block generating tools loading tools monitor tools etc 6FC5297 3AB60 2 Components and Installation 03 96 2 4 Hardware PC hardware e PC AT386 or higher with DOS gt 5 0 and MPI card VGA graphics i t Nee e Up to 80 Mbytes of free hard disk storage capacity e Minimum of 4 Mbytes main memory e Minimum of 500 Kbytes of free DOS memory 2 5 System resources of the PLC The maximum available PLC memory is On th
21. purpose can be found in directory project This file controls compilation linking and locating by means of the tasking tool chain References BSO Users Guide The block generator ab_gen exe uses this to generate a loadable C program block which is transferred to the PLC by means of loading tool downplc exe In addition the symbol preprocessor sp166ta exe generates a symbol file for the on line monitor after locating see Section 3 4 On line monitor so that it is possible to access memory addresses symbolically Siemens AG 1995 All Rights Reserved 6FC5297 3AB60 FB FB 3 33 3 C Block Programming 03 96 Source File C Source File C Source File 2 n 721 2 ICH l PG L c A Tasking C Compiler Tasking C Compiler are a STC src N Tasking Assembler Tasking Assembler 0bj obj obj En r i 2 CS7RTLIB LNO runtime library Tasking Linker lt ABMAIN OBJ call interface AB_START OBJ call interface Tasking Transformator IEEE format V Symbol Preprocessor Siemens C Block Generator AB_GEN el 1 sym bees C Block Symbol File for Bins ietes for the PLC On line Monitor Fig 3 19 Generating sequence for C program block and symbol file Control file abmain bat serves as the basis for your application If the C application includes other modules these only need t
22. to 0 Provided the signal is not overwritten by the running program then it retains this value If you exit the system in the normal way i e with the ESC key then the current signal value is stored and restored again when the application is restarted Fig 3 10 and Fig 3 11 Generating screen pages below show you how you can generate this type of screen page Beschreibung der anzuzeigenden 7 Standardobjekte static lt I 1393224 Konfigurationsheader fur die anzuzeigenden Stand el FG_HD vis_std_sym_nck_chan_t1_hd 1 NCK K Signale Funktionstastenbeschriftung Auszug aus NCK PLC Schnittstelle s 2 7 Text Kopfzeile links Interface zu NC Text Kopfzeile rechts xx Datenbaustein 21722 F Text Fu zeile rechts is_sym nck_ch_dt1 Pas Verweis auf Objektbeschreibung HARE ERTRY_CNTTG_UIS_SYMOBU_CFG_E viS Syn Pa a hb Yap u Anzahl jder Eintr ge in Objektbesch BILD3 10 DS4 Fig 3 10 Generating screen pages For the purpose of understanding the process let us concentrate on the first element on the screen because you use the same procedure for all the other elements First of all write down the text for the bits see upper left hand window and embed them in an object to which you should assign a name Make sure that the definition of your object is correct The object represents an array of pointers to bytes It is best if you copy the example object with the e
23. to local data Note Please refer to file sys_inc func_doc clib_doc for further details about transfer parameters and return values System services A series of system services for manipulating the runtime system enabling disabling initiating watchdog process and delay alarm levels for generating data blocks and for interrupting processing STOP state are also available For further details regarding transfer parameters and error messages please refer to file sys_inc func_doc clib_doc Siemens AG 1995 All Rights Reserved 6FC5297 3AB60 FB FB 3 5 3 C Block Programming Program execution levels 3 6 03 96 Table 3 5 System services Generate data block SFC_Create_DB Time of day alarm level SFC_Set_Time_Alarm Parameterize activate deactivate SFC_Activate_Time_Alarm Status interrogation SFC_Cancel_Time_Alarm in preparation SFC_Query_Time_Alarm Delay alarm level SFC_Start_Del_Alarm Start deactivate SFC_Cancel_Del_Alarm Status interrogation SFC _Query Del Alarm SFC Enable_ Event Processingt SFC_Enable_Alarm_Interruption Set system time SFC_Set_Clk Read system time into clock structure SFC_Read_Clk Interrogate system timer SFC_Time_Tick 0 to 2 32 1 msec Initiate STOP state SFC_Stop Set operating hours counter SFC_Set_Rtm Start stop operating hours counter SFC_Ctrl_Rtm Read status of operating hours counter SFC_Read_Rtm The functionality of the library fu
24. 0 ms monitoring for the machine control panel MCP 1Cycl ULONG Recommended Time frame for cyclical MCP2Cycl 200 ms update of signals to machine control panel BHG WORD Handheld operator panel interface 0 no handheld OP 1 handheld OP on MPI 2 handheld OP on MCP BHGIn S7_POINTER Start address for data received on the PLC from the handheld operator panel BHGOut S7_POINTER Start address for data sent from the PLC to the handheld operator panel BHGStatSend S7_POINTER Q0 0 to Q124 0 Start address for the status F0 0 to F252 0 or doubleword for sending to DBn DBX0 0 to the handheld operator DBXm 0 panel DW 16 08000000 time out expired else 0 Siemens AG 1995 All Rights Reserved 6FC5297 3AB60 FB FB 4 3 4 C Call Interface for the Basic PLC Program 03 96 Signat Type Valuerange Remarks _ BHGStatRec S7_POINTER Q0 0 to Q124 0 Start address for the status F0 0 to F252 0 or doubleword for receiving DBn DBX0 0 to from the handheld operator DBXm 0 panel DW 16 00040000 time out expired else 0 BHGInLen BYTE Handheld OP No of data items received default from the handheld operator B 16 6 6 Byte panel BHGOutLen BYTE Handheld OP No of data items sent to default the handheld operator B 16 14 20 Byte panel BHGTimeout ULONG Recommended Cyclical sign of life 700 ms monitoring for the handheld operator panel BHGCycl ULONG Recommended Time frame for cyclical 400 ms update of signals to handheld operator panel 200
25. 03 96 3 C Block Programming 3 2 8 Setting configuration data Setting options CS7DLIB provides the user with a number of configuring options To make use of these it is necessary to make appropriate entries or modifications in the project specific file user_cfg c The available options and supplementary conditions are documented in this file by means of comments Please observe the specified supplementary conditions to avoid any malfunctions later You move around in file user_cfg c in a similar way as you do in a form except that in this case the frame is specified by C statements and the file is interpreted by the compiler and the CS7DLIB The following setting options are currently available e Input of file in which the S7 object contents are saved It is possible to implement various scenarios through modification and to return to predefined scenarios when required e Input of user data blocks with number and size An entry block must always be used or else the computer will signal an error e Input of machine configuration number of mode groups channels axes e List in which the user can optionally control the transfer of data between the simulated I O area and the process image This list must contain at least one entry block or else the computer will signal an error 3 2 9 Test of alarm runtime levels Alarm levels In addition to the cyclical program section StdAppICycl and the start up section StdApplStart th
26. 10_OB_NUMEBR byte 10 Organization block 10 OB10 OB10_RESERVED_1 byte Reserved for system OB10_RESERVED_2 byte Reserved for system OB10_PERIOD_EXE word Period of execution once per minute hour day week month year OB10_RESERVED_3 int Reserved for system OB10_RESERVED_4 int Reserved for system OB10 DATE_TIME date_and_time Date and time OB10 started 6FC5297 3AB60 Siemens AG 1995 All Rights Reserved 5 2 FB FB 03 96 OB 20 OB 35 OB 40 OB20_EV_CLASS byte OB20_STRT_INF byte OB20_PRIORITY byte 0B20_OB_NUMBR byte 0B20 RESERVED _1 byte OB20_RESERVED_2 byte OB20_SIGN word 5 Miscellaneous Bits 0 3 1 Coming event Bits 4 7 1 Event class 1 16 21 OB 20 has started 3 Priority of 1 is lowest 20 Organization block 20 OB20 Reserved for system Reserved for system dentifier input SIGN attached to SRT_DALM OB20_RESERVED_3 int Reserved for system OB20_DTIME int Delay time DTIME input to SRT_DALM instruction OB20_DATE_TIME date_and_time Date and time OB20 started OB35_EV_CLASS byte OB35_STRT_INF byte 0B35_PRIORITY byte 0B35_OB_NUMBR byte 0B35 RESERVED _1 byte OB35_RESERVED_2 byte OB35_PHASE_OFFSET word Bits 0 3 1 Coming event Bits 4 7 1 Event class 1 16 36 OB 35 has started 11 Priority of 1 is lowest 135 Organization block 35 OB35 Reserved for system Reserved
27. 3 Overview of directory structure issii iiti eei nennen nennen ernennen nennen nn nnnn 2 7 2 4 Hardware angeregten 2 8 2 5 System resources of the PLC nn einsamen 2 8 Siemens AG 1995 All Rights Reserved 6FC5297 3AB60 FB FB 2 Components and Installation Software for developing and testing C PLC programs on PC S7DLIB Borland C 3 1 SIEMENS Turbo C 3 0 BORLAND mm 03 96 VGA graphics IBM compatible PC with 80386 processor or higher min 4 MB RAM min 50 80 MB free hard disk capacity min 500 KB free user memory with drivers and operating system loaded Fig 2 1 Software for See developing and testing C PLC programs on PC Software for See generating and testing C PLC programs on PLC Software for generating and testing C PLC programs on PLC C166 development syste J inci PXROSLIB j BSO tasking SIEMENS Online Monitor HITEX Section to 2 1 Section to 2 2 6FC5297 3AB60 MS DOS gt 5 0 and WINDOWS 3 x MPI card BILD_2 1 DS4 Components for the development of C PLC programs Development environment for PC Development environment for PLC Siemens AG 1995 All Rights Reserved FB FB 03 96 2 Components and Installation 2 1 Development environment for PC C development package Borland C 3 x Turbo C 3 0 Installing CS7DLIB Generating example project You will require the f
28. 4 15 4 2 6 ASUP start asynchronous subroutines 0uus4s442444snnnnnenennnnnnnnnnannnnnnnnnn nenn 4 18 4 2 7 AL_MSG error messages and operational messages eneee 4 19 4 2 8 BHGDisp display control for the handheld operator panel 4 20 4 2 9 POS_AX positioning of linear and rotary axes u neenneseessnnnnnnennnnnnnnnnnner nennen 4 23 4 2 10 PART_AX positioning of indexing axes uueesnsnnnsnnnnenssnnnnnnnnnnnnnnnnnnnnnr nennen nn 4 24 4 2 11 YDelta star delta selection sorserien iini ieie e 4 25 4 2 12 SpinGtrl spindle confrol 2er a mern 4 26 4 2 13 MCP_IFM transfer of MCP signals to the interface uu422444 nennen een 4 28 4 2 14 MCP_IFT transfer of MCP OP signals to the interface s c 4 29 Siemens AG 1995 All Rights Reserved 6FC5297 3AB60 FB FB 4 1 4 C Call Interface for the Basic PLC Program 03 96 4 1 General information Basic JU FB Basic program gt Program Startup FB cuser 08100 oe application gt NCK Basic JU FB na gt M decoder program gt Mode group Distributor FE auxiliary gt M list ae Basic Channa G functions decoder program B gt G group Een gt decoder p gt Axis spindle MISIF gt MCP gt distributor p gt Alarms PER er l messages CALL ln SECS S q PP R D DB1 NC PLC interface JU FB es ae olan J DB 70 72 DBs for C blocks
29. 5 3 off line development environment 2 3 on line development environment 2 5 on line monitor breakpoint handling 3 40 general information 3 39 load monitor block 3 40 operating information 3 42 start monitor 3 40 PLC memory C memory 3 35 example for PLC memory allocation 3 35 general information 3 35 STEP 7 memory 3 35 program execution levels 3 6 simulation routines 3 24 user stack 5 7 visualization objects 3 17 Index 1 SIEMENS AG AUT V24 P O Box 3180 D 91050 Erlangen Fed Rep of Germany From Name Company department Address Telephone Telefax Suggestions and or corrections Suggestions Corrections For Publication Manual SINUMERIK 840D C PLC Programming Manufacturer Documentation Description of Functions Order No 6FC5297 3AB60 Edition 03 96 Should you come across any printing errors when reading this publication please notify us on this sheet Suggestions for improvements are also welcome Siemens AG Siemens quality for software and training to Automation Group DIN ISO 9001 Reg No 2160 01 Automation Systems This edition was printed on paper bleached using for Machine Tools Robots an environmentally friendly chlorine free method and Special Purpose Machines Copyright Siemens AG 1994 All Rights Reserved Prog ress P O Box 3180 D 91050 Erlangen Subject to change without prior notice Federal Republic of Germany csr Nas GRGE2073AB6 in Automation S
30. 96 Table 4 13 State Meaning Information WORD H woRDt OE fo td Access error ___ __ 2 Ererinjobrequesi __ Incorrect variable syntaxinjob Negative ore error possible remedy acknowledgement job Reset NC not executable 4 Insufficient local user Check data to be read in RD memory available Pe ee ee a queue is full enabled o de Incorrect dest area RD RD cannot be local data Communication busy Job must be repeated C Error on addressing Unit contains value 0 11 Variable address invalid Check Addr or variable name Area Unit Programming example for GETGUD VOID Bsp_GETGUD VOID GETGUD_STAT getgud_ret PUT_STAT put rety BYTE var MAX_STR_LEN 1 GUD_VAR_NCK S7_ANY_POINTER dest UBYTE unit 8 UWORD column 8 UWORD line 8 S7_ANY_POINTER src 8 S7_DB_HANDLE dbtest AUF_DB DB_TEST static UBYTE cycle VKE_TYPE put_start Destination for GUD variable dest type TYP_BYTE dest count 4 dest dbNo DB_TEST dest offset DB_TEST_OFS_GETGUD getgud_ret GETGUD E_R 73 4 Req var Addr 0 Area Ly Unit 0 Indexl 0 Index2 ERG T3y 5 gt Cnvt Token dest ee RD A_W 112 0 getgud_ret Error A_W 112 1 getgud_ret Done 6FC5297 3AB60 Siemens AG 1995 All Rights Reserved FB FB 03 96
31. AG 1995 All Rights Reserved 6FC5297 3AB60 FB FB 4 C Call Interface for the Basic PLC Program 4 5 4 C Call Interface for the Basic PLC Program 03 96 4 2 2 GET read NCK variables Function description Parameters Return parameters Error codes 4 6 The GET function can be used to read variables from the NCK area The variables addressed by Addr 8 are copied to the referenced data block following a successful read operation To reference the variables all the required variables are first selected with the NCK VAR selector tool and then generated as an STL source in a data block In the C user program structures of the NCK_VAR type are now filled with the generated values For some variables it is necessary to select the unit and or the line or column It is possible to select a base type for these variables i e unit column line are initialized with O The value for this is taken from input parameters Unit 8 Column 8 Line 8 The GET function calls basic function block FB2 For a description of FB2 and the NCK VAR selector please refer to References PLCGP Description of Functions Standard Machine Table 4 2 Parameters for GET Signat Type Valuerange Remarks 775m Req VKE TYPE Start job on positive edge UWORD No of variables to be read Kl Dacre VAR selector e PA HE N variable addressing Column 8 UWORD Column address optional for pe ee eremie earessing oa Line 8 UWORD Lin
32. B FB 03 96 3 C Block Programming Caution If data formats are modified or additional variables declared the memory location of a data may be shifted uncontrollably Reloading of C programs after changes to data declarations may therefore only take place in the PLC STOP state Initialize data Static data are not stored on the stack but in a defined memory area This memory area is initialized during power up e Data with a programmed start value are always initialized with this value during power up e Data for which no initial value is specified are not initialized These data therefore remain unchanged by a POWER ON RESET caution when modifying the data declaration Observe the following list of data types which are relevant to you as the user see also sys_inc data_def datatype datatype h Elementary data types j Abstract S7 data types VOID void BYTE 8 bit signed System functions have a prefix of F_ or SFC_ for the return data type i e FVKE_TYPE instead of VKE_TYPE UBYTE amp blt unsigned Always create your variables without this prefix SHORT 16 bit signed USHORT 16 bit unsigned Create variables for S7 services using the function prototypes WORD 16 bit signed in the header files UWORD 16 bit unsigned LONG 32 bit signed ULONG 32 bit unsigned FLOAT Floating point number DOUBLE Floating point number doub acc Prefix P_ means pointer to data type Prefix G_ means declaration in extended
33. B60 3 15 3 C Block Programming 03 96 3 2 2 Header files for PLC and PC environments Header files for function prototypes Higher level header files for constants and data types System header files 3 16 In addition to the implementation files file extension c listed in Section 3 2 1 Example project rotary table control there are other important source files to be noted Each implementation file has a so called header file with the function prototypes of the implementation file concerned Function prototypes are the so called function headers i e they define the call structure of the functions including parameters The files containing the function prototypes have the same file name as the implementation files The only difference is that the file extension is h instead of c If an implementation file now calls a function which is located in another implementation file then the prototype header file of this other implementation file must be included in the implementation file calling the function by means of the include instruction Failure to do so will generally lead to compiler warnings and possible to a system crash or malfunctions during processing The prototypes of the S7 PLC functions offered by the library are entered in the supplied header file cs7_clib h For this reason the supplied implementation files always include the entry of an include instructions to this header file cs7_clib h You should therefo
34. C of the SINUMERIK 840D Development of C PLC programs with Borland C and CS7DLIB The Borland C package provides you with powerful tools for generating testing and modifying C programs The CS7DLIB library is used in conjunction with the package and provides functions which are relevant to runtime processes These include timers counters I O accessing functions as well as S7 specific data objects and system services 6FC5297 3AB60 1 1 1 Overview Creating C blocks Basic PLC program Data exchange between STEP 7 and C On line test environment 1 2 03 96 CS7DLIB also offers a complete test sequence system which can manage user specific routines for process simulation in addition to the actual PLC application The status of the system objects can be saved and reconstructed In addition to the visualization facilities available with the Borland debugger CS7DLIB provides user defined screen pages for visualization of S7 objects in off line test mode with which data contents with symbolic information can be displayed or manipulated The BSO tasking tool chain can be used to create C blocks from the program modules developed in off line mode These blocks can be loaded to the integrated PLC via the MPI interface C call Application interface USER_CYC C StdAppICycle OB1 Program body to fill in C with user code for cycle Sea DBs for basic Application PLC program USER_ALT C
35. Event class 1 Entering event state Event logged in diag buffer 116 81 82 83 84 Method of startup 1 27 Priority of 1 is lowest 100 Organization block 100 OB100 Reserved for system Reserved for system Event that caused CPU to stop 16 4xxx Reserved for system Reserved for system OB100_DATE_TIME date_and time Date and time OB100 started 6FC5297 3AB60 Siemens AG 1995 All Rights Reserved FB FB 03 96 5 Miscellaneous 5 2 Response to errors Entry of return values Possible return values The C block processing program supplies a return value which is entered in memory words to the S7 level issuing the call When an error is detected the PLC is switched to the STOP operating state Tabelle 5 2 Entry of return values Table 5 3 Possible return values No error 0 2 Block does not exist Match call number to block call eee i nrineeoeie nee DB_pointer too small Check entries in DB_pointer Incorrect number of C blocks Length block spec data incorrect DB_pointer Definition in DB_pointer missing Offset block spec data incorrect DB_pointer 9 DB_K missing Generate and load DB_K DB_K too small Check DB_pointer DB_K and DB_pointer identical Assign different DB numbers 128 Monitor not loaded Link in monitor during generation process Monitor not initialized Initialize monitor DB_K for monitor not correct Check DB_pointer 133 debugger block
36. F_ or SFC_ This convention must be observed in order to conceal the different subordinate addressing modes Please refer to the header file CLIB_DOC H for further details on how to use these functions See Section to 3 2 Off line program development for details of functions for the off line programming environment which are only available in the PC environment Siemens AG 1995 All Rights Reserved 6FC5297 3AB60 FB FB 3 7 3 C Block Programming 03 96 3 1 2 Use of data types Data types User data types Storing data 3 8 Within the scope of the CS7DLIB development package a variety of precautions has been taken to ensure easy portability and to conceal system specific differences between the PC and S7 environments Important in this respect are the abstract data types used some of which are derived from elementary data types and others user compiled data types For your own applications use only the data types provided by CS7DLIB or if you create your own data types make sure they are derived from these prespecified data types This does not impose any restrictions on you in practical terms and also means that you do not need to bother with complicated system specific details If you create a variable to use in calls of S7 utilities then all you need to do is copy the appropriate parameters from the function prototypes of the CS7_CLIB H header file and insert them in your source code Your source code will the
37. LO een 5 7 5 4 Example project Rotary table positioning ccccceecceceeeeeseeeeeeeeeeeeeeseeeeseeeeeeeees 5 8 Siemens AG 1995 All Rights Reserved 6FC5297 3AB60 FB FB 5 Miscellaneous 03 96 5 1 Access to local data from the C program In order to access the start information of the standard OBs from the C program the start information of the OBs is copied to communication data block DB70 on every OB entry Table 5 1 Detailed description of OB start information extract from standard OB shells Standard OB Start information in DB70 StdAppICycle DBB 80 to 99 StdTimeAlert OB 10 DBB 100 to 119 OB 1 OB1_EV_CLASS byte Bits 0 3 1 Coming event Bits 4 7 1 Event class 1 OB1_SCAN_1 byte 1 Cold restart scan 1 of OB 1 13 Scan 2 n of OB 1 OB1_PRIORITY byte 1 Priority of 1 is lowest OB1_OB_NUMBR byte 1 Organization block 1 OB1 OB1_RESERVED_1 byte Reserved for system OB1_RESERVED_2 byte Reserved for system OB1_PREV_CYCLE int Cycle time of previous OB1 scan milliseconds OB1_MIN_CYCLE int Minimum cycle time of OB1 milliseconds OB1_MAX_CYCLE int Maximum cycle time of OB1 milliseconds OB1_DATE_TIME date_and_time Date and time OB1 started OB 10 OB10_EV_CLASS byte Bits 0 3 1 Coming event Bits 4 7 1 Event class 1 OB10_STRT_INFO byte 16 11 OB 10 has started OB10_PRIORITY byte 2 Priority of 1 is lowest OB
38. LOAT 0 1469368 E 38 to Linear axis mm Rotary axis iar mere ee FRate FLOAT 0 1469368 E 38 to Linear axis mm min Rotary ee POM ioone se ast aegreesmm gt Table 4 20 Return parameters for POS_AX Signat Type Value range Remarks 2 InPos VKE_TYPE 1 Position reached VKE TYPE t active StartErr VKE TYPE Axis cannot be started VKETYPE Cd Errorontraversal Programming example for POS_AX VOID Bsp_POS_AX VOID POS_AX_ STAT pos_ax_ret pos_ax_ret POS_AX R 76 7 Start 5 AxisNo ERC 16r Oo ig f IC VKE_FALSE Inch VKE_FALSE HWheelOv STE TOs Ro O 3333 0 FRate A_W 104 7 pos_ax_ret InPos A_W 104 6 pos_ax_ret Activ A_W 104 5 pos_ax_ret StartErr A_W 104 4 pos_ax_ret Error Siemens AG 1995 All Rights Reserved 6FC5297 3AB60 FB FB 4 23 4 C Call Interface for the Basic PLC Program 03 96 4 2 10 PART_AX positioning of indexing axes Function description The PART_AX function can be used to traverse NC axes which have been defined in machine data as indexing axes from the PLC During normal operation these axes can also be traversed using the JOG keys The PART_AX function calls up basic program block FC16 For a description of FC16 please refer to References PLCGP Description of Functions Standard Machine Parameters Table 4 21 Parameters for PART_AX Signal
39. P DBnr dbxm n Data to be written Return parameters Table 4 6 Return parameters for PUT Signat Tpe __ Valuerange Remarks Error VKE_TYPE Job was given negative acknowledgement or could not be executed VKE_TYPE Job was successfully executed UWORD see mrodeds DD Error codes If ajob could not be executed this is indicated by a 1 in the state parameter The cause of the error is coded in the State block output Siemens AG 1995 All Rights Reserved 6FC5297 3AB60 FB FB 4 9 4 C Call Interface for the Basic PLC Program 03 96 Programming example 4 10 Table 4 7 Error codes for PUT State WORD H WORD L which error occurred o 2 Error in job request Incorrect variable syntax in job 3 Negative Internal error possible remedy acknowledgement job Reset NC not executable 1to8 4 Data areas or data types Check data to be written in SD 8 do not match in high byte number of variable in which error occurred BR full Job must be ee because Ban ee is full 7 Option not enabled GP parameter NCKomm is not enabled 1t08 8 Incorrect dest area SD SD 8 cannot be local data a EEE Communication busy Job must be repeated 1to8 Error on variable Unit or Column Line contain addressing value 0 o 11 Variable address invalid Check Addr 8 Programming example for PUT VOID Bsp_PUT VOID PUT_STAT p t ret UWORD i NCK_VAR var 8 UBYTE unit 8 U
40. SIEMENS SINUMERIK 840D C PLC Programming Description of Functions 03 96 Edition Manufacturer Documentation SIEMENS SINUMERIK 840D C PLC Programming Description of Functions Manufacturer Documentation Valid for Control Software Version SINUMERIK 840D 03 96 Edition Overview Components and Installation C Block Programming C Call Interface for Basic PLC Program Miscellaneous Abbreviations References Index O u gt SINUMERIK documentation Printing history Brief details of this edition and previous editions are listed below The status of each edition is shown by the code in the Remarks column Status code in the Remarks column A New documentation B Unrevised reprint with new Order No C Revised edition with new status If factual changes have been made on the page since the last edition this is indicated by a new edition coding in the header on that page Edition Order No 04 95 6FC5297 2AB60 0BPO 03 96 6FC5297 3AB60 0BPO Siemens quality for software and training to DIN ISO 9001 Reg No 2160 01 This publication was produced with WinWord V 6 0c and Designer V 6 0 The reproduction transmission or use of this document or its contents is not permitted without express written authority Offenders will be liable for damages All rights including rights created by patent grant or registration of a utility model or design are reserved Siemens AG 1995
41. SpinCtrl spindle control Function description Parameters Return parameters Error detection 4 26 The SpinCtrl function can be used to control spindles from the PLC The function supports the functions e Position spindle e Rotate spindle e Oscillate spindle The SpinCtrl function calls up basic function block FC18 For a description of FC18 please refer to References PLCGP Description of Functions Standard Machine Table 4 25 Parameters for SpinCtrl Signal__ Type Value range Remarks _ Start VKE_TYPE Start spindle control from PLC VKE_TYPE o Stop spindle control from PLC re Pe 1 Position spindle 2 Rotate spindle 3 Oscillate spindle eal hae 0 Pos at absolute pos 1 Pos incremental 2 Pos shortest path 3 Pos absolute positive approach 4 Pos absolute negative approach 5 Direction of rotation as M4 Pos ro 1 8 0 No ofaxistobetraversed axis No of axis tobe traversed 8 0 1701412 E 39 0 1701412 E 39 Spindle rpm Table 4 26 Return parameters for SpinCtrl Signal Type Value range Remarks VKE_TYPE 1 Position reached or fct executed VKE TYPE I sem UBYTE 0 255 If a job could not be executed this is indicated by a 1 in the state parameter The cause of the error is coded in the State block output 6FC5297 3AB60 Siemens AG 1995 All Rights Reserved FB FB 03 96 4 C Call Interface for the Basic PLC Program Table 4 27 Error cod
42. StdProcess Alert ES Runtime system Program body to fill in with user code for process alarms Application USER_INI C StdApplIStart Program body to fill in with user code for Bild_1 2 DS4 start up Fig 1 2 Call interface for the C block The basis ofthe PLC environment is the supplied basic STL program which links the PLC with the runtime system and the process NCK PLC interface see Fig 1 2 Call interface for the C block Call interfaces SFC63 for C blocks are available on the STEP 7 program execution levels Basic cycle OB1 Delay interrupt OB20 Watchdog alarm OB35 Process interrupt OB40 and Start up branch OB100 It is therefore possible to implement all user specific expansions fully in C Data are exchanged between STEP 7 and C by means of data blocks or bit memories A data exchange may be required for example for operator communication and monitoring or for the NCK PLC interface Testing and start up of the C program block in the control are supported by a C source level monitor for the PLC environment which is connected to the MPI interface 6FC5297 3AB60 Siemens AG 1995 All Rights Reserved FB FB Components and Installation 2 1 Development environment for PC uuusersnnnneennnnnnnnnnnnnnnnnnnn nennen ennnnn nennen nn nnnn nn 2 3 2 2 Development environment for PLC 2444400ssssnsnnnnnnnnennnnnnnnennnnnennnnnnnnnnenennnnnn 2 5 2
43. TEX monitor This monitor is based on the remote debugger telemon 80C166 167 telemon 800167 with dialog software HiTOP supplied by HITEX licence HITEX References HITEX User Manual The dialog software is mouse oriented with pull down menus and flexible window system It is installed on a DOS PC gt 386 with MPI interface The tool SP166TA EXE for editing the C166 Locator Formats for debug operation is supplied with the dialog software see Section 3 3 Generating and loading a C block For further details about installation and operator control please refer to References HITEX User Manual The monitor is a remote debugger The full range of functions for a remote debugger is divided between two programs i e the monitor block and the user interface The two programs operate on separate processors which are interlinked via a defined interface The monitor and user interface communicate via debug data block DB71 SINUMERIK 840D PLC PLC basic PCIPG program Monitor block Remote debugger SFC 63 block HiTOP Monitor dialog software user interface ik Debug a data block DB71 VA MPI MPI interface Operating system BILD3 23 DS4 Fig 3 23 On line monitor Siemens AG 1995 All Rights Reserved 6FC5297 3AB60 FB FB 3 39 3 C Block Programming Loadi
44. Type Value range Remarks O VKE_TYPE ii u UWORD No of axis to be traversed IC VKE_TYPE 0 abs direction 1 incremental direction VKE_TYPE 0 defined direction 1 shortest path VKE TYPE inppadton VKE_TYPE in preparation Pos WORD 0 to 32767 Indexing position no FRate FLOAT 0 1469368 E 38 to Linear axis mm min 0 1701412 E 39 Rotary axis degrees min Return parameters Table 4 22 Return parameters for PART_AX Signal Type Value range Remarks 2 InPos VKE_TYPE 1 Position reached Activ VKE_TYPE 1 active Activ VKE_ StartErr VKE_TYPE Axis cannot be started VKE TYPE Cd Errorcontraversal Programming example for PART_AX VOID Bsp_PART_AX VOID PART_AX_STAT part_ax_ret Programming example part_ax_ret PART_AX E_R 76 3 Start 6 AxisNo BRUT 2 Jp TO VKE_FALSE DC VKE_FALSE Minus VKE_FALSE Plus EB_R 72 Pos 1111 0 FRate A_W 105 7 part_ax_ret InPos A_W 105 6 part_ax_ret Activ A_W 105 5 part_ax_ret StartErr A_W 105 4 part_ax_ret Error 6FC5297 3AB60 Siemens AG 1995 All Rights Reserved 4 24 FB FB 03 96 4 C Call Interface for the Basic PLC Program 4 2 11 YDelta star delta selection Function description Parameters Return parameters Programming example The function for star delta selection is performed i
45. WORD column 8 UWORD line 8 S7_ANY_POINTER src 8 S7_DB_HANDLE dbtest AUF_DB DB_TEST for i 0 i lt 8 i R10 to R17 variable addressing var i syntax_id 0x82 var i bereich_u_einheit 0 var i spalte 0 var i zeile 0 var i bausteintyp 0x15 var i zeilenanzahl 0x1 var i typ Oxf var i laenge 0x8 unit i 0x41 column i 0x1 line i 10 itl Source for R10 to R17 src i type TYP_BYTE src i count var i laenge 6FC5297 3AB60 Siemens AG 1995 All Rights Reserved FB FB 4 C Call Interface for the Basic PLC Program src i dbNo DB_TEST src i offset DB_TEST_OFS_ PUT i src i count Overwrite source with value DD_W dbtest src i offset F2L 1 0 put_ret PUT E_R 77 6 Req 8 NumVar var Addr unit Unit volumn Column line Line sre RD A_W 112 2 put_ret Error A_W 112 3 put_ret Done MW_W 102 put_ret State Data block generated by NCK VAR selector with structure for R10 STRUCT rpa_1l0C1RP STRUCT SYNTAX_ID BYTE B 16 82 bereich_u_einheit byte B 16 41 spalte word W 16 1 zeile word W 16 11 bausteintyp byte B 16 15 ZEILENANZAHL BYTE B 16 1 typ byte B 16 F laenge byte B 16 8 END_STRUCT Miscellaneous function for converting flo
46. aai nee 3 30 3 3 Generating and loading a block uurezsssnssssnnenensnnnnnennnnnnnnnnnnnnnnnnnnnn nennen nn nnnnn nn 3 33 3 3 1 Generating a C block en ns renden 3 33 3 3 2 Loading a Ciblock 4 ensure 3 35 3 4 On line monitor ern eine Ei nn ihher lien 3 39 C Call Interface for the Basic PLC Program 22224444444444nnBnan nn nn nen nnnnnnanannnnnnnnnnnannnnnnnn nn 4 1 4 1 General information 2 0 0 0 ccccccccccccsseseececececeaeeaecececeaeeaeeeseeeeeeaueaeeceeeeeseaeaseeeeseeauaneneeeess 4 2 4 2 Description of the C functions siisii isinin nona nennen e ernennen 4 3 4 2 1 RUN UP Start Up function uusssesnersnnnnnnessnnnnnennnnnnn nennen nenne ernennen ernennen enter nn 4 3 4 2 2 GET read NCK variables ccccccsccssccsscesscsccsuccusessesssecsceusessecusceucesssesestuecuecsssss 4 6 Siemens AG 1995 All Rights Reserved 6FC5297 3AB60 FB FB v Contents 03 96 4 2 3 PUT write NCK Variable niini ei en a en EN i e e 4 9 4 2 4 Pl general Pl services anelieeiehhenan 4 12 4 2 5 GETGUD read GUD variable ccc cecccccccccecseeeececeeeeeseeaeeeceeeseaueeeseeeseeaeaaenenees 4 15 4 2 6 ASUP start asynchronous subroutines 0 eee cee ceeeee cece cece eee ee cece teen eeeeteaeeeeeeeeeneee 4 18 4 2 7 AL_MSG error messages and operational messages eneee 4 19 4 2 8 BHGDisp display control for the handheld operator panel 4 20 4 2 9 POS_AX positioning of line
47. ach object and determine the designations of the individual signals of the objects by entering your own texts example See Fig 3 9 Example of a screen page Fig 3 9 Example of a screen page Some of the components of the screen page are for example a left aligned and right aligned text in the title bar and a left aligned text in the screen footer The S7 objects are represented in the form of rectangles each of which has a user defined object designation justified to the right in the 1st line The abbreviated current S7 object designation is located in the 2nd line of each rectangle The example given here shows an extract of the NCK PLC interface of the SINUMERIK 840D 6FC5297 3AB60 3 21 3 C Block Programming 3 22 03 96 The symbolic designator is DB 20 0 in this case DB stands for data block 20 for data block number 20 and 0 for byte O of data block 20 Since the symbolic signals apply only to this byte it is not possible to page on to other bytes in this data block nor is it possible to change the data block through an operator input Every bit is marked by its current state i e 0 or 1 and also has a text which has been assigned by the user Non assigned bits can be identified by the text Bit x where x represents the bit number Using the cursor keys you can position the cursor on the bit of your choice Now press the spacebar and the bit will invert its value i e change from 0 to 1 or from 1
48. ar and rotary axes ue eenseseessnnnnensnnnnnnennnnner nennen 4 23 4 2 10 PART_AX positioning of indexing axes uueesnnnnnennnenenssnnnnnnennnnnen ernennen nnnnn ern 4 24 4 2 11 YDelta star delta selection sonore cccccccccscccsceseesscssecescesesusccuccusesseeusecuccsneeseesueeueessess 4 25 4 2 12 SpinCtrl spindle Control iiion aiet viaii nennen ern 4 26 4 2 13 MCP_IFM transfer of MCP signals to the interface uu42244n nennen 4 28 4 2 14 MCP_IFT transfer of MCP OP signals to the interface s e 4 29 Miscela OUS PORRERERERSESPPFRGREPERPESERRERTFEBERERPELSURSFEFERFE PRCERFRRFTFERFEPEFPEPESPERBRFFERFLERTREERFEFSSFEFSPREESEFETFEFSPEER 5 1 5 1 Access to local data from the C program uusserssnnneneennnnennnnnnnnenennnnnnennnennnnnnner nn 5 2 5 2 Response tO eors dingn netee A E eee eee cess 5 5 5 3 Stack handling on the PLC uuersnsnenessnnnnennnnnnnnnsnnnnnnnnnnnnnnnnnnnennnnnnn nennen ernennen nn 5 7 5 4 Example project Rotary table positioning 44rs44snnn nennen nennen nnnnnnnnnnn nenne 5 8 Abbreviations 2 4 4s04 4402 00a nn nn m an Han een ran A 1 References nasse deen Bee cl un ce decd none an an ve dove ann al sevens ved sitasesseaasaaaae B 1 Index 4 ae een aa Index 1 6FC5297 3AB60 Siemens AG 1995 All Rights Reserved vi FB FB Overview High level language programming Borland C package CS7DLIB Siemens AG 1995 All Rights Reserved FB FB
49. asic program the handwheel selections operating modes and other operating signals are transferred from the operator panel OP or MMC to the NCK PLC interface such that it is possible to select the operating modes from either the MCP or the OP The MCP_IFT function calls up basic function block FC25 For a description of FC25 please refer to References PLCGP Description of Functions Standard Machine Table 4 30 Parameters for MCP_IFT Signat Type Value range Remarks 027 BAGNo UBYTE 0 1 No of mode group to which the operating mode signals are transferred UBYTE Channel number for the channel signals SpindlelFNo UBYTE Number of the axis interface declared as a spindle Table 4 31 Return parameters for MCP_IFT Signat Type Value range Re marks 2027 FeedHold VKE_TYPE Feed hold from MCP modal SpindleHold VKE_TYPE Spindle hold from MCP modal Programming example for MCP_IFT VOID Bsp_MCP_IFT MCP_IFT_STAT ift_ret ift_ret MCP_IFT 1 ModeGrpNo 1 ChanNo 4 SpindleIFNo Signals to LEDs A_W 104 0 ift_ret FeedHold A_W 104 1 ift_ret SpindleHold Siemens AG 1995 All Rights Reserved 6FC5297 3AB60 FB FB 4 29 Miscellaneous 5 1 Access to local data from the C program uussersnnneneennnennnnnnnnennnnnn nenn nnnnnnn nenn 5 2 5 2 Response to errors 0 2 2 ce E cece ee eeee E E E A EE 5 5 5 3 Stack handling on the P
50. at 1 as long as the timer value is higher than 0 A rlo input value of 0 does not reset the timer The next positive edge at rlo resets the timer which has still not expired back to the specified value i e it extends the pulse e The timer with ON delay is set to the specified value by a positive edge at logic input rlo This value is counted down to 0 in the specified clock cycle The logic output return value of function does not however switch to 1 until the time has expired and input rlo is still at 1 When rlo switches to 0 the output also switches to 0 e The timer with OFF delay is set to the specified value by a negative edge at logic input rlo This value is counted down to 0 in the specified clock cycle e The timer with latched ON delay is set to the specified value by a positive edge at logic input rio This value is counted down to 0 in the specified clock cycle The logic output return value of function does not however switch to 1 until the time has expired It remains at 1 even when rlo switches to 0 The output state can be reset only by a reset command For further details please refer to References S7 User Manual Table 3 4 Timer functions 6FC5297 3AB60 Siemens AG 1995 All Rights Reserved FB FB 03 96 3 C Block Programming Counter functions SIMATIC S7 can make use of counter objects which can be set on an edge triggered basis and reset on a status dependent basis These objects permit edge tri
51. at to long VOID F2L FLOAT value P_USHORT pointer Cast pointer and generate return value pointer USHORT value return pointer 0x10000UL pointer l Siemens AG 1995 All Rights Reserved 6FC5297 3AB60 4 11 4 C Call Interface for the Basic PLC Program 03 96 4 2 4 PI general PI services Description Parameters Return parameters Error codes 4 12 The PI function can be used to start program instance services in the NCK area The specified service is referenced in the PlService parameter see gp840d h for the defines The selected PI service is supplied with parameters by means of the additional freely assignable input variables with different data types Addr 4 for strings WVar 6 for integers or word variables The PI function calls up basic function block FB4 For a description of FB4 please refer to References PLCGP Description of Functions Standard Machine Table 4 8 Parameters for PI Signal Type Vauernge Remarks 2727233 Req VKE_TYPE Startjobonpositiveeger Addr 4 S7_ANY_POINTER P DBnr dbxm n Reference to string specification according to PI service selected WVar 9 WORD 1a Word specification according to PI service selected Table 4 9 Return parameters for PI Signat _ Type Value range Remarks _ Error VKE_TYPE Job was given negative acknowledgement or could not be executed VKE_TYPE Job was successfully executed UWORD See
52. ck Programming 03 96 3 2 10 Notes on testing Debugger functions Monitor status and contents of S7 system objects Notes on debugging the example project 3 30 Borland C 3 x or Turbo C 3 0 contains a user friendly integrated debugger with the following functions e Move step by step through program Single Step skipping functions as required or stepping to functions e Allow program to run on until a specified point break point is reached e View variables and structures nspect function e Monitor variables and structures continuously Watch function Note Refer to the Borland documentation for more information about handling and functional scope of this tool If you want to monitor the status and contents of S7 system objects with the debugger then you should use file user_gib c This file contains pointers which are managed and initialized by the library and which have debugger friendly data types The inspect function can also be moved to the right hand mouse key supplies the current values of the clicked object It may be necessary to open further inspect windows for detailed views by pressing the Return key You will see any changes when stepping through program sections which modify the contents being monitored of these objects The use of S7 objects will be explained in the following Some information about debugging with CS7DLIB based on the example project Rotary table control is given below
53. ction keys Fig 3 7 Visualization facilities 6FC5297 3AB60 Siemens AG 1995 All Rights Reserved 3 20 FB FB 03 96 Example NCK PLC interface of SINUMERIK 840D Siemens AG 1995 All Rights Reserved FB FB 3 C Block Programming Object IDs for standard bit display VT_DB_OBJ VT_PRC_IM_INPUT_OBJ VT_PRC_IM_OUTPUT_OBJ VT_MARKER_OBJ VT_DIRECT_IO_OBJ VT_TIMER_OBJ VT_COUNTER_OBJ With data block Byte offset Data block object ID Input process image object ID otherwise the number of the timer counter bit memory the direct IO cell input or Output process image object ID Bit memory object ID Direct O object ID Timer object ID Counter object ID Object IDs for numeric display mostly 0 VT_DB_NUM_OBJ VT_PRC_IM_INPUT_NUM_OBJ VT_PRC_IM_OUTPUT_NUM OBJ VT_MARKER_NUM_OBJ VT_DIRECT_IO_NUM_OBJ Data block other values number Data block object ID Input process image object ID only when relevant Output process image object ID otherwise 0 Bit memory object ID Direct IO object ID Macro for generating access identification One of these values dependin p p g BILD_3 8 DS4 on type Fig 3 8 Identifiers for visualization objects You can create screen pages yourself using S7 objects In this case you can select the position of each object assign a logical name to e
54. d StdApplICycle OB1 during the run time A prespecified stack is located for each of the other runtime levels i e this stack is not calculated by the compiler The user can modify the user stack by means of file user_stk c The stack is modified on the basis of the following constants OB1_STACK LIT 256 StdApplCycle amp StdApplStart OB10_STACK LIT 512 StdTimeAlert OB20_STACK LIT 512 StdDelayedTimeAlert OB35 STACK LIT 512 StdWatchdogAlert OB40_STACK LIT 512 StdProcessAlert The value for OB1_STACK is an additive component in the C166 user stack calculation This value acts as the default memory for the return addresses of function calls Normally speaking the user does not need to concern himself about the size of this stack For description of the stack mechanism please refer to References BSO Users Guide Siemens AG 1995 All Rights Reserved 6FC5297 3AB60 FB FB 5 7 5 Miscellaneous 03 96 5 4 Example project Rotary table positioning Cam switch Rotate amp ounter clockwise position y 1 2 3 fo Index extended Workpiece SSS SSS N NUN Rotate clockwise er 4 Index retracted Motor BILD_5 2 D84 ale Fig 5 1 Positioning a rotary table Description of e The rotary table is driven by an electric motor with 2 speeds rapid traverse example and creep speed and 2 directions clockwise and counter clockwise rotation e On approach t
55. ditor and then enter your own object designation and texts This is the easiest and least complicated method and helps to avoid a lot of errors right from the start 6FC5297 3AB60 Siemens AG 1995 All Rights Reserved FB FB 03 96 3 C Block Programming After you have done this for each of the objects to be displayed on the screen page generate the next object preferably by copying and altering the example template which contains all the objects on the screen page Remember to specify the following for each individual object Its title first line in object display the line and column on the screen in which it must be displayed which byte of which S7 object it represents and finally a reference to the texts of each bit for this S7 object The next step is to define the screen Here you need to specify the text with which you want to call it This text is entered in the function key overview call by pressing function key F1 and acts as the identifier You must then specify the texts which are output on the left in the header and footer Now you need to enter the reference to the general object descriptions i e those which include all individual objects and the number of objects To save you having to count yourself you will be assisted here by a macro which also registers new entries ELE E Lokale Variable x 0 0 j x Anmelden der Uhranzeige x xxxx RR MPLES DSP_DEMO C RR JRex Anwei
56. divided into blocks ab00 1vx of 64 Kbyte each by the generator These blocks are loaded successively onto the PLC by means of tool downplc exe and are linked into the PLC when the last block has been loaded The C program is loaded onto the PLC automatically at the end of control file abmain bat It can be loaded separately by calling control file asmload bat in directory CS7TOOLS MPI Reloading of the C program after changes to the data declaration may only take place when the PLC is in the STOP state The C program on the PLC can only be erased through a PLC overall memory reset The PLC basic program is included in the scope of delivery CS7TOOLS GP840D directory The above directory is set up for you automatically when the development environment is installed on your computer This directory also includes control file awlload bat When this file is called the compiled blocks of the PLC basic program are loaded on the PLC The C program can be executed on the PLC only if the PLC basic program is loaded The C program is called by the PLC basic program If the C program cannot be processed properly or the C program block is not installed then the PLC switches to the STOP operating state check entry in MW 40 to 52 see Section 5 2 Response to errors 6FC5297 3AB60 Siemens AG 1995 All Rights Reserved FB FB 03 96 3 C Block Programming 3 4 On line monitor The on line monitor can be used to test the C block on the PLC HI
57. drivers COMOFF BAT Control file for de installing the MPI drivers e Generating tools Directory CS7TOOL AB_GEN EXE Generates a loadable C block BS_ADDR EXE Locates code and data segments RDDBBPLC EXE Reads the start address of the C block in the PLC e Control files Directory CS7TOOLS CC BAT Control file for compiling the C source files Siemens AG 1995 All Rights Reserved 6FC5297 3AB60 FB FB 2 5 2 Components and Installation 03 96 Installing CS7TOOLS Extending AUTOEXEC BAT 2 6 Loading tools Directory CS7TOOLS DOWNPLC EXE Loads the C and STEP 7 blocks on the PLC UPPLC EXE Saves the STEP7 blocks from the PLC Monitor tools Directory CS7TOOLS HITEX AB15 1V1 Monitor block MONLOAD BAT Loads the monitor block on the PLC HIT_167 CFG Config file for HITEX user interface DEBUGGER INI File with cross reference to Debug data block DB71 STARTUP SCR HiScript file which is executed on start of the HITEX user interface MONSTART BAT Starts the HITEX user interface Basic PLC program for SINUMERIK 840D Directory CS7TOOLS GP840D AWLLOAD BAT Loads the basic PLC program on the PLC AWLSAVE BAT Saves the basic PLC program from the PLC To install CS7TOOLS insert the installation diskette in drive A Enter a gt install TargetDirectory Please enter a directory name of your choice for the TargetDirectory parameter and specify the destination drive Example a gt install C CS7TOOLS This command c
58. e AS314 672 Kbytes On the AS315 1280 Kbytes 6FC5297 3AB60 Siemens AG 1995 All Rights Reserved 2 8 FB FB C Block Programming 3 1 Conventions inian ain ie vn had eat eon 3 2 3 1 1 Language and functionality uuerssseeeessnnnnnennnnnnnsnnnn nennen nennen nme nn nnnnnnnnn nennen 3 2 3 122 Use of data A ES E aea sagen see acer an eaae rearea Iai sds eae Peia edarien 3 8 3k Constants ic in en ae Aen ei dad ei vee 3 10 3 1 4 Runtime environment and standard program Structure iesene 3 10 3 2 Off line program development uuursusessersnnnnnennnnnnnnnnnnnnennnnnnn ernennen nennen nnnnn ernennen 3 12 3 2 1 Example project rotary table control u 2uusesrsnnnnnnsnnnnnnnennnnnennnnnnnnnnnnnnnnnn nenn 3 12 3 2 2 Header files for PLC and PC environment 224442244HHnn nennen nenne nennen nennen nn 3 16 3 2 3 Standard visualization objects uu4222uunnnnnnnnnnsnnnnnnennnnnnnnnnnnnen nme ernennen nn nennen 3 17 3 2 4 User defined visualization objects uu4424444nrsnnnnnnennnnnnnennnnnen nennen nenn nnnnnnnnnn nn 3 20 3 2 5 Simulation roufines nss sn rennen sea are Convecenevs 3 24 3 2 6 Presetting data during start up of test environment 3 25 3 2 7 Termination pr ced re 2 un een i e E een 3 26 3 2 8 Setting configuration data uusersnneseessnnnnnennnnnnnsnnnnnnnnnnnennnnnnnnn nme nen nnnnnnnn nennen nn 3 27 3 2 9 Test of alarm runtime levels u uu0eersnnnnennnnnnnnnnnnn
59. e address optional for pene aatabieaeressng R Table 4 3 Return parameters for GET Signat Type Value range Remarks 2 Error VKE_TYPE Job was given negative acknowledgement or could not be executed ee eee al _TYPE Job was successfully executed Data are available Er i o o o i Pe If a job could not be executed this is indicated by a 1 in the state parameter The cause of the error is coded in the State block output 6FC5297 3AB60 Siemens AG 1995 All Rights Reserved FB FB 03 96 4 C Call Interface for the Basic PLC Program Table 4 4 Error codes for GET State Meaning Information WORD H WORD A fe SOS 1to8 Access error In high byte number of variable in which error occurred O 3 2 Error in job request Incorrect variable syntax in job 1to8 Insufficient local user Variable read is longer than memory available definition in RD 8 in high byte number of variable in which error occurred 5 Format conversion error Error on conversion of double variable type Var not within range of S7 REAL queue is full enabled 1t08 8 Incorrect dest area RD RD 8 cannot be local data o 9 Communication busy Job must be repeated 1to8 10 Error on variable Unit or Column Line contain addressing value 0 o 11 Variable address invalid Check Addr 8 2 3 Negative Internal error possible remedy acknowledgement job Reset NC not executable 1 E Programming examp
60. e and switch over quickly Integrating The example file dsp_demo c shows you how you can integrate visualization visualization objects objects to suit your own needs Experiment with these objects by making changes in the example project and then copy them to your own application and change them there Fig 3 7 Visualization facilities and Fig 3 8 Identifiers for visualization objects give a summary of the visualization facilities available Geis soni Visual bit signal objects for T visualization objects process image inputs f Online operator control process image outputs and monitoring possible I O area inputs Values are stored on VO area outputs system shutdown and data block cells restored again on bit memory cells restart Visual value objects with byte word and Selection and BILD_3 7 DS4 doubleword representation for switchover via process image inputs function keys process image outputs O area inputs I O area outputs data block cells bit memory cells Visual object representations for counters timers Generic signal labelling Application specific with generic with technological application specific object signal and labelling labelling labelling and object labelling object selection object selection Included as standard in PLC LIB User can define his own screens with Use without programming and individual selection of objects and labels configuring and call them via fun
61. e example program for rotary table positioning sequence control The functions of the files named above are executable immediately both on the PC and on the PLC after compilation and integration into the relevant infrastructure Siemens AG 1995 All Rights Reserved 6FC5297 3AB60 FB FB 3 13 3 C Block Programming Source files for simulation Source files for simulation of example project 3 14 03 96 All other files of the project window contain functions for testing visualization and simulation and can be executed on the PC under CS7DLIB Most of these files contain an example code or act as dummies for example codes in order to illustrate the options available with CS7DLIB Comments are given at the locations at which you can delete the example code or remove it in order to replace it with your own routines If you create a new project see Section 2 1 Development environment for PC then this example code is missing from the start The following files are supplied as a source code but are an integral part of CS7DLIB in terms of their functions and variables Please enter your own code sequences only at the locations marked by a comment and do not alter either existing variable names function names or the existing entries in the associated header files e user_cfg c is used to set a series of application specific configuration data for the off line environment These data also include the definitions of the da
62. e following alarm levels exist e StdProcessAlert e StdTimeAlert e StdWatchdogAlert e StdDelayedTimeAlert These levels can be programmed via SFCs see Section 3 1 2 Use of data types or are initiated via system events Using a preprogrammed S7 display object you can simulate this type of process using CS7DLIB Siemens AG 1995 All Rights Reserved 6FC5297 3AB60 FB FB 3 27 3 C Block Programming 03 96 Borland C Fig 3 15 Visualization objects for alarm levels standard display Initiating alarms On the basis of these objects you can now initiate 8 different events per alarm level The respective event is added to the appropriate hook function in the alt_hook c file for preparation of the alarm simulation After the hook function CS7DLIB branches into the actual alarm processing level Example for process The example below shows how you can simulate the occurrence of different interrupt events process interrupt events such as for example M40 M19 1 etc using alt_hook c The hook functions receive the transfer parameters alert_ctrl_info event information and instance containing alarm ID ID for process interrupt watchdog alarm 6FC5297 3AB60 Siemens AG 1995 All Rights Reserved 3 28 FB FB 03 96 3 C Block Programming Borland C return BILD3 16 DS4 Fig 3 16 Listing of file alt_hook c extract Siemens AG 1995 All Rights Reserved 6FC5297 3AB60 FB FB 3 29 3 C Blo
63. e functions Read process input image bit byte word doubleword Write process input image bit byte word doubleword Determine address of PII for pointer access ADR _PAE Read direct access to I O inputs L_PEB bit byte word doubleword L a L_PED Read process output image bit byte word doubleword Write process output image bit byte word doubleword Write direct access to I O outputs T _PAB byte word doubleword T_PAW T_PAD Please note that a transfer takes place during the off line test between the simulated I O area and the process image depending on your input in the supplied source file user_cfg c in this case you can determine the area for the output and the input yourself For test purposes it is often advisable to keep this area small in order to avoid undesirable side effects which may adversely affect the test 6FC5297 3AB60 Siemens AG 1995 All Rights Reserved 3 2 FB FB 03 96 3 C Block Programming Bit memory functions SIMATIC S7 can make use of so called bit memories which are global variables which can be written or read bit by bit byte by byte in 16 bit blocks or 32 bit blocks The bit memories are addressed via the byte offset parameter s7_byte_offset referred to the 0 memory byte In the case of bit by bit accessing the bit offset parameter s7_bit_offset specifies the bit in the memory byte Table 3 2 Bit memory functions Read bit memory bit byte word doubleword Wr
64. ead a GUD variable GUD Global User Data from the NCK or channel area The GETGUD function calls up basic function block FB5 For a description of FB5 please refer to References PLCGP Description of Functions Standard Machine Parameters Table 4 11 Parameters for GETGUD Signat Type Valuerange Remarks SS O O Req VKE_TYPE Startjob on positive edge Addr 32 BYTE GUD variable name Area BYTE Unit address 0 NCK variable 2 Channel variable Unit BYTE Unit NCK Unit 1 Unit channel channel no Index1 WORD The value of the variable is 0 if the array index is not used The value of the variable ist 0 if the array index is not used CnvtToken VKE_TYPE mo S7_ANY_POINTE P DBnr dbxm n Data to be read R Array index 1 of variable Activation of the generation of a variable token Return parameters Table 4 12 Return parameters for GETGUD Signal Type Vauerange Remarks ______ _ NCK_VAR Address of a 10 byte token Error VKE_TYPE Job was given negative acknowledgement or could not be executed Done VKE_TYPE Job was successfully executed Data are available UWORD Seeerorcodes Error codes If a job could not be executed this is indicated by a 1 in the state parameter The cause of the error is coded in the State block output Siemens AG 1995 All Rights Reserved 6FC5297 3AB60 FB FB 4 15 4 C Call Interface for the Basic PLC Program Programming example 4 16 03
65. ealistic testing even without machine User specific simulation routines Access to signals with standard commands Call management by CS7DLIB Visualization possible via user specific screen of standard visualization objects Simulation with CS7DLIB 6FC5297 3AB60 Siemens AG 1995 All Rights Reserved FB FB 03 96 3 C Block Programming 3 2 6 Presetting data during start up of test environment In order to establish a defined start environment or for the purpose of testing you can preset data during start up with CS7DLIB You need to insert the functions for this option in file pset_udt c which is called by the CS7DLIB during start up Please note the information about general initialization in the following diagram Setting up of additional user DBs Defined presetting of data areas C data areas and areas in S7 objects Preparation and registration of visualization simulation and test objects During system start up During BILD3 13 D84 sehen Incorporate initialization routines in functions supplied and managed by CS7DLIB for by user in cyclic operation Control and management executed PLC application user_ini c as on PLC Basis includes Data blocks of application user_cfg c User managed statuses Simulation used for the application Declared and evaluated usim_ini c i MHP y hao An signal combinations e Visualization created for the application uviewini c
66. errorcodes _ _ _ If a job could not be executed this is indicated by a 1 in the state parameter The cause of the error is coded in the State block output Table 4 10 Error codes for PI State Meaning i Information 3 Negative Internal error possible remedy Reset NC acknowledgement job not executable 6 FIFO full Job must be repeated because queue is full Option not enabled GP parameter NCKomm is not enabled 9 Communication busy Job must be repeated 6FC5297 3AB60 Siemens AG 1995 All Rights Reserved FB FB 03 96 Programming example Siemens AG 1995 All Rights Reserved FB FB 4 C Call Interface for the Basic PLC Program Programming example for PI VOID Bsp_PI VOID PI_STAT pi_ret S7_ANY_POINTER adr 4 WORD var 9 UWORD i S7_DB_HANDLE dbtest AUF_DB DB_TEST UWORD ebtest EB _R 72 BYTE mpfpath MAX_STR_LEN 1 _N_MPF_DIR BYTE mpfprog MAX_STR_LEN 1 _N_ASUP_MPF switch ebtest PI_SELECT case 1 Address for mpfpath adr 0 type TYP_BYTE adr 0 count MAX_STR_LEN 2 adr 0 dbNo DB_TEST adr 0 offset DB_TEST_OFS_PI Address for mpfprog adr type TYP_BYTE adr count MAX_STR_LEN 2 adr dbNo DB_TEST adr offset DB_TEST_OFS_PI adr 0 count Write string for mpfpath DS_W dbtest
67. es for SpinCtrl State Meaning Error caused by NCK handling The alarm numbers are described in the 840D Diagnostics Guide corresponds to alarm number 16830 corresponds to alarm number 16770 corresponds to alarm number 22052 107 corresponds to alarm number 22051 corresponds to alarm number 22050 System or other major alarms corresponds to system alarm number 450007 1 1 Programming example Programming example for SpinCtrl VOID Bsp_SpinCtrl SPINCTRL_STAT spinctrl_ret spinctrl_ret SpinCtrl E_R 76 1 Start E_R 76 0 Stop 1 Funct 1 Mode 4 AxisNo 100 0 Pos 9 0 i FRate A_W 113 5 spinctrl_ret InPos A_W 113 4 spinctrl_ret Error MW_W 114 spinctrl_ret State Siemens AG 1995 All Rights Reserved 6FC5297 3AB60 FB FB 4 27 4 C Call Interface for the Basic PLC Program 03 96 4 2 13 MCP_IFM transfer of MCP signals to the interface Function description Parameters Return parameters Programming example 4 28 The MCP_IFM function M variant can be used to transfer operating modes axis selections WCS MCS switchover travel keys overrides and keyswitch from the machine control panel MCP to the corresponding signals on the NCK PLC interface In the basic program the handwheel selections operating modes and other operating signals are transferred from the operator panel OP or MMC to the NCK PLC interface s
68. etected errors can be found in header file user_err h In the example project for rotary table positioning the error handler file usr_err c was extended insofar as the error code is entered in communication data block DB70 e DW 40 Error code error_id e DW 42 Errored parameter error_reason_par e DD 44 Address of errored command error_adr The PLC is also swiched to the STOP operating state in the example project for rotary table positioning The user can now read out the cause of the error from the PLC status information PG or MMC Example of an error entry in DB70 DB70 DBW40 h0431 DB70 DBW42 h0080 DB70 DBD44 h00080488 6FC5297 3AB60 Siemens AG 1995 All Rights Reserved FB FB 03 96 5 Miscellaneous 5 3 Stack handling on the PLC Modify constants for user stack The user stack is located in the near data segment of the C block The C program requires this stack for the automatic variables as well as to manage the return addresses of function calls gt C166 Special Stack Frame Library The compiler calculates the stack size on the basis of the stack requirement of each individual function without the return addresses This stack requirement is therefore based on the assumption that all functions are called simultaneously In most cases the requirement is oversized but may be undersized in the case of a recursive call The calculated stack requirement is occupied by runtime levels StdApp Start OB100 an
69. evelopment package for microprocessor types SAB 80C165 80C166 This package contains C compilers assemblers linkers and the required libraries The library expansion PXROSLIB C166 Special Stack Frame Library must also be installed Please follow the installation instructions given in References BSO Users Guide HITEX user interface space requirement approx 3 Mbytes HITEX licence This package also includes the symbol preprocessor SP166TA EXE see Section 3 4 On line monitor Please follow the installation instructions given in References HITEX Users Manual Directory CS7TOOLS HITEX must be specified as the destination directory for installation purposes In addition symbol preprocessor SP166TA EXE must be copied to directory CS7TOOLS CS7RTLIB LNO the runtime library for accessing S7 objects from C programs disk 1 directory CS7DLIB LIB incl the call interfaces AB_START OBJ and ABMAIN OBJ CS7RTLIB LNO AB_START OBJ and ABMAIN OBJ are stored in directory CS7DLIB LIB see Section 2 3 Overview of directory structure CS7TOOLS Generation tools loading tools and tools for on line testing during start up e MPI tools Directory CS7TOOLS MPI MPIDOS EXE MPI driver MPIMON EXE MPI driver BT_L7STD COM MPI driver BT_L7TSR COM MPI driver NETNAMES CPU Default settings for the MPI interface NC_CD EXE Directory change in the NCK NC_DIR EXE Directory display in the NCK COMON BAT Control file for installing the MPI
70. f you set a breakpoint when the machine is in operation the C block will no longer be processed cyclically if for example a motional function was started before a breakpoint then this can neither be checked nor stopped For this reason the PLC basic program is stopped and the command output disabled when a breakpoint except for start breakpoint is reached However cyclic processing of the monitor block continues meaning that the C block can be checked again This state remains valid until the PLC is next reset e You can change memory cells in the RAM selectively using the monitor The monitor does not check the location at which it writes the values If you change the system data this will cause the system to crash There are 3 different types of breakpoint e User breakpoint this is set by the user 6FC5297 3AB60 Siemens AG 1995 All Rights Reserved FB FB 03 96 Deactivating the monitor Notes on monitor operation 3 C Block Programming e Temporary breakpoint this is set by the monitor in single step mode e Start breakpoint this is set as soon as you call the user interface on the computer If the C block to be tested encounters a breakpoint program processing is halted at this point Processing of the C block continues as soon as a RUN or STEP command is entered via the user interface To deactivate the monitor and reload a C block Set DB70 DB500 0 0 Load the C block e execute a PLC overall mem
71. fect quickly and easily it is advisable to conduct preliminary tests in the course of system startup CS7DLIB provides space for these tests in file u_test_f c The events or runs can be generated by loops which can easily be examined by means of carefully selected breakpoints in the relevant locations For testing of timer functions CS7DLIB also offers the possibility of simulating timer clocks see CS7_DLIB H While the program is running you should monitor the counters with the standard visualization tools of the CS7DLIB Since updating in this case takes place only every 100 ms the macroscopic behaviour can be monitored and interpreted it is best to analyse this behaviour using the debugger e Timers are only ever updated between cycles The jump to the time levels always takes place between cycles no interruption of cycle e The transfer between I O and process image must be parameterized if desired by means of user_cfg c 6FC5297 3AB60 Siemens AG 1995 All Rights Reserved FB FB 03 96 3 C Block Programming 3 3 Generating and loading a C block 3 3 1 Generating a C block Compiling and linking program modules Compiling and linking C blocks Generating symbol file To run your application on the PLC you must first compile your program modules link them to the required runtime libraries and convert the linker file generated in this way into a loadable format The abmain bat control file provided for this
72. for system Phase offset msec OB35_RESERVED_3 int Reserved for system OB35_EXC_FREQ int Frequency of execution I XX integer 100 msec OB35_DATE_TIME date_and_time Date and time OB1 started OB40_EV_CLASS byte OB40_STRT_INF byte OB40_PRIORITY byte OB40_OB_NUMBR byte OB40_RESERVED_1 byte OB40_MDL_ID byte OB40_MDL_ADDR int OB40_POINT_ADDR dword Bits 0 3 1 Coming event Bits 4 7 1 Event class 1 16 41 OB 40 has started 16 Priority of 1 is lowest 1140 Organization block 40 OB40 Reserved for system Module identifier initiating interupt Base address of module initiating Point address of interupt OB40_DATE_TIME date_and_time Date and time OB1 started Siemens AG 1995 All Rights Reserved 6FC5297 3AB60 FB FB 5 3 5 Miscellaneous OB 100 GP_IRFromNCK bool GP_TM bool 03 96 nterrupt for user by NCK Tool management GP_InPosition array 1 31 of bool Axis oriented for positioning axes I ndexing axes spindles GP_AuxFunction array 1 10 of bool Channel oriented for miscellaneous GP_FMBlock array 1 10 of bool OB100_EV_CLASS byte 0B100_STRTUP byte 0B100_PRIORITY byte 0B100_OB_NUMBR byte 0B100_ RESERVED _1 byte OB100_RESERVED_2 byte 0B100_STOP word 0B100_ RESERVED 3 word OB100_RESERVED_4 word functions Channel oriented for block transfer to FM K in preparation 16 13
73. ggered up down counting It is possible to interrogate the counter contents max 999 and the counter status counter contents gt 0 For further details please refer to References S7 User Manual Special features Word serial or doubleword serial access operations by means of these access regarding accessing of functions result in the C byte order Little Endian Format being converted to process images bit the SIMATIC Big Endian Format see Fig 3 1 SIMATIC byte order memories and data S7 data are always stored with the highest order byte at the lowest address blocks The user should always use the defined access functions to transfer data to and from S7 objects n 2 Memory map Memory map SIMATIC format C format Big Endian Little Endian BILD_3 1 D84 Fig 3 1 SIMATIC byte order S7 data are always stored with the highest order byte at the lowest address A bit serial read access supplies the logic status of the appropriate bit In the case of a write access the addressed signal bit is set according to the logic state of the input value During processing PC or PLC environment the system detects whether the valid addressing space of an S7 object has been violated This error is displayed in the status line in the PC environment the PLC environment branches with an error identifier and additional debug parameters to an error handler which the user can program freely see 5 1 Access
74. ic program basic program startup of file gp840d c see project window in this example and initializes the error handler see Section C Call Interface for the Basic PLC Program e user_cyc c contains the function StdAppICycle which is called up in the free cycle see OB1 This function calls the C basic program extension MsttAnNahtstelle of file gp840d c and the rotary table control rotary table of file rund c in this example project see project window e user_alt c contains the start function StdProcessAlert which is started by the process interrupted see OB40 e time_alt c contains the function StdTimeAlert which is time of day alarm triggered see OB10 e dely_alt c contains the function StdDelayedTimeAlert which is triggered by delay alarms see OB20 e wdog_alt c contains the function StdWatchdogAlert which is triggered by the time alarm see OB35 e user_err c contains the user specific error handler StdErrorHandler which is called in the event of an erroneous S7 system access operation from the on line library cs7rtlib Ino CS7DLIB outputs a message in the status line in the event of an error but does not call this error handler The following source code files belong to the example project demo project they are not therefore an integral part of CS7DLIB and can be modified or omitted e gp840d c contains C functions see Section C Call Interface for the Basic PLC Program e rund c contains th
75. iemens Aktiengesellschaft Printed in the Federal Republic of Germany Siemens
76. ite bit memory bit byte word doubleword Determine address of bit memory area for pointer access ADR_MRK Data block functions Data blocks are global memory areas of a size specified by the user in each case They are addressed by a data block number Data blocks are required to exchange data via interfaces with external devices such as for example operator interfaces or the NCK In contrast to data blocks in the SIMATIC S7 environment which are loaded from a programming device PC or generated in the program the memory area for such blocks must always be allocated by the user in the development and test environment on the PC The CS7DLIB automatically sets up the data blocks used as standard in the SINUMERIK 840D see References PLCGP References PLCGP Description of Functions Standard Machine Once a data block exists it can be opened The appropriate function call OPN_DB supplies a handle in exchange which is required for all further calls of the data block You can have several data blocks opened at the same time and access them optionally via the functions below if you are managing and using the appropriate handles Addressing within data blocks is implemented via the byte offset parameter s7_byte_offset referred to the 0 byte of the data block addressed by handle s7_db_handle When blocks are accessed bit by bit the bit offset parameter s7_bit_offset must also be specified Table 3 3 Data block functions
77. ithin each window using the lt spacebar gt or the right hand mouse button Within most input fields it is possible to open an additional selection menu e g wildcard sample for breakpoints watches etc using the lt gt key or the left hand mouse key When you exit from the operator interface lt FQ gt you can save the current screen settings in a restore file In order to restore these settings again at the next session you must modify file hit_167 cfg switch r For a detailed description of the HiTOP dialog software please refer to References HITEX User Manual 6FC5297 3AB60 Siemens AG 1995 All Rights Reserved FB FB C Call Interface for the Basic PLC Program 4 1 General information 22 4 0 ts ei ne 4 2 4 2 Description of the C functions 0 u00ssssssnnnnennnnennnnnnnnnnnnnennnnnnnnnnnnnnnnnnnnnnnnnnn 4 3 4 2 1 RUN_UP Start Up function uusssesnrsnnnnnnensnnnnnennnnnennnnnnner nennen ernennen nennen ernten nn 4 3 4 2 2 GET read NCK variables cccccsccssccsscssecscecnccusssssessecsccusesseeusecuceseseseesnecueessess 4 6 4 2 3 PUT write NCK variables 222220000sssnnnseneenenennnnnnnnenensnnnnnnnnnennnnennnnnnnnenen nennen 4 9 4 2 4 Pl general Pl services 224400s0snunnnnnnnnnnnnnunnnnnnnnnnnnnannnnnnnnnnnnnnnnannannnn nenn 4 12 4 2 5 GETGUD read GUD variable uuu uuuuueennenenaannnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnn nennen
78. laenge byte B 16 8 END_STRUCT Siemens AG 1995 All Rights Reserved FB FB 03 96 4 C Call Interface for the Basic PLC Program 4 2 3 PUT write NCK variables Description The PUT function can be used to write variables into the NCK area The variables addressed by Addr 8 are overwritten with the data in the data block referenced by SD 8 To reference the variables all the required variables are first selected with the NCK VAR selector tool and then generated as an STL source in a data block In the C user program structures of the NCK_VAR type are now filled with the generated values For some variables it is necessary to select the unit and or the line or column It is possible to select a base type for these variables i e unit column line are initialized with O The value for this is taken from input parameters Unit 8 Column 8 Line 8 The PUT function calls basic function block FB3 For a description of FB3 and the NCK VAR selector please refer to References PLCGP Description of Functions Standard Machine Parameters Table 4 5 Parameters for PUT Signat Tpe Valuerange Remarks __ Req VKE TYPE Start job on positive edge UWORD No of variables to be written Addr 8 NCK_VAR Variable names from NCK VAR selector pee S aati addressing variable addressing pone O aati actessing oe e variable addressing pees fie veramie adtesting variable addressing SD 8 S7_ANY_POINTER
79. le Programming example for GET VOID Bsp_GET VOID GET_STAT get ret UWORD i NCK_VAR var 8 UBYTE unit 8 UWORD column 8 UWORD line 8 S7_ANY_POINTER dest 8 for i 0 i lt 8 i R10 to R17 permanent addressing var i syntax_id 0x82 var i bereich_u_einheit 0x41 var i spalte 0x1 var i zeile 10 itl var i bausteintyp 0x15 var i zeilenanzahl 0x1 var i typ Oxf var i laenge 0x8 unit i 0 column i 0 line i 0 Destination for R10 to R17 dest i type TYP_BYTE dest i count var i laenge Siemens AG 1995 All Rights Reserved 6FC5297 3AB60 FB FB 4 7 4 C Call Interface for the Basic PLC Program 4 8 dest i dbNo DB_ 03 96 TEST dest i offset DB _TEST_OFS_GET i dest i count get_ret GET E_R 77 7 Req 8 NumVar var Addr unit Unit column Column line Line dest RD A W 112 0 get_ret Error A_W 112 1 get_ret NDR MW_W 100 get_ret State Data block generated by NCK VAR selector with structure for R10 STRUCT rpa_1l0C1RP STRUCT 6FC5297 3AB60 SYNTAX_ID BYTE B 16 82 bereich_u_einheit byte B 16 41 spalte word W 16 1 zeile word W 16 11 bausteintyp byte B 16 15 ZEILENANZAHL BYTE B 16 1 typ byte B 16 F
80. m Spacebar Inverts the bit on which the red marker is positioned Cursor key down Selects the following signal of the object Cursor key up Selects the preceding signal of the object Siemens AG 1995 All Rights Reserved 6FC5297 3AB60 FB FB 3 17 3 C Block Programming 3 18 03 96 Page down key Selects the last signal of the object Page up key Selects the first signal of the object CTRL key and page down key together Selects the last signal of the last object CTRL key and page up key together Selects the first signal of the first object Tab key Selects the next object Shift and Tab keys together The preceding object is selected CTRL key and cursor to right keys together Increments the number of the S7 object e g PII 1 gt PII 2 CTRL key and cursor to left key together Decrements the number of the S7 object e g memory bit 15 gt memory bit 14 Pos1 key Selects S7 object with the number 0 e g memory bit 15 gt memory bit 0 End key Selects S7 object with the number 127 e g memory bit 15 gt memory bit 127 CTRL key and Pos1 key together Selects the S7 object with a number which is 16 lower e g memory bit 50 gt memory bit 34 CTRL key and End key together Selects the S7 object with a number which is 16 higher e g memory bit 50 gt memory bit 66 Plus key Increments the data byte for a data block e g DB 20 byte 3 gt DB 20 byte 4 Mi
81. ms monitoring for NCK 50s NCK ListMDecGrp WORD 0 16 Activation of extended M group decoding 0 not active 1 16 no of M groups Pr VKE_TYPE PLC NC communication services FB 2 3 4 Put Get PI true active Be VKE_TYPE Transfer of MMC signals to the interface modes program modification etc true active HWheelMMC VKE_TYPE True Handwheel selection via MMC False handwheel selection via user program er De BT re of user areas for u eee DB 2 ee Be _TYPE OB40 local data extension required for processing signals from user there ee eee ee OB40 ceca le rer OB40 ee i ced OB40 6FC5297 3AB60 Siemens AG 1995 All Rights Reserved 4 4 FB FB 03 96 Programming example for RUN_UP Programming example VOID Bsp_RUN_UP VOID S7_POINTER MCP1In MCP1Out CPlStatSend MCP1StatRec unused CPlIn memArea INPUT CPlIn byteNo 0 CPlOut memArea OUTPUT CPlOut byteNo 0 CPlStatSend memArea OUTPUT CPlStatSend byteNo 8 CPlStatRec memArea OUTPUT CPlStatRec byteNo 12 unused memArea 0 unused byteNo 0 RUN_UP 1 MCP1In MCPlOut MCP1StatSend MCP1StatRec 6 700 200 unused unused unused unused 0 700 200 0 unused unused unused unused 2042 65 F004 4010 217 Lin 25027 Ly 200 50000UL 1 VKE_TRUE VKE_TRUE VKE_TRUE TO VKE_FALSE VKE_FALSE VKE_FALS VKE_FALS Siemens
82. n both directions by defined time controlled selection logic The function can only be used for digital main spindle drives and must be called up separately for each spindle The YDelta function calls up basic function block FC17 For a description of FC17 please refer to References PLCGP Description of Functions Standard Machine Table 4 23 Parameters for YDelta Signat Type Valuerange Remarks 2 m YDelta VKE_TYPE 0 star 1 delta The selection edge of the signal initiates the selection SpindlelFNo UWORD Number of spindle interface ULONG 0 _______ Selection time UWORD Timer for programming the wait time Table 4 24 Return parameters for YDelta Signat Tpe Value range Remarks o ctivation of the star contactor VKE_TYPE __ Activation of the star contact elta ctivation of the delta contactor VKE_TYPE __ Activation of the delta contact Programming example for Ydelta VOID Bsp_YDelta YDELTA_STAT ydelta_ret S7_DB_HANDLE db34 AUF_DB 34 ydelta_ret YDelta E_R 77 0 YDelta 4 SpindleIFNo 3000 TimeVal 3s 10 Ve TimerNo D_W db34 21 3 VKE_FALSE Acknowledge motor selection Initiate selection A_W 113 3 ydelta_ret Y A_W 113 2 ydelta_ret Delta Siemens AG 1995 All Rights Reserved 6FC5297 3AB60 FB FB 4 25 4 C Call Interface for the Basic PLC Program 03 96 4 2 12
83. nctions is identical to that of the appropriate STEP 7 functions Please refer to References S7 User Manual The following S7 program execution levels are available for the C program blocks These levels are called up by the system according to defined events Depending on the event or program execution level one of the following functions is called by the system Table 3 6 Functions for program execution levels Cf 57 StdAppiCycle StdTimeAlert Time of day alarm OB 10 2 Function is called at user defined time preparation ee Delay alarm OB 20 3 Function is called after expiry of delay defined by user StdWatchdogAlert Watchdog alarm OB 35 12 Function is called periodically according to user defined time default 100 ms StdProcessAlert Process alarm OB 40 16 Call implemented by process signals e g alarm module M function transfer from NCK StdApplStart Start up OB 100 27 Function is called on system start With regard to execution level priorities the execution level with the highest ordinal number interrupts the level with the lowest ordinal number 6FC5297 3AB60 Siemens AG 1995 All Rights Reserved FB FB 03 96 Return values 3 C Block Programming Please note that a number of the functions have a return type which starts with the prefix F_ or SFC_ If you define a variable which receives the return value then you should do this with the data type of the same name without the prefix
84. nennnnnnnnnnnnnnnnnnnnnnnnnnnnnn ernennen nenn 3 27 3 2 10 Notes on testing nn een ii un n 3 30 3 3 Generating and loading a block uuneesnsnssssnnnnersnnnnnnnnnnnen ernennen nennen nenn nennnnnnnnn nn 3 33 3 3 1 Generating a C block een na ep 3 33 3 3 2 L ading a C bl ck u ren en en anfing ensere 3 35 34 On line monitor anreisen n he 3 39 Siemens AG 1995 All Rights Reserved 6FC5297 3AB60 FB FB 3 1 3 C Block Programming 03 96 3 1 Conventions 3 1 1 Language and functionality The full functionality in accordance with the ANSI C standard is available for the C applications Functions which require a specific type of environment for example output or file functions etc and which cannot operate either in the S7 or in the PC test environment are naturally not permissible Function expansions of the tasking C compiler specific to the 80165 cannot be tested with the off line environment It is not permissible to change the processor setting or to access the special function register of the SAB 80C165 microcontroller In addition to the ANSI C vocabulary a series of S7 basic instructions are also provided Process image You can access the process image for read or write purposes either bit by bit functions byte by byte word by word or in doublewords You must distinguish between the input area of the process image PII and the output area of the process image PIQ Table 3 1 Process imag
85. ng the monitor block Activating the monitor Starting the monitor Breakpoint handling 3 40 03 96 In order to activate the monitor you must first load the monitor block into the PLC This is performed by means of control file monload bat Note The monitor block can be loaded only if alternating buffer operation is deselected The monitor is activated on the basis of data bit 500 0 in communication data block DB 70 DB70 DBX500 0 0 Normal operating mode 1 Debug mode with HITEX monitor Note After setting this data bit it is absolutely essential to execute a complete PLC restart because the monitor block is activated in OB100 The HiTOP dialog software is started with control file monstart bat This file activates the MPI interface and calls the dialog software hit_167 exe When the dialog software is started the HiScript file startup scr is called This presets certain variables for the interface and loads the symbol table You can use files startup scr and hit_167 cfg to customize the dialog software After successful initialization of the monitor block in event of an error note MW 50 and MW 52 cyclical operation is initiated Note The C block is not operative after initialization of the monitor block The C block can be controlled after activation of the monitor block and start of the dialog interface Caution When testing C blocks with the on line monitor please note the following points e I
86. nment IDE for DOS of Borland C First select the directory which you specified when setting up the demo project in the Project Open menu by entering the directory name or selecting the drive and directories Now go into the subdirectory named project where you will find the project file rd_tisch prj Now activate menu item Window Project The project window of the example project will then appear on your Borland interface see Fig 3 3 Project window of example project s Borland C ja Project Fig 3 3 Project window of example project The project window contains all the files required to generate the example application in an executable form 6FC5297 3AB60 Siemens AG 1995 All Rights Reserved FB FB 03 96 Library Source files for runtime levels Source files for example project 3 C Block Programming The first entry in this project window i e file cs7dlib lib is the library supplied with CS7DLIB It provides you with a runtime environment and PLC functions on your PC as well as special functions for the off line test The next files entered in the project window i e user_ini c user_cyc c user_alt c time_alt c dely_alt c wdog_alt c and user_err c contain the function bodies for the actual PLC user program The user can program his PLC application in these files e user_ini c contains the start function StdAppIStart which is called during start up see OB100 This function calls the C bas
87. nneennnnnnnnnnnnnnnnnnnnnnnnnnnnnnnsnnnnnnnnnnnnnnnnnnnrnsnnnnnnnnn nenne nerssnnnnnnnnnnnnn 3 1 3 1 CONVENON S icii keieren hapa ea Three ihre 3 2 3 1 1 Language and functionality 00 0 0 eee eeeeeeee cence ee eeneeeeeeeaaeeeseneeeeesaeeeseeaaeeeenneeeene 3 2 3 1 2 USe 0f datatypes 0m sans ala nee 3 8 Sid 3 670 p 211 1 91 E ETE TETA E E T OT 3 10 3 1 4 Runtime environment and standard program Structure 20 0 0 eeeeeeeeeeeeeeeeeeeeeeeeeee 3 10 3 2 Off line program development uursnneesessnnnnennnnnnnnnnnnnennnnnn nennen nnnnnnn ernennen nn 3 12 3 2 1 Example project rotary table control uu enueseersnnnnnesnnnnnnnnnnnnnnennnnnnnnnnnnnnnnnnnnnn nn 3 12 3 2 2 Header files for PLC and PC environment 2244444444HHn nennen nenne nennen nennen nn 3 16 3 2 3 Standard visualization objects 0 ee eee nennen snnnnnennnnnnnnnnnnnnn nme nennen ern nnnn nn 3 17 3 2 4 User defined visualization objects uusr224usseersnnnnneennnnennnnnnnnnnnnnnnn nennen ann nnnn nn 3 20 3 2 5 SiMulation roufinesz 2 2 ha ee anne nes edendesade cep tan denen 3 24 3 2 6 Presetting data during start up of test environment 3 25 3 27 Termination procedure u ren ee ta est 3 26 3 2 8 Setting configuration data uusersnnesnessnnnennnnnnnnnnnnnnn nennen ernennen a 3 27 3 2 9 Test of alarm runtime levels essen nennen a eau Nii 3 27 3 2 10 Notes on testing 2 Nu ne en Aa seen iea e Eee Ee er
88. nus key Decrements the data byte for a data block e g DB 20 byte 3 gt DB 20 byte 2 The program is aborted with the ESC key In this case altered bits are stored in a file file name can be specified in the supplied C source file user_cfg c These bits are restored on the next start and become visible again provided they have not been overwritten by the user The most important keys are summarized in Fig 3 6 Operator control of visualization objects 6FC5297 3AB60 Siemens AG 1995 All Rights Reserved FB FB 03 96 Siemens AG 1995 All Rights Reserved FB FB 3 C Block Programming Select preceding bit Cursor up Cursor down Select next bit DB object Select first bit un Page up j Select last bit DB object B 60 0 Bit 0 Bit 1 Bit 2 Bit 3 Bit 4 Bit 5 Bit 6 Bit 7 o 20000 0 o 1st object B 60 0 Bit 0 Bit 1 Bit 2 Bit 3 Bit 4 Bit 5 Bit 6 Bit 7 oooo0o00 0 o Center object to next object bit 0 i B 60 0 TAB gt SHIFT TAB to preceding object bit 7 oooo000 0 Bit 0 Bit 1 Bit 2 Bit 3 Bit 4 Bit 5 Bit 6 Bit 7 to first object bit 0 Ctrl page up to last object bit 7 Ctrl page down Last obj B 60 0 Bit 0 Bit 1 Bit 2 Bit 3 Bit 4 Bit 5 Bit 6 Bit 7
89. o be added to the compiler and linker sections The return to the project directory must be added to the end of control file abmain bat Note In the event of warnings or error messages please see Section 5 2 Response to errors or References BSO Users Guide 6FC5297 3AB60 Siemens AG 1995 All Rights Reserved 3 34 FB FB 03 96 3 C Block Programming 3 3 2 Loading a C block Memory allocation on the PLC STEP 7 memory C memory Example for PLC memory allocation The memory of the PLC can be enabled explicitly via machine data Changes to these machine data only become effective after general resetting of the PLC The enabling of C memory reduces the available STEP 7 memory If the machine data settings cause overlapping of the memory areas the C memory has a higher priority than the STEP 7 memory The size of the STEP 7 memory can be set in the general machine data ON_PLC_USER_MEM_ SIZE The default setting is 2 i e 64 Kbytes of STEP 7 memory are enabled AS314 ON_PLC_USER_MEM_SIZE Oto3 0 to 3 220 KB AS315 ON_PLC_USER_MEM_SIZE Oto6 0 to 6 220 KB Owing to the special memory allocation method of STEP 7 the memory requirements is as follows depending on the machine data Table 3 7 Memory requirements of the STEP 7 memory ee ee een ae P1820 Kbytes The size of the C memory can be set in the general machine data ON_PLC_C_USER_MEM SIZE The default setting is 0 i e no C memory is
90. o the position the motor switches from rapid traverse to creep speed e Positioning is implemented by means of 3 cam switches with binary positional values 1 2 and 4 Positions 1 to 7 are defined on the basis of these cam switches e The position reached is maintained by an index bolt This bolt has 2 positions retracted extended and is fixed by means of valves e The end support likewise has 2 positions clamped unclamped and is valve controlled The support is unclamped during the traversing motion e The positioning operation is started by means of an expanded M function e The read in disable is transferred to the NC during positioning Signal description Table 5 5 Input signals for rotary table positioning example project Input signal Description 0 Limit switch Motor table in position 6FC5297 3AB60 Siemens AG 1995 All Rights Reserved 5 8 FB FB 03 96 5 Miscellaneous Table 5 6 Output signals for rotary table positioning example project Enable Motor clockwise rotation Enable Motor counter clockwise rotation Table 5 7 Interface signals for rotary table positioning example project Interface signals M_Funktion M function for rotary table e g M1 90 90 rotary table M_Adresse M address for position e g M1 90 1 Position Einlesesperre_an_NC Read in disable to NC Siemens AG 1995 All Rights Reserved 6FC5297 3AB60 FB FB 5 9 5 Miscellaneous Description of operational
91. ollowing items to develop and test C PLC programs on the PC e C development package Borland C 3 0 or 3 1 with DOS component or Turbo C 3 0 for off line environment e CS7DLIB extension from SIEMENS In order to install the development system you must follow the installation instructions in the documentation of the development system You do not need to install the Windows components the class libraries or their on line documentation as only the DOS components are required Nor do you need to install the source text of the libraries supplied by Borland To avoid having to make changes to the project file supplied with the CS7DLIB software package you should install the development system under directory C BORLANDC Otherwise you must change the path name for the include and library directories to your path in menu Options Directories After inserting the installation diskette into drive A install CS7DLIB by entering the following command Enter a gt install TargetDirectory Please enter a directory name of your choice for the TargetDirectory parameter and specify the destination drive Example a gt install C CS7DLIB This command copies the supplied files from the installation diskette plus all subdirectories into the specified directory The supplied example project can be generated from the directory created in the above operation Enter c cs7dlib gt instdemo DemoDirectory You must specify a directory name for
92. opies the supplied files from the installation diskette with all subdirectories to directory CS7TOOLS in the specified drive The AUTOEXEC BAT file must be extended as follows Path name for BSO tools lt LW gt C166 BIN386 Path name for CS7 tools lt LW gt CS7TOOLS Environment variables for include files set C166INC lt LW gt C166 INCLUDE Environment variables for MPI working directory set TEMP lt LW gt TEMP Environment variables in MPI driver directory set BTDIR lt LW gt CS7TOOLS MPI Settings for DOS extender set DOS16M 11 set DOS4GVM NEW4G VMC set DOS4GPATH lt BSO main directory gt bin386 e g c c166 bin386 References BSO Users Guide 6FC5297 3AB60 Siemens AG 1995 All Rights Reserved FB FB 03 96 2 3 Description of individual directories Siemens AG 1995 All Rights Reserved FB FB Overview of directory structure 2 Components and Installation The following diagram shows you the directory structure of a C block project Fig 2 3 C166 path e g C166 bin386 Borland path e g BORLANDC E37 Project path e g SIN_APPL Tool path e g CS7TOOLS Bild_2 3 DS4 include project bin bin_c166 sys_inc doc mpi gp840d hitex Overview of main directory paths C166 development system BSO C166 development system BSO Assembler header files help files etc BSO C header files of C166 development system Library
93. ory reset e System times and STEP 7 runtime levels remain active even if the C application has reached a stop point e Prior to every debug session the C block must be reloaded on the PLC and a PLC reset executed e The on line monitor supports debugging only in the basic cycle StdApplCycle The C alarm runtime levels are not processed in monitor operation Siemens AG 1995 All Rights Reserved 6FC5297 3AB60 FB FB 3 41 3 C Block Programming User related functions 3 42 03 96 The most important functions are given below Table 3 8 User related functions Key combination File Load Load symbol file for View List window File name Symbolfile sym File type SYMBOLS All other input fields options are irrelevant Define Breakpoint_ Definestoppoint_ DB View Instruction Display and modify code in assembler VI representation Display RAM Display and modify monitoring points Execute a machine command Into Command execution up to next C line this command can also be used to branch to functions This command is used to exit a function which you have entered with Go Into calls are skipped Start program execution Halt Stop program execution Shift F9 Program execution up to a certain address Options Update Setting to define which window must be OU refreshed cyclically Symbols Display symbols ON OFF Screen Change text resolution It is possible to call a local submenu w
94. owledgement Programming example Programming example for AL_MSG VOID Bsp_AL_MSG S7_DB_HANDLE db2 AUF_DB 2 D_W db2 1 0 E_R 77 3 BM 510008 D_W db2 0 0 E_R 77 4 FM 510000 AL_MSG VKE_FALSE ToUserIF E_R 77 2 7 Quit Siemens AG 1995 All Rights Reserved 6FC5297 3AB60 FB FB 4 19 4 C Call Interface for the Basic PLC Program 03 96 4 2 8 BHGDisp display control for the handheld operator panel Function description Parameters Return parameters Programming example 4 20 This function controls the display of the handheld operator panel The BHGDisp function calls up basic function block FC13 For a description of FC13 please refer to References PLCGP Description of Functions Standard Machine Table 4 17 Parameters for BHGDisp Signat Type Value range Remarks O Row UBYTE 0 3 Display row 0 no display output 1 Row 1 2 Row 2 3 Row 1 and row 2 ChrArrray 32 BYTE Complete display contents VKE_TYPE Activation of numeric conversion i S7_ POINTE fod Points to variable to be converted ieee SBYTE Data type of variable 1 Bool 1 character Byte 3 characters Char 1 character Word 5 characters Int 6 characters Dword 7 characters Dint 8 characters Real 9 characters see Parameter Digits Digits UBYTE 1 3 Only relevant for data type Real with leading sign LS 1 6 1 digits wi
95. re also enter this instruction in the implementation files you create yourself The prototype header files refer to higher level header files which generally contain constants as well as the declaration of data types which are relevant for more than one implementation file This hierarchy allows a clearly structured modularization to be implemented on a large scale permitting modules to be removed if they are not required for functional purposes and to be added relatively easily and without adverse affects The additions for the test environment are structured according to the same principle The prototypes of the additional services of library cs7dlib are entered in header file cs7_dlib h Implementation files intended solely for the test environment contain therefore the include instruction for the two library header files cs7_clib h and cs7_dlib h in addition to the instruction for their own prototype header files System header files are stored under the path sys_inc user defined header files should be stored under the path user_inc 6FC5297 3AB60 Siemens AG 1995 All Rights Reserved FB FB 03 96 3 C Block Programming 3 2 3 Standard visualization objects Operator control CSDLIB offers a range of standard display objects which can be called by means of function keys These objects were specially selected to ensure that several representatives of each supported S7 object are available so that the user is provided q
96. refore be independent of the appropriate destination system and thus fully testable on the PC with CS7DLIB Data are either declared in the C program modules or in S7 data blocks and bit memories If data need to be available in the S7 world or via interfaces on external devices e g for operator interfaces or NCK then they must be stored in S7 data blocks or flags the SIMATIC byte order see Fig 3 1 SIMATIC byte order must be observed in this case if applicable S7 data are always stored with the highest order byte at the lowest address Owing to the memory segmentation of the CPU 314 destination processor the following must be noted with respect to global or static variables e Up to 32K so called near data which can be accessed particularly quickly Use the elementary data types UBYTE WORD without prefix for these data see Fig 3 2 Overview of data types Data objects within the near data area must not be larger than 16K e An unlimited so called huge data area extended memory area Use of this area effects a slightly slower and more comprehensive code Create this type of data using the elementary data types with the prefix G_ e g G_UBYTE G_WORD see Fig 3 2 Overview of data types If possible access operations to huge data should be minimized by careful memory page allocation The absolute memory address within these areas cannot be influenced by the user 6FC5297 3AB60 Siemens AG 1995 All Rights Reserved F
97. rs access to NCK functionality see Section C Call Interface for the Basic PLC Program The examples supplied for simulation and visualization can be adapted or extended for the off line test see Section 3 2 Off line program development 6FC5297 3AB60 Siemens AG 1995 All Rights Reserved 3 10 FB FB 03 96 Example project 3 C Block Programming The example project supplied has a standard structure which is tailored to NCK applications It can be executed immediately in the off line development environment Control file ABMAIN BAT can be used to generate a C block from the source files of the example project this C block can be executed immediately on the PLC Siemens AG 1995 All Rights Reserved 6FC5297 3AB60 FB FB 3 11 3 C Block Programming 03 96 3 2 Off line program development What is in this Section This Section explains the structure and handling of the CS7DLIB off line development environment on the basis of the supplied example project Rotary table The example below can be translated and executed immediately both in the PC development environment and in the PLC development environment Note Please refer to Section 5 4 Example project Rotary table positioning for a description of the example project 3 2 1 Example project rotary table control Open example project Files in project window 3 12 If you want to open the example project please start the integrated development enviro
98. s of the Borland package will not be found during linking You can set up a new project as follows Enter c cs7dlib gt new_prj c ProjectDirectory ProjectName The path name of the new project must be specified in the ProjectDirectory parameter and the project name must be specified in ProjectName Example c cs7dlib gt new_prj c wzm_plc std_plcp The project file you have now created is assigned the project name you have specified all subdirectories required for the project are set up and the necessary files stored in the directory with the name entered above The Borland C development system offers numerous options which you can set via menus Please note the following points e The CS7DLIB requires the large memory model of Borland C and also expects a DOS EXE file to be generated e The two paths SYS_INC and USR_INC are entered as include directories for the project in addition to the Borland path e The OBJ and EXE files of the project are stored in the BIN project directory e The PROJECT project directory is used as the starting point for calling up the development environment 6FC5297 3AB60 Siemens AG 1995 All Rights Reserved FB FB 03 96 2 Components and Installation 2 2 Development environment for PLC C166 development system On line monitor Runtime library The following items are required for generating and loading a C block on the PLC BSO tasking tools version 4 0 d
99. s with call number 0 14 for one C block at a time Siemens AG 1995 All Rights Reserved 6FC5297 3AB60 FB FB 5 5 5 Miscellaneous Information about linker locater error messages Error handler for C library functions 5 6 03 96 Table 5 4 Linker locater error messages Error Meaning oS O Warning 130 missing system stack definition This message is caused by the runtime system and has no significance Warning 152 class name s not found Non critical warning if a class not contained in the current object is specified in the class instruction Warning 193 class s without classes control Remedy Include the designated section in the classes instruction for ROM or RAM or else the program response is not defined Error 268 s linear element s s cannot be located within 4 pages Remedy Check first whether the DPP assignments are correct DPP formula base address of specified data area 16k e g 90000H 16k 36 Error 270 s segmented element s s cannot be located The available memory has been exceeded increase the specified memory limits for code or data section of locater The C library cs7rtlib Ino provides a freely programmable error handler StdErrorHandler user_err c to which the program branches in the case of runtime errors After processing your application is continued You can add application specific error handling actions to the error handler The error codes for the d
100. sequence 5 10 03 96 Rotary tabe YES already i ___ position d _ NO C End gt Read in disable 1 Unclamp end support 1 clamp 0 Extend index 1 retract 0 End support clamped 0 Retract index 0 Index extended 1 Set Setpoint position eS actual position YES Counter clockwise rotation 1 Clockwise rotation 1 High speed Lee Setpoint position ee NO FL actual position YES High speed 0 lt z In position 1 Counter clockwise rotation 0 Clockwise rotation 0 Retract index 1 extend 0 Index retracted 1 Index extended 0 YES Clamp end support 1 unclamp 0 u u End support clamped YES Read in disable 0 2 E W BILD_5 3 DS4 w End Bi Fig 5 2 Flowchart Siemens AG 1995 All Rights Reserved 6FC5297 3AB60 FB FB Abbreviations AB Assembler block AS314 Automation System 314 AS315 Automation System 315 DB Data Block SIMATIC S7 FB Function Block SIMATIC S7 FC Function Call SIMATIC S7 MMC Man Machine Communication MPI Multipoint Interface NCK NC Kernel OB Organization Block SIMATIC S7 PII Process Input Image PIQ Process Output Image PLC Programmable Logic Controller SDB System Data Block SIMATIC S7 STL Statement List Siemens AG 1995 All Rights Reserved 6FC5297 3AB60 FB FB References BSO 80C166 Assembler
101. sungen return BILD3 11 DS4 Fig 3 11 Generating screen pages Assignment of You can always view the assignment of the function keys by pressing function function keys key F1 when an application is active The first keys are allocated to predefined system displays When you register your visualization objects you occupy further function keys After function key F10 you must press the CTRL key and the function key simultaneously identified by F1 i e press CTRL key and F1 key simultaneously Siemens AG 1995 All Rights Reserved 6FC5297 3AB60 FB FB 3 23 3 C Block Programming 3 2 5 Simulation routines Simulation in example project 3 24 03 96 CS7DLIB offers you the means to create your own simulation routines In the example file rund_tst c of the example project you will find a machine simulation for sequence control rund c as a guide to how this type of simulation can be incorporated in your application Experiment with this option by making changes in the example project and then use the facility if you need to Fig 3 12 Simulation with CS7DLIB gives you an overview of the simulation routine option Simulation objects Link to process Image or to I O In place of real I O Supply signal responses incl time based like genuine signal responses parameterlzable within limits BILD3 12 DS4 Fig 3 12 Can be incorporated in user application through easy parameterization R
102. t opened and press the Return key This causes a further Inspect window to be opened in which the byte index enclosed in square brackets of the process input image is displayed line by line in the left hand column and the current value of the assigned position is output on the right in two representation modes i e character and decimal representation e If you want the program to continue after completing your analysis press CTRL F9 RUN again Program execution will now continue provided that no further breakpoints are encountered or a termination command given with ESC Siemens AG 1995 All Rights Reserved 6FC5297 3AB60 FB FB 3 31 3 C Block Programming Displaying counters and timers Information about CS7DLIB test system 3 32 03 96 VRR Prozefabbild Eingange TOBE extern Prozepabbild Ausg nge ACHTUNG ACHTUNG ACHTUNG A f I Inspecting p_dbg_inputs 1 t er t a ll ll Bild 3 18 Process image display This example shows you how you can process the code step by step and while doing so monitor its effects using the Borland debugger tools and the pointers prepared for access to system objects such as process image counters timers bit memories or data blocks see file user_g b c Counters and timers are not often easy to test because the counter or timer events usually do not occur until the program has been executed many times In order to test the elementary ef
103. ta blocks required by the user The system then converts these configuration entries e pset_udt c is called in the start up phase of the test system and allows you to preset values for data and S7 objects When the test system is terminated with the escape key the status of the S7 objects is stored on restart This system is restored again when the test system is restarted This restoration is followed by execution of pset_udt c e usim_ini c is used to initialize the user simulation The system activates this function on system power up e uviewini c provides you with space to insert the registration routines for user defined visualization objects The system activates this function on system start up e u_test_f c provides you with space to insert the calls for user test functions during system start up The user can perform preliminary tests on his functions independently of the system in this file any required clean up operations e g resetting S7 objects and data deletion of unneeded data blocks are automatically performed by the system e user_sim c provides you with space to insert user simulation routines which must be called in every cycle e user_glb c contains standardized debug pointers which have been initialized by the system These allow you to view the current values of the system objects with the aid of the integrated Borland debugger e user_shd c is called when the test system is terminated with the escape key i
104. the DemoDirectory parameter Example c cs7dlib gt instdemo cs7_demo Siemens AG 1995 All Rights Reserved 6FC5297 3AB60 FB FB 2 3 2 Components and Installation Setting up a new project Development environment settings 03 96 Installation of CS7DLIB on hard disk gt a or from CS7DLIB directory on hard disk gt install c CS7DLIB After installation complete message start Borland C and open the appropriate file in the directory of the specified project subdirectory project Installation of demo project on hard disk gt a or from CS7DLIB directory on hard disk gt instdemo C CS7_DEMO Destination drive for new project If you observe the recommended conventions for the compiler directories then you can start the project with menu item Run Run Setting up a new user project gt a or from CS7DLIB directory on hard disk gt new_prj C PRJ_APP1 PLC_APP1 N stands for path name stands for name of project of project Bild_2 2 DS4 Fig 2 2 Installation of CS7DLIB and example project Setting up a user project Note This version is based on the assumption that Borland C has been installed in directory C BORLANDC If this is not the case then the entries in menu Options Directories must be changed to the actual path of the Borland compiler or else header files will not be found during compilation and library file
105. thout LS 2 5 2 digits without LS 3 4 3 digits without LS Table 4 18 Return parameters for BHGDisp Signal Type Value range Remarks O Error VKE_TYPE Conversion error number overflow or StringAddr error Programming example for BHGDisp VOID Bsp_BHGDisp VOID BHGDISP_STAT bhgdisp_ret static UWORD cycle S7_POINTER varl var2 BYTE bhgdisp MAX_STR_LEN 1 Zeile 1 Zeile 2 a ee Wwe S7_DB_HANDLE dbtest AUF_DB DB_TEST Assign address for varl 6FC5297 3AB60 Siemens AG 1995 All Rights Reserved FB FB 03 96 4 C Call Interface for the Basic PLC Program varl memArea DATABLOCK DB_TEST_OFS_BHG 0 DB_TEST varl byteNo varl dbNo Assign address for var2 var2 memArea DATABLOCK DB_TEST_OFS_BHG 4 PBA TEST var2 byteNo var2 dbNo Write values for varl and var2 to dbtest if E_R 76 5 DD_W dbtest varl byteNo F2L 0 5 DD_W dbtest var2 byteNo F2L 10 0 else DD_W dbtest varl byteNo F2L 0 5 DD_W dbtest var2 byteNo F2L 10 0 switch cycle case 1 Write first display row bhgdisp_ret BHGDisp 1 Row bhgdisp ChrArray E_R 76 4 Convert varl Addr 8 DataType 16 StringAddr 3 ey Digits A_W 113 6 bhgdisp_ret Error cycle 2 break case 2 Write second display row bhgdisp_ret
106. uch that it is possible to select the operating modes from either the MCP or the OP The MCP_IFM function calls up basic function block FC19 For a description of FC19 please refer to References PLCGP Description of Functions Standard Machine Table 4 28 Parameters for MCP_IFM Signal Type Valuerange Remarks __ __ S BAGNo UBYTE 0 1 No of mode group to which the operating mode signals are transferred signals pee eee Peeing eee een as a spindle Table 4 29 Return parameters for MCP_IFM Signat Type Value range Remarks 202 FeedHold VKE_TYPE Feed hold from MCP modal SpindleHold VKE_TYPE Spindle hold from MCP modal Programming example for MCP_IFM VOID Bsp_MCP_IFM MCP_IFM_STAT ifm_ret ifm_ret MCP_IFM 1 ModeGrpNo 1 ChanNo 4 SpindleIFNo Signals to LEDs A_W 104 0 ifm_ret FeedHold A_W 104 1 ifm_ret SpindleHold 6FC5297 3AB60 Siemens AG 1995 All Rights Reserved FB FB 03 96 4 C Call Interface for the Basic PLC Program 4 2 14 MCP_IFT transfer of MCP OP signals to the interface Function description Parameters Return parameters Programming example The MCP_IFT function T variant can be used to transfer operating modes the direction keys of 4 axes WCS MCS switchover travel keys overrides and keyswitch from the machine control panel MCP to the corresponding signals on the NCK PLC interface In the b
107. uickly with basic ready programmed tools for testing an application With these tools he can monitor and influence the effects of important sections of an application CS7DLIB offers visualization objects for the S7 objects PA Eingange PA Ausgange Pat 1 PAA 15 I 1 2 3 i i il 5 6 fl ii SOA OIE ON SS SS SSS Fig 3 5 Display of standard visualization objects The system automatically displays 4 screens with different combinations When you can see the bit assignment in the bit display you will find it is possible to interpret the values quickly and to change them just as quickly by entering new ones The changed bits remain valid over and beyond the life of the program if you terminate the program with the ESC key and the value is not overwritten by the program The set object display remains unchanged during the program life provided it is not altered Even if you switch over to other screens you will still find the set object display on the original screen when you return to it later Keys have been defined for operator control which are based on commonly used key assignments inasmuch as comparable examples exist A few notes on operator control are given below e When the demo program is started screen displays can be called via function keys Some of these displays are a feature of the system others originate from the user program e If S7 objects are visualized then the following keys can be used to control the
108. ys if Ugg i Uys if Uys if Uys if Uys if Uggs if Uggs if rt hi Uggs if Uggs if rt hip Ug hip It if BILD3 21 DS4 3 C Block Programming 80000H Start address of C block area MD 19280 4 90000H A0000H BOOOOH B8000H C0000H End address of C block area PLC type AS314 Allocation of C memory with active alternating buffer using the example of an AS314 also applies to AS315 When the alternating buffer is deactivated the code section always begins at the start address of the C block area The data section is located directly after the code section If a monitor block is installed it is located permanently at the end of the C block area see Fig 3 22 Important Allocation of C memory The alternating buffer must always be deactivated when the monitor block is loaded Siemens AG 1995 All Rights Reserved FB FB 6FC5297 3AB60 3 37 3 C Block Programming Loading the C program Loading the PLC basic program 3 38 03 96 80000H Start address of C block area Code section MD 19280 4 CODE 64k 90000H Data section DATA 32k 98000H Free memory B8000H Reserved for monitor C0000H End address of C block area PLC type AS314 Fig 3 22 Allocation of C memory with deactivated alternating buffer using the example of an AS314 also applies to AS315 The C block abmain mc5 generated by block generator ab_gen exe is

Download Pdf Manuals

image

Related Search

Related Contents

Manuel d`utilisation  Samsung NP930X5JI User Manual (Windows8.1)  Eglo ILANIE  

Copyright © All rights reserved.
Failed to retrieve file