Home
C Programmer`s Toolkit for PACSystems User`s Manual, GFK
Contents
1. Include File include lt string h gt include lt string h gt include lt string h gt Supported C Run Time Library Functions Associated with File size_t strspn const char const char char strstr const char const char a char strtok_r char string const char separators char ppLast C Programmer s Toolkit for PACSystems User s Manual January 2012 Series 90 C Run Time Library Compatibility Notes Issues Errno information and return value exceptions This function does not set errno Note NULL or invalid input pointers to this function will put the CPU into CPU Halted mode This function does not set errno Note NULL or invalid input pointers to this function will put the CPU into CPU Halted mode strtok and _fstrtok are not supported since they are not re entrant Description This routine considers the null terminated string as a sequence of zero or more text tokens separated by spans of one or more characters from the separator string separators The argument ppLast points to a user provided pointer which in turn points to the position within string at which scanning should begin In the first call to this routine string points to a null terminated string separators points to a null terminated string of separator characters and ppLast points to a NULL pointer The function returns a pointer to the first character of the first token writes a nu
2. no parameters to GefMain PW 1 RW 1 Copy R1 to P1 LW 1 RW 2 Copy R2 to L1 return GEF_EXECUTION_OK Since L1 is actually P1 in this case this results in P1 being set to the value contained in R2 Again this is because P and L when used in a block refer to the same memory table when called from the marn ladder logic block Conversely when this same block is called from any ladder sub block the result will be that P1 equals R1 and that L1 equals R2 Note Refer to Blocks as Timed or I O Interrupt Blocks for an explanation of P and L in interrupt blocks Chapter 3 Writing a C Application 3 131 P and L in Ladder Logic The references P and L refer to two of the PLC s internal memory tables Each of these types is word oriented Descriptions of P and L Type Description P The prefix P is used to assign program register references which will store program data from the main program block This data can be accessed from all program blocks The size of the P data block is based on the highest P reference in all ladder logic program blocks L The prefix L is used to assign local register references which will store data unique to a ladder logic program block The size of the L data block is based upon the highest L reference in the associated ladder logic program block Both P and L user references have a scope associated with them Each
3. NOTE time stamps are in BCD format struct time_stamp_rec T_BYTE second BCD format seconds tens of seconds i T_BYTE minute BCD format same T_BYTE hour BCD format same T_BYTE day BCD format same T_BYTE month BCD format same T_BYTE year BCD format same struct ext_time_stamp_rec T_BYTE second BCD tens T_BYTE minute BCD T_BYTE hour BCD T_BYTE day BCD T_BYTE month BCD T BYTE year BCD T_WORD millisecond BCD format format format format format format format in low order xxTx hundreds next xHxx de struct PLC flt address rec T_BYTE rack T_BYTE slot T_WORD task struct IO _flt_address rec T_BYTE rack T_BYTE slot T_BYTE IO bus T_BYTE block T_WORD point struct reference address rec T_BYTE memory _ type T_WORD offset Chapter 3 Writing a C Application in as as as as as seconds in low order nibble of seconds in high order nibble for seconds for seconds for seconds for seconds for seconds same same same same same 32 in low order nibble high order nibble for for for for for as as as as as OHTO ms nibble xxx0O seconds seconds seconds seconds seconds format milliseconds tens next 3 73 3 74 Note this is the long PLC fault entry type struct
4. TLIB_ERRNO_MSG_INVALID_PORT TLIB_ERRNO_MSG_NOT_CONFIGURED TLIB_ERRNO_MSG_INVALID_LENGTH New function to provide serial input Errnos TLIB_ERRNO_MSG_INVALID_PORT TLIB_ERRNO_MSG_NOT_CONFIGURED TLIB_ERRNO_MSG_INVALID_LENGTH A 19 Target Library General Functions Structures and Constants Series 90 PLC Library Compatibility Notes amp Issues T_INT32 PLCC_CharsInMessageWriteQ T_INT32 port New function that Returns the number of bytes in the write queue Errnos TLIB_ERRNO_MSG_INVALID_PORT TLIB_ERRNO_MSG_NOT_CONFIGURED T_INT32 PLCC_CharsInMessageRead T_INT32 port char buffer T_INT32 New function that returns the number of bytes in the read queue Errnos TLIB_ERRNO_MSG_INVALID_PORT TLIB_ERRNO_MSG_NOT_CONFIGURED Functions based on service requests from the SVCREQ function block T_INT32 PLCC_const_sweep_timer struct const_sweep_timer_rec x Compatible with 90 70 and 90 30 except that Microcycle 90 70 is Change Read Constant Sweep Timer not supported struct const_sweep_input_rec T_WORD action T_WORD timer_value E structure with return values struct const_sweep_output_rec T_WORD sweep_mode T_WORD current_time_value E struct const_sweep_timer_rec union struct const_sweep_input_rec input struct const_sweep_output_rec output action values define DISABLE_CONSTANT_SWEEP_MODE 0 define ENABLE_CONSTANT_SWEEP_MODE 1 define CHANGE_TIMER_VALUE 2 define READ_TIMER_VALU
5. InParam pDestVarInfo Pointer to a PLC_VAR_REC information record for the destination variable InParam pSrcVarInfo Pointer to a PLC_VAR_REC information record for the destination variable ReturnVal GEF_OK if successful GEF_ERROR for bad parameter Use Errno to determine cause Errno If there is an error this function sets Errno to give specific information on what caused the error Applications that use Errno should first call PLCC_ClearErrno to ensure Errno was not already set by another function call Errno can be read using PLCC_GetErrno Errno values are provided in ctkPlcErrno h Chapter 3 Writing a C Application 3 117 3 118 Proc PicVarType typedef enum PLC_BOOL VAR TYPE 0 PLC_BYTE_VAR_TYPE 13 PLC_WORD_VAR_TYPE 14 PLC_INT_VAR_TYPE 25 PLC_UINT_VAR_TYPE 26 PLC_DWORD VAR TYPE 18 PLC_DINT_VAR_TYPE 115 PLC_REAL VAR_TYPE 27 PLC_STRING_VAR_TYPE 24 PLC_INVALID_VAR_TYPE 0xFFFFFFFF PLC_VAR_TYPES extern T_DWORD PlcVarType PLC_VAR_REC pVarInfo Description This function returns the type value for a PLC variable InParam pVarlnfo Pointer to a PLC_VAR_REC information record ReturnVal varType Value defining the type of the PLC variable Returns PLC_INVALID_VAR_TYPE if input is NULL Proc PicVarSizeof extern T_DWORD PlicVarSizeof PLC_VAR_REC pVarInfo Description This function returns the total size of a PLC variable If the variable is a BOOL or array of BOOLS
6. These macros do not set errno This function does not set errno _rotl _rotr are not supported int rotate left and right respectively This function does not set errno This function does not set errno Return exceptions For an input value of 2147483648 the return value is 2147483648 Sets errno if the input cannot be represented as a 64 bit floating point number For ex numbers significantly outside 1 79e308 range Note numbers just beyond this range will return Infinity but will not set errno Sets errno if the input cannot be represented as a 32 bit signed integer For example numbers outside 2147483648 to 2147483647 range Sets errno if the input cannot be represented as a 32 bit signed integer For example numbers outside 2147483648 to 2147483647 range _itoa Convert an integer to a string is not supported This function does not set errno _ltoa Convert a long integer to a string is not supported B 5 B 6 Include File include lt stdlib h gt include lt stdlib h gt include lt stdlib h gt include lt stdlib h gt Supported C Run Time Library Series 90 C Run Time Library Functions Associated with File Compatibility Notes Issues Errno information and return value exceptions long strtol const char char Sets errno if the input cannot be represented endptr int base as a 32 bit signed integer For example numbers outside 2147483648 to 2
7. double tanh double x float tanhf float x C Programmer s Toolkit for PACSystems User s Manual January 2012 Series 90 C Run Time Library Compatibility Notes Issues Errno information and return value exceptions modfl is not supported powl is not supported Errno amp return exceptions When x 0 and y 0 EDOM is not set and the return value is 1 0 When x 0 and y lt 0 EDOM is not set and the return value is Positive Infinity When x lt 0 and y is non integer EDOM is not set and the functions returns 0 sinl is not supported Function does not set errno For NAN input returns NAN respectively For Infinity input returns NAN sinhl is not supported Function does not set errno For NAN input returns NAN respectively For Infinity input returns Infinity respectively sqrtl is not supported Errno amp return exceptions EDOM is not set for the following conditions When x lt 0 the return value is NAN When x Infinity the return value is Infinity respectively When x NAN the return value is NAN tanl is not supported Errno is not set by this function Return exceptions When x NAN the return value is NAN respectively When x Infinitiy the return value is NAN tanhl is not supported Errno is not set by this function Return exceptions When x NAN the return value is NAN respectively GFK 2259E GFK 2259E Include F
8. x1 NULL amp amp y1 NULL amp amp x2 NULL amp amp y2 NULL yl x1 x2 y2 x1 x2 return GEF_EXECUTION_OK else return GEF_EXECUTION ERROR As written above the example is correct the ladder logic call and the block declaration match The operation of the ladder logic and the block will execute properly C Programmer s Toolkit for PACSystems User s Manual January 2012 GFK 2259E Type Mismatch Errors If however the block declaration is changed to the following execution errors will occur int GefMain T_REAL32 x1 T_REAL32 x2 T_REAL32 yl T_REAL32 y2 if x1 NULL amp amp y1 NULL amp amp x2 NULL amp amp y2 NULL yl x1 x2 y2 x1 x2 return GEF_EXECUTION_OK else return GEF_EXECUTION_ ERROR The block will compile and link without error The gefElf file will be added and imported to the application folder without error Similarly the folder will store to the PACSystems CPU without error No error will appear until the ladder and block are executed The ladder logic will call MATH2 passing pointers to two 2 input parameters and pointers to two 2 output parameters MATH2 expects two 2 input parameter pointers and two 2 output parameter pointers The error occurs because the ladder logic uses integer variables 16 bits each but the block uses float variables 32 bits each This results in
9. 3 122 C Programmer s Toolkit for PACSystems User s Manual January 2012 GFK 2259E Application Considerations When creating a C application it is necessary to keep in mind a few items regarding the target PACSystems 1 How big is each of the target PLC s reference memories 2 Will the block be called from the MAIN ladder block or from some other ladder block 3 How large is the C application likely to be All of these questions must be kept in mind while developing C applications The following sections provide detail on each of these questions and other questions regarding the creation of C applications Application File Names Application file names are limited to 31 characters The first character in the filename must be alphabetic Floating Point Arithmetic All PACSystems CPUs support floating point math Available Reference Data Ranges When a C application uses an index variable to select an element from PLC reference memory via a reference memory macro the value of the index variable should always be checked against the size of the target PLC s reference memory It is also a good practice to check the size before calling reference memory functions but is not absolutely necessary because the function will return an error status or set Errno if the index variable is out of range for the selected memory The size of any PLC reference memory can be determined using the corresponding SIZE macro As an example consi
10. BusRefs 0 assuming no other faulted modules would be 0x000000008 Chapter 3 Writing a C Application 3 101 3 102 4 pRackRefRec ModRefs BusNumber Slo This gives an 8 bit variable where each bit represents whether a tNumber ModuleBytePosition module on a bus connected to a rack based module in a slot has a fault BusNumber can be a value of 0 or 1 for bus1 or bus2 respectively SlotNumber can be a value from 0 to 31 representing the slot of the module that supports one of the busses ModuleBytePosition is a value from 0 to 31 where each value represents 8 modules For example if ModuleBytePosition equals 0 it represents fault bits for modules at bus addresses 0 through 7 A value of 1 represents bus addresses 8 to 15 and so forth If a slot based I O modules does not have a bus associated with it and if the modules has a fault all BusRefs and ModRefs bits associated with that slot will be set InParam rackNumber Indicates which rack to use rackNumber is 0 based and the maximum number of racks is specified in model_specifics h ReturnVal Returns pointer to a RACK_REFERENCE_REC structure Errno If there is an error this function sets Errno to give specific information on what caused the error Applications that use Errno should first call PLCC_ClearErrno to ensure Errno was not already set by another function call Errno can be read using PLCC_GetErrno Errno values are located in ctkPlcErrno h C Programmer s
11. InParam x Pointer to structure containing record of last PLC and I O fault Return Data The function returns a 1 if successful and a 0 if unsuccessful Chapter 3 Writing a C Application 3 75 PLCC_read_fault_tables T_INT32 PLCC read fault _tables struct read_fault_tables rec x struct read fault _tables rec T_WORD table T_WORD zero T_WORD reserved 13 struct tine_stamp_rec time_since clear T_WORD num_faults_since clear T_WORD num_faults_in_ queue T_WORD num_faults_read union struct PLC_entry rec PLC faults NUM LEGACY PLC _FAULT_ ENTRIES struct IO entry rec IO faults NUM_LEGACY IO FAULT ENTRIES faultEntry 90 70 C Toolkit did not require union name he define PLC_FAULT_TABLE 0 define IO FAULT TABLE 1 Description This function is the C interface to service request 20 Read Fault Tables The function will read the fault table specified in the table field PLC_FAULT_TABLE or IO_FAULT_TABLE The function will return the table in an array of PLC_faults or 1O_ faults The zero field and the reserved fields do not hold fault data The time_since_clear fields are BCD numbers with seconds in the low order nibble and tens of seconds in the high order nibble The num_faults_since_clear field shows the number of faults that have occurred since the table was last cleared The num_faults_read field shows the number of faults read into the arrays for I O and PLC faults there is room for the entire table but o
12. Index Index Runtime library errors 3 134 S Sample blocks 6 1 SampleProj1 6 1 SampleProj2 6 2 Scheduling C blocks 3 11 Service Request functions 3 48 Set application redundancy mode 3 72 setBit 3 97 Single C source file sample 6 1 Size C block 1 1 slotX 3 99 Specifying parameters 3 10 Stack overflow checking 3 14 Standard library routines 3 27 Static variables 3 125 System requirements 2 1 T Target library error functions structures and constants A 28 fault table functions structures and constants A 11 general functions structures and constants A 17 reference memory functions and macros A 1 utility functions structures and constants A 28 VME functions structures and constants A 27 Target library functions A 1 Technical Support See page iii Testing C Applications in the PC Environment 4 1 Transition Alarm and Fault macros 3 25 Troubleshooting C 1 U Uninitialized pointers 3 130 Uninstalling 2 4 Using the C Block in an LD program 3 11 Utility functions 3 103 Utility functions structures and constants A 28 Index 3 Index Index 4 V Variable declarations 3 14 Variable initialization 3 124 Variable types 3 5 VME functions structures and constants A 27 W WritePlcArrayVarElement 3 116 WritePlcByte 3 87 WritePlcDint 3 92 WritePlcDouble 3 94 WritePlclInt 3 90 WritePlicVar 3 115 WritePlcWord 3 89 Writes to S memory usi
13. PLC_VAR_ENTRY_RECORD VariableRecord PlcVariableName Description This macro is used to create a reference to a PLC variable in C logic These should be declared as variables global to the C applications All variables used in C applications must be internally or externally published in the PLC InParam VariableRecord Name for a reference variable of type PLC_VAR_REC that will be used to reference the PLC variable when calling routines in this module This input parameter must be a valid C variable name InParam PlicVariableName Exact name of the PLC variable to be accessed within quotes for example myPlcVar Example 1 For a PLC variable named motorPosition PLC_VAR motorPositionRec motorPosition To use this in multiple C files for a single application place the following extern statement in a header file extern PLC_VAR_REC motorPositionRec GFK 2259E Chapter 3 Writing a C Application 3 105 Example 2 For a3 x 5 array of WORDs named algDiagnostics PLC_VAR algDiagnosticRec algDiagnostics When calling ReadPlcVar and WritePlcVar with this declaration the entire 3 x 5 array is read written ReadPlcArrayVarElement and WritePlcArrayVarElement can be used to access individual elements of the array Example 3 For a3 x 5 array of WORDs named algDiagnostics where access to a single element is needed PLC_VAR algDiagnosticElemRec algDiagnostics 2 1 When calling ReadPlcVar and WritePlcVar wi
14. R W P L AQ and Al may be accessed as 32 bit floating point numbers T_REAL32 As an example a C application needs to read R77 as a 32 bit integer and write a single precision floating point value to P6 Example include PACRXPlc h GefMain T_INT32 T_INT32_val T_REAL32 fp val 15 56 INT21 val RD 77 read R77 as a 32 bit integer PF 6 fp_val write P6 as single precision floating point return GEF_EXECUTION_OK Double Precision Floating Point Macros Word oriented PLC reference memories Al AQ L P R W may be accessed as 64 bit floating point values T_REAL64 As an example a C application needs to read the LREAL variable in R101 and write that value to the LREAL variable at W50 Example include PACRXPlc h GefMain T_REAL64 lreal_ value lreal_value RDb1 101 WDb1 50 lreal_ value GFK 2259E Chapter 3 Writing a C Application 3 23 Reference Memory Size Macros Macros are defined in ctkRefMem h for determining the size of each memory type These macros are in the form X_SIZE where Xis the memory type letter I Q M T G S R W Al AQ P or L Each of these size macros returns an unsigned integer value equal to the highest reference available in the specified reference memory If the last available reference in the l table is l32768 when a C application uses the SIZE macro the value 32768 will be returned The refe
15. T_INT32 BIT_SET_SB T_DWORD address Function compatible with 90 70 and 90 30 Same return status T_INT32 BIT_CLR_SB T_DWORD address as BIT_SET_I BIT_TST_SC address Macro compatible with 90 70 and 90 30 T_INT32 BIT_SET_SC T_DWORD address Function compatible with 90 70 and 90 30 Same return status T_INT32 BIT_CLR_SC T_DWORD address as BIT_SET_I BIT_TST_R address bitPosition Macros compatible with 90 70 and 90 30 BIT_SET_R address bitPosition BIT_CLR_R address bitPosition BIT_TST_Al address bitPosition BIT_SET_Al address bitPosition BIT_CLR_Al address bitPosition BIT_TST_AQ address bitPosition BIT_SET_AQ address bitPosition BIT_CLR_AQ address bitPosition BIT_TST_P address bitPosition Macros compatible with 90 70 BIT_SET_P address bitPosition BIT_CLR_P address bitPosition BIT_TST_L address bitPosition BIT_SET_L address bitPosition BIT_CLR_L address bitPosition AJK BIT_TST_S address Macros compatible with 90 70 and 90 30 BIT_TST_W address bitPosition New Macros to access W memory Not compatible with BIT_SET_W address bitPosition Series 90 BIT_CLR_W address bitPosition C Programmer s Toolkit for PACSystems User s Manual January 2012 GFK 2259E Target Library Reference Memory Series 90 PLC Library Compatibility Functions amp Macros Notes amp Issues T_INT32 setBit T_WORD RefTable New function to generically set a bit reference memory The T_DWORD offset b
16. This function returns TRUE if the PLC variable supports transitions FALSE if not Note This routine returns TRUE if the variable supports transitions regardless of the state of the transitions InParam pVarinfo Pointer to a PLC_VAR_REC information record ReturnVal TRUE if the PLC variable has transition values associated with it FALSE if not Chapter 3 Writing a C Application 3 121 Proc PicVarArrayElementSize extern T_DWORD PlicVarArrayElementSize PLC_VAR_REC pVarInfo Description This function returns the size in bytes of an individual element of an array variable If the variable is a BOOL an array of BOOLs or not an array zero will be returned InParam pVarinfo Pointer to a PLC_VAR_REC information record ReturnVal Size in bytes of an individual array element Proc PicVarArrayBound extern T_DWORD PlicVarArrayBound PLC_VAR_REC pVarInfo T_DWORD dimension Description This function returns the upper boundary for a given array dimension For example if the variable is a 3 by 5 array requesting dimension 1 would return 3 and requesting dimension 2 would return 5 If the variable is not an array or the variable does not have as many dimensions as indicated by the dimension input parameter zero is returned InParam pVarinfo Pointer to a PLC_VAR_REC information record InParam dimension Indicates the array dimension to return the bound for ReturnVal Boundary of the requested array dimension
17. readmePACRxX ixt contains start up information for PACs targets readmePACRX3i txt contains start up information for PAC RX3i targets readmePACRX7i ixt contains start up information for PAC RX7i targets uninstall exe removes the C Toolkit from your computer Your project directories are not removed during the uninstall process Uninstalling C Toolkit 2 4 To uninstall the C Toolkit execute the Uninstal exe file This deletes all files created by the C Toolkit install program Any new files that you have created in the directory structure will remain as user project files C Programmer s Toolkit for PACSystems User s Manual January 2012 GFK 2259E Chapter Writing a C Application This chapter contains information needed to write C applications for the PACSystems control system It includes details on declaring parameters accessing CPU reference memory and using standard library routines m Name Requirements 3 2 a C Applications in the PACSystems Environment 3 3 PACSystems C Block Structure 3 13 m PLC Reference Memory Access 3 18 m Standard Library Routines 3 27 a Application Considerations 3 123 Note For information on testing and debugging C applications refer to chapter 4 For information on compatibility with Series 90 70 and Series 90 30 C applications and issues to be aware of when converting C applications from 90 70 or 90 30 to PACSystems refer to chapter 5 The C source code used to build C appl
18. 6 2 N Names file 3 2 reserved 3 2 Non standard C library functions 5 5 Null pointer 3 16 P PACSystems environment 3 3 PACSystems functions 3 27 PACSystems vs Series 90 1 1 C Programmer s Toolkit for PACSystems User s Manual January 2012 Parameter pointer validation 3 17 PLC data types 3 19 memory sizes determining from C program See C Macros reference types L 3 131 P 3 131 S 3 132 PLC local registers P and L 3 131 PLC target library function compatibility 5 3 PLC_VAR 3 105 C Types 3 106 PLC_VAR_MEM 3 86 PLCC_change_background_window 3 52 PLCC_change_backplane_comm_window 3 51 PLCC_change_controller_comm_window 3 50 PLCC_chars_in_printf_q 3 29 PLCC _clear_fault_tables 3 75 PLCC_ClearErrno 3 104 PLCC_comm_req 3 79 PLCC_const_sweep_timer 3 48 PLCC_Crc16Checksum 3 103 PLCC_do_io 3 80 PLCC_do_io ext 3 81 PLCC_gen_alarm 3 32 PLCC_get_escm_status 3 71 PLCC_get_plc_version 3 33 PLCC_GetErrno 3 104 PLCC_mask_lO_ interrupts 3 65 PLCC_mask_lO_interrupts_ext 3 66 PLCC_mask_timed_interrupts 3 68 PLCC_nano_time_since_start_of_sweep 3 62 PLCC_number_of_words_in_chksm 3 53 PLCC_read_elapsed_clock 3 28 PLCC_read_ext_fault_tables 3 78 PLCC_read_fault_tables 3 76 PLCC_read_folder_name 3 62 PLCC_read_lO_override_status 3 67 PLCC_read_last_ext_fault 3 77 PLCC_read_last_fault 3 75 PLCC_read_override 3 84 PLCC_read_PLC_ID 3 63 PLCC_read_PLC_ state 3 63 PLCC_read_win
19. LDbl address PDbl address RDbl address WDbi address T_INT32 WritePlcDouble T_WORD RefTable T_DWORD offset T_REAL64 writeValue This function writes to reference memory taking into account overrides and transition bits Reference memory in the specified Reference Table RefTable and at the specified offset is written with the writeValue as a 64 bit floating point value If the RefTable or offset are out of range no reference memory values are changed and the function returns GEF_ERROR If the offset is within range the function returns GEF_OK Note this function will affect only the transition bits that actually change Errnos TLIB_ERRNO_OFFSET_RANGE_ER TLIB_ERRNO_READ_ONLY_ER TLIB_ERRNO_INVALID_REF_TABLE_ER T_REAL64 ReadPlicDouble T_WORD RefTable T DWORD offset T_INT32 PlcMemCopy void pDestination void pSource T_DWORD size BIT_TST_l_TRANS address BIT_TST_Q_TRANS address BIT_TST_M_TRANS address BIT_TST_T_TRANS address BIT_TST_G_TRANS address C Programmer s Toolkit for PACSystems User s Manual January 2012 Reference memory in the specified Reference Table RefTable and at the specified offset is read as a 64 bit floating point value and returned by the function Errno is set if there is an error reading the value Errnos TLIB_ERRNO_OFFSET_RANGE_ER TLIB_ERRNO_INVALID_REF_TABLE_ER This function writes to
20. Note this function will only affect the transition bits that actually change Errnos TLIB_ERRNO_OFFSET_RANGE_ER TLIB_ERRNO_READ_ONLY_ER TLIB_ERRNO_INVALID_REF_TABLE_ER Reference memory in the specified Reference Table RefTable and at the specified offset is read as a 32 bit signed integer and returned by the function Errno is set if there is an error reading the value Errnos TLIB_ERRNO_OFFSET_RANGE_ER T_INT32 ReadPlcDint T_WORD RefTable T_DWORD offset TLIB_ERRNO_INVALID_REF_TABLE_ER Similar issues as Ib Qd address Md address Td address Gd address GAD x not supported Similar issues as lb This is read only and the compiler will issue an error if you attempt to write to this memory using this macro d address Ad address Bd address Cd address RD address AlD address AQD address PD address LD address WD address RF address AlF address AQF address PF address Similar issues as Ib Macros compatible with the 90 70 and 90 30 Macros compatible with the 90 70 New Macro to support W memory Macros compatible with the 90 70 and 90 30 Macros compatible with the 90 70 Appendix A Target Library Functions A 7 LF address GFK 2259E Target Library Reference Memory Series 90 PLC Library Compatibility Functions amp Macros Notes amp Issues WF address AlDbl address New Macro to support W memory AQDbI address
21. R_MEM and offset 1 accesses R00001 ReturnVal The value read from the specified reference table at the specified offset Errno If there is an error this function sets Errno to give specific information on what caused the error Applications that use Errno should first call PLCC_ClearErrno to ensure Errno was not already set by another function call Errno can be read using PLCC_GetErrno Errno values are located in ctkPlcErrno h GFK 2259E Chapter 3 Writing a C Application 3 91 WritePIcDint T_INT32 WritePlcDint T_WORD RefTable T_DWORD offset T_INT32 writeValue Description This function writes to reference memory taking into account overrides and transition bits Reference memory in the specified Reference Table RefTable and at the specified offset is written with the writeValue as a 32 bit signed integer InParam RefTable Reference table to write InParam offset Offset within the reference table to write Note The offset is 1 based For example Reffable R_MEM and offset 1 accesses R00001 InParam writeValue The value to write to the specified reference table and offset ReturnVal If the RefTable or offset are out of range no reference memory values are changed and the function returns GEF_ERROR If the offset is within range the function returns GEF_OK Errno If there is an error this function sets Errno to give specific information on what caused the error Applications that us
22. T_BYTE month T_BYTE day of month T_BYTE hours T_BYTE minutes T_BYTE seconds T_BYTE day of week T_BYTE null struct BCD tod 4 rec T_BYTE year lo T_BYTE year hi T_BYTE month T_BYTE day of month T_BYTE hours T_BYTE minutes T_BYTE seconds T_BYTE day of week UNPACKED_BCD_FORMAT Two byte fields make up the word category For example 94 for the year is 9 in yearhi and 4 in yearlo struct unpacked _ BCD_rec T_BYTE yearlo T_BYTE yearhi T_BYTE monthlo T_BYTE monthhi T_BYTE day of month_lo T_BYTE day of month_hi T_BYTE hourslo T_BYTE hourshi T_BYTE minslo T_BYTE minshi T_BYTE secslo T_BYTE secshi T_WORD day of week struct unpacked bcd _tod _4_rec T_WORD huns_year T_WORD tens_year T_WORD month T_WORD day_of_month T_WORD hours T_WORD minutes T_WORD seconds T_WORD day_of_week Chapter 3 Writing a C Application 3 55 3 56 PACKED_ASCIl_FORMAT Two ASCII character fields make up the word category For example 94 for the year is 9 in yearhi and 4 in yearlo struct ASCII_tod_rec T_BYTE yearhi T_BYTE yearlo T_BYTE spacel T_BYTE monthhi T_BYTE monthlo T_BYTE space2 T_BYTE day of month_hi T_BYTE day of month_lo T_BYTE space3 T_BYTE hourshi T_BYTE hourslo T_BYTE colonl T_BYTE minshi T_BYTE minslo T_BYTE colon2 T_BYTE secshi T_BYTE secslo T_BYTE space4 T_BYTE day of week_hi T_BYTE day of week_lo struct asci
23. T_DWORD seconds T_WORD hundred usecs Description This function returns the current time from the PLC in memory pointed to by pElapsedClockRec which is the time since the PLC powered up InParam pElapsedClockRec Pointer to structure containing the value of the PLC s elapsed clock Return Val The return value is 0 if successful 1 if unsuccessful PLCC_read_nano_elapsed_clock T_INT32 PLCC_read_nano_elapsed_clock struct nano_elapsed_clock_rec pNanoElapsedClockRec struct nano elapsed _ clock rec T_DWORD seconds T_DWORD nanoseconds Description This function returns the current time in nanosecond units from the PLC in memory pointed to by pNanoElapsedClockRec which is the time since the PLC powered up InParam pNanoElapsedClockRec Pointer to structure containing the value of the PLC s elapsed clock in nanosecond units ReturnVal The return value is 0 if successful 1 if unsuccessful 3 28 C Programmer s Toolkit for PACSystems User s Manual January 2012 GFK 2259E PLCC_chars_in_printf_q Obsolete Use PLCC_CharsInMessageWriteQ function T_INT32 PLCC_chars in printf_q void This function returns GEF_NOT_ SUPPORTED PLCC_MessageWrite T_INT32 PLCC_MessageWrite T_INT32 port char buffer T_INT32 numBytes define PORT1 0 define PORT2 1 Description Writes to a serial port on the PLC InParam port Indicates which PLC serial port to write i e PORT1 PORT2 InParam buffer Poi
24. have up to sixty three input and sixty four output parameters The input parameters do not have to be paired with output parameters as required in the Series 90 70 Blocks invoked as an I O timed or module interrupt cannot have parameters Shown below are two ladder logic rungs containing a C block with zero parameters and a C Block with three input and three output parameters 100004 Qo0004 100002 Mo0025 Roo001 Figure 3 3 Ladder Logic Calls to C Blocks Note The Enable output ENO is present regardless of whether the block has parameters and is set based on the function return result either GEF_EXECUTION_OK or GEF_EXECUTION_ERROR Each block is written as a separate application that is linked and located during the program store process Chapter 3 Writing a C Application 3 13 Appropriate definitions of GEF_EXECUTION_OK or GEF_EXECUTION_ERROR are given in the ctk h file which is included by the header file PACRXPlc h The ctk h file is located in the subdirectory PACSystems CToolkit Targets CommonFiles IlncCommon The gefElf file produced by the build process of a block must be added to the program folder via CME using the Add C Block command The main function in each block must always be called GefMain Any legal C declaration and code may be used in a C block The file PACRxPIc h installed as part of the C Toolkit should be included in the block source file s PACRxPlc h contains or includes other files that contai
25. properties page in the programmer If C block stack checking is enabled when the block is built and the CPU detects the stack has already overflowed when calling a user function within a C block a fatal application fault will be logged in the controller fault table and the PLC will be placed in Stop Faulted mode In some cases such as when a function allocates a large amount of local or automatic variables in the stack and the stack depth is near the bottom of the stack a page fault may occur and the CPU will be placed in CPU halted mode C Programmer s Toolkit for PACSystems User s Manual January 2012 GFK 2259E If stack checking is disabled via the block build process and the application exceeds the allocated stack space a page fault may occur or the CPU may receive invalid data The order of the parameter declarations must match the CALL instruction parameter order with the input parameters followed by the output parameters The declaration code shown below could be used for a block that has two input and two output parameters 100002 Roo004 Pooo01 Rooo02 Figure 3 4 Matching Parameters Between Call and C Block int GefMain X1 X2 Y1 Y2 X1 pointer to a single 16 bit integer T_INT16 X1 X2 pointer to a 256 element array of integers T_INT16 X2 256 Y 1 pointer to a structure containing a 16 bit integer and a floating point variable struct T_INT16 a T_REAL32 b
26. the ladder logic call will pass four parameters R1 R2 P1 and P2 The block expects two parameters x1 and y1 which it will associate with the passed in parameters as follows T_INT16 xl refers to R1 T_INT16 yl refers to R2 P1 and P2 are not referenced The operation of this block with regard to parameter x1 is flawless However when y1 is used as the pointer for storing the sum the sum will be written to R2 not to P1 This will cause incorrect operation of the application C Programmer s Toolkit for PACSystems User s Manual January 2012 GFK 2259E GFK 2259E A more severe scenario is a block declared as follows int GefMain T_INT16 x1 T_INT16 x2 T_INT16 x3 T_INT16 yl T INT16 y2 T_INT16 y3 Add the contents of R to the contents pointed to by x and then store the sum in the location pointed to by y kyl x1 RI 1 ky2 x2 RI 2 y3 x3 RI 3 return GEF_EXECUTION_OK The above block can have catastrophic results if executed in conjunction with the example ladder logic rung Again the ladder logic call is passing four parameters a pointer to R1 a pointer to R2 a pointer to P1 and a pointer to P2 The C program expects six parameters all pointers The block will then associate each of the declared parameters to GefMain with the pointers passed from the ladder logic call as follows refers R1 OK refers SR2 OK refers SP1 error w
27. this function sets Errno to give specific information on what caused the error Applications that use Errno should first call PLCC_ClearErrno to ensure Errno was not already set by another function call Errno can be read using PLCC_GetErrno Errno values are provided in ctkPlcErrno h Chapter 3 Writing a C Application 3 111 Proc ReadPlcArrayVarElementOvr extern T_INT32 ReadPlcArrayVarElementOvr PLC _VAR_REC pVarInfo void pReadOvrTo T_INT32 numIndices re he Description This function reads the override value s for a single element in a PLC array variable into a buffer provided by the caller InParam pVarinfo Pointer to a PLC_VAR_REC information record for the array containing the element whose diagnostics are to be read If the variable does not have overrides an error will be returned InParam pReadOvrTo Pointer to the memory location where the override values are to be written Notes For type BOOL an entire byte will be written to pReadOvrTo with the low bit of the byte containing the override value for the BOOL variable For all other types the number of bytes written will be equal to the byte size of an element in the PLC array variable InParam numindices Number of indices needed to locate an element of the array This must be greater than zero and must match the number of dimensions of the variable declared on the PLC InParam lt indices gt A variable number of indices must match numIndices indicating the ele
28. 5 C Block functionality between Rx3i and Rx7i targets is essentially the same so that compilation for specific targets is currently not needed However the PACSystems C Toolkit is structured to support variation between targets in case it is needed in the future 3 136 C Programmer s Toolkit for PACSystems User s Manual January 2012 GFK 2259E Chapter Debugging and Testing C Applications 4 Testing C Applications in the PC Environment It is highly recommended that all C applications be tested prior to execution on the PACSystems CPU This is best accomplished by testing the application on the PC using the PC debugging environment provided by the C Toolkit This environment provides various batch files that use the Cygwin compiler linker and debugger to produce an exe file that can be directly executed on the PC The first step is to develop the C Block source code using the editor of your choice The C Toolkit provides a set of stub functions for each of the C Toolkit PLC functions that are compiled and linked to your C Block during the PC compilation process These stub functions are located in the Targets CommonFiles TargetStubLibCommon subdirectory You can modify these stub functions to simulate dynamic behavior When debugging on the PC the C Run Time library functions of the Cygwin environment are used However some non standard C library functions such as re entrant forms of functions such as div_r for div m
29. A pointer to Scan Set IO record ReturnVal The PLCC_scan_set_io function returns one of the following values 1 if successful 0 if unsuccessful 1 if not supported GFK 2259E Chapter 3 Writing a C Application 3 83 Miscellaneous General Functions 3 84 PLCC_SNP_ID The following miscellaneous functions are described in ctkPlcFunc h T_INT PLCC_SNP_ID T_BYTE request type char id _str_ptr Valid request_type values define READ ID 0 define WRITE_ID 1 Description This function will read or write the SNP ID string passed in through id_str_ptr to the PLC The string should be an eight character buffer space for seven letters and a NULL termination InParam request_type Indicates whether the SNP Id should be read or written InParam id_str_ptr Pointer to character buffer that contains the id to write or receives the current id This buffer needs to be allocated by the caller ReturnVal This function returns 1 if successful 0 if unsuccessful and 1 if unsupported PLCC_read_override T_INT32 PLCC_read_override BYTE seg sel WORD ref num WORD len BYTE data Valid seg sel values define I_OVR I_MEM this was 0 for the 90 70 C Toolkit define Q OVR Q MEM this was 1 for the 90 70 C Toolkit define M OVR M MEM this was 2 for the 90 70 C Toolkit define G _OVR G MEM this was 3 for the 90 70 C Toolkit Description This function reads the override table for the spe
30. C Blocks that work with PACSystems RX7i target 5 1 Writing Directly to Discrete Memory If the application uses the Series 90 style macros that write directly to discrete reference memory l Q etc overrides will not be respected and the corresponding transition bit will not be set because this functionality is not implemented in hardware on the PACSystems product Since there is not a one to one correspondence in the functionality of the Series 90 and PACSystems discrete macros the PACSystems discrete macro definitions are similar to the Series 90 macros but slightly different to flag potential overrides and transition issues For example the macro that accessed a byte of l memory in Series 90 PLCs was called IB In the PACSystems C Toolkit it is called Ib If you want to overrides to be respected and to set the corresponding transition bit you must use a set of new read write PLC functions Here are some compatibility conversion examples a Direct assignment to discrete reference Here is an example of Series 90 C code IB 1 0x33 Here is how the code must be written for the PACSystems to have the same functionality as the Series 90 WritePlcByte I_ MEM 1 0x33 FALSE The first parameter of the WritePlcByte function determines which reference table to access The second parameter of determines the reference address to access The third parameter determines the value to write to the reference table The fo
31. DIAGNOSTIC memory s HI_ALARM_MSK 0x02 LO_ALARM_MSK 0x01 Al_OVERRANGE_MSK 0x08 Al_UNDERRANGE_MSK 0x04 Definitions used with macros that access Analog Output DIAGNOSTIC memory s AQ_OVERRANGE_MSK 0x40 AQ_UNDERRANGE_MSK 0x20 Diagnostic memory macros Note Discrete diagnostic memory is organized so that there is one fault bit per discrete memory location Analog diagnostic memory is organized so that there is one byte of memory for each analog input or output channel for example there is one diagnostic byte associated with the analog input AQ1 For analog diagnostic memory use the mask definitions above to determine the type of analog fault for a particular analog input or output channel BIT_TST_ _DIAG x BIT_TST_Q_DIAG x IB_DIAG x QB_DIAG x AIB_DIAG x AQB_DIAG x Al_HIALRM x Al_LOALRM x Note AIB FAULT and AQB FAULT are non zero for conditions that set a fault contact or generate a fault entry in the I O fault table such as Overrange Underrange AIB_FAULT x AQB_FAULT x Al_OVERRANGE x Al_UNDERRANGE x AQ_OVERRANGE x AQ_UNDERRANGE x Macros for accessing RACK SLOT BLOCK fault information See descriptions of the corresponding functions in the Reference Memory Functions section on page 3 86 RACKX r rackX r page 3 98 SLOTX r s slotX r s page 3 99 BLOCKX r s b sba blockX r s b sba page 3 100 RSMB x rsmb x page 3 101 3 26 C Programmer s Toolkit for PACSystems User s Manual January 2012
32. Errno This function sets Errno if reference memory is out of range See cpuErrno h for possible values C Programmer s Toolkit for PACSystems User s Manual January 2012 GFK 2259E PLCC_read_ 0_override_status T_INT32 PLCC read IO override status struct read_IO override status rec pReadOverrideStatusRec struct read_IO override _status_rec T_WORD override status define OVERRIDES_SET 1 define NO_OVERRIDES_SET 0 Description This function is the C interface to service request 18 Read I O Override Status The function will return the override_status OVERRIDES_SET or NO_OVERRIDES_SET OutParam pReadloOverrideStatusRec Pointer to structure containing override status information ReturnVal The function will return 1 if successful and 0 if unsuccessful PLCC_set_run_enable T_INT32 PLCC set_run_enable struct set _run_enable rec pSetRunEnableRec struct set_run_enable rec T_WORD enable define RUN_ENABLED 1 define RUN_DISABLED 2 Description This function is the C interface to service request 19 Set Run Enable Disable The function will set the PLC in either RUN _ENABLED or RUN_DISABLED depending on what value was passed in the structure Use SVCREQ function 19 to permit the ladder program to control the RuN mode of the CPU InParam pSetRunEnableRec Pointer to structure containing enable run value ReturnVal The function will return 1 if successful and 0 if unsuccessful GF
33. InParam subSlot The sub slot number of the module to access InParam region The region number describing the location of the BUS memory This is set up in hardware configuration for the module OutParam pStatus Pointer to status variable see common definition above InParam value Word value to be written to a device on the bus InParam address Address of the word to be written ReturnVal 1 if successful 0 if unsuccessful 1 if not supported 3 40 C Programmer s Toolkit for PACSystems User s Manual January 2012 GFK 2259E Proc PLCC_BUS _write_dword T_INT32 PLCC BUS write dword T_ WORD rack T_WORD slot T_WORD subSlot T_WORD region T_WORD pStatus T_DWORD value T_DWORD address Description Write a dword to a device on the bus InParam rack The rack number containing the module to access InParam slot The slot number containing the module to access InParam subSlot The sub slot number of the module to access InParam region The region number describing the location of the BUS memory This is set up in hardware configuration for the module OutParam pStatus Pointer to status variable see common definition above InParam value Dword value to be written to a device on the bus InParam address Address of the dword to be written ReturnVal 1 if successful 0 if unsuccessful 1 if not supported GFK 2259E Chapter 3 Writing a C Application 3 41 Proc PLCC_BUS _write_block T_INT32 PLC
34. PACRXSiPIc h If a C block is used as the _MAIN block in a 90 30 folder you must compile the C source into a program block and create a one rung main program in LD that calls this block PLCC9070 h This file equates some of the 90 70 C Toolkit names to the equivalent PACSystems C Toolkit names For example in the 90 70 C Toolkit many run time functions have a far version such as _fstrcat Since the PACSystems does not require the far version of functions the PLCC9070 h file equates them to the non far function such as strcat for _fstrcat Similarly the 90 70 C Toolkit used OK and ERROR as defines for the return value that controls the state of ENO These are equated to GEF_EXECUTION_OK and GEF_EXECUTION_ERROR respectively Also this file equates some of the common basic types such as byte and word to the equivalent PACSystems types T_ BYTE and T_ WORD PLCC9030 h This file equates some of the 90 30 C Toolkit names to the equivalent PACSystems C Toolkit names Similar to the 90 70 version the PLC9030 h file equates far versions of functions to non far versions This file also equates common basic types such as byte and word to the equivalent PACSystems types T_BYTE and T_WORD For new applications one of the following target header files should be used PACRXPLC h Compiles C Blocks that work with all PACSystems CPU targets PACRX3iPLC h Compiles C Blocks that work with PACSystems RX3i target PACRX7iPLC h Compiles
35. SampleProj2 6 2 The SampleProj2 directory contains an example for compiling multiple C sources into a single C Block The files to be compiled and linked together for the PLC execution are specified in the sources file Similarly the files to be compiled and linked together for PC debugging are specified in the sourcesDebug file This directory also has examples of precompiled object files 1 ctkCBlockTest4 plcO ctkCBlockTest5 plc0 and ctkCBlockTest plcO for PLC linking 2 ctkCBlockTest4 pc0 ctkCBlockTest5 pcO ctkCBlockTest pc0 for PC linking These files were produced by compiling their corresponding C source file with the following command for the PLC object files compileCPACRX7i ctkCBlockTest4 DisableGefLibLink And the following command for the PC object files compileCDebugPACRX7i ctkCBlockTest4 DisableGefLibLink The sources and sourcesDebug files respectively specify the use of these object files for compilation as opposed to the source file All files are compiled and linked together with one of the following commands for the PLC compileCPACRX7i compileCPACRX3i compileCPACRX And one of the following commands for the PC compileCDebugPACRX7i compileCDebugPACRX3i compileCDebugPACRX These files also illustrate the use of the serial port message mode read write functions This sample block will not execute on a PACSystems CPU with the default configuration See the setup note at the top of ct
36. Y1 Y 2 pointer to an unsigned 16 bit integer T WORD Y2 Body of GefMain function starts here GFK 2259E Chapter 3 Writing a C Application 3 15 3 16 It is not required that all of the CALL instruction parameters be used If a CALL instruction parameter is not used a NULL pointer is passed as that parameter s value The parameter must still be declared for the C Block in the programmer so that subsequent parameters are lined up correctly with their pointers In the following example a NULL pointer is passed in for the second and third input parameters 100002 R0000 Poooo1 Figure 3 5 Reserving Space for Unused Parameters to a C Block int GefMain x1 x2 x3 yl y2 y3 T_INT16 T_INT16 T_INT16 T_INT16 T_INT16 T_INT16 x1 x2 x3 yl1 y2 A y3 H placeholder for unused parameter value is null placeholder for unused parameter value is null y1 x1 Copy value at x1 to yl y2 x1l 2 y3 x1 3 return GEF_EXECUTION_OK copy twice the value at x1 to y2 Copy three times the value at x1 to y3 C Programmer s Toolkit for PACSystems User s Manual January 2012 GFK 2259E Parameter Pointer Validation The ladder logic program provides pointers to the variables that are passed into the block s GefMain function Since it is not required to provide variables for all input output parameters you should check to make sure
37. a C block from Ladder Program For this example x1 points to the memory location of R1 and y1 points to the memory location of R2 A return value of GEF_EXECUTION_OK enables power flow output from the C Block while a return value of GEF_EXECUTION_ ERROR results in no power flow from the output of the C Block C Programmer s Toolkit for PACSystems User s Manual January 2012 GFK 2259E C Toolkit Variable Types To maintain portability and reduce errors it is recommended that you use the basic types defined by the header file ctkGefTypes h and the files it includes This file is located in the Toolkit subdirectory Targets CommonFiles IncCommon This file defines the recommended basic signed and unsigned types from 8 or 64 bit quantities These types are described below Table 3 1 Variable Types C Toolkit Description Corresponding Notes Variable Types Programmer Variable Type T_BOOLEAN 8 bit type where 0 means FALSE BOOL In the programmer PLC this type and non zero means TRUE represents a single bit Note when However TRUE typically is set to a passing a Boolean parameter to a C value of 0x01 block the memory address of the PLC reference table memory must be byte aligned because the C Block is passed a pointer to a Byte of reference memory The C user must then mask off and test the least significant bit to get the boolean state T_BYTE 8 bit unsigned type BYTE T_
38. a pointer is not NULL before using it in your application An example of this NULL pointer checking is shown below int GefMain T_INT16 x1l T_INT16 x2 T_INT16 x3 T_INT16 y2 T_INT16 y3 Ensure that required parameters were provided by caller if x1 NULL x2 NULL x3 NULL yl1 NULL y2 NULL y3 NULL return GEF_EXECUTION_ ERROR Required parameters are present y1 x1 Copy value at x1 to yl y2 x1l 2 copy twice the value at x1 to y2 y3 x1 3 Copy three times the value at x1 to y3 return GEF_EXECUTION_OK GFK 2259E Chapter 3 Writing a C Application 3 17 PLC Reference Memory Access 3 18 PACSystems reference address and diagnostic memory may be read and written directly via macros defined in ctkRefMem h which is included with PACRx Most of these macros consist of a string of capitalized letters for non discrete memory and Title Case for discrete memory which indicate the PACSystems reference type and in some cases the type of operation to be performed followed by the reference offset in parentheses In general PLC reference memories may be accessed via these macros as bits bytes 8 bit values words 16 bit values double words 32 bit values single precision floating point numbers 32 bits or double precision floating point numbers 64 bits Use extreme caution with the following discrete macros These macros directly acce
39. aa a rs The Enhanced DO_IO function Series 90 30 only is not supported T_INT32 PLCC_sus_io void Suspend I O T_INT32 PLCC_scan_set_io struct scan_set_io_rec pScanSetloRec struct scan_set_io_rec T_BOOLEAN scan_inputs T_BOOLEAN scan_outputs T_UINT16 scan_set_number E T_INT32 PLCC_SNP_ID T_BYTE request_type char id_str_ptr Read or Write SNP ID define READ_ID 0 define WRITE_ID 1 T_INT32 PLCC_read_override T_BYTE tbl_typ T WORD ref_num T_WORD len T_BYTE data Error return values define BAD_ MEMORY_TYPE 2 define OFFSET_NOT_BYTE_ALIGNED 3 define READING_OUTSIDE_REF_MEM 4 define BAD_DATA_POINTER 5 Read Overrides define OVR 0 define Q_OVR 1 define MLOVR 2 define G_LOVR 3 Compatible with the 90 70 and 90 30 library Not supported by Series 90 Supported by PACSystems Release 5 0 or greater Compatible with 90 70 and 90 30 libraries Release 2 0 and later The following 90 70 and 90 30 values are not supported by PACSystems T_INT32 PLCC_MessageWrite T_INT32 port char buffer T_INT32 numBytes define PORT1 0 define PORT2 1 T_INT32 PLCC_MessageRead T_INT32 port char buffer T_INT32 numBytes Appendix A Target Library Functions New function to provide serial output Note for all PLCC_Message functions the Hardware configuration for the serial port must be setup for Message Mode for the function to access the serial port Errnos
40. are not updated with data from inputs However during the input scan portion of the sweep the CPU will verify that Genius Bus Controllers have completed their previous output updates Note This function suspends all I O both analog and discrete whether rack I O or Genius I O ReturnVal The PLCC_sus_io function returns a 1 if successful 0 if unsuccessful 3 82 C Programmer s Toolkit for PACSystems User s Manual January 2012 GFK 2259E PLCC_scan_set_io Note CPU firmware version 5 00 or higher is required for this function struct scan_set_io_rec T_BOOLEAN scan_inputs T_BOOLEAN scan_outputs T_UINT16 scan_set_number y extern T_INT32 PLCC_scan_set_io struct scan_set_io_rec pScanSetloRec Description This function scans the I O of a specified scan set number Modules can be assigned to scan sets in hardware configuration You can specify whether the Inputs and or Outputs of the associated scan set will be scanned Execution of this function block does not affect the normal scanning process of the corresponding scan set If the corresponding scan set is configured for non default Number of Sweeps or Output Delay settings they remain in effect regardless of how many executions of the Scan Set IO function occur in any given sweep The Scan Set IO function skips modules that do not support DO_IO scanning For details see Control Functions in the PACSystems CPU Reference Manual GFK 2222 InParam pScanSetlo
41. blocks to the application 3 9 Application considerations 3 123 Application file names 3 123 Arrays using PLC reference memory as 3 123 Associating a compiled C block to the application program 3 9 Available reference data ranges 3 123 B Bit macros 3 20 Block enable output ENO 3 132 blockX 3 100 Bus Read Write functions 3 34 BUS semaphore functions 3 43 Byte macros 3 21 C C block ladder logic ENO output 3 132 size in PLC 3 134 C block structure 3 13 C FBKs structure 3 135 when to use 3 135 C function blocks structure 3 135 when to use 3 135 C Macros general 3 18 PLC memory sizes 3 123 C program block impact on memory 3 134 C run time functions B 1 C Standalone Programs 5 5 C Toolkit file structure 2 3 installing 2 1 Running 2 3 uninstalling 2 4 variable types 3 5 Calls 3 11 clearBit 3 98 Common errors mismatch in parameters to GefMain 3 126 Compatibility enum type 5 4 int type 5 4 non standard C library functions 5 5 Index PLC target library function 5 3 retentive variables 5 4 Compatibility header file 5 1 Compiling 3 6 for specific target 3 136 options 3 8 specifying Toolkit version 3 9 D Data initialization 3 124 Data retentiveness for C blocks 3 125 Debugging in the PLC 4 4 Developing a C block 3 3 Documentation 1 1 Double Precision Floating Point macros 3 23 Double Word Floating Point macros 3 23 E Entry Point
42. bring up a Windows based debugger that allows setting break points single step viewing and changing memory etc Use the help facility within this application for information on how to use the debugger The Toolkit places copies of the PLCC stub file source code into the pc directory to allow source line debugging You should not modify these files because they will be replaced with the master stub files located in Targets CommonFiles TargetStubLibCommon each time your source files are recompiled 8 The C Block can also be run at the DOS prompt with the following command runPACRX pc myCBlock exe For Rx7i targets use runPACRX7i_pc myCBlock exe for Rx3i targets use runPACRX3i_pc myCBlock exe Debugging in this case requires PLCC_MessageWrite statements within the application to indicate program flow and state Chapter 4 Debugging and Testing C Applications 4 3 4 4 Debugging C Applications in the PLC There are two primary ways to debug the C application operating in the PLC message mode writes to serial port and reference table monitoring Message Mode Debugging The use of PLCC_MessageWrite to debug a C application running in a PACSystems is very similar to using PLCC_MessageWrite to debug the same C application on the PC The PLCC_MessageWrite statements should be placed in the source code to provide a road map of the execution path and to display the value of any key data items Note For PLCC_MessageWrite
43. current_time_ value struct const_sweep_timer_rec union struct const_sweep_input_rec input struct const_sweep_output_rec output const_sweep Note union name required with PACSystems sweep mode values these determine which action is to be taken define DISABLE CONSTANT SWEEP MODE 0 define ENABLE CONSTANT SWEEP_MODE 1 define CHANGE TIMER VALUE 2 define READ TIMER VALUE AND STATE 3 sweep mode return values idefine CONSTANT _SWEEP_ENABLED 1 define CONSTANT SWEEP DISABLED 0 Description This function is the C interface to service request 1 Change Read Constant Sweep Timer This function can be used to Disable constant sweep time mode m Enable constant sweep time mode and use the old timer value m Enable constant sweep time mode and use a new timer value E Set anew timer value only Read constant sweep mode state timer and value Setting sweep_mode to DISABLE_CONSTANT_SWEEP_MODE disables the constant sweep timer Setting sweep_mode to ENABLE CONSTANT SWEEP_MODE enables the constant with the value in C Programmer s Toolkit for PACSystems User s Manual January 2012 GFK 2259E sweep_timer or keep the current value if the sweep_timer is 0 Setting the sweep_mode to CHANGE_TIMER_VALUE changes the constant sweep timer to the value in timer_value Setting sweep_mode to READ_TIMER_VALUE_AND_STATE sets sweep_enabled to 1 if the constant sweep timer is enabled and sets the current c
44. equal to READ_CLOCK then the function will read the Time of Day Clock into the structure passed If read_write is equal to WRITE_CLOCK then the function will write the values in the structure to the time_of_day_clock The format will be based on the format field in the structure NUMERIC_DATA_FORMAT BCD_FORMAT UNPACKED_BCD_FORMAT and PACKED_ASCIl_FORMAT The function will fail in the following instances m If read_write is some number other than 0 or 1 m If format is some number other than 0 3 m If data for a write does not match format For all the formats the hours are 24 hour and the days of the week are defined as macros in ctkFuncPle h The packed BCD format needs the null field to be 0 as shown in the following example Example include PACRxPLC h int GeFMain struct tod_clock_rec data data read_write 1 data format BCD FORMAT set the time and date to 1 13 08pm Tuesday August 9 1994 data record BCD_tod year 0x94 data record BCD_tod month 8 data record BCD_tod day of _ month 9 data record BCD_tod hours 0x13 data record BCD_tod minutes 0x13 data record BCD_tod seconds 8 data record BCD_tod day of week TUESDAY data record BCD_tod null 0 PLCC_tod_ clock amp data 3 58 C Programmer s Toolkit for PACSystems User s Manual January 2012 GFK 2259E The unpacked format should have a digit in every byte including the day of the week as shown in the fol
45. example use 1 to access 100001 InParam bitNumber For word type memories this determines which bit to clear For bit type memories this input is ignored This is 1 based with a range of 1 to 16 For example use 1 to clear the least significant bit in a word memory ReturnVal The function returns GEF_OK if the offset is within range or GEF_ERROR if the offset is out of range In the GEF_ERROR case the specified bit is not changed Errno If there is an error this function sets Errno to give specific information on what caused the error Applications that use Errno should first call PLCC_ClearErrno to ensure Errno was not already set by another function call Errno can be read using PLCC_GetErrno Errno values are located in ctkPlcErrno h T_DWORD rackX T_BYTE rackNumber Description Returns the rack fault summary bit in the rack slot reference record based on the rackNumber Only the first bit is significant This indicates whether one or more modules in the rack are faulted InParam rackNumber Indicates which rack to get the fault summary bit from rackNumber is 0 based and the maximum number of racks is specified in model_specifics h ReturnVal Returns the rack fault summary bit for the requested rack in bit 0 Errno If there is an error this function sets Errno to give specific information on what caused the error Applications that use Errno should first call PLCC_ClearErrno to ensure Errno was not already set b
46. format This function is the C interface to service request 15 when the fault table entry value is either PLC_EXT_FAULT_TABLE or IO_EXT_FAULT_TABLE InParam x Pointer to structure containing extended record of last PLC and I O fault ReturnVal 1 if successful 0 if unsuccessful 1 if not supported GFK 2259E Chapter 3 Writing a C Application 3 77 PLCC_read_ext_fault_tables T_INT32 PLCC read ext fault _tables struct read ext _fault_tables rec x struct read _ext fault _tables rec T_WORD table PLC_EXT FAULT TABLE or IO EXT FAULT TABLE T_WORD start_index T_WORD number of entries to_read T_WORD reserved 12 struct time_stamp_rec time_since clear T_WORD num faults since clear T_WORD num faults in queue T_WORD num _ faults read T_WORD PlcName 16 union struct PLC_ext_fault_entry rec PLC_faults 1 struct IO ext _fault_entry rec IO faults 1 faultEntry note 90 70 C Toolkit did not require name for union Note the faultEntry member structures are intended to be variable size arrays See Appendix A for instructions on how to change the size of the array Description This service request will read the entire PLC or I O fault table in extended format This function is the C interface to service request 20 Read Fault Tables when the table is specified to be either PLC_EXT_FAULT_TABLE or IO_EXT_FAULT_TABLE InParam x Pointer to structure containing record of all PLC or I O f
47. function reads a word sized semaphore from the bus address and tests the least significant bit The semaphore output will be 0 is the semaphore is not obtained 1 if it is obtained You must free this semaphore when it is no longer needed To release a semaphore write 0 to the semaphore The address must be word aligned InParam rack The rack number containing the module to access InParam slot The slot number containing the module to access InParam subSlot The sub slot number of the module to access InParam region The region number describing the location of the BUS memory This is set up in hardware configuration for the module OutParam pStatus Pointer to status variable see common definition above OutParam semaphore_output Results of locking semaphore 0 not obtained 1 obtained InParam address Address of the data to be written ReturnVal 1 if successful 0 if unsuccessful 1 if not supported GFK 2259E Chapter 3 Writing a C Application 3 47 Service Request Functions 3 48 The following functions are patterned after the service request SVC_REQ function in ladder logic and defined in ctkPlcFunc h PLCC_const_sweep_timer T_INT32 PLCC_const_ sweep timer struct const _sweep timer_rec pConstSweepTimerRec input structure struct const _sweep_input_rec T_WORD action T_WORD timer value structure with return value struct const_sweep_ output rec T_WORD sweep mode T WORD
48. m Message generation m Input selection m Arithmetic operations a PID Sorting moving and copying data Related Information PACSystems CPU Reference Manual GFK 2222 TCP IP Ethernet Communications for PACSystems GFK 2224 Station Manager for PACSystems GFK 2225 Proficy Machine Edition Logic Developer PLC Getting Started GFK 1918 Chapter Installation This chapter explains how to install the PACSystems C Toolkit software on your personal computer This chapter provides the following information What you will need to use the C Toolkit software Installing the C Toolkit for PACSystems Running the C Toolkit C Toolkit file structure System Requirements To use the C Toolkit you will need the following Note GFK 2259E PC Pentium class processor 166MHz or better RAM 128MB minimum Free Disk Space 100MB minimum Operating System Windows XP Professional service pack 1 recommended or Windows 2000 Professional service pack 3 recommended The C Programmer s Toolkit for PACSystems has not been qualified for use with the Windows Vista operating system 2 1 Installing the C Toolkit for PACSystems This section describes how to install the C Toolkit software for PACSystems on your computer and how to set up your computer to use the Toolkit Before installing the C Toolkit to the same directory as a previous installation you should first uninstall the previous version Failure to do so may cause
49. of these references may be available throughout the logic program or access to these references may be limited to a single ladder logic program block Data Scope of P and L User Reference Range Scope Accessible from any program block AL Local Accessible from within a ladder logic block Also accessible from any external block called by the ladder logic block In a program block P should be used for program references which will be shared with other program blocks L are local references which can be used to restrict the use of register data to that ladder logic program block and any C block called by that ladder logic block These references are not available to any other parts of the program Block Enable Output ENO In ladder logic the function block CALL when used with a block as the target provides a boolean ENO output This ENO output from the call is under the direct control of the block The ENO output is controlled by the return value from GefMain If GefMain returns a value of GEF_EXECUTION_OK the ENO output is turned ON 1 If however GefMain returns a value of GEF_EXECUTION_ERROR the CALL function block ENO output is turned OFF 0 The C symbols GEF_EXECUTION_OK and GEF_EXECUTION_ERROR are defined in the toolkit file PACRxP1c h Writes to S Memory Using SB x 3 132 The S table is for the PLC to provide status on its operation This table is intended to be written only by the CPU f
50. only on an RX7i use the command compileCPACRX7i For example to compile multiple C files for a C Block that can be run on any PACSystems RX PLC target enter compileCPACRX In this case a file name is not given because the file name set comes from the sources file The name of the output file is the base name of the first file in the sources file list plus the gefElf extension For the example given above the output file is myCFile1 gefElf Again this file will be located in the subdirectory plc When working with multiple files you will need to add the keyword extern to any function or global variable that is referenced and declared in another file For example if myCFile1 uses myFunction2 and myVar2 in myCFile2 myCFile1 must declare these extern as shown below extern int myVar2 extern void myFunction2 void GFK 2259E Chapter 3 Writing a C Application 3 7 Specifying Compiler Options 3 8 You can specify the following compiler options by supplying keywords after the filename for the single file case or setting flag1 and flag2 with one of the keywords in the sources file when compiling multiple files 1 Disable Stack Checking Keyword DisableStackCheck this disables stack checking on every user function call This decreases C Block execution time but eliminates a check to determine if a particular function call will overrun the user program stack which could lead to data corruption and use
51. the error number in errcode to an error message string It stores the error string in buffer The function returns GEF_OK or GEF_ERROR GEF_ERROR is returned if a NULL pointer is passed as the input for stringBuffer Errno is not set _stricmp Perform a lowercase comparison of strings is not supported This function does not set errno Note NULL or invalid input pointer to this function will put the CPU into CPU Halted mode _strlwr Convert a string to lowercase is not supported This function does not set errno Note NULL or invalid input pointers to this function will put the CPU into CPU Halted mode This function does not set errno Note NULL or invalid input pointers to this function will put the CPU into CPU Halted mode This function does not set errno Note NULL or invalid input pointers to this function will put the CPU into CPU Halted mode _strnicmp Compare characters of two strings without regard to case is not supported _strnset Initialize characters of a string to a given format is not supported This function does not set errno Note NULL or invalid input pointers to this function will put the CPU into CPU Halted mode This function does not set errno Note NULL or invalid input pointer to this function will put the CPU into CPU Halted mode _strrev Reverse characters of a string is not supported _strset Set characters of a string to a character is not supported
52. the name uses BUS instead of VME to make the function more general i e the same code could be used on various PACSystems CPUs word PLCC_VME_config_read void buffer word length byte rack byte slot unsigned long offset Not supported word PLCC_VME_config_write void buffer word length byte rack byte slot unsigned long offset Not supported Similar function as the 90 70 but the function now has four additional input parameters rack slot sub slot and region that specify the VME memory access In addition the functions now have a status parameter and the name uses BUS instead of VME to make the function more general i e the same code could be used on various PACSystems CPUs New Bus function for 32 bit access A 27 Target Library VME Functions Structures and Constants 90 70 PLC Library Compatibility Notes amp Issues T_INT32 PLCC_BUS_write_dword T_WORD rack T WORD slot T WORD New Bus function for 32 bit access subSlot T_WORD region T_ WORD pStatus T_ DWORD value T_ DWORD address Write a dword to the VME bus T_INT32 PLCC_BUS_RMW_dword T_WORD rack T_WORD slot T_ WORD New Bus function for 32 bit access subSlot T WORD region T_WORD pStatus T_DWORD pOriginalValue T_BYTE op_type T DWORD mask T_DWORD address Read Modify Write a dword to the VME bus define BUS_OR 1 define BUS_AND 0 Target Library Error Functions Structures and Constants Implem
53. the size is in bits For all other types the size is in bytes InParam pVarInfo Pointer to a PLC_VAR_REC information record ReturnVal size Size in bits for BOOLs Arrays of BOOLs Size in bytes for all other types Zero is returned for NULL input pointer Note BYTE arrays in non discrete memory are not packed on the PLC so each byte occupies 16 bits of PLC memory This routine will return the size in bytes as if the byte array were packed not the size of the memory occupied on the PLC C Programmer s Toolkit for PACSystems User s Manual January 2012 GFK 2259E Proc PicVarSizeofDiag extern T_DWORD PlicVarSizeofDiag PLC_VAR_REC pVarInfo Description This function returns the total size of the diagnostic memory for a PLC variable If the variable is a BOOL or array of BOOLS the size is in bits For all other types the size is in bytes InParam pVarInfo Pointer to a PLC_VAR_REC information record ReturnVal size Size in bits for BOOLs Arrays of BOOLs Size in bytes for all other types Zero is returned for NULL input pointer Note BYTE arrays in non discrete memory are not packed on the PLC therefore each byte occupies 16 bits of PLC memory This routine will return the size in bytes as if the byte array were packed not the size of the memory occupied on the PLC Proc PicVarSizeofOvr extern T_DWORD PlicVarSizeofOvr PLC_VAR_REC pVarInfo Description This function returns the total size of the override me
54. the specified Reference Table RefTable and at the specified offset is written with the writeValue as a 16 bit signed integer InParam RefTable Reference table to write InParam offset Offset within the reference table to write Note the offset is 1 based For example Reffable R_MEM and offset 1 accesses R00001 InParam writeValue The value to write to the specified reference table and offset ReturnVal If the RefTable or offset are out of range no reference memory values are changed and the function returns GEF_ERROR If the offset is within range the function returns GEF_OK C Programmer s Toolkit for PACSystems User s Manual January 2012 GFK 2259E Errno If there is an error this function sets Errno to give specific information on what caused the error Applications that use Errno should first call PLCC_ClearErrno to ensure Errno was not already set by another function call Errno can be read using PLCC_GetErrno Errno values are located in ctkPlcErrno h ReadPlicint T_INT16 ReadPlicInt T_WORD RefTable T_DWORD offset Description Reference memory in the specified Reference Table RefTable and at the specified offset is read as a 16 bit signed integer and returned by the function Errno is set if there is an error reading the value InParam RefTable Reference table to read InParam offset Offset within the reference table to read Note the offset is 1 based For example Reffable
55. to work the CPU s serial port must be configured for Message mode If the CPU s serial port is not configured for Message mode and PLCC_MessageWrite is called no characters are placed into the print queue and the return value from PLCC_MessageWrite is 1 Reference Table Monitoring As with PLCC_MessageWrite debugging the execution path and key data items may be determined by modifying a C application to place this information into unused areas of the global PLC reference tables R W M T P etc and then viewing the saved execution road map and key data items through the programmer s online reference display s C Programmer s Toolkit for PACSystems User s Manual January 2012 GFK 2259E Chapter Conversion Notes and Series 90 Compatibility For the most part C Block programming with the PACSystems is very similar to the Series 90 70 and Series 90 30 PLCs This chapter describes differences that must be considered when converting Series 90 70 or Series 90 30 applications to PACSystems C blocks in existing Series 90 program folders must be recompiled using the PACSystems C Toolkit Series 90 Compatibility Header Files PLCC9070 h and PLCC9030 h GFK 2259E To minimize conversion issues when converting Series 90 applications use the appropriate include file in your C Block application Series 90 70 Use PLCC9070 h instead of PACRXPLC h or PACRX7IiPIc h Series 90 30 Use PLCC9030 h instead of PACRXPLC h or
56. value Infinity is Ox7ffO000000000000 and OxfffO000000000000 respectively for a double value NAN is 0x7f8xxxxx and Oxff8xxxxx respectively where xxxxx is non zero for a float value Infinity is Ox7f800000 and Oxff800000 respectively for a float value acos 32 bit on the 90 70 is functionally equivalent to acosf on PACSystems acosl 80 bits is not supported Similar compatibility issues exist for the other math functions Errno exception EDOM is not set by this function and returns not a number NAN if outside the range of 1 to 1 asinl is not supported Errno exception EDOM is not set by this function and returns not a number NAN if outside the range of 1 to 1 atanl is not supported Function does not set errno For NAN input returns NAN respectively NAT eb not supporto PNA ab isnt supported include lt math h gt include lt math h gt include lt math h gt double ceil double float ceilf float double cos double float cosf float double cosh double float coshf float C Programmer s Toolkit for PACSystems User s Manual January 2012 ceill is not supported Function does not set errno For NAN input returns NAN respectively For Infinity input returns Infinity respectively cosl is not supported Function does not set errno For NAN input returns NAN respectively For Infinity input returns NAN coshl is n
57. when the application was first stored All global and static variables which are given an initial value will be non retentive In general uninitialized global data will be retentive Since non retentive data requires twice the memory space within the CPU one for the working copy and one for the saved copy large initialized data structures should be avoided if memory usage is a concern The following examples illustrate retentive and non retentive variables Examples T_INT16 my varl retentive T_INT16 my _var2 20 non retentive reset to20 on stop to run transitions static T_INT16 my var3 retentive static T_INT16 my var4 12 non retentive reset to12 on stop to run transitions Chapter 3 Writing a C Application 3 125 GefMain Parameter Declaration Errors for Blocks 3 126 When declaring the parameters to cetmain in a block the type order and number of parameters must match the ladder logic call instruction exactly Use the following ladder logic segment and associated C block as an example This rung of ladder logic calls MATH2 to add the two integers X1 and X2 and place the sum in Y1 and subtract the integer X2 from the integer X1 placing the difference in Y2 100004 Roo001 POOOO1 This function has two input parameters and two output parameters Y1 X1 X2 Y2 X1 X2 int GefMain T_INT16 x1 T_INT16 x2 T_INT16 yl T_INT16 y2 if
58. 0 if pR8 0 RW 10 pR8 write R8 to R10 as word RD 12 failCount return GEF_EXECUTION_OK else pM500 pl1000 Copy I1000 one byte to M500 status GEF_EXECUTION_ ERROR failCount return status 4 2 C Programmer s Toolkit for PACSystems User s Manual January 2012 GFK 2259E GFK 2259E 3 Optionally add code to the PLC C stub functions to simulate the desired PLC behavior Note PLC C stub function files are located in the following directory lt yourlnstallDir gt PACSystemsCToolkit Targets CommonFiles TargetStubLioCommon 4 Create sourcesDebug file that specifies which files to compile together An example is given below Note Comments can be included by putting a in the first column sourcesDebug file CFILENAMES myCBlock c ctkPcDriver c 5 Start the C Toolkit Double click the desktop icon PACSystems TM C Toolkit or use the Start menu to execute the file ctkPACS bat located at the Toolkit s root directory 6 Within the DOS window created in step 4 compile the C Block for the PC using the following command in the same directory containing the source files and the sourcesDebug file CompileCDebugPACRX For Rx7i targets use CompileCDebugPACRX7i for RX3i targets use CompileCDebugPACRX3i 7 Run the Cygwin debugger using the following command debugPACRX pc myCBlock exe For Rx7i targets use DebugPACRX7i for RX3i targets use DebugPACRX3i This will
59. 0 and 90 30 T_INT32 BIT_SET_M T_DWORD address T_INT32 BIT_CLR_M T_DWORD address Function ee with 90 70 and 90 30 Same return status as BIT_SET_l BIT_TST_T address Macro compatible with 90 70 and 90 30 T_INT32 BIT_SET_T T_DWORD address T_INT32 BIT_CLR_T T_DWORD address Function oe with 90 70 and 90 30 Same return status as BIT_SET_l BIT_TST_G address Macro compatible with 90 70 and 90 30 T_INT32 BIT_SET_G T_DWORD address T_INT32 BIT_CLR_G T_DWORD address Function ae with 90 70 and 90 30 Same return status as BIT_SET_l PT o ooet Aoun 80 70 On FS _ IBIT SET_GA x not supported 90 70 only FBI CLR GAL not supported 80 70 only ee BIT TST GB x not supported 90 70 only GFK 2259E Target Library Reference Memory Functions amp Macros Notes amp Issues pig td o a a Oo BIT_TST_GD gt xX lt not supported 90 70 only lS BIT_SET_GD x not supported 90 70 only gt a BIT_CLR_GD x not supported 90 70 only BIT_TST_GE x not supported 90 70 only BIT_SET_GE x not supported 90 70 only BIT_CLR_GE x not supported 90 70 only BIT_TST_SA address Macro compatible with 90 70 and 90 30 Oo Rare an a o S T_INT32 BIT_SET_SA T_DWORD address Function compatible with 90 70 and 90 30 Same return status T_INT32 BIT_CLR_SA T_DWORD address as BIT_SET_I BIT_TST_SB address Macro compatible with 90 70 and 90 30
60. 1 T_INT32 PLCC_sus_res_HSC_interrupts struct sus_res_HSC_interrupts_rec x Suspend Resume High Speed Counter Interrupts define SUSPEND 1 define RESUME 0 define _BIT define Al MEM 70 10 struct sus_res_ HSC_interrupts_rec T_WORD action SUSPEND or RESUME T_WORD memory_type T_WORD reference_address E T_INT32 PLCC_sus_res_interrupts_ext struct sus_res_interrupts_ext_rec x struct sus_res_interrupts_ext_rec T_WORD action SUSPEND or RESUME T_WORD memory_type Address of the interrupt trigger T_DWORD memory_offset E T_INT32 PLCC_get_escm_status struct escm_status_rec Function PLCC_get_escm_status struct escm_status_rec T_WORD port_number T_WORD port_status E T_INT32 PLCC_set_application_redundancy_mode T_WORD mode Possible values for the backup mode define BACKUP_MODE 0 define ACTIVE_MODE 1 C Programmer s Toolkit for PACSystems User s Manual January 2012 Series 90 PLC Library Compatibility Notes amp Issues Compatible with 90 70 and 90 30 Compatible with 90 70 and 90 30 Not supported by Series 90 Supported by PACSystems Release 3 5 or greater int PLCC_acc_mem struct plec_mem_acc_rec mem_acc_rec_ptr Not Supported since bulk memory is supported directly through W memory type Compatible with 90 70 except the function will always return 0 escm not available or unsupported for this release of PACSystems because the ESCM is not prese
61. 147483647 range unsigned long strtoul const char Sets errno if the input cannot be represented char endptr int base as a 32 bit unsigned integer For example numbers outside 0 to 4294967295 range _ultoa Convert an unsigned long integer to a string is not supported Search This function does not set errno void bsearch const void key Note NULL or invalid input pointers to this const void base function will put the CPU into CPU Halted size_t nmemb mode size_t size int compar const void const void qsort void base This function does not set errno size_t nmemb Note NULL or invalid input pointers to this size_t size function will put the CPU into CPU Halted int _compar const void const void moge NA Search _Ifind Performs a linear search for the specified key Not supported NA _lsearch Performs a linear search for a value adds to end of list if not found Not supported include lt string h gt include lt string h gt include lt string h gt include lt string h gt include lt string h gt C Programmer s Toolkit for PACSystems User s Manual January 2012 String Manipulation This function does not set errno char strcat char const char Note NULL or invalid input pointers to this function will put the CPU into CPU Halted mode char strchr const char int This function does not set errno Note NULL or invalid input poin
62. 5 5 Errno functions 3 104 Error functions structures and constants A 28 F Fault table functions structures and constants A 11 Fault table service request functions 3 73 File names 3 2 File structure 2 3 Filenames 3 123 Floating point arithmetic 3 123 FST _EXE and FST_SCN macros 3 133 Functions bus read write 3 34 BUS semaphore 3 43 errno 3 104 fault table service request 3 73 general PLC 3 28 ladder function blocks 3 80 miscellaneous general 3 84 module communications 3 79 reference memory 3 86 service request 3 48 utility 3 103 G GefMain Parameter declaration errors for blocks 3 126 General functions structures and constants A 17 Index 1 Index Index 2 General PLC functions 3 28 Global variables 3 124 initialization 3 124 PLC handling 3 125 PLC STOP to RUN re initialization 3 125 H Header files compatibility 5 1 I O Variable Access 3 105 Installation 2 1 Integer Word macros 3 22 Interrupt blocks 3 135 Introduction 1 1 L Ladder function blocks 3 80 LST_SCN macro 3 133 M Macros bit 3 20 byte 3 21 Double precision floating point 3 23 double word floating point 3 23 for referencing PLC memory 3 18 integer word 3 22 reference memory size 3 24 transition alarm and fault 3 25 Message Mode Debugging 4 4 Miscellaneous general functions 3 84 Module communications 3 79 Multiple C files compiling 3 7 Multiple C source files sample
63. 85 2661 Microsoft Corp C GE Software PACS ystemsCToolkit Projects gt 2 2 C Programmer s Toolkit for PACSystems User s Manual January 2012 GFK 2259E Running C Toolkit To start the toolkit double click the desktop icon PACSystems TM C Toolkit or use the Start menu to execute the file ctkPACS bat located at el the Toolkit s root directory PACS ystem In addition you can also open an independent DOS window navigate C Toolkit to the directory containing the ctkPACS bat file run the ctkPACS bat file navigate to your project and then compile the project Because the ctkPACS bat file does not change the autoexec bat file the environment variables are only valid for the life of the DOS window This means that you can run another version of the toolkit on the same machine without conflicts between the two packages because the environment variables are local to each DOS window C Toolkit File Structure The file structure of the installed C Toolkit is shown below bin File Folder Compilers File Folder Does File Folder Projects File Folder Targets File Folder Pe ictkPACS bat MS DOS Batch File GNU Ext Text Document index htm HTML Document Z license txt Text Document readme txt Text Document readmePACRX3i txt Text Document readmePACRX7i txt Text Document 2 readmePACRX txt Text Document A Uninstal exe Application GFK 2259E Chapter 2 Installation 2 3 Directories Bin contains t
64. ASK T_WORD memory_type T_WORD memory_address E define MASK 1 define UNMASK 0 T_INT32 PLCC_mask_lO_interrupts_ext struct Not supported by Series 90 mask_lO_interrupts_ext_rec x Supported by PACSystems Release 3 5 or greater struct mask_lO_interrupts_ext_rec T_WORD action MASK or UNMASK T_WORD memory_type Address of input interrupt trigger T_DWORD memory_offset T_INT32 PLCC_read_lO_override_status struct Compatible with 90 70 and 90 30 read_lO_override_status_rec x Read I O Override Status struct read_lO_override_status_rec T_WORD override_set E define OVERRIDES_SET define NO_OVERRIDES_SET T_INT32 PLCC_set_run_enable struct set_run_enable_rec x Compatible with 90 70 Set Run Enable Disable define RUN_DISABLED 1 define RUN_ENABLED 2 struct set_run_enable_rec T_WORD enable E GFK 2259E Appendix A Target Library Functions A 25 A 26 Target Library General Functions Structures and Constants T_INT32 PLCC_mask_timed_interrupts struct mask_timed_interrupts_rec x Mask Unmask Timed Interrupts struct mask_timed_interrupts_rec T_WORD action READ_INTERRUPT_MASK or WRITE_INTERRUPT_MASK T_WORD status if action is READ_INTERRUPT_MASK then this field has MASK or UNMASK as the return value if the action is WRITE_INTERRUPT_MASK then set this field to MASK or UNMASK define READ_INTERRUPT_MASK 0 define WRITE_INTERRUPT_MASK
65. Blocks 6 In the C Toolkit directory structure there are two subdirectories under the Projects directory that contain examples of blocks SampleProj1 and SampleProj2 SampleProj1 The SampleProj1 directory contains three sample C files that generate a C Block from a single C source file Each file is discussed below mw ctkCBlockTest c is intended for compilation for the RX7i RX3i or PACRX and makes a Call to every function and macro supported by the C Toolkit This block is an example of an application without input output parameters Because ctkCBlockTest exercises all available toolkit routines and macros it will not execute on a PACSystems CPU with the default configuration See the setup note at the top of the C file for more information m ctkCBlockTestParams_7_7 c provides a simple example using seven input and seven output parameters The application equates the output to the inputs simulating a simple move type of operation In addition it provides an example of controlling ENO by returning GEF_EXECUTION_ERROR ENO off if input 1 pCoolantTemp is greater than 1000 or GEF_EXECUTION_OK ENO on otherwise To execute this sample block on a PACSystems CPU the C block must be setup as a parameterized block with 7 WORD inputs and 7 WORD outputs mw ctkCBlockTestPc c is a version similar to ctkCBlockTest C with additional driver code at the end of the file so that it can be compiled and run on the PC GFK 2259E 6 1 e
66. CALL function block diagram program place a Call instruction in the desired location Select the name of the block to call Select the C block desired If the block has parameters provide reference memory locations for each input and output parameter To use aC block in an ST program see page 3 12 GFK 2259E Chapter 3 Writing a C Application 3 11 3 12 Using a C Block in an ST Program You can call a C block from an ST program by using a Block Call statement A block call to a parameterized C block can use either the informal or formal convention Call to an unparameterized C block My C Block Call to a parameterized block using the informal convention My C Block my_Inputl my Input2 my Output2 my Outputl Call to a parameterized block using the formal convention parameters can be in any order My C Block Outl gt my Output1 Inl my Inputl In2 my Input2 Out2 gt my Output2 C Programmer s Toolkit for PACSystems User s Manual January 2012 GFK 2259E PACSystems C Block Structure A C block can be invoked in one of five ways GFK 2259E 1 2 3 4 5 As a sub block of the main block As a sub block of an LD ST or FBD block As a sub block of an LD ST or FBD block with parameters parameterized block As an I O timed or module interrupt block As a sub block of an interrupt block Blocks invoked as a sub block of main or as a sub block of an interrupt block may
67. C_BUS_ write block T_WORD rack T_WORD slot T_WORD subSlot T_WORD region T_WORD pStatus void pBuffer T_WORD length T_DWORD address Description Write a block of data to a device on the bus InParam rack The rack number containing the module to access InParam slot The slot number containing the module to access InParam subSlot The sub slot number of the module to access InParam region The region number describing the location of the BUS memory This is set up in hardware configuration for the module OutParam pStatus Pointer to status variable see common definition above InParam pBuffer Pointer to the data to be written to a device on the bus InParam length Length of the data to written to a device on the bus in bytes InParam address Address of the data to be written ReturnVal 1 if successful 0 if unsuccessful 1 if not supported 3 42 C Programmer s Toolkit for PACSystems User s Manual January 2012 GFK 2259E BUS Semaphore Functions The following functions are designed to enable semaphore handling on the bus These functions cannot be interrupted BUS_RMW read modify write Note The following definitions are used to define whether the mask parameter uses an OR or AND operation on the data BUS_OR BUS_AND PLCC_BUS_RMW_byte GFK 2259E T_INT32 PLCC_BUS_RMW_byte T WORD rack T WORD slot T_ WORD subSlot T_WORD region T_WORD pStatus T_BYTE pOriginalValue T_WORD op type T_D
68. DiagsTo Pointer to the memory location where the diagnostic values are to be written Notes For type BOOL an entire byte will be written to pReadDiagsTo with the low bit of the byte containing the diagnostic value of the BOOL variable For type BYTE 8 bits of diagnostics will be written to pReadTo regardless of whether the array is in discrete or non discrete memory on the PLC For all other types if the variable is in non discrete memory the number of bytes written will be the byte size of the array element divided by 2 For example an element from an array of words would be 1 byte of diagnostic data If the variable is discrete memory the number of bytes written will be equal to the size of an array element in bytes InParam numIndices Number of indices needed to locate an element of the array This must be greater than zero and must match the number of dimensions of the variable declared on the PLC InParam lt indices gt A variable number of indices must match numIndices that indicates the element of the array for which diagnostics is to be read These should be T_INT32 type Errno If there is an error this function sets Errno to give specific information on what caused the error Applications that use Errno should first call PLCC_ClearErrno to ensure Errno was not already set by another function call Errno can be read using PLCC_GetErrno Errno values are provided in ctkPlcErrno h C Programmer s Toolkit f
69. E DINT DWORD INT LREAL REAL UINT WORD See section C Toolkit Variable Types for information on how to map programmer PLC types to C Toolkit types m Length Inputs Outputs alamet Tame Ler _Deseipion _ Cancel gt gt Help Note All parameters must be declared even if some of them are NULL A NULL parameter may be used when converting a 90 70 C Block to PACSystems To declare the parameter in Machine Edition the parameter must have both a type and a length If the type is specified as NONE with no length Machine Edition does not generate the parameter 3 10 C Programmer s Toolkit for PACSystems User s Manual January 2012 GFK 2259E Scheduling C Blocks To schedule a C Block as a timed I O or module Interrupt click on the C Block In the Properties page for the C Block click the Scheduling item and then click on the button provided This opens the Scheduling dialog box that allows you to select m Type Timed I O or Module Interrupt m Trigger I O address for I O or Module Interrupt Time Base 0 001s 0 01s 0 1s or 1s base for timed interrupts m Interval the number of time base units between timed interrupts ma Delay initial delay before the timer starts for timed interrupts Please note that only C blocks with no Input and Output parameters may be scheduled Scheduling x iai ce S Timed Interrupt Using a C Block in an LD or FBD Program To use a C Block in the ladder or
70. EF_OK Errno If there is an error this function sets Errno to give more specific information on what caused the error Applications that use Errno should first call PLCC_ClearErrno to ensure Errno was not already set by another function call Errno can be read using PLCC_GetErrno Errno values are located in ctkPlcErrno h 3 96 C Programmer s Toolkit for PACSystems User s Manual January 2012 GFK 2259E refMemSize setBit GFK 2259E T_DWORD refMemSize T_WORD RefTable Description This function returns the size of specified reference memory InParam RefTable Reference table segment selector used to indicate which table to find the size ReturnVal Returns the size of reference memory in word units for word type memories and bits for bit type memories and in bytes for analog diagnostic memory If RefTable is invalid or pRefLocalSegSizeTable pointer is null the function returns 0 The function can also return 0 if the memory has been configured with a 0 length Errno If there is an error this function sets Errno to give specific information on what caused the error Applications that use Errno should first call PLCC_ClearErrno to ensure Errno was not already set by another function call Errno can be read using PLCC_GetErrno Errno values are located in ctkPlcErrno h T_INT32 setBit T_WORD RefTable T_DWORD offset T WORD bitNumber Description This function sets the specified bit in reference memory This fun
71. EL if not used T_DWORD alt_mem offset hi Valid memory types define I_MEM 16 define Q MEM 18 define R_MEM 8 define AI_MEM 10 define AQ MEM 12 define W_MEM 196 define PLCVAR MEM 262 extern T_INT32 PLCC_do io ext struct do_io_ext_rec pDoIoExtRec Description This function is an extension of PLCC_do_io It is used to update inputs or outputs for one scan while the program is running This function can be used in conjunction with the Suspend I O function page 3 82 which stops the normal I O scan It can also be used to update selected I O during the program in addition to the normal I O scan This function provides PLC variable access along with reference addresses having 32 bit offset as input To specify a PLC variable as an input to a routine use the Chapter 3 Writing a C Application 3 81 PLC_VAR_MEM memory type and the address of the variable record as the offset For details on the use of PLC_VAR_MEM see page 3 86 InParam pDoloRec A pointer to the Do I O Extn record ReturnVal 1 if successful 0 if unsuccessful 1 if not supported Errno Sets Errno if input memory or alt memory is out of range See cpuErrno h for possible values PLCC_sus_io T_INT32 PLCC_sus_io void Description This function is used to stop normal I O scans from occurring for one CPU sweep During the next output scan all outputs are held at their current states During the next input scan the input references
72. E_AND_STATE 3 sweep mode return values define CONSTANT_SWEEP_ENABLED 1 define CONSTANT_SWEEP_DISABLED 0 A 20 C Programmer s Toolkit for PACSystems User s Manual January 2012 GFK 2259E Target Library General Functions Structures and Constants Series 90 PLC Library Compatibility Notes amp Issues T_INT32 PLCC_read_window_values struct read_window_values_rec x Compatible with the 90 70 and 90 30 except that structure member x Values names with the prog_ suffix now use the controller _ suffix and 7 Head window fa ues those that use the sys_ suffix now use the backplane_ suffix This window modes is to make the names consistent with the PACSystems terminology define LIMITED_MODE define CONSTANT_MODE 1 define RUN_TO_COMPLETION_MODE 2 structure with return values struct read_window_values_rec T_BYTE controller_win_time T_BYTE controller_win_mode LIMITED_ MODE CONSTANT_MODE Ns RUN_TO_COMPLETION_MODE T_BYTE backplane_comm_win_time T_BYTE backplane_comm_win_mode LIMITED_MODE CONSTANT_MODE RUN_TO_COMPLETION_MODE T_BYTE background_win_time T_BYTE background_win_mode LIMITED_MODE CONSTANT_MODE r RUN_TO_COMPLETION_MODE E T_INT32 PLCC_change_controller_comm_window struct Compatible with the 90 70 and 90 30 except that function and change_controller_comm_window_rec x structure names containing prog_ now use the
73. GE Intelligent Platforms Programmable Control Products C Programmer s Toolkit for PACSystems User s Manual GFK 2259E January 2012 GFL 002 Warnings Cautions and Notes as Used in this Publication Warning notices are used in this publication to emphasize that hazardous voltages currents temperatures or other conditions that could cause personal injury exist in this equipment or may be associated with its use In situations where inattention could cause either personal injury or damage to equipment a Warning notice is used Caution notices are used where equipment might be damaged if care is not taken Note Notes merely call attention to information that is especially significant to understanding and operating the equipment This document is based on information available at the time of its publication While efforts have been made to be accurate the information contained herein does not purport to cover all details or variations in hardware or software nor to provide for every possible contingency in connection with installation operation or maintenance Features may be described herein which are not present in all hardware and software systems GE Intelligent Platforms assumes no obligation of notice to holders of this document with respect to changes subsequently made GE Intelligent Platforms makes no representation or warranty expressed implied or statutory with respect to and assumes no responsibility fo
74. GFK 2259E Standard Library Routines Appendix A contains a complete list of the standard C library routines supported by C blocks The routines implement ANSI C functionality unless otherwise noted The printf function is not supported You should use the message mode functions described later in this section to access the PLC serial port PACSystems Functions Additional functions are provided by the C Toolkit in support of the PACSystems CPU s operations These functions are defined in the header file included by PACRxPLC h These header files are Header File Functions Page ctkPlcBus h Bus Read Write Functions 3 34 ctkPlcErrno h Errno Functions 3 104 ctkPlcFault h Fault Table Service Request Functions 3 73 ctkPlcFunc h General PLC Functions 3 28 Miscellaneous General Functions 3 84 Service Request Functions 3 48 ctkPIcUtil h Utility Function 3 103 ctkRefMem h Reference Memory Functions 3 86 ctkVariables h PLC Variable Access 3 105 These files are located in the following subdirectory PACSystemsCtoolkit Targets CommonFiles IncCommon Descriptions of the functions are provided in the sections that follow GFK 2259E Chapter 3 Writing a C Application 3 27 General PLC Functions The following functions make PLC features available to C applications These functions are described in ctkPlcFunc h PLCC_read_elapsed_clock T_INT32 PLCC_read_elapsed_ clock struct elapsed clock_rec pElapsedClockRec struct elapsed _clock_rec
75. If there is an error this function sets Errno to give specific information on what caused the error Applications that use Errno should first call PLCC_ClearErrno to ensure Errno was not already set by another function call Errno can be read using PLCC_GetErrno Errno values are located in ctkPlcErrno h Chapter 3 Writing a C Application 3 89 3 90 ReadPicWord WritePIcint T_WORD ReadPlcWord T_WORD RefTable T_DWORD offset Description A word 16 unsigned bits of reference memory in the specified Reference Table RefTable and at the specified offset is read and returned by the function Errno is set if there is an error reading the value InParam RefTable Reference table to read InParam offset Offset within the reference table to read Note the offset is 1 based For example Reffable R_MEM and offset 1 accesses R00001 ReturnVal The value read from the specified reference table at the specified offset Errno If there is an error this function sets Errno to give specific information on what caused the error Applications that use Errno should first call PLCC_ClearErrno to ensure Errno was not already set by another function call Errno can be read using PLCC_GetErrno Errno values are located in ctkPlcErrno h T_INT32 WritePlcInt T_ WORD RefTable T_DWORD offset T_INT16 writeValue Description This function writes to reference memory taking into account overrides and transition bits Reference memory in
76. K 2259E Chapter 3 Writing a C Application 3 67 PLCC_mask_timed_interrupts T_INT32 PLCC_mask_timed_interrupts struct mask_timed_interrupts rec pMaskTimedInterruptRec struct mask_timed_interrupts_rec T_WORD action READ INTERRUPT MASK or WRITE INTERRUPT MASK T WORD status if action is READ INTERRUPT MASK then this field has MASK or UNMASK as the return value if the action is WRITE_INTERRUPT MASK then set this field to MASK or UNMASK Possible action field values define READ_INTERRUPT_MASK 0 define WRITE_INTERRUPT_MASK 1 Possible status field values define MASK 1 define UNMASK 0 Description This function is the C interface to service request 22 Mask Unmask Timed Interrupts Use this function to mask or unmasked timed interrupts and to read the current mask When the interrupts are masked the PLC CPU will not execute any interrupt block that is associated with a timed interrupt Timed interrupts are masked unmasked as a group They cannot be individually masked or unmasked To read current mask set action to READ_INTERRUPT_MASK To change current mask to unmask timed interrupts set action to WRITE_INTERRUPT_MASK and status to UNMASK To change current mask to mask timed interrupts set action to WRITE_INTERRUPT_MASK and status to MASK Successful execution will occur unless some number other than 0 or 1 is entered as the requested operation or mask value In OutParam pMaskTimedi
77. M T MEM M_MEM SA_MEM SB_MEM SC_MEM S MEM Al_DIAG_MEM AQ_DIAG_MEM G_MEM BIT 10 12 196 16 18 20 22 24 26 28 30 40 42 56 70 DIAG_MEM Q_DIAG_MEM TRANS_MEM Q_TRANS_MEM T_TRANS_MEM M_TRANS_MEM SA_TRANS_MEM SB_TRANS SC_TRANS_MEM S TRANS MEM G_TRANS_MEM RPT_FLT_MEM NULL_SEGSEL PLC_VAR_MEM 110 112 132 134 136 138 140 142 144 146 148 188 Oxff 262 PLC_VAR_MENM is used for PLC variable access When PLC_VAR_MEM is used the offset should be the address of the PLC variable record This memory type must be used on a routine that supports a 32 bit offset For example mask_io_intr_ext_rec action MASK mask_io_intr_ext_rec memory_type PLC_VAR_MEM mask_io_intr_ext_rec memory_offset amp myVarRec The variables used must be internally or externally published in the PLC If they are not published store to the PLC will fail C Programmer s Toolkit for PACSystems User s Manual January 2012 GFK 2259E WritePicByte GFK 2259E T_INT32 WritePlcByte T_ WORD RefTable T_DWORD offset T_ BYTE writeValue T_BOOLEAN msbByte Description This function writes to reference memory taking into account overrides and transition bits A byte of reference memory in the specified Reference Table RefTable and at the specified offset is written with the writeValue InParam RefTable Reference table to write InParam offset Offset within the reference table to write Note t
78. NIU_001 CMU_310 Description This function returns the PLC family model firmware version and firmware revision 0x02 0x04 0x05 0x06 0x08 0x0A 0x0C 0x0E InParam PLC_ver_info Pointer to the structure of type PLC_ver_info The PLC will return information concerning its firmware version in each of the fields in this structure ReturnVal The function will return O if successful and 1 if unsuccessful GFK 2259E Chapter 3 Writing a C Application for proper interpretation Host PLC product line Specific Model of PLC Major Version of PLC firmware Minor Revision of PLC firmware PACSystems PACSystems PACSystems PACSystems PACSystems PACSystems PACSystems PACSystems RX7i RX7i RX7i RX7i RX7i Rx3i Rx3i Rx3i 300Mhz PLC 700Mhz PLC CPU CPU 700Mhz Redundant PLC CPU VME 700Mhz VME 1 8Ghz PCI 300Mhz PCI 300Mhz PCI 300Mhz Pentium M PLC CPU Pentium M PLC CPU PLC CPU NIU MaxOn CPU 3 33 Bus Read Write Functions The following functions based on the BUS functions available in ladder logic are defined in ctkPlcBus h These functions are currently unsupported in the Rx3i and will return a not supported return value 1 When reading the memory pointed to by 3 34 pStatus the following values are possible variables returned by these functions Note Note C Programmer s Too
79. ORD pStatus T_ DWORD pOriginalValue T_BYTE op_type T_BYTE mask T_ DWORD address Read Modify Write a byte to the VME bus define BUS_OR 1 define BUS_AND 0 T_INT32 PLCC_BUS_RMW_word T_WORD rack T WORD slot T WORD subSlot T_ WORD region T_ WORD pStatus T_ DWORD pOriginalValue T_BYTE op_type T WORD mask T_DWORD address Read Modify Write a word to the VME bus define BUS_OR 1 define BUS_AND 0 T_INT32 PLCC_BUS_TST_byte T_WORD rack T_WORD slot T_ WORD subSlot T WORD region T_WORD pStatus T_BYTE semaphore_output T_DWORD address Test and set a byte on the VME bus T_INT32 PLCC_BUS_TST_word T_WORD rack T WORD slot T WORD subSlot T_WORD region T_WORD pStatus T_ WORD semaphore_output T_DWORD address Test and set a word on the VME bus T_INT32 PLCC_BUS_read_dword T_WORD rack T_WORD slot T_ WORD subSlot T_WORD region T_WORD pStatus T_ DWORD value T_DWORD address Read a dword from the VME bus Appendix A Target Library Functions 90 70 PLC Library Compatibility Notes amp Issues byte PLCC_VME_set_amcode byte amcode function is not supported since the PACSystems system uses rack slot sub slot region to address VME memory Similar function as the 90 70 but the function now has four additional input parameters rack slot sub slot and region that specify the VME memory access In addition the functions now have a status parameter and
80. PLC_EXT_FAULT_TABLE or IO_EXT_FAULT_TABLE union struct PLC_ext_fault_entry_rec PLC_entry struct O_ext_fault_entry_rec O_entry define PLC_EXT_FAULT_TABLE 0x80 define O_EXT_FAULT_TABLE 0x81 C Programmer s Toolkit for PACSystems User s Manual January 2012 This function is not described in the Series 90 C Toolkit Users Manual but is included in the 90 70 90 30 C Toolkit header files This function is included in the PACSystems C Toolkit for compatibility GFK 2259E T_INT32 PLCC_read_last_fault struct read_last_fault_rec x Compatible with 90 70 and 90 30 Read Last Logged Fault Table Entry struct time_stamp_rec T_BYTE second BCD format seconds in low order nibble tens of seconds in high order nibble T_BYTE minute BCD format same as for seconds h T_BYTE hour BCD format same as for seconds T_BYTE day BCD format same as for seconds T_BYTE month BCD format same as for seconds T_BYTE year BCD format same as for seconds struct PLC_flt_address_rec T_BYTE rack T_BYTE slot T_WORD task j struct IO_flt_address_rec T_BYTE rack T_BYTE slot T_BYTE IO_bus T_BYTE block T_WORD point E struct PLC_fault_entry_rec T_BYTE long_short T_BYTE reserved 3 struct PLC_flt_address_rec PLC_fault_address T_BYTE fault_group T_BYTE fault_action T_WORD error_code T_WORD fault_specific_data 12 struct time_stamp_rec time_stamp F struct lO_fault_e
81. PLC_fault_entry rec T_BYTE T_BYTE struct T_BYTE T_BYTE T_WORD T_WORD struct be long_short reserved 3 PLC_flt_address rec PLC_fault_address fault_group fault_action error_code fault_specific_data 12 time_stamp_rec time_stamp struct IO fault entry rec T_BYTE struct struct T_BYTE T_BYTE T_BYTE T_BYTE T_BYTE T_BYTE struct long_short reference_address_rec reference_address IO flt_address_rec IO_fault_address fault_group fault_action fault_category fault_type fault_description fault_specific_data 21 time _stamp_rec time_stamp struct PLC_ext_fault_entry rec T_BYTE T_BYTE struct T_BYTE T_BYTE T_WORD T_WORD struct T_WORD long_short reserved 3 PLC_flt_address rec PLC_fault_address fault_group fault_action error_code fault_specific_data 12 ext_time_stamp_rec time_stamp fault_id struct IO _ext_fault_entry rec T_BYTE struct struct T_BYTE T_BYTE T_BYTE T_BYTE T_BYTE T_BYTE struct T_WORD C Programmer s Toolkit for PACSystems User s Manual January 2012 long_short reference address rec reference address IO flt_address_rec IO_ fault address fault_group fault_action fault_category fault_type fault_description fault_specific_data 21 ext_time_stamp_rec time_stamp fault_id GFK 2259E PLCC_clear_fault_tables T_INT32 PLCC_clear fault tables struct clear fault tables rec x struct clear fault tab
82. PLC_fault_entry_rec T_BYTE long_short T_BYTE reserved 3 struct PLC_flt_address rec PLC_fault_address T_BYTE fault_group T_BYTE fault_action T_WORD error_code T_WORD fault_specific_data 12 struct time_stamp_rec ti F struct lO_fault_entry_rec T_BYTE long_short struct reference_addres me_stamp s_rec reference_address struct O_flt_address_rec O_fault_address T_BYTE fault_group T_BYTE fault_action T_BYTE fault_category T_BYTE fault_type T_BYTE fault_description T_BYTE fault_specific_data 21 struct time_stamp_rec ti F me_stamp struct PLC_ext_fault_entry_rec T_BYTE long_short T_BYTE reserved 3 struct PLC_flt_address rec PLC_fault_address T_BYTE fault_group T_BYTE fault_action T_WORD error_code T_WORD fault_specific_data 12 struct ext_time_stamp_rec time_stamp T_WORD fault_id E struct lO_ext_fault_entry_rec T_BYTE long_short struct reference_address_rec reference_address struct IO_flt_address_rec IO_fault_address T_BYTE fault_group T_BYTE fault_action T_BYTE fault_category T_BYTE fault_type T_BYTE fault_description T_BYTE fault_specific_data 21 struct ext_time_stamp_rec time_stamp T_WORD fault_id C Programmer s Toolkit for PACSystems User s Manual January 2012 Series 90 PLC Library Compatibility Notes amp Issues GFK 2259E Target Library Fault Table Functions Series 90 PLC Library Compat
83. SIZE M_SIZE ISA SIZE Compatible with the 90 70 and 90 30 but implemented as a B SIZE function for example C_SIZE define SA_SIZE refMemSize SA_MEM SIZE W_SIZE New Macro to support W memory Not supported by Series 90 DIAGS_ SIZE Compatible with the 90 70 but implemented as a function for Q_DIAGS_SIZE example Al_DIAGS_ SIZE define _DIAGS_SIZE refMemSize l_DIAG_MEM AQ_DIAGS_SIZE RACKX r Compatible with the 90 70 but implemented as a function call to the function rackX Errnos TLIB_ERRNO_INVALID_RACK alo gt l Ji O on ee N NIN n m m m N m r s Compatible with the 90 70 but implemented as a function call to slotX Errnos TLIB_ERRNO_INVALID RACK TLIB_ERRNO_INVALID_SLOT BLOCKX r s b sba Compatible with the 90 70 but implemented as a function call to blockX Errnos REF_ERRNO_INPUT_OUT_OF_RANGE Compatible with the 90 70 but implemented as a function call to rsmb Errnos TLIB_ERRNO_INVALID RACK FST_SCN Macro compatible with 90 70 C Programmer s Toolkit for PACSystems User s Manual January 2012 GFK 2259E Target Library Reference Memory Series 90 PLC Library Compatibility Functions amp Macros Notes amp Issues Macro to provide access to the S00002 system last scan indication bit Compatible with Series 90 30 Macros compatible with 90 70 and 90 30 inherited from the calling block Target Library Fault Table Functions Structures an
84. TE variable consumes 16 bits on the PLC the 8 bit value will be written to the least significant 8 bits of the 16 bit word For type STRING the size of the data copied from pWriteFrom will be the max length in the variables declaration InParam numIndices Number of indices needed to locate an element of the array This must be greater than zero and must match the number of dimensions of the variable declared on the PLC InParam lt indices gt A variable number of indices must match numIndices indicating the element of the array to be written These should be T_INT32 type ReturnVal GEF_OK if successful GEF_ERROR for bad parameter Use Errno to determine cause Errno If there is an error this function sets Errno to give specific information on what caused the error Applications that use Errno should first call PLCC_ClearErrno to ensure Errno was not already set by another function call Errno can be read using PLCC_GetErrno Errno values are located in ctkPlcErrno h C Programmer s Toolkit for PACSystems User s Manual January 2012 GFK 2259E Proc PilcVarMemCopy extern T_INT32 PlcVarMemCopy PLC_VAR_REC pDestVarInfo PLC_VAR_REC pSrcVarInfo Description This function copies the contents of one PLC variable to another PLC variable of the same type and size The size of the destination variable must be greater than or equal to the size of the source variable No other type or bounds checking will be done
85. Toolkit for PACSystems User s Manual January 2012 GFK 2259E Utility Function The following utility function is described in ctkPLCUtil h PLCC_Crce16Checksum T_WORD PLCC _Crcl6Checksum T BYTE pFirstByte T_DWORD length T_ WORD currentCrcValue Description This function calculates a CRC16 checksum over the given area with the given starting value and length in bytes The currentCrcValue is normally 0 When checking a large memory range section by section you can use the previous section s CRC value as the initial value InParam pFirstByte Pointer to the first byte to include in the checksum InParam length Length of data in units of bytes to calculate the checksum InParam currentCrceValue The initial CRC value from the previous CRC calculation when creating CRC over multiple sections ReturnVal Returns the CRC16 checksum Errno This function sets Errno if pFirstByte is a null pointer See couErrno h for possible values GFK 2259E Chapter 3 Writing a C Application 3 103 Errno Functions Some functions provide status by setting a global errno variable To effectively examine the value of errno you should 1 Call PLCC_ClearErrno to make sure errno was not set by a previous function call 2 Call the desired function that can potentially set errno 3 Call PLCCGetErrno to get the current errno value Any non zero errno value indicates an error The errno definitions are described in cpuErrno h Targets Co
86. UN_TO_COMPLETION_MODE The time fields contain the time values in milliseconds OutParam pStatus Pointer to structure containing record of the read window values ReturnVal This function will return 1 if successful and 0 if unsuccessful Chapter 3 Writing a C Application 3 49 PLCC_change_controller_comm_window T_INT32 PLCC_change_controller_comm_window struct change_controller_comm_window_rec pChangeControllerCommWindowRec struct change controller comm_window_rec T_BYTE time T BYTE mode LIMITED MODE CONSTANT MODE RUN_TO COMPLETION MODE Description This function is the C interface to service request 3 Change Controller Communications Window State and Values Note The Series 90 70 documentation refers to the Controller Communications window as the Programmer Communications window This function will change the Controller communications window state and timer to the values specified in the structure The mode will be changed to one of the three states LIMITED_MODE CONSTANT_MODE or RUN_TO_COMPLETION_MODE depending on the value in the mode field InParam pChangeControllerCommWindowRec Pointer to structure containing change controller window record The time value should be from 1 to 255 milliseconds ReturnVal This function will return 1 if successful and 0 if unsuccessful 3 50 C Programmer s Toolkit for PACSystems User s Manual January 2012 GFK 2259E PLCC_change_backplane_comm_wi
87. WORD 16 bit unsigned type WORD T_DWORD 32 bit unsigned type DWORD T_INT8 8 bit signed type NA T_INT16 16 bit signed type INT Caution Using int in the C source results in a 32 signed type that does not properly match the programmer s INT type T_INT32 32 bit signed type DINT T_UINT8 8 bit unsigned type BYTE T_UINT16 16 bit unsigned type UINT T_UINT32 32 bit unsigned type DWORD T_UINT64 64 bit unsigned type NA T_REAL32 32 bit floating point type REAL This is equivalent to float T_REAL64 64 bit floating point type LREAL This is equivalent to double Table 3 2 Standard Basic Types Commonly Used For C Block Applications C Toolkit Variable Description Corresponding Notes Types Programmer Variable Type char 8 bit character NA Similar to a BYTE in programmer double 64 bit floating point LREAL If you include the header file PLCC9070 h or PLCC9030 h it equates Series 90 C Toolkit basic types and the corresponding PACSystems C Toolkit basic types This is shown in the following table GFK 2259E Chapter 3 Writing a C Application 3 5 3 6 Compiling Table 3 3 Relationship Between Series 90 and PACSystems Basic Types 90 30 90 70 Variable Corresponding PACSystems C Toolkit Variable Type type byte T_BYTE word T_WORD dword T_DWORD dint T_INT32 bflow T_BOOLEAN After developing a C Block as described in Developing a C Block on pag
88. WORD data 128 E struct comm_req_rec_extended struct comm_req_command_blk_rec_extended command_blk T_BYTE slot T_BYTE rack T_DWORD task_id T_INT32 PLCC_do_io struct do_io_rec x Do I O struct do_io_rec T_BYTE start_mem_type T_WORD start_mem_offset T_WORD length T_BYTE alt_mem_type T_WORD alt_mem_offset must be set to NULL_SEGSEL if not used C Programmer s Toolkit for PACSystems User s Manual January 2012 Series 90 PLC Library Compatibility Notes amp Issues Compatible with the 90 70 and 90 30 but not able to access full range of W memory Use PLCC_comm_req_extended to provide access to the full W address range Has the same functionality as PLCC_comm _req except that it can access the full address range of W memory Not supported by Series 90 PLCs Compatible with 90 70 and 90 30 libraries Errnos TLIB_ERRNO_DOIO_INVALID_1O_REF_ER TLIB_ERRNO_DOIO_INVALID_AUX_REF_ER GFK 2259E GFK 2259E Target Library General Functions Structures and Constants T_INT32 PLCC_do_io_ext struct do_io_ext_rec x struct do_io_ext_rec T_WORD start_mem_type T_DWORD start_mem_offset T_DWORD length Ignored if start_mem_type is PLC_VAR_MEM T_WORD alt_mem_type must be set to NULL_SEGSEL if not used T_DWORD alt_mem_offset E Series 90 PLC Library Compatibility Notes amp Issues Not supported by Series 90 Supported by PACSystems Release 3 5 or greater bee a
89. WORD mask T_DWORD address Description Read Modify Write a byte to a device on the bus InParam rack The rack number containing the module to access InParam slot The slot number containing the module to access InParam subSlot The sub slot number of the module to access InParam region The region number describing the location of the BUS memory This is set up in hardware configuration for the module OutParam pStatus Pointer to status variable see common definition above OutParam pOriginalValue Pointer to the value before the read modify write operation InParam op_type Specifies whether the mask is ANDed or ORed with the data BUS_OR or BUS_AND InParam mask Data mask InParam address Address of the data to be written ReturnVal 1 if successful 0 if unsuccessful 1 if not supported Chapter 3 Writing a C Application 3 43 Proc PLCC_BUS_RMW_word T_INT32 PLCC_BUS_RMW _word T WORD rack T_WORD slot T_WORD subSlot T_WORD region T_WORD pStatus T_WORD pOriginalValue T_WORD op type T_DWORD mask T_DWORD address Description Read Modify Write a word to a device on the bus InParam rack The rack number containing the module to access InParam slot The slot number containing the module to access InParam subSlot The sub slot number of the module to access InParam region The region number describing the location of the BUS memory This is set up in hardware configuration for the module OutPa
90. _DISABLED Requested port is disabled If value is 1 the port is disabled If value is 0 the port is enabled bit 3 PORTN_FUSE_BLOWN Requested port s fuse is blown for Port 2 or supply voltage is not within range for Port 1 If value is 1 the fuse is blown or voltage not within range If value is 0 the fuse or supply voltage is okay Note Because the ESCM is not supported on the PACSystems CPUs this function always returns a value of 0 OutParam pEscmStatusRec A pointer to an escm_status_rec ReturnVal 1 if successful 0 if unsuccessful or ESCM is not supported Chapter 3 Writing a C Application 3 71 PLCC_set_application_redundancy_mode Note CPU firmware version 5 00 or higher is required for this function extern T_INT32 PLCC_set_application_redundancy mode T_WORD mode Possible values for the redundancy mode define BACKUP_MODE 0 define ACTIVE _MODE 1 Description Note The PLCC_set_application_redundancy_mode function is recognized only in non HSB hot standby CPUs These CPUs have a CPE or CPU designation This function is intended for use in user developed redundancy applications In these systems the application logic coordinates between CPUs that act as redundant partners and determines which CPU is the active unit and which are backup units This function is not needed for HSB CRE CPUs because the redundancy firmware in those CPUs automatically adjusts the active back
91. _of_words_in_chksm_rec x Set Read Number of Words to Checksummed struct number_of_words_in_chksm_rec T_WORD read_set T_WORD word_count number of words checksummed E define READ_CHECKSUM_WORDS 0 define SET_CHECKSUM_WORDS 1 T_INT32 PLCC_tod_clock struct tod_clock_rec x Compatible with 90 70 and 90 30 libraries Some additional formats Change Read Time of Day Clock State and Values Pre bal Gli cos idveaslt aac define NUMERIC_DATA_FORMAT 0 define BCD_FORMAT 1 define UNPACKED_BCD_FORMAT 2 define PACKED_ASCII_FORMAT 3 define POSIX_FORMAT 4 define NUMERIC_DATA_FORMAT_4 DIG YR 0x80 define BCD_FORMAT_4 DIG_YR 0x81 define UNPACKED_BCD_FORMAT_4_DIG_YR 0x82 define PACKED_ASCII_FORMAT_4_DIG_YR 0x83 define SUNDAY define MONDAY define TUESDAY define WEDNESDAY 4 define THURSDAY 5 define FRIDAY define SATURDAY struct num_tod_rec T_WORD year T_WORD month T_WORD day_of_month T_WORD hours T_WORD minutes T_WORD seconds T_WORD day_of_week struct BCD_tod_rec T_BYTE year T_BYTE month T_BYTE day_of_month T_BYTE hours T_BYTE minutes T_BYTE seconds T_BYTE day_of_week T_BYTE null J struct BCD_tod_4_rec T_BYTE year_lo T_BYTE year_hi T_BYTE month T_BYTE day_of_month T_BYTE hours T_BYTE minutes T_BYTE seconds T_BYTE day_of_week E A 22 C Programmer s Toolkit for PACSystems User s Manual January 2012 GFK 2259E GFK 2259E Target Library Genera
92. a 16 bit signed number However PACSystems is a 32 bit system so the int basic type is a 32 bit signed number You will need to evaluate your programs to determine if this conversion causes any issues Here are some examples int myVar myVar RI 1 sets myVar to equal R1 as a 16 bit signed value When this is compiled and executed on a PACSystems PLC the least significant 16 bits will be set equal to R1 The most significant 16 bits will be set to 0 unless the number is negative in which case the most significant 16 bits will be set to Oxffff sign extended This case should not typically cause any problems because the cast is from a smaller to a higher number of bits However the reverse case may cause problems in some cases int myVar RI 1 myVar sets R1 with a 32 bit signed value In this case the least significant 16 bits of myVar will be written to R1 Thus if the value of myVar is outside the range of a signed 16 bit number 32767 to 32768 then the value in R1 will be a signed 16 bit truncated version of myVar For example if myVar is 32768 0x00008000 the value in R1 will be 32768 0x8000 enum Type Issues The enum basic type in the 90 70 and 90 30 represents a 16 bit signed number However PACSystems is a 32 bit system so the enum basic type is a 32 bit signed number You will need to evaluate your programs to determine if this conversion causes any issues 5 4 C Progra
93. able declared on the PLC InParam lt indices gt A variable number of indices must match numIndices indicating the element of the array for which diagnostics are to be read These should be T_INT32 type Errno If there is an error this function sets Errno to give specific information on what caused the error Applications that use Errno should first call PLCC_ClearErrno to ensure Errno was not already set by another function call Errno can be read using PLCC_GetErrno Errno values are provided in ctkPlcErrno h 3 114 C Programmer s Toolkit for PACSystems User s Manual January 2012 GFK 2259E Proc WritePicVar extern T_INT32 WritePlcVar PLC_VAR_REC pVarInfo void pWriteFrom Description This function writes a value to a PLC variable from the buffer provided by the caller This routine accounts for overrides and transitions when applicable InParam pVarInfo Pointer to a PLC_VAR_REC information record for the variable to be written InParam pWriteFrom Pointer to the memory location of the value s to be written to the PLC variable Note If pVarlnfo references an array the entire array will be written Notes For type BOOL the least significant bit at the byte pointed to by pWriteFrom will be written to the PLC variable m Foran array of type BOOL the bits will be copied starting at the least significant bit of the byte pointed to by pWriteFrom m For type BYTE an 8 bit value will be read from pWriteFrom F
94. ano_time_since_start_of_sweep_rec x Read Sweep Time in nanoseconds from the Beginning of Sweep struct nano_time_since_start_of_sweep_rec T_DWORD time_since_start_of_sweep T_INT32 PLCC_read_folder_name struct read_folder_name_rec x Change in number of characters in name to 32 including the NULL Read Folder Name terminator struct read_folder_name_rec char folder_name 32 NULL terminated A 24 C Programmer s Toolkit for PACSystems User s Manual January 2012 GFK 2259E Target Library General Functions Structures and Constants Series 90 PLC Library Compatibility Notes amp Issues T_INT32 PLCC_read_PLC_ID struct read_PLC_ID_rec x Compatible with 90 70 and 90 30 Read PLC ID struct read_PLC_ID_rec char PLC_ID 8 NULL terminated i T_INT32 PLCC_read_PLC_state struct read_PLC_state_rec x Compatible with 90 70 and 90 30 Read PLC Run State define RUN_DISABLED 1 define RUN_ENABLED 2 struct read_PLC_state_rec T_WORD state T_INT32 PLCC_shut_down_plc T_WORD numberOfSweeps Compatible with the 90 70 and 90 30 except the function takes an Shut Down PLC input parameter number of sweeps that indicates the number of full sweeps to execute after the function is called T_INT32 PLCC_mask_IO_interrupts struct mask_lO_interrupts_rec x Compatible with 90 70 and 90 30 Mask Unmask I O Interrupt struct mask_IO_interrupts_rec T_WORD mask MASK or UNM
95. ansition bits Reference memory in the specified T_INT16 writeValue Reference Table RefTable and at the specified offset is written with the writeValue as a 16 bit signed integer If the offset is out of range no reference memory values are changed and the function returns GEF_ERROR If the offset is within range the function returns GEF_OK Note this function will only affect the transition bits that actually change Errnos TLIB_ERRNO_OFFSET_RANGE_ER TLIB_ERRNO_READ_ONLY_ER TLIB_ERRNO_INVALID_REF_TABLE_ER GFK 2259E Appendix A Target Library Functions A 5 Target Library Reference Memory Series 90 PLC Library Compatibility Functions amp Macros Notes amp Issues T_INT16 ReadPlcint T_WORD RefTable Reference memory in the specified Reference Table RefTable T_DWORD offset and at the specified offset is read as a 16 bit signed integer and returned by the function Errno is set if there is an error reading the value Errnos TLIB_ERRNO_OFFSET_RANGE_ER TLIB_ERRNO_INVALID_REF_TABLE_ER Qi address Similar issues as Ib Mi address G S D E OC CNSC C O CC C not SUppOe CCSCSC S S S S S Cot supported SSOSCSC S IG not Supported CCSCSCSC SC S S S S S IE not supported OSSSCSCSC S S s S S Similar issues as lb This is read only and the compiler will i
96. ated with reference memory can also be referenced In addition the special system S contacts FST_SCN LST_SCN T_10MS T_100MS T SEC T_MIN ALW_ON ALW OFF SY_FULL and 10 FULL are supported for C blocks The FST_EXE macro is supported This is high 1 the first time a block is executed C Blocks and Parameterized Blocks inherit FST_EXE from the calling block Interrupt blocks C LD FBD or ST inherit FST_EXE from the _MAIN block The following macros are available for a PACSystems folder Transition and Alarm Macros Macros for accessing the l Q M T G S and SA SC transition bits Note A transition bit is set high 1 if consecutive writes to a reference bit results in the bit transitioning form a 0 to 1 or 1 to 0 The bit is cleared 0 if consecutive writes to a reference bit result in the bit staying at the same state 0 to 0 1 to 1 for example BIT_TST_ _TRANS x BIT_TST_Q_TRANS x BIT_TST_M_TRANS x BIT_TST_T_TRANS x BIT_TST_G TRANS x BIT_TST_S_TRANS x BIT_TST_SA_TRANS x BIT_TST_SB_TRANS x BIT_TST_SC_TRANS x Macros for accessing the l Q M T G S and SA SC transition bits as bytes IB_TRANS x QB_TRANS x MB_TRANS x TB_TRANS x GB_TRANS x SB_TRANS x SAB_TRANS x SBB_TRANS x SCB_TRANS x GFK 2259E Chapter 3 Writing a C Application 3 25 Macros for accessing the l Q Al AQ Diagnostic memory Definitions used with macros that access Analog Input
97. ault tables in extended format ReturnVal 1 if successful 0 if unsuccessful 1 if not supported 3 78 C Programmer s Toolkit for PACSystems User s Manual January 2012 GFK 2259E Module Communications PLCC_comm_req GFK 2259E T_INT32 PLCC_comm_req struct comm_req rec pCommReqRec struct status addr T_WORD seg selector T_WORD offset struct comm_req_command_blk rec T_WORD length T_WORD wait struct status_addr status T_WORD idle_timeout T_WORD max _ comm _ time T_WORD data 128 struct comm_req rec struct comm_req_command_blk_rec command_blk T_BYTE slot T_BYTE rack T_DWORD task_id T BYTE ft ft is set if the commreq fails Description This function is based on the comm_ReEQ ladder logic block InParam pCommReqRec A pointer to communications request record ReturnVal The function returns 1 if successful and 0 if unsuccessful Chapter 3 Writing a C Application 3 79 Ladder Function Blocks 3 80 PLCC_do_io T_INT PLCC_do_io struct do_io_rec pDoIoRec struct do io rec T_BYTE start_mem_type T_WORD start _mem_ offset T_WORD length T BYTE alt_mem type must be set to NULL_SEGSEL if not used T_WORD alt_mem offset hi define NULL_SEGSEL OxFF Only valid for alt _mem_type Valid memory types define I_MEM 16 define Q MEM 18 define R_MEM 8 define AI_MEM 10 define AQ MEM 12 define W_MEM 196 Description This function is used to update
98. bility Notes amp Issues Similar issues as Ib imilar issues as b sini Similar issues as lb This is read only and the compiler will issue an error if you attempt to write to this memory using this macro Similar issues as Ib Similar issues as Ib Similar issues as Ib Macros compatible with 90 70 and 90 30 Macros compatible with 90 70 New Macro to support W memory Not supported by Series 90 Implemented as macro compatible with 90 70 and 90 30 syntax with the exception that the name has been changed from IW to Iw However this macro does not respect overrides and does not set corresponding transition bits so the functionality is different than the 90 70 and 90 30 You should use the WritePlcWord function to get the same functionality as the 90 70 and 90 30 see next item This function writes to reference memory taking into account overrides and transition bits A word 16 unsigned bits of reference memory in the specified Reference Table RefTable and at the specified offset is written with the writeValue If the offset is out of range no reference memory values are changed and the function returns GEF_ERROR If the offset is within range the function returns GEF_OK Note this function will only affect the transition bits that actually change Errnos TLIB_ERRNO_OFFSET_RANGE_ER TLIB_ERRNO_READ_ONLY_ER TLIB_ERRNO_INVALID_REF_TABLE_ER A word 16 unsigned bits o
99. block user not setting all required parameters Check parameter pointers for NULL before using 3 130 C Programmer s Toolkit for PACSystems User s Manual January 2012 GFK 2259E PLC Local Registers P and L GFK 2259E C Blocks have access to P and L PLC reference memory through several macros or functions provided in the file PACRxP1c h in the C Toolkit When referencing P and L from a block the following two reference memories appear as two separate tables int GefMain no parameters to GefMain PW 1 RW 1 Copy R1 to P1 LW 1 RW 2 Copy R2 to L1 return GEF_EXECUTION_OK The PLC memory location used as L or P is determined by the PACSystems at runtime based on the context from which the block was called If the block is called from the Marn ladder logic block then all L references inside the block will reference the P table The P table and the L table are the same when a block is called from the main block If however the same block is called from a ladder logic program block other than MAIN the P and L tables will be separate and unique in PLC memory When the P and L tables are separate all references to L will affect only the calling block s L table and all references to P will affect only the main program block s P table When called from the marn ladder logic block the following block will set P1 equal to R1 and then set L1 equal to R2 GefMain
100. cified type The read at the offset must be byte aligned that is ref_num must be set to a value from the following series 1 9 17 33 The length is in bytes The area pointed to by data must be large enough to hold the amount being read InParam seg_sel Indicates the segment selector of the table to get the override values For example use l segment selector to access the override table associated with l InParam ref_num Indicates which reference number to start reading from the override table The address should be byte aligned for discrete memory 1 9 17 etc C Programmer s Toolkit for PACSystems User s Manual January 2012 GFK 2259E InParam len Indicates the number of bytes to read from the override table starting from ref_num OutParam data Pointer to memory location to put the requested override data ReturnVal This function returns 0 if successful 2 bad_memory_type 3 offset_not_byte_aligned 4 reading_outside_ref_mem 5 bad_data_pointer GFK 2259E Chapter 3 Writing a C Application 3 85 3 86 Reference Memory Functions The functions in this section are used to access PLC reference memory These functions properly take into account transitions and overrides In addition they PLC_VAR_MEM perform memory range checking These functions are described in ctkRefMem h When specifying the Ref Table input parameter use the following values R_MEM Al_MEM AQ_MEM W_MEM MEM Q_ME
101. ck 3 Block 4 Figure 3 7 Interrupt Block Calls and C Blocks FBKs In the example shown in Figure 3 7 two separate execution paths are depicted normal execution and interrupt execution Normal execution is initiated through the standard sweep mechanism of the operating system calling the _MAIN block Then through a series of calls to sub blocks the example eventually calls some C block Interrupt execution is initiated by either a timed event or by an interrupt event interrupt input coming into the CPU causing the operating system to invoke a block Note that calling a C block terminates the call chain The example in Figure 3 7 shows that both the Normal Execution path AND the Interrupt Execution path calling through a chain of different blocks the same C block For this example to work correctly the C Block must be designed for re entrant operation Chapter 3 Writing a C Application 3 135 A C Block developer should use the following guidelines to ensure the success of a situation such as the one illustrated in Figure 3 7 1 All variables used by the C Block should be stack based automatic variables 2 If there is any portion of the Block that operates on PLC global memories R P etc the Block must contain additional code to handle some sort of hand shaking between normal executions and interrupt executions to prevent data incoherency The hand shaking could be accomplished by declaring a global
102. contains the compiled relocate able code that is used by the PLC to load the C Block into user memory See section Restricting Compilation To a Specific Target if you want your C Block to always be compiled for a specific target C Programmer s Toolkit for PACSystems User s Manual January 2012 GFK 2259E Compiling Multiple C Files If you want to have multiple C files compiled and linked together you need to create a file called sources and include a line that specifies the files to compile This line must start with the word CFILENAMES all capitals no spaces followed by the filenames there can be multiple spaces or tabs between CFILENAMES and the first file and multiple spaces or tabs between each filename An example of this line is shown below CFILENAMES myCFilel c myCFile2 c myCFile3 c If the list of files is long a continuation symbol P may be added to improve readability in the file as shown below CFILENAMES myCFilel c myCFile2 c myCFile3 c The sources file must be in the same project directory as the other C source files when compiling To compile multiple C files into a C Block that can be run on any PACSystems RX PLC use the command compileCPACRX To compile multiple C files into a C Block that uses functionality that is available only on an RX3i use the command compileCPACRX3i To compile multiple C files into a C Block that uses functionality that is available
103. controller_ This Change Controller Communications Window State and Values makes the names consistent with the PACSystems terminology input structure struct change_controller_comm_window_rec T_BYTE time T_BYTE mode LIMITED_MODE CONSTANT_MODE RUN_TO_COMPLETION_MODE k window modes define LIMITED_MODE define CONSTANT_MODE 1 define RUN_TO_COMPLETION_MODE 2 T_INT32 PLCC_change_backplane_comm_window struct Compatible with the 90 70 and 90 30 except that function and change_backplane_comm_window_rec x structure names containing system_ now use the backplane_ Change Backplane Communications Window State and Values This makes the names consistent with the PACSystems terminology struct change_system_comm_window_rec T_BYTE time T_BYTE mode LIMITED_MODE CONSTANT_MODE RUN_TO_COMPLETION_MODE T_INT32 PLCC_change_background_window struct Compatible with 90 70 and 90 30 libraries change_background_window_rec x Change Background Window State and Values struct change_background_window_rec T_BYTE time T_BYTE mode LIMITED_MODE CONSTANT_MODE RUN_TO_COMPLETION_MODE af GFK 2259E Appendix A Target Library Functions A 21 Target Library General Functions Structures and Constants Series 90 PLC Library Compatibility Notes amp Issues T_INT32 PLCC_number_of_words_in_chksm struct Compatible with 90 70 and 90 30 libraries number
104. ction ensures overrides and transitions are taken into account for bit memory InParam RefTable Reference table segment selector used to indicate which table to access InParam offset Offset to use to clear the bit This is 1 based For example use 1 to access 100001 InParam bitNumber For word type memories this determines which bit to set For bit type memories this input is ignored This is 1 based with a range of 1 to 16 For example use 1 to set the least significant bit in a word memory ReturnVal The function returns GEF_OK if the offset is within range or GEF_ERROR if the offset is out of range In the GEF_ERROR case the specified bit is not changed Errno If there is an error this function sets Errno to give specific information on what caused the error Applications that use Errno should first call PLCC_ClearErrno to ensure Errno was not already set by another function call Errno can be read using PLCC_GetErrno Errno values are located in ctkPlcErrno h Chapter 3 Writing a C Application 3 97 3 98 clearBit rackX T_INT32 clearBit T_WORD RefTable T_DWORD offset T_WORD bitNumber Description This function clears the specified bit in reference memory This function ensures overrides and transitions are taken into account for bit memory InParam RefTable Reference table segment selector used to indicate which table to access InParam offset Offset to use to clear the bit This is 1 based For
105. d you must associate the gefElf file with a C Block in your PLC program using the programmer The C Block must have the same number of parameters as the GefMain function s input parameter signature as illustrated in Figure 3 1 However there is not a check to determine if the signatures match In cases where the signatures do not match the C Block may not behave correctly Adding Blocks through the Machine Edition Programmer Before importing the block into Machine Edition the C application source file must be compiled and linked to create the relocate able version of the C application gefElf Once the relocate able version of a C application source file is created the file needs to be added to a target within your CME project as follows 1 Inthe Project tab expand the Logic node 2 Right click the Program Block node under the Logic node 3 Select Add C Block This brings up a file navigation dialog box 4 Navigate to the gefElf file and click the Open button to add the C Block to the folder GFK 2259E Chapter 3 Writing a C Application 3 9 Specifying Parameters To specify the parameters for a C Block with one or more input output parameters click on the C Block In the properties page for the C Block click the Parameters item and then click on the button provided This opens the Parameters dialog box containing two tabs one for inputs and one for outputs For each input output provide m Name m Type BOOL BYT
106. d Constants Implemented in ctkPIcFault h Target Library Fault Table Functions Series 90 PLC Library Compatibility Notes amp Issues Structures and Constants T_INT32 PLCC_read_fault_tables struct read_fault_tables_rec x Compatible with the Series 90 library with the exception that the union This service request will read the entire PLC or I O fault table must be named as required by the GNU C compiler Therefore to get access to a particular fault the following syntax must be used fine PLC_FAULT_TABLE 0 ane C_FAULT_ myFaultRec faultEntry PLC_faults 0 define O_FAULT_TABLE 1 define NUM_LEGACY_PLC_FAULT_ENTRIES 16 define NUM_LEGACY_IO_FAULT_ENTRIES 32 struct time_stamp_rec T_BYTE second BCD format seconds in low order nibble tens of seconds in high order nibble T_BYTE minute BCD format same as for seconds T_BYTE hour BCD format same as for seconds T_BYTE day BCD format same as for seconds gi T_BYTE month BCD format same as for seconds 3I T_BYTE year BCD format same as for seconds i E struct PLC_flt_address_rec T_BYTE rack T_BYTE slot T_WORD task E struct IO_flt_address_rec T_BYTE rack T_BYTE slot T_BYTE IO_bus T_BYTE block T_WORD point GFK 2259E Appendix A Target Library Functions A 11 Target Library Fault Table Functions Structures and Constants struct reference_address_rec T_BYTE memory_type T_WORD offset E struct
107. de File Supported C Run Time Library Series 90 C Run Time Library Functions Associated with File Compatibility Notes Issues Errno information and return value exceptions include lt time h gt Time asctime is not supported since it is not re int asctime_r entrant const struct tm timeptr Description char asctimeBuf This routine converts the broken down time pointed to by timeptr into a string of size_t buflen the form SUN SEP 16 01 03 52 1973 n 0 The string is copied to asctimeBuf This function returns the size of the created string This function does not return errno Note NULL or invalid input pointers to this function will put the CPU into CPU Halted mode include lt time h gt double difftime time_t_time2 time_t This function does not set errno _time1 NA _ strdate Copy a date to a buffer is not supported supported include lt ctype h gt Character Classification and isalnum include lt ctype h gt int isalpha int c TS include lt ctype h gt int iscntrl int c include lt ctype h gt int isdigit int c include lt ctype h gt int isgraph int c i include lt ctype h gt int isspace int c include lt ctype h gt int isupper int c include lt ctype h gt int islower int c include lt ctype h gt int isxdigit int c a COSS sigitint Se soraph int c ot slower Eoo roudezoypehs misim OSS FHinclude lt cype h gt irtisano OoOO suppertint ee i sxc
108. der the following ladder logic rung and sample block where the value in P1 is to be used as an index into R memory and the value at R P1 is to be copied to P2 100004 PoOoOoO1 GFK 2259E Chapter 3 Writing a C Application 3 123 Range Checking Indirect References Using the SIZE Macros The value at x1 will be used as an index into register memory The value at R x1 will be copied to yl E int GefMain T_WORD x1 T_INT16 y1 FIRST check X1 amp Y1 NULL SECOND must range check value at x1 to ensure A that we will stay within limits of PIC SR reference memory xf if x1 NULL amp amp yl NULL if xl gt R_SIZE return ERROR Range check proved OK gt go ahead and copy data yl RW x1 return GEF EXECUTION OK else return GEF EXECUTION ERROR In the above example the index x1 is compared to R_SIZE If the target PLC contains 1024 registers then R_SIZE will evaluate to 1024 If x1 is greater than 1024 R_SIZE the program will return with the status GEF_EXECUTION_ERROR which indicates that the ENO output of the CALL function block should be turned OFF With x1 greater than R_SIZE the C block will return with GEF_EXECUTION_ ERROR status and no attempt is made to index into register memory nor to copy any register memory value to y1 Global Variable Initialization Global variables can b
109. dow_ values 3 49 PLCC_reset_watchdog_timer 3 61 PLCC_scan_set_io 3 83 PLCC_set_run_enable 3 67 PLCC_shut_down_plc 3 64 PLCC_SNP_ID 3 84 PLCC_sus_io 3 82 GFK 2259E GFK 2259E PLCC_sus_res_ HSC_interrupts 3 69 PLCC_sus_res_interrupts_ext 3 70 A 26 PLCC_time_since_start_of_sweep 3 61 PLCC_tod_clock 3 54 PlcMemCopy 3 96 PlcVarArrayBound 3 122 PlcVarArrayElementSiz 3 122 PlcVarHasDiags 3 121 PlcVarHasTransitions 3 121 PlcVarMemCopy 3 117 PlcVarNumDimensions 3 120 PlcVarSizeof 3 118 PlcVarSizeofDiag 3 119 PlcVarSizeofOvr 3 119 PlcVarSizeofTrans 3 120 PlcVarType 3 118 Pointers to discrete memory tables input parameters 5 5 Proc ReadPlcVar 3 107 R rackX 3 98 ReadPlcArrayVarElement 3 108 ReadPlcArrayVarElementDiag 3 110 ReadPlcArrayVarElementOvr 3 112 ReadPlcArrayVarElementTrans 3 114 ReadPlcByte 3 88 ReadPlcDint 3 93 ReadPlcDouble 3 95 ReadPIclInt 3 91 ReadPlcVarDiag 3 109 ReadPlcVarOvr 3 111 ReadPlcVarTrans 3 113 ReadPlcWord 3 90 Reference access macros 3 18 formatting 3 19 Reference memory functions 3 86 Reference memory functions and macros A 1 Reference Memory Size macros 3 24 Reference Table Monitoring 4 4 Reference types 3 19 refMemSize 3 97 Related information 1 1 Reserved names 3 2 Retentive data for C blocks 3 125 Retentive variables compatibility 5 4 rsmb 3 101 Running C Toolkit 2 3 Runtime errors PLC support 3 134 Run time functions B 1
110. dy set by another function call Errno can be read using PLCC_GetErrno Errno values are provided in ctkPlcErrno h C Programmer s Toolkit for PACSystems User s Manual January 2012 GFK 2259E GFK 2259E Proc ReadPlicVarDiag extern T_INT32 ReadPlcVarDiag PLC_VAR_REC pVarInfo void pReadDiagsTo Description This function reads the diagnostic value s for a PLC variable into a buffer provided by the caller If the variable does not have diagnostics an error will be returned Variables of type STRING are invalid and will return an error InParam pVarInfo Pointer to a PLC_VAR_REC information record for the variable to be read InParam pReadDiagsTo Pointer to the memory location where the diagnostic values of the variable should be written Notes m f pVarlnfo references an array the diagnostics for the entire array will be read For type BOOL an entire byte will be written to pReadDiagsTo with the low bit of the byte containing the diagnostic value of the BOOL variable a Foran array of type BOOL the number of bytes written will be total number of elements 7 8 The first diagnostic bit will be written to the least significant byte of the first byte For type BYTE and BYTE arrays there will be one byte of diagnostic written for every byte element For all other types the number of bytes written will be the byte size of the PLC variable divided by 2 if the variable is in non discrete memory For exampl
111. e an array of 8 words would have 8 bytes of diagnostic data If the variable is discrete memory the number of bytes written will be equal to the size of the array variable in bytes Errno If there is an error this function sets Errno to give specific information on what caused the error Applications that use Errno should first call PLCC_ClearErrno to ensure Errno was not already set by another function call Errno can be read using PLCC_GetErrno Errno values are provided in ctkPlcErrno h Bit Masks to be Used with Diagnostics These bit masks are defined in ctkRefMem h For access to analog input diagnostic memory HI_ALARM_MSK 0x02 LO_ALARM_MSK 0x01 Al_OVERRANGE_MSK 0x08 AI_UNDERRANGE_MSK 0x04 For access to analog output diagnostic memory AQ_OVERRANGE_MSK 0x40 AQ_UNDERRANGE_MSK 0x20 Chapter 3 Writing a C Application 3 109 3 110 Proc ReadPlicArrayVarElementDiag extern T_INT32 ReadPlcArrayVarElementDiag PLC_VAR_REC pVarInfo void pReadDiagsTo T_INT32 numIndices mee es Description This function reads the diagnostic values for a single element in a PLC array variable into a buffer provided by the caller InParam pVarinfo Pointer to a PLC_VAR_REC information record for the array containing the element whose diagnostics are to be read If the variable does not have diagnostics an error will be returned Arrays of STRINGs are invalid and will return an error InParam pRead
112. e 3 3 the C Block must be compiled to create a relocate able object file that can be stored into the PLC Compiling a Single C File To compile the C Block 1 Start the C Toolkit by double clicking on the PACSystems C Toolkit icon on your desktop double clicking on the ctkPACS bat file through Windows explorer or using the Start gt Programs menu 2 Inthe C Toolkit DOS box navigate to the project directory containing the C block file 3 Type the appropriate compile command followed by your file name To compile a C Block that can be run on any PACSystems RX PLC use the command compileCPACRxX lt file name gt To compile a C Block that uses functionality that is available only on an RX3i use the command compileCPACRX3i lt file name gt To compile a C Block that uses functionality that is available only on an RX7i use the command compileCPACRX7i lt file name gt For example to run the RX7i compiler for a C file called myCFile type compileCPACRX7i myCFile If there are errors or warnings they are noted on the screen If the compile is successful no errors an output file is produced with the same base name as the input file and the extension gefElf The file is placed in a subdirectory under your project directory called plc so that it is clear which file is intended for downloading to the PLC For the myCFile example the following file is produced myCFile gefE1f myCFile gefElf
113. e Errno should first call PLCC_ClearErrno to ensure Errno was not already set by another function call Errno can be read using PLCC_GetErrno Errno values are located in ctkPlcErrno h 3 92 C Programmer s Toolkit for PACSystems User s Manual January 2012 GFK 2259E ReadPlcDint GFK 2259E T_INT32 ReadPlcDint T_WORD RefTable T_DWORD offset Description Reference memory in the specified Reference Table RefTable and at the specified offset is read as a 32 bit signed integer and returned by the function Errno is set if there is an error reading the value InParam RefTable Reference table to read InParam offset Offset within the reference table to read Note The offset is 1 based For example Reffable R_MEM and offset 1 accesses R00001 ReturnVal The value read from the specified reference table at the specified offset Errno If there is an error this function sets Errno to give specific information on what caused the error Applications that use Errno should first call PLCC_ClearErrno to ensure Errno was not already set by another function call Errno can be read using PLCC_GetErrno Errno values are located in ctkPlcErrno h Chapter 3 Writing a C Application 3 93 WritePIcDouble T_INT32 WritePlcDouble T_WORD RefTable T_DWORD offset T_REAL64 writeValue Description This function writes to reference memory taking into account overrides and transition bits Reference memory in the specified Refer
114. e Programs ccccccccceeeececeeeeeceeeeeeeaeeeeeeeseeeeecaeeecaaeseeaaeseeeeeseaeeesaeeeeaeeeeeeees 5 5 Use of Input Parameters as Pointers to Discrete Memory Tables cccseeseeeeeees 5 5 Installed Sample Blocks siccc4isen tei hest tte irene ee Gente 6 1 Sample Rroji uiine Wee a ae A ee ne L A ea 6 1 AY Tn 0 a Ro EREE EO AEREE ET E etree err errr ee crecee O ET 6 2 GFK 2259E Contents vi Target Library FUN CUOMS iicc ticciiiaiiasistcaticinaeseccsntaeeiiantantan di aineniediaeeecuetiaaienaeeld A 1 Target Library Reference Memory Functions and Macros cccccccccesssseeesssseeeeseeeeees A 1 Target Library Fault Table Functions Structures and Constants scccssseeeeeees A 11 Target Library General Functions Structures and Constant c ccccesseeeessteeeeeeeees A 17 Target Library VME Functions Structures and Constant ccccssccssssseeesssteeeeeeees A 27 Target Library Error Functions Structures and Constant cccecsccessesseeesseseeeeseeees A 28 Target Library Utility Functions Structures and Constants aaa aaae a T aaaea A 28 C Run Time Library Functions nisi iscctscec cesses cc ccensds cece cetacstinc cheese dee eeeteneeec B 1 DIGQIMOSEIGS E E icdusverenucacedcaaivanssdudavsuuueseriasaseudesdaguauustsuadasacaueltasdutinyscsnaiuenetennerectd C 1 C Programmer s Toolkit for PACSystems User s Manual January 2012 GFK 2259E Chapter GFK 2259E Introductio
115. e byte is read from the most significant byte msbByte TRUE or to the least significant byte msbByte FALSE ReturnVal The value read from the specified reference table at the specified offset Errno If there is an error this function sets Errno to give specific information on what caused the error Applications that use Errno should first call PLCC_ClearErrno to ensure Errno was not already set by another function call Errno can be read using PLCC_GetErrno Errno values are located in ctkPlcErrno h 3 88 C Programmer s Toolkit for PACSystems User s Manual January 2012 GFK 2259E WritePlcWord GFK 2259E T_INT32 WritePlcWord T_ WORD RefTable T_DWORD offset T WORD writeValue Description This function writes to reference memory taking into account overrides and transition bits A word 16 unsigned bits of reference memory in the specified Reference Table RefTable and at the specified offset is written with the writeValue InParam RefTable Reference table to write InParam offset Offset within the reference table to write Note the offset is 1 based For example Reffable R_MEM and offset 1 accesses R00001 InParam writeValue The value to write to the specified reference table and offset ReturnVal If the RefTable or offset are out of range no reference memory values are changed and the function returns GEF_ERROR If the offset is within range the function returns GEF_OK Errno
116. e used by C applications running in a PACSystems control system Global variables are those which are declared outside of a function typically outside of and before GefMain Both initialized and uninitialized global variables may be used T_INT32 XYZ uninitialized global var T_INT32 abc 123 initialized global var int GefMain xyz RW 1 RI 2 abc return GEF EXECUTION Ok When a C application is compiled and linked to form relocate able gefE1 file all global variables have a relative location within the gefE1 image If the global variable is declared in the C source to have an initial value the location in the gefElf image for that global variable will contain the initialized value When a C application is incorporated into a Machine Edition folder and that folder is stored to a PACSystems CPU the CPU stores an image of the gefE1f file into user memory with space pre allocated for all global variables and with all initialized global variables 3 124 C Programmer s Toolkit for PACSystems User s Manual January 2012 GFK 2259E Static Variables already containing their predefined values Upon storing the gefE1f image the PLC will make a copy of the data portion data portion initialized global variables Once the PLC is placed into RuN mode the C application may operate upon any of its global variables Each of the C application s global variables will retain it
117. egion number describing the location of the BUS memory This is set up in hardware configuration for the module OutParam pStatus Pointer to status variable see common definition above OutParam pBuffer Pointer to the byte read in from a device on the bus InParam address Address of the byte to be read ReturnVal 1 if successful 0 if unsuccessful 1 if not supported GFK 2259E Chapter 3 Writing a C Application 3 35 Proc PLCC_BUS_read_word T_INT32 PLCC_BUS_read_word T WORD rack T_WORD slot T_WORD subSlot T_WORD region T_WORD pStatus T_WORD pBuffer T_DWORD address Description Read a word from a device on the bus InParam rack The rack number containing the module to access InParam slot The slot number containing the module to access InParam subSlot The sub slot number of the module to access InParam region The region number describing the location of the BUS memory This is set up in hardware configuration for the module OutParam pStatus Pointer to status variable see common definition above OutParam pBuffer Pointer to the word read in from a device on the bus InParam address Address of the word to be read ReturnVal 1 if successful 0 if unsuccessful 1 if not supported 3 36 C Programmer s Toolkit for PACSystems User s Manual January 2012 GFK 2259E Proc PLCC_BUS_read_dword T_INT32 PLCC_BUS_read_dword T_ WORD rack T_WORD slot T_WORD subSlot T_WORD region T_WORD pStat
118. ence Table RefTable and at the specified offset is written with the writeValue as a 64 bit floating point value InParam RefTable Reference table to write InParam offset Offset within the reference table to write Note The offset is 1 based For example Reffable R_MEM and offset 1 accesses R00001 InParam writeValue The value to write to the specified reference table and offset ReturnVal If the RefTable or offset are out of range no reference memory values are changed and the function returns GEF_ERROR If the offset is within range the function returns GEF_OK Errno If there is an error this function sets Errno to give specific information on what caused the error Applications that use Errno should first call PLCC_ClearErrno to ensure Errno was not already set by another function call Errno can be read using PLCC_GetErrno Errno values are located in ctkPlcErrno h 3 94 C Programmer s Toolkit for PACSystems User s Manual January 2012 GFK 2259E ReadPlicDouble GFK 2259E T_REAL64 ReadPlcDouble T_WORD RefTable T WORD offset Description Reference memory in the specified Reference Table RefTable and at the specified offset is read as a 64 bit floating point value and returned by the function Errno is set if there is an error reading the value InParam RefTable Reference table to read InParam offset Offset within the reference table to read Note The offse
119. ented in ctkPlcErrno h Target Library Error Functions Structures and Constants Series 90 PLC Library Compatibility Notes amp Issues void PLCC_ClearErrno void This is a new function It clears the errno in the current context As a general rule this function should be called just before calling a function whose status will be checked by using PLCC_GetErrno If this is not done the Errno value could be the result of previous function call This is a new function It returns the errno in the current context errno contains the error code set by the last Target Library or C Run Time Library function to declare an error int PLCC_GetErrno void Target Library Utility Functions Structures and Constants Implemented in ctkPIcUtil h Target Library Utility Functions Structures and Constants T_WORD PLCC_Crc16Checksum T_BYTE pFirstByte This is a new function It calculates a CRC16 checksum over T_DWORD length the given area with the given starting value and length in E bytes The currentCrcValue is normally 0 When checking a T_WORD currentCrcValue y l y ing large memory range section by section one can use the previous section s CRC value as the initial value Errnos TLIB_ERRNO_UTIL_NULL_POINTER A 28 C Programmer s Toolkit for PACSystems User s Manual January 2012 GFK 2259E Appendix B Include File include lt stdio h gt include lt stdio h gt include lt stdio h gt GFK 2259E C Run T
120. es for the action element define MASK 1 define UNMASK 0 Valid memory type define PLCVAR MEM 262 for use with Variables define IBIT 70 define AIMEM10 All offsets are 1 based l1 1 l2 2 Al1 1 AI2 2 Discrete offsets and lengths are in bits and must be byte aligned 1 9 17 25 are valid for offsets 2 8 10 16 18 24 are invalid for offsets Analog offsets and lengths must be in words Description This function is based on the MASK_IO_INTR function block It is used to mask or unmask an interrupt from an I O board When the interrupt is masked the CPU processes the interrupt but does not schedule the associated logic for execution When the interrupt is unmasked the CPU processes the interrupt and schedules the associated logic for execution When the CPU transitions from Stop to Run the interrupt is unmasked This function provides PLC variable access along with reference addresses having 32 bit offset as input Memory type and offset specify the address of an input interrupt trigger on an input module that supports interrupts To specify an IO variable as an input to a routine use the PLC_VAR_MEM memory type and the address of the variable record as the offset For details on the use of PLC_VAR_MEM see page 3 86 InParam pMaskloInterruptsExtRec Pointer to structure containing mask I O interrupt information ReturnVal 1 if successful 0 if unsuccessful 1 if not supported
121. essful 1 if not supported GFK 2259E Chapter 3 Writing a C Application 3 45 Proc PLCC_BUS_TST_byte T_INT32 PLCC_BUS_TST_byte T WORD rack T_WORD slot T_WORD subSlot T_WORD region T WORD pStatus T_BYTE pSemaphoreOutput T_DWORD address Description This function reads a byte sized semaphore from the bus address and tests the least significant bit The semaphore output will be 0 is the semaphore is not obtained 1 if it is obtained You must release this semaphore when it is no longer needed To release a semaphore write 0 to the semaphore InParam rack The rack number containing the module to access InParam slot The slot number containing the module to access InParam subSlot The sub slot number of the module to access InParam region The region number describing the location of the BUS memory This is set up in hardware configuration for the module OutParam pStatus Pointer to status variable see common definition above OutParam semaphore_output Results of locking semaphore 0 not obtained 1 obtained InParam address Address of the data to be written ReturnVal 1 if successful 0 if unsuccessful 1 if not supported 3 46 C Programmer s Toolkit for PACSystems User s Manual January 2012 GFK 2259E Proc PLCC_BUS_TST_word T_INT32 PLCC_BUS_TST_word T WORD rack T_WORD slot T_WORD subSlot T_WORD region T_WORD pStatus T_WORD pSemaphoreOutput T_DWORD address Description This
122. eturn value exceptions fstrcat _fstrchr _fstremp _ fstrcpy _fstrcspn _fstrlen _fstrncat _ fstrncmp _fstrncpy _fstrpbrk _ fstrrchr _fstrspn _fstrstr These functions are far pointer versions of functions without the _f prefix Since far pointer versions are not needed for a 32 bit architecture PLCC9070 h equates these functions to the primary functions with the following type of statement define _fstrcat strcat These functions are far pointer versions of functions without the _f prefix Since far pointer versions are not needed for a 32 bit architecture PLCC9030 h equates these functions to the primary functions with the following type of statement define _fstrcat strcat _fstricmp _fstrlwr _fstrnicmp _fstrnset fstrrev _fstrset _fstrtok _fstrupr These functions are not supported include lt string h gt Buffer Manipulation ee _memccpy Copies characters from a buffer is not supported include lt string h gt include lt string h gt include lt string h gt as ee const void include lt string h gt include lt string h gt GFK 2259E void memchr const void size_t int memcmp const void const void size_t void memcpy void const void size_t void memmove void size_t void memset void int size_t Appendix B C Run Time Library Functions This function does not set errno Note NULL or in
123. f bytes written will be equal to the byte size of the PLC variable Errno If there is an error this function sets Errno to give specific information on what caused the error Applications that use Errno should first call PLCC_ClearErrno to ensure Errno was not already set by another function call Errno can be read using PLCC_GetErrno Errno values are located in ctkPlcErrno h Chapter 3 Writing a C Application 3 113 Proc ReadPlicArrayVarElementTrans extern T_INT32 ReadPlcArrayVarElementTrans PLC _VAR_REC pVarInfo void pReadTransTo T_INT32 numIndices T Description This function reads the transition value s for a single element in a PLC array variable into a buffer provided by the caller InParam pVarlnfo Pointer to a PLC_VAR_REC information record for the array containing the element whose diagnostics are to be read If the variable does not have transitions an error will be returned InParam pReadTransTo Pointer to the memory location where the transition values are to be written Notes For type BOOL an entire byte will be written to pReadTransTo with the low bit of the byte containing the transition value for the BOOL variable m For all other types the number of bytes written will be equal to the byte size of an element in the PLC array variable InParam numindices Number of indices needed to locate an element of the array This must be greater than zero and must match the number of dimensions of the vari
124. f reference memory in the specified Reference Table RefTable and at the specified offset is read and returned by the function Errno is set if there is an error reading the value Errnos TLIB_ERRNO_OFFSET_RANGE_ER TLIB_ERRNO_INVALID_REF_TABLE_ER GFK 2259E Target Library Reference Memory Series 90 PLC Library Compatibility Functions amp Macros Notes amp Issues Qw address Similar issues as Ib Mw address Tw address Gw address w address Similar issues as lb This is read only and the compiler will issue an error if you attempt to write to this memory using this macro Aw address Similar issues as Ib BW address Similar issues as Ib Cw address Similar issues as Ib RW address Macro Compatible with 90 70 and 90 30 AlW address AQW address PW address Macro Compatible with 90 70 LW address WW address ot re to support W memory Not supported by eries 90 li address Implemented as macro compatible with 90 70 and 90 30 syntax with the exception that the name has been changed from II to li However this macro does not respect overrides and does not set corresponding transition bits so the functionality is different than the 90 70 and 90 30 You should use the WritePIcInt function to get the same functionality as the 90 70 and 90 30 see next item T_INT32 WritePicInt T_WORD RefTable This function writes to reference memory taking into account T_DWORD offset overrides and tr
125. flag variable in the Block or using an application reserved location in PLC global memory that the Block sets just prior to writing to the PLC global memories and then clears when the update is complete Execution of the block regardless of normal or interrupt should read the global flag before changing the PLC global memory If the flag is set the C Block should not change the PLC global memory 3 Use re entrant versions of functions Restricting Compilation to a Specific Target In most cases you will want to the use the PACRXPIc h header file and the corresponding command line compileCPACRx to compile a C Block for any PACSystems RX PLC If you want to compile your application for a specific target such as the RX7i or RX3i you can use the command line compileCPACRx7i or compileCPACRx3i respectively while still using the PACRXPIc h header file However if you always want to restrict compilation for a specific target on a particular C Block you should use the PACRX7iPlc h for the RX7i target or PACRX3iPlc h for the RX3i target By using these header files the C Block will successfully compile only for the specified target For example if you use the PACRX7iPlc h header file in your C Block source file you must use the compileCPACRX7i command line to successfully compile the C Block In this case if you attempt to use the compileCPACRX3i command line the compilation will fail Note As of Release 3
126. function reads the value of a single element in a PLC array variable into a buffer provided by the caller InParam pVarinfo Pointer to a PLC_VAR_REC information record for the array containing the element to be read InParam pReadTo Pointer to the memory location where the value of the variable to be read is located Notes For type BOOL an entire byte will be written to pReadTo with the low bit of the byte containing the value of the BOOL variable m For type BYTE an 8 bit value will be written to pReadTo regardless of whether the array is in discrete or non discrete memory on the PLC BYTEs mapped to non discrete memories such as R or W consume 16 bits on the PLC For type STRING the size in bytes of the data written to pReadTo will be the max length in the variables declaration on the PLC InParam numIndices Number of indices needed to locate an element of the array This must be greater than zero and must match the number of dimensions of the variable declared on the PLC InParam lt indices gt A variable number of indices must match numIndices indicating the element of the array to be read These should be T_INT32 type ReturnVal GEF_OK if successful GEF_ERROR for bad parameter Use Errno to determine cause Errno If there is an error this function sets Errno to give specific information on what caused the error Applications that use Errno should first call PLCC_ClearErrno to ensure Errno was not alrea
127. gitnt 6 rs 3 es include lt ctkGefCLib h gt int toascii int c include lt ctype h gt int tolower int c _tolower is not supported use tolower include lt ctype h gt int toupper int c _toupper is not supported use toupper GFK 2259E Appendix B C Run Time Library Functions B 11 Appendix Diagnostics C This section includes descriptions of some known problems and solutions to those problems Issue Compiler issues the following warning when the EnableAnsi flag is used myCBlock c 240 warning implicit declaration of function infinity myCBlock c 263 warning implicit declaration of function acosf myCBlock c 264 warning implicit declaration of function asinf myCBlock c 265 warning implicit declaration of function atanf myCBlock c 266 warning implicit declaration of function ceilf myCBlock c 267 warning implicit declaration of function cosf myCBlock c 268 warning implicit declaration of function coshf myCBlock c 269 warning implicit declaration of function expf myCBlock c 270 warning implicit declaration of function fabsf myCBlock c 271 warning implicit declaration of function floorf myCBlock c 272 warning implicit declaration of function fmodf myCBlock c 273 warning implicit declaration of function logf myCBlock c 274 warning implicit declaration of function log10f myCBlock c 275 warning implicit declaration of function powf myCBlock c 276 warning implicit declarati
128. gned 1 9 17 25 are valid for offsets 2 8 10 16 18 24 are invalid for offsets Analog offsets and lengths must be in words InParam pSusResinterruptsExtRec A pointer to Suspend Resume Interrupts Extn record C Programmer s Toolkit for PACSystems User s Manual January 2012 GFK 2259E ReturnVal 1 if successful 0 if unsuccessful 1 if not supported Errno This function sets Errno if reference memory is out of range See cpuErrno h for possible values PLCC_get_escm_status GFK 2259E INT32 PLCC_get_escm_status struc escm_status_ rec pEscmStatusRec struc escm_status rec T_WORD port_number T_WORD port_status define port 1 1 define port 2 2 Description If the function return value is zero 0 the function was not successful usually indicating that the PLC does not support ESCM embedded serial communications module ports see Note below If the function return value is one 1 the function was successful This function also returns a status word for Ports 1 or 2 word port_status The bit values for that word are shown in the following table Port_Status for the PLCC_get_escm_status Function Port Status Meaning bit O PORTN_OK Requested port is ready If value is 1 the port is ready If value is 0 the port is not usable bit 1 PORTN_ACTIVE There is activity on this port If value is 1 the port is active If value is 0 the port is inactive bit 2 PORTN
129. he binary executable files used by C Toolkit Compilers contains the tools to compile and link your C Block file s Docs contains local copies of user documentation in a standard format html or pdf To navigate to the user documentation double click the index htm file located in the root directory The index htm file provides links to the documentation on the Support web site Projects can be used to contain your C Block projects and in addition contains sample C Block projects Targets contains a target subdirectory and a debug subdirectory for each supported target The target subdirectories contain subdirectories for the C Run Time and Target Library header files and compilation programs specifically needed for compiling C Block files for that particular target The debug subdirectories contain files needed to compile and debug C Blocks on the PC using the Cygwin development environment The Targets directory also contains a CommonFiles subdirectory that contains files common to more than one target Files ctkPACS bat opens a DOS box and sets up path and environment variables so that C Blocks can be compiled from any location on your computer GNU txt lists the locations of files covered by the GNU General Public License index htm contains links to the user documentation license txt contains the license information for the C Toolkit readme txt indicates how to get to the readme file for a particular target
130. he offset is 1 based For example Reffable R_MEM and offset 1 accesses R00001 InParam writeValue The value to write to the specified reference table and offset InParam msbByte For word references determines whether the byte is written to the most significant byte msbByte TRUE or to the least significant byte msbByte FALSE ReturnVal If the RefTable or offset are out of range no reference memory values are changed and the function returns GEF_ERROR If the offset is within range the function returns GEF_OK Errno If there is an error this function sets Errno to give specific information on what caused the error Applications that use Errno should first call PLCC_ClearErrno to ensure Errno was not already set by another function call Errno can be read using PLCC_GetErrno Errno values are located in ctkPlcErrno h Chapter 3 Writing a C Application 3 87 ReadPicByte T_ BYTE ReadPlcByte T_WORD RefTable T_DWORD offset T_ BOOLEAN msbByte Description A byte of reference memory in the specified Reference Table RefTable and at the specified offset is read and returned by the function Errno is set if there is an error reading the value InParam RefTable Reference table to read InParam offset Offset within the reference table to read Note The offset is 1 based For example Reffable R_MEM and offset 1 accesses R00001 InParam msbByte For word references determines whether th
131. i_tod 4 rec T_BYTE hun_year hi T_BYTE hun_year lo T_BYTE year hi T_BYTE year lo T_BYTE spacel T_BYTE month_hi T_BYTE month_lo T_BYTE space2 T_BYTE day of month_hi T_BYTE day of month_lo T_BYTE space3 T_BYTE hours_hi T_BYTE hours_lo T_BYTE colonl T_BYTE minutes hi T_BYTE minutes lo T_BYTE colon2 T_BYTE seconds hi T_BYTE seconds _ lo T_BYTE space4 T_BYTE day of week _hi T_BYTE day of week_lo Definitions to be used with read write field READ_CLOCK 0 WRITE_CLOCK 1 struct tod_clock_rec T_WORD read write READ_CLOCK or WRITE_CLOCK T_WORD format NUMERIC_DATA FORMAT BCD_FORMAT C Programmer s Toolkit for PACSystems User s Manual January 2012 GFK 2259E UNPACKED_BCD_FORMAT PACKED ASCII_FORMAT etc see above for additional formats Note All formats may not be supported by a particular PLC target union struct num_tod_rec num_tod struct BCD _tod_rec BCD_tod struct BCD _tod_4 rec BCD tod 4 struct unpacked _BCD rec unpacked_BCD_tod struct unpacked_bcd_tod_4 rec unpacked_BCD_tod 4 struct ASCII_tod_rec ASCII_tod struct ascii _tod_4 rec ASCII_tod 4 struct timespec POSIX tod timespec is defined in sys types h record Note 90 70 C Toolkit did not name this union GFK 2259E Chapter 3 Writing a C Application 3 57 Description This function is the C interface to service request 7 Change Read Time of Day Clock State and Values If read_write is
132. ibility Notes amp Issues Structures and Constants struct read_fault_tables_rec T_WORD table PLC_FAULT_TABLE or O_FAULT_TABLE T_WORD zero must be set to zero T_WORD reserved 13 struct time_stamp_rec time_since_clear T_WORD num_faults_since_clear T_WORD num_faults_in_queue T_WORD num_faults_read union struct PLC_fault_entry_rec PLC_faultsINUM_LEGACY_PLC_FAULT_ENTRIES struct IO_fault_entry_rec 1O_faultsINUM_LEGACY_IO_FAULT_ENTRIES faultEntry E GFK 2259E Appendix A Target Library Functions A 13 Target Library Fault Table Functions Series 90 PLC Library Compatibility Notes amp Issues Structures and Constants T_INT32 PLCC_read_last_ext_fault struct read_last_ext_fault_rec x Read Last Logged Extended Fault Table Entry struct PLC_ext_fault_entry_rec T_BYTE long_short T_BYTE reserved 3 struct PLC_flt_address_rec PLC_fault_address T_BYTE fault_group T_BYTE fault_action T_WORD error_code T_WORD fault_specific_data 12 struct ext_time_stamp_rec time_stamp E struct lO_ext_fault_entry_rec T_BYTE long_short struct reference_address_rec reference_address struct IO_flt_address_rec IO_fault_address T_BYTE fault_group T_BYTE fault_action T_BYTE fault_category T_BYTE fault_type T_BYTE fault_description T_BYTE fault_specific_data 21 struct ext_time_stamp_rec time_stamp F struct read_last_ext_fault_rec T_WORD table
133. ications may be created using the text editor of your choice provided that the output from your editor is compatible with the GNU C compiler Word processors are not recommended for editing C source code In addition your editor must properly handle both DOS and UNIX type line feeds Note that Notepad does not handle UNIX style line feeds and may not display some C Toolkit files correctly It is also recommended that each C application be developed in its own subdirectory One approach would be to use the project subdirectory created when the C Toolkit was installed As each application is developed a new subdirectory under the Projects subdirectory is created for example Projects Ramp Projects Limit Projects Press y etC GFK 2259D 3 1 Name Requirements File Names A C Block s file name for example myCBlock gefElf before the gefElf extension must conform to Machine Edition block naming conventions a maximum of 31 characters long first character must be a letter no spaces In addition you should not use the file name Rel This name is reserved by the C Toolkit see Compiling User C Blocks Under an Older Toolkit Version on page 3 9 Reserved Names To avoid C Toolkit and user naming conflicts you should not use any of the following types of names in your C Block application 1 Names that begin with GEF_ 2 Names that begin with a period For example mydata Failure to follo
134. ight justified least significant bit in the byte that is each of the bit test macros will evaluate to 0 if the bit is OFF or 1 if the bit is ON The C application shown below will set Q137 M29 and T99 if 1120 is ON and will clear Q137 M29 and T99 if 1120 is OFF Example include PACRXPlc h int GeFMain if BIT_TST_1I 120 BIT_SET_Q 137 BIT_SET_M 29 BIT_SET_T 99 else BIT_CLR_Q 137 BIT_CLR_M 29 BIT_CLR_T 99 return GEF_EXECUTION_OK The bit macros for accessing word oriented PLC memories R W P L AI and AQ as bits are similar to the above description except that these macros require one additional parameter namely the position within the word of the bit being accessed The three forms of bit macros for accessing word oriented PLC memory are BIT_SET_ BIT_CLR_ and BIT_TST_ to specify the type of operation followed by R W P L Al or AQ to specify the PLC reference memory to be used There are two required parameters to these macros 1 The word in the reference memory to access 1 to highest reference available in the specified PLC memory 2 The bit in the selected word to use bit numbers 1 to 16 with bit 1 being the least significant or rightmost bit C Programmer s Toolkit for PACSystems User s Manual January 2012 GFK 2259E Byte Macros GFK 2259E To illustrate the bit macros for word oriented memory consider the following sectio
135. iii C Programmer s Toolkit for PACSystems User s Manua January 2012 GFK 2259E Contents MACE OC GUN oes fait cte te tee canandwenieencae a heivee teases naib as tdnasteateluada tea le unie due nateaaebweaeeveamalaeneaeatv eal 1 1 installation iiias rinnuni ea adiada viareiadeceeauaed si tid eddaudadasvaneuaieauausteiedatuneddiatdaniviatav aves 2 1 System Requirements ccccecceceeeceenceeeeece cee eeeaaeeeeaaeegeeeeceaeeeeaaesdeaaeseaeeeecaeeesaaeseeaeeeeeeees 2 1 Installing the C Toolkit for PACSYStOMS c cccccceeeeeeeeeneeceeeeeceaeeeeaaeseeeeeseaeeesaeeseneeesaees 2 2 RUNING TOOK a nean eaaa aa ai aaa ARAA Ta oaa iaaa AARONA TEKENE ead ttn 2 3 C Toolkit File Structure osseeneeeneeeneeseeesnesseessnessnessnnsssnstnnssenttnnttnnstnnntnnntnnnennnennnenn nenn nenn 2 3 Uninstalling TOOl Kits ccccfoesehs Det adeeeea tase agt dicta cnaageeiateseaseas aia aaa aaa Aara OEN Uad iaat ena 2 4 Writing aC Applicaton as sicicsececcsscscncecavetesncsesecepestececasesasuedeneavetecestue neues Peisana ananira nini 3 1 Name Requirement corneri ain are an OA ATAKE AS AAA EAE AEEA aa EAE KAATA AE DAE KENEAN EKE A 3 2 C Applications in the PACSystems Environment 2 cccccceseeeeeeeseeeeeseeeeeaeeeeeeeeeeees 3 3 PACS ystems C Block Str ct re esinta rra a ara a aana uai a aaka na ata nai eaaa AE anadaiwa 3 13 PLC Reference Memory ACCESS 0 c cccssceceeeeeceeeeeesaeeeeeeeseaeeeeaaesseneeseaeeeeaeseeaaeeneneeeaas 3 18 S
136. ile Supported C Run Time Library Functions Associated with File include lt stdlib h gt Math void div_r int numerator int denominator div_t divStructPtr typedef struct int quot int rem div_t a E include lt ctkGefCLib h gt max a b min a b include lt stdlib h gt int rand void a E include lt stdlib h gt void srand unsigned int seed include lt stdlib h gt Data Conversion int abs int include lt stdlib h gt double atof const char include lt stdlib h gt int atoi const char include lt stdlib h gt long atol const char a include lt stdlib h gt long labs long a E Appendix B C Run Time Library Functions Series 90 C Run Time Library Compatibility Notes Issues Errno information and return value exceptions div is not supported because it is not re entrant Description This routine computes the quotient and remainder of numer denom The quotient and remainder are stored in the div_t structure pointed to by divStructPrtr This function does not set errno Denominator 0 will cause a divide by 0 fault and put the CPU into CPU Halted mode Idiv is not supported because it is not re entrant _lrotl _lrotr are not supported long rotate left and right respectively max min macros are supported in the GefCLib library via macros in the header file max returns the greater of two numbers and min returns the smaller of two numbers
137. ime Library Functions The library functions listed in this appendix do not set errno unless otherwise indicated Supported C Run Time Library Functions Associated with File Input Output int sprintf char const char format int sscanf const char string const char format Series 90 C Run Time Library Compatibility Notes Issues Errno information and return value exceptions The Series 90 70 function printf is not supported on the target and will return GEF_ERROR The following lines provide equivalent printf functionality char buffer 100 T_INT32 numBytes numBytes sprintf buffer my Message r n PLCC_MessageWrite PORT1 buffer numBytes When debugging on the PC printf is supported or you can use the sprintf PLCC_MessageWrite combination shown above New function to PACSystems i e it was not supported on Series 90 PLCs B 2 Include File include lt math h gt include lt math h gt include lt math h gt include lt math h gt Supported C Run Time Library Functions Associated with File double acos double 64 bit float acosf float 32 bit double asin double float asinf float double atan double float atanf float Series 90 C Run Time Library Compatibility Notes Issues Errno information and return value exceptions Note for the following Math functions NAN is 0x7ff8000000000000 amp Oxfff8000000000000 respectively for a double
138. inputs or outputs for one scan while the program is running This function can be used in conjunction with the Suspend I O function page 3 82 which stops the normal I O scan It can also be used to update selected I O during the program in addition to the normal I O scan If input references are specified the function allows the most recent values of inputs to be obtained for program logic If output references are specified PLCC_do_io updates outputs based on the most current values stored in I O memory I O points are serviced in increments of entire I O modules the PLC adjusts the references if necessary while the function executes The PLCc_do_io function will not scan I O modules that are not configured The PLCC_do_io function is supported for most PACSystems modules It does not support Genius I O modules The pLcc_do_io function skips modules that do not support DO_IO scanning For details see Control Functions in the PACSystems CPU Reference Manual GFK 2222 When this function executes the input point specified by start_mem_type and start_mem offset and the bits included as specified by length are scanned If alternate_mem type and alternate_mem offset is defined a copy of the data is placed in alternate memory and the real input points are not updated If this function references output data data specified in start_mem_type and start_mem offset is written to the output modules If alt locations are defined the alter
139. irmware therefore it is also intended to be read only from elsewhere in the system specifically from the application program Attempting to use the SB x macro to write into S memory will result in a compile error when compiling the application C source file Similarly attempting to use the pointer variable sb_mem provided in PACRxP1c h and the same pointer variable used by the SB x macro will result in the same compile error C Programmer s Toolkit for PACSystems User s Manual January 2012 GFK 2259E FST_EXE and FST_SCN Macros In the file PACRxP1c h provided in the PACSystems C Toolkit there are two macros FST_SCN and FST_EXE that provide blocks with direct access to S0001 system first scan indication and with direct access to the block s first execution bit The FST_SCN macro references S0001 and acts exactly like the ladder logic reference FST_SCN S0001 If a block is not called on the first PLC sweep the macro rst_scn should not be used for initializing data in the block In this case Fst_scn would never be true The FST_EXE macro operates differently than the Fst_scn macro There is no system status bit associated with the first call to blocks A block inherits Fst_ExE from the block that calls it Therefore if FST_EXE in the calling ladder logic program is true when the block is executed the C macro FsT_ExE will also be true The value of FST_EXE is determined by the calling ladder logic block not by the C bloc
140. itNumber is only used for word type memory The function T_WORD bitNumber returns GEF_OK if the bit is set and GEF_ERROR if the bit cannot be set Errnos TLIB_ERRNO_OFFSET_RANGE_ER offset is outside of valid range TLIB_ERRNO_READ_ONLY_ER TLIB_ERRNO_INVALID_REF_TABLE_ER T_INT32 clearBit T_WORD RefTable New function to generically clear a bit in reference memory The T_DWORD offset bitNumber is only used for word type memory The function T_WORD bitNumber returns GEF_OK if the bit is set and GEF_ERROR if the bit cannot be set Errnos TLIB_ERRNO_OFFSET_RANGE_ER offset is outside of valid range TLIB_ERRNO_READ_ONLY_ER TLIB_ERRNO_INVALID_REF_TABLE_ER Ib address Implemented as macro compatible with 90 70 and 90 30 syntax with the exception that the name has been changed from IB to lb However this macro does not respect overrides and does not set corresponding transition bits so the functionality is different than the 90 70 and 90 30 You should use the WritePlcByte function to get the same functionality as the 90 70 and 90 30 See next item T_INT32 WritePicByte T_WORD RefTable This function writes to reference memory taking into account T_DWORD offset overrides and transition bits The reference memory in the T_BYTE writeValue specified Reference Table RefTable and at the specified T_BOOLEAN msbByte offset is written using the value of writeValue If the offset is out of range n
141. ize of the data area in bytes InParam address Start Address of the data area to be read ReturnVal 1 if successful 0 if unsuccessful 1 if not supported 3 38 C Programmer s Toolkit for PACSystems User s Manual January 2012 GFK 2259E Proc PLCC_BUS_write_byte T_INT32 PLCC_BUS_ write byte T_ WORD rack T_WORD slot T_WORD subSlot T_WORD region T_WORD pStatus T_BYTE value T_DWORD address Description Write a byte to a device on the bus InParam rack The rack number containing the module to access InParam slot The slot number containing the module to access InParam subSlot The sub slot number of the module to access InParam region The region number describing the location of the BUS memory This is set up in hardware configuration for the module OutParam pStatus Pointer to status variable see common definition above InParam value Byte value to be written to a device on the bus InParam address Address of the byte to be written ReturnVal 1 if successful 0 if unsuccessful 1 if not supported GFK 2259E Chapter 3 Writing a C Application 3 39 Proc PLCC_BUS _write_word T_INT32 PLCC_BUS_ write word T_ WORD rack T WORD slot T WORD subSlot T_WORD region T_WORD pStatus T_WORD value T_DWORD address Description Write a word to a device on the bus InParam rack The rack number containing the module to access InParam slot The slot number containing the module to access
142. k FST_EXE may be TRUE 1 if the block is called multiple times from one ladder logic block or is called from multiple ladder logic blocks If the call from the ladder logic to the block is conditional it is possible that the block may never see FST_EXE as true LST_SCN Macro The LSC_SCN macro provides access to the S00002 system last scan indication bit This bit is 1 when the CPU transitions to Run mode and cleared when the CPU is performing its final sweep The CPU clears this bit 0 and then performs one more complete sweep before transitioning to Stop or Stop Faulted mode If the number of last scans is configured to be 0 S0002 will be cleared after the CPU is stopped and user logic will not see this bit cleared If a C subroutine is not called on the last scan before a PLC enters Stop mode the LST_SCN macro should not be used in that block to capture data or trigger events on the last scan In such a case the data or events would never be triggered because the C subroutine was not called on the last scan GFK 2259E Chapter 3 Writing a C Application 3 133 Runtime Error Handling When a C application executes in a PACSystems CPU if an error is generated from one of the runtime library functions or from incorrect interaction between the C application and the CPU the error will be detected and logged in the controller fault table as an application fault on the CPU rack 0 slot 1 Examples of such errors include but are not limi
143. kCBlockTest1 c for more information C Programmer s Toolkit for PACSystems User s Manual January 2012 GFK 2259E Appendix A Target Library Functions As a general note the following functions will set errno in the current context if the function does not return status in some form errno contains an error code from the last Target Library or C Run Time Library function which encountered an error You can access errno via the function PLCC_GetErrno Target Library Reference Memory Functions and Macros Implemented in ctkRefMem h Target Library Reference Memory Series 90 PLC Library Compatibility Functions amp Macros Notes amp Issues BIT_TST_lI address Macro compatible with 90 70 and 90 30 T_INT32 BIT_SET_I T_DWORD address Same functionality as 90 70 and 90 30 but implemented as a T_INT32 BIT_CLR_I T_DWORD address function rather than a macro to respect overrides and to change corresponding transition bits This function also returns an GEF_OK status if the address is within range and an GEF_ERROR status if the address is not within range In the GEF_ERROR case the bit is not changed Errnos TLIB_ERRNO_OFFSET_RANGE_ER Address is outside of valid range BIT_TST_Q address Macro compatible with 90 70 and 90 30 T_INT32 BIT_SET_Q T_DWORD address T_INT32 BIT_CLR_Q T_DWORD address Function aa e with 90 70 and 90 30 Same return status as BIT_SET_l BIT_TST_M address Macro compatible with 90 7
144. ks as Timed or I O Interrupt Blocks GFK 2259E Blocks may be used in the PLC as the target of a timed or I O interrupt with the following restrictions 1 A block invoked as the result of a timed I O or module interrupt may not have parameters associated with the call The block must have 0 input parameters and 0 output parameters A block invoked as a sub block of a timed I O or module interrupt may have parameters associated with the call 2 When a block is invoked as a timed I O or module interrupt all references to L memory will reference the same location in the P table This action is the same as when a block is called directly from the MAIN logic program When a block is invoked as the sub block of a timed I O or module interrupt block all references to L memory will be references to the L of the block from which they were called 3 Additional interrupts are not processed while a timed I O or module interrupt blocks and associated sub blocks are executing if preemptive block scheduling is disabled The preemptive block scheduling feature is available on PACSystems firmware revision 2 0 and greater The following example and associated text cover the issues related to using C Blocks when the same C application is going to be called during the normal execution of the program and from a possible timed I O or module interrupt Calls Interrupt Execution Block 1 Block 2 Some C Block Calls Normal Execution Blo
145. l Functions Structures and Constants struct unpacked_BCD_rec T_BYTE yearlo T_BYTE yearhi T_BYTE monthlo T_BYTE monthhi T_BYTE day_of_month_lo T_BYTE day_of_month_hi T_BYTE hourslo T_BYTE hourshi T_BYTE minslo T_BYTE minshi T_BYTE secslo T_BYTE secshi T_WORD day_of_week iE struct unpacked_bcd_tod_4_rec T_WORD huns_year T_WORD tens_year T_WORD month T_WORD day_of_month T_WORD hours T_WORD minutes T_WORD seconds T_WORD day_of_week E struct ASCII_tod_rec T_BYTE yearhi T_BYTE yearlo T_BYTE space1 T_BYTE monthhi T_BYTE monthlo T_BYTE space2 T_BYTE day_of_month_hi T_BYTE day_of_month_lo T_BYTE space3 T_BYTE hourshi T_BYTE hourslo T_BYTE colon1 T_BYTE minshi T_BYTE minslo T_BYTE colon2 T_BYTE secshi T_BYTE secslo T_BYTE space4 T_BYTE day_of_week_hi T_BYTE day_of_week_lo E struct ascii_tod_4_rec T_BYTE hun_year_hi T_BYTE hun_year_lo T_BYTE year_hi T_BYTE year_lo T_BYTE space1 T_BYTE month_hi T_BYTE month_lo T_BYTE space2 T_BYTE day_of_month_hi T_BYTE day_of_month_lo T_BYTE space3 T_BYTE hours_hi Appendix A Target Library Functions Series 90 PLC Library Compatibility Notes amp Issues The union must be named as required by the GNU C compiler Therefore to get access to a particular member in the record union of the tod_clock_rec structure the following syntax must be used todClockRec record num_tod seconds A 23 Ta
146. les rec T_WORD table Valid table values define PLC_FAULT_TABLE 0 define IO FAULT TABLE 1 Description This function is the C interface to service request 14 Clear Fault Tables The function will clear the fault table according to the value PLC_FAULT_TABLE or IO_FAULT_TABLE InParam x Pointer to structure which indicates whether to clear the PLC or the I O fault table ReturnVal The function returns 1 if successful and 0 if unsuccessful PLCC_read_last_fault GFK 2259E INT32 PLCC_read_last fault struct read last fault _rec x struct read last fault rec T_WORD table union struct PLC_entry rec PLC entry struct I0_entry rec IO entry rec faultEntry Note 90 70 C Toolkit did not require union name Valid table values define PLC_FAULT TABLE 0 define IO FAULT TABLE 1 Description This function is the C interface to service request 15 Read Last Logged Fault Table Entry The function will return the last fault table entry of the table specified in the table field PLC_FAULT_TABLE or 1O_FAULT_TABLE In the return data the long short indicator defines the quantity of fault data present in the fault entry In the controller fault table a long short value of 00 represents 8 bytes of fault extra data present in the fault entry and 01 represents 24 bytes of fault extra data In the I O fault table 02 represents 5 bytes of fault specific data and 03 represents 21 bytes
147. lkit for PACSystems User s Manual January 2012 Variable Numeric Value NOT_SUPPORTED 1 OPERATION_SUCCESSFUL BUS_ERROR MOD_DOES_NOT_EXIST INVALID_MOD START_ADDR_RANGE_ERR END_ADDR_RANGE_ERR EVEN_ADDR_ODD_CONFIG_ERR ODD_ADDR_EVEN_CONFIG_ERR WINDOW_NOT_ENABLED COYN OD Oo R IN o INVALID_ACCESS_WIDTH o INVALID_PARAM 10 The hardware configuration must be set up for the largest access for these functions to complete with a successful status For example the module memory region Interface Type must use Dword Access if any of the Dword functions are used However if only Word or Byte functions are used the Interface type can be Word Access Similarly if only byte functions are used the Interface type can be Byte Access In addition Word Access functions must use only even addresses and Dword Access functions must be Dword aligned 0 4 8 etc The subSlot value for most modules will be 0 GFK 2259E Proc PLCC_BUS_read_byte T_INT32 PLCC_BUS_read_byte T WORD rack T_WORD slot T_WORD subSlot T_WORD region T_WORD pStatus T_BYTE pBuffer T_DWORD address Description Read a byte from a device on the bus InParam rack The rack number containing the module to access InParam slot The slot number containing the module to access InParam subSlot The sub slot number of the module to access InParam region The r
148. ll character into string immediately following the returned token and updates the pointer to which ppLast points so that it points to the first character following the null written into string Note that because the separator character is overwritten by a null character the input string is modified as a result of this call In subsequent calls string must be a NULL pointer and ppLast must be unchanged so that subsequent calls will move through the string returning successive tokens until no tokens remain The separator string separators may be different from call to call When no token remains in string a NULL pointer is returned This function returns a pointer to the first character of a token or a NULL pointer if there is no token _strupr Converts any lowercase characters in the specified string to uppercase is not supported GFK 2259E Include File include lt PLCC9070 h gt include lt PLCC9030 h gt Supported C Run Time Library Functions Associated with File fstrcat _fstrchr _ fstremp _fstrcpy _fstrcspn _ fstrlen _fstrncat _fstrncmp _fstrncpy _fstrpbrk _fstrrchr _fstrspn _ fstrstr fstrcat _fstrchr _ fstremp _fstrcpy _fstrcspn _ fstrlen _fstrncat _fstrncmp _ fstrncpy _fstrpbrk _fstrrchr _ fstrspn _fstrstr _fmemchr _fmemcmp _fmemcpy _fmemmove _fmemset Series 90 C Run Time Library Compatibility Notes Issues Errno information and r
149. loating point format Certain combinations of reference type designators and data type modifiers are not supported Those combinations that are supported have macros defined in the ctkRefMem h file Refer to Appendix A for the complete set of macros provided Macros that permit access to reference memories as bits are slightly different from macros that access the same reference memories as bytes words double words and or floating point numbers Bit access macros byte access macros word integer access macros word memories as bytes access macros and double word floating point access macros are described on the following pages of this chapter Chapter 3 Writing a C Application 3 19 3 20 Bit Macros There are three bit macros defined for each reference memory type Macro Description BIT_TST_X Tests the specified bit BIT_SET_X Sets the specified bit BIT_CLR_X Clears the specified bit References in a C application to l would use BIT_TST_I BIT_CLR_I Or BIT _SET_I The macro name indicates that l reference memory is to be operated on and the operation is tested TST cleared CLR or set SET The value contained in parentheses is the reference number of the item to be tested cleared or set for example 120 for l120 The bit set and bit clear macros are separate C application source statements Note The bit test macros return a boolean value contained in a byte The accessed bit is r
150. lowing example Example include PACRxPLC h int GeFMain struct tod_clock_rec data data read_write 1 data format UNPACKED BCD FORMAT set the time and date to 1 13 08pm Tuesday August 9 1994 data data data data data data data data data data data data data record record record record record record record record record record record record record unpacked BCD tod unpacked _BCD_ tod unpacked _BCD_ tod unpacked _BCD_ tod unpacked _BCD_ tod unpacked _BCD_ tod unpacked _BCD_ tod unpacked _BCD_ tod unpacked _BCD_ tod unpacked _BCD_ tod unpacked _BCD_ tod unpacked BCD tod unpacked _BCD_ tod PLCC_tod_ clock amp data GFK 2259E Chapter 3 Writing a C Application yearhi 9 yearlo 4 monthhi 0 monthlo 8 day of month_hi day _of month_lo hourshi 1 hourslo 3 minshi minslo secshi secslo day of week TUESDAY 3 59 The packed ASCII format should have an ASCII character in every byte as shown in the following example Example include PACRx PLC h int GeFMain struct tod_clock_rec data data read_ write 1 data format PACKED ASCII_FORMAT set the time and date to 1 13 08pm Tuesday August 9 1994 data data data data data data data data data data data data data data data data data place 0 ASCII 30 hex in record rec
151. ly for reading reference memory G Discrete global data references use only for reading reference memory S Discrete system references use only for reading reference memory SA Discrete maskable fault references SB Discrete non maskable fault references SC Discrete fault summary references SAI Analog input registers AQ Analog output registers R System register references W Bulk memory references P Program registers use to store program data from main AL Local registers use to store program data unique to a block How to Format a PLC Reference Access Macro GFK 2259E The table shown below gives the modifiers used with the PLC reference macros listed in Appendix A The format for usage of these macros is as follows The letter of reference type followed by one of the modifiers followed by a parenthetical number for the address you wish to access e g RI 1 3 This assigns the integer value 3 to R00001 RW 2 0x55AA This assigns the word value 55AAh to R00002 The data type modifiers are as follows Modifier Description B Unsigned byte reference 8 bits 0 gt 255 WwW Word reference 16 bits 0 gt 65535 l Integer reference signed 16 bits 32768 gt 32767 D Double precision integer reference signed 32 bits 2147483648 gt 2147483647 F Floating point reference 32 bit IEEE floating point format Dbl Double precision floating point reference 64 bit IEEE f
152. m number of racks is specified in model_specifics h InParam slotNumber Indicates which slot to use to get the module fault reference bit slotNumber is 0 based and the maximum number of racks is specified in model_specifics h InParam busNumber Indicates which bus to use to get the module fault reference bit Valid values are 1 or 2 InParam sbaNumber Indicates which serial bus offset to use to get the module fault reference bit sbaNumber is 0 based and the maximum number of modules per bus is specified in model_specifics h ReturnVal Returns the module fault reference bit for the requested rack slot bus and serial bus address in bit 0 Errno If there is an error this function sets Errno to give specific information on what caused the error Applications that use Errno should first call PLCC_ClearErrno to ensure Errno was not already set by another function call Errno can be read using PLCC_GetErrno Errno values are located in ctkPlcErrno h 3 100 C Programmer s Toolkit for PACSystems User s Manual January 2012 GFK 2259E rsmb Notes RACK REFERENCE REC rsmb T_BYTE rackNumber typedef struct T_DWORD RackFlags Summary and failure flags T DWORD SlotFaults All 32 bits of Dword for slot fault bits T_DWORD BusRefs MAX NUM BUSES PER SLOT Bus fault bits T_BYTE ModRefs MAX _NUM BUSES PER_SLOT LIMIT_NUM_SLOTS PER_RACK MAX_NUMBER_MODULES PER_BUS 8 RACK_REFERENCE_ REC Definiti
153. mension PLC_faults and O_ faults members to the size of the maximum number of faults you want to read You must then declare a variable of this type and cast it to a read_ext_fault_tables_rec when calling this function See Example Note that the structure must be packed to work properly Another issue is that the union must be named as required by the GNU C compiler Therefore to get access to a particular fault the following syntax must be used myExtFaultRec faultEntry PLC_faults 0 GFK 2259E Target Library General Functions Structures and Constants Implemented in ctkPIcFunc h Target Library General Functions Structures and Constants Series 90 PLC Library Compatibility Notes amp Issues General PLC Functions T_INT32 PLCC_read_elapsed_clock struct elapsed_clock_rec Compatible with 90 70 and 90 30 libraries struct elapsed_clock_rec T_DWORD seconds T_WORD hundred_usecs E T_INT32 PLCC_read_nano_elapsed_clock struct nano_elapsed_clock_rec Function returns elapsed time in nanoseconds DE struct nano_elapsed_clock_rec T_DWORD seconds T_DWORD nanoseconds E T_INT32 PLCC_chars_in_printf_q void Returns GEF_NOT_SUPPORTED since printf is not supported The following functions provide information on the number of characters in integer value equal to number of characters currently in the printf buffer Pnteger value ogu S s yi pr 4 the input output queues define PRINTF_Q_SIZE 2048 PLCC_Char
154. ment of the array for which diagnostics are to be read These should be T_INT32 type Errno If there is an error this function sets Errno to give specific information on what caused the error Applications that use Errno should first call PLCC_ClearErrno to ensure Errno was not already set by another function call Errno can be read using PLCC_GetErrno Errno values are provided in ctkPlcErrno h 3 112 C Programmer s Toolkit for PACSystems User s Manual January 2012 GFK 2259E Proc ReadPlicVarTrans extern T_INT32 ReadPlcVarTrans PLC_VAR_REC pVarInfo void pReadTransTo Description This function reads the transition value s for a PLC variable into a buffer provided by the caller InParam pVarinfo Pointer to a PLC_VAR_REC information record for the variable to be read If the variable does not have transitions an error will be returned InParam pReadTransTo Pointer to the memory location where the transition values for the variable should be written Note If pVarlnfo references an array the transitions for the entire array will be read Notes For type BOOL an entire byte will be written to pReadTransTo with the low bit of the byte containing the transition value for the BOOL variable m Foran array of type BOOL the number of bytes written will be total number of elements 7 8 The first transition bit will be written to the least significant byte of the first byte For all other types the number o
155. mmer s Toolkit for PACSystems User s Manual January 2012 GFK 2259E Non Standard C Library Functions Non Standard C Library functions are not supported in the PACSystems C Toolkit See appendix B for functions that are not supported Entry Point In the Series 90 C Toolkit the entry point into the user application was main For the PACSystems C Toolkit the entry point is GefMain C Standalone Programs C standalone programs are not supported However C program applications that do not rely on the C program scheduling features can be compiled and executed as C blocks Use of Input Parameters as Pointers to Discrete Memory Tables In the PACSystems C Toolkit if the user application is passed a pointer to one of the discrete memory tables l Q etc for example as one of the input parameters to GefMain and the pointer is used to write to discrete reference table memory overrides and transitions are not taken into account for the write operation When a discrete memory write operation occurs via a pointer in the Series 90 PLCs overrides and transitions are taken into account For the PACSystems C Toolkit you should use the following function when writing directly to discrete memory via a pointer if you want overrides and transition bits to be respected T_INT32 PlcMemCopy void pDestination void pSource T_DWORD size GFK 2259E Chapter 5 Conversion Notes and Series 90 Compatibility 5 5 Chapter Installed Sample
156. mmonFiles IncCommon Plcinc and Errno h Targets CommonFiles IncCommon VxCommon The PLCC Errno Functions are described in ctkPlcErrno h PLCC_GetErrno int PLCC_GetErrno void Description This function returns the errno value in the current context The errno value is an error code set by the last PLC Target Library or C Run Time Library function to declare an error ReturnVal Returns the errno value PLCC_ClearErrno void PLCC_ClearErrno void Description This function sets the Errno value in the current context to 0 3 104 C Programmer s Toolkit for PACSystems User s Manual January 2012 GFK 2259E PLC Variable Access The C toolkit can access PLC variables which are declared on the PLC and can be managed variables I O variables or mapped variables This section describes the macros and external functions externs used for accessing PLC variables These macros and functions are described in ctkVariables h Notes m When reading writing non array variables or individual elements of arrays for user data types coherency will be guaranteed for the entire read or write For string variables the data is not guaranteed to be coherent m When reading writing non boolean array variables coherency will be guaranteed for each individual element of the array m This feature is supported only on versions 3 50 and later Type and Structure Definitions PLC_VAR define PLC_VAR VariableRecord PlcVariableName
157. mory address Possible values for the mask element define MASK 1 define UNMASK 0 Valid memory types define IBIT 70 define AIMEM10 All offsets are 1 based l1 1 l2 2 Al1 1 AI2 2 Discrete offsets and lengths are in bits and must be byte aligned 1 9 17 25 are valid for offsets 2 8 10 16 18 24 are invalid for offsets Analog offsets and lengths must be in words Description This function is the C interface to service request 17 Mask Unmask I O Interrupt The function will mask or unmask interrupts from an input module according to the value in mask MASK or UNMASK The memory_type parameter specifies the memory type of the input to mask or unmask and can have a value of l IBIT or Al AIMEM The address specified must match a PACSystems input module with maskable channel and interrupts enabled InParam pMaskloInterruptsRec Pointer to structure containing mask I O interrupt information ReturnVal This function will return 1 if successful and 0 if unsuccessful GFK 2259E Chapter 3 Writing a C Application 3 65 PLCC_mask_lO_interrupts_ext 3 66 Note Firmware version 3 50 or higher is required for this function struct mask_IO interrupts _ext_rec T WORD action MASK or UNMASK T_WORD memory type Address of input interrupt trigger T_DWORD memory offset extern T_INT32 PLCC_mask_IO interrupts ext struct mask_IO interrupts _ext_rec Possible valu
158. mory for a PLC variable If the variable is a BOOL or array of BOOLS the size is in bits For all other types the size is in bytes InParam pVarinfo Pointer to a PLC_VAR_REC information record ReturnVal size Size in bits for BOOLs Arrays of BOOLs Size in bytes for all other types Zero is returned for NULL input pointer Note BYTE arrays in non discrete memory are not packed on the PLC so each byte occupies 16 bits of PLC memory This routine returns the size in bytes as if the byte array were packed not the size of the memory occupied on the PLC Chapter 3 Writing a C Application 3 119 Proc PicVarSizeofTrans extern T_DWORD PlicVarSizeofTrans PLC_VAR_REC pVarInfo Description This function returns the total size of the transition memory for a PLC variable If the variable is a BOOL or array of BOOLS the size is in bits For all other types the size is in bytes InParam pVarInfo Pointer to a PLC_VAR_REC information record ReturnVal size This function returns size in Bits for BOOLs Arrays of BOOLs Bytes for all other types Zero is returned for NULL input pointer Note BYTE arrays in non discrete memory are not packed on the PLC so each byte occupies 16 bits of PLC memory This routine will return the size in bytes as if the byte array were packed not the size of the memory occupied on the PLC Proc PlcVarNumDimensions extern T_DWORD PlicVarNumDimensions PLC_VAR_REC pVarInfo Description This functio
159. n This manual contains essential information about the construction of C applications for PACSystems control systems It is written for the experienced programmer who is familiar with both the C programming language and with the operation of PACSystems control systems For more information about PACSystems refer to the list of documents at the end of this chapter The PACSystems C Programmer s Toolkit contains libraries utilities and documentation required to create C applications for the PACSystems control system C blocks are constructed using the ANSI C programming language using text editing and toolkit applications on a personal computer The C blocks are incorporated into a PACSystems application program through Proficy Machine Edition programming software Using the programming software C blocks can be called from ladder logic or invoked by an I O module or timed interrupt In the programming software use the Add C Block feature to insert C blocks The PACSystems CPU supports one type of C block which has the capabilities of both the Series 90 70 type C blocks and C function blocks The PACSystems CPUs and the PACSystems C Toolkit do not support Standalone C Programs which is a feature of the Series 90 70 A PACSystems C block is by default limited to 256Kbytes in size provided there is sufficient PLC memory Examples of calculations that might be performed in C blocks include a Ramp soak profiling m Lead lag calculation
160. n of a C application if BIT_TST_R 135 6 BIT_SET P 13 4 else BIT_CLR_AI 2 1 This portion of a C application checks the sixth bit in R135 If the bit is on 1 then the fourth bit in P13 is to be set ON 1 otherwise the first bit in AI2 is to be set OFF 0 Note The BIT_ macros used to access bits in word oriented memories use a 1 to 16 bit numbering scheme with bit 1 being the least significant bit and bit 16 being the most significant bit Macros are provided to read the PLC bit memories as bytes These macros are Ib x Qb x Mb x To x Gb x Sb x SAb x SBb x and SCb x Use extreme caution with the following discrete macros These macros should not be used to write directly to discrete memory because they do not take into account corresponding override and transition memory For details refer to PLC Reference Memory Access on page 3 18 The parameter x in each of these macros should be replaced with the reference address of a bit which is contained in the byte for example if the byte containing M123 is needed use Mb 123 The byte access macros should only be used on the right hand side of a C statement read operation only The example that follows sets the variable MyVar equal to the byte starting at Q65 and ending at Q72 Example include PACRxPlc h int GeFMain T_ BYTE MyVar MyVar Qb 72 return GEF_EXECUTION_OK Accessi
161. n declarations definitions and macros used in writing blocks The following example shows the basic components of a block with no parameters include PACRXPLC h PACSystems RX interface file int GefMain value of function block ENO output determined by return value return GEF_EXECUTION_OK Variable Declarations Global and static variables may be used in a C block The space allocated for them is taken from the 256K byte default space allowed for each block Local or automatic variables are allocated on the stack PACSystems guarantees that a minimum of 5120 bytes is available on the stack before calling a C block If this amount of space is not available before calling the block a diagnostic application fault will be logged in the fault table Stack Overflow Checking 3 14 Stack overflow checking is enabled by default If C block stack checking is enabled when the block is built and the CPU detects that there is not enough space available on the stack when calling a user function within a block an application fault will be logged in the controller fault table and the block will be exited at the point where the potential stack overflow is detected The block ENO output will be turned off To resolve the problem you will need to evaluate if there is a problem in your application such as a recursion a block calling itself or increase the stack size Stack size can be increased in 8K byte increments on the _MAIN Block
162. n returns the number of dimensions for a PLC variable If the variable is not an array zero is returned Note A variable of type STRING will return zero An array of STRINGs will return non zero InParam pVarinfo Pointer to a PLC_VAR_REC information record ReturnVal numDimensions Number of dimensions for array variables zero for scalar types 3 120 C Programmer s Toolkit for PACSystems User s Manual January 2012 GFK 2259E GFK 2259E Proc PilcVarHasDiags extern T_ BOOLEAN PlcVarHasDiags PLC_VAR_REC pVarInfo Description This function returns TRUE if the PLC variable supports diagnostics FALSE if not Note This routine returns TRUE if the variable supports diagnostics regardless of the state of the diagnostic data InParam pVarinfo Pointer to a PLC_VAR_REC information record ReturnVal TRUE if the PLC variable has diagnostic values associated with it FALSE if not Proc PicVarHasOverrides extern T_BOOLEAN PlcVarHasOverrides PLC_VAR_REC pVarInfo Description This function returns TRUE if the PLC variable supports overrides FALSE if not Note This routine returns TRUE if the variable supports overrides regardless of the state of the overrides InParam pVarinfo Pointer to a PLC_VAR_REC information record ReturnVal TRUE if the PLC variable has override values associated with it FALSE if not Proc PicVarHas Transitions extern T_ BOOLEAN PlcVarHasTransitions PLC _VAR_REC pVarInfo Description
163. nate data is written to the output modules Execution of the function continues until either all inputs in the selected range have reported or all outputs have been serviced on the I O cards C Programmer s Toolkit for PACSystems User s Manual January 2012 GFK 2259E PLCC_do_io_ext GFK 2259E For PLCC_do_io the Offset and Length for Word types is in units of Words For Bit types the Offset and Length is in units of Bits Offset and Length is 1 based InParam pDoloRec A pointer to Do I O record ReturnVal The function return a 1 unless one or more of the following is true in which case it returns a 0 Notall references of the type specified are present within the selected range The CPU is not able to properly handle the temporary list of I O created by the function m The range specified includes I O modules that are associated with a Loss of I O Module fault Note If the function is used with timed or I O interrupts transitional contacts associated with scanned inputs may not operate as expected If an I O or Alt reference address including length is outside the configured memory limits the function will set errno with values described in CPUErrno h Note Firmware version 3 50 or higher is required for this function struct do io ext_rec T_WORD start_mem type T_DWORD start mem offset T_DWORD length Ignored if start_mem_type is PLC_VAR MEM T WORD alt_mem type must be set to NULL _SEGS
164. ndow T_INT32 PLCC_change_backplane_comm_window struct change_system_comm_window_rec pChangeBackplaneCommWindowRec struct change _system_comm_window_rec T_BYTE time T_BYTE mode window modes define LIMITED MODE 0 define CONSTANT MODE 1 define RUN_TO COMPLETION MODE 2 Description This function is the C interface to service request 4 Change Backplane Communications Window State and Values Note The Series 90 documentation refers to the Backplane Communications window as the System Communications Window This function will change the Backplane Communications Window state and timer to the values specified in the structure The mode will be changed to one of the three states LIMITED_MODE CONSTANT_MODE or RUN_TO_COMPLETION_MODE depending on the value in the mode field InParam pChangeBackplaneCommWindowRec Pointer to structure containing backplane communications record The time value should be from 1 to 255 milliseconds ReturnVal This function will return 1 if successful and 0 if unsuccessful GFK 2259E Chapter 3 Writing a C Application 3 51 PLCC_change_background_window T_INT32 PLCC_change_background_window struct change_background_window_rec pChangeBackgroundWindowRec struct change background window_rec T_BYTE time T_BYTE mode window modes define LIMITED MODE 0 define CONSTANT MODE 1 define RUN_TO COMPLETION MODE 2 Description This function is the C interface to
165. ng SB x 3 132 Writing directly to discrete memory 5 2 C Programmer s Toolkit for PACSystems User s Manual January 2012 GFK 2259E
166. ng bytes from word oriented memories R W P L AQ and Al requires an additional parameter to indicate which byte is to be read or written The symbols HIBYTE and LOBYTE are defined in PACRxPLC h for this purpose For Chapter 3 Writing a C Application 3 21 example your C application requires that the low byte of R5 be read into a C application local variable and then copied into the high byte of R17 Example include PACRxPLC h int GefMain T_BYTE abytvar abytvar RB 5 LOBYTE read low byte of R5 RB 17 HIBYTE abytvar write high byte of R17 return GEF_EXECUTION_OK Integer Word Macros All PLC reference memories may be accessed as 16 bit 2 s complement integers T_INT16 or as 16 bit unsigned integers T_WORD As an example a C application needs to read R123 as an unsigned 16 bit integer and write P13 as a 2 s complement 16 bit integer and store the values in separate local C source variables Example include PACRxPLC h int GefMain T_WORD word val T_INT16 int_val 133 word val RW 123 read R123 as a word PI 13 int_val copy 2 s complement integer to P00013 return GEF_EXECUTION_OK 3 22 C Programmer s Toolkit for PACSystems User s Manual January 2012 GFK 2259E Double Word Floating Point Macros All PLC reference memories may be accessed as 32 bit signed integers T_INT32 but only the word oriented memories
167. nly the num_faults_read field will have valid data In the return data the long short indicator defines the quantity of fault data present in the fault entry In the controller fault table a long short value of 00 represents 8 bytes of fault extra data present in the fault entry and 01 represents 24 bytes of fault extra data In the I O fault table 02 represents 5 bytes of fault specific data and 03 represents 21 bytes This function provides a maximum of 16 controller fault table entries and 32 I O fault table entries If the fault table read is empty no data is returned InParam x Pointer to structure containing record of all current PLC or I O fault table entries Return Data The function will return 1 if successful and 0 if unsuccessful 3 76 C Programmer s Toolkit for PACSystems User s Manual January 2012 GFK 2259E PLCC_read_last_ext_fault T_INT32 PLCC read last ext fault struct read last _ext_fault rec x struct read last _ext_fault rec T_WORD table PLC_EXT FAULT TABLE or IO EXT FAULT TABLE union struct PLC_ext fault entry rec PLC entry struct IO ext _fault_entry rec IO entry faultEntry note 90 70 C Toolkit did not require name for union e Use the following definitions for table define PLC_EXT FAULT TABLE 0x80 define IO EXT FAULT TABLE 0x81 Description This service request will read the last entry logged in either the PLC or I O fault table with the extended
168. not need to change if BIT_TST I 1 BIT_SET_I 2 BIT _CLR_I 2 d Other Macros Most other macros can be used just as they were used in the Series 90 PLC and require no conversion A complete list of all macros and their compatibility with the 90 70 and 90 30 macros is located in Appendix A PLC Target Library Function Compatibility Issues Most 90 70 and 90 30 Target Library functions are supported but there are some compatibility issues A complete list of all PACSystems Target Library functions and compatibility issues are described in Appendix A GFK 2259E Chapter 5 Conversion Notes and Series 90 Compatibility 5 3 Compatibility Issues with Retentive Global Variables In the Series 90 C Block s retentive global variables are uninitialized and denoted with the static attribute All other global variables are non retentive Although not documented in the Series 90 uninitialized non retentive global variables were set to 0 on arun to stop transition For the PACSystems C Blocks both static and non static uninitialized global variables are retentive and are truly uninitialized not set to 0 Users who relied on uninitialized non static variables being set to 0 on a stop to run transition will need to add initialization code PACSystems C Blocks with initialized variables are non retentive which is the same behavior as the Series 90 int Type Issues The int basic type in the 90 70 and 90 30 represents
169. nt Not supported by Series 90 Supported by PACSystems Release 5 0 or greater GFK 2259E GFK 2259E Target Library VME Functions Structures and Constants Implemented in ctkPlcBus h Compatible with Rx7 only Target Library VME Functions Structures and Constants T_INT32 PLCC_BUS_read_byte T_WORD rack T_WORD slot T WORD subSlot T_WORD region T_ WORD pStatus T_BYTE value T DWORD address Read a byte from the VME bus T_INT32 PLCC_BUS_read_word T_WORD rack T_WORD slot T_ WORD subSlot T WORD region T_WORD pStatus T WORD value T_ DWORD address Read a word from the VME bus T_INT32 PLCC_BUS_read_block T_WORD rack T_ WORD slot T WORD subSlot T_WORD region T_WORD pStatus void buffer T_ WORD length T_DWORD address Read a block from the VME bus T_INT32 PLCC_BUS_write_byte T_WORD rack T_WORD slot T WORD subSlot T_WORD region T_ WORD pStatus T_BYTE value T_ DWORD address Write a byte to the VME bus T_INT32 PLCC_BUS_write_word T_WORD rack T_WORD slot T WORD subSlot T_ WORD region T_ WORD pStatus T_WORD value T DWORD address Write a word to the VME bus T_INT32 PLCC_BUS_write_block T_WORD rack T_ WORD slot T WORD subSlot T WORD region T_WORD pStatus void buffer T WORD length T_DWORD address Write a block of data to the VME bus T_INT32 PLCC_BUS_RMW_byte T_WORD rack T_ WORD slot T WORD subSlot T WORD region T_W
170. nt directory type the following line compileCPACRX myCFile4 DisableGefLibLink C Programmer s Toolkit for PACSystems User s Manual January 2012 GFK 2259E Compiling User C Blocks Under an Older Toolkit Version If you are developing C blocks for a PLC with an older firmware version the C Toolkit allows the code to be compiled under the limitations of an older C Toolkit version You can specify the Toolkit release on the command line as the last two parameters at the time the C block is compiled If a version is not specified the C code will be compiled with the most recent version newest feature set For example Normal command compileCPACRX myCFile OR compileCPACRX assumes a sources file Release specifying command example compileCPACRX myFile Rel 1_0 OR compileCPACRX Rel 1_0 assumes a sources file In this example the release specified in the second command is 1 0 Release numbers should be preceded by the keyword Rel so that the compile batch file knows that compileCPACRX Rel 1_0 is meant to compile the C code specified in a sources file within the constraints of release 1 0 of the C Toolkit The name of the file containing the user s C code if specified on the command line cannot be Rel As of Release 5 00 the following revisions can be specified on the command line after the keyword Rel Associating a Compiled C Block with the Application Program After the program is compile
171. nter to the buffer of data to write to the serial port InParam numBytes Number of bytes to write up to MESSAGE_BUFFER_SIZE ReturnVal If successful returns the number of bytes written This may be less than the number of bytes requested if the write queue fills Returns 1 for a bad parameter or if message mode is not configured for the specified port Errno If there is an error this function sets Errno to give specific information on what caused the error Applications that use Errno should first call PLCC_ClearErrno to ensure Errno was not already set by another function call Errno can be read using PLCC_GetErrno Errno values are located in ctkPlcErrno h GFK 2259E Chapter 3 Writing a C Application 3 29 Proc PLCC_MessageRead T_INT32 PLCC_MessageRead T_INT32 port char buffer T_INT32 numBytes Description Reads from the serial port input queue on the PLC InParam port Indicates which PLC serial port to read i e PORT1 PORT2 InParam buffer Pointer to the buffer to place the data read from the input queue InParam numBytes Number of bytes to read up to MESSAGE_BUFFER_SIZE ReturnVal If successful returns the number of bytes read This may be less than the number of bytes requested if it is larger than the number of bytes in the read queue Returns 1 for a bad parameter or if message mode is not configured for the specified port Errno If there is an error this function sets Errno to give s
172. nterruptsRec Pointer to structure containing masked timed interrupt values ReturnVal 1 if successful 0 if unsuccessful 1 if not supported 3 68 C Programmer s Toolkit for PACSystems User s Manual January 2012 GFK 2259E PLCC_sus_res_HSC_interrupts T_INT32 PLCC sus_res_HSC_interrupts struct sus HSC interrupts rec pSusResHscInterruptsRec struct sus_res HSC_interrupts_rec T WORD action SUSPEND or RESUME T_WORD memory type T_WORD reference address Valid memory types define IBIT 70 define AIMEM10 Valid action values define RESUME 0 define SUSPEND 1 All offsets are 1 based 1I1 1 I2 2 AI1 1 AI2 2 Discrete offsets and lengths are in bits and must be byte aligned 1 9 17 25 are valid for offsets 2 8 10 16 18 24 are invalid for offsets Analog offsets and lengths must be in words Description This function is based on service request 32 Suspend High Speed Counter Interrupts The function will enable or disable the high speed counter interrupts for a given address and memory type InParam pSusResHscinterruptsRec Pointer to structure containing high speed counter interrupt suspension resumption values ReturnVal 1 if successful 0 if unsuccessful 1 if not supported GFK 2259E Chapter 3 Writing a C Application 3 69 PLCC_sus_res_interrupts_ext 3 70 Note Firmware version 3 50 or higher is required for this function struct sus_res_in
173. ntry_rec T_BYTE long_short struct reference_address_rec reference_address struct IO_flt_address_rec IO_fault_address T_BYTE fault_group T_BYTE fault_action T_BYTE fault_category T_BYTE fault_type T_BYTE fault_description T_BYTE fault_specific_data 21 struct time_stamp_rec time_stamp T_WORD fault_id E struct read_last_fault_rec T_WORD table PLC_FAULT_TABLE or IO_FAULT_TABLE union struct PLC_fault_entry_rec PLC_entry struct O_fault_entry_rec O_entry GFK 2259E Appendix A Target Library Functions A 15 Target Library Fault Table Functions Series 90 PLC Library Compatibility Notes amp Issues Structures and Constants T_INT32 PLCC_clear_fault_tables struct clear_fault_tables_rec x Clear Fault Tables struct clear_fault_tables_rec T_WORD table k define PLC_FAULT_TABLE 0 define IO_FAULT_TABLE 1 T_INT32 PLCC_read_ext_fault_tables struct read_ext_fault_tables_rec x Read Extended Fault Tables struct read_ext_fault_tables_rec T_WORD table PLC_EXT_FAULT_TABLE or IO_EXT_FAULT_TABLE T_WORD start_index T_WORD number_of_entries_to_read T_WORD reserved 12 struct time_stamp_rec time_since_clear T_WORD num_faults_since_clear T_WORD num_faults_in_queue T_WORD num_faults_read T_WORD PlicName 16 _ union struct PLC_ext_fault_entry_rec PLC_faults 1 struct O_ext_fault_entry_rec O_faults 1 faultEntry E Example Extended fault table structure declaration with
174. o P2 GFK 2259E Chapter 3 Writing a C Application 3 127 When the block executes the statement yl x1 x2 the resulting operation adds the contents of R1 x1 to the contents of P1 x2 and place the sum in R2 y1 which is not what the ladder logic program expects Since the ladder logic call to a block always specifies the parameters in order inputs 1 to 63 and outputs 1 to 63 the block declaration of GefMain must specify the parameters to GefMain in the same order Parameter Number Errors 3 128 If the number of parameters associated with a block in ladder logic does not match the number of parameters in the declaration of GefMain for the block potentially severe execution errors will occur Note Itis essential that the number of parameters in a call to a block and the actual number of parameters required by the called block match otherwise the block will use invalid pointer variables to perform reads and writes Again using our example with the ladder logic portion unchanged the effect of a difference in the number of parameters can be illustrated in the following example int GefMain T_INT16 x1 T_INT16 yl Add the contents of R1 to the contents pointed to by x1 and then store the sum in the location pointed to by yl if x1 NULL amp amp yl NULL kyl x1 RI 1 return GEF_EXECUTION_OK else return GEF_EXECUTION ERROR In this scenario
175. o reference memory values are changed and the function returns GEF_ERROR If the offset is within range the function returns GEF_OK msbByte determines whether the MSB or LSB of a word type reference is written Note this function will only affect the transition bits that actually change Errnos TLIB_ERRNO_OFFSET_RANGE_ER TLIB_ERRNO_READ_ONLY_ER TLIB_ERRNO_INVALID_REF_TABLE_ER T_BYTE ReadPlcByte T_WORD RefTable The reference memory in the specified Reference Table T_DWORD offset RefTable and at the specified offset is read and returned by T_BOOLEAN msbByte the function Errno is set if there is an error reading the value msbByte determines whether the MSB or LSB of a word type reference is read Errnos TLIB_ERRNO_OFFSET_RANGE_ER TLIB_ERRNO_INVALID_REF_TABLE_ER Qb address Similar issues as Ib Mb address Similar issues as Ib GFK 2259E Appendix A Target Library Functions A 3 Target Library Reference Memory Functions amp Macros Tb address Gb address b address Ab address Bb address Cb address address highByte AlB address highByte AQB adadress highByte PB address highByte LB address highByte WB address highByte Iw address T_INT32 WritePlcWord T_WORD RefTable T_DWORD offset T_WORD writeValue T_WORD ReadPlicWord T_WORD RefTable T_DWORD offset C Programmer s Toolkit for PACSystems User s Manual January 2012 Series 90 PLC Library Compati
176. on of function sinf myCBlock c 277 warning implicit declaration of function sinhf myCBlock c 278 warning implicit declaration of function sqrtf myCBlock c 279 warning implicit declaration of function tanf myCBlock c 280 warning implicit declaration of function tanhf Solution The warnings are given because these are not supported ANSI functions However if you choose you can store the C Block to the PLC because these functions are supported in the PLC To get rid of the warnings compile the C Block without the EnableAnsi flag GFK 2259E C 1 Issue Compiler issues the following statement warning HUGE_VAL redefined Solution Place the PACRXPLC h PACRX3iPLc h or PACRX7iPIc h include file before math h This properly defines HUGE_VAL and prevents redefinition If the warning is ignored the C Block may not store successfully to the PLC due to not being able to resolve a reference used by HUGE_VAL Issue Compiler issues the following error statement undefined reference to isascii when the EnableAnsi flag is used In addition the C Block will not store to the PLC Solution The isascii macro is not supported when compiling with ANSI checking turned on If the function is required you will need to compile without the EnableAnsi flag The C Block will not store because there is not a isascii function in the PLC to link with the symbol Issue On some Windows 2000 PCs the local DOS Box Environment path va
177. ons and Masks Used with RACK REFERENCE REC structure Note LIMIT NUM SLOTS PER_RACK amp MAX NUMBER MODULES PER_BUS are defined in model_specifics h define MAX NUM BUSES PER SLOT 2 define REF _RACK SUMMARY FLAG 0x01 define REF_RACK FAILURE FLAG 0x02 Description Returns a pointer to a RACK_REFERENCE_REC structure for the specified rack The RACK_REFERENCE_REC provides a structure to determine the location of faults anywhere in a single rack in the PLC system The following notes provide details on how to use the structure when the return value is assigned to a pointer named pRackRefRec 1 pRackRefRec Rack Flags If bit O is set there is at least one module in the rack system with a fault If bit 1 is set the rack has a fault 2 pRackRefRec Slot Each bit of this 32 bit variable represents 1 of 32 possible slots in the rack If a bit is set 1 it indicates the module in the slot corresponding to the bit number 0 31 has a fault For example if pRackRefRec gt Slot equals 0Ox0000000A modules in slots 1 and 3 have faults because the 1 and 3 bits are set 3 pRackRefRec BusRefs 0 Each bit of this 32 bit variable represents one of two possible for bus 1 or pRackRefRec gt BusRefs 1 busses on 1 of 32 possible slots in the rack The bit is set if any for bus 2 GFK 2259E modules on the bus have a fault For example if a Genius block on bus 1 has a fault for a GBC located in slot 3 the value of pRackRef
178. onstant sweep timer value to the current_value In OutParam pConstSweepTimerRec Pointer to structure containing constant sweep timer record ReturnVal This function returns 1 if successful and 0 if unsuccessful and 1 if not supported PLCC_read_window values GFK 2259E T_INT32 PLCC read window _values struct read window_values rec pReadWindowValuesRec window modes define LIMITED MODE 0 define CONSTANT MODE 1 define RUN_TO COMPLETION MODE 2 structure with return values struct read window values rec T_BYTE controller win_time T_BYTE controller win_mode LIMITED MODE CONSTANT MODE RUN_TO COMPLETION MODE T_BYTE backplane _comm_win_time T_BYTE backplane _comm_win_mode LIMITED MODE CONSTANT MODE RUN_TO COMPLETION MODE T_BYTE background _win_time T_BYTE background_win_mode LIMITED MODE CONSTANT MODE RUN_TO COMPLETION MODE Description This function is the C interface to service request 2 Read Window Values This function will return the mode and time for the controller communications window the backplane communications window and the background task window in the structure Note The Series 90 70 referred to the Controller Communications window as the Programmer Communications window Also the 90 70 referred to the Backplane Communications window as the System Communications Window The possible values for the mode fields are LIMITED_MODE CONSTANT_MODE and R
179. or PACSystems User s Manual January 2012 GFK 2259E GFK 2259E Bit Masks to be Used with Diagnostics These bit masks are defined in ctkRefMem h For access to analog input diagnostic memory H _ALARM_MSK 0x02 LO_ALARM_MSK 0x01 Al_OVERRANGE_MSK 0x08 AI_UNDERRANGE_MSK 0x04 For access to analog output diagnostic memory AQ_OVERRANGE_MSK 0x40 AQ_UNDERRANGE_MSK 0x20 Proc ReadPlicVarOvr extern T_INT32 ReadPlcVarOvr PLC_VAR_REC pVarInfo void pReadOvrTo Description This function reads the override value s for a PLC variable into a buffer provided by the caller InParam pVarinfo Pointer to a PLC_VAR_REC information record for the variable to be read If the variable does not have overrides an error will be returned InParam pReadOvrTo Pointer to the memory location where the override values for the variable should be written Note If pVarlnfo references an array the overrides for the entire array will be read Notes For type BOOL an entire byte will be written to pReadOvrTo with the low bit of the byte containing the override value for the BOOL variable m Foran array of type BOOL the number of bytes written will be total number of elements 7 8 The first override bit will be written to the least significant byte of the first byte For all other types the number of bytes written will be equal to the byte size of the PLC variable Errno If there is an error
180. or non discrete memories where the BYTE variable consumes 16 bits on the PLC the 8 bit value will be written to the least significant 8 bits of the 16 bit word For type STRING the size of the data copied from pWriteFrom will be the max length in the variables declaration ReturnVal GEF_OK if successful GEF_ERROR for bad parameter Use Errno to determine cause Errno If there is an error this function sets Errno to give specific information on what caused the error Applications that use Errno should first call PLCC_ClearErrno to ensure Errno was not already set by another function call Errno can be read using PLCC_GetErrno Errno values are provided in ctkPlcErrno h GFK 2259E Chapter 3 Writing a C Application 3 115 3 116 Proc WritePicArrayVarElement extern T_INT32 WritePlcArrayVarElement PLC_VAR_REC pVarInfo void pWriteFrom T_INT32 numIndices ee Re Description This function writes a single element in a PLC array variable from a buffer provided by the caller InParam pVarinfo Pointer to a PLC_VAR_REC information record for the array containing the element to be written InParam pWriteFrom Pointer to the memory location containing the value to be written to the array element Notes For type BOOL the least significant bit at the byte pointed to by pWriteFrom will be written to the PLC variable array element m For type BYTE an 8 bit value will be read from pWriteFrom For non discrete memories where the BY
181. ord record record record record record record record record record record record record record record record ASCII_tod ASCII_tod ASCII_tod ASCII_tod ASCII_tod ASCII_tod ASCII_tod ASCII_tod ASCII_tod ASCII_tod ASCII_tod ASCII tod ASCII_tod ASCII_tod ASCII_tod ASCII_tod ASCII_tod yearhi yearlo spacel monthhi monthlo space2 QO A rs 0 igi x Nore r day_of_month_hi day_of_month_lo space3 hourshi hourslo colonl minshi minslo colon2 secshi secslo Aa A eae 3 Vel 1 ac ae Vere 0 8 the high byte for the number data record ASCII_tod day of weekhi 0 place TUESDAY 3 plus 30 hex into the lo byte to make the number an ASCII character data record ASCII_tod day of weeklo TUESDAY 0x30 PLCC_tod_clock_rec amp data In OutParam pTodClockRec Pointer to structure containing time of day clock record ReturnVal This function returns 1 if successful 0 if unsuccessful or 1 if not supported 3 60 C Programmer s Toolkit for PACSystems User s Manual January 2012 GFK 2259E PLCC_reset_watchdog_timer PLCC_time_since T_INT32 PLCC_reset_watchdog timer void Description This function is the C interface to service request 8 Reset Watchdog Timer This function will reset the watchdog timer during the sweep When the watchdog timer e
182. ot supported Function does not set errno For NAN input returns NAN respectively For Infinity input returns NAN GFK 2259E Include File Supported C Run Time Library Series 90 C Run Time Library Functions Associated with File Compatibility Notes Issues Errno information and return value exceptions include lt math h gt double exp double expl is not supported float expf float Errno exceptions ERANGE or EDOM are not set by this function and the functions returns NAN when the input is Infinity or NAN The function returns Infinity if the input is Infinity include lt math h gt double fabs double fabsl is not supported float fabsf float Errno amp return exceptions EDOM and ERANGE are not set A Infinity input returns a Infinity value A NAN input returns a NAN value include lt math h gt double floor double floorl is not supported float floorf float Function does not set errno For NAN input returns NAN respectively For Infinity input returns Infinity respectively include lt math h gt double fmod double x double y fmodl is not supported float fmodf float x float y Errno amp return value exceptions EDOM is not set If y 0 the return value is NAN include lt math h gt double frexp double x int y frexpl is not supported Errno sets EDOM for x NAN or Infinity NA _hypot is not supported calculates the hypotenuse NAY tis nt sup
183. ot supported Macros compatible with 90 70 and 90 30 Macros compatible with 90 70 and 90 30 This is read only and the compiler will issue an error if you attempt to write to this memory using this macro GAB_TRANS x not supported not supported not supported GCB_TRANS x GDB_TRANS x not supported GEB_TRANS x not supported Macros compatible with 90 70 and 90 30 This is read only and the compiler will issue an error if you attempt to write to this memory using this macro GBB_TRANS x Macros compatible with 90 70 This is read only and the compiler will issue an error if you attempt to write to this memory using this macro Macros compatible with 90 70 Macro compatible with 90 70 AIB_FAULT is non zero for conditions that set a fault contact or generate a fault entry in the I O fault table such as Overrrange and Underrange Macros compatible with 90 70 Macro not supported by 90 70 Macro not supported by 90 70 New generic memory size function The function returns the memory size based on the RefTable segment selector Errnos TLIB_ERRNO_INVALID_REF_TABLE_ER Target Library Reference Memory Series 90 PLC Library Compatibility Functions amp Macros Notes amp Issues L_SIZE Compatible with the 90 70 but is implemented as a function for P SIZE example 7 define L_SIZE refMemSize L_MEM R_SIZE Compatible with the 90 70 and 90 30 Implemented as a Al SIZE function
184. pecific information on what caused the error Applications that use Errno should first call PLCC_ClearErrno to ensure Errno was not already set by another function call Errno can be read using PLCC_GetErrno Errno values are located in ctkPlcErrno h 3 30 C Programmer s Toolkit for PACSystems User s Manual January 2012 GFK 2259E Proc PLCC_CharsInMessageWriteQ T_INT32 PLCC_CharsInMessageWriteQ T_INT32 port Description Returns the number of bytes in the write queue InParam port Indicates which PLC serial port to query i e PORT1 PORT2 ReturnVal If successful returns the number of bytes in the queue Returns 1 for a bad parameter or if message mode is not configured for the specified port Errno If there is an error Errno is set by this function to give specific information on what caused the error Applications that use Errno should first call PLCC_ClearErrno to ensure Errno was not already set by another function call Errno can be read using PLCC_GetErrno Errno values are located in ctkPlcErrno h Proc PLCC_CharsinMessageReadQ T_INT32 PLCC_CharsInMessageReadQ T_INT32 port Description Returns the number of bytes in the read queue InParam port Indicates which PLC serial port to query i e PORT1 PORT2 ReturnVal If successful returns the number of bytes in the queue Returns 1 for a bad parameter or if message mode is not configured for the specified port Errno If there is an error this f
185. port include lt math h gt double Idexp double x int y Idexpl is not supported Errno set errno to EDOM for x NAN and ERANGE for x Infinity Caution setting y gt 65535 could cause the PLC watchdog to time out include lt math h gt double log double x logl is not supported float logf float x Errno and return exceptions EDOM is not set for a negative input ERANGE is not set for an input of 0 x lt 0 returns NAN x Infinity returns Infinity x 0 returns Infinity x NAN returns NAN respectively include lt math h gt double log10 double x log10I is not supported float log1 Of float x Errno and return exceptions EDOM is not set for a negative input ERANGE is not set for an input of 0 x lt 0 returns NAN x Infinity returns Infinity x 0 returns Infinity x NAN returns NAN respectively GFK 2259E Appendix B C Run Time Library Functions B 3 B 4 Include File Supported C Run Time Library Functions Associated with File include lt math h gt double modf double double include lt math h gt include lt math h gt include lt math h gt include lt math h gt include lt math h gt include lt math h gt double pow double x double y float powf float x float y double sin double float sinf float double sinh double float sinhf float double sqrt double x float sqrtf float x double tan double x float tanf float x
186. r program failure 2 Enable ANSI compatibility Keyword EnableAnsi this causes the compiler to enforce ANSI standards such as the prevention of the use of the double slash for comments An example of a single file compile using these keywords is shown below compileCPACRX myCFile DisableStackCheck EnableAnsi An example of a multiple file compile using these keywords is shown below In a file with the name sources include the following lines CFILENAMES myCFilel c myCFile2 c myCFile3 c flagl DisableStackCheck flag2 EnableAnsi To compile type the following line in the DOS box in the same directory as the sources file CompileCPACRX You can also link pre compiled object files by using the following line in the sources file OFILENAMES myCFile4 plcO Multiple object files can be linked by placing space spaces or TABS between file names In addition the file names can be on separate lines if the continuation slash is added at the end of the line as shown below OFILENAMES myCFile4 plcO myCFile5 plco MyCFile6 plcO The following lines show an example of a sources file that compiles multiple C source files multiple object files and sets compile flags CFILENAMES myCFilel c myCFile2 c myCFile3 c OFILENAMES myCFile4 plcO myCFile5 plcO flagl DisableStackCheck flag2 EnableAnsi PLC object files can be created by using the flag DisableGefLibLink To create myCFile4 plcO in the curre
187. r the accuracy completeness sufficiency or usefulness of the information contained herein No warranties of merchantability or fitness for purpose shall apply indicates a trademark of GE Intelligent Platforms Inc and or its affiliates All other trademarks are the property of their respective owners Copyright 2012 GE Intelligent Platforms Inc All Rights Reserved Contact Information If you purchased this product through an Authorized Channel Partner please contact the seller directly General Contact Information Online technical support and http support ge ip com GlobalCare Additional information http Awww ge ip com Solution Provider solutionprovider ip ge com Technical Support If you have technical problems that cannot be resolved with the information in this manual please contact us by telephone or email or on the web at http support ge ip com Americas Online Technical Support http support ge ip com Phone 1 800 433 2682 International Americas Direct Dial 1 780 420 2010 if toll free 800 option is unavailable Technical Support Email support ip ge com Primary language of support English Europe the Middle East and Africa Online Technical Support http support ge ip com 352 26 722 780 if toll free 800 option is unavailable or if dialing from a mobile telephone Asia Pacific support jp ip ge com ini i 21 3217 4826 su cn i i customercare cn ip ge com China
188. ram pStatus Pointer to status variable see common definition above OutParam pOriginalValue Pointer to the value before the read modify write operation InParam op_type Specifies whether the mask is ANDed or ORed with the data BUS_OR or BUS_AND InParam mask Data mask InParam address Address of the data to be written ReturnVal 1 if successful 0 if unsuccessful 1 if not supported 3 44 C Programmer s Toolkit for PACSystems User s Manual January 2012 GFK 2259E Proc PLCC_BUS_RMW_dword T_INT32 PLCC_BUS_RMW dword T WORD rack T_WORD slot T_WORD subSlot T_WORD region T_WORD pStatus T_DWORD pOriginalValue T_WORD op type T_DWORD mask T_DWORD address Description Read Modify Write a dword to a device on the bus InParam rack The rack number containing the module to access InParam slot The slot number containing the module to access InParam subSlot The sub slot number of the module to access InParam region The region number describing the location of the BUS memory This is set up in hardware configuration for the module OutParam pStatus Pointer to status variable see common definition above OutParam pOriginalValue Pointer to the value before the read modify write operation InParam op_type Specifies whether the mask is ANDed or ORed with the data BUS_OR or BUS_AND InParam mask Data mask InParam address Address of the data to be written ReturnVal 1 if successful 0 if unsucc
189. reference memory taking into account overrides and transition bits The function writes data pointed to by pDestination based on the memory pointed to by pSource The length of data written is determined by the size parameter which is in units of bytes 8 bits Errnos TLIB_ERRNO_INVALID_SOURCE_POINTER Considers pointer and size TLIB_ERRNO_INVALID_DEST_POINTER Considers pointer and size TLIB_ERRNO_READ_ONLY_ER Macros compatible with the 90 70 and 90 30 BIT_TST_GA_TRANS address not supported BIT_TST_GB_TRANS address not supported BIT_TST_GC_TRANS address not supported not supported BIT_TST_GD_TRANS address GFK 2259E GFK 2259E Target Library Reference Memory Functions amp Macros BIT_TST_S_TRANS address BIT_TST_SA_TRANS address BIT_TST_SB_TRANS address BIT_TST_SC_TRANS address IB_TRANS address QB_TRANS address MB_TRANS address address GB_TRANS address B_TRANS address AB_TRANS address BB_TRANS address CB_TRANS address BIT_TST_ _DIAG address BIT_TST_Q_DIAG address IB_DIAG address QB_DIAG address AIB_DIAG address AQB_DIAG address Al_HIALRM address Al_LOALRM address AIB_FAULT address AQB_FAULT address Al_OVERRANGE address Al_UNDERRANGE address AQ_OVERRANGE address AQ_UNDERRANGE address T_DWORD refMemSize T_WORD RefTable Appendix A Target Library Functions Series 90 PLC Library Compatibility Notes amp Issues BIT_TST_GE_TRANS address n
190. rence memory size macros should be used to determine the size of the memory types written within a C application Reads and writes outside of the configured range can result in incorrect data or PLC CPU failure A safer alternative is to use read write PLC functions that perform address boundary checking These functions are WritePlcByte WritePlcWord WritePicInt WritePIcDint PlcMemCopy SetBit ClearBit ReadPlicByte ReadPicWord ReadPicint ReadPlicDint For example a C application is created that takes an index as a single input parameter into the register table The application is designed to index into the register table using the input parameter and copy the located value to the single output location MOVE from source array registers input parameter to output parameter This C application is to be designed so that it may be run on any PACSystems CPU regardless of differing register memory table sizes Example include PACRxPlc h int GefMain T_WORD X1 T_INT16 Y1 if X1 NULL amp amp Y1 NULL if X1 gt R_SIZE Index into registers is too large return ERROR else Index into registers and copy value to output parameter Y1 RI X1 return GEF_EXECUTION_OK else return GEF_EXECUTION ERROR 3 24 C Programmer s Toolkit for PACSystems User s Manual January 2012 GFK 2259E Transition Alarm and Fault Macros Transition alarm and fault bits associ
191. rget Library General Functions Structures and Constants Series 90 PLC Library Compatibility Notes amp Issues T_BYTE hours_lo T_BYTE colon1 T_BYTE minutes_hi T_BYTE minutes_lo T_BYTE colon2 T_BYTE seconds_hi T_BYTE seconds _lo T_BYTE space4 T_BYTE day_of_week_hi T_BYTE day_of_week_lo i define READ_CLOCK 0 define WRITE_CLOCK 1 typedef long int time_t struct timespec time_t tv_sec long int tv_nsec E struct tod_clock_rec T_WORD read_write READ_CLOCK or WRITE_CLOCK T_WORD format NUMERIC_DATA_FORMAT BCD_FORMAT UNPACKED_BCD_FORMAT PACKED_ASCII_FORMAT eh union struct num_tod_rec num_tod struct BCD_tod_rec BCD_tod struct BCD tod 4 rec BCD tod 4 struct unpacked_BCD_rec unpacked_BCD_tod struct unpacked_bcd_tod_4 rec unpacked_BCD_tod_4 struct ASCII tod_rec ASCII_tod struct ascii_tod_4 rec ASCIl_tod_4 struct timespec POSIX_tod T_INT32 PLCC_tod_clock_with_status struct tod_clock_with_status_rec x Not Supported T_INT32 PLCC_reset_watchdog_timer void Compatible with 90 70 and 90 30 libraries Reset Watchdog Timer T_int32 PLCC_time_since_start_of_sweep struct Compatible with 90 70 and 90 30 libraries time_since_start_of_sweep_rec x Read Sweep Time from the Beginning of Sweep struct time_since_start_of_sweep_rec T_WORD time_since_start_of_sweep T_INT32 PLCC_nano_time_since_start_of_sweep struct New function Provides time in nanosecond units n
192. riable is not used resulting in the compile process failing because the path to the compiler batch file is not found Solution The problem can be corrected using the following steps 1 2 3 4 5 Press Start gt Settings gt Control Panel Double click on System Click on the Advanced Tab Click on the Environment Variables button In the System Variables window scroll to the Path variable and click on it to highlight it Press the Edit button Add the following text at the end of the current string lt PACSystemsInstallLocation gt Compilers EIfXx86 lt PACSystemslnstallLocation gt Compilers CommonTools lt PACSystemsinstallLocation gt Targets PACRX Compiler lt PACSystemsinstallLocation gt Targets DebugPACRX Compiler lt PACSystemsinstallLocation gt Targets PACRX3i Compiler lt PACSystemsinstallLocation gt Targets DebugPACRX3i Compiler lt PACSystemsinstallLocation gt Targets PACRX7i Compiler lt PACSystemsinstallLocation gt Targets DebugPACRX7i Compiler lt PACSystemsinstallLocation gt Targets CommonFiles CompilerCommon where lt PACSystemslnstallLocation gt is the location of the C Toolkit installation on your machine For example the default installation location is CAGE Software PACSystemsCToolkit Press OK three times to exit from the System Properties application Reboot your PC C 2 C Programmer s Toolkit for PACSystems User s Manual January 2012 GFK 2259E GFK 2259E A Adding
193. rong parameter refers SP2 error wrong parameter refers an unknown value on the PLC stack refers an unknown value on the PLC stack The unknown values on the PLC stack will be used for y2 and y3 and will cause the C program to write erroneously into PLC memory or cause a page fault The exact location of the write is unpredictable Note Always verify that the number of parameters expected by a block and the number the ladder logic call will pass to that block are the same Always verify that the parameters are not NULL pointers before using Chapter 3 Writing a C Application 3 129 Uninitialized Pointers Use of an uninitialized C pointer variable in your C application can cause catastrophic effects on the PLC It is essential that all pointer variables be correctly initialized prior to use by a C application BAD PROGRAM Uninitialized Pointer intGefMain T_BYTE bad ptr T_INT16 loop Attempt to initialize data area through uninitialized pointer for loop 0 loop lt 10 loop t bad ptr 0 return GEF_EXECUTION_OK All pointer variables in a C application including those used by library functions must be initialized before they are used or unpredictable results will occur The use of an uninitialized pointer may result in the PACSystems logging a fatal fault in the controller fault table and going to STOP HALT mode Uninitialized pointers may also result from a C
194. s value from one sweep to the next sweep and will continue to do so until the PLC goes to stop mode On the transition from stop mode to RUN mode the PLC will re initialize all of the C application s initialized global data to those values in the saved copy of global data start values Recall that the start values were saved when the folder was stored to the PLC The keyword static may be used with either global variables or variables declared inside a function including GefMain These variables will retain their value from sweep to sweep like global data If a static variable is declared with an initial value the variable will be initialized on the first execution from store or on transition from STOP to RUN mode If a static variable is declared without an initial value the initial value is undefined and must be initialized by the C application Note If C blocks are used multiple times in a ladder static or global variables may not contain expected data from sweep to sweep Multiple use blocks must at least receive a unique ID for each call or a unique work area to properly distinguish multiple calls Data Retentiveness GFK 2259E All global variables and static variables are either retentive or non retentive Values of retentive data are preserved across both power cycles assuming a good battery is attached and stop to run transitions Non retentive data is reinitialized on each stop to run transitions using values saved
195. sInMessageWriteQ PLCC_CharsInMessageReadQ T_INT32 PLCC_gen_alarm word char Compatible with the 90 70 and 90 30 libraries Log a user specified application fault in the PLC fault table T_INT32 PLCC_get_plc_version struct PLC_ver_info_rec Compatible with 90 70 and 90 30 libraries Get the PLC family model and firmware version and revision struct PLC_ver_info_rec T_WORD family Host PLC product line T_WORD model Specific Model of PLC T_BYTE sw_ver Major Version of PLC firmware T_BYTE sw_rev Minor Revision of PLC firmware E define FAMILY_PACSYSTEMS 0x2002 GFK 2259E Appendix A Target Library Functions A 17 A 18 Target Library General Functions Structures and Constants T_INT32 PLCC_comm_req struct comm_req_rec x Communications Request struct status_addr T_WORD seg_ selector T_WORD offset E struct comm_req_command_blk_rec T_WORD length T_WORD wait struct status_addr status T_WORD idle_timeout T_WORD max_comm_time T_WORD data 128 iE struct comm_req_rec struct comm_req_command_blk_rec command_blk T_BYTE slot T_BYTE rack T_DWORD task_id E T_INT32 PLCC_comm_req_extended struct comm_req_rec x Communications Request struct status_addr_extended T_WORD seg_ selector T_DWORD offset E struct comm_req_command_blk_rec T_WORD length T_WORD wait struct status_addr_extended status T_WORD idle_timeout T_WORD max_comm_time T_
196. service request 5 Change_Background Window State and Values This function will change the background window state and timer to the values specified in the structure The mode will be changed to one of the three states LIMITED_MODE CONSTANT_MODE or RUN_TO_COMPLETION_MODE depending on the value in the mode field InParam pChangeBackgroundWindowRec Pointer to structure containing background window record The time value should be from 1 to 255 milliseconds ReturnVal This function will return 1 if successful and 0 if unsuccessful 3 52 C Programmer s Toolkit for PACSystems User s Manual January 2012 GFK 2259E PLCC_number_of_words_in_chksm T_INT32 PLCC_number of words in chksm struct number of words _in_chksm_rec pNumberofWordsInChksmRec struct number word of words in chksm_rec T_WORD read set T_WORD word count e define READ CHECKSUM_WORDS 0 define SET_CHECKSUM_ WORDS 1 Description This function is the C interface to service request 6 Change Read Checksum Task State and Number of Words to Checksum This function will either read the current checksum word count or set a new checksum word count depending on the value in read_set If read_set is READ CHECKSUM then the function will read the current word count and return it in word_count If the read_set is SET_ CHECKSUM then the function will set the current word count to word_count rounded to the nearest multiple of 8 To disable the checksums set the word_count
197. ss discrete memory without taking into account corresponding override and transition memory lb x lw x li x ld x Qb x Qw x Qi x Qd x Mb x Mw x Mi x Md x Tb x Tw x Ti x Td x Gb x Gw x Gi x Gd x Sb x Sw x Si x Sd x SAb x SAw x SAi x SAd x SBb x SBw x SBi x SBd x SCb x SCw x SCi x SCd x Note This behavior is different from the Series 90 70 and Series 90 30 C feature Potential consequences E Inputs outputs or internal discrete memory for example M that are overridden forced to a particular state can change to the opposite of the overridden state if a write operation is performed using these macros E Transitions on discrete memory will not be detected potentially affecting transition sensitive logic Alternatives m Use the following functions to write to discrete memory WritePLCByte WritePLCWord WritePLCINT WritePLCDint PLMemCopy SetBit ClearBit WritePLCDouble C Programmer s Toolkit for PACSystems User s Manual January 2012 GFK 2259E The complete set of reference type designators are as follows ae Description l Discrete input references use only for reading reference memory Q Discrete output references use only for reading reference memory M Discrete internal references use only for reading reference memory T Discrete temporary references use on
198. ssue an error if you attempt to write to this memory using this macro Ai address Similar issues as Ib Bi address address Ci address Rl address Macros Compatible with 90 70 and 90 30 All address Macros Compatible with 90 70 L i i i i I I address Wwiadares New Macro to support AW memory Id address Implemented as macro compatible with 90 70 and 90 30 syntax with the exception that the name has been changed from ID to Id However this macro does not respect overrides and does not set corresponding transition bits so the functionality is different than the 90 70 and 90 30 You should use the WritePlcDword function to get the same functionality as the 90 70 and 90 30 see next item l C Programmer s Toolkit for PACSystems User s Manual January 2012 GFK 2259E Target Library Reference Memory Functions amp Macros T_INT32 WritePlcDint T_WORD RefTable T_DWORD offset T_DWORD writeValue Series 90 PLC Library Compatibility Notes amp Issues This function writes to reference memory taking into account overrides and transition bits Reference memory in the specified Reference Table RefTable and at the specified offset is written with the writeValue as a 32 bit signed integer If the offset is out of range no reference memory values are changed and the function returns GEF_ERROR If the offset is within range the function returns GEF_OK
199. string h gt String Manipulation Internationalization include lt time h gt Time include lt ctype h gt Character Classification and Conversion A list of the C Run Time library functions supported by the PACSystems is provided in Appendix B The paths to these include files are set up when the C compiler runs therefore the full paths are not required in the include file names After including the appropriate header files you can write a C block using library calls as needed to implement the desired functionality The C Block file or set of C Block files must have one and only one function titled GefMain to act as the entry point A brief example is shown in Figure 3 1 GFK 2259E Chapter 3 Writing a C Application 3 3 3 4 myCFile c include lt stdio h gt include lt PACRXPlc h gt T_INT32 status T_INT32 status2 1 T_INT32 failCount 0 T_INT32 GefMain T_INT16 x1 T_INT16 y1 if x1 0 RW 10 x1 write x1 to R10 as word return GEF_EXECUTION_OK else status GEF_EXECUTION_ERROR status2 failCount failCount return status Figure 3 1 Example C Block Source File The input parameters to the main block x1 and y1 are derived from the input output parameters in the ladder program that calls the C Block Input parameters are always passed as pointers An example is shown below CALL 100001 CBLOCK 00001 Roo001 Figure 3 2 Invoking
200. successful 0 if unsuccessful 1 if not supported PLCC_read_folder_name 3 62 T_INT32 PLCC read _folder_name struct read folder name rec pReadFolderNameRec struct read folder name char folder name MAX FOLDER NAME LENGTH NULL terminated define MAX FOLDER NAME LENGTH 32 Description This function is the C interface to the PLC similar to service request 10 Read Folder Name which only supports a folder name length of 8 characters including NULL terminator This function supports 32 characters which includes one NULL terminator character This function will return the application folder name as a NULL terminated string OutParam pReadFolderNameRec Pointer to structure containing the folder name ReturnVal The function will return 1 if successful and 0 if unsuccessful C Programmer s Toolkit for PACSystems User s Manual January 2012 GFK 2259E PLCC_read_PLC_ID T_INT32 PLCC read PLC ID struct read PLC_ID rec pReadPlcIdRec struct read PLC_ID rec char PLC_ID 8 Description This function is based on service request 11 Read PLC ID The function returns the name of the PACSystems controller in ASCII OutParam pReadPlicldRec Pointer to structure containing the PLC Id ReturnVal The function will return 1 if successful and 0 if unsuccessful PLCC_read_PLC_state T_INT32 PLCC read PLC _state struct read PLC state rec pReadPLCStateRec struct read PLC state _rec T_WORD sta
201. t is 1 based For example Reffable R_MEM and offset 1 accesses R00001 ReturnVal The value read from the specified reference table at the specified offset Errno If there is an error this function sets Errno to give specific information on what caused the error Applications that use Errno should first call PLCC_ClearErrno to ensure Errno was not already set by another function call Errno can be read using PLCC_GetErrno Errno values are located in ctkPlcErrno h Chapter 3 Writing a C Application 3 95 PicMemCopy T_INT32 PlcMemCopy void pDestination void pSource T_DWORD size Description This function copies values from one PLC memory location to another taking into account overrides and transition bits if the destination address is in one of the discrete memory tables The length of data written is determined by the size parameter which is in units of bytes 8 bits InParam pDestination Pointer to a PLC memory location to be written InParam pSource Pointer to PLC memory to be copied into pDestination memory InParam size Indicates the number of bytes to copy ReturnVal If one of the pointers to memory is a null pointer the function returns GEF_ERROR In addition if the source or destination is a reference table and the size causes the copy operation to go outside the boundaries of the specified table the function also returns GEF_ERROR If the write operation is successful the function returns G
202. tandard Library Routines 00 cccceesseceeececeeeeeeeaeeeeeeeeneeeceaeeeeaaeseeaeeseeeeseaeeeeaaesseneeesaeey 3 27 Application Considerations cc ccccccceeseeeeeeeeeeeeeceaeeeeaaeeeeaeeseaeeesaaeeseaaeseeeeeeneeesaeeees 3 123 Debugging and Testing C Applications cecccceseeeeeeeseeeeeeeeseneeeeeeeeeeeeeenseeneeeeseeeeey 4 1 Testing C Applications in the PC Environment cccccccecceceeeeeeseeeeeeeeeeeeeseaeeeeeeeeeeees 4 1 Debugging C Applications in the PLC 0 c cecccccseeeeeneeeeeeeseeeeeeeaeeeeaeeseeeeeseaeeeseaeeneneeeeaees 4 4 Conversion Notes and Series 90 Compatibility eccccessseeeeneeeneeeeseeeeeeeseseeneeeeseeneeseeeees 5 1 Series 90 Compatibility Header Files PLCC9070 h and PLCC9030 N seeeeeees 5 1 Writing Directly to Discrete Memory ccsceceeeeeeeeeeeeeeeceeeeeceaeeeeaaeeeeaeeseeeesaeeeeeeseeeeess 5 2 PLC Target Library Function Compatibility ISSUCS 0 cccecececeeeeeeeeeseeeeeseeeeeeaeeeeeeeeeaees 5 3 Compatibility Issues with Retentive Global Variables ccccesceceeeeeeeeeeeeeeeeneeeeeeees 5 4 Int TYPE SSeS eiiron stasis teres che contd a o Meas Os oS at Mee Oe ett etl 5 4 ENUM TYPC ISSUCS er etase keee AEE Eer aE die E Ae AENA AEE ERE EREE aasetenbive 5 4 Non Standard C Library Functions cccccceceeeeeeeeeeeeeeeeeeeecaeeesaaeseeeeeseeeesaeeesaeeeeeeeeeas 5 5 Enty Pointe ccc edes cs a E EEA eee ee A cee ee cca AEE a 5 5 C Standalon
203. te define RUN_DISABLED 1 define RUN_ENABLED 2 Description This function is based on service request 12 Read PLC Run State This function returns the PLC run state RUN_DISABLED or RUN_ENABLED OutParam pReadPicStateRec Pointer to structure containing the PLC state ReturnVal The function will return 1 if successful and 0 if unsuccessful GFK 2259E Chapter 3 Writing a C Application 3 63 PLCC_shut_down_plc T_INT32 PLCC_shut_down_plc T_ WORD numberOfSweeps Description This function is the C interface to service request 13 Shut Down Stop PLC The function stops the PLC at the end of the current sweep if numberOfSweeps is equal to 0 All outputs go to their designated default states at the beginning of the next sweep and the STOPPED by SVC 13 information fault will be logged in the controller fault table The numberOfSweeps parameter determines the number of full sweeps that should occur before shutting down the PLC This is normally set to 0 InParam numberOfSweeps Number of full sweeps that should occur before shutting down the PLC This is normally set to 0 ReturnVal The function will return 1 if successful and 0 if unsuccessful 3 64 C Programmer s Toolkit for PACSystems User s Manual January 2012 GFK 2259E PLCC_mask_lO_interrupts T_INT32 PLCC_mask_IO interrupts struct mask_IO interrupts rec pMaskIoInterruptsRec struct mask_IO_interrupts_rec T_WORD mask T_WORD memory type T_WORD me
204. ted to the following 1 Integer divide by 0 2 Stack overflow 3 Page fault When a runtime error is logged into the controller fault table the fault will contain a text message describing the error An example of a runtime error and the resulting controller fault is illustrated in the following C application Dvo c Example include PACRxPlc h int GefMain T_INT32 x 3 y 0 return x y The faults logged in the CPU and displayed by Machine Edition software appear as follows Fault Description Program runtime error Fault Extra Data in ASCII format Div by 0 C Application Impact on PLC Memory 3 134 As displayed on the PC the size of a gefElf output file is the relocate able image When the C application is stored to the CPU the CPU must allocate more memory than merely the gefElf size The additional space allocated by the CPU includes 1 The located executable image of the gefElf file 2 The saved the initial values of C application global data initialized global data 3 Pertinent information regarding the C application internal processing overhead 4 A copy of the original gefElf file One method of determining the PLC memory usage is to view the status dialog in the programmer and note the Program Logic usage of the folder stored without the C Block and the same folder stored with the C Block C Programmer s Toolkit for PACSystems User s Manual January 2012 GFK 2259E Bloc
205. terrupts_ext_rec T WORD action SUSPEND or RESUME T WORD memory type Address of the interrupt trigger T_DWORD memory offset extern T_INT32 PLCC sus_res_interrupts_ext struct sus_res_interrupts_ext_rec pSusResInterruptsExtRec Possible values for the action element define SUSPEND 1 define RESUME 0 Valid memory type define PLCVAR_MEM 262 for use with Variables define IBIT 70 define AIMEM10 All offsets are 1 based I1 1 12 2 tAI1 1 SAI2 2 Discrete offsets and lengths are in bits and must be byte aligned 1 9 17 25 are valid for offsets 2 8 10 16 18 24 are invalid for offsets Analog offsets and lengths must be in words Description This function is based on the SUSP_IO_INTR function block It is used to suspend or resume an I O interrupt Currently it is supported only for High Speed Counter This function provides PLC variable access along with reference addresses having 32 bit offset as input Memory type and offset specify the address of an input interrupt trigger on an input module that supports interrupts To specify a PLC variable as an input to a routine use the PLC_VAR_MEM memory type and the address of the variable record as the offset For details on the use of PLC_VAR_MEM see page 3 86 When used for reference addresses all offsets are 1 based l1 1 l2 2 Al1 1 AI2Z 2 Discrete offsets and lengths are in bits and must be byte ali
206. ters to this function will put the CPU into CPU Halted mode int stremp const char const char This function does not set errno Note NULL or invalid input pointers to this function will put the CPU into CPU Halted mode char strcpy char const char This function does not set errno Note NULL or invalid input pointers to this function will put the CPU into CPU Halted mode size_t strcspn const char const This function does not set errno char Note NULL or invalid input pointers to this function will put the CPU into CPU Halted mode GFK 2259E Include File Supported C Run Time Library Functions Associated with File include lt string h gt char strerror_r int errorcode char stringBuffer include lt string h gt size_t strlen const char aan eee include lt string h gt char strncat char const char size_t include lt string h gt int strncmp const char const char size_t include lt string h gt char strncpy char const char size_t a a E include lt string h gt char strpbrk const char const char include lt string h gt char strrchr const char int lt C lt I GFK 2259E Appendix B C Run Time Library Functions Series 90 C Run Time Library Compatibility Notes Issues Errno information and return value exceptions strerror and _strerror are not supported since they are not re entrant Description This routine maps
207. th this declaration a single word is read written ReadPlcArrayVarElement and WritePlcArrayVarElement called with this declaration would return an error Example 4 For an array of custom structures named mainValves with a member flowRate PLC_VAR mainValveFlowRateRec mainValves 3 4 flowRate Members of structures must be accessed independently Declaring a PLC_VAR with only mainValves or mainValves 3 4 will result in an error when attempting to store logic PLC Var C Types typedef typedef typedef typedef typedef typedef typedef typedef T BYTE T_WORD T_INT16 T_UINT16 T_DWORD T_INT32 float T_BOOLEAN PLC_VAR_BYTE PLC_VAR_WORD PLC_VAR_INT PLC_VAR_UINT PLC_VAR_DWORD PLC_VAR_DINT PLC_VAR_REAL PLC_VAR_BOOL This should be used for a single BOOL variable only PLC_VAR_BYTE should be used for arrays of BOOLs because the bits are packed into bytes 3 106 C Programmer s Toolkit for PACSystems User s Manual January 2012 GFK 2259E Routines GFK 2259E Proc ReadPlicVar extern T_INT32 ReadPlcVar PLC_VAR_REC pVarInfo void pReadTo Description This function reads the value of a PLC variable into a buffer provided by the caller InParam pVarinfo Pointer to a PLC_VAR_REC information record for the variable to be read InParam pReadTo Pointer to the memory location where the value of the variable to be read should be located Note If pVarlnfo references an array the en
208. the Toolkit to function incorrectly To install the Toolkit 1 Execute the setup exe file 2 Click the Next button The next installation screen displays the default location where the Toolkit will be installed C GE Software PACSystemsCToolkit You can change the install directory either by entering a directory path or by browsing to the desired directory 3 Click the Next button The install program prompts you to create the installation directory if necessary The install program then asks if you want to proceed with the installation in the designated directory 4 To complete the installation click the Start button The install package installs the software and user documentation components in the designated directory The installation program also installs an icon on your desktop el When this operation is complete the final installation screen is presented This screen provides the option for viewing the PACSystem readme txt which presents important start up information C Toolkit Click Next 6 To exit the installation program click the Exit button This launches the Toolkit which brings up a DOS box in the user project area From the DOS box you can navigate to your project directories and compile C files The initial screen will be similar to the example shown below cx PACSystems TM C Toolkit Toolkit Release 7 66 Toolkit Build Number 37D1 Microsoft Windows XP Version 5 1 2666 lt C Copyright 19
209. the block using the pointer x1 to read a 32 bit floating point value which starts at R1 the value used in the ladder logic The 32 bit floating point value starting at R1 includes both R1 and R2 but R2 is the reference specified in ladder logic as x2 Since the input variables overlap unpredictable values will result from the execution of this block Notice also that the output parameters will have a similar problem Parameter Ordering Errors Execution errors can also occur due to differences in the order of the parameters when calling a block and the order of the parameters in the block declaration of GefMain Continuing with the same example if the ladder logic is unchanged but GefMain is declared as follows an execution error will occur int GefMain T_INT16 xl T_INT16 yl T_INT16 x2 T_INT16 y2 No error message will be generated just unpredictable output values The execution error occurs because ladder logic always passes all of the specified input parameters in top to bottom order followed by all of the specified output parameters also in top to bottom order In this case the ladder logic passes R1 R2 P1 and P2 the two input parameters followed by the two output parameters The block associates the parameters from the ladder logic call with its own variable names as in the following example T_INT16 xl refers to R1 T_INT16 yl refers to R2 T_INT16 x2 refers to P1 T_INT16 y2 refers t
210. tire array will be read Notes For type BOOL an entire byte will be written to pReadTo with the low bit of the byte containing the value of the BOOL variable The remaining seven bits are zero filled m Foran array of type BOOL the number of bytes written will be total number of elements 7 8 The first bit will be written to the least significant bit of the first byte The data written will be byte aligned even if the PLC variable is not Bits that are not part of the array are zero filled For type BYTE an 8 bit value will be written to pReadTo BYTEs mapped to non discrete memories such as R or W consume 16 bits on the PLC but will be packed when written to pReadTo by this routine For type STRING the size in bytes of the data written to pReadTo will be the max length in the variables declaration on the PLC ReturnVal GEF_OK if successful GEF_ERROR for bad parameter Use Errno to determine cause Errno If there is an error this function sets Errno to give specific information on what caused the error Applications that use Errno should first call PLCC_ClearErrno to ensure Errno was not already set by another function call Errno can be read using PLCC_GetErrno Errno values are located in ctkPlcErrno h Chapter 3 Writing a C Application 3 107 3 108 Proc ReadPlicArrayVarElement extern T_INT32 ReadPlcArrayVarElement PLC_VAR_REC pVarInfo void pReadTo T_INT32 numIndices EER a Description This
211. to 0 The function will fail if the read_write field is set to a value other than 0 or 1 InParam pNumberOfWordsInChksmRec Pointer to structure containing number of words in checksum record ReturnVal This function will return 1 if successful and 0 if unsuccessful GFK 2259E Chapter 3 Writing a C Application 3 53 3 54 PLCC_tod_clock T_INT32 PLCC_tod_clock struct tod_clock_rec pTodClockRec Data Formats This function supports the following data formats define define define define define define define define define NUMERIC_DATA_FORMAT BCD_FORMAT UNPACKED _BCD_FORMAT PACKED _ASCII_FORMAT POSIX_FORMAT amp WNHER O NUMERIC_DATA FORMAT 4 DIG YR BCD FORMAT 4 DIG YR UNPACKED BCD FORMAT 4 DIG YR PACKED _ASCII_FORMAT 4 DIG YR Day of the Week Definitions define define define define define define define SUNDAY MONDAY TUESDAY WEDNESDAY THURSDAY FRIDAY SATURDAY NOU PWNHEH NUMERIC_DATA_FORMAT Decimal values for fields For example year field struct num tod rec T_WORD year T_WORD month T_WORD day of month T_WORD hours T_WORD minutes T_WORD seconds T_WORD day of week C Programmer s Toolkit for PACSystems User s Manual January 2012 0x80 0x81 0x82 0x83 94 for the year would be 94 decimal in the GFK 2259E BCD_FORMAT Hexadecimal values for the fields For example 94 for the year would be 0x94 struct BCD_tod_rec T_ BYTE year
212. unction sets Errno to give specific information on what caused the error Applications that use Errno should first call PLCC_ClearErrno to ensure Errno was not already set by another function call Errno can be read using PLCC_GetErrno Errno values are located in ctkPlcErrno h GFK 2259E Chapter 3 Writing a C Application 3 31 PLCC_gen_alarm T_INT32 PLCC_gen_alarm T WORD error code char fault_ string Description This function puts the fault described by error_code and fault_string into the controller fault table InParam error_code Indicates the user specified error that is to be logged The error code must be less than 2048 InParam fault_string Pointer to a character string describing the fault String must be NULL terminated and less than 24 characters ReturnVal This function will return 0 if successful and 1 if unsuccessful 3 32 C Programmer s Toolkit for PACSystems User s Manual January 2012 GFK 2259E PLCC_get_plc_version T_INT32 PLCC_get_ plc _version struct PLC_ver_info_rec PLC_ver info ALL DATA RETURNED FROM THE PLC in the structure PLC_ver_info NEEDS TO BE LOOKED AT IN HEXADECIMAL struct PLC _ver_info rec T_WORD family T_WORD model T_BYTE sw_ver T_BYTE sw_rev he Family value define FAMILY PACSYSTEMS 0x2002 Model numbers define define define define define define define define CPE_010 CPE_020 CRE_020 CPE_030 CPE_040 CPU_310
213. up role of each Ethernet interface that is configured for redundant IP operation This service request sends a role switch command to all Ethernet interfaces in the PLC that are configured for redundant IP operation When a redundancy role switch occurs the backup CPU becomes active and begins responding to the Redundant IP address in addition to its direct IP address The formerly active CPU switches to backup and stops communicating on the network using the Redundant IP address PLCC_set_application_redundancy_mode has no effect on Ethernet interfaces that are not configured for redundant IP operation For information on Ethernet redundancy operation refer to the Ethernet TCP IP Communications for PACSystems User s Manual GFK 2224 InParam mode The requested redundancy mode Use 0 for backup mode or 1 for active mode ReturnVal This function will return 1 if successful and 0 if unsuccessful 3 72 C Programmer s Toolkit for PACSystems User s Manual January 2012 GFK 2259E Fault Table Service Request Functions GFK 2259E The following functions access the fault table These functions are defined in ctkPlcFault h The following definitions and structures are common to the Fault Table Service Request Functions tdefine NUM_LEGACY PLC FAULT ENTRIES 16 tdefine NUM_LEGACY IO FAULT ENTRIES define PLC_FAULT_TABLE 0 define IO FAULT TABLE 1 tdefine PLC_EXT FAULT TABLE 0x80 define IO EXT FAULT TABLE 0x81
214. urth parameter determines if the byte is written to the most or least significant byte if using a word reference Since the write occurs to a discrete reference the parameter is unused If the RefTable or address are out of range no reference memory values are changed and the function returns GEF_ERROR If the RefTable and address are within range the function returns GEF_OK The prototype for this function is shown below T_INT32 WritePlcByte T_ WORD RefTable T_DWORD address T_BYTE writeValue T BOOLEAN msbByte b Reading a discrete reference Here is an example of Series 90 C code MyVarl IB 1 Because this is a read operation that does not need to take into account override and transition bits you have the choice of using a macro or a function call to get the same functionality as the Series 90 PLC Macro MyVarl Ib 1 MyVarl ReadPlcByte I MEM 1 FALSE 5 2 C Programmer s Toolkit for PACSystems User s Manual January 2012 GFK 2259E c Using test bit bit set or bit clear functions In this case there is no coding change from Series 90 to the PACSystems because a function is implemented using the same syntax as the macro The function carries out the proper behavior with respect to overrides and transition bits From a reuse standpoint the macro call looks exactly the same as the function call so there is no coding change required For example the following 90 70 C code does
215. us T_DWORD pBuffer T_DWORD address Description Read a dword from a device on the bus InParam rack The rack number containing the module to access InParam slot The slot number containing the module to access InParam subSlot The sub slot number of the module to access InParam region The region number describing the location of the BUS memory This is set up in hardware configuration for the module OutParam pStatus Pointer to status variable see common definition above OutParam pBuffer Pointer to the dword read in from a device on the bus InParam address Address of the dword to be read ReturnVal 1 if successful 0 if unsuccessful 1 if not supported GFK 2259E Chapter 3 Writing a C Application 3 37 Proc PLCC_BUS_read_block T_INT32 PLCC_BUS_read_block T_WORD rack T_WORD slot T_WORD subSlot T_WORD region T_WORD pStatus void pBuffer T WORD length T_DWORD address Description Read a block from a device on the bus InParam rack The rack number containing the module to access InParam slot The slot number containing the module to access InParam subSlot The sub slot number of the module to access InParam region The region number describing the location of the BUS memory This is set up in hardware configuration for the module OutParam pStatus Pointer to status variable see common definition above OutParam pBuffer Pointer to the data area to put the data InParam length S
216. user defined number of fault entries Constants defines define MY_PLC_FLT_TBL_SIZE 64 define MY_IO_FLT_TBL_SIZE 64 Structures and typedefs Note this structure must be packed pragma pack 1 struct my_read_ext_fault_tables_rec T_WORD table PLC_EXT_FAULT_TABLE or IO_EXT_FAULT_TABLE Y T_WORD start_index T_WORD number_of_entries_to_read T_WORD reserved 12 struct time_stamp_rec time_since_clear T_WORD num_faults_since_clear T_WORD num_faults_in_queue T_WORD num_faults_read T_WORD PlicName 16 union struct PLC_ext_fault_entry_rec PLC_faults MY_PLC_FLT_TBL_SIZE struct O_ext_fault_entry_rec O_faults MY_IlO_FLT_TBL_SIZE faultEntry pragma pack Variable Declaration and Calling Example struct my_read_ext_fault_tables_rec readExtFaultTablesRec PLCC_read_ext_fault_tables struct read_ext_fault_tables_rec amp readExtFaultTablesRec C Programmer s Toolkit for PACSystems User s Manual January 2012 Compatible with 90 70 and 90 30 This function is not described in the Series 90 C Toolkit Users Manual but is included in the 90 70 C Toolkit header file This is included in the PACSystems C Toolkit for compatibility This function maps to service request 20 in the PACSystems Since the size of the extended fault table can be variable Depending on the model of the PACSystems CPU you will need to create you own structure with the same members and di
217. ust be used on the PLC These functions are provided by the C Toolkit and compiled and linked with your C Block during the PC compilation process After compiling and linking the C block you can then run the application using the Cygwin environment to simulate and debug the application GFK 2259E The following steps describe how to debug an application on the PC 1 Create C Test driver code that initializes memory pointers and calls the C Block to be tested An example is given below C PC Driver code ctkPcDriver c include PACRXPlc h For any PACSystems PLC For RX3i use PACRX3iPLC h For Rx7i use PACRx7iPLC h include ctkInitCBlock h declare GefMain as external function in another file extern int GefMain T_WORD pR8 T_BYTE pI1000 T_BYTE pM500 int main int argc char argv initCBlock creates ref mem and initializes pointers to that memory GefMain amp RW 8 amp Ib 1000 amp Mb 500 calling main passing pointers to R8 I1000 and 3M500 return 0 To avoid having to remove or bypass this code when compiling for the PLC it is recommended that this code reside in another C source file and then compiled with the C Block under test 2 Create your C Block application An example is shown below myCBlock c include lt stdio h gt include lt PACRXPIc h gt T_INT32 status T_INT32 failCount 0 int GefMain T_WORD pR8 T_ BYTE pI1000 T_BYTE pM50
218. valid input pointer to this function will put the CPU into CPU Halted mode This function does not set errno Note NULL or invalid input pointers to this function will put the CPU into CPU Halted mode This function does not set errno Note NULL or invalid input pointers to this function will put the CPU into CPU Halted mode _memicmp compares characters in two buffers case insensitive is not supported This function does not set errno Note NULL or invalid input pointers to this function will put the CPU into CPU Halted mode This function does not set errno Note NULL or invalid input pointer to this function will put the CPU into CPU Halted mode B 9 Include File Supported C Run Time Library Functions Associated with File include lt GefCLib h gt void _swab char source char destination int nbytes include lt PLCC9070 h gt _fmemchr fmemcmp _fmemepy _fmemmove _fmemset include lt PLCC9030 h gt _fmemchr fmemcmp _fmemepy _fmemmove _fmemset So i include lt string h gt Internationalization int strcoll const char const char include lt time h gt Time Internationalization size_t strftime char _s size_t _maxsize const char _fmt const struct tm _t C Programmer s Toolkit for PACSystems User s Manual January 2012 Series 90 C Run Time Library Compatibility Notes Issues Errno information and return value exceptions _swab swap nbytes b
219. w these rules could result in compilation or store errors and possibly incorrect operation 3 2 C Programmer s Toolkit for PACSystems User s Manual January 2012 GFK 2259E C Applications in the PACSystems Environment Developing a C Block For PACSystems there is only one type of C Block and this block can be re entrant if re entrant guidelines are followed C Block source code is written using a text editor of choice with restrictions as outlined at the beginning of this chapter In order to use the Target Library functions and macros you must use one of the following lines at top of the C file include lt PACRXPlc h gt For C blocks that run on any PACSystems PLC include lt PACRX7iPlc h gt For C blocks that use features only available on an RX7i include lt PACRX3iPlc h gt For C blocks that use features only available on an RX3i Note In the 90 70 there are two types of C blocks C BLK amp C FBK The C BLK type cannot be re entrant but can make use of the C Run Time library The C FBK can be re entrant but cannot use the C Run Time library A list of the Target Library functions and macros are listed in Appendix A To use the C Run Time Library functions you must include one of more of the following files as appropriate at the top of the C file include lt stdio h gt Input Output include lt math h gt Math include lt stdlib h gt Math Data Conversion Search include lt
220. xpires the PLC shuts down without warning This function allows the timer to be refreshed during a time consuming task ReturnVal This function will return 1 if successful and 0 if unsuccessful Be careful resetting the watchdog timer It may affect the process start_of_sweep GFK 2259E T_INT32 PLCC_time_ since start_of sweep struct time_since start_of sweep rec pTimeSinceStartofSweepRec struct time since start_of sweep _rec T_WORD time_since_start_of sweep he Description This function is the C interface to service request 9 Read Sweep Time from Beginning of Sweep The function will read the time in milliseconds from the beginning of the sweep InParam pTimeSinceStartOfSweepRec Pointer to structure containing the time since the start of sweep ReturnVal The function will return 1 if successful and 0 if unsuccessful Chapter 3 Writing a C Application 3 61 PLCC_nano_time_since_start_of_sweep T_INT32 PLCC_nano time since start_of sweep struct nano _time_since start _of_sweep_rec pNanoTimeSinceStartOfSweepRec struct nano time since start_of sweep rec T_DWORD time_since start _of_sweep Description Read Sweep Time from the Beginning of Sweep in nanosecond units This service request will get the time in nanoseconds since the start of the sweep InParam pNanoTimeSinceStartOfSweepRec Pointer to structure containing the time in nanoseconds since the start of sweep ReturnVal 1 if
221. y another function call Errno can be read using PLCC_GetErrno Errno values are located in ctkPlcErrno h C Programmer s Toolkit for PACSystems User s Manual January 2012 GFK 2259E slotX GFK 2259E T_DWORD slotX T_BYTE rackNumber T_DWORD slotNumber Description Returns the fault bit for the specified slot and rack in the least significant bit InParam rackNumber Indicates which rack to use to get the fault bit rackNumber is 0 based and the maximum number of racks is specified in model_specifics h InParam slotNumber Indicates which slot to use to get the fault bit slotNumber is 0 based and the maximum number of racks is specified in model_specifics h ReturnVal Returns the fault bit for the requested rack and slot in bit 0 Errno If there is an error this function sets Errno to give specific information on what caused the error Applications that use Errno should first call PLCC_ClearErrno to ensure Errno was not already set by another function call Errno can be read using PLCC_GetErrno Errno values are located in ctkPlcErrno h Chapter 3 Writing a C Application 3 99 blockX T_DWORD blockX T_BYTE rackNumber T_DWORD slotNumber T_DWORD busNumber T_DWORD sbaNumber Description Returns the module fault reference bit for a particular block on the bus in the least significant bit InParam rackNumber Indicates which rack to use to get the module fault reference bit rackNumber is 0 based and the maximu
222. ytes from the source buffer swaps even and odd bytes and copies the result to the destination buffer where buffers do not have to be aligned on even byte boundaries If nbytes is not an odd number the function will swap nbytes 1 Supported in GefCLib h with the following statement define _swab uswab This function does not return errno Note NULL or invalid input pointers to this function will put the CPU into CPU Halted mode _fmemchr _fmemcmp _fmemcpy _fmemmove _fmemset These functions are far pointer versions of functions without the _f prefix Since far pointer versions are not needed for a 32 bit architecture PLCC9070 h equates these functions to the primary functions with the following type of statement define_fmemcpy memcpy _fmemchr _fmemcmp _fmemcpy _fmemmove _fmemset These functions are far pointer versions of functions without the _f prefix Since far pointer versions are not needed for a 32 bit architecture PLCC9030 h equates these functions to the primary functions with the following type of statement define_fmemcpy memcpy _fmemccpy _fmemicmp These functions are not supported This function does not return errno Note NULL or invalid input pointers to this function will put the CPU into CPU Halted mode This function does not return errno Note NULL or invalid input pointers to this function will put the CPU into CPU Halted mode GFK 2259E Inclu
Download Pdf Manuals
Related Search
Related Contents
ORDINATEUR DE PLONGÉE MANUEL D`UTILISATION Samsung CE104VD-B User Manual PXU Temperature/Process Controller Installation Hitachi Mobile DeskTop CP-X300 Tricity Bendix SB 410 User's Manual Samsung Galaxy Camera WiFi PH71 Personal pH Meter TC)SH`BA 東芝ネオポールシャンデリア取扱説明書 保管用 8041214 Copyright © All rights reserved.
Failed to retrieve file