Omron NJ501-1500 Reference Manual

Omron NJ501-1500 Reference Manual

Machine automation controller nj-series
Hide thumbs Also See for NJ501-1500:
Table of Contents

Advertisement

Machine Automation Controller
NJ-series
Instructions Reference Manual
NJ501-1300
NJ501-1400
NJ501-1500
W502-E1-01

Advertisement

Table of Contents
loading

Summary of Contents for Omron NJ501-1500

  • Page 1 Machine Automation Controller NJ-series Instructions Reference Manual NJ501-1300 NJ501-1400 NJ501-1500 W502-E1-01...
  • Page 2 OMRON. No patent liability is assumed with respect to the use of the information contained herein. Moreover, because OMRON is constantly striving to improve its high-quality products, the information contained in this manual is subject to change without notice.
  • Page 3: Introduction

    For programming, this manual is intended for personnel who understand the programming language specifications in international standard IEC 61131-3 or Japanese standard JIS B3503. Applicable Products This manual covers the following products. • NJ-series CPU Units • NJ501-1300 • NJ501-1400 • NJ501-1500 NJ-series Instructions Reference Manual (W502)
  • Page 4: Relevant Manuals

    Relevant Manuals Relevant Manuals There are three manuals that provide basic information on the NJ-series CPU Units: the NJ-series CPU Unit Hardware User’s Manual, the NJ-series CPU Unit Software User’s Manual (this manual), and the NJ-series Instructions Reference Manual. Most operations are performed from the Sysmac Studio Automation Software. Refer to the Sysmac Stu- dio Version 1 Operation Manual (Cat.
  • Page 5: Manual Configuration

    Manual Configuration Manual Configuration NJ-series CPU Unit Hardware User’s Manual (Cat. No. W500) Section Description Section 1 This section provides an introduction to the NJ-series Controllers and their features, Introduction and gives the NJ-series Controller specifications. Section 2 This section describes the system configuration used for NJ-series Controllers. System Configuration Section 3 This section describes the parts and functions of the configuration devices in the NJ-...
  • Page 6 Manual Configuration NJ-series Instructions Reference Manual (Cat. No. W502) (This Manual) Section Description Section 1 This section provides a table of the instructions that are described in this manual. Instruction Set Section 2 This section describes instruction specifications in detail. Instruction Descriptions The appendices provide a table of error codes and other supplemental information to Appendices...
  • Page 7: Sections In This Manual

    Sections in this Manual Sections in this Manual Instruction Set Instruction Descriptions Appendices Index NJ-series Instructions Reference Manual (W502)
  • Page 8 Sections in this Manual NJ-series Instructions Reference Manual (W502)
  • Page 9: Table Of Contents

    CONTENTS CONTENTS Introduction....................... 1 Relevant Manuals...................... 2 Manual Configuration....................3 Sections in this Manual.................... 5 Read and Understand this Manual ................ 15 Safety Precautions ....................19 Precautions for Safe Use ..................20 Precautions for Correct Use .................. 21 Regulations and Standards ................... 22 Unit Versions......................
  • Page 10 CONTENTS OutABit ........................2-57 Sequence Control Instructions ....... . .2-59 End ..........................
  • Page 11 CONTENTS AryMean ........................ 2-201 ArySD ........................2-203 ModReal ........................ 2-205 Fraction ......................... 2-207 CheckReal ......................2-209 BCD Conversion Instructions ....... . . 2-211 **_BCD_TO_*** .....................
  • Page 12 CONTENTS AryMove ........................ 2-335 Clear ........................2-337 Copy**ToNum (Bit String to Signed Integer) ............2-339 Copy**To*** (Bit String to Real Number) ............... 2-341 CopyNumTo** (Signed Integer to Bit String) ............2-343 CopyNumTo** (Signed Integer to Real Number) ..........2-345 Copy**To*** (Real Number to Bit String) ............... 2-347 Copy**ToNum (Real Number to Signed Integer) ..........
  • Page 13 CONTENTS StringCRCCCITT ....................2-508 StringCRC16 ......................2-510 AryLRC_** ......................2-512 AryCRCCCITT ....................... 2-514 AryCRC16 ......................2-516 Text String Instructions ........2-519 CONCAT .......................
  • Page 14 CONTENTS ResetPLCError ...................... 2-619 GetPLCError ......................2-622 ResetCJBError ...................... 2-624 GetCJBError ......................2-626 GetEIPError ......................2-628 ResetMCError ....................... 2-630 GetMCError ......................2-634 ResetECError ......................2-636 GetECError ......................2-637 SetInfo ........................2-639 ResetUnit ....................... 2-641 GetNTPStatus ....................... 2-645 Communications Instructions ....... . .2-647 ExecPMCR ......................
  • Page 15 CONTENTS Other Instructions ......... . 2-863 ReadNbit_** ......................
  • Page 16: Nj-Series Instructions Reference Manual (W502)

    CONTENTS NJ-series Instructions Reference Manual (W502)
  • Page 17: Read And Understand This Manual

    WHETHER SUCH CLAIM IS BASED ON CONTRACT, WARRANTY, NEGLIGENCE, OR STRICT LIABILITY. In no event shall the responsibility of OMRON for any act exceed the individual price of the product on which liability is asserted. IN NO EVENT SHALL OMRON BE RESPONSIBLE FOR WARRANTY, REPAIR, OR OTHER CLAIMS...
  • Page 18 Application Considerations SUITABILITY FOR USE OMRON shall not be responsible for conformity with any standards, codes, or regulations that apply to the combination of products in the customer's application or use of the products. At the customer's request, OMRON will provide applicable third party certification documents identifying ratings and limitations of use that apply to the products.
  • Page 19 Performance data given in this manual is provided as a guide for the user in determining suitability and does not constitute a warranty. It may represent the result of OMRON's test conditions, and the users must correlate it to actual application requirements. Actual performance is subject to the OMRON Warranty and Limitations of Liability.
  • Page 20 Read and Understand this Manual NJ-series Instructions Reference Manual (W502)
  • Page 21: Safety Precautions

    Safety Precautions Safety Precautions Refer to the following manuals for safety precautions. • NJ-series CPU Unit Hardware User’s Manual (Cat No. W500) • NJ-series CPU Unit Software User’s Manual (Cat No. W501) NJ-series Instructions Reference Manual (W502)
  • Page 22: Precautions For Safe Use

    Precautions for Safe Use Precautions for Safe Use Refer to the following manuals for precautions for safe use. • NJ-series CPU Unit Hardware User’s Manual (Cat No. W500) • NJ-series CPU Unit Software User’s Manual (Cat No. W501) NJ-series Instructions Reference Manual (W502)
  • Page 23: Precautions For Correct Use

    Precautions for Correct Use Precautions for Correct Use Refer to the following manuals for precautions for correct use. • NJ-series CPU Unit Hardware User’s Manual (Cat No. W500) • NJ-series CPU Unit Software User’s Manual (Cat No. W501) NJ-series Instructions Reference Manual (W502)
  • Page 24: Regulations And Standards

    Concepts EMC Directive OMRON devices that comply with EC Directives also conform to the related EMC standards so that they can be more easily built into other devices or the overall machine. The actual products have been checked for conformity to EMC standards.* Whether the products conform to the standards in the system used by the customer, however, must be checked by the customer.
  • Page 25 The NJ-series Controllers comply with the following shipbuilding standards. Applicability to the ship- building standards is based on certain usage conditions. It may not be possible to use the product in some locations. Contact your OMRON representative before attempting to use a Controller on a ship.
  • Page 26: Unit Versions

    Gives the lot number and serial number of the Unit. serial number DDMYY: Lot number, @: For use by OMRON, xxxx: Serial number “M” gives the month (1 to 9: January to September, X: October, Y: November, Z: December) MAC address Gives the MAC address of the built-in port on the Unit.
  • Page 27 Unit Versions Right-click any open space in the Unit Editor and select Production Information. The Production Information Dialog Box is displayed. Simple Display Detailed Display In this example, “Ver.1.0” is displayed next to the unit model. The following items are displayed. CPU Unit CJ-series Units Unit model...
  • Page 28 Unit Versions Unit Version Notation In this manual, unit versions are specified as shown in the following table. Product nameplate Notation in this manual Remarks “Ver.1.0” or later to the right of Unit version 1.0 or later Unless unit versions are specified, the information in this manual the lot number applies to all unit versions.
  • Page 29: Related Manuals

    When programming, use this manual together Manual trol instructions that are with the NJ-series CPU Unit Hardware User’s provided by OMRON. Manual (Cat. No. W500), NJ-series CPU Unit Software User’s Manual (Cat. No. W501) and NJ-series CPU Unit Motion Control User’s Man- ual (Cat.
  • Page 30 Related Manuals Manual name Cat. No. Model numbers Application Description NJ-series CPU Unit Built- W505 NJ501-@@@@ Using the built-in EtherCAT Information on the built-in EtherCAT port is pro- in EtherCAT Port User’s port on an NJ-series CPU vided. This manual provides an introduction and Manual Unit.
  • Page 31: Revision History

    Revision History Revision History A manual revision code appears as a suffix to the catalog number on the front and back covers of the manual. W502-E1-01 Cat. No. Revision code Revision code Date Revised content July 2011 Original production NJ-series Instructions Reference Manual (W502)
  • Page 32 Revision History NJ-series Instructions Reference Manual (W502)
  • Page 33: Instruction Set

    Instruction Set This section provides a table of the instructions that you can use with NJ-series Con- trollers. Instruction Set ..........1-2 NJ-series Instructions Reference Manual (W502)
  • Page 34 1 Instruction Set Instruction Set Type Instruction Name Function Page Ladder Diagram Load Reads the value of a BOOL variable. 2-14 Instructions Load NOT Reads the inverse of the value of a BOOL vari- 2-14 able. Takes the logical AND of the value of a BOOL 2-16 variable and the input value.
  • Page 35 1 Instruction Set Type Instruction Name Function Page Sequence Out- Set-Priority Keep Retains the value of a BOOL variable. It gives 2-48 put Instructions priority to the Set input if both the Set input and Reset input are TRUE. Changes a BOOL variable to TRUE. 2-50 Reset Reset...
  • Page 36 1 Instruction Set Type Instruction Name Function Page Comparison GTascii Text String Performs a greater than comparison between 2-95 Instructions Comparison text strings. Greater Than GEascii Text String Performs a greater than or equal comparison 2-95 Comparison between text strings. Greater Than or Equal Compare...
  • Page 37 1 Instruction Set Type Instruction Name Function Page Counter Instruc- Down-counter Decrements the counter value when the 2-134 tions counter input signal is received. The preset value and counter value must have an INT data type. CTD_** Down-counter Decrements the counter value when the 2-136 Group counter input signal is received.
  • Page 38 1 Instruction Set Type Instruction Name Function Page Math Instruc- SQRT Square Root Finds the square root of a number. 2-180 tions Natural Logarithm Finds the natural logarithm of a real number. 2-182 Logarithm Base 10 Finds the base-10 logarithm of a real number. 2-182 Natural Performs calculations for the natural exponen-...
  • Page 39 1 Instruction Set Type Instruction Name Function Page Data Type Con- **_TO_*** (Integer-to- Integer-to-Real Converts integers to real numbers. 2-237 version Instruc- Real Number Conver- Number tions sion Group) Conversion Group **_TO_*** (Bit String-to- Bit String-to- Converts bit strings to integers. 2-239 Integer Conversion Integer Conversion...
  • Page 40 1 Instruction Set Type Instruction Name Function Page Data Type Con- RoundUp Round Up Real Rounds up a real number at the first decimal 2-283 version Instruc- Number digit to make an integer. tions Bit String Pro- AND (&) Logical AND Performs a logical AND operation on Boolean 2-286 cessing Instruc-...
  • Page 41 1 Instruction Set Type Instruction Name Function Page Data Movement AryExchange Array Data Exchanges the elements of two arrays. 2-333 Instructions Exchange AryMove Array Move Moves one or more array elements. The data 2-335 types of the move source and move destina- tion can be different.
  • Page 42 1 Instruction Set Type Instruction Name Function Page Conversion Decoder Bit Decoder Sets the specified bit to TRUE and the other 2-371 Instructions bits to FALSE in array elements that consist of a maximum of 256 bits. Encoder Bit Encoder Finds the position of the highest TRUE bit in 2-374 array elements that consist of a maximum of...
  • Page 43 1 Instruction Set Type Instruction Name Function Page Conversion StringToAry Text String-to-Array Converts a text string to a BYTE array. 2-441 Instructions Conversion AryToString Array-to-Text String Converts a BYTE array to a text string. 2-443 Conversion DispartDigit Four-bit Separation Separates a bit string into 4-bit units. 2-445 UniteDigit_** Four-bit Join Group Joins 4-bit units of data into a bit string.
  • Page 44 1 Instruction Set Type Instruction Name Function Page Text String CONCAT Concatenate String Joins two to five text strings. 2-520 Instructions LEFT Get String Left Extracts a text string with the specified number 2-522 of characters from the start (left) of a text string.
  • Page 45 1 Instruction Set Type Instruction Name Function Page Time and Time GetTime Get Time of Day Reads the current time. 2-572 of Day Instruc- DtToSec Convert Date and Converts a date and time to the number of sec- 2-574 tions Time to Seconds onds from 00:00:00 on January 1, 1970.
  • Page 46 1 Instruction Set Type Instruction Name Function Page System Control GetPLCError Get PLC Controller Gets the highest level status (partial fault or 2-622 Instructions Error Status minor fault) and highest level event code of the current Controller errors in the PLC Function Module.
  • Page 47 1 Instruction Set Type Instruction Name Function Page Communica- CIPUCMMRead Read Variable Uses a UCMM explicit message to read the 2-706 tions Instruc- UCMM Explicit value of a variable in another Controller on the tions specified CIP network. CIPUCMMWrite Write Variable Uses a UCMM explicit message to write the 2-710 UCMM Explicit...
  • Page 48 1 Instruction Set Type Instruction Name Function Page SD Memory FileWriteVar Write Variable to Writes the value of a variable to the specified 2-794 Card Instruc- File file in the SD Memory Card. The value is writ- tions ten in binary format. FileReadVar Read Variable from Reads the contents of the specified file on the...
  • Page 49: Instruction Descriptions

    Instruction Descriptions This section describes the specifications of the instructions that you can use with NJ- series Controllers. Using this Section ..........2-2 Ladder Diagram Instructions .
  • Page 50: Using This Section

    2 Instruction Descriptions Using this Section The notation used to describe instructions in this section is explained below. Items The following items are provided. Item Description Instruction The instruction word is given. Example: MoveBit Name The name of the instruction is given. Example: Move Bit FB/FUN Whether the instruction is a function block (FB) instruction or a function (FUN) instruction is given.
  • Page 51 2 Instruction Descriptions Item Description ST expression The notation that represents the instruction in ST is given. There are two ways that you can use to code an instruction in ST. These are described below. 1. Directly Specifying the Correspondence between the Parameters and the Input, Output, and In- Out Variables Example: MoveBit(In:=abc, InPos:=def, InOut:=ghi, InOutPos:=jkl);...
  • Page 52 2 Instruction Descriptions Item Description Additional Information Additional information on the function of the instruction is provided. This includes related instruc- tions and helpful information for application of the instruction. Precautions for Cor- Precautions for application of the instruction are given. The conditions under which errors occur for rect Use the instruction are also given here.
  • Page 53 2 Instruction Descriptions Execute, Done, and Busy Execute is an input variable that gives the execution condition for some FB instructions. Instruction execution starts when Execute changes to TRUE. After Execute changes to TRUE, execu- tion of this instruction is continued until processing is completed even if the value of Execute changes to FALSE or the instruction execution time exceeds the task period.
  • Page 54 2 Instruction Descriptions Timing charts are provided below for Execute, Done, Busy, Error, ErrorID, and ErrorIDEx. Normal End TRUE Execute FALSE One task period TRUE Busy FALSE TRUE Done FALSE TRUE Error FALSE ErrorID ErrorIDEx Execution starts when Execute Execute is FALSE at the end of changes to TRUE.
  • Page 55 2 Instruction Descriptions Error End TRUE Execute FALSE TRUE Busy FALSE One task period TRUE Done FALSE TRUE Error FALSE ErrorID ErrorIDEx Execute is FALSE at the end of Execution starts when Execute execution, so Error is TRUE for one task changes to TRUE.
  • Page 56 2 Instruction Descriptions Classifica- Data Valid range Default tion type USINT USINT#0 to +255 USINT#0 UINT UINT#0 to +65535 UINT#0 UDINT UDINT#0 to +4294967295 UDINT#0 ULINT ULINT#0 to +18446744073709551615 ULINT#0 Integers SINT SINT#−128 to +127 SINT#0 INT#−32768 to +32767 INT#0 DINT DINT#−2147483648 to +2147483647 DINT#0...
  • Page 57 2 Instruction Descriptions Derivative Data Types (Enumerations, Structures, and Unions) Variables that use derivative data types (enumerations, structures, and unions) are specified as such in the tables of variable data types. The notation is described below. Enumerations The data type for an enumerated variable is given within the table. The following is an example. Here, the data type of the Out variable is enumerated type _eDAYOFWEEK.
  • Page 58 2 Instruction Descriptions Array Specifications Array variable names are followed by “[]” and “(array)” is specified. For these variables, specify an ele- ment of the array (i.e., specify the subscript) as the parameter. An example is shown below. Here, the table shows that In1[] is a BYTE array. Times, durations, Bit strings Integers...
  • Page 59 2 Instruction Descriptions • Assigning a text string that has character code error to a STRING variable. • Dividing an integer variable by 0. Precautions for All Instructions The amount of processing that is required for some instructions depends on the parameters that you connect.
  • Page 60 2 Instruction Descriptions 2-12 NJ-series Instructions Reference Manual (W502)
  • Page 61: Ladder Diagram Instructions

    Ladder Diagram Instructions Instruction Name Page LD and LDN Load/ 2-14 Load NOT AND and ANDN AND/ 2-16 AND NOT OR and ORN 2-18 OR NOT Out and OutNot Output/ 2-20 Output NOT NJ-series Instructions Reference Manual (W502) 2-13...
  • Page 62: Ld And Ldn

    2 Instruction Descriptions LD and LDN Reads the value of a BOOL variable. LDN: Reads the inverse of the value of a BOOL variable. Instruction Name FB/FUN Graphic expression ST expression Load None Variable Variable Variable Upward Downward differentiation differentiation Load NOT None Variable...
  • Page 63 2 Instruction Descriptions If you specify upward or downward differentiation, the operation depends on the following: the value of the variable the last time the instruction was executed and the current value of the variable. This is shown below. Differentiation specifi- Value of variable at last execution and current Instruction Output value...
  • Page 64: And And Andn

    2 Instruction Descriptions AND and ANDN AND: Takes the logical AND of the value of a BOOL variable and the execution condition. ANDN: Takes the logical AND of the inverse of the value of a BOOL variable and the execution condition.
  • Page 65 2 Instruction Descriptions The operation is as shown below if you do not specify upward or downward differentiation. Combination of variable value and execution Output Instruction condition value Variable value: TRUE TRUE Execution condition: TRUE Other than the above. FALSE Variable value: FALSE TRUE ANDN...
  • Page 66: Or And Orn

    2 Instruction Descriptions OR and ORN Takes the logical OR of the value of a BOOL variable and the execution condition. ORN: Takes the logical OR of the inverse of the value of a BOOL variable and the execution condi- tion.
  • Page 67 2 Instruction Descriptions The operation is as shown below if you do not specify upward or downward differentiation. Combination of variable value and execution Output Instruction condition value Variable value: FALSE FALSE Execution condition: FALSE Other than the above. TRUE Variable value: TRUE FALSE Execution condition: FALSE...
  • Page 68: Out And Outnot

    2 Instruction Descriptions Out and OutNot Out: Takes the logical result from the previous instruction and outputs it to a BOOL variable. OutNot: Takes the inverse of the logical result from the previous instruction and outputs it to a BOOL variable. Instruction Name FB/FUN...
  • Page 69 2 Instruction Descriptions OutNot The OutNot instruction takes the inverse of the logical result from the previous instruction and outputs it to a specified BOOL variable. Logic processing result from Output previous instruction TRUE FALSE FALSE TRUE The following figure shows a programming example and timing chart. TRUE FALSE TRUE...
  • Page 70 2 Instruction Descriptions Precautions for Correct Use • In the following case, an error occurs and nothing is output. • You specify an array element for the variable value and the element does not exist. Example: A BOOL array a[0..5] is defined, but the instruction is executed using a[10] as the vari- able.
  • Page 71: St Statement Instructions

    ST Statement Instructions Instruction Name Page 2-24 CASE Case 2-28 WHILE While 2-32 REPEAT Repeat 2-34 RETURN Return 2-36 Repeat Start 2-37 EXIT Break Loop 2-38 NJ-series Instructions Reference Manual (W502) 2-23...
  • Page 72 2 Instruction Descriptions The IF construct uses the evaluation result of a specified condition expression to select one of two statements to execute. Instruction Name FB/FUN Graphic expression ST expression None IF condition expression THEN statement; ELSIF condition expression THEN statement;...
  • Page 73 2 Instruction Descriptions Operator Meaning Example Evaluation result Logical OR a OR b The result is the logical OR of BOOL variables a and b. Exclusive OR a XOR b The result is the logical exclusive OR of BOOL variables a and NOT a The result is the NOT of BOOL variable a.
  • Page 74 2 Instruction Descriptions You can use ELSIF more than once. The following processing flow is for this example. IF condition expression 1 THEN statement 1; ELSIF condition expression 2 THEN statement 2; ELSIF condition expression 3 THEN statement 3; ELSE statement 4;...
  • Page 75 2 Instruction Descriptions Sample Programming This example assigns INT#0 to variable def if the value of variable abc is less than INT#0. It assigns INT#1 to variable def and INT#2 to variable ghi if the value of variable abc is INT#0. It assigns INT#3 to variable def if the value of variable abc is none of the above.
  • Page 76: Case

    2 Instruction Descriptions CASE You use the CASE construct to select the statement to execute based on the value of a specified inte- ger expression. Instruction Name FB/FUN Graphic expression ST expression CASE Case None CASE integer expression value: statement; value: statement;...
  • Page 77 2 Instruction Descriptions TRUE Equal to value 1? FALSE TRUE Equal to value 2? FALSE Equal to TRUE value n? FALSE Statement m Statement n Statement 2 Statement 1 Additional Information • You can use the CASE construct to build a hierarchy. The following example executes statement 12 if the value of integer expression 1 is 1 and the value of integer expression 11 is 2.
  • Page 78 2 Instruction Descriptions • You can use a range of consecutive values. Place two periods between the numbers to indicate con- secutive values. The following example executes statement 1 if the value of the integer expression is between 10 and 15, inclusive. CASE integer expression 1 OF 10..15: statement 1;...
  • Page 79 2 Instruction Descriptions Sample Programming This example assigns INT#10 to variable def if the value of variable abc is INT#1, INT#20 if the value of variable abc is INT#2, and INT#30 if the value of variable abc is INT#3. Otherwise, it assigns the value of variable ghi to variable def.
  • Page 80: While

    2 Instruction Descriptions WHILE The WHILE construct repeatedly executes a statement as long as the evaluation result of a specified condition expression is TRUE. Instruction Name FB/FUN Graphic expression ST expression WHILE While None WHILE condition expression statement; END_WHILE; Variables None Function The WHILE construct repeatedly executes a statement as long as the evaluation result of a specified...
  • Page 81 2 Instruction Descriptions The following processing flow is for this example. You can use more than one statement. WHILE condition expression DO statement; END_WHILE; FALSE Condition expression TRUE Statement Additional Information • The statement is not executed even once if the condition expression is FALSE the first time it is eval- uated.
  • Page 82: Repeat

    2 Instruction Descriptions REPEAT The REPEAT construct executes a statement once and then executes it repeatedly until a specified condition expression is TRUE. Instruction Name FB/FUN Graphic expression ST expression REPEAT Repeat None REPEAT statement; UNTIL condition expression END_REPEAT; Variables None Function The REPEAT construct executes a statement once and then executes it repeatedly until a specified...
  • Page 83 2 Instruction Descriptions The following processing flow is for this example. You can use more than one statement. REPEAT statement; UNTIL condition expression END_REPEAT; Statement TRUE Condition expression FALSE Additional Information • The statement is executed once before the condition expression is evaluated. Therefore, the state- ment is always executed at least once.
  • Page 84: Return

    2 Instruction Descriptions RETURN Refer to RETURN on page 2-61 in the Sequence Control Instructions for a description of this instruc- tion. 2-36 NJ-series Instructions Reference Manual (W502)
  • Page 85: For

    2 Instruction Descriptions Refer to FOR and NEXT on page 2-76 in the Sequence Control Instructions for a description of this instruction. NJ-series Instructions Reference Manual (W502) 2-37...
  • Page 86: Exit

    2 Instruction Descriptions EXIT Refer to BREAK on page 2-81 in the Sequence Control Instructions for a description of this instruction. The BREAK ladder diagram instruction and the EXIT structured text instruction function in the same way. 2-38 NJ-series Instructions Reference Manual (W502)
  • Page 87: Sequence Input Instructions

    Sequence Input Instructions Instruction Name Page R_TRIG (Up) and F_TRIG (Down) Up Trigger/ 2-40 Down Trigger TestABit and TestABitN Test A Bit/ 2-43 Test A Bit NOT NJ-series Instructions Reference Manual (W502) 2-39...
  • Page 88: R_Trig (Up) And F_Trig (Down)

    2 Instruction Descriptions R_TRIG (Up) and F_TRIG (Down) R_TRIG (Up): Outputs TRUE for one task period only when the input signal changes to TRUE. F_TRIG (Down): Outputs TRUE for one task period only when the input signal changes to FALSE. Instruction Name FB/FUN...
  • Page 89 2 Instruction Descriptions The following figure shows a programming example and timing chart. R_TRIG_instance(A, abc); R_TRIG_instance R_TRIG TRUE Clk, In FALSE TRUE Q, Out=abc FALSE Task period F_TRIG F_TRIG assigns TRUE to output signal Q for one task period only when input signal Clk changes to FALSE.
  • Page 90 2 Instruction Descriptions Precautions for Correct Use • Detection of upward or downward differentiation depends on differences between the current value of Clk or In and the value the last time the instruction was executed. Caution is required when using the JMP instruction or other times that the instruction is not executed every task period.
  • Page 91: Testabit And Testabitn

    2 Instruction Descriptions TestABit and TestABitN TestABit: Outputs the value of the specified bit in a bit string. TestABitN: Outputs the inverse of the value of the specified bit in a bit string. Instruction Name FB/FUN Graphic expression ST expression TestABit Test A Bit Out:=TestABit (In, Pos);...
  • Page 92 2 Instruction Descriptions Function TestABit The TestABit instruction assigns the value of the bit at bit position Pos in the bit string In to the bit value Out when EN is TRUE. When EN is FALSE, the value of Out is FALSE. TestABitN The TestABitN instruction assigns the inverse of the value of the bit at bit position Pos in the bit string In to the bit value Out when EN is TRUE.
  • Page 93: Sequence Output Instructions

    Sequence Output Instructions Instruction Name Page Reset-Priority Keep 2-46 Set-Priority Keep 2-48 Set and Reset Set/Reset 2-50 SetBits and ResetBits Set Bits/Reset Bits 2-53 SetABit and ResetABit Set A Bit/Reset A Bit 2-55 OutABit Output A Bit 2-57 NJ-series Instructions Reference Manual (W502) 2-45...
  • Page 94 2 Instruction Descriptions The RS instruction retains the value of a BOOL variable. It gives priority to the Reset input if both the Set input and Reset input are TRUE. Instruction Name FB/FUN Graphic expression ST expression Reset-Priority Keep RS_instance(Set, Reset1, RS_instance Q1);...
  • Page 95: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions The following figure shows a programming example and timing chart. RS_instance(A, B, abc); RS_instance Reset1 TRUE Set=A FALSE TRUE Reset1=B FALSE TRUE Q1=abc FALSE Additional Information • The RS instruction behaves like the following self-holding rung. • However, if the RS instruction is in a master control region and the master control region is reset, the behavior will not be the same as the above self-holding rung.
  • Page 96: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions The SR instruction retains the value of a BOOL variable. It gives priority to the Set input if both the Set input and Reset input are TRUE. Instruction Name FB/FUN Graphic expression ST expression Set-Priority Keep SR_instance(Set1, Reset, SR_instance Q1);...
  • Page 97: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions The following figure shows a programming example and timing chart. SR_instance(A, B, abc); SR_instance Set1 Reset TRUE Set1=A FALSE TRUE Reset=B FALSE TRUE Q1=abc FALSE Additional Information • The SR instruction behaves like the following self-holding rung. •...
  • Page 98: Set And Reset

    2 Instruction Descriptions Set and Reset Set: Changes a BOOL variable to TRUE. Reset: Changes a BOOL variable to FALSE. Instruction Name FB/FUN Graphic expression ST expression None Upward Downward differentiation differentiation Reset Reset None Upward Downward differentiation differentiation Variables Name Meaning Description...
  • Page 99: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions If you specify upward or downward differentiation, the operation depends on the following: the value of the input for the last execution and the current value of the input. This is shown below. Differentiation speci- Instruction Value of input at last execution and current value Output value fication FALSE at the last execution →...
  • Page 100: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions Additional Information Differences between the Set and Reset Instructions and the Out Instruction • The Set and Reset instructions operate only when the input value changes to TRUE. They do not operate when the input value is FALSE. When the input value is FALSE, the output does not change. •...
  • Page 101: Setbits And Resetbits

    2 Instruction Descriptions SetBits and ResetBits SetBits: Changes consecutive bits in bit string data to TRUE. ResetBits: Changes consecutive bits in bit string data to FALSE. Instruction Name FB/FUN Graphic expression ST expression SetBits Set Bits SetBits(InOut, Pos, Size); (@)SetBits InOut Size ResetBits...
  • Page 102: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions ResetBits The ResetBits instruction changes the value of Size bits from the bit position Pos in the bit string InOut to FALSE. The status of the other bits will not change. The following example shows the SetBits instruction when Pos is USINT#3 and Size is USINT#2. SetBits(abc, USINT#3, USINT#2);...
  • Page 103: Setabit And Resetabit

    2 Instruction Descriptions SetABit and ResetABit SetABit: Changes the specified bit in bit string data to TRUE. ResetABit: Changes the specified bit in bit string data to FALSE. Instruction Name FB/FUN Graphic expression ST expression SetABit Set A Bit SetABit (InOut, Pos); (@)SetABit InOut ResetABit...
  • Page 104: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions ResetABit The ResetABit instruction changes the value of the bit at bit position Pos in the bit string InOut to FALSE. The bits that are not specified do not change. Even if EN changes to FALSE after execution, the Pos bit in InOut will not change. The following example shows the SetABit instruction when Pos is USINT#3.
  • Page 105: Outabit

    2 Instruction Descriptions OutABit The OutABit instruction changes the specified bit in bit string data to TRUE or FALSE. Instruction Name FB/FUN Graphic expression ST expression OutABit Output A Bit OutABit (InOut, Pos, BitVal); (@)OutABit InOut BitVal Variables Name Meaning Description Valid range Unit...
  • Page 106: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions Function The OutABit instruction stores the value of set value BitVal at bit position Pos in the bit string InOut. Only the bit at Pos changes. The following example is for when Pos is USINT#2 and BitVal is TRUE. OutABit(abc, USINT#2, TRUE);...
  • Page 107: Sequence Control Instructions

    Sequence Control Instructions Instruction Name Page 2-60 RETURN Return 2-61 MC and MCR Master Control Start/ 2-62 Master Control End Jump 2-74 FOR and NEXT Repeat Start/ 2-76 Repeat End BREAK Break Loop 2-81 NJ-series Instructions Reference Manual (W502) 2-59...
  • Page 108: End

    2 Instruction Descriptions The End instruction ends execution of a program in the current task period. Instruction Name FB/FUN Graphic expression ST expression None Variables None Function The End instruction ends execution of a program in the current task period. The following figure shows a programming example.
  • Page 109: Return

    2 Instruction Descriptions RETURN The RETURN instruction ends a function or function block and returns processing to the calling instruc- tion. Instruction Name FB/FUN Graphic expression ST expression RETURN Return RETURN; RETURN Variables None Function The RETURN instruction ends a function or function block and returns processing to the calling instruc- tion.
  • Page 110: Mc And Mcr

    2 Instruction Descriptions MC and MCR Marks the starting point of a master control region and resets the master control region. MCR: Marks the end point of a master control region. Instruction Name FB/FUN Graphic expression ST expression Master Control None Start MCNo...
  • Page 111: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions The value that is output from the LD instruction changes to FALSE regardless of the value of variable A. MCNo UINT#1 Master control region MCNo UINT#1 If the value of In is TRUE, then master control is not reset. The POUs in the master control region oper- ate normally.
  • Page 112: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions Operation BREAK instruction This instruction is not executed. Function blocks that are executed The power flow from the left bus bar changes to FALSE. If the instruction over more than one task period (i.e., was operating before the master control reset, execution of the instruction instructions with Done, Busy, and is continued until processing is completed.
  • Page 113: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions Master control reset MC_ON TRUE UINT#1 MCNo MC_ON FALSE TRUE FALSE Output from TRUE LD instruction FALSE TRUE FALSE UINT#1 MCNo Master control reset TRUE MC_ON FALSE TRUE FALSE Output from TRUE LD instruction FALSE TRUE FALSE Master control reset MC_ON TRUE...
  • Page 114: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions MC_ON Master control reset UINT#1 MCNo TRUE MC_ON FALSE CTU_instance TRUE FALSE Reset Output from TRUE LD instruction FALSE UINT#1 MCNo Operation of POUs with Input Upward Differentiation or Input Downward Differentiation The POUs that are given in the following table have upward or downward differentiation specifications. Differentiation Instructions Input upward differentiation...
  • Page 115: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions F_TRIG (Down) When the master control is reset, the execution condition changes to FALSE. If the previous execution condition was TRUE, then the input downward differentiation condition is met. However, the value of the output from the F_TRIG (Down) instruction during the master control reset is forced to change to FALSE, so the output value changes to FALSE.
  • Page 116: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions Master control reset MC_ON TRUE UINT#1 MCNo MC_ON FALSE TRUE FALSE TRUE Output from FALSE LD instruction TRUE FALSE UINT#1 MCNo Master control reset TRUE MC_ON FALSE TRUE FALSE TRUE Output from FALSE LD instruction TRUE FALSE Here, the input upward differentiation condition is met and the output value changes to FALSE.
  • Page 117: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions CTU, CTD, and CTUD When the master control is reset, the value of the counter input changes to FALSE. If the value of the counter input is TRUE when the master control reset is cleared, the input upward differentiation condition is met and the instruction counts.
  • Page 118 2 Instruction Descriptions UINT#1 MCNo Reset. TON_instance T#10ms position UINT#0 InitVal Index EndVal UINT#10 These are not executed. StepVal UINT#1 MOVE array[position] INT#0 NEXT FALSE is output. MCNo UINT#1 Precautions for Correct Use • These instructions must be used in a ladder diagram. They cannot be used in ST. They also cannot be used in inline ST in a ladder diagram.
  • Page 119: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions • If you use the MC and MCR instructions and the JMP instruction together, the operation is as follows: • The following figure shows an MC-MCR pair inside a JMP-Label pair. Here, the jump is executed regardless of the value of In. Flow of processing JMP instruction executed.
  • Page 120: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions • The instructions are in the following order in the following figure: JMP instruction, MC instruction, Label, and MCR instruction. First, the jump is made. As a result, the MC instruction is not exe- cuted. Therefore, the instructions after the Label instruction are executed. If the value of In is FALSE, the MCR instruction is executed, but nothing changes.
  • Page 121: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions • If you use the MC and MCR instructions and the FOR and NEXT instructions together, the operation is as follows: • The following figure shows an MC-MCR pair inside a FOR-NEXT pair. Here, operation is as given in the following table.
  • Page 122: Jmp

    2 Instruction Descriptions The JMP instruction moves processing to the specified jump destination. Instruction Name FB/FUN Graphic expression ST expression Jump None Label Variables None Function When the execution condition is TRUE, the JMP instruction moves processing to the jump destination specified by a Label in a ladder diagram.
  • Page 123: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions • The following restrictions apply to the characters that can be used as labels. Item Specification Maximum number of bytes 127 bytes 127 characters when converted to ACSII 31 characters when converted to Japanese characters (including single-byte kana) Character code UTF-8...
  • Page 124: For And Next

    2 Instruction Descriptions FOR and NEXT FOR: Marks the starting position for repeat processing and specifies the repeat condition. NEXT: Marks the ending position for repeat processing. Instruction Name FB/FUN Graphic expression ST expression Repeat Start FOR Index:=InitVal TO End- Val BY StepVal DO expression InitVal...
  • Page 125 2 Instruction Descriptions Function The FOR and NEXT instructions repeat the processing that you place between them. (FOR and END_FOR are used in ST.) The processing procedure for a FOR-NEXT loop is as follows: The value of InitVal is set in control variable Index. The value of Index is checked to see if it is equal to or greater than InitVal and equal to or less than EndVal (or equal to or greater than EndVal and equal to or less than InitVal).
  • Page 126 2 Instruction Descriptions • FOR-NEXT loops (or FOR-END_FOR loops in ST) can be nested. In the following figure, the pro- cesses are performed in the following order. Process A → Process B → Process B → Process C → Process A → Process B → Process B → Pro- cess C →...
  • Page 127 2 Instruction Descriptions • The value of Index after repeat processing is different in a ladder diagram and ST. In a ladder dia- gram, the value of StepVal is not added to Index at the end of repeat processing. In ST, the value of StepVal is added to Index at the end of repeat processing.
  • Page 128 2 Instruction Descriptions In the following programming, upward differentiation of x[i] is determined by the R_TRIG instruction. An instance of the R_TRIG instruction is provided for each element of x[i], so it is possible to detect which element of x[i] changed its value. As a result, Count2[0] to Count2[10] are all incremented. InitVal Index DINT#0...
  • Page 129: Break

    2 Instruction Descriptions BREAK The BREAK instruction is used to cancel repeat processing from the lowest level FOR instruction to the NEXT instruction. Instruction Name FB/FUN Graphic expression ST expression BREAK Break Loop FOR Index:=0 TO 9 BY 1 BREAK IF Error[index] THEN EXIT*;...
  • Page 130: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions Precautions for Correct Use • Always place this instruction between the FOR and NEXT instructions (or the FOR and END_FOR instructions in ST). • If FOR-NEXT loops (or FOR-END_FOR loops in ST) are nested, you will need one BREAK instruc- tion (or one EXIT instruction in ST) for each nesting level to cancel all repeat processing.
  • Page 131: Comparison Instructions

    Comparison Instructions Instruction Name Page EQ (=) Equal 2-84 NE (<>) Not Equal 2-86 LT (<), LE (<=), GT (>), and GE (>=) Less Than/Less Than Or Equal/ 2-88 Greater Than/Greater Than Or Equal EQascii Text String Comparison Equal 2-91 NEascii Text String Comparison Not Equal 2-93...
  • Page 132: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions EQ (=) The EQ (=) instruction determines if the contents of two or more variables are all equivalent. Instruction Name FB/FUN Graphic expression ST expression EQ (=) Equal Out:=(In1=In2) & (In2=In3) (@)EQ & ··· & (InN-1=InN); (@)= Variables Name Meaning...
  • Page 133: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions abc:=(INT#3=INT#5)&(INT#5=INT#10); INT#3 INT#5 INT#10 Additional Information • The functions of the EQ instruction and the = instruction are exactly the same. Use the form that is easier to use. • Use the EQascii instruction (page 2-91) to determine if text strings are equal. Precautions for Correct Use •...
  • Page 134: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions NE (<>) The NE (<>) instruction determines if the contents of two variables are not equivalent. Instruction Name FB/FUN Graphic expression ST expression NE (<>) Not Equal Out:=(In1<>In2); (@)NE (@)<> Variables Name Meaning Description Valid range Unit Default In1 and In2 Comparison...
  • Page 135: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions Additional Information • The functions of the NE instruction and the <> instruction are exactly the same. Use the form that is easier to use. • Use the NEascii instruction (page 2-93) to determine if text strings are not equal. Precautions for Correct Use •...
  • Page 136: Lt (<), Le (<=), Gt (>), And Ge (>=)

    2 Instruction Descriptions LT (<), LE (<=), GT (>), and GE (>=) These instructions compare the sizes of two or more values. LT (<): Performs a less than comparison. LE (<=): Performs a less than or equal comparison. GT (>): Performs a greater than comparison.
  • Page 137: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions Variables Name Meaning Description Valid range Unit Default In1 to InN Comparison Input Values to compare, N = 2 to Depends on data type. data Comparison Output Comparison result Depends on data type. result * If you omit the input parameter that connects to InN, the default value is not applied, and a building error will occur. For example, if N is 3 and the input parameters that connect to In1 and In2 are omitted, the default values are applied, but if the input parameter that connects to In3 is omitted, a building error will occur.
  • Page 138: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions Precautions for Correct Use • If the data types of In1 to InN are different, they will be expanded to a data type that includes the ranges of all of the data types. • Signed integers (SINT, INT, DINT, and LINT) cannot be compared to unsigned integers (USINT, UINT, UDINT, and ULINT).
  • Page 139: Eqascii

    2 Instruction Descriptions EQascii The EQascii instruction determines if two or more text strings are all equivalent. Instruction Name FB/FUN Graphic expression ST expression EQascii Text String Com- Out:=EQascii(In1, ··, (@)EQascii parison Equal InN); Variables Name Meaning Description Valid range Unit Default In1 to InN...
  • Page 140: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions Additional Information The text string comparison instructions are convenient when you want to reorder text strings according to the character codes. For example, the character codes for alphabet characters are in the same order as the alphabet characters. This allows you to alphabetize. Precautions for Correct Use •...
  • Page 141: Neascii

    2 Instruction Descriptions NEascii The NEascii instruction determines if two text strings are not equivalent. Instruction Name FB/FUN Graphic expression ST expression NEascii Text String Com- Out:=NEascii(In1, In2); (@)NEascii parison Not Equal Variables Name Meaning Description Valid range Unit Default In1 and In2 Comparison Input...
  • Page 142: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions Additional Information The text string comparison instructions are convenient when you want to reorder text strings according to the character codes. For example, the character codes for alphabet characters are in the same order as the alphabet characters. This allows you to alphabetize. Precautions for Correct Use •...
  • Page 143: Ltascii, Leascii, Gtascii, And Geascii

    2 Instruction Descriptions LTascii, LEascii, GTascii, and GEascii These instructions compare the sizes of two or more text strings. LTascii: Performs a less than comparison. LEascii: Performs a less than or equal comparison. GTascii: Performs a greater than comparison. GEascii: Performs a greater than or equal comparison.
  • Page 144: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions Times, durations, Bit strings Integers dates, and text strings In1 to InN Function These instructions compare the sizes of from two to five text strings in In1 to InN (N = 2 to 5). The out- put value Out is shown below for each instruction. Instruction Value of Out LTascii...
  • Page 145: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions Additional Information The text string comparison instructions are convenient when you want to reorder text strings according to the character codes. For example, the character codes for alphabet characters are in the same order as the alphabet characters. This allows you to alphabetize. Precautions for Correct Use •...
  • Page 146: Cmp

    2 Instruction Descriptions The Cmp instruction compares two values. Instruction Name FB/FUN Graphic expression ST expression Compare Out:=Cmp(In1, In2, OutEQ, (@)Cmp OutGT, OutGE, OutNE, OutLT, OutLE); OutEQ You can omit Out. OutGT OutGE OutNE OutLT OutLE Variables Name Meaning Description Valid range Unit Default...
  • Page 147: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions Function The Cmp instruction compares two values (In1 and In2) and outputs flag values. The values of the flags are as follows: Flag Value OutEQ If In1 equals In2, the flag shows TRUE. Otherwise the flag shows FALSE. OutGT If In1 is greater than In2, the flag shows TRUE.
  • Page 148: Zonecmp

    2 Instruction Descriptions ZoneCmp The ZoneCmp instruction determines if the comparison data is within the specified maximum and mini- mum values. Instruction Name FB/FUN Graphic expression ST expression ZoneCmp Zone Comparison Out:=ZoneCmp(MN, In, (@)ZoneCmp MX); Variables Name Meaning Description Valid range Unit Default Minimum value...
  • Page 149: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions Function The ZoneCmp instruction determines if comparison data In is between maximum value MX and mini- mum value MN. If MX ≥ In ≥ MN, Out will be TRUE. Otherwise, Out will be FALSE. The following example is for when MN is INT#10, In is INT#20 and MX is INT#30. The value of variable abc will be TRUE.
  • Page 150: Tablecmp

    2 Instruction Descriptions TableCmp The TableCmp instruction compares the comparison data with multiple defined ranges in a comparison table. Instruction Name FB/FUN Graphic expression ST expression TableCmp Table Comparison Out:=TableCmp(In, Table, (@)TableCmp Size, AryOut); Table Size AryOut Variables Name Meaning Description Valid range Unit...
  • Page 151: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions Times, durations, Bit strings Integers dates, and text strings OK OK OK OK OK OK OK OK OK OK Table[] (two- dimen- Must be a two-dimensional array with elements that have the same data type as In. sional array) Size...
  • Page 152: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions The following example is for when In is INT#120 and Size is UINT#3. ghi:=TableCmp(INT#120, abc[1,2], UINT#3, def[3]); TableCmp INT#120 abc[1,2] Table UINT#3 Size AryOut def[3] def[3] In=INT#120 FALSE AryOut[0]=def[3] Table[0,0]=abc[1,2] Table[0,1]=abc[1,3] TRUE Table[1,0]=abc[2,2] Table[1,1]=abc[2,3] AryOut[1]=def[4] Size=UINT#3 Table[2,0]=abc[3,2] FALSE AryOut[2]=def[5] Table[2,1]=abc[3,3]...
  • Page 153: Arycmpeq And Arycmpne

    2 Instruction Descriptions AryCmpEQ and AryCmpNE These instructions compare the values of the elements of two arrays. AryCmpEQ: Determines if the elements are equal. AryCmpNE: Determines if the elements are not equal. Instruction Name FB/FUN Graphic expression ST expression AryCmpEQ Array Comparison AryCmpEQ(In1, In2, Size, (@)AryCmpEQ...
  • Page 154: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions Function These instructions compare the values of the elements with the same element numbers in two arrays (In1[0] to In1[Size−1] and In2[0] and In2[Size−1]). The comparison results are stored in comparison results array AryOut[] in the elements with the corresponding element numbers (AryOut[0] to Ary- Out[Size −1]).
  • Page 155: Arycmplt, Arycmple, Arycmpgt, And Arycmpge

    2 Instruction Descriptions AryCmpLT, AryCmpLE, AryCmpGT, and AryCmpGE These instructions compare the values of the elements of two arrays. AryCmpLT: Performs a less than comparison. AryCmpLE: Performs a less than or equal comparison. AryCmpGT: Performs a greater than comparison. AryCmpGE: Performs a greater than or equal comparison.
  • Page 156: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions Variables Name Meaning Description Valid range Unit Default In1[] and Comparison Arrays containing the ele- Depends on data type. In2[] arrays ments to compare (arrays) Input Size Number of Number of elements to com- Depends on data type. comparison pare elements...
  • Page 157: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions Function These instructions compare the values of the elements with the same element numbers in two arrays (In1[0] to In1[Size −1] and In2[0] and In2[Size −1]). The comparison results are stored in comparison results array AryOut[] in the elements with the corresponding element numbers (AryOut[0] to Ary- Out[Size −1]).
  • Page 158: Arycmpeqv And Arycmpnev

    2 Instruction Descriptions AryCmpEQV and AryCmpNEV These instructions compare a value to the values of the elements of an array. AryCmpEQV: Determines if the elements are equal. AryCmpNEV: Determines if the elements are not equal. Instruction Name FB/FUN Graphic expression ST expression AryCmpEQV Array Value Com-...
  • Page 159: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions Function These instructions compare comparison value In2 with the specified elements in an array (In1[0] to In1[Size −1]). The comparison results are stored in comparison results array AryOut[] in the elements with the corresponding element numbers (AryOut[0] to AryOut[Size −1]). The value of AryOut[i] is as follows for each instruction: Instruction Value of AryOut[i]...
  • Page 160: Arycmpltv, Arycmplev, Arycmpgtv, And Arycmpgev

    2 Instruction Descriptions AryCmpLTV, AryCmpLEV, AryCmpGTV, and AryCmpGEV These instructions compare a value to the values of the elements of an array. AryCmpLTV: Performs a less than comparison. AryCmpLEV: Performs a less than or equal comparison. AryCmpGTV: Performs a greater than comparison. AryCmpGEV: Performs a greater than or equal comparison.
  • Page 161: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions Variables Name Meaning Description Valid range Unit Default In1[] (array) Comparison Array containing the ele- array ments to compare Depends on data type. Comparison Value to compare value Input Size Number of Number of elements to com- Depends on data type.
  • Page 162: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions Function These instructions compare comparison value In2 with the specified elements in an array (In1[0] to In1[Size − 1]). The comparison results are stored in comparison results array AryOut[] in the elements with the corresponding element numbers (AryOut[0] to AryOut[Size −1]). The value of AryOut[i] is as follows for each instruction: Instruction Value of AryOut[i]...
  • Page 163: Timer Instructions

    Timer Instructions Instruction Name Page On-Delay Timer 2-116 Off-Delay Timer 2-120 Timer Pulse 2-123 AccumulationTimer Accumulation Timer 2-126 Timer Hundred-ms Timer 2-129 NJ-series Instructions Reference Manual (W502) 2-115...
  • Page 164: Ton

    2 Instruction Descriptions The TON instruction outputs TRUE when the set time elapses after the timer starts. Instruction Name FB/FUN Graphic expression ST expression On-Delay Timer TON_instance (In, PT, Q, TON_instance ET); Variables Name Meaning Description Valid range Unit Default Timer input TRUE: Timer start signal Depends on data type.
  • Page 165: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions The following figure shows a programming example and timing chart when PT is T#10ms. Variable abc will change to TRUE 10 ms after variable A changes to TRUE. TON_instance(A, T#10ms, abc, def); TON_instance T#10ms PT=T#10ms TRUE In=A FALSE TRUE Q=abc...
  • Page 166: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions • If this instruction is not executed due to the execution of a jump instruction (e.g., the JMP instruction), the value of ET is not updated. However, timing still continues. Therefore, ET is updated to the correct value the next time the instruction is executed.
  • Page 167 2 Instruction Descriptions TON_instance[0] TimeUp[0] TRUE TON_instance[1] TimeUp[1] TRUE TON_instance[9] TimeUp[9] TRUE TON_instance[10] TimeUp[10] TRUE TON_instance[99] TimeUp[99] TRUE Data type Comment Variable Initial value [100(False)] Input Timer input ARRAY[0..99] OF BOOL [100(False)] TimeUp Timer output ARRAY[0..99] OF BOOL [T#1s, T#2s, T#3s, T#4s, T#5s, T#6s, Set time TimePT ARRAY[0..99] OF TIME...
  • Page 168: Tof

    2 Instruction Descriptions The TOF instruction outputs FALSE when the set time elapses after the timer starts. Instruction Name FB/FUN Graphic expression ST expression Off-Delay Timer TOF_instance (In, PT, Q, TOF_instance ET); Variables Name Meaning Description Valid range Unit Default Timer input TRUE: Timer reset signal Depends on data type.
  • Page 169: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions The following figure shows a programming example and timing chart for a PT of T#10ms. Variable abc will change to FALSE 10 ms after variable A changes to FALSE. TOF_instance(A, T#10ms, abc, def); TOF_instance T#10ms PT=T#10ms TRUE In=A FALSE TRUE...
  • Page 170: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions • If this instruction is not executed due to the execution of a jump instruction (e.g., the JMP instruction), the value of ET is not updated. However, timing still continues. Therefore, ET is updated to the correct value the next time the instruction is executed.
  • Page 171: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions The TP instruction outputs TRUE while the set time elapses after the timer starts. Instruction Name FB/FUN Graphic expression ST expression Timer Pulse TP_instance (In, PT, Q, TP_instance ET); Variables Name Meaning Description Valid range Unit Default Timer input TRUE: Timer start signal Depends on data type.
  • Page 172: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions The following figure shows a programming example and timing chart for a PT of T#10ms. Variable abc changes to TRUE as soon as variable A changes to TRUE. Variable abc changes to FALSE 10 ms later. TP_instance(A, T#10ms, abc, def); TP_instance T#10ms PT=T#10ms...
  • Page 173: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions • If this instruction is not executed due to the execution of a jump instruction (e.g., the JMP instruction), the value of ET is not updated and timing is not performed. Timing restarts when the instruction is executed again.
  • Page 174: Accumulationtimer

    2 Instruction Descriptions AccumulationTimer The AccumulationTimer instruction totals the time that the timer input is TRUE. Instruction Name FB/FUN Graphic expression ST expression AccumulationTimer Accumulation Timer FB AccumulationTimer_instanc AccumulationTimer_instance e(In, PT, Reset, Q, ET); AccumulationTimer Reset Variables Name Meaning Description Valid range Unit Default...
  • Page 175: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions The following figure shows a programming example and timing chart for a PT of T#10ms. Variable abc changes to TRUE when variable A is TRUE for a total of 10 ms (i.e., the total time). AccumulationTimer_instance(A, T#10ms, abc, def, ghi); AccumulationTimer_instance AccumulationTimer T#10ms...
  • Page 176: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions • If this instruction is in a master control region and the master control region is reset, the operation is as follows: • The timer stops. The values of ET and Q at that time are retained. •...
  • Page 177: Timer

    2 Instruction Descriptions Timer The Timer instruction outputs TRUE when the set time elapses after the timer starts. Set the time in increments of 100 ms. The timing accuracy is 100 ms. Instruction Name FB/FUN Graphic expression ST expression Timer Hundred-ms Timer Out:=Timer (In, PT, Tim- Timer...
  • Page 178: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions The timer is reset when timer input In changes to FALSE. Remaining time ET is set to set time PT, and timer output Q changes to FALSE. The timer starts when In changes to TRUE. The value of ET is timed down. When the value of ET reaches 0, timer output Q changes to TRUE.
  • Page 179: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions • If this instruction is used in a ladder diagram, the values of Q and Out change to FALSE if an error occurs in the previous instruction on the rung. NJ-series Instructions Reference Manual (W502) 2-131...
  • Page 180: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions 2-132 NJ-series Instructions Reference Manual (W502)
  • Page 181: Counter Instructions

    Counter Instructions Instruction Name Page Down-counter 2-134 CTD_** Down-counter Group 2-136 Up-counter 2-138 CTU_** Up-counter Group 2-140 CTUD Up-down Counter 2-142 CTUD_** Up-down Counter Group 2-146 NJ-series Instructions Reference Manual (W502) 2-133...
  • Page 182: Ctd

    2 Instruction Descriptions The CTD instruction decrements the counter value when the counter input signal is received. The pre- set value and counter value must have an INT data type. Instruction Name FB/FUN Graphic expression ST expression Down-counter CTD_instance (CD, Load, CTD_instance PV, Q, CV);...
  • Page 183: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions The following figure shows a programming example and timing chart for a PV of LINT#5. CTD_instance(A, abc, LINT#5, def, ghi); CTD_instance Load LINT#5 TRUE CD=A FALSE TRUE Load=abc FALSE PV=LINT#5 CV=ghi TRUE Q=def FALSE When Load changes to TRUE, CV When CV reaches 0, Q is set to the value of PV and Q changes to TRUE.
  • Page 184: Ctd_**

    2 Instruction Descriptions CTD_** The CTD_** instruction decrements the counter value when the counter input signal is received. The preset value and counter value must be one of the following data types: DINT, LINT, UDINT, or ULINT. Instruction Name FB/FUN Graphic expression ST expression CTD_**...
  • Page 185: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions After the value of CV reaches 0 or less, CV does not change even if CD changes to TRUE. CD is ignored while Load is TRUE. CV is not decremented. The following figure shows a CTD_LINT programming example and timing chart for a PV of LINT#5. CTD_LINT_instance(A, abc, LINT#5, def, ghi);...
  • Page 186: Ctu

    2 Instruction Descriptions The CTU instruction increments the counter value when the counter input signal is received. The preset value and counter value must have an INT data type. Instruction Name FB/FUN Graphic expression ST expression Up-counter CTU_instance (CU, Reset, CTU_instance PV, Q, CV);...
  • Page 187: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions The following figure shows a programming example and timing chart for a PV of LINT#5. CTU_instance(A, abc, LINT#5, def, ghi); CTU_instance Reset LINT#5 TRUE CU=A FALSE TRUE Reset=abc FALSE PV=LINT#5 CV=ghi TRUE Q=def FALSE When Reset changes to TRUE, When CV reaches PV , Q CV is reset to 0 and Q changes to changes to TRUE.
  • Page 188: Ctu_**

    2 Instruction Descriptions CTU_** The CTU_** instruction increments the counter value when the counter input signal is received. The preset value and counter value must be one of the following data types: DINT, LINT, UDINT, or ULINT. Instruction Name FB/FUN Graphic expression ST expression CTU_**...
  • Page 189: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions After the value of CV reaches the value of PV or higher, the value of CV does not change even if the value of CU changes to TRUE. CU is ignored while Reset is TRUE. CV is not incremented. The following figure shows a CTU_LINT programming example and timing chart for a PV of LINT#5.
  • Page 190: Ctud

    2 Instruction Descriptions CTUD The CTUD instruction creates an up-down counter that operates according to an up-counter input and a down-counter input. The preset value and counter value must have an INT data type. Instruction Name FB/FUN Graphic expression ST expression CTUD Up-down Counter CTUD_instance (CU, CD,...
  • Page 191: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions Times, durations, Bit string Integers dates, and text strings Function The CTUD instruction creates an up-down counter that operates according to an up-counter input sig- nal and a down-counter input signal. It has the functions of both an up counter and a down counter. The preset value and counter value must have an INT data type.
  • Page 192: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions The following table shows the relationship between Reset, Load, CV, QU, and QD. This assumes that the value of PV is larger than 0. Reset Load Operation 0 or FALSE TRUE Only up counter operation is performed. lower •...
  • Page 193: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions TRUE CU=A FALSE TRUE CD=B FALSE TRUE Reset=abc FALSE TRUE Load=def FALSE PV=INT#3 CV=mno TRUE QU=ghi FALSE TRUE QD=jkl FALSE When CV reaches PV, QU changes to TRUE. When Reset changes to TRUE, CV changes to 0, QU changes to FALSE, and QD changes to TRUE.
  • Page 194: Ctud

    2 Instruction Descriptions CTUD_** The CTUD_** instruction creates an up-down counter that operates according to an up-counter input and a down-counter input. The preset value and counter value must be one of the following data types: DINT, LINT, UDINT, or ULINT. Instruction Name FB/FUN...
  • Page 195: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions Times, durations, Bit string Integers dates, and text strings Reset Load OK OK OK OK Must be the same data type as PV Function A CTUD_** instruction creates an up-down counter that operates according to an up-counter input sig- nal and a down-counter input signal.
  • Page 196: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions The following table shows the relationship between Reset, Load, CV, QU, and QD. This assumes that the value of PV is larger than 0. Reset Load Operation 0 or FALSE TRUE Only up counter operation is performed. lower •...
  • Page 197: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions TRUE CU=A FALSE TRUE CD=B FALSE TRUE Reset=abc FALSE TRUE Load=def FALSE PV=LINT#3 CV=mno TRUE QU=ghi FALSE TRUE QD=jkl FALSE When CV reaches PV, QU changes to TRUE. When Reset changes to TRUE, CV changes to 0, QU changes to FALSE, and QD changes to TRUE.
  • Page 198: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions • If the value of CU or CD is FALSE and the power supply is interrupted or the operating mode is changed to PROGRAM mode, the value of CV is incremented or decremented once if the value of CU or CD is TRUE when instruction execution is restarted.
  • Page 199: Math Instructions

    Math Instructions Instruction Name Page Instruction Name Page ADD (+) Addition 2-152 Natural Exponential Opera- 2-185 tion AddOU (+OU) Addition with Overflow/Under- 2-154 EXPT (**) Exponentiation 2-187 flow Check SUB (-) Subtraction 2-156 Inc and Dec Increment/Decrement 2-189 SubOU (-OU) Subtraction with Over- 2-158 Rand...
  • Page 200: Add (+)

    2 Instruction Descriptions ADD (+) The ADD (+) instruction adds integers or real numbers. It also joins text strings. Instruction Name FB/FUN Graphic expression ST expression ADD (+) Addition Out:=In1 + ··· + InN; (@)ADD (@)+ EN ENO Variables Name Meaning Description Valid range...
  • Page 201: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions If In1 to InN are STRING data, the text strings are joined. However, if In1 to InN are STRING data, you must use the instruction in a ladder diagram. The following example is for when In1 is UV, In2 is WX and In3 is YZ. The value of variable abc will be UVWXYZ.
  • Page 202: Addou (+Ou)

    2 Instruction Descriptions AddOU (+OU) The AddOU (+OU) instruction adds integers and real numbers. It also performs an overflow/underflow check. Instruction Name FB/FUN Graphic expression ST expression AddOU (+OU) Addition with Over- Out:=AddOU(In1, ···, InN); (@)AddOU flow/Underflow Check (@)+OU Variables Name Meaning Description...
  • Page 203: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions abc:=AddOU(INT#32767, INT#1); AddOU INT#32767 INT#1 The functions of the AddOU instruction and the +OU instruction are exactly the same. Use the form that is easier to use. Related System-defined Variables Name Meaning Data type Description P_CY Carry (CY) Flag BOOL TRUE: There is an overflow or underflow.
  • Page 204: Sub

    2 Instruction Descriptions SUB (-) The SUB (-) instruction subtracts integers and real numbers. Instruction Name Graphic expression ST expression FB/FUN SUB (-) Subtraction Out:=In1 - In2; (@)SUB (@)- EN ENO Variables Name Meaning Description Valid range Unit Default Minuend Minuend Input Depends on data type.
  • Page 205: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions Additional Information When you calculate real numbers, use the CheckReal instruction (page 2-209) to see if Out is positive infinity, negative infinity, or nonnumeric data. Precautions for Correct Use • Set the data type of Out to include the valid ranges of In1 and In2. •...
  • Page 206: Subou (-Ou)

    2 Instruction Descriptions SubOU (-OU) The SubOU (-OU) instruction subtracts integers or real numbers. It also performs an overflow/underflow check. Instruction Name FB/FUN Graphic expression ST expression SubOU (-OU) Subtraction with Out:=SubOU(In1, In2); (@)SubOU Overflow/Under- flow Check (@)-OU Variables Name Meaning Description Valid range...
  • Page 207: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions The following example is for when In1 is SINT#-128, In2 is SINT#1 and variable abc has an SINT data type. The subtraction result (−129) exceeds the valid range of SINT data, so the value of P_CY changes to TRUE.
  • Page 208: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions • If the value of Out is positive infinity, negative infinity, or nonnumeric data, the value of P_CY does not change. • You can subtract a real number from an integer or an integer from a real number. If you do, Out is a real number.
  • Page 209: Mul (*)

    2 Instruction Descriptions MUL (*) The MUL (*) instruction multiplies integers and real numbers. Instruction Name FB/FUN Graphic expression ST expression MUL (*) Multiplication Out:=In1 * ··· * InN; (@)MUL (@)* EN ENO Variables Name Meaning Description Valid range Unit Default In1 to InN Values to...
  • Page 210: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions abc:=INT#10*INT#20*INT#30; INT#10 INT#20 INT#30 The functions of the MUL instruction and the * instruction are exactly the same. Use the form that is easier to use. Additional Information When you calculate real numbers, use the CheckReal instruction (page 2-209) to see if Out is positive infinity, negative infinity, or nonnumeric data.
  • Page 211: Mulou (*Ou)

    2 Instruction Descriptions MulOU (*OU) The MulOU (*OU) instruction multiplies integers and real numbers and outputs the result. It also per- forms an overflow/underflow check. Instruction Name FB/FUN Graphic expression ST expression MulOU (*OU) Multiplication with Out:=MulOU(In1, ···, InN); (@)MulOU Overflow/Under- flow Check (@)*OU...
  • Page 212: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions The following example is for when In1 is INT#20000, In2 is INT#2 and variable abc has an INT data type. The multiplication result (40000) exceeds the valid range of INT data, so the value of P_CY changes to TRUE. The value of variable abc will be INT#−25536 (the lower 16 bits of 40000). abc:=MulOU(INT#20000, INT#2);...
  • Page 213: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions • If the value of Out is positive infinity, negative infinity, or nonnumeric data, the value of P_CY does not change. • You can multiply real numbers and integers. If you do, Out is a real number. NJ-series Instructions Reference Manual (W502) 2-165...
  • Page 214: Div (/)

    2 Instruction Descriptions DIV (/) The DIV (/) instruction divides integers or real numbers. Instruction Name FB/FUN Graphic expression ST expression DIV (/) Division Out:=In1/ In2; (@)DIV (@)/ EN ENO Variables Name Meaning Description Valid range Unit Default Dividend Dividend Input Depends on data type.
  • Page 215: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions The functions of the DIV instruction and the / instruction are exactly the same. Use the form that is eas- ier to use. Additional Information When you calculate real numbers, use the CheckReal instruction (page 2-209) to see if Out is positive infinity, negative infinity, or nonnumeric data.
  • Page 216: Mod

    2 Instruction Descriptions The MOD instruction finds the remainder for division of integers. Instruction Name FB/FUN Graphic expression ST expression Modulo-division Out:=In1 MOD In2; (@)MOD Variables Name Meaning Description Valid range Unit Default Dividend Dividend Input Depends on data type. Divisor Divisor Remainder...
  • Page 217: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions The following example is for when In1 is INT#18 and In2 is INT#5. The value of variable abc will be INT#3. abc:=INT#18 MOD INT#5; INT#18 INT#5 Precautions for Correct Use • Set the data type of Out to include the valid ranges of In1 and In2. •...
  • Page 218: Abs

    2 Instruction Descriptions The ABS instruction finds the absolute value of an integer or real number. Instruction Name FB/FUN Graphic expression ST expression Absolute Value Out:=ABS(In); (@)ABS Variables Name Meaning Description Valid range Unit Default Number to Input Number to process Depends on data type.
  • Page 219: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions Additional Information When you calculate real numbers, use the CheckReal instruction (page 2-209) to see if Out is positive infinity, negative infinity, or nonnumeric data. Precautions for Correct Use • Set the data type of Out to include the absolute value of In. •...
  • Page 220: Radtodeg And Degtorad

    2 Instruction Descriptions RadToDeg and DegToRad RadToDeg: Converts a real number from radians (rad) to degrees (°). DegToRad: Converts a real number from degrees (°) to radians (rad). Instruction Name FB/FUN Graphic expression ST expression RadToDeg Radians to Degrees FUN Out:=RadToDeg(In);...
  • Page 221: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions The following example for the DegToRad instruction is for when In is REAL#45. The value of the REAL variable abc will be REAL#0.785398. abc:=DegToRad(REAL#45); DegToRad REAL#45 Additional Information Use the CheckReal instruction (page 2-209) to see if Out is positive infinity, negative infinity, or nonnu- meric data.
  • Page 222: Sin, Cos, And Tan

    2 Instruction Descriptions SIN, COS, and TAN These instructions perform trigonometric calculations on real numbers. SIN: Finds the sine of a number. COS: Finds the cosine of a number. TAN: Finds the tangent of a number. Instruction Name FB/FUN Graphic expression ST expression Sine in Radians Out:=SIN(In);...
  • Page 223: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions Function These instructions perform trigonometric calculations on real numbers. Number to process In is an angle in radians (rad). The SIN instruction finds the sine of In. −1 The COS instruction finds the cosine of In. −1 The TAN instruction finds the tangent of In.
  • Page 224: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions The following example for the COS instruction is for when In is REAL#3.141592. The value of vari- able abc will be REAL#−1.0. abc:=COS(REAL#3.141592); REAL#3.141592 Additional Information • Use the RadToDeg and DegToRad instructions (page 2-172) to convert between degrees and radi- ans.
  • Page 225: Asin, Acos, And Atan

    2 Instruction Descriptions ASIN, ACOS, and ATAN These instructions perform inverse trigonometric calculations on real numbers. ASIN: Finds the arc sine of a number. ACOS: Finds the arc cosine of a number. ATAN: Finds the arc tangent of a number. Instruction Name FB/FUN...
  • Page 226: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions −1.0 − ACOS The ACOS instruction finds the arc cosine of In. Out is between 0 and π. −1.0 ATAN The ATAN instruction finds the arc tangent of In. Out is between −π/2 and π/2. If the value of In is positive infinity, the value of Out is π/2. If the value of In is negative infinity, the value of Out is −π/2.
  • Page 227: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions The following example for the ACOS instruction is for when In is REAL#−1.0. The value of variable abc will be REAL#3.141592. abc:=ACOS(REAL#-1.0); ACOS REAL#-1.0 Additional Information Use the RadToDeg and DegToRad instructions (page 2-172) to convert between degrees and radians. Precautions for Correct Use •...
  • Page 228: Sqrt

    2 Instruction Descriptions SQRT The SQRT instruction finds the square root of a number. Instruction Name FB/FUN Graphic expression ST expression SQRT Square Root Out:=SQRT(In); (@)SQRT Variables Name Meaning Description Valid range Unit Default Number to Input Number to process Depends on data type.
  • Page 229: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions The following example is for when In is REAL#16.0. The value of variable abc will be REAL#4.0. abc:=SQRT(REAL#16.0); SQRT REAL#16.0 Additional Information Use the CheckReal instruction (page 2-209) to see if the value of Out is positive infinity. Precautions for Correct Use •...
  • Page 230: Ln And Log

    2 Instruction Descriptions LN and LOG These instructions find the logarithm of a real number. Finds the natural logarithm of a number. LOG: Finds the base-10 logarithm of a number. Instruction Name FB/FUN Graphic expression ST expression Natural Logarithm Out:=LN(In); (@)LN Logarithm Base 10 Out:=LOG(In);...
  • Page 231: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions Function These instructions find the logarithm of a real number. The LN instruction finds the natural logarithm (logarithm to base e, where e = 2.718282). 2.718282 The LOG instruction finds the base-10 logarithm. The following example for the LOG instruction is for when In is REAL#1000.0. The value of variable abc will be REAL#3.0.
  • Page 232: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions Additional Information Use the CheckReal instruction (page 2-209) to see if Out is positive infinity, negative infinity, or nonnu- meric data. Precautions for Correct Use • If the value of In is not a positive number, the value of Out is as shown below. Value of In Value of Out Negative number...
  • Page 233: Exp

    2 Instruction Descriptions The EXP instruction performs calculations for the natural exponential function. Instruction Name FB/FUN Graphic expression ST expression Natural Exponen- Out:=EXP(In); (@)EXP tial Operation Variables Name Meaning Description Valid range Unit Default Exponent Input Exponent Depends on data type. Calculation Output Calculation result...
  • Page 234: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions Precautions for Correct Use • If the value of In is 0.0, positive infinity, negative infinity, or nonnumeric data, the value of Out is as shown below. Value of In Value of Out +∞ +∞ −∞ Nonnumeric data Nonnumeric data •...
  • Page 235: Expt (**)

    2 Instruction Descriptions EXPT (**) The EXPT (**) instruction raises one real number to the power of another real number. Instruction Name FB/FUN Graphic expression ST expression EXPT (**) Exponentiation Out:=EXPT(In, Pwr); (@)EXPT Out:=In ** Pwr; (@)** EN ENO Variables Name Meaning Description...
  • Page 236: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions Additional Information • Use the EXP instruction (page 2-185) to find powers of base e. • Use the CheckReal instruction (page 2-209) to see if Out is positive infinity, negative infinity, or non- numeric data. Precautions for Correct Use •...
  • Page 237: Inc And Dec

    2 Instruction Descriptions Inc and Dec Inc: Increments an integer value. Dec: Decrements an integer value. Instruction Name FB/FUN Graphic expression ST expression Increment Inc(InOut); (@)Inc InOut Decrement Dec(InOut); (@)Dec InOut Variables Name Meaning Description Valid range Unit Default InOut Target data In-out Target data...
  • Page 238: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions The following example for the Inc instruction is for when variable abc is passed to InOut. Inc(abc); InOut Precautions for Correct Use Return value Out is not used when the instruction is used in ST. 2-190 NJ-series Instructions Reference Manual (W502)
  • Page 239: Rand

    2 Instruction Descriptions Rand The Rand instruction generates pseudorandom numbers. Instruction Name FB/FUN Graphic expression ST expression Rand Random Number Rand_instance(Execute, Rand_instance Seed, Rnd); Rand Execute ENO Seed Variables Name Meaning Description Valid range Unit Default Seed Random num- Input Random number pattern Depends on data type.
  • Page 240: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions Additional Information The value of Rnd is a real number between 0 and 1. Use the following processing to generate ran- dom numbers within a specific range. Example: The following formula generates random numbers between 100 and 200. Rand_instance(A, UINT#1, abc);...
  • Page 241: Aryadd

    2 Instruction Descriptions AryAdd The AryAdd instruction adds corresponding elements of two arrays. Instruction Name FB/FUN Graphic expression ST expression AryAdd Array Addition AryAdd(In1, In2, Size, Ary- (@)AryAdd Out); Size AryOut Variables Name Meaning Description Valid range Unit Default In1[] (array) Array to Array to process and In2[]...
  • Page 242: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions The following example is for when Size is UINT#3. AryAdd(abc[1], def[2], UINT#3, ghi[3]); AryAdd abc[1] def[2] UINT#3 Size AryOut ghi[3] ghi[3] In1[0]=abc[1] In2[0]=def[2] AryOut[0]=ghi[3] 1234 2345 3579 In1[1]=abc[2] 2345 In2[1]=def[3] 3456 AryOut[1]=ghi[4] 5801 Size=UINT#3 In1[2]=abc[3] 3456 In2[2]=def[4] 4567 AryOut[2]=ghi[5] 8023...
  • Page 243: Aryaddv

    2 Instruction Descriptions AryAddV The AryAddV instruction adds the same value to specified elements of an array. Instruction Name FB/FUN Graphic expression ST expression AryAddV Array Value AryAddV(In1, In2, Size, Ary- (@)AryAddV Addition Out); Size AryOut Variables Name Meaning Description Valid range Unit Default...
  • Page 244: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions The following example is for when In2 is INT#11 and Size is UINT#3. AryAddV(abc[1], INT#11, UINT#3, def[2]); AryAddV abc[1] INT#11 UINT#3 Size AryOut def[2] def[2] In1[0]=abc[1] In2=INT#11 AryOut[0]=def[2] Size=UINT#3 In1[1]=abc[2] In2=INT#11 AryOut[1]=def[3] In1[2]=abc[3] In2=INT#11 AryOut[2]=def[4] Precautions for Correct Use •...
  • Page 245: Arysub

    2 Instruction Descriptions ArySub The ArySub instruction subtracts corresponding elements of two arrays. Instruction Name FB/FUN Graphic expression ST expression ArySub Array Subtraction ArySub(In1, In2, Size, Ary- (@)ArySub Out); Size AryOut Variables Name Meaning Description Valid range Unit Default In1[] (array) Minuend Minuend array array...
  • Page 246: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions The following example is for when Size is UINT#3. ArySub(abc[1], def[2], UINT#3, ghi[3]); ArySub abc[1] def[2] UINT#3 Size AryOut ghi[3] ghi[3] In1[0]=abc[1] In2[0]=def[2] AryOut[0]=ghi[3] In1[1]=abc[2] In2[1]=def[3] AryOut[1]=ghi[4] Size=UINT#3 In1[2]=abc[3] In2[2]=def[4] AryOut[2]=ghi[5] Precautions for Correct Use • Use the same data type for In1[], In2[], and AryOut[]. •...
  • Page 247: Arysubv

    2 Instruction Descriptions ArySubV The ArySubV instruction subtracts the same value from specified elements of an array. Instruction Name FB/FUN Graphic expression ST expression ArySubV Array Value ArySubV(In1, In2, Size, Ary- (@)ArySubV Subtraction Out); Size AryOut Variables Name Meaning Description Valid range Unit Default...
  • Page 248: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions The following example is for when In2 is INT#11 and Size is UINT#3. ArySubV(abc[1], INT#11, UINT#3, def[2]); ArySubV abc[1] INT#11 UINT#3 Size AryOut def[2] def[2] In1[0]=abc[1] In2=INT#11 AryOut[0]=def[2] In1[1]=abc[2] In2=INT#11 AryOut[1]=def[3] Size=UINT#3 In1[2]=abc[3] In2=INT#11 AryOut[2]=def[4] Precautions for Correct Use •...
  • Page 249: Arymean

    2 Instruction Descriptions AryMean The AryMean instruction calculates the average of the elements of an array. Instruction Name FB/FUN Graphic expression ST expression AryMean Array Mean Out := AryMean(In, Size); (@)AryMean Size Variables Name Meaning Description Valid range Unit Default In[] (array) Array to Array to process...
  • Page 250: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions Precautions for Correct Use • Refer to the descriptions of the functions of the ADD (+) instruction (page 2-152), SUB (−) instruction (page 2-156), MUL (*) instruction (page 2-161), and DIV (/) instruction (page 2-166) for the calcula- tion results when the value of In[] is positive infinity, negative infinity, or nonnumeric data.
  • Page 251: Arysd

    2 Instruction Descriptions ArySD The ArySD instruction calculates standard deviation of the elements of an array. Instruction Name FB/FUN Graphic expression ST expression ArySD Array Element Out:=ArySD(In, Size); (@)ArySD Standard Deviation Size Variables Name Meaning Description Valid range Unit Default In[] (array) Array to Array to process...
  • Page 252: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions The following example is for when Size is UINT#5. def:=ArySD(abc[1], UINT#5); ArySD abc[1] UINT#5 Size In[0]=abc[1] 123.4 In[1]=abc[2] 234.5 Standard deviation calculated. Size=UINT#5 In[2]=abc[3] 175.6645 345.6 Out=def In[3]=abc[4] 456.7 In[4]=abc[5] 567.8 Precautions for Correct Use • If the value of Size is 0 or 1, the value of Out is 0. •...
  • Page 253: Modreal

    2 Instruction Descriptions ModReal The ModReal instruction calculates the remainder of real number division. Instruction Name FB/FUN Graphic expression ST expression ModReal Real Number Out:=ModReal(In1, In2); (@)ModReal Modulo-division Variables Name Meaning Description Valid range Unit Default Dividend Dividend Input Depends on data type. Divisor Divisor Remainder...
  • Page 254: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions Additional Information Use the CheckReal instruction (page 2-209) to see if the value of Out is positive infinity, negative infinity, or nonnumeric data. Precautions for Correct Use • The following table shows the values of Out for different combinations of In1 and In2 values. Nonnumeric −∞...
  • Page 255: Fraction

    2 Instruction Descriptions Fraction The Fraction instruction finds the fractional part of a real number. Instruction Name FB/FUN Graphic expression ST expression Fraction Real Number Out:=Fraction(In); (@)Fraction Fraction Variables Name Meaning Description Valid range Unit Default Real num- Input Real number Depends on data type.
  • Page 256: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions • If you pass an integer parameter to In, the data type is converted as follows: Data type of parameter that is Data type of In passed to In USINT, UINT, SINT, or INT REAL UDINT or DINT LREAL ULINT or LINT A building error will occur.
  • Page 257: Checkreal

    2 Instruction Descriptions CheckReal The CheckReal instruction checks a real number to see if it is infinity or nonnumeric data. Instruction Name FB/FUN Graphic expression ST expression CheckReal Real Number CheckReal(In, Nan, PosInfi- (@)CheckReal Check nite, NegInfinite); PosInfinite NegInfinite Variables Name Meaning Description...
  • Page 258: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions Function The CheckReal instruction checks a real number In to see if it is nonnumeric data, positive infinity, or negative infinity. It outputs the results to Nan, PosInfinite, and NegInfinite. The following figure shows a programming example. The values of REAL variables a and b are multi- plied and the result is tested to see if it is a real number.
  • Page 259: Bcd Conversion Instructions

    BCD Conversion Instructions Instruction Name Page **_BCD_TO_*** BCD-to-Unsigned Integer Conver- 2-212 sion Group **_TO_BCD_*** Unsigned Integer-to-BCD Conver- 2-215 sion Group BCD_TO_** BCD Data Type-to-Unsigned Inte- 2-218 ger Conversion Group BCDsToBin Signed BCD-to-Signed Integer 2-221 Conversion BinToBCDs_** Signed Integer-to-BCD Conver- 2-224 sion Group AryToBCD Array BCD Conversion...
  • Page 260: **_Bcd_To

    2 Instruction Descriptions **_BCD_TO_*** These instructions convert BCD bit strings into unsigned integers. Instruction Name FB/FUN Graphic expression ST expression **_BCD_TO_*** BCD-to-Unsigned Out:=**_BCD_TO_*** (In); (@)**_BCD_TO_*** Integer Conversion Group "**" must be a bit string data type. "***" must be an integer data "**"...
  • Page 261: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions The following table shows the valid ranges for In and Out according to their data types. Data type Data type Valid range for In Valid range for Out of In of Out USINT UINT UDINT ULINT BYTE 16#00 to 16#99 (BCD) 0 to 99 SINT...
  • Page 262: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions • The value of In is outside of the valid range. • The value in In is not BCD bit string data (i.e., contains A, B, C, D, E, or F hexadecimal). 2-214 NJ-series Instructions Reference Manual (W502)
  • Page 263: **_To_Bcd

    2 Instruction Descriptions **_TO_BCD_*** These instructions convert unsigned integers to BCD bit strings. Instruction Name FB/FUN Graphic expression ST expression **_TO_BCD_*** Unsigned Integer- Out:=**_TO_BCD_*** (In); (@)**_TO_BCD_*** to-BCD Conversion Group "**" must be an integer data type. "***" must be a bit string "**"...
  • Page 264: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions The following table shows the valid ranges for In and Out according to their data types. Data type Data type Valid range for In Valid range for Out of In of Out BYTE 0 to 99 16#00 to 16#99 (BCD) WORD 16#0000 to 16#0255 (BCD) USINT...
  • Page 265: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions • The value of In is outside of the valid range. NJ-series Instructions Reference Manual (W502) 2-217...
  • Page 266: Bcd_To

    2 Instruction Descriptions BCD_TO_** The BCD_TO_** instruction converts BCD bit strings into unsigned integers. Instruction Name FB/FUN Graphic expression ST expression BCD_TO_** BCD Data Type-to- Out:=BCD_TO_** (In); (@)BCD_TO_** Unsigned Integer Conversion Group "**" must be an integer data type. "**" must be an integer data type. Variables Name Meaning...
  • Page 267: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions The following table shows the valid ranges for In and Out according to their data types. Data type Data type Valid range for In Valid range for Out of In of Out USINT UINT UDINT ULINT BYTE 16#00 to 16#99 (BCD) 0 to 99 SINT...
  • Page 268: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions • The value of In is outside of the valid range. • The value in In is not BCD bit string data (i.e., contains A, B, C, D, E, or F hexadecimal). 2-220 NJ-series Instructions Reference Manual (W502)
  • Page 269: Bcdstobin

    2 Instruction Descriptions BCDsToBin The BCDsToBin instruction converts signed BCD bit strings to signed integers. Instruction Name FB/FUN Graphic expression ST expression BCDsToBin Signed BCD-to- Out:=BCDsToBin(In, Format); (@)BCDsToBin Signed Integer Conversion Format Variables Name Meaning Description Valid range Unit Default Data to Data to convert convert...
  • Page 270: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions The data type of data format number Format is enumerated type _eBCD_FORMAT. Select one of the following: _BCD0, _BCD1, _BCD2, or _BCD3. The sign specification in the upper four bits of In depends on the BCD format number. The data format examples shown below use WORD data for In. Format = _BCD1 Format = _BCD0 Valid range of In: −999 to 999 (BCD)
  • Page 271: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions Precautions for Correct Use • Use the same sizes of data types for In and Out. • An error occurs in the following cases. ENO will be FALSE, and Out will not change. • The value of Format is _BCD0 and the upper digit of In is 2 to F. •...
  • Page 272: Bintobcds

    2 Instruction Descriptions BinToBCDs_** These instructions convert signed integers to signed BCD bit strings. Instruction Name FB/FUN Graphic expression ST expression BinToBCDs_** Signed Integer-to- Out:=BinToBCDs(In, For- (@)BinToBCDs_** BCD Conversion mat); Group "**" must be a bit string data Format type. "**"...
  • Page 273: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions The data type of data format number Format is enumerated type _eBCD_FORMAT. Select one of the following: _BCD0, _BCD1, _BCD2, or _BCD3. The sign specification in the upper four bits of Out depends on the BCD format number. The data format examples shown below use WORD data for Out. Format = _BCD0 Format = _BCD1 Valid range of Out: −999 to 999 (BCD)
  • Page 274: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions Precautions for Correct Use • Always use the correct instruction name for the data type of Out. • An error occurs in the following cases. ENO will be FALSE, and Out will not change. • The value of In is outside of the valid range. •...
  • Page 275: Arytobcd

    2 Instruction Descriptions AryToBCD The AryToBCD instruction converts the elements of an unsigned integer array to BCD bit strings. Instruction Name FB/FUN Graphic expression ST expression AryToBCD Array BCD AryToBCD(In, Size, Ary- (@)AryToBCD Conversion Out); Size AryOut Variables Name Meaning Description Valid range Unit...
  • Page 276: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions Function The AryToBCD instruction converts Size elements of unsigned integer array In[] starting from In[0] to a BCD bit string. It outputs the BCD bit string to BCD array AryOut[]. The following example is for when Size is UINT#3. AryToBCD(abc[1], UINT#3, def[2]);...
  • Page 277: Arytobin

    2 Instruction Descriptions AryToBin The AryToBin instruction converts the elements of an array of BCD bit strings into unsigned integers. Instruction Name FB/FUN Graphic expression ST expression AryToBin Array Unsigned AryToBin(In, Size, Ary- (@)AryToBin Integer Conversion Out); Size AryOut Variables Name Meaning Description...
  • Page 278: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions Function The AryToBin instruction converts Size elements of array of BCD bit strings In[] starting from In[0] to unsigned integers. It outputs the unsigned integers to unsigned integer array AryOut[]. The following example is for when Size is UINT#3. AryToBin(abc[1], UINT#3, def[2]);...
  • Page 279: Data Type Conversion Instructions

    Data Type Conversion Instructions Instruction Name Page Instruction Name Page **_TO_*** (Integer-to-Integer Integer-to-Integer Conver- 2-232 **_TO_STRING (Real Num- Real Number-to-Text String 2-257 Conversion Group) sion Group ber-to-Text String Conver- Conversion Group sion Group) **_TO_*** (Integer-to-Bit Integer-to-Bit String Con- 2-235 RealToFormatString REAL-to-Formatted Text 2-259 String Conversion Group)
  • Page 280: To_*** (Integer-To-Integer Conversion Group)

    2 Instruction Descriptions **_TO_*** (Integer-to-Integer Conversion Group) These instructions convert integers to integers with different data types. Instruction Name FB/FUN Graphic expression ST expression **_TO_*** Integer-to-Integer Out:=**_TO_*** (In); (@)**_TO_*** Conversion Group "**" and "***" must be different integer data types. "**"...
  • Page 281: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions The following table shows the valid ranges for In and Out according to their data types. Data type Data type Valid range for In and Out of In of Out UINT UDINT 0 to 255 ULINT USINT SINT 0 to 127 DINT...
  • Page 282: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions Data type Data type Valid range for In and Out of In of Out USINT 0 to 255 UINT 0 to 65535 UDINT 0 to 4294967295 LINT ULINT 0 to 9223372036854775807 −128 to 127 SINT −32768 to 32767 −2147483648 to 2147483647 DINT Additional Information...
  • Page 283: To_*** (Integer-To-Bit String Conversion Group)

    2 Instruction Descriptions **_TO_*** (Integer-to-Bit String Conversion Group) These instructions convert integers to bit strings. Instruction Name FB/FUN Graphic expression ST expression **_TO_*** Integer-to-Bit String Out:=**_TO_*** (In); (@)**_TO_*** Conversion Group "**" must be an integer data type. "**" must be an integer data type. "***"...
  • Page 284: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions The following table shows the valid ranges for In and Out according to their data types. Data type Data type Valid range for In Valid range for Out of In of Out BYTE WORD USINT 0 to 255 16#00 to 16#FF DWORD LWORD...
  • Page 285: To_*** (Integer-To-Real Number Conversion Group)

    2 Instruction Descriptions **_TO_*** (Integer-to-Real Number Conversion Group) These instructions convert integers to real numbers. Instruction Name FB/FUN Graphic expression ST expression **_TO_*** Integer-to-Real Out:=**_TO_*** (In); (@)**_TO_*** Number Conversion Group "**" must be an integer data type. "***" must be a real number "**"...
  • Page 286: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions REAL data INT data Out=abc 1.234e+3 INT#1234 The following table shows the valid ranges for In and Out according to their data types. Data type Data type Valid range for In Valid range for Out of In of Out REAL USINT...
  • Page 287: To_*** (Bit String-To-Integer Conversion Group)

    2 Instruction Descriptions **_TO_*** (Bit String-to-Integer Conversion Group) These instructions convert bit strings to integers. Instruction Name FB/FUN Graphic expression ST expression **_TO_*** Bit String-to-Inte- Out:=**_TO_*** (In); (@)**_TO_*** ger Conversion Group "**" must be a bit string data type. "***" must be an integer data "**"...
  • Page 288: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions WORD data INT data Out=abc 4660 WORD#16#1234 The following table shows the valid ranges for In and Out according to their data types. Data type Data type Valid range for In Valid range for Out of In of Out USINT UINT...
  • Page 289: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions • If the data size of Out is smaller than the data size of In, the upper digits are truncated in Out. NJ-series Instructions Reference Manual (W502) 2-241...
  • Page 290: To_*** (Bit String-To-Bit String Conversion Group)

    2 Instruction Descriptions **_TO_*** (Bit String-to-Bit String Conversion Group) These instructions convert bit strings to bit strings with different data types. Instruction Name FB/FUN Graphic expression ST expression **_TO_*** Bit String-to-Bit Out:=**_TO_*** (In); (@)**_TO_*** String Conversion Group "**" and "***" must be differ- ent bit string data types.
  • Page 291: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions DWORD data WORD data WORD#16#F123 Out=abc 16#0000F123 The following table shows the valid ranges for In and Out according to their data types. Data type Data type Valid range for In and Out of In of Out WORD BYTE DWORD...
  • Page 292: To_*** (Bit String-To-Real Number Conversion Group)

    2 Instruction Descriptions **_TO_*** (Bit String-to-Real Number Conversion Group) These instructions convert bit strings to real numbers. Instruction Name FB/FUN Graphic expression ST expression **_TO_*** Bit String-to-Real Out:=**_TO_*** (In); (@)**_TO_*** Number Conversion Group "**" must be a bit string data type.
  • Page 293: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions REAL data WORD data Out=abc 3.2768e+4 WORD#16#8000 The following table shows the valid ranges for In and Out according to their data types. Data Data type type of Valid range for In Valid range for Out of Out REAL BYTE 16#00 to 16#FF...
  • Page 294: To_*** (Real Number-To-Integer Conversion Group)

    2 Instruction Descriptions **_TO_*** (Real Number-to-Integer Conversion Group) These instructions convert real numbers to integers. Instruction Name FB/FUN Graphic expression ST expression **_TO_*** Real Number-to- Out:=**_TO_*** (In); (@)**_TO_*** Integer Conversion Group "**" must be a real number data type. "***" must be an integer data "**"...
  • Page 295: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions LINT data LREAL data Out=abc LREAL#1.0e+10 10000000000 The fractional part of the value of In is rounded off to the closest integer. The following table shows how values are rounded. Value of fractional Treatment Examples part 1.49 → 1 Less than The fractional part is truncated.
  • Page 296: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions Additional Information • To convert an integer to a real number, use an Integer-to-Real Number Conversion Group Instruction. • To convert data with any data type to an integer, use an Integer Conversion Group Instruction. • You can use the following instructions to convert a real number to an integer: TRUNC (Truncate), Round (Round Off Real Number), and RoundUp (Round Up Real Number).
  • Page 297: To_*** (Real Number-To-Bit String Conversion Group)

    2 Instruction Descriptions **_TO_*** (Real Number-to-Bit String Conversion Group) These instructions convert real numbers to bit strings. Instruction Name FB/FUN Graphic expression ST expression **_TO_*** Real Number-to- Out:=**_TO_*** (In); (@)**_TO_*** Bit String Conver- sion Group "**" must be a real number data type.
  • Page 298: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions LREAL data DWORD data Out=abc 16#0001_0000 LREAL#6.5536e+4 Conversion is performed using the following procedure. The fractional part of the value of In is rounded off to the closest integer as described below. The resulting integer is taken as an unsigned integer and output as a bit string. The following table shows how values are rounded.
  • Page 299: To_*** (Real Number-To-Real Number Conversion Group)

    2 Instruction Descriptions **_TO_*** (Real Number-to-Real Number Conversion Group) These instructions convert real numbers to real numbers with different data types. Instruction Name FB/FUN Graphic expression ST expression **_TO_*** Real Number-to- Out:=**_TO_*** (In); (@)**_TO_*** Real Number Con- version Group "**" and "***" must be dif- ferent real number data types.
  • Page 300: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions LREAL data REAL data Out=abc REAL#3.141592e+0 3.141592e+0 The following table shows the valid ranges for In and Out according to their data types. Data type of In Data type of Out Valid range for In and Out −3.402823e+38 to 3.402823e+38 REAL LREAL...
  • Page 301: To_String (Integer-To-Text String Conversion Group)

    2 Instruction Descriptions **_TO_STRING (Integer-to-Text String Conversion Group) These instructions convert integers to text strings. Instruction Name FB/FUN Graphic expression ST expression **_TO_STRING Integer-to-Text Out:=**_TO_STRING(In); (@)**_TO_STRING String Conversion Group "**" must be an integer data type. "**" must be an integer data type. Variables Name Meaning...
  • Page 302: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions The following example for the INT_TO_STRING instruction is for when In is INT#1234. abc:=INT_TO_STRING(INT#1234); INT_TO_STRING INT#1234 STRING data INT data Out=abc ‘1234’ INT#1234 The valid range of Out depends on the data type of In as shown below: Data type of In Valid range of Out (maximum number of bytes) USINT...
  • Page 303: To_String (Bit String-To-Text String Conversion Group)

    2 Instruction Descriptions **_TO_STRING (Bit String-to-Text String Conversion Group) These instructions convert bit strings to text strings. Instruction Name FB/FUN Graphic expression ST expression **_TO_STRING Bit String-to-Text Out:=**_TO_STRING(In); (@)**_TO_STRING String Conversion Group "**" must be a bit string data type. "**"...
  • Page 304: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions The following example for the WORD_TO_STRING instruction is for when In is WORD#16#1F. abc:=WORD_TO_STRING(WORD#16#1F); WORD_TO_STRING WORD#16#1F WORD data STRING data ‘001F’ WORD#16#1F Out=abc The valid range of Out depends on the data type of In as shown below: Data type of In Valid range of Out (maximum number of bytes) BYTE...
  • Page 305: To_String (Real Number-To-Text String Conversion Group)

    2 Instruction Descriptions **_TO_STRING (Real Number-to- Text String Conversion Group) These instructions convert real numbers to text strings. Instruction Name FB/FUN Graphic expression ST expression **_TO_STRING Real Number-to- Out:=**_TO_STRING(In); (@)**_TO_STRING Text String Conver- sion Group "**" must be a real number data type.
  • Page 306: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions Item Description Sign column If In contains a negative value, a minus sign (−) is added. If In contains a positive value, a plus sign (+) is not added. Integer part The integer part is always only one digit. Decimal point The decimal point is always given even if In is not a decimal number.
  • Page 307: Realtoformatstring

    2 Instruction Descriptions RealToFormatString The RealToFormatString instruction converts a REAL variable to a text string with the specified format. Instruction Name FB/FUN Graphic expression ST expression RealToFormat- REAL-to-Format- Out:=RealToFormat- (@)RealToFormatString String ted Text String String(In, Exponent, Sign, MinLen, DecPlace); Exponent Sign MinLen DecPlace...
  • Page 308: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions If In contains a negative value, a minus sign (−) is added to the front of the text string. If In contains a positive value, a plus sign (+) is not added to the front of the text string. The format of Out is determined by exponent Exponent, sign column Sign, minimum number of digits MinLen, and precision DecPlace.
  • Page 309: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions Here, no sign column is specified for a negative number, so a minus sign (−) is added to the front of the integer part. abc:=RealToFormatString(REAL#-1234.567, FALSE, FALSE, USINT#16, USINT#10); RealToFormatString REAL#-1234.567 FALSE Exponent FALSE Sign USINT#16 MinLen USINT#10 DecPlace - 1 2 3 4 .
  • Page 310: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions Example 5: Exponent: TRUE Sign: TRUE MinLen: USINT#12 DecPlace: USINT#0 The first decimal place is rounded off because DecPlace is USINT#0. The decimal point is also not given. 1 e + 0 3 Example 6: Exponent: FALSE Sign: TRUE MinLen: USINT#8 DecPlace: USINT#0...
  • Page 311: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions The following table shows how values are rounded. Value of fractional Treatment Examples part 1.49 → 1 Less than The fractional part is truncated. 1.50 → 2 If the ones digit is an even number, the fractional part is truncated.
  • Page 312: Lrealtoformatstring

    2 Instruction Descriptions LrealToFormatString The LrealToFormatString instruction converts a LREAL variable to a text string with the specified for- mat. Instruction Name FB/FUN Graphic expression ST expression LrealToFormat- LREAL-to-Format- Out:=LrealToFormat- (@)LrealToFormatString String ted Text String String(In, Exponent, Sign, MinLen, DecPlace); Exponent Sign MinLen...
  • Page 313: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions Function The LrealToFormatString instruction converts LREAL variable In to a text string. In is expressed as an alphanumeric text string and output to conversion result Out. A NULL character (16#00) is placed at the end of Out. If In contains a negative value, a minus sign (−) is added to the front of the text string.
  • Page 314: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions Here, no sign column is specified for a negative number, so a minus sign (−) is added to the front of the integer part. abc:=LrealToFormatString(LREAL#-1234.56789, FALSE, FALSE, USINT#16, USINT#10); LrealToFormatString LREAL#-1234.56789 FALSE Exponent FALSE Sign USINT#16 MinLen USINT#10 DecPlace - 1 2 3 4 .
  • Page 315: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions Example 5: Exponent: TRUE Sign: TRUE MinLen: USINT#12 DecPlace: USINT#0 The first decimal place is rounded off because DecPlace is USINT#0. The decimal point is also not given. 1 e + 0 3 Example 6: Exponent: FALSE Sign: TRUE MinLen: USINT#8 DecPlace: USINT#0...
  • Page 316: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions 2-268 NJ-series Instructions Reference Manual (W502)
  • Page 317: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions The following table shows how values are rounded. Value of fractional Treatment Examples part 1.49 → 1 Less than The fractional part is truncated. 1.50 → 2 If the ones digit is an even number, the fractional part is truncated.
  • Page 318: String_To_** (Text String-To-Integer Conversion Group)

    2 Instruction Descriptions STRING_TO_** (Text String-to- Integer Conversion Group) These instructions convert text strings to integers. Instruction Name FB/FUN Graphic expression ST expression STRING_TO_** Text String-to-Inte- Out:=STRING_TO_** (In); (@)STRING_TO_** ger Conversion Group "**" must be an integer data type. "**" must be an integer data type. Variables Name Meaning...
  • Page 319: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions The following example for the STRING_TO_DINT instruction is for when In is ‘123456789’. abc:=STRING_TO_DINT(‘123456789’); STRING_TO_DINT ‘123456789’ STRING data DINT data Out=abc 123456789 ‘123456789’ The valid range of In depends on the data type of Out as shown below: Data type of Out Valid range of In (maximum number of bytes)* USINT...
  • Page 320: String_To_** (Text String-To-Bit String Conversion Group)

    2 Instruction Descriptions STRING_TO_** (Text String-to-Bit String Conversion Group) These instructions convert text strings to bit strings. Instruction Name FB/FUN Graphic expression ST expression STRING_TO_** Text String-to-Bit Out:=STRING_TO_** (In); (@)STRING_TO_** String Conversion Group "**" must be a bit string data type.
  • Page 321: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions The following example for the STRING_TO_BYTE instruction is for when In is ‘ AB’. Any blank charac- ters at the beginning are ignored. abc:=STRING_TO_BYTE(’ AB’); STRING_TO_BYTE ‘ AB’ STRING data BTYE data Out=abc 16#AB ‘ AB’ The valid range of In depends on the data type of Out as shown below: Data type of Out Valid range of In (maximum number of bytes)* BYTE...
  • Page 322: String_To_** (Text String-To-Real Number Conversion Group)

    2 Instruction Descriptions STRING_TO_** (Text String-to- Real Number Conversion Group) These instructions convert text strings to real numbers. Instruction Name FB/FUN Graphic expression ST expression STRING_TO_** Text String-to-Real Out:=STRING_TO_** (In); (@)STRING_TO_** Number Conversion Group "**" must be a real number data type.
  • Page 323: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions Name Format Sign • Any consecutive blank characters at the beginning of the text string are ignored. Any follow- ing single plus or minus sign is treated as the sign. • The plus sign can be omitted. •...
  • Page 324: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions Example 3: The following example does not use the sign, but uses the decimal point, fractional part, and exponent. STRING data LREAL data ‘ ’ Out=abc 1 2 3 . 4 5 6 7 e - 0 2 1.234567 Example 4: The following example does not use the sign, fractional part, decimal point, and expo- nent.
  • Page 325: To_** (Integer Conversion Group)

    2 Instruction Descriptions TO_** (Integer Conversion Group) These instructions convert integers, bit strings, real numbers, and text strings to integers. Instruction Name FB/FUN Graphic expression ST expression TO_** Integer Conversion Out:=TO_** (In); (@)TO_** Group "**" must be an integer data type.
  • Page 326: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions • Conversion is performed to within the effective digits of the data type of In. If In is a real number, the fractional part is rounded off to the closest integer. The following table shows how values are rounded.
  • Page 327: To_** (Bit String Conversion Group)

    2 Instruction Descriptions TO_** (Bit String Conversion Group) These instructions convert integers, bit strings, real numbers, and text strings to bit strings. Instruction Name FB/FUN Graphic expression ST expression TO_** Bit String Conver- Out:=TO_**(In); (@)TO_** sion Group "**" must be a bit string data type.
  • Page 328: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions The valid ranges for In and Out depend on their data types. Refer to the descriptions of the functions of the following instructions for the valid ranges: **_TO_*** (Integer-to-Bit String Conversion Group) (page 2-235), **_TO_*** (Bit String-to-Bit String Conversion Group) (page 2-242), and **_TO_*** (Real Num- ber-to-Bit String Conversion Group) (page 2-249).
  • Page 329: To_** (Real Number Conversion Group)

    2 Instruction Descriptions TO_** (Real Number Conversion Group) These instructions convert integers, bit strings, real numbers, and text strings to real numbers. Instruction Name FB/FUN Graphic expression ST expression TO_** Real Number Con- Out:=TO_**(In); (@)TO_** version Group "**" must be a real number data type.
  • Page 330: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions INT data REAL data Out=abc INT#1234 1.234e+3 The valid ranges for In and Out depend on their data types. Refer to the descriptions of the functions of the following instructions for the valid ranges: **_TO_*** (Integer-to-Real Number Conversion Group) (page 2-237), **_TO_*** (Bit String-to-Real Number Conversion Group) (page 2-244), and **_TO_*** (Real Number-to-Real Number Conversion Group) (page 2-251).
  • Page 331: Trunc, Round, And Roundup

    2 Instruction Descriptions TRUNC, Round, and RoundUp These instructions change real numbers to integers. TRUNC: Truncates the number at the first decimal digit. Round: Rounds the number at the first decimal digit. RoundUp: Rounds up the number at the first decimal digit. Instruction Name FB/FUN...
  • Page 332: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions Round The Round instruction rounds the number at the first decimal digit. The following table shows how values are rounded. Value of Treatment Examples fractional part 1.49 → 1 Less than 0.5 The fractional part is truncated. −1.49 →...
  • Page 333: Bit String Processing Instructions

    Bit String Processing Instructions Instruction Name Page AND (&), OR, and XOR Logical AND/Logical OR/ 2-286 Logical Exclusive OR XORN Logical Exclusive NOR 2-289 Bit Reversal 2-291 AryAnd, AryOr, AryXor, and Array Logical AND/ 2-293 AryXorN Array Logical OR/ Array Logical Exclusive OR/ Array Logical Exclusive NOR NJ-series Instructions Reference Manual (W502) 2-285...
  • Page 334: And (&), Or, And Xor

    2 Instruction Descriptions AND (&), OR, and XOR These instructions perform processing on Boolean variables or individual bits in bit stings. AND (&): Logical AND Logical OR XOR: Logical Exclusive OR Instruction Name FB/FUN Graphic expression ST expression AND (&) Logical AND Out:=In1 AND ··AND InN;...
  • Page 335: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions Function These instructions perform processing on Boolean variables or corresponding bits in bit strings. The data to process is in In1 to InN. In1 to InN and Out must be the same data types. If there are more than two data to process, processing is performed with the following procedure. Processing is performed for In1 and In2.
  • Page 336: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions The following example shows the AND instruction when In1 is BYTE#16#3A, In2 is BYTE#16#28 and In3 is BYTE#16#73. abc:=BYTE#16#3A AND BYTE#16#28 AND BYTE#16#73; BYTE#16#3A BYTE#16#28 BYTE#16#73 In1=BYTE#16#3A 0 0 1 1 1 0 1 0 0 0 1 0 1 0 0 0 In2=BYTE#16#28 0 1 1 1 0 0 1 1 In3=BYTE#16#73...
  • Page 337: Xorn

    2 Instruction Descriptions XORN The XORN instruction performs a logical exclusive NOR operation on Boolean variables or individual bits in bit stings. Instruction Name FB/FUN Graphic expression ST expression XORN Logical Exclusive Out:=In1 XOR NOT ·· XOR (@)XORN NOT InN; Variables Name Meaning...
  • Page 338: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions The relationships between input and output variables are given in the following table. If both values are the same, then the processing result is TRUE. Otherwise, the processing result is FALSE. In1 bit In2 bit Out bit FALSE FALSE TRUE...
  • Page 339: Not

    2 Instruction Descriptions The NOT instruction reverses the value of a Boolean variable or the individual bits in a bit string. Instruction Name FB/FUN Graphic expression ST expression Bit Reversal Out:=NOT(In); (@)NOT Variables Name Meaning Description Valid range Unit Default Data to Input Data to process...
  • Page 340: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions Precautions for Correct Use The data types of In and Out must be the same. Otherwise, a building error will occur. 2-292 NJ-series Instructions Reference Manual (W502)
  • Page 341: Aryand, Aryor, Aryxor, And Aryxorn

    2 Instruction Descriptions AryAnd, AryOr, AryXor, and AryXorN These instructions process Boolean variables or individual bits in bit stings between arrays. AryAnd: Logical AND AryOr: Logical OR AryXor: Logical Exclusive OR AryXorN: Logical Exclusive NOR Instruction Name FB/FUN Graphic expression ST expression AryAnd Array Logical AND...
  • Page 342: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions Times, durations, Bit strings Integers dates, and text strings In1[] (array) OK OK OK OK OK In2[] (array) Must be same data type as In1[] Size AryOut[] Must be same data type as In1[] (array) Function These instructions process Size elements from the beginning of arrays to process In1[] and In2[]. Pro- cessing is performed for corresponding bits of corresponding elements.
  • Page 343: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions AryXor If both bits are the same, then the processing result is FALSE. If one bit is TRUE and the other is FALSE, then the processing result is TRUE. Bit of ele- Bit of ele- Bit of Ary- ment in In1[] ment in In2[] Out[]...
  • Page 344: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions 2-296 NJ-series Instructions Reference Manual (W502)
  • Page 345: Selection Instructions

    Selection Instructions Instruction Name Page Binary Selection 2-298 Multiplexer 2-300 LIMIT Limiter 2-302 Band Deadband Control 2-304 Zone Dead Zone Control 2-307 MAX and MIN Maximum/Minimum 2-310 AryMax and AryMin Array Maximum/Array Minimum 2-312 ArySearch Array Search 2-314 NJ-series Instructions Reference Manual (W502) 2-297...
  • Page 346: Sel

    2 Instruction Descriptions The SEL instruction selects one of two selections. Instruction Name FB/FUN Graphic expression ST expression Binary Selection Out:=SEL(G, In0, In1); (@)SEL Variables Name Meaning Description Valid range Unit Default Gate FALSE: Selects In0. FALSE TRUE: Selects In1. Input Depends on data type.
  • Page 347: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions Function The SEL instruction selects one of two selections, In0 and In1. Gate G specifies which of In0 and In1 to select. If G is FALSE, In0 is assigned to Out. If G is TRUE, In1 is assigned to Out. FALSE TRUE Out: = In1...
  • Page 348: Mux

    2 Instruction Descriptions The MUX instruction selects one of three to five selections. Instruction Name FB/FUN Graphic expression ST expression Multiplexer Out:=MUX(K, In0, In1, ···, (@)MUX InN); Variables Name Meaning Description Valid range Unit Default Selector 0: Selects In0. 0 to N 1: Selects In1.
  • Page 349: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions The value of one of the input variables is assigned to Out according to the value of K. In0 is assigned if K is 0, In1 is assigned if K is 1, etc. TRUE K = 0 FALSE TRUE K = 1...
  • Page 350: Limit

    2 Instruction Descriptions LIMIT The LIMIT instruction limits the value of the input variable to the specified minimum and maximum val- ues. Instruction Name FB/FUN Graphic expression ST expression LIMIT Limiter Out:=LIMIT(MN, In, MX); (@)LIMIT Variables Name Meaning Description Valid range Unit Default Minimum...
  • Page 351: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions Function The LIMIT instruction limits the value of data to limit In according to the maximum value, MX, and the minimum value, MN. The value of processing result Out is as shown below. Value of In Value of Out In <...
  • Page 352: Band

    2 Instruction Descriptions Band The Band instruction performs deadband control. Instruction Name FB/FUN Graphic expression ST expression Band Deadband Control Out:=Band(MN, In, MX); (@)Band Variables Name Meaning Description Valid range Unit Default Minimum Minimum value of deadband value Data to Data to control Input Depends on data type.
  • Page 353: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions Function The Band instruction controls the value of data to control In according to the maximum value, MX, and the minimum value, MN. The value of processing result Out is as shown below. Value of In Value of Out In −...
  • Page 354: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions Value of In Value of MN Value of MX Value of Out −∞ +∞ +∞ −∞ Error −∞ +∞ −∞ −∞ • An error occurs in the following cases. ENO will be FALSE, and Out will not change. •...
  • Page 355: Zone

    2 Instruction Descriptions Zone The Zone instruction adds a bias value to the input value. Instruction Name FB/FUN Graphic expression ST expression Zone Dead Zone Control Out:=Zone(BiasN, In, (@)Zone BiasP); BiasN BiasP Variables Name Meaning Description Valid range Unit Default BiasN Negative Negative bias...
  • Page 356: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions Function The Zone instruction controls the value of data to control In according to the positive bias, BiasP, and the negative bias, BiasN. The value of processing result Out is as shown below. Value of Value of In In <...
  • Page 357: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions Value of In Value of BiasP Value of BiasN Value of Out +∞ +∞ −∞ −∞ −∞ +∞ Error −∞ −∞ −∞ • An error occurs in the following cases. ENO will be FALSE, and Out will not change. •...
  • Page 358: Max And Min

    2 Instruction Descriptions MAX and MIN MAX: Finds the largest of two to five values. MIN: Finds the smallest of two to five values. Instruction Name FB/FUN Graphic expression ST expression Maximum Out:=MAX(In1, In2, ···, InN); (@)MAX Minimum Out:=MIN(In1, In2, ···, InN); (@)MIN Variables Name...
  • Page 359: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions Function The MAX instruction finds the largest value of two to five data to process, In1 to InN. The MIN instruction finds the smallest value of two to five data to process, In1 to InN. The following example is for the MAX instruction when In1 is INT#10, In2 is INT#5, In3 is INT#23, In4 is INT#14, and In5 is INT#−5.
  • Page 360: Arymax And Arymin

    2 Instruction Descriptions AryMax and AryMin AryMax: Finds the elements with the largest value in a one-dimensional array. AryMin: Finds the elements with the smallest value in a one-dimensional array. Instruction Name FB/FUN Graphic expression ST expression AryMax Array Maximum Out:=AryMax(In, Size, (@)AryMax InOutPos, Num);...
  • Page 361: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions Function These instructions search Size elements in array to search In[] starting from In[0]. The value that is found is assigned to Out, the element number where it was found is assigned to InOutPos, and the number of times the value was found is assigned to Num. If Num is greater than 1, the value in InOut- Pos is the number of the lowest element that contains the value that was found.
  • Page 362: Arysearch

    2 Instruction Descriptions ArySearch The ArySearch instruction searches for the specified value in a one-dimensional array. Instruction Name FB/FUN Graphic expression ST expression ArySearch Array Search Out:=ArySearch(In, Size, (@)ArySearch Key, InOutPos, Num); Size InOutPos Variables Name Meaning Description Valid range Unit Default In[] (array)
  • Page 363: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions Function The ArySearch instruction searches Size elements of one-dimensional array to search In[] for elements with the same value as search key Key. The search starts from In[0]. The values of search result Out, found element number InOutPos, and number found Num are as fol- lows: Element with same value as...
  • Page 364: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions 2-316 NJ-series Instructions Reference Manual (W502)
  • Page 365: Data Movement Instructions

    Data Movement Instructions Instruction Name Page MOVE Move 2-318 MoveBit Move Bit 2-321 MoveDigit Move Digit 2-323 TransBits Move Bits 2-325 MemCopy Memory Copy 2-327 SetBlock Block Set 2-329 Exchange Data Exchange 2-331 AryExchange Array Data Exchange 2-333 AryMove Array Move 2-335 Clear Initialize...
  • Page 366: Move

    2 Instruction Descriptions MOVE The MOVE instruction moves the value of a constant or variable to another variable. Instruction Name FB/FUN Graphic expression ST expression MOVE Move Out:=In; (@)MOVE Variables Name Meaning Description Valid range Unit Default Move Input Move source Depends on data type.
  • Page 367: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions Additional Information • When moving an array, you can move either one element or all of the elements in the array. To move only one element, add the subscript to the array variable name. To move the entire array, do not add the subscript to the array variable name.
  • Page 368: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions • BYTE, WORD, DWORD, and LWORD • USINT, UINT, UDINT, ULINT, SINT, INT, DINT, LINT, REAL, and LREAL • If In is an enumeration, array element, structure, or structure member, then Out must have the same data type as In. •...
  • Page 369: Movebit

    2 Instruction Descriptions MoveBit The MoveBit instruction moves one bit in a bit string. Instruction Name FB/FUN Graphic expression ST expression MoveBit Move Bit MoveBit(In, InPos, InOut, (@)MoveBit InOutPos); InPos InOut InOutPos Variables Name Meaning Description Valid range Unit Default Move Move source Depends on data type.
  • Page 370: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions Function The MoveBit instruction moves one bit from the bit position InPos in move source In to the bit position InOutPos in move destination InOut. The following example is for when InPos is USINT#3 and InOutPos is USINT#5. MoveBit(abc, USINT#3, def, USINT#5);...
  • Page 371: Movedigit

    2 Instruction Descriptions MoveDigit The MoveDigit instruction moves digits (4 bits per digit) in a bit string. Instruction Name FB/FUN Graphic expression ST expression MoveDigit Move Digit MoveDigit(In, InPos, InOut, (@)MoveDigit InOutPos, Size); InPos InOut InOutPos Size Variables Name Meaning Description Valid range Unit...
  • Page 372: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions Function The MoveDigit instruction moves Size digits from the InPos digit in move source In to the InOutPos digit in move destination InOut. One digit is four bits. The following example is for when InPos is USINT#1, InOutPos is USINT#2, and Size is USINT#2. MoveDigit(abc, USINT#1, def, USINT#2, USINT#2);...
  • Page 373: Transbits

    2 Instruction Descriptions TransBits The TransBits instruction moves one or more bits in a bit string. Instruction Name FB/FUN Graphic expression ST expression TransBits Move Bits TransBits(In, InPos, InOut, (@)TransBits InOutPos, Size); InPos InOut InOutPos Size Variables Name Meaning Description Valid range Unit Default...
  • Page 374: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions Function The TransBis instruction moves Size bits from the InPos bit in move source In to the InOutPos bit in move destination InOut. The following example is for when InPos is USINT#3, InOutPos is USINT#4, and Size is USINT#2. TransBits(abc, USINT#3, def, USINT#4, USINT#2);...
  • Page 375: Memcopy

    2 Instruction Descriptions MemCopy The MemCopy instruction moves one or more array elements. The move source and move destination must have the same data type. Instruction Name FB/FUN Graphic expression ST expression MemCopy Memory Copy MemCopy(In, AryOut, Size); (@)MemCopy AryOut Size Variables Name...
  • Page 376: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions Function The MemCopy instruction moves Size elements of move source array In[] starting from In[0] to move destination array AryOut[] starting from AryOut[0]. The following example is for when Size is UINT#3. MemCopy(abc[1], def[2], UINT#3); MemCopy abc[1] AryOut def[2] def[2]...
  • Page 377: Setblock

    2 Instruction Descriptions SetBlock The SetBlock instruction moves the value of a variable or constant to one or more array elements. Instruction Name FB/FUN Graphic expression ST expression SetBlock Block Set SetBlock(In, AryOut, Size); (@)SetBlock AryOut Size Variables Name Meaning Description Valid range Unit...
  • Page 378: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions The following example is for when Size is UINT#3. SetBlock(abc, def[1], UINT#3); SetBlock AryOut def[1] def[1] UINT#3 Size AryOut[0]=def[1] In=abc 1234 1234 Size=UINT#3 AryOut[1]=def[2] 1234 AryOut[2]=def[3] 1234 Precautions for Correct Use • Use the same data type for In and AryOut[]. If they are different, a building error will occur. •...
  • Page 379: Exchange

    2 Instruction Descriptions Exchange The Exchange instruction exchanges the values of two variables. Instruction Name FB/FUN Graphic expression ST expression Exchange Data Exchange Exchange(InOut1, InOut2); (@)Exchange InOut1 InOut2 Variables Name Meaning Description Valid range Unit Default InOut1 and Data to In-out Data to exchange Depends on data type.
  • Page 380: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions Precautions for Correct Use • The data types of InOut1 and InOut2 must be the same. If they are different, a building error will occur. • Return value Out is not used when the instruction is used in ST. •...
  • Page 381: Aryexchange

    2 Instruction Descriptions AryExchange The AryExchange instruction exchanges the elements of two arrays. Instruction Name FB/FUN Graphic expression ST expression AryExchange Array Data AryExchange(InOut1, (@)AryExchange Exchange InOut2, Size); InOut1 InOut2 Size Variables Name Meaning Description Valid range Unit Default Size Number of Input Number of elements to...
  • Page 382: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions The following example is for when Size is UINT#2. AryExchange(abc[1], def[2], UINT#2); AryExchange InOut1 abc[1] abc[1] InOut2 def[2] def[2] UINT#2 Size InOut1[0]=abc[1] Exchanged InOut2[0]=def[2] Size=UINT#2 InOut1[1]=abc[2] InOut2[1]=def[3] Additional Information • Use the MOVE instruction (page 2-318) to assign constants to variables. •...
  • Page 383: Arymove

    2 Instruction Descriptions AryMove The AryMove instruction moves one or more array elements. The data types of the move source and move destination can be different. Instruction Name FB/FUN Graphic expression ST expression AryMove Array Move AryMove(In, AryOut, Size); (@)AryMove AryOut Size Variables...
  • Page 384: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions The following example is for when Size is UINT#2. AryMove(abc[1], def[2], UINT#2); AryMove abc[1] AryOut def[2] def[2] UINT#2 Size In[0]=abc[1] AryOut[0]=def[2] Moved Size=UINT#2 In[1]=abc[2] AryOut[1]=def[3] Additional Information • If the data types of In[] and AryOut[] are the same, the MemCopy instruction is faster. •...
  • Page 385: Clear

    2 Instruction Descriptions Clear The Clear instruction initializes a variable. Instruction Name FB/FUN Graphic expression ST expression Clear Initialize Clear(InOut); (@)Clear InOut Variables Name Meaning Description Valid range Unit Default InOut Data to In-out Data to initialize Depends on data type. initialize Return Output...
  • Page 386: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions If InOut is an array, array element, structure, or structure member, the following processing is per- formed. InOut Processing Array All elements in the array are initialized. Array element Only the specified element is initialized. Structure All members in the structure are initialized. Structure member Only the specified member is initialized.
  • Page 387: Copy**Tonum (Bit String To Signed Integer)

    2 Instruction Descriptions Copy**ToNum (Bit String to Signed Integer) The Copy**ToNum instruction copies the content of a bit string directly to a signed integer. Instruction Name FB/FUN Graphic expression ST expression Copy**ToNum Bit Pattern Copy Out:=Copy**ToNum(In); (@)Copy**ToNum (Bit String to Signed Integer) Group "**"...
  • Page 388: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions The following example for the CopyWordToNum instruction is for when In is WORD#16#4D2. abc:=CopyWordToNum(WORD#16#4D2); CopyWordToNum WORD#16#4D2 WORD#16#4D2 INT#1234 Out = abc (2#00000100_11010010) (WORD#2#00000100_11010010) 2-340 NJ-series Instructions Reference Manual (W502)
  • Page 389: Copy**To*** (Bit String To Real Number)

    2 Instruction Descriptions Copy**To*** (Bit String to Real Number) The Copy**To*** instruction copies the content of a bit string directly to a real number. Instruction Name FB/FUN Graphic expression ST expression Copy**To*** Bit Pattern Copy Out:=CopyDwordToReal(In); (@)CopyDwordToReal (Bit String to Real Number) Group Out:=CopyLwordToLreal(In);...
  • Page 390: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions Function The Copy**To*** instruction copies the content of copy source In directly to copy destination Out. There are two instructions depending on the data types of In and Out. Instruction DWORD REAL CopyDwordToReal LWORD LREAL CopyLwordToLreal The following example for the CopyDwordToReal instruction is for when In is DWORD#16#40200000. abc:=CopyDwordToReal(DWORD#16#40200000);...
  • Page 391: Copynumto** (Signed Integer To Bit String)

    2 Instruction Descriptions CopyNumTo** (Signed Integer to Bit String) The CopyNumTo** instruction copies the content of a signed integer directly to a bit string. Instruction Name FB/FUN Graphic expression ST expression CopyNumTo** Bit Pattern Copy Out:=CopyNumTo**(In); (@)CopyNumTo** (Signed Integer to Bit String) Group "**"...
  • Page 392: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions The following example for the CopyNumToWord instruction is for when In is INT#1234. abc:=CopyNumToWord(INT#1234); CopyNumToWord INT#1234 INT#1234 WORD#16#4D2 Out = abc (2#00000100_11010010) (2#00000100_11010010) 2-344 NJ-series Instructions Reference Manual (W502)
  • Page 393: Copynumto** (Signed Integer To Real Number)

    2 Instruction Descriptions CopyNumTo** (Signed Integer to Real Number) The CopyNumTo** instruction copies the content of a signed integer directly to a real number. Instruction Name FB/FUN Graphic expression ST expression CopyNumTo** Bit Pattern Copy Out:=CopyNumToReal(In); (@)CopyNumToReal (Signed Integer to Real Number) Out:=CopyNumToLreal(In);...
  • Page 394: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions The following example for the CopyNumToReal instruction is for when In is DINT#1075838976. abc:=CopyNumToReal(DINT#1075838976); CopyNumToReal DINT#1075838976 DINT#1075838976 REAL#2.5 Out = abc (2#01000000_00100000_00000000_00000000) (2#01000000_00100000_00000000_00000000) 2-346 NJ-series Instructions Reference Manual (W502)
  • Page 395: Copy**To*** (Real Number To Bit String)

    2 Instruction Descriptions Copy**To*** (Real Number to Bit String) The Copy**To*** instruction copies the content of a real number directly to a bit string. Instruction Name FB/FUN Graphic expression ST expression Copy**To*** Bit Pattern Copy Out:=CopyRealToDword(In); (@)CopyRealToDword (Real Number to Bit String) Group Out:=CopyLrealToLword(In);...
  • Page 396: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions Function The Copy**To*** instruction copies the content of copy source In directly to copy destination Out. There are two instructions depending on the data types of In and Out. Instruction REAL DWORD CopyRealToDword LREAL LWORD CopyLrealToLword The following example for the CopyRealToDword instruction is for when In is REAL#2.5. abc:=CopyRealToDword(REAL#2.5);...
  • Page 397: Copy**Tonum (Real Number To Signed Integer)

    2 Instruction Descriptions Copy**ToNum (Real Number to Signed Integer) The Copy**ToNum instruction copies the content of a real number directly to a signed integer. Instruction Name FB/FUN Graphic expression ST expression Copy**ToNum Bit Pattern Copy Out:=CopyRealToNum(In); (@)CopyRealToNum (Real Number to Signed Integer) Out:=CopyLrealToNum(In);...
  • Page 398: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions The following example for the CopyRealToNum instruction is for when In is REAL#2.5. abc:=CopyRealToNum(REAL#2.5); CopyRealToNum REAL#2.5 REAL#2.5 DINT#1075838976 Out = abc (2#01000000_00100000_00000000_00000000) (2#01000000_00100000_00000000_00000000) 2-350 NJ-series Instructions Reference Manual (W502)
  • Page 399: Shift Instructions

    Shift Instructions Instruction Name Page AryShiftReg Shift Register 2-352 AryShiftRegLR Reversible Shift Register 2-354 ArySHL and ArySHR Array N-element Left Shift/ 2-357 Array N-element Right Shift SHL and SHR N-bit Left Shift/ 2-360 N-bit Right Shift NSHLC and NSHRC Shift N-bits Left with Carry/ 2-362 Shift N-bits Right with Carry ROL and ROR...
  • Page 400: Aryshiftreg

    2 Instruction Descriptions AryShiftReg The AryShiftReg instruction shifts a shift register one bit to the left and inserts the input value to the least-significant bit. The shift register consists of array elements. Instruction Name FB/FUN Graphic expression ST expression AryShiftReg Shift Register AryShiftReg_instance(Shift, AryShiftReg_instance...
  • Page 401: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions Function The AryShiftReg instruction shifts Size array elements in the array of bit strings InOut[] to the left (i.e., toward most-significant bit) when Shift changes to TRUE. The shift operation starts from InOut[0]. Input value In is inserted to the least-significant bit. The most-significant bit of the array of bit strings is output to the Carry (CY) Flag (P_CY).
  • Page 402: Aryshiftreglr

    2 Instruction Descriptions AryShiftRegLR The AryShiftRegLR instruction shifts a bit string one bit to the left or right and inserts the input value to the least-significant or most-significant bit. The bit string consists of array elements. Instruction Name FB/FUN Graphic expression ST expression AryShiftRegLR Reversible Shift...
  • Page 403: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions Function The AryShiftRegLR instruction shifts Size array elements of array of bit strings InOut[] to the left when ShiftL changes to TRUE. The shift operation starts from InOut[0]. Input value In is inserted to the least- significant bit. The most-significant bit of the array of bit strings is output to the Carry (CY) Flag (P_CY). Size elements P_CY InOut[1]...
  • Page 404: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions Related System-defined Variables Name Meaning Data type Description P_CY Carry (CY) Flag BOOL Value stored in Carry Flag Precautions for Correct Use • While Reset is TRUE, the register is not shifted even if ShiftL or ShiftR changes to TRUE. •...
  • Page 405: Aryshl And Aryshr

    2 Instruction Descriptions ArySHL and ArySHR These instructions shift array elements by one or more elements. ArySHL: Shifts the array to the left (toward the higher elements). ArySHR: Shifts the array to the right (toward the lower elements). Instruction Name FB/FUN Graphic expression ST expression...
  • Page 406: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions Function These instructions shift the upper Size elements in shift register array InOut[] by Num elements. The values that are shifted out of the array are discarded. The default value for the data type of InOut[] is stored in the empty elements. If an initial value attribute is set for InOut[], the specified initial value is used.
  • Page 407: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions Size=UINT#6 InOut[5] InOut[4] InOut[3] InOut[2] InOut[1] InOut[0] =abc[6] =abc[5] =abc[4] =abc[3] =abc[2] =abc[1] Discarded. InOut[5] InOut[4] InOut[3] InOut[2] InOut[1] InOut[0] =abc[6] =abc[5] =abc[4] =abc[3] =abc[2] =abc[1] Zeros inserted. Additional Information If InOut[] is BOOL data, the results will be the same as shifting a bit string of Size bits by Num bits. Precautions for Correct Use •...
  • Page 408: Shl And Shr

    2 Instruction Descriptions SHL and SHR These instructions shift a bit string by one or more bits. SHL: Shifts the bit string to the left (toward the higher bits). SHR: Shifts the bit string to the right (toward the lower bits). Instruction Name FB/FUN...
  • Page 409: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions The following example if for when In is BYTE#16#89 and Num is USINT#2. abc:=SHL(BYTE#16#89, USINT#2); BYTE#16#89 USINT#2 Bit 7 Bit 0 1 0 0 0 1 0 0 1 Out=abc 0 0 1 0 0 1 0 0 Shifted 2 bits left.
  • Page 410: Nshlc And Nshrc

    2 Instruction Descriptions NSHLC and NSHRC These instructions shift an array of bit strings by one or more bits. The Carry (CY) Flag is included. NSHLC: Shifts the array to the left (toward the higher elements). NSHRC: Shifts the array to the right (toward the lower elements). Instruction Name FB/FUN...
  • Page 411: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions Function These instructions shift Size array elements in shift register array InOut[] by the number of bits specified in Num. The shift register starts at InOut[0]. The last bit that is shifted out of the register is output to the Carry (CY) Flag.
  • Page 412: Rol And Ror

    2 Instruction Descriptions ROL and ROR These instructions rotate a bit string by one or more bits. ROL: Rotates the bit string to the left (toward the higher bits). ROR: Rotates the bit string to the right (toward the lower bits). Instruction Name FB/FUN...
  • Page 413: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions The following example is for when In is BYTE#16#89 and Num is USINT#2. abc:=ROL(BYTE#16#89, USINT#2); BYTE#16#89 USINT#2 Bit 7 Bit 0 1 0 0 0 1 0 0 1 0 0 1 0 0 1 1 0 Out=abc Shifted 2 bits left.
  • Page 414: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions 2-366 NJ-series Instructions Reference Manual (W502)
  • Page 415: Conversion Instructions

    Conversion Instructions Instruction Name Page Instruction Name Page Swap Swap Bytes 2-368 FixNumToString Fixed-decimal Number-to-Text String Conver- 2-428 sion Reverse Sign 2-369 StringToFixNum Text String-to-Fixed-decimal Conversion 2-430 Decoder Bit Decoder 2-371 DtToString Date and Time-to-Text String Conversion 2-433 Encoder Bit Encoder 2-374 DateToString Date-to-Text String Conversion...
  • Page 416: Swap

    2 Instruction Descriptions Swap The Swap instruction swaps the upper byte and lower byte of a 16-bit value. Instruction Name FB/FUN Graphic expression ST expression Swap Swap Bytes Out:=Swap(In); (@)Swap Variables Name Meaning Description Valid range Unit Default Data to Input Data to convert Depends on data type.
  • Page 417: Neg

    2 Instruction Descriptions The Neg instruction reverses the sign of a number. Instruction Name FB/FUN Graphic expression ST expression Reverse Sign Out:=Neg(In); (@)Neg Variables Name Meaning Description Valid range Unit Default Data to Input Data to convert Depends on data type. convert Conver- Output...
  • Page 418: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions The following example is for when In is INT#123. abc:=Neg(INT#123); INT#123 Bits reversed and 1 added. −123(2#1111_1111_1000_0101) 123(2#0000_0000_0111_1011) Out = abc The following example is for when In is UINT#123. Bits reversed and 1 added. 123(2#0000_0000_0111_1011) Out = abc 65413(2#1111_1111_1000_0101) Precautions for Correct Use If you use a different data type for In and Out, make sure the valid range of Out includes the valid range...
  • Page 419: Decoder

    2 Instruction Descriptions Decoder The Decoder instruction sets the specified bit to TRUE and the other bits to FALSE in array elements that consist of a maximum of 256 bits. Instruction Name FB/FUN Graphic expression ST expression Decoder Bit Decoder Decoder(In, Size, InOut);...
  • Page 420: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions InOut[] is a BYTE array, so the ninth bit from the least-significant bit is bit 1 in InOut[1]. Therefore, bit 1 in InOut[1] is made TRUE, all other bits in InOut[1] are made FALSE, and all bits in InOut[0] are made FALSE.
  • Page 421: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions • The value of Size is outside of the valid range. • The value of Size exceeds the array area of InOut[]. • InOut[] is not a BOOL array or an array of bit strings. • An array without a subscript is passed to InOut[]. NJ-series Instructions Reference Manual (W502) 2-373...
  • Page 422: Encoder

    2 Instruction Descriptions Encoder The Encoder instruction finds the position of the highest TRUE bit in array elements that consist of a maximum of 256 bits. Instruction Name FB/FUN Graphic expression ST expression Encoder Bit Encoder Out:=Encoder(In, Size); (@)Encoder Size Variables Name Meaning...
  • Page 423: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions Size is USINT#4, so 2#1001 (i.e., 9) is stored in the lower 4 bits of Out. FALSE is stored in the upper four bits of Out. def:=Encoder(abc[3], USINT#4); Encoder abc[3] USINT#4 Size In[0]=abc[3] 0 0 0 0 0 0 0 0 Size = 16 bits In[1]=abc[4]...
  • Page 424: Bitcnt

    2 Instruction Descriptions BitCnt The BitCnt instruction counts the number of TRUE bits in a bit string. Instruction Name FB/FUN Graphic expression ST expression BitCnt Bit Counter Out:=BitCnt(In); (@)BitCnt Variables Name Meaning Description Valid range Unit Default Count Input String in which to count Depends on data type.
  • Page 425: Colmtoline

    2 Instruction Descriptions ColmToLine_** The ColmToLine_** instruction extracts bit values from the specified position of array elements and out- puts them as a bit string. Instruction Name FB/FUN Graphic expression ST expression ColmToLine_** Column to Line Out:=ColmToLine_**(In, (@)ColmToLine_** Conversion Group Size, Pos);...
  • Page 426: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions The following example shows the ColmToLine_BYTE instruction when Pos is USINT#3 and Size is USINT#4. def:=ColmToLine_BYTE(abc[3], USINT#4, USINT#3); ColmToLine_BYTE abc[3] Size USINT#4 USINT#3 Pos= Most-significant bit Bit 0 USINT#3 0 0 0 0 0 0 0 0 0 0 0 0 In[0]=abc[3] 0 0 0 0 0 0 In[1]=abc[4]...
  • Page 427: Linetocolm

    2 Instruction Descriptions LineToColm The LineToColm instruction takes the bits from a bit string and outputs them to the specified bit position in array elements. Instruction Name FB/FUN Graphic expression ST expression LineToColm Line to Column LineToColm(In, InOut, Size, (@)LineToColm Conversion Pos);...
  • Page 428: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions First, Size bits are extracted from the least-significant bit of data to convert In. These bits are treated individually. Then, the bits are stored in conversion result array InOut[] in the Pos bit of the elements starting from InOut[0]. Size specifies the number of array elements to receive bits. The values of all bits for which values are not stored are retained.
  • Page 429: Gray

    2 Instruction Descriptions Gray The Gray instruction converts a gray code into an angle. Instruction Name FB/FUN Graphic expression ST expression Gray Gray Code Conver- Out:=Gray(In, Resolution, (@)Gray sion ERC, ZPC); Resolution Variables Name Meaning Description Valid range Unit Default Data to Gray code to convert Depends on data type.
  • Page 430: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions The data type of Resolution is enumerated type _eGRY_RESOLUTION. The meaning of the enumera- tors are as follows: Enumerator Meaning _R256 _R1B 1-bit (2) _R2B 2-bit (4) _R3B 3-bit (8) _R4B 4-bit (16) _R5B 5-bit (32) _R6B 6-bit (64) _R7B 7-bit (128)
  • Page 431: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions Additional Information Refer to the user documentation for your rotary encoder for the values to specify for Resolution and ERC. Precautions for Correct Use An error occurs in the following cases. ENO will be FALSE, and Out will not change. •...
  • Page 432: Pwlapprox

    2 Instruction Descriptions PWLApprox The PWLApprox instruction performs broken line approximations for integer or real number data. Instruction Name FB/FUN Graphic expression ST expression PWLApprox Broken Line Out:=PWLApprox(In, Line, (@)PWLApprox Approximation Num); Line Variables Name Meaning Description Valid range Unit Default Data to Data to convert...
  • Page 433: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions Line[] must be a two-dimensional or three-dimensional array. Set the number of elements for the first dimension to 2. Set the number of elements for the second dimension to 2. Set the array elements from Line[0,0] to X , etc., as shown in the following figure.
  • Page 434: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions • If the value of In is larger than the value of Line[Num−1,0] (i.e., the value of X ), then the value of − Out will be the value of Line[Num 1,1] (i.e., the value of Y •...
  • Page 435: Movingaverage

    2 Instruction Descriptions MovingAverage The MovingAverage instruction calculates a moving average. Instruction Name FB/FUN Graphic expression ST expression MovingAverage Moving Average Out:=MovingAverage(In, (@)MovingAverage CurIndex, Buf, BufSize, Q); CurIndex BufSize Variables Name Meaning Description Valid range Unit Default Input value Number to include in aver- Input Depends on data type.
  • Page 436 2 Instruction Descriptions Function The MovingAverage instruction stores the value of input value In in input value storage array Buf[] each time it is executed. It stores the average of the stored values in calculation result Out. Specify the maxi- mum number of elements to include in the average with BufSize.
  • Page 437 2 Instruction Descriptions Inputting Numbers Up to BufSize Each time the instruction is executed, the value of In is stored in Buf[CurIndex]. The average of CurIn- dex + 1 numbers that start from Buf[0] is calculated and stored in Out. When the number of instruction executions reaches BufSize, the value of Q changes to TRUE.
  • Page 438 2 Instruction Descriptions Initializing the Stored Values − If the value of CurIndex is set to 0 before the instruction is executed, the values in Buf[0] to Buf[BufSize 1] are set to 0 and the current value of In is stored again in Buf[0]. The value of CurIndex changes to 1 and the value of Q changes to FALSE.
  • Page 439 2 Instruction Descriptions Sample Programming This sample shows how to eliminate the effect of noise and other disturbances in analog input data, e.g., from a sensor. It assigns the average (DataAve) of the last 25 values of the input data (InputData) to the input data (InputDataForOperating) for the next process.
  • Page 440 2 Instruction Descriptions Data type Comment Variable Initial value False Execution condition Trigger BOOL False Value of Trigger from previous task period LastTrigger BOOL Operating False Processing BOOL False Processing started OperatingStart BOOL [25(0)] Input value storage array Buffer ARRAY[0..24] OF INT InputData Input value Average value...
  • Page 441: Pidat

    2 Instruction Descriptions PIDAT The PIDAT instruction performs PID control with autotuning (2-PID control with set point filter). Instruction Name FB/FUN Graphic expression ST expression PIDAT PID Control with PIDAT_instance( PIDAT_instance Autotuning Run, PIDAT ManCtl, ATDone StartAT, ManCtl ATBusy StartAT Error ErrorID OprSetParams,...
  • Page 442: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions Name Meaning Description Valid range Unit Default ATDone Autotuning nor- TRUE: Normal completion mal completion FALSE: Depends on data type. ATBusy Autotuning TRUE: Autotuning Output busy FALSE: Not autotuning −320 to 320 Manipulated Manipulated variable variable *1 Value of input range lower limit InitSetParams.RngLowLmt to Value of input range upper limit InitSetParams.RngUpLmt *2 Digits below 0.0001 s are truncated.
  • Page 443: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions Structure Specifications The data type of operation setting parameter OprSetParams is structure _sOPR_SET_PARAMS. The specifications are as follows: Name Meaning Description Data type Valid range Unit Default OprSetParams Operation Set- Parameters that are set _sOPR_SET_ ting Parame- during operation.
  • Page 444: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions Meanings of Variables The meanings of the variables that are used in this command are described below. Run (Execution Condition) This is the execution condition for the instruction. PID control is performed while the value is TRUE. PID control is stopped when the value changes to FALSE.
  • Page 445: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions MVTrackVal Time MVTrackSw = TRUE MVTrackSw = FALSE MVTrackVal (MV Tracking Value) This is the value to which MV is set during MV tracking. The value of MVTrackVal does not have to be between MVLowLmt and MVUpLmt. StopMV (Stop MV) This is the value to which MV is set when the value of Run is FALSE (i.e., when execution of this instruction is stopped).
  • Page 446: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions DirOpr (Action Direction) This variable specifies if MV is increased or decreased for changes in the value of PV. These are called a forward action and a reverse action. Value of DirOpr Meaning Value of MV TRUE Forward action Increases with the value of PV.
  • Page 447: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions Value of MV from automatic operation used. Value of MV from manual operation used. Time ManCtl changed to FALSE. ManCtl changed to TRUE. Value of ManMV changed. ATDone (Autotuning Normal Completion) This flag indicates when autotuning was completed normally. It changes to TRUE when autotuning is completed normally and remains TRUE as long as the value of StartAT is TRUE.
  • Page 448: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions Proportional Action (P) The proportional action increases the absolute value of the manipulated variable in proportion to the deviation between the process value and the set point. The process value of the controlled system changes as shown below. Process value A small deviation produces a small MV, which produces a small change in the process value.
  • Page 449: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions If the manual reset value is not suitable, the deviation will never reach 0. The remaining deviation is called the offset or the residual deviation. You can make the proportional band narrower to reduce the offset. If the proportional band is too narrow, the process value will not stop at the set point. This is called overshooting.
  • Page 450: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions Derivative Action (D) If the proportional and integral actions are used together, the offset will reach 0 and the process value will reach the set point. However, if disturbance causes the process value to change quickly, time is required to restore the original state. The derivative action functions to quickly return the pro- cess value to the set point when there is a disturbance.
  • Page 451: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions Deviation Deviation Stepwise response Ramp response Time Time PID control Manipulated Manipulated variable variable PID control Integral action only Integral action only Derivative action only Proportional action only Time Time Proportional action only Derivative action only 2-PID Control with Set Point Filter There are three main parameters that you must adjust to perform PID control: the proportional band, integration time, and derivative time.
  • Page 452: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions Disturbance Proportional + Set point filter integral components Manipulated 1 + (1−α)Ti ⋅ s Deviation Process value variable Controlled Kp + 1 + Ti ⋅ s system − Ti ⋅ s − point Kp: Proportional constant Ti: Integration time Advanced derivative component Td: Derivative time...
  • Page 453: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions Autotuning The 2-PID parameter α is not adjusted very often, so the main parameters that are adjusted for this instruction are the PID constants. The PIDAT instruction supports autotuning of the PID constants. The limit cycle method is used for autotuning. With the limit cycle method, the manipulated variable is tem- porarily changed to the upper and lower limits of the manipulated variable to find the optimum PID con- stants based on the resulting changes in the process value.
  • Page 454: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions Task period = 60 ms and SampTime < 60 ms The task period is greater than or equal to SampTime, so PID processing is executed once every task period. Task period Task period Task period Task period Task period PIDAT PIDAT...
  • Page 455: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions Autotuning Executed during Automatic Operation TRUE FALSE TRUE StartAT FALSE TRUE ATBusy FALSE TRUE ATDone FALSE Time StopMV Time PID processing processing Autotuning PID constants updated for MV set to StopMV. results of autotuning. NJ-series Instructions Reference Manual (W502) 2-407...
  • Page 456: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions Autotuning Executed at the Start of PIDAT Execution TRUE FALSE TRUE StartAT FALSE TRUE ATBusy FALSE TRUE ATDone FALSE Time StopMV Time Autotuning processing MV set to StopMV. PID constants updated for results of autotuning. 2-408 NJ-series Instructions Reference Manual (W502)
  • Page 457: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions Autotuning Canceled TRUE FALSE TRUE StartAT FALSE TRUE ATBusy ATBusy also changes to FALSE FALSE when autotuning is canceled. TRUE ATDone ATDone remains FALSE. FALSE Time StopMV Time processing processing Autotuning Autotuning canceled. MV set to StopMV. The PID constants from before autotuning was started are set.
  • Page 458: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions An Autotuning Error Occurs during Autotuning An autotuning error occurs and autotuning is stopped in the following cases. • If the MV equals the MV upper limit and the time for the deviation to reach 0 exceeds 19,999 s. •...
  • Page 459: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions • If hunting continues too long, increase ProportionalBand or increase IntegrationTime. Increase ProportionalBand or increase IntegrationTime. Time • If rapid hunting occurs, decrease DerivativeTime. Decrease DerivativeTime. Time Initial PID Constants for Temperature Control If you use the PIDAT instruction for temperature control, use the following initial values of the PID con- stants as reference.
  • Page 460: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions Control status Automatic operation Automatic operation Variables Instruction execution when autotuning is not when autotuning is being stopped being executed executed MVTrackVal Possible Possible Not possible StopMV Possible Possible Possible ErrorMV Possible Possible Possible Alpha Possible Possible Not possible ATCalcGain Possible...
  • Page 461: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions Specifications Temperature control is performed according to the following specifications. Item Specification Input type K thermocouple Input Unit CJ1W-PH41U Analog Input Unit with Universal Inputs Output Unit CJ1W-OD212 Transistor Output Unit Set point 90°C Sampling period for PID control 100 ms Output control period Configuration and Settings...
  • Page 462: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions 1-s period 200 ms 800 ms Output control value PID processing 100-ms period Time MV at this point: 20% MV at this point: 30% The output control values are immediately changed to turn the output ON for 300 ms and OFF for 700 ms.
  • Page 463: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions Application Programming Data type Retain Comment Initial value Variable Execution condition Run1 BOOL False Manual/auto control ManCtl1 BOOL False StartAT1 BOOL Autotuning execution condition False Process value REAL Set point REAL OprSetParams1 _sOPR_SET_PARAMS Operation setting parameters (MVLowLmt:=0.0, MVUpLmt:=100.0, ManResetVal:=0.0, MVTrackSw:=False, MVTrackVal:=0.0, StopMV:=0.0, ErrorMV=0.0, Alpha:=0.65,...
  • Page 464: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions Time-proportional output Inline ST // Calculate ON time output control value. 1 PulseOnTime:=MULTIME(PulseCycTime, MV1/REAL#100.0); // Switch between ON and OFF with TOF instruction. 2 TOF_instance(In:=BOOL#FALSE, PT:=PulseOnTime, Q=>DO1); // Measure timer reset time with TON instruction. 3 TON_instance(In:=BOOL#TRUE, PT:=PulseCycTime, Q=>ResetPulse); // Reset timer.
  • Page 465: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions Data type Initial value Retain Comment Variable Execution condition Run1 BOOL False Manual/auto control ManCtl1 BOOL False StartAT1 Autotuning execution condition BOOL False Process value REAL Set point REAL OprSetParams1 Operation setting parameters _sOPR_SET_PARAMS (MVLowLmt:=0.0, MVUpLmt:=100.0, ManResetVal:=0.0, MVTrackSw:=False, MVTrackVal:=0.0, StopMV:=0.0, ErrorMV=0.0, Alpha:=0.65, ATCalcGain:=1.0, ATHystrs:=0.2)
  • Page 466: Dispartreal

    2 Instruction Descriptions DispartReal The DispartReal instruction separates a real number into the signed mantissa and the exponent. Instruction Name FB/FUN Graphic expression ST expression DispartReal Separate Mantissa Out:=DispartReal(In, Frac- (@)DispartReal and Exponent tion, Exponent); Fraction Exponent Variables Name Meaning Description Valid range Unit...
  • Page 467: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions The following example is for when In is REAL data with a value of REAL#−123.456. DispartReal(REAL#−123.456, abc, def); DispartReal REAL#−123.456 Fraction Exponent Signed mantissa −1234560 Fraction = abc REAL#−123.456 Exponent −4 Exponent = def The following example is for when In is LREAL data with a value of LREAL#−123.456789. DispartReal(LREAL#−123.456789, abc, def);...
  • Page 468: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions • If the number of valid digits in In exceeds the number of valid digits of Fraction, the value is rounded to fit in the valid range of Fraction. The following table shows how values are rounded. Value of fractional part Treatment Examples...
  • Page 469: Unitereal

    2 Instruction Descriptions UniteReal The UniteReal instruction combines a signed mantissa and exponent to make a real number. Instruction Name FB/FUN Graphic expression ST expression UniteReal Combine Real Out:=UniteReal(Fraction, (@)UniteReal Number Mantissa Exponent); and Exponent Fraction Exponent Variables Name Meaning Description Valid range Unit...
  • Page 470: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions Additional Information Use the DispartReal instruction (page 2-418) to separate a real number into the signed mantissa and exponent. Precautions for Correct Use • Depending on the values of Fraction and Exponent, error may occur in the conversion from an integer to a real number.
  • Page 471: Numtodecstring And Numtohexstring

    2 Instruction Descriptions NumToDecString and NumToHexString NumToDecString: Converts an integer to a fixed-length decimal text string. NumToHexString: Converts an integer to a fixed-length hexadecimal text string. Instruction Name FB/FUN Graphic expression ST expression NumToDecString Fixed-length Out:=NumToDecString(In, (@)NumToDecString Decimal Text String L, Fill);...
  • Page 472: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions NumToHexString The NumToHexString instruction converts integer In to a hexadecimal text string of UTF-8 alphanu- meric characters. If In is negative, it is expressed in its two’s complement (bits inverted and then 1 added). For either instruction, the number of characters in text string Out is adjusted to number of characters L. If there are not enough characters, the upper digits are filled with fill character Fill.
  • Page 473: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions Precautions for Correct Use • The value of Out does not change if the value of L is 0. • If the number of characters in the conversion result exceeds the value of L, L characters from the lower characters of the conversion result are stored in Out.
  • Page 474: Hexstringtonum

    2 Instruction Descriptions HexStringToNum_** The HexStringToNum_** instruction converts a hexadecimal text string to an integer. Instruction Name FB/FUN Graphic expression ST expression HexStringTo Hexadecimal Text Out:=HexStringToNum_**(In); (@)HexStringToNum_** Num_** String-to-Number "**" must be an integer data Conversion Group type. "**" must be an integer data type. Variables Name Meaning...
  • Page 475: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions Precautions for Correct Use • Even if the conversion result exceeds the valid range of Out, an error will not occur. The value of Out will be an illegal value. • An error occurs in the following cases. ENO will be FALSE, and Out will not change. •...
  • Page 476: Fixnumtostring

    2 Instruction Descriptions FixNumToString The FixNumToString instruction converts a signed fixed-decimal number to a decimal text string. Instruction Name FB/FUN Graphic expression ST expression FixNumToString Fixed-decimal Out:=FixNumToString(In, (@)FixNumToString Number-to-Text Zero); String Conversion Zero Variables Name Meaning Description Valid range Unit Default Fixed- Signed fixed-decimal...
  • Page 477: Nj-Series Instructions Reference Manual (W502

    Additional Information The format for fixed-point decimal numbers is the same as the fixed-decimal output format of the OMRON FZ-series Vision Sensors. Precautions for Correct Use An error occurs in the following case. ENO will be FALSE, and Out will not change.
  • Page 478: Stringtofixnum

    2 Instruction Descriptions StringToFixNum The StringToFixNum instruction converts a decimal text string to a signed fixed-decimal number. Instruction Name FB/FUN Graphic expression ST expression StringToFixNum Text String-to- Out:=StringToFixNum(In); (@)StringToFixNum Fixed-decimal Conversion Variables Name Meaning Description Valid range Unit Default Decimal text Input Decimal text string Depends on data type.
  • Page 479: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions In = abc Out = def ‘83.5’ 16#0001462C (10#83500) ‘334.5’ 16#00051AA4 (10#334500) ‘245.5’ 16#0003BEFC (10#245500) The format of the text sting in In is given below. i i i i . f f f f f f f f e + n n Integer Sign Fractional part...
  • Page 480: Nj-Series Instructions Reference Manual (W502

    00003E8 Additional Information The format for fixed-point decimal numbers is the same as the fixed-decimal output format of the OMRON FZ-series Vision Sensors. Precautions for Correct Use • The digits after the third decimal digit are truncated in In. • Underbars (16#5F) in the text string in In are ignored.
  • Page 481: Dttostring

    2 Instruction Descriptions DtToString The DtToString instruction converts a date and time to a text string. Instruction Name FB/FUN Graphic expression ST expression DtToString Date and Out:=DtToString(In); (@)DtToString Time-to-Text String Conversion Variables Name Meaning Description Valid range Unit Default Date and Input Date and time Depends on data type.
  • Page 482: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions Additional Information Out is in nanoseconds. To get a text string in seconds or milliseconds, combine this instruction with the LEFT or RIGHT instruction (page 2-522). An example to get a text string in seconds is given below. ●...
  • Page 483: Datetostring

    2 Instruction Descriptions DateToString The DateToString instruction converts a date to a text string. Instruction Name FB/FUN Graphic expression ST expression DateToString Date-to-Text String Out:=DateToString(In); (@)DateToString Conversion Variables Name Meaning Description Valid range Unit Default Date Input Date Depends on data type. Year, month, D#1970-1-1 Text string...
  • Page 484: Todtostring

    2 Instruction Descriptions TodToString The TodToString instruction converts a time of day to a text string. Instruction Name FB/FUN Graphic expression ST expression TodToString Time of Day-to-Text Out:=TodToString(In); (@)TodToString String Conversion Variables Name Meaning Description Valid range Unit Default Time of day Input Time of day Depends on data type.
  • Page 485: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions An example to get a text string in seconds is given below. ● LD TodToString TOD#01:23:45.678 LEFT UINT#8 ● ST def:=LEFT(TodToString(TOD#01:23:45.678), UINT#8); Precautions for Correct Use An error occurs in the following case. ENO will be FALSE, and Out will not change. •...
  • Page 486: Graytobin_** And Bintogray

    2 Instruction Descriptions GrayToBin_** and BinToGray_** GrayToBin_**: Converts a gray code to a bit string. BinToGray_**: Converts a bit string to a gray code. Instruction Name FB/FUN Graphic expression ST expression GrayToBin_** Gray Code-to- Out:=GrayToBin_**(In); (@)GrayToBin_** Binary Code Conversion Group "**"...
  • Page 487: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions The following example for the GrayToBin_BYTE instruction is for when In is BYTE#16#A5. abc:=GrayToBin_BYTE(BYTE#16#A5); GrayToBin_BYTE BYTE#16#A5 Most-significant Bit 0 XOR XOR XOR XOR XOR XOR Out = abc BinToGray_** The BinToGray_** instructions convert the bit string in data to convert In to a gray code. The conversion procedure is as follows for when In and Out are BYTE data.
  • Page 488: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions Precautions for Correct Use The data types of In and Out must be the same. 2-440 NJ-series Instructions Reference Manual (W502)
  • Page 489: Stringtoary

    2 Instruction Descriptions StringToAry The StringToAry instruction converts a text string to a BYTE array. Instruction Name FB/FUN Graphic expression ST expression StringToAry Text String-to-Array Out:=StringToAry(In, Ary- (@)StringToAry Conversion Out); AryOut Variables Name Meaning Description Valid range Unit Default Text string Input Text string Depends on data type.
  • Page 490: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions The following example is for when In is ‘XYZ’. def:=StringToAry(’XYZ’, abc[1]); StringToAry ‘XYZ’ AryOut abc[1] abc[1] Character code for ‘X’ AryOut[0]=abc[1] 16#58 Character code for ‘Y’ 16#59 ‘XYZ’ AryOut[1]=abc[2] Character code for ‘Z’ 16#5A AryOut[2]=abc[3] Out=def UINT#3 Precautions for Correct Use •...
  • Page 491: Arytostring

    2 Instruction Descriptions AryToString The AryToString instruction converts a BYTE array to a text string. Instruction Name FB/FUN Graphic expression ST expression AryToString Array-to-Text String Out:=AryToString(In, Size); (@)AryToString Conversion Size Variables Name Meaning Description Valid range Unit Default In[] (array) BYTE array BYTE array Depends on data type.
  • Page 492: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions The following example is for when Size is UINT#3. def:=AryToString(abc[1], UINT#3); AryToString abc[1] UINT#3 Size Character code for ‘V’ In[0]=abc[1] 16#56 Character code for ‘W’ 16#57 Out = def ‘VWX’ In[1]=abc[2] Size = UINT#3 Character code for ‘X’ 16#58 In[2]=abc[3] Character code for ‘Y’...
  • Page 493: Dispartdigit

    2 Instruction Descriptions DispartDigit The DispartDigit instruction separates a bit string into 4-bit units. Instruction Name FB/FUN Graphic expression ST expression DispartDigit Four-bit Separation DispartDigit(In, Num, Ary- (@)DispartDigit Out); AryOut Variables Name Meaning Description Valid range Unit Default Data to separate Bit string to separate Depends on data type.
  • Page 494: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions The following example is for when Num is USINT#3. DispartDigit(abc, USINT#3, def[1]); DispartDigit USINT#3 AryOut def[1] def[1] Num=USINT#3 Highest digit Digit 2 Digit 1 Digit 0 In=abc Bits Bits 0 to 3 4 to 7 AryOut[0]=def[1] AryOut[1]=def[2] Num=USINT#3 AryOut[2]=def[3] 16#0...
  • Page 495: Unitedigit

    2 Instruction Descriptions UniteDigit_** The UniteDigit_** instructions join 4-bit units of data into a bit string. Instruction Name FB/FUN Graphic expression ST expression UniteDigit_** Four-bit Join Group Out:=UniteDigit_**(In, (@)UniteDigit_** Num); "**" must be a bit string data type. "**" must be a bit string data type. Variables Name Meaning...
  • Page 496: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions The following example shows the UniteDigit_WORD instruction when Num is USINT#3. def:=UniteDigit_WORD(abc[1], USINT#3); UniteDigit_WORD abc[1] USINT#3 Bits Bits 4 to 7 0 to 3 In[0]=abc[1] In[1]=abc[2] Num=USINT#3 In[2]=abc[3] In[3]=abc[4] Highest digit Digit 2 Digit 1 Digit 0 Out=def Num=USINT#3 16#0...
  • Page 497: Dispart8Bit

    2 Instruction Descriptions Dispart8Bit The Dispart8Bit instruction separates a bit string into individual bytes. Instruction Name FB/FUN Graphic expression ST expression Dispart8Bit Byte Data Dispart8Bit(In, Num, Ary- (@)Dispart8Bit Separation Out); AryOut Variables Name Meaning Description Valid range Unit Default Data to separate Bit string to separate Depends on data type.
  • Page 498: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions The following example is for when Num is USINT#3. Dispart8Bit(abc, USINT#3, def[1]); Dispart8Bit USINT#3 AryOut def[1] def[1] Num=USINT#3 Highest byte Byte 2 Byte 1 Byte 0 In=abc AryOut[0]=def[1] AryOut[1]=def[2] Num=USINT#3 AryOut[2]=def[3] Additional Information Use the Unite8Bit_** instruction (page 2-451) to join 1-byte units from array elements. Precautions for Correct Use •...
  • Page 499: Unite8Bit

    2 Instruction Descriptions Unite8Bit_** The Unite8Bit_** instructions join bytes of data into a bit string. Instruction Name FB/FUN Graphic expression ST expression Unite8Bit_** Byte Data Join Out:=Unite8Bit_**(In, Num); (@)Unite8Bit_** Group "**" must be a bit string data type. "**" must be a bit string data type. Variables Name Meaning...
  • Page 500: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions The following example shows the Unite8Bit_DWORD instruction when Num is USINT#3. def:=Unite8Bit_DWORD(abc[1], USINT#3); Unite8Bit_DWORD abc[1] USINT#3 In[0]=abc[1] In[1]=abc[2] Num=USINT#3 In[2]=abc[3] In[3]=abc[4] Highest Byte 2 Byte 1 Byte 0 byte Out=def Num=USINT#3 16#00 Additional Information Use the Dispart8Bit instruction (page 2-449) to separate a bit string into 1-byte units. Precautions for Correct Use •...
  • Page 501: Toarybyte

    2 Instruction Descriptions ToAryByte The ToAryByte instruction separates a variable into bytes and stores the bytes in a BYTE array. Instruction Name FB/FUN Graphic expression ST expression ToAryByte Conversion to Byte Out:=ToAryByte(In, Order, (@)ToAryByte Array AryOut); Order AryOut Variables Name Meaning Description Valid range...
  • Page 502: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions When the Data Type of In Is Two Bytes or Larger If the data type of In is two bytes or larger, In is separated into bytes and stored in AryOut[]. The follow- ing data types have two bytes or more. Classification Data type Bit strings...
  • Page 503: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions The following example is for when In is the same as above and Order is _HIGH_LOW. In[0] DWORD#16#01234567 AryOut[0] 16#45 In[1] DWORD#16#89ABCDEF AryOut[1] 16#67 In[2] DWORD#16#CCDDEEFF AryOut[2] 16#01 AryOut[3] 16#23 AryOut[4] 16#CD AryOut[5] 16#EF Out = UINT#12 AryOut[6] 16#89 16#AB...
  • Page 504: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions When In Is BOOL Data If the data type of In is BOOL (one bit), data is stored in AryOut[] as described below. Value of In (array or not) Storage method in AryOut[] Order Not an array The logical OR of the value of In and 16#00 is stored in AryOut[0].
  • Page 505: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions The following example is for when In is the same as above and Order is _HIGH_LOW. AryOut[0] 16#45 In[0] TRUE In[1] AryOut[1] 16#89 FALSE Out = UINT#4 AryOut[2] In[2] 16#00 FALSE AryOut[3] In[3] TRUE 16#04 In[4] FALSE In[5] FALSE In[6]...
  • Page 506: Arybyteto

    2 Instruction Descriptions AryByteTo The AryByteTo instruction joins BYTE array elements and stores the result in a variable. Instruction Name FB/FUN Graphic expression ST expression AryByteTo Conversion from AryByteTo(In, Size, Order, (@)AryByteTo Byte Array OutVal); Size Order OutVal Variables Name Meaning Description Valid range...
  • Page 507: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions Order specifies the order to join the elements of In[]. The data type of Order is enumerated type _eBYTE_ORDER. The meaning of the enumerators are as follows: Enumerators Meaning _LOW_HIGH Lower byte first, higher byte last _HIGH_LOW Higher byte first, lower byte last When the Data Type of OutVal Is Two Bytes or Larger If the data type of OutVal is two bytes or larger, elements from In[] are joined so that the result is just...
  • Page 508: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions The following example is for when OutVal is the same as above, Size is UINT#4, and Order is _HIGH_LOW. In[0] BYTE#16#67 DWORD#16#23016745 OutVal In[1] BYTE#16#45 Size = UINT#4 In[2] BYTE#16#23 In[3] BYTE#16#01 When the Data Type of OutVal Is One Byte If the data type of OutVal is one byte, one byte of In[] is stored directly in OutVal.
  • Page 509: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions When OutVal Is BOOL Data If the data type of OutVal is BOOL (one bit), data is stored in OutVal as described below. Value of OutVal Storage method in OutVal Order (array or not) Not an array Value of bit 0 of In[0] is stored in OutVal.
  • Page 510: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions The following example is for when OutVal and Size are the same as above and Order is _HIGH_LOW. In[0] BYTE#16#89 TRUE OutVal[0] In[1] Size = UINT#3 OutVal[1] BYTE#16#45 FALSE In[2] BYTE#16#04 TRUE OutVal[2] FALSE OutVal[3] OutVal[4] FALSE OutVal[5] FALSE OutVal[6]...
  • Page 511: Sizeofary

    2 Instruction Descriptions SizeOfAry The SizeOfAry instruction gets the number of elements in an array. Instruction Name FB/FUN Graphic expression ST expression SizeOfAry Get Number of Out:=SizeOfAry(In); (@)SizeOfAry Array Elements Variables Name Meaning Description Valid range Unit Default In[] (array) Array Input Array...
  • Page 512: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions Additional Information In[] can be an array with two or more dimensions. Out will contain the total number of elements for all dimensions of In[]. For example, if the input parameter that is passed to In[] is ARRAY[0..1,0..2], the value of Out will be UINT#6.
  • Page 513: Stack And Table Instructions

    Stack and Table Instructions Instruction Name Page StackPush Push onto Stack 2-466 StackFIFO and StackLIFO First In First Out/Last In First Out 2-475 StackIns Insert into Stack 2-478 StackDel Delete from Stack 2-480 RecSearch Record Search 2-482 RecRangeSearch Range Record Search 2-487 RecSort Record Sort...
  • Page 514: Stackpush

    2 Instruction Descriptions StackPush The StackPush instruction stores a value at the top of a stack. Instruction Name FB/FUN Graphic expression ST expression StackPush Push onto Stack StackPush(In, InOut, Size, (@)StackPush Num); InOut Size Variables Name Meaning Description Valid range Unit Default Input value...
  • Page 515: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions The following example is for when Size is UINT#5 and Num is UINT#2. StackPush(INT#3456, abc[1], UINT#5, def); StackPush INT#3456 InOut abc[1] abc[1] UINT#5 Size Incremented Num=def UINT#2 Num=def UINT#3 InOut[0]=abc[1] InOut[0]=abc[1] 1234 1234 InOut[1]=abc[2] 2345 InOut[1]=abc[2] 2345 Size=UINT#5 InOut[2]=abc[3] InOut[2]=abc[3]...
  • Page 516: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions Sample Programming The array variable stcA[0..9] is used as a stack. As preparations, three values (UINT#1111, UINT#2222, and UINT#3333) are stored in the stack. stcA[0] 1111 stcA[1] 2222 stcA[2] 3333 stcA[3] stcA[4] stcA[5] stcA[6] stcA[7] stcA[8] stcA[9] The StackPush instruction is used to store a new value (UINT#4444) at the top of the stack stcA[3].
  • Page 517: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions Finally, the StackIns instruction is used to insert a value (UINT#5555) between stcA[1] and stcA[2]. That means there will be four values in the stack. StackIns instruction executed. StcANUM UINT#3 StcANUM UINT#4 stcA[0] stcA[0] 1111 1111 stcA[1] 2222 stcA[1] 2222...
  • Page 518: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions Data type Comment Initial value Variable False InitStc BOOT Stack initialization condition stcANum UINT Number of stored elements StcA [10(0)] ARRAY[0..9] OF UINT Stack array StcASize UINT Number of stack elements SetParaPush False BOOL Execution condition to set StcAInVal. StcAInVal UINT Value added by StackPush...
  • Page 519: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions Add data with StackPush instruction. StcAPushStat StackPush_err StackPush StcAinVal InOut StcA[0] StcASize Size StcANum Processing after normal end of StackPush Inline ST StackPush_err StcAPushStat 1 // Processing after normal end of StackPush Processing after error end of StackPush Inline ST StackPush_err StcAPushStat...
  • Page 520: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions Insert data with StackIns instruction. StcAInsStat StackIns_err StackIns StcAInsVal InOut StcA[0] StcASize Size StcANum StcAOffset Offset Processing after normal end of StackIns Inline ST StackIns_err StcAInsStat 1 // Processing after normal end of StackIns Processing after error end of StackIns Inline ST StackIns_err StcAInsStat...
  • Page 521: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions Data type Comment Initial value Variable InitStc False BOOL Stack initialization condition preInitStc False BOOL Value of InitStc from previous task period stcANum UINT Number of stored elements StcA [10(0)] ARRAY[0..9] OF UINT Stack array StcASize UINT Number of stack elements False StcAPushStat...
  • Page 522: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions // Remove data with StackLIFO instruction. IF ( (StcALIFOStat=TRUE) AND (preStcALIFOStat=FALSE) ) THEN StackLIFO( InOut :=StcA[0], // First element in stack array OutVal:=StcAOutVal, // Value removed from stack Size :=StcASize, // Number of stack elements :=StcANum, // Number of stored elements =>StcALIFO_OK);...
  • Page 523: Stackfifo And Stacklifo

    2 Instruction Descriptions StackFIFO and StackLIFO StackFIFO: Removes the bottom value from a stack. StackLIFO: Removes the top value from a stack. Instruction Name FB/FUN Graphic expression ST expression StackFIFO First In First Out StackFIFO(InOut, OutVal, (@)StackFIFO Size, Num); InOut OutVal Size StackLIFO...
  • Page 524: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions Times, durations, Bit strings Integers dates, and text strings Size OK OK OK OK OK OK OK OK OK OK OK OK OK OK OK OK OK OK OK OK InOut[] (array) Arrays of enumerations or structures can also be specified. OutVal Must be the same data type as the elements of InOut[].
  • Page 525: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions StackLIFO The StackLIFO instruction removes the top value from a stack. Value of InOut[Num−1] is assigned to OutVal. Then, Num is decremented. The following example is for when Size is UINT#5 and Num is UINT#2. StackLIFO(abc[1], def, UINT#5, ghi); StackLIFO InOut abc[1]...
  • Page 526: Stackins

    2 Instruction Descriptions StackIns The StackIns instruction inserts a value at a specified position in a stack. Instruction Name FB/FUN Graphic expression ST expression StackIns Insert into Stack StackIns(In, InOut, Size, (@)StackIns Num, Offset); InOut Size Offset Variables Name Meaning Description Valid range Unit...
  • Page 527: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions Function The instruction assumes that there are number of stored elements Num elements stored in stack array InOut[]. Insert value In is inserted at the position specified by the offset Offset (InOut[Offset]). All higher elements, i.e., InOut[Offset] to InOut[Num−1], are moved to the next higher element in the stack array. Then, Num is incremented.
  • Page 528: Stackdel

    2 Instruction Descriptions StackDel The StackDel instruction deletes a value from a specified position in a stack. Instruction Name FB/FUN Graphic expression ST expression StackDel Delete from Stack StackDel(InOut, Size, Num, (@)StackDel Offset); InOut Size Offset Variables Name Meaning Description Valid range Unit Default...
  • Page 529: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions The following example is for when Size is UINT#6, Num is UINT#3 and Offset is UINT#1. StackDel(abc[1], UINT#6, def, UINT#1); StackDel InOut abc[1] abc[1] Size UINT#6 UINT#1 Offset Decremented. Num = def UINT#3 Num=def UINT#2 InOut[0]=abc[1] Offset=UINT#1 InOut[0]=abc[1] 1234 1234...
  • Page 530: Recsearch

    2 Instruction Descriptions RecSearch The RecSearch instruction searches an array of structures for elements that match the search key with the specified method. Instruction Name FB/FUN Graphic expression ST expression RecSearch Record Search Out:=RecSearch(In, Size, (@)RecSearch Member, Key, Mode, InOut- Pos, Num);...
  • Page 531: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions Times, durations, Bit strings Integers dates, and text strings In[] (array) Specify an array of structures. Size Member OK OK OK OK OK OK OK OK OK OK Specify the same data type as the search member of In[] Must be the same data type as Member.
  • Page 532: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions The following example is for when Size is UINT#5, Key is INT#1234 and Mode is _LINEAR. ghi:=RecSearch(abc[0], UINT#5, abc[0].m, INT#1234, _LINEAR, def, jkl); RecSearch abc[0] Size UINT#5 Member abc[0].m INT#1234 Mode _LINEAR InOutPos Member=abc[0].m INT#1234 Mode=_LINEAR 0000 In[0]=abc[0] Member m 3456...
  • Page 533: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions Using the same example as before, the order of the array elements and the processing results will be as shown below for an ascending binary search. INT#1234 Mode=_BIN_ASC Matches 0000 Out = ghi TRUE In[0]=abc[0] 1234 0000 InOutPos[0] = def UINT#0 0000...
  • Page 534: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions • If In[] is a three-dimensional array, the element number in the first dimension of the element that matches the search conditions is assigned to InOutPos[0], the element number in the second dimen- sion is assigned to InOutPos[1], and the element number in the third dimension is assigned to InOut- Pos[2].
  • Page 535: Recrangesearch

    2 Instruction Descriptions RecRangeSearch The RecRangeSearch instruction searches an array of structures for elements that match the search condition range with the specified method. Instruction Name FB/FUN Graphic expression ST expression RecRangeSearch Range Record Out:=RecRangeSearch(In, (@)RecRangeSearch Search Size, Member, MN, MX, Condition, Mode, InOutPos, Num);...
  • Page 536: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions Times, durations, Bit strings Integers dates, and text strings In[] (array) Specify an array of structures. Size Member OK OK OK OK OK OK OK OK OK OK Specify the same data type as the search member of In[]. Must be the same data type as Member.
  • Page 537: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions The following example is for when Size is UINT#5, MN is INT#1000, MX is INT#2000, Condition is _EQ_BOTH and Mode is _LINEAR. ghi:=RecRangeSearch(abc[0], UINT#5, abc[0].m, INT#1000, INT#2000, _EQ_BOTH, _LINEAR, def, jkl); RecRangeSearch abc[0] UINT#5 Size Member abc[0].m INT#1000 INT#2000 Condition...
  • Page 538: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions Using the same example as before, the order of the array elements and the processing results will be as shown below for an ascending binary search. INT#1000 Condition=_EQ_BOTH INT#2000 Mode=_BIN_ASC Out = ghi Matches 0000 TRUE In[0]=abc[0] 1234 0000 InOutPos[0] = def...
  • Page 539: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions Additional Information • In[] can be a member of a higher-level structure. Example: In[0]=str0.str1[0] • In[] can be an array with two or more dimensions. If In[] is a two-dimensional array, the element num- ber in the first dimension of the element that matches the search conditions is assigned to InOut- Pos[0] and the element number in the second dimension is assigned to InOutPos[1].
  • Page 540: Recsort

    2 Instruction Descriptions RecSort The RecSort instruction sorts the elements of an array of structures. Instruction Name FB/FUN Graphic expression ST expression RecSort Record Sort RecSort_instance(Execute, RecSort_instance InOut, Size, Member, Order, RecSort Done, Busy, Error); Execute Done InOut Size Busy Member Error Order Variables...
  • Page 541: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions Function When the value of Execute is TRUE, Size elements of InOut[] (a structure array) is sorted. Specifically, − the elements from InOut[0] to InOut[Size 1] are sorted. Specifically, the elements from InOut[0] to − InOut[Size 1] are sorted. Order specifies the sort order. Details are provided below. One of the mem- bers to sort in the elements of In[] is passed as an argument to Member.
  • Page 542: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions Additional Information If the power supply is interrupted during execution of this instruction, the contents of InOut may be cor- rupted. If you back up the contents of InOut[] each time the instruction is completed normally, you can restore the data if it is corrupted.
  • Page 543: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions Initial Internal Data type Retain Comment Variable Variables value Sorting BOOL False Processing (retained) OperatingEnd BOOL False Processing completed Trigger BOOL False Execution condition Operating BOOL False Processing RS_instance RecSort_instance RecSort External Data type Variable Comment Variables ARRAY[0..4] OF MyStr Sort array Abc_backup...
  • Page 544: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions Initial Internal Variable Data type Retain Comment Variables value BOOL False Processing (retained) Sorting BOOL False Execution condition Trigger BOOL Value of Trigger from previous task period False LastTrigger BOOL False Processing started OperatingStart BOOL False Processing Operating RS_instance RecSort...
  • Page 545: Recnum

    2 Instruction Descriptions RecNum The RecNum instruction finds the number of records in an array of structures to the end data. Instruction Name FB/FUN Graphic expression ST expression RecNum Get Number of Out:=RecNum(In, Member, (@)RecNum Records EndDat); Member EndDat Variables Name Meaning Description...
  • Page 546: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions The following example is for when EndDat is INT#9999. def:=RecNum(abc[0], abc[0].m, INT#9999); RecNum abc[0] abc[0].m Member INT#9999 EndDat EndDat INT#9999 Member = abc[0].m 0000 Member m In[0]=abc[0] 3456 0000 0000 Num = def UINT#3 In[1]=abc[1] 2345 0000 0000 In[2]=abc[2] 1234...
  • Page 547: Recmax And Recmin

    2 Instruction Descriptions RecMax and RecMin RecMax: Searches the specified member in the structures of an array of structures for the maximum value. RecMin: Searches the specified member in the structures of an array of structures for the minimum value. Instruction Name FB/FUN...
  • Page 548: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions Times, durations, Bit strings Integers dates, and text strings InOutPos[] (array) OK OK OK OK OK OK OK OK OK OK Function These instructions search Size elements in an array of structures In[]. The search range is therefore −...
  • Page 549: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions Member=abc[0].m 0000 In[0]=abc[0] 1234 Member m 0000 0000 In[1]=abc[1] 2345 0000 0000 In[2]=abc[2] Size=UINT#5 INT#3456 Out = ghi 3456 0000 0000 In[3]=abc[3] 1234 0000 0000 In[4]=abc[4] UINT#2 3456 Num = jkl 0000 UINT#2 InOutPos[0] = def Additional Information •...
  • Page 550: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions 2-502 NJ-series Instructions Reference Manual (W502)
  • Page 551: Fcs Instructions

    FCS Instructions Instruction Name Page StringSum Checksum Calculation 2-504 StringLRC Calculate Text String LRC 2-506 StringCRCCCITT Calculate Text String CRC-CCITT 2-508 StringCRC16 Calculate Text String CRC-16 2-510 AryLRC_** Calculate Array LRC Group 2-512 AryCRCCCITT Calculate Array CRC-CCITT 2-514 AryCRC16 Calculate Array CRC-16 2-516 NJ-series Instructions Reference Manual (W502) 2-503...
  • Page 552: Stringsum

    2 Instruction Descriptions StringSum The StringSum instruction calculates the checksum for a text string. Instruction Name FB/FUN Graphic expression ST expression StringSum Checksum Calcula- Out:=StringSum(In, Size); (@)StringSum tion Size Variables Name Meaning Description Valid range Unit Default Text string Text string to process Depends on data type.
  • Page 553: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions Precautions for Correct Use • If the sum of the character codes in In exceeds the number of digits of Size, the upper digits are dis- carded. • An error occurs in the following cases. ENO will be FALSE, and Out will not change. •...
  • Page 554: Stringlrc

    2 Instruction Descriptions StringLRC The StringLRC instruction calculates the LRC value (horizontal parity). Instruction Name FB/FUN Graphic expression ST expression StringLRC Calculate Text Out:=StringLRC(In); (@)StringLRC String LRC Variables Name Meaning Description Valid range Unit Default Text string Input Text string to process Depends on data type.
  • Page 555: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions Precautions for Correct Use An error occurs in the following cases. ENO will be FALSE, and Out will not change. • In does not end in a NULL character. • The number of bytes in In is 0 (i.e., the NULL character only). •...
  • Page 556: Stringcrcccitt

    2 Instruction Descriptions StringCRCCCITT The StringCRCCCITT instruction calculates the CRC-CCITT value using the XMODEM method. Instruction Name FB/FUN Graphic expression ST expression StringCRCCCITT Calculate Text Out:=StringCRCCCITT(In, (@)StringCRCCCITT String CRC-CCITT Initial, OutOrder); Initial OutOrder Variables Name Meaning Description Valid range Unit Default Text string Text string to process...
  • Page 557: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions The following example is for when In is ‘RD’, Initial is WORD#16#0000, and OutOrder is _HIGH_LOW. abc:=StringCRCCCITT(’RD’, WORD#16#0000, _HIGH_LOW); StringCRCCCITT ‘RD’ WORD#16#0000 Initial _HIGH_LOW OutOrder ‘RD’ Character codes CRC-CCITT value Out = abc ‘609D’ Precautions for Correct Use An error occurs in the following cases.
  • Page 558: Stringcrc16

    2 Instruction Descriptions StringCRC16 The StringCRC16 instruction calculates the CRC-16 value using the MODBUS method. Instruction Name FB/FUN Graphic expression ST expression StringCRC16 Calculate Text Out:=StringCRC16(In, Ini- (@)StringCRC16 String CRC-16 tial, OutOrder); Initial OutOrder Variables Name Meaning Description Valid range Unit Default Text string...
  • Page 559: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions The following example is for when In is ‘01’, Initial is WORD#16#FFFF and OutOrder is _LOW_HIGH. abc:=StringCRC16(’01’, WORD#16#FFF _LOW_HIGH); StringCRC16 ‘01’ WORD#16#FFFF Initial _LOW_HIGH OutOrder ‘01’ Character codes CRC-16 value Out = abc ‘D464’ Precautions for Correct Use An error occurs in the following cases.
  • Page 560: Arylrc

    2 Instruction Descriptions AryLRC_** The AryLRC_** instructions calculate the LRC value for an array. Instruction Name FB/FUN Graphic expression ST expression AryLRC_** Calculate Array Out:=AryLRC_**(In, Size); (@)AryLRC_** LRC Group "**" must be a bit string data type. Size "**" must be a bit string data type. Variables Name Meaning...
  • Page 561: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions The following example shows the AryLRC_WORD instruction when Size is UINT#5. def:=AryLRC_WORD(abc[4], UINT#5); AryLRC_WORD abc[4] UINT#5 Size 16#1234 In[0]=abc[4] Exclusive logical OR In[1]=abc[5] 16#2345 16#1638 In[2]=abc[6] 16#3456 Size = UINT#5 Out = def 16#4567 In[3]=abc[7] In[4]=abc[8] 16#5678 Precautions for Correct Use •...
  • Page 562: Arycrcccitt

    2 Instruction Descriptions AryCRCCCITT The AryCRCCCITT instruction calculates the CRC-CCITT value using the XMODEM method. Instruction Name FB/FUN Graphic expression ST expression AryCRCCCITT Calculate Array Out:=AryCRCCCITT(In, (@)AryCRCCCITT CRC-CCITT Size, Initial, OutOrder); Size Initial OutOrder Variables Name Meaning Description Valid range Unit Default In[] (array)
  • Page 563: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions The data type of OutOrder is enumerated type _eBYTE_ORDER. The meaning of the enumerators are as follows: Enumerators Meaning _LOW_HIGH Lower byte first, upper byte last _HIGH_LOW Upper byte first, lower byte last Always attach the element number to in-out parameter that is passed to In[], e.g., array[3]. The following example is for when Size is UINT#2, Initial is WORD#16#0000, and OutOrder is _LOW_HIGH.
  • Page 564: Arycrc16

    2 Instruction Descriptions AryCRC16 The AryCRC16 instruction calculates the CRC-16 value using the MODBUS method. Instruction Name FB/FUN Graphic expression ST expression AryCRC16 Calculate Array Out:=AryCRC16(In, Size, (@)AryCRC16 CRC-16 Initial, OutOrder); Size Initial OutOrder Variables Name Meaning Description Valid range Unit Default In[] (array)
  • Page 565: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions The data type of OutOrder is enumerated type _eBYTE_ORDER. The meaning of the enumerators are as follows: Enumerator Meaning _LOW_HIGH Lower byte first, upper byte last _HIGH_LOW Upper byte first, lower byte last The following example is for when Size is UINT#2, Initial is WORD#16#FFFF and OutOrder is _LOW_HIGH.
  • Page 566: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions 2-518 NJ-series Instructions Reference Manual (W502)
  • Page 567: Text String Instructions

    Text String Instructions Instruction Name Page CONCAT Concatenate String 2-520 LEFT and RIGHT Get String Left/Get String Right 2-522 Get String Any 2-524 FIND Find String 2-526 String Length 2-528 REPLACE Replace String 2-529 DELETE Delete String 2-531 INSERT Insert String 2-533 GetByteLen Get Byte Length...
  • Page 568: Concat

    2 Instruction Descriptions CONCAT The CONCAT instruction joins two to five text strings. Instruction Name FB/FUN Graphic expression ST expression CONCAT Concatenate String Out:=CONCAT(In1,···, InN); (@)CONCAT Variables Name Meaning Description Valid range Unit Default In1 to InN Strings to Input Text strings to join, where N Depends on data type.
  • Page 569: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions ‘AB’ Joined. ‘ABCDEF’ Out=abc ‘C’ ‘DEF’ Precautions for Correct Use An error occurs in the following cases. ENO will be FALSE, and Out will not change. • One of In1 to InN does not end in a NULL character. •...
  • Page 570: Left And Right

    2 Instruction Descriptions LEFT and RIGHT These instructions extract a text string with the specified number of characters. LEFT: Extracts characters from the left (beginning) of the text string. RIGHT: Extracts characters from the right (end) of the text string. Instruction Name FB/FUN...
  • Page 571: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions The following example is for when In is ‘ABCDEF’ and L is UINT#3. The value of variable abc will be ‘ABC’. abc:=LEFT(‘ABCDEF’, UINT#3); LEFT ‘ABCDEF’ UINT#3 ‘ABCDEF’ Three characters extracted from the left. ‘ABC’ Out=abc RIGHT Extracts characters from the right (end) of In. The following example is for when In is ‘ABCDEF’...
  • Page 572: Mid

    2 Instruction Descriptions The MID instruction extracts a text string with the specified number of characters from the specified character position. Instruction Name FB/FUN Graphic expression ST expression Get String Any Out:=MID(In, L, P); (@)MID Variables Name Meaning Description Valid range Unit Default Source...
  • Page 573: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions The following example is for when In is ‘ABCDEF’, L is UINT#3, and P is UINT#2. The value of variable abc will be ‘BCD’. abc:=MID(‘ABCDEF’, UINT#3, UINT#2); ‘ABCDEF’ UINT#3 UINT#2 ‘ABCDEF’ Three characters are extracted starting from second character. ‘BCD’...
  • Page 574: Find

    2 Instruction Descriptions FIND The FIND instruction searches a specified text string for the position of a specified text string. Instruction Name FB/FUN Graphic expression ST expression FIND Find String Out:=FIND(In1, In2); (@)FIND Variables Name Meaning Description Valid range Unit Default String to Text string to search...
  • Page 575: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions Precautions for Correct Use • Make sure the number of characters in In2 is less than the number of characters in In1. Otherwise, the value of Out will be 0. • If In2 exists more than once in In1, the position of the first In2 from the beginning of In1 is assigned to Out.
  • Page 576: Len

    2 Instruction Descriptions The LEN instruction finds the number of characters in a text string. Instruction Name FB/FUN Graphic expression ST expression String Length Out:=LEN(In); (@)LEN Variables Name Meaning Description Valid range Unit Default Length Input Text string to find length Depends on data type.
  • Page 577: Replace

    2 Instruction Descriptions REPLACE The REPLACE instruction replaces part of a text string with another text string. Instruction Name FB/FUN Graphic expression ST expression REPLACE Replace String Out:=REPLACE(In1, In2, L, (@)REPLACE Variables Name Meaning Description Valid range Unit Default String for Text string for replacement replace- ment...
  • Page 578: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions The following example is for when In1 is ‘ABCDEF’, In2 is ‘GHI’, P is UINT#2, and L is UINT#4. The value of variable abc will be ‘AGHIF’. abc:=REPLACE(‘ABCDEF’, ‘GHI’, UINT#4, UINT#2); REPLACE ‘ABCDEF’ ‘GHI’ UINT#4 UINT#2 Deleted ‘AGHIF’...
  • Page 579: Delete

    2 Instruction Descriptions DELETE The DELETE instruction deletes all or part of a text string. Instruction Name FB/FUN Graphic expression ST expression DELETE Delete String Out:=DELETE(In, L, P); (@)DELETE Variables Name Meaning Description Valid range Unit Default String for Text string for deletion Depends on data type.
  • Page 580: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions The following example is for when In is 'ABCDEF', L is UINT#4, and P is UINT#2. The value of variable abc will be 'AF'. abc:=DELETE(‘ABCDEF’, UINT#4, UINT#2); DELETE ‘ABCDEF’ UINT#4 UINT#2 Deleted Out=abc ‘AF’ ‘ABCDEF’ Precautions for Correct Use •...
  • Page 581: Insert

    2 Instruction Descriptions INSERT The INSERT instruction inserts a text string into another text string. Instruction Name FB/FUN Graphic expression ST expression INSERT Insert String Out:=INSERT(In1, In2, P); (@)INSERT Variables Name Meaning Description Valid range Unit Default Original Text string into which to string insert string Depends on data type.
  • Page 582: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions The following example is for when In1 is 'ABCD', In2 is 'GHI', and P is UINT#2. The value of variable abc will be 'ABGHICD'. abc:=INSERT(‘ABCD’, ‘GHI’, UINT#2); INSERT ‘ABCD’ ‘GHI’ UINT#2 Out=abc ‘ABGHICD’ ‘ABCD’ Insert ‘GHI’ Additional Information If P is 0, In1 is inserted at the end of In2.
  • Page 583: Getbytelen

    2 Instruction Descriptions GetByteLen The GetByteLen instruction counts the number of bytes in a text string. Instruction Name FB/FUN Graphic expression ST expression GetByteLen Get Byte Length Out:=GetByteLen(In); (@)GetByteLen Variables Name Meaning Description Valid range Unit Default Count Input Text string to count number Depends on data type.
  • Page 584: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions Additional Information If In contains only ASCII characters, the result will be the same as the result of the LEN instruction. Precautions for Correct Use An error occurs in the following case. ENO will be FALSE, and Out will not change. •...
  • Page 585: Clearstring

    2 Instruction Descriptions ClearString The ClearString instruction clears a text string. Instruction Name FB/FUN Graphic expression ST expression ClearString Clear String ClearString(InOut); (@)ClearString InOut Variables Name Meaning Description Valid range Unit Default InOut Clear string In-out Text string to clear Depends on data type.
  • Page 586: Toucase And Tolcase

    2 Instruction Descriptions ToUCase and ToLCase ToUCase: Converts all single-byte letters in a text string to uppercase. ToLCase: Converts all single-byte letters in a text string to lowercase. Instruction Name FB/FUN Graphic expression ST expression ToUCase Convert to Upper- Out:=ToUCase(In); (@)ToUCase case ToLCase...
  • Page 587: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions The following example for the ToUCase instruction is for when In is ‘xyz’. The value of variable abc will be ‘XYZ’. abc:=ToUCase(‘xyz’); ToUCase ‘xyz’ Precautions for Correct Use • Two-byte letters are not converted. • An error occurs in the following cases. ENO will be FALSE, and Out will not change. •...
  • Page 588: Triml And Trimr

    2 Instruction Descriptions TrimL and TrimR TrimL: Removes blank space from the beginning of a text string. TrimR: Removes blank space from the end of a text string. Instruction Name FB/FUN Graphic expression ST expression TrimL Trim String Left Out:=TrimL(In); (@)TrimL TrimR Trim String Right...
  • Page 589: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions The following example for the TrimL instruction is for when In is ‘ AB C’. The value of variable abc will be ‘ AB C’. abc:=TrimL(‘ AB C’); TrimL ‘ AB C’ Precautions for Correct Use An error occurs in the following cases. ENO will be FALSE, and Out will not change. •...
  • Page 590: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions 2-542 NJ-series Instructions Reference Manual (W502)
  • Page 591: Time And Time Of Day Instructions

    Time and Time of Day Instructions Instruction Name Page Instruction Name Page ADD_TIME Add Time 2-544 DateToSec Convert Date to Seconds 2-576 ADD_TOD_TIME Add Time to Time of Day 2-546 TodToSec Convert Time of Day to Sec- 2-577 onds ADD_DT_TIME Add Time to Date and Time 2-548 SecToDt...
  • Page 592: Add_Time

    2 Instruction Descriptions ADD_TIME The ADD_TIME instruction adds two times. Instruction Name FB/FUN Graphic expression ST expression ADD_TIME Add Time Out:=ADD_TIME(In1, In2); (@)ADD_TIME Variables Name Meaning Description Valid range Unit Default Add time 1 Add time 1 Input Depends on data type. T#0s Add time 2 Add time 2...
  • Page 593: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions Precautions for Correct Use An error will not occur even if the addition result exceeds the valid range of Out. • T#106751d_23h_47m_16s_854.775807ms + T#0.000001ms → T#-106751d_23h_47m_16s_854.775808ms • T#-106751d_23h_47m_16s_854.775808ms + T#-0.000001ms → T#106751d_23h_47m_16s_854.775807ms NJ-series Instructions Reference Manual (W502) 2-545...
  • Page 594 2 Instruction Descriptions ADD_TOD_TIME The ADD_TOD_TIME instruction adds a time to a time of day. Instruction Name FB/FUN Graphic expression ST expression ADD_TOD_TIME Add Time to Time Out:=ADD_TOD_TIME(In1, (@)ADD_TOD_TIME of Day In2); Variables Name Meaning Description Valid range Unit Default Add time of Add time of day Hour, min-...
  • Page 595: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions Precautions for Correct Use An error will not occur even if the addition result exceeds the valid range of Out. • TOD#23:59:59.999999999 + T#0.000001ms → TOD#0:0:0.000000000 • TOD#0:0:0.000000000 + T#-0.000001ms → TOD#23:59:59.999999999 NJ-series Instructions Reference Manual (W502) 2-547...
  • Page 596: Add_Dt_Time

    2 Instruction Descriptions ADD_DT_TIME The ADD_DT_TIME instruction adds a time to a date and time. Instruction Name FB/FUN Graphic expression ST expression ADD_DT_TIME Add Time to Date Out:=ADD_DT_TIME(In1, (@)ADD_DT_TIME and Time In2); Variables Name Meaning Description Valid range Unit Default Add date Add date and time Year, month,...
  • Page 597: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions Function The ADD_DT_TIME instruction adds a time, In2, to a date and time In1. The result of addition in Out is also a date and time. Leap years are also accounted for. The following example is for when In1 is DT#1970-1-1-0:0:0 and In2 is T#1d.
  • Page 598: Sub_Time

    2 Instruction Descriptions SUB_TIME The SUB_TIME instruction subtracts one time from another. Instruction Name FB/FUN Graphic expression ST expression SUB_TIME Subtract Time Out:=SUB_TIME(In1, In2); (@)SUB_TIME Variables Name Meaning Description Valid range Unit Default Original Original time time Input Depends on data type. T#0s Time to Time to subtract...
  • Page 599: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions Precautions for Correct Use An error will not occur even if the subtraction result exceeds the valid range of Out. • T#106751d_23h_47m_16s_854.775807ms − T#-0.000001ms → T#-106751d_23h_47m_16s_854.775808ms • T#-106751d_23h_47m_16s_854.775808ms − T#0.000001ms → T#106751d_23h_47m_16s_854.775807ms NJ-series Instructions Reference Manual (W502) 2-551...
  • Page 600 2 Instruction Descriptions SUB_TOD_TIME The SUB_TOD_TIME instruction subtracts a time from a time of day. Instruction Name FB/FUN Graphic expression ST expression SUB_TOD_TIME Subtract Time from Out:=SUB_TOD_TIME(In1, (@)SUB_TOD_TIME Time of Day In2); Variables Name Meaning Description Valid range Unit Default Time of day Time of day Hour, min-...
  • Page 601: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions Precautions for Correct Use An error will not occur even if the subtraction result exceeds the valid range of Out. • TOD#23:59:59.999999999 − T#-0.000001ms → TOD#0:0:0 • TOD#0:0:0 − T#0.000001ms → TOD#23:59:59.999999999 NJ-series Instructions Reference Manual (W502) 2-553...
  • Page 602: Sub_Tod_Tod

    2 Instruction Descriptions SUB_TOD_TOD The SUB_TOD_TOD instruction subtracts a time of day from another time of day. Instruction Name FB/FUN Graphic expression ST expression SUB_TOD_TOD Subtract Time of Out:=SUB_TOD_TOD(In1, (@)SUB_TOD_TOD In2); Variables Name Meaning Description Valid range Unit Default Time of day Time of day 1 Hour, min- TOD#0:0...
  • Page 603: Sub_Date_Date

    2 Instruction Descriptions SUB_DATE_DATE The SUB_DATE_DATE instruction subtracts another date from another date. Instruction Name FB/FUN Graphic expression ST expression SUB_DATE_DATE Subtract Date Out:=SUB_DATE_DATE(In1, (@)SUB_DATE_DATE In2); Variables Name Meaning Description Valid range Unit Default Date 1 Date 1 Year, month, D#1970- Input Depends on data type.
  • Page 604: Sub_Dt_Dt

    2 Instruction Descriptions SUB_DT_DT The SUB_DT_DT instruction subtracts another date and time from another date and time. Instruction Name FB/FUN Graphic expression ST expression SUB_DT_DT Subtract Date and Out:=SUB_DT_DT(In1, (@)SUB_DT_DT Time In2); Variables Name Meaning Description Valid range Unit Default Date and Date and time 1 Year, month,...
  • Page 605: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions Related System-defined Variables Name Meaning Data type Description _CurrentTime System Time of Day The time of day from the system clock. The num- ber of seconds from 00:00:00 on January 1,1970. Precautions for Correct Use If the processing result exceeds the valid range of Out, Out will contain an illegal value. NJ-series Instructions Reference Manual (W502) 2-557...
  • Page 606: Sub_Dt_Time

    2 Instruction Descriptions SUB_DT_TIME The SUB_DT_TIME instruction subtracts a time from a date and time. Instruction Name FB/FUN Graphic expression ST expression SUB_DT_TIME Subtract Time from Out:=SUB_DT_TIME(In1, (@)SUB_DT_TIME Date and Time In2); Variables Name Meaning Description Valid range Unit Default Date and Date and time Year, month,...
  • Page 607: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions Function The SUB_DT_TIME instruction subtracts a time In2 from a date and time In1. The result of subtraction in Out is a date and time. Leap years are also accounted for. The following example is for when In1 is DT#1970-1-1-0:0:0 and In2 is T#1d. abc:=SUB_DT_TIME(DT#1970-1-7-0:0:0, T#1d);...
  • Page 608: Multime

    2 Instruction Descriptions MULTIME The MULTIME instruction multiplies a time by a specified number. Instruction Name FB/FUN Graphic expression ST expression MULTIME Multiply Time Out:=MULTIME(In1, In2); (@)MULTIME Variables Name Meaning Description Valid range Unit Default Original Original time T#0s time Input Depends on data type.
  • Page 609: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions Precautions for Correct Use • If In2 is a real number, the multiplication result is rounded to the nearest nanosecond. The following table shows how values are rounded. Value below nanosec- Treatment Examples onds 1.49 → 1 Less than 0.5 The value is truncated.
  • Page 610: Divtime

    2 Instruction Descriptions DIVTIME The DIVTIME instruction divides a time by a specified number. Instruction Name FB/FUN Graphic expression ST expression DIVTIME Divide Time Out:=DIVTIME(In1, In2); (@)DIVTIME Variables Name Meaning Description Valid range Unit Default Original Original time T#0s time Input Depends on data type.
  • Page 611: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions Precautions for Correct Use • If the value of In2 is 0, positive infinity, negative infinity, or nonnumeric data, the value of Out is as shown below. Value of In2 Value of Out T#-106751d23h47m16.854775808s +∞ T#0s −∞ T#0s Nonnumeric data Nonnumeric data...
  • Page 612: Concat_Date_Tod

    2 Instruction Descriptions CONCAT_DATE_TOD The CONCAT_DATE_TOD instruction combines a date and a time of day. Instruction Name FB/FUN Graphic expression ST expression CONCAT_DATE Concatenate Date Out:=CONCAT_DATE_TOD (@)CONCAT_DATE_TOD _TOD and Time of Day (In1, In2); Variables Name Meaning Description Valid range Unit Default Date...
  • Page 613: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions Function The CONCAT_DATE_TOD instruction combines a date In1 and a time of day In2. The result of combin- ing in Out is also a date and time. The following example is for when In1 is D#1970-1-7 and In2 is TOD#23:59:59.999999999. abc:=CONCAT_DATE_TOD(D#1970-1-7, TOD#23:59:59.999999999);...
  • Page 614: Dt_To_Tod

    2 Instruction Descriptions DT_TO_TOD The DT_TO_TOD instruction extracts the time of day from a date and time. Instruction Name FB/FUN Graphic expression ST expression DT_TO_TOD Extract Time of Day Out:=DT_TO_TOD(In); (@)DT_TO_TOD from Date and Time Variables Name Meaning Description Valid range Unit Default Date and...
  • Page 615: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions Related System-defined Variables Name Meaning Data type Description _CurrentTime System Time of Day The time of day from the system clock. The num- ber of seconds from 00:00:00 on January 1,1970. NJ-series Instructions Reference Manual (W502) 2-567...
  • Page 616: Dt_To_Date

    2 Instruction Descriptions DT_TO_DATE The DT_TO_DATE instruction extracts the date from a date and time. Instruction Name FB/FUN Graphic expression ST expression DT_TO_DATE Extract Date from Out:=DT_TO_DATE(In); (@)DT_TO_DATE Date and Time Variables Name Meaning Description Valid range Unit Default Date and Input Date and time Depends on data type.
  • Page 617: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions Related System-defined Variables Name Meaning Data type Description _CurrentTime System Time of Day The time of day from the system clock. The num- ber of seconds from 00:00:00 on January 1,1970. NJ-series Instructions Reference Manual (W502) 2-569...
  • Page 618: Settime

    2 Instruction Descriptions SetTime The SetTime instruction sets the system time. Instruction Name FB/FUN Graphic expression ST expression SetTime Set Time SetTime(In); (@)SetTime Variables Name Meaning Description Valid range Unit Default Time data Input Current time to set system Depends on data type. Year, month, DT#197 time...
  • Page 619: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions Related System-defined Variables Name Meaning Data type Description _CurrentTime System Time of Day The time of day from the system clock. The num- ber of seconds from 00:00:00 on January 1,1970. Additional Information The following methods can also be used to set the system time. •...
  • Page 620: Gettime

    2 Instruction Descriptions GetTime The GetTime instruction reads the current time. Instruction Name FB/FUN Graphic expression ST expression GetTime Get Time of Day Out:=GetTime(); (@)GetTime Variables Name Meaning Description Valid range Unit Default Current Output Current time Depends on data type. Year, month, time day, hour,...
  • Page 621: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions Related System-defined Variables Name Meaning Data type Description _CurrentTime System Time of Day The time of day from the system clock. The num- ber of seconds from 00:00:00 on January 1,1970. Additional Information • Use the DtToSec instruction (page 2-574) to convert the current time of day to the system time of day (number of seconds from 00:00:00 on January 1,1970).
  • Page 622: Dttosec

    2 Instruction Descriptions DtToSec The DtToSec instruction converts a date and time to the number of seconds from 00:00:00 on January 1, 1970. Instruction Name FB/FUN Graphic expression ST expression DtToSec Convert Date and Out:=DtToSec(In); (@)DtToSec Time to Seconds Variables Name Meaning Description...
  • Page 623: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions Related System-defined Variables Name Meaning Data type Description _CurrentTime System Time of Day The time of day from the system clock. The num- ber of seconds from 00:00:00 on January 1,1970. Additional Information Use the SecToDt instruction (page 2-578) to convert the number of seconds from 00:00:00 on January 1,1970 to a date and time.
  • Page 624: Datetosec

    2 Instruction Descriptions DateToSec The DateToSec instruction converts a date to the number of seconds from 00:00:00 on January 1, 1970. Instruction Name FB/FUN Graphic expression ST expression DateToSec Convert Date to Out:=DateToSec(In); (@)DateToSec Seconds Variables Name Meaning Description Valid range Unit Default Date...
  • Page 625: Todtosec

    2 Instruction Descriptions TodToSec The TodToSec instruction converts a time of day to the number of seconds from 00:00:00. Instruction Name FB/FUN Graphic expression ST expression TodToSec Convert Time of Out:=TodToSec(In); (@)TodToSec Day to Seconds Variables Name Meaning Description Valid range Unit Default Time of day Input...
  • Page 626: Sectodt

    2 Instruction Descriptions SecToDt The SecToDt instruction converts the number of seconds from 00:00:00 on January 1, 1970 to a date and time. Instruction Name FB/FUN Graphic expression ST expression SecToDt Convert Seconds to Out:=SecToDt(In); (@)SecToDt Date and Time Variables Name Meaning Description...
  • Page 627: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions Related System-defined Variables Name Meaning Data type Description _CurrentTime System Time of Day The time of day from the system clock. The num- ber of seconds from 00:00:00 on January 1,1970. Additional Information Use the DtToSec instruction (page 2-574) to convert the current time of day to the number of seconds from 00:00:00 on January 1,1970.
  • Page 628: Sectodate

    2 Instruction Descriptions SecToDate The SecToDate instruction converts the number of seconds from 00:00:00 to a date. Instruction Name FB/FUN Graphic expression ST expression SecToDate Convert Seconds to Out:=SecToDate(In); (@)SecToDate Date Variables Name Meaning Description Valid range Unit Default Seconds Input Number of seconds from 0 to 18446744073...
  • Page 629: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions Precautions for Correct Use An error occurs in the following case. ENO will be FALSE, and Out will not change. • The value of In is outside of the valid range. NJ-series Instructions Reference Manual (W502) 2-581...
  • Page 630: Sectotod

    2 Instruction Descriptions SecToTod The SecToTod instruction converts the number of seconds from 00:00:00 to a time of day. Instruction Name FB/FUN Graphic expression ST expression SecToTod Convert Seconds to Out:=SecToTod(In); (@)SecToTod Time of Day Variables Name Meaning Description Valid range Unit Default Seconds...
  • Page 631: Timetonanosec

    2 Instruction Descriptions TimeToNanoSec The TimeToNanoSec instruction converts a time to nanoseconds. Instruction Name FB/FUN Graphic expression ST expression TimeToNanoSec Convert Time to Out:=TimeToNanoSec(In); (@)TimeToNanoSec Nanoseconds Variables Name Meaning Description Valid range Unit Default Time Input Time Depends on data type. T#0s Nanosec- Output...
  • Page 632: Timetosec

    2 Instruction Descriptions TimeToSec The TimeToSec instruction converts a time to seconds. Instruction Name FB/FUN Graphic expression ST expression TimeToSec Convert Time to Out:=TimeToSec(In); (@)TimeToSec Seconds Variables Name Meaning Description Valid range Unit Default Time Input Time Depends on data type. T#0s −9223372036 to Seconds...
  • Page 633: Nanosectotime

    2 Instruction Descriptions NanoSecToTime The NanoSecToTime instruction converts nanoseconds to a time. Instruction Name FB/FUN Graphic expression ST expression NanoSecToTime Convert Nanosec- Out:=NanoSecToTime(In); (@)NanoSecToTime onds to Time Variables Name Meaning Description Valid range Unit Default Nanosec- Input Nanoseconds onds Time Output Time Depends on data type.
  • Page 634: Sectotime

    2 Instruction Descriptions SecToTime The SecToTime instruction converts seconds to a time. Instruction Name FB/FUN Graphic expression ST expression SecToTime Convert Seconds to Out:=SecToTime(In); (@)SecToTime Time Variables Name Meaning Description Valid range Unit Default −9223372036 to Seconds Input Seconds Seconds 9223372036 Time Output...
  • Page 635: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions Precautions for Correct Use • In is in seconds. Out is in nanoseconds. • An error occurs in the following case. ENO will be FALSE, and Out will not change. • The value of In is outside of the valid range. NJ-series Instructions Reference Manual (W502) 2-587...
  • Page 636: Chkleapyear

    2 Instruction Descriptions ChkLeapYear The ChkLeapYear instruction is used to check for a leap year. Instruction Name FB/FUN Graphic expression ST expression ChkLeapYear Check for Leap Out:=ChkLeapYear(In); (@)ChkLeapYear Year Variables Name Meaning Description Valid range Unit Default Year Input Year 1970 to 2554 Year 1970...
  • Page 637: Getdaysofmonth

    2 Instruction Descriptions GetDaysOfMonth The GetDaysOfMonth instruction gets the number of days in the specified month. Instruction Name FB/FUN Graphic expression ST expression GetDaysOfMonth Get Days in Month Out:=GetDaysOfMonth(Year, (@)GetDaysOfMonth Month); Year Month Variables Name Meaning Description Valid range Unit Default Year Year...
  • Page 638: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions Sample Programming This sample gets the number of days in the current month. Internal Comment Variable Data type Initial value Variables _sDT (Year:=0, Month:=0, Day:=0, Hour:=0, Min:=0, Sec:=0, NSec:=0) Date and time USINT Days in current month External Variable Data type...
  • Page 639: Daystomonth

    2 Instruction Descriptions DaysToMonth The DaysToMonth instruction calculates the month based on the number of days from January 1. Instruction Name FB/FUN Graphic expression ST expression DaysToMonth Convert Days to Out:=DaysToMonth(Year, (@)DaysToMonth Month Days); Year Days Variables Name Meaning Description Valid range Unit Default...
  • Page 640: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions Precautions for Correct Use • If the value of Year exceeds the valid range, an error will not occur and the value of Out will be an ille- gal value. • An error occurs in the following case. ENO will be FALSE, and Out will not change. •...
  • Page 641: Getdayofweek

    2 Instruction Descriptions GetDayOfWeek The GetDayOfWeek instruction gets the day of the week for the specified year, month, and day of month. Instruction Name FB/FUN Graphic expression ST expression GetDayOfWeek Get Day of Week Out:=GetDayOfWeek(In); (@)GetDayOfWeek Variables Name Meaning Description Valid range Unit Default...
  • Page 642: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions The following example is for when In is D#2011-1-1. abc:=GetDayOfWeek(D#2011-1-1); GetDayOfWeek D#2011-1-1 Day of the week _SAT Day of the week Out=abc D#2011-1-1 Related System-defined Variables Name Meaning Data type Description _CurrentTime System Time of Day The time of day from the system clock. The num- ber of seconds from 00:00:00 on January 1,1970.
  • Page 643: Getweekofyear

    2 Instruction Descriptions GetWeekOfYear The GetWeekOfYear instruction gets the week number for the specified year, month, and day of month. Instruction Name FB/FUN Graphic expression ST expression GetWeekOfYear Get Week Number Out:=GetWeekOfYear(In); (@)GetWeekOfYear Variables Name Meaning Description Valid range Unit Default Year, Input...
  • Page 644: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions Related System-defined Variables Name Meaning Data type Description _CurrentTime System Time of Day The time of day from the system clock. The num- ber of seconds from 00:00:00 on January 1,1970. 2-596 NJ-series Instructions Reference Manual (W502)
  • Page 645: Dttodatestruct

    2 Instruction Descriptions DtToDateStruct The DtToDateStruct instruction converts a date and time to the year, month, day, hour, minutes, sec- onds, and nanoseconds. Instruction Name FB/FUN Graphic expression ST expression DtToDateStruct Break Down Date Out:=DtToDateStruct(In, (@)DtToDateStruct and Time DateStruct); DateStruct Variables Name Meaning...
  • Page 646: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions The following example is for when In is DT#1970-1-2-12:34:56.999999999. abc:=DtToDateStruct(DT#1970-1-2-12:34:56.999999999); DtToDateStruct DT#1970-1-2-12:34:56.999999999 Broken down .Year DT#1970-1-2-12:34:56.999999999 Out=abc UINT#1970 Year .Month Month USINT#1 .Day USINT#2 Hour USINT#12 .Hour Minutes .Min USINT#34 Seconds .Sec USINT#56 .Nsec ULINT#999999999 Nanoseconds Related System-defined Variables Name Meaning Data type...
  • Page 647: Datestructtodt

    2 Instruction Descriptions DateStructToDt The DateStructToDt instruction joins a year, month, day, hour, minutes, seconds, and nanoseconds into a date and time. Instruction Name FB/FUN Graphic expression ST expression DateStructToDt Join Time Out:=DateStructToDt(In); (@)DateStructToDt Variables Name Meaning Description Valid range Unit Default Date and...
  • Page 648: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions The following example is for the following values for the members of In: Year is UINT#1970, Month is USINT#1, Day is USINT#2, Hour is USINT#12, Min is USINT#34, Sec is USINT#56, and Nsec is ULINT#999999999. def:=DateStructToDt(abc); DateStructToDt In=abc .Year Year...
  • Page 649: System Control Instructions

    System Control Instructions Instruction Name Page TraceSamp Data Trace Sampling 2-602 TraceTrig Data Trace Trigger 2-605 GetTraceStatus Read Data Trace Status 2-607 SetAlarm Create User-defined Error 2-610 ResetAlarm Reset User-defined Error 2-615 GetAlarm Get User-defined Error Status 2-617 ResetPLCError Reset PLC Controller Error 2-619 GetPLCError Get PLC Controller Error Status...
  • Page 650: Tracesamp

    2 Instruction Descriptions TraceSamp The TraceSamp instruction performs sampling for a data trace. Instruction Name FB/FUN Graphic expression ST expression TraceSamp Data Trace Sam- TraceSamp(TraceNo, Point); (@)TraceSamp pling TraceNo Point Variables Name Meaning Description Valid range Unit Default TraceNo Trace num- Trace number 0 to 3 Input...
  • Page 651: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions Related System-defined Variables Name Meaning Data type Description _PLC_TraceSta[0..3] Trace Information Trace information Refer to the NJ-series CPU Unit Software User's Manual (Cat. No. W501) for details. * _sTRACE_STA[] Additional Information • Refer to the NJ-series CPU Unit Software User’s Manual (Cat. No. W501) for details on data tracing. •...
  • Page 652: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions Sample Programming Here, sampling is performed at the end of each process A to D. The values of the variables are stored at each point. Process A TraceSamp USINT#0 TraceNo USINT#11 Point Process B TraceSamp USINT#1 TraceNo USINT#12 Point Process C...
  • Page 653: Tracetrig

    2 Instruction Descriptions TraceTrig The TraceTrig instruction generates a trigger for data tracing. Instruction Name FB/FUN Graphic expression ST expression TraceTrig Data Trace Trigger TraceTrig(TraceNo); (@)TraceTrig TraceNo Variables Name Meaning Description Valid range Unit Default TraceNo Trace num- Input Trace number 0 to 3 Return Output...
  • Page 654: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions Related System-defined Variables Name Meaning Data type Description _PLC_TraceSta[0..3] Trace Information Trace information Refer to the NJ-series CPU Unit Software User's Manual (Cat. No. W501) for details. * _sTRACE_STA[] Additional Information • Refer to the NJ-series CPU Unit Software User’s Manual (Cat. No. W501) for details on data tracing. •...
  • Page 655: Gettracestatus

    2 Instruction Descriptions GetTraceStatus The GetTraceStatus instruction reads the execution status of a data trace. Instruction Name FB/FUN Graphic expression ST expression GetTraceStatus Read Data Trace GetTraceStatus(TraceNo, (@)GetTraceStatus Status IsStart, IsComplete, ParamErr, IsTrigger); TraceNo IsStart IsComplete ParamErr IsTrigger Variables Name Meaning Description Valid range...
  • Page 656: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions Function The GetTraceStatus instruction reads the execution status of the data trace that is specified with trace number TraceNo. The status that is read is output to execution flag IsStart, completed flag IsComplete, parameter error flag ParamErr, and trigger flag IsTrigger. The value of ParamErr changes to TRUE when one of the following errors is found in the trace settings.
  • Page 657: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions Sample Programming In this sample, the GetTraceStatus instruction reads the execution status of the data trace with trace number 3. If the data trace is in progress, the TraceTrig instruction is executed to trigger data tracing. Comment Data type Initial value Variable StaFlag...
  • Page 658: Setalarm

    2 Instruction Descriptions SetAlarm The SetAlarm instruction creates a user-defined error. Instruction Name FB/FUN Graphic expression ST expression SetAlarm Create User- SetAlarm(Code, Info1, (@)SetAlarm defined Error Info2); Code Info1 Info2 Variables Name Meaning Description Valid range Unit Default Code Event code Event code of user-defined 1 to 40000 error to generate...
  • Page 659: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions Function The SetAlarm instruction generates the user-defined error that corresponds to event code Code. Event codes are defined in the event setting table on the Sysmac Studio. The time of occurrence, event name, event group, event code Code, event level, additional information Info1, additional information Info2, and detailed information are stored in the user event log area that corresponds to the level of the event code.
  • Page 660: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions • If a user-defined error for the same event code already exists, the new error is not recorded in the event log. • Always use variables for the input parameters that pass Info1 and Info2. If you use a constant, a building error will occur.
  • Page 661: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions When variable F changes to TRUE, the user-defined error is cleared. Internal Variable Data type Initial value Variables BOOL False BOOL False BOOL False BOOL False UINT UINT TON_instance0 TON_instance1 External Variable Data type Constant Comment Variables _AlarmFlag WORD Error Status of User-defined Errors Check the value of variable A.
  • Page 662: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions Internal Variable Data type Initial value Variables BOOL False BOOL False BOOL False BOOL False UINT UINT TON_instance0 TON_instance1 External Variable Data type Constant Comment Variables _AlarmFlag WORD Error Status of User-defined Errors // Check the value of variable A. IF (A=TRUE) THEN TON_instance0(In:=TRUE, PT:=T#5s, Q=>B);...
  • Page 663: Resetalarm

    2 Instruction Descriptions ResetAlarm The ResetAlarm instruction resets a user-defined error. Instruction Name FB/FUN Graphic expression ST expression ResetAlarm Reset User-defined ResetAlarm(Code); (@)ResetAlarm Error Code Variables Name Meaning Description Valid range Unit Default Code Event code Input Event code of user-defined Depends on data type.
  • Page 664: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions Related System-defined Variables Name Meaning Data type Description _AlarmFlag Error Status of User- WORD These flags indicate when user-defined errors defined Errors are detected. Bit 0 to bit 7 indicate the status of user-defined error levels 1 to 8. Refer to the NJ-series CPU Unit Software User's Manual (Cat.
  • Page 665: Getalarm

    2 Instruction Descriptions GetAlarm The GetAlarm instruction gets the highest event level (of user-defined error levels 1 to 8) and the high- est level event code of the current user-defined errors. Instruction Name FB/FUN Graphic expression ST expression GetAlarm Get User-defined Out:=GetAlarm(Level, (@)GetAlarm Error Status...
  • Page 666: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions The following figure shows a programming example. abc:=GetAlarm(def, ghi); GetAlarm Level Code Related System-defined Variables Name Meaning Data type Description _AlarmFlag Error Status of User- WORD These flags indicate when user-defined errors defined Errors are detected. Bit 0 to bit 7 indicate the status of user-defined error levels 1 to 8.
  • Page 667: Resetplcerror

    2 Instruction Descriptions ResetPLCError The ResetPLCError instruction resets errors in the PLC Function Module. Instruction Name FB/FUN Graphic expression ST expression ResetPLCError Reset PLC Control- ResetPLCError(Execute, ResetPLCError_instance ler Error Done, Busy, Error, ErrorID); ResetPLCError Execute Done Busy Error ErrorID Variables Only common variables are used.
  • Page 668: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions Variable Data type Initial value Comment OperatingEnd BOOL Processing completed False Execution condition Trigger BOOL False Processing Operating BOOL False RS_instance ResetPLCError_instance ResetPLCError Determine if execution of the ResetPLCError has ended. ResetPLCError_instance.Done OperatingEnd ResetPLCError_instance.Error Accept trigger. RS_instance Trigger Operating OperatingEnd...
  • Page 669: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions Data type Comment Variable Initial value Trigger BOOL Execution condition False LastTrigger Value of Trigger from previous task period BOOL False OperatingStart BOOL False Processing started Operating BOOL Processing False ResetPLCError_instance ResetPLCError // Detect when Trigger changes to TRUE. IF ( (Trigger=TRUE) AND (LastTrigger=FALSE) ) THEN OperatingStart:=TRUE;...
  • Page 670: Getplcerror

    2 Instruction Descriptions GetPLCError The GetPLCError instruction gets the highest level status (partial fault or minor fault) and highest level event code of the current Controller errors in the PLC Function Module. Instruction Name FB/FUN Graphic expression ST expression GetPLCError Get PLC Controller Out:=GetPLCError(Level, (@)GetPLCError...
  • Page 671: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions The following figure shows a programming example. abc:=GetPLCError(def, ghi); GetPLCError Level Code Related System-defined Variables Name Meaning Data type Description _PLC_ErrSta Error Status of PLC WORD Contains the error status of the PLC Func- Function Module tion Module. Refer to the NJ-series CPU Unit Software User's Manual (Cat.
  • Page 672: Resetcjberror

    2 Instruction Descriptions ResetCJBError The ResetCJBError instruction resets a Controller error in the I/O bus. Instruction Name FB/FUN Graphic expression ST expression ResetCJBError Reset I/O Bus Error FB ResetCJBError_instance( ResetCJBError_instance Execute, UnitNo, Done, ResetCJBError Busy, Error, ErrorID); Done UnitNo Busy Error ErrorID Variables...
  • Page 673: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions The following example is for when UnitNo is _CBU_No00. The Controller error on the I/O bus is reset and the CPU Bus Unit with unit number 0 is restarted. ResetCJBError_instance(A, _CBU_No00, abc, def, ghi, jkl); ResetCJBError_instance ResetCJBError Done _CBU_No00 UnitNo...
  • Page 674: Getcjberror

    2 Instruction Descriptions GetCJBError The GetCJBError instruction gets the highest level status (partial fault or minor fault) and highest level event code of the current Controller errors in the I/O bus. Instruction Name FB/FUN Graphic expression ST expression GetCJBError Get I/O Bus Error Out:=GetCJBError(Level, (@)GetCJBError Status...
  • Page 675: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions The following figure shows a programming example. abc:=GetCJBError(def, ghi); GetCJBError Level Code Related System-defined Variables Name Meaning Data type Description _CJB_ErrSta I/O Bus Error Status WORD Contains the error status of the I/O bus. Refer to the NJ-series CPU Unit Software User's Manual (Cat.
  • Page 676: Geteiperror

    2 Instruction Descriptions GetEIPError The GetEIPError instruction gets the highest level status (partial fault or minor fault) and highest level event code of the current Controller errors in the EtherNet/IP Function Module. Instruction Name FB/FUN Graphic expression ST expression GetEIPError Get EtherNet/IP Out:=GetEIPError(Level, (@)GetEIPError...
  • Page 677: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions The following figure shows a programming example. abc:=GetEIPError(def, ghi); GetEIPError Level Code Related System-defined Variables Name Meaning Data type Description _EIP_ErrSta Error Status of Ether- WORD Contains the error status of the EtherNet/IP Net/IP Function Mod- Function Module. Refer to the NJ-series CPU Unit Software User's Manual (Cat.
  • Page 678: Resetmcerror

    2 Instruction Descriptions ResetMCError The ResetMCError instruction resets Controller errors in the Motion Control Function Module. Instruction Name FB/FUN Graphic expression ST expression ResetMCError Reset Motion Con- ResetMCError_instance( ResetMCError_instance trol Error Execute, Done, Busy, ResetMCError Failure Error, ErrorID); Execute Done Busy Failure Error...
  • Page 679: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions Related System-defined Variables Name Meaning Data type Description _MC_ErrSta Motion Control Error WORD Contains the error status of the Motion Con- Status trol Function Module. Refer to the NJ-series CPU Unit Software User's Manual (Cat. No. W501) for details. Precautions for Correct Use •...
  • Page 680: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions Initial Comment Variable Data type value Request BOOL Error detection reset request False Resetting error in EtherCAT Master Function Module EC_Operating BOOL False Resetting error in Motion Control Function Module MC_Operating BOOL False Normal_End BOOL Normal end False ResetECError_instance ResetECError...
  • Page 681: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions Initial Data type Variable Comment value Request BOOL False Error detection reset request EC_Error BOOL False Error in EtherCAT Master Function Module EC_Stage Resetting error in EtherCAT Master Function Module MC_Error BOOL False Error in Motion Control Function Module MC_Stage Error reset in Motion Control Function Module ResetECError_instance...
  • Page 682: Getmcerror

    2 Instruction Descriptions GetMCError The GetMCError instruction gets the highest level status (partial fault or minor fault) and highest level event code of the current Controller errors in the Motion Control Function Module. Instruction Name FB/FUN Graphic expression ST expression GetMCError Get Motion Control Out:=GetMCError(Level,...
  • Page 683: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions The following figure shows a programming example. abc:=GetMCError(def, ghi); GetMCError Level Code Related System-defined Variables Name Meaning Data type Description _MC_ErrSta Error Status of Motion WORD Contains the error status of the Motion Con- Control Function Mod- trol Function Module.
  • Page 684: Resetecerror

    2 Instruction Descriptions ResetECError The ResetECError instruction resets a Controller error in the EtherCAT Master Function Module. Instruction Name FB/FUN Graphic expression ST expression ResetECError Reset EtherCAT ResetECError_instance( ResetECError_instance Controller Error Execute, Done, Busy, Error, ResetECError ErrorID); Execute Done Busy Error ErrorID Variables...
  • Page 685: Getecerror

    2 Instruction Descriptions GetECError The GetECError instruction gets the highest level status (partial fault or minor fault) and highest level event code of the current communications port errors or master errors in the EtherCAT Master Function Module. Instruction Name FB/FUN Graphic expression ST expression GetECError...
  • Page 686: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions Function The GetECError instruction gets the highest level status and highest level event code of the current communications port errors or master errors in the EtherCAT Master Function Module and outputs them to Level and Code. If there are currently no communications port errors or master errors, the value of error flag Out is FALSE.
  • Page 687: Setinfo

    2 Instruction Descriptions SetInfo The SetInfo instruction creates user-defined information. Instruction Name FB/FUN Graphic expression ST expression SetInfo Create User- SetInfo(Code, Info1, Info2); (@)SetInfo defined Information Code Info1 Info2 Variables Name Meaning Description Valid range Unit Default Code Event code Event code of user-defined 40001 to 60000 40001...
  • Page 688: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions Function The SetInfo instruction generates the user-defined information specified by event code Code. The time of occurrence, event code Code, event level, attached information Info1, and attached information Info2 are stored in the user event log area that corresponds to the level of the event code. The following figure shows a programming example.
  • Page 689: Resetunit

    2 Instruction Descriptions ResetUnit The ResetUnit instruction restarts a CPU Bus Unit or Special I/O Unit. Instruction Name FB/FUN Graphic expression ST expression ResetUnit Restart Unit ResetUnit_instance(Exe- ResetUnit_instance cute, UnitNo, Done, Busy, ResetUnit Error, ErrorID); Execute Done UnitNo Busy Error ErrorID Variables Name...
  • Page 690: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions Precautions for Correct Use • This instruction will not end in an error even if restart processing is in progress for the Unit specified by UnitNo. The value of Busy remains at TRUE and the value of Done changes to TRUE when restart processing is finished.
  • Page 691: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions Internal Variable Data type Initial value Comment Variables OperatingEnd BOOL Processing completed False Execution condition Trigger BOOL False Operating BOOL False Processing RS_instance ResetUnit_instance ResetUnit External Variable Comment Data type Variables SCU_P1_BaudrateCfg USINT Baud rate Determine if execution of the ResetUnit has ended. ResetUnit_instance.Done OperatingEnd ResetUnit_instance.Error...
  • Page 692: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions Internal Data type Initial value Comment Variable Variables Execution condition Trigger BOOL False Value of Trigger from previous task period LaseTrigger BOOL False Processing started OperatingStart BOOL False Processing Operating BOOL False ResetUnit_instance ResetUnit External Variable Data type Comment Variables SCU_P1_BaudrateCfg USINT Baud rate...
  • Page 693: Getntpstatus

    2 Instruction Descriptions GetNTPStatus The GetNTPStatus instruction reads the NTP status. Instruction Name FB/FUN Graphic expression ST expression GetNTPStatus Read NTP Status GetNTPStatus(ExecTime, (@)GetNTPStatus ExecNormal); ExecTime ExecNormal Variables Name Meaning Description Valid range Unit Default Return value Always TRUE TRUE only ExecTime NTP last normal NTP last normal opera-...
  • Page 694: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions Related System-defined Variables Name Meaning Data type Description _EIP_NTPResult NTP Status Contains the NTP status. Refer to the NJ-series CPU Unit Software User's Manual (Cat. No. W501) for details. * _sNTP_RESULT Precautions for Correct Use • Return value Out is not used when the instruction is used in ST. •...
  • Page 695: Communications Instructions

    Communications Instructions Instruction Name Page Instruction Name Page ExecPMCR Protocol Macro 2-648 EC_StopMon Stop EtherCAT Packet Monitor 2-740 SerialSend SCU Send Serial 2-658 EC_SaveMon Save EtherCAT Packets 2-742 SerialRcv SCU Receive Serial 2-665 EC_CopyMon Transfer EtherCAT Packets 2-744 SendCmd Send Command 2-674 EC_DisconnectSlave Disconnect EtherCAT Slave...
  • Page 696: Execpmcr

    2 Instruction Descriptions ExecPMCR The ExecPMCR instruction requests execution of a communications sequence (protocol data) regis- tered in a Serial Communications Unit (unit version 2.2 or later). Instruction Name Graphic expression ST expression ExecPMCR Protocol Macro ExecPMCR_instance(Execute, ExecPMCR_instance Port, SeqNo, SrcDat, DstDat, ExecPMCR Done, Busy, Error, ErrorID, Execute...
  • Page 697: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions Function The ExecPMCR instruction requests execution of the sequence that is specified with communications sequence number SeqNo from the specified destination port Port. If data is sent, it is sent from the second element (SrcDat[1]) of send data array SrcDat[]. The number of array elements to send is specified in SrcDat[0].
  • Page 698: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions Related System-defined Variables Name Meaning Data type Description _Port_numUsingPort Number of Used Ports USINT This is the number of ports that are currently used. _Port_isAvailable Network Communica- BOOL TRUE: A port is available. tions Instruction FALSE: A port is not available. Enabled Flag _CJB_SCU##P1ChgSta, Serial Communica-...
  • Page 699: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions • The Protocol Macro Execution Flag (semi-user-defined variable P#_PmrExecSta) changes to TRUE when instruction execution is started. It changes to FALSE after the communications sequence is completed and the receive data is stored in DstDat[]. You cannot execute this instruction for the same serial port while P#_PmrExecSta is TRUE.
  • Page 700: Nj-Series Instructions Reference Manual (W502

    In this sample, a CJ-series Serial Communications Unit is used for data communications with an OMRON Temperature Controller. The present value of the Temperature Controller is read with a proto- col macro. CompoWay/F master sequence 610 (Read Variable Area) is used. The contents of send data array SendData[] is sent from the Controller.
  • Page 701: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions The contents of send data SendData[] and receive data RecvData[] are as follows: Send Data: WORD Array Variable Item Contents Value SendData[0] Number of send data Five words from Send- WORD#16#0005 words Data[0] to SendData[4] are sent. SendData[1] Node number Node 3 is used.
  • Page 702: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions Internal Variable Data type Initial value Retain Comment specification Variables OperatingEnd BOOL Processing completed False Execution condition Trigger BOOL False Operating BOOL False Processing InPort _sPORT Port settings (UnitNo:=_CBU_No00, PhysicPortNo:=0) Send data SendData ARRAY[0..4] OF WORD [5(16#0)] RecvData ARRAY[0..3] OF WORD [4(16#0)]...
  • Page 703: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions Processing after normal end Inline ST SCU_P1_PmrSeqEndSta SCU_P1_PmrExecSta // Processing after normal end 2 TmpData:=DWORD_TO_DINT(SHL(WORD_TO_DWORD( RecvData[3]), 16) OR WORD_TO_DWORD(RecvData[2]) ); Processing after error end Inline ST ExecPMCR_instance.Error 1 // Processing after error end SCU_P1_PmrExecSta SCU_P1_PmrSeqAbtSta NJ-series Instructions Reference Manual (W502) 2-655...
  • Page 704: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions Internal Variable Data type Initial value Comment Retain specification Variables State Current state Trigger BOOL False Execution condition InPort _sPORT Port settings (UnitNo:=_CBU_No00, PhysicPortNo:=0) SendData ARRAY[0..4] OF WORD [5(16#0)] Send data RecvData ARRAY[0..3] OF WORD %D200 Receive data [4(16#0)] End_ExecPMCR BOOL...
  • Page 705: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions // Confirm completion of ExecPMCR instruction execution. IF (State=INT#3) THEN IF (SCU_P1_PmrSeqEndSta=TRUE) THEN State:=INT#4; END_IF; IF (SCU_P1_PmrSeqAbtSta=TRUE) THEN State:=INT#5; END_IF; END_IF; IF (State=INT#4) THEN // Processing after normal end. TmpData:=DWORD_TO_DINT(SHL(WORD_TO_DWORD(RecvData[3]), 16) OR WORD_TO_DWORD(RecvData[2])); State:=INT#0; END_IF; IF (State=INT#5) THEN // Processing after error end State:=INT#0;...
  • Page 706: Serialsend

    2 Instruction Descriptions SerialSend The SerialSend instruction sends data in No-protocol Mode from a serial port on a Serial Communica- tions Unit. Instruction Name Graphic expression ST expression SerialSend SCU Send SerialSend_instance(Execute, SerialSend_instance Serial Port, SrcDat, SendSize, Done, SerialSend Busy, Error, ErrorID, ErrorIDEx); Execute Done Port...
  • Page 707: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions Function The SerialSend instruction sends data in No-protocol Mode from the port and the Serial Communica- tions Unit specified with Port. The data that is sent is contained in send data array SrcDat[]. The number of array elements to send is specified in number of send data elements SendSize. To attach start and end codes to the send data, set them in the DM Area words that are assigned to the Special Unit.
  • Page 708: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions Related System-defined Variables Name Meaning Data type Description _Port_numUsingPort Number of Used Ports USINT This is the number of ports that are currently used. _Port_isAvailable Network Communica- BOOL TRUE: A port is available. tions Instruction FALSE: A port is not available. Enabled Flag Related Semi-user-defined Variables Name...
  • Page 709: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions • You cannot use this instruction in the primary periodic task. • An error occurs in the following cases. Error will change to TRUE. • The serial communications mode is not set to No-protocol Mode when the instruction is executed. •...
  • Page 710: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions Item Set value Port 2: No-Protocol End Code Port 2: No-Protocol Start Code Inclusion Setting Port 2: No-Protocol End Code Inclusion Setting Yes (Specify a desired end code.) The text string ‘@READ’ is separated into individual characters and the character codes are stored in the array elements of SendDat[].
  • Page 711: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions Internal Variable Data type Initial value Comment Variables OperatingEnd BOOL Processing completed False Trigger Execution condition BOOL False Processing Operating BOOL False InPort _sPORT Port settings (UnitNo:=_CBU_No00, PhysicPortNo:=0) SendDat Send data ARRAY[0..4] OF BYTE [5(16#0)] RS_instance SerialSend_instance SerialSend External Variable...
  • Page 712: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions Internal Variable Data type Initial value Comment Variables Trigger BOOL False Execution condition LastTrigger BOOL False Value of Trigger from previous task period OperatingStart BOOL False Processing started Operating BOOL False Processing InPort _sPORT (UnitNo:=_CBU_No00, PhysicPortNo:=0) Port settings SendDat ARRAY[0..4] OF BYTE [5(16#0)]...
  • Page 713: Serialrcv

    2 Instruction Descriptions SerialRcv The SerialRcv instruction receives data in No-protocol Mode from a serial port on a Serial Communica- tions Unit. Instruction Name Graphic expression ST expression SerialRcv SCU Receive SerialRcv_instance(Execute, Port, SerialRcv_instance Serial Size, DstDat, Done, Busy, Error, SerialRcv ErrorID, ErrorIDEx, RcvSize);...
  • Page 714: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions Function First, data is received in No-protocol Mode from the serial port specified with Port and stored in the receive buffer in the Serial Communications Unit. This instruction transfers the number of bytes speci- fied with receive data size Size from the receive buffer to receive data array DstDat[]. After the data is transferred, the number of array elements that was actually stored in DstDat[] is assigned to the number of receive data array elements RcvSize.
  • Page 715: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions The following figure shows a timing chart. TRUE Execute FALSE TRUE Busy FALSE TRUE Done FALSE TRUE Error FALSE DstDat[] Reception TRUE Completed FALSE Flag Received data it is stored in DstDat[]. Reception Completed Flag changes to FALSE. Data reception ended.
  • Page 716: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions Name Meaning Data type Description P#_NopRcvDatSzCfg* Number of No-protocol USINT 16#01 to 16#FF: 1 to 255 bytes Receive Data Bytes 16#00: 256 bytes P#_NopStartCodeCfg* No-protocol Start Code USINT 16#00 to 16#FF P#_NopEndCodeCfg* No-protocol End Code USINT 16#00 to 16#FF P#_TransErr* Transmission Error BOOL...
  • Page 717: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions • The instruction is executed only when there is an available port. Therefore, use the system-defined variable _Port_isAvailable (Network Communications Instruction Enabled Flag) in an N.O. execution condition for the instruction. • Execute the instruction only when the Reception Completed Flag (P#_NopRcvCompleteSta) is TRUE.
  • Page 718: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions The settings of Serial Communications Unit are given in the following table. Item Set value Port 2: User-specified Setting Inclusion User settings Port 2: Serial Communications Mode No-protocol Port 2: Data Length 8 bits Port 2: Stop Bits 1 bit Port 2: Parity Port 2: Baud Rate...
  • Page 719: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions Internal Variable Data type Initial value Comment Variables Processing completed OperatingEnd BOOL False Trigger BOOL Execution condition False Operating Processing BOOL False Port settings InPort _sPORT (UnitNo:=_CBU_No00, PhysicPortNo:=0) RecvDat ARRAY[0..12] OF BYTE Receive data [13(16#0)] RecvSize Receive data size UINT Barcode text string RecvStringDat...
  • Page 720: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions Processing after normal end Operating SerialRcv_instance.Done AryToString RecvDat[0] RecvStringDat RecvSize Size STRING_TO_ULINT RecvStringDat Code Inline ST 1 // Processing after normal end Processing after error end Inline ST SerialRcv_instance.Error Operating 1 // Processing after error end 2-672 NJ-series Instructions Reference Manual (W502)
  • Page 721: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions Internal Variable Data type Initial value Comment Variables Trigger Execution condition BOOL False LastTrigger Value of Trigger from previous task period BOOL False OperatingStart False Processing started BOOL Operating False Processing BOOL InPort (UnitNo:=_CBU_No00, PhysicPortNo:=0) Port settings _sPORT [13(16#0)] RecvDat...
  • Page 722: Sendcmd

    2 Instruction Descriptions SendCmd The SendCmd instruction uses a serial gateway and sends a command to a Serial Communications Unit. Or, it sends an explicit command to a DeviceNet Unit. Instruction Name Graphic expression ST expression SendCmd Send Com- SendCmd_instance(Execute, SendCmd_instance mand DstNetAdr, CommPort, CmdDat,...
  • Page 723: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions Function The SendCmd instruction sends the contents of command array CmdDat[] to the destination specified with destination network address DstNetAdr and destination serial port CommPort. The command data size CmdSize specifies how many elements of CmdDat[] contain the command. The response that is returned is stored in response storage array RespDat[].
  • Page 724: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions Related System-defined Variables Name Meaning Description _Port_numUsingPort Number of Used Ports This is the number of ports that are currently used. _Port_isAvailable Network Communica- TRUE: A port is available. tions Instruction FALSE: A port is not available. Enabled Flag Additional Information •...
  • Page 725: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions • For this instruction, expansion error code ErrorIDEx gives the communications response code. The values and meanings are listed in the following table. An expansion error code is output to ErrorIDEx when the value of error code ErrorID is WORD#16#0800. Value Error Correction...
  • Page 726: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions Sample Programming In this sample, the SendCmd instruction sends an explicit message via a DeviceNet Unit. This sample reads the vendor ID from the slave with node address 16#0B through the DeviceNet Unit with unit address 16#10. The following communications specifications are used.
  • Page 727: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions Response Storage Array: BYTE Array Array element Item Content RecvDat[0] The command code to send an explicit message is Command code 16#2801. RecvDat[1] RecvDat[2] Completion code The completion code is 16#0000 for a normal end. RecvDat[3] RecvDat[4] Number of bytes received after 4 bytes the slave node address...
  • Page 728: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions Internal Variable Data type Initial value Comment Variables OperatingEnd BOOL Processing completed False Trigger Execution condition BOOL False Processing Operating BOOL False InDNetAdr _sDNET_ADR Destination network address (NetNo:=0, NodeNo:=0, UnitNo:=16#0) InOption Response _sRESPONSE (isNonResp:=False, TimeOut:=0, Retry:=0) Send data SendDat ARRAY[0..8] OF BYTE [9(16#0)]...
  • Page 729: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions Processing after normal end Inline ST SendCmd_instance.Done Operating // Processing after normal end Processing after error end Inline ST Operating SendCmd_instance.Error 1 // Processing after error end NJ-series Instructions Reference Manual (W502) 2-681...
  • Page 730: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions Internal Variable Data type Initial value Comment Variables Trigger BOOL False Execution condition LastTrigger BOOL False Value of Trigger from previous task period OperatingStart BOOL False Processing started Operating BOOL False Processing InDNetAdr _sDNET_ADR (NetNo:=0, NodeNo:=0, UnitNo:=16#0) Destination network address InOption _sRESPONSE...
  • Page 731: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions // Execute SendCmd instruction. IF (Operating=TRUE) THEN SendCmd_instance( Execute :=TRUE, DstNetAdr:=InDNetAdr, CommPort:=_NONE, CmdDat :=SendDat[0], CmdSize :=UINT#9, RespDat:=RecvDat[0], Option :=InOption); IF (SendCmd_instance.Done=TRUE) THEN // Processing after normal end Operating:=FALSE; END_IF; IF (SendCmd_instance.Error=TRUE) THEN // Processing after error end Operating:=FALSE;...
  • Page 732: Cipopen

    2 Instruction Descriptions CIPOpen The CIPOpen instruction opens a CIP class 3 connection with the specified remote node. Instruction Name Graphic expression ST expression CIPOpen Open CIP CIPOpen_instance(Execute, CIPOpen_instance Class 3 Con- RoutePath, TimeOut, Done, Busy, CIPOpen nection Error, ErrorID, ErrorIDEx, Handle); Execute Done RoutePath...
  • Page 733: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions The following figure shows a programming example. CIPOpen_instance(A, ‘2\192.168.250.2’, UINT#0, abc, def, ghi, jkl, mno, pqr); CIPOpen_instance CIPOpen Execute Done RoutePath Busy ‘02\192.168.250.2’ UINT#0 TimeOut Error ErrorID ErrorIDEx Handle Related System-defined Variables Data Name Meaning Description type _EIP_EtnOnlineSta Online BOOL...
  • Page 734: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions Sample Programming This sample uses CIP class 3 messages to write a variable, read a variable, and send a message. The Controllers are connected to an EtherNet/IP network. The IP address of the remote node is 192.168.250.2. The following procedure is used.
  • Page 735: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions Variable Initial value Comment Data type OperatingEnd BOOL False Processing completed Trigger BOOL False Execution condition Operating BOOL False Processing WriteDat 1234 Write data ReadDat Read data ReqPath _sREQUEST_PATH (ClassID:=0, InstanceID:=0, isAttributeID:=False, AttributeID:=0) Request path ResDat ARRAY[0..10] OF BYTE [11(16#0)] Response data Dummy...
  • Page 736: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions Instruction execution CIPOpen_instance Operating CIPOpen Execute Done ‘02\192.168.250.2’ RoutePath Busy UINT#20 TimeOut Error ErrorID ErrorIDEx Handle CIPWrite_instance CIPOpen_instance.Done CIPWrite Execute Done CIPOpen_instance.Handle Handle Busy ‘WritingDat’ DstDat Error UINT#1 Size ErrorID WriteDat SrcDat ErrorIDEx CIPRead_instance CIPWrite_instance.Done CIPRead Execute Done CIPOpen_instance.Handle Handle...
  • Page 737: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions Processing after normal end Inline ST CIPClose_instance.Done Operating 1 // Processing after normal end Processing after error end Inline ST CIPOpen_instance.Error Operating 1 // Processing after error end CIPWrite_instance.Error CIPRead_instance.Error CIPSend_instance.Error CIPClose_instance.Error NJ-series Instructions Reference Manual (W502) 2-689...
  • Page 738: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions Internal Variable Initial value Comment Data type Variables BOOL False Execution condition Trigger False DoCIPTrigger BOOL Processing Stage Stage change Write data WriteDat ReadDat Read data (ClassID:=0, InstanceID:=0, ReqPath _sREQUEST_PATH Request path isAttributeID:=False, AttributeID:=0) [11(16#0)] ResDat ARRAY[0..10] OF BYTE Response data 16#0 Dummy...
  • Page 739: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions // Request reading value of variable. CIPRead_instance( Execute:=TRUE, Handle :=CIPOpen_instance.Handle, // Handle SrcDat :=’OriginalDat’, // Source variable name Size :=UINT#1, // Number of elements to read DstDat :=ReadDat); // Read data IF (CIPRead_instance.Done=TRUE) THEN Stage:=INT#4; // Normal end ELSIF (CIPRead_instance.Error=TRUE) THEN Stage:=INT#30;...
  • Page 740: Cipread

    2 Instruction Descriptions CIPRead The CIPRead instruction uses a class 3 explicit message to read the value of a variable in another Con- troller on a CIP network. Instruction Name Graphic expression ST expression CIPRead Read Variable CIPRead_instance(Execute, CIPRead_instance Class 3 Explicit Handle, SrcDat, Size, DstDat, CIPRead Done, Busy, Error, ErrorID,...
  • Page 741: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions Function The CIPRead instruction reads the value of the network variable specified with source variable name SrcDat from another Controller on a CIP network. The other Controller is specified with Handle. The read data value is stored in DstDat. Size specifies the number of elements to read.
  • Page 742: Nj-Series Instructions Reference Manual (W502

    • This instruction can be used only through the built-in EtherNet/IP ports on NJ-series CPU Units. • If a variable is read from an OMRON Controller, the variable must be published to the network. Pub- lish the variable to the network in advance.
  • Page 743: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions • The value of RcvSize is outside of the valid range. • For this instruction, expansion error code ErrorIDEx gives the CIP message error code. The meanings are as follows: Value Error 16#02000000 Normal communications are not possible due to a high load at the remote node. 16#05000000 The specified source variable does not exits on the other Controller.
  • Page 744: Cipwrite

    2 Instruction Descriptions CIPWrite The CIPWrite instruction uses a class 3 explicit message to write the value of a variable in another Con- troller on a CIP network. Instruction Name Graphic expression ST expression CIPWrite Write Variable CIPWrite_instance(Execute, CIPWrite_instance Class 3 Explicit Handle, DstDat, Size, SrcDat, CIPWrite Done, Busy, Error, ErrorID,...
  • Page 745: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions The data type of Handle is structure _sCIP_HANDLE. The specifications are as follows: Name Meaning Description Data type Valid range Unit Default Handle Handle Handle _sCIP_ HANDLE Handle Handle Handle UDINT Depends on data type. If the value of ErrorID is WORD#16#1C00, the CIP message error code is stored in ErrorIDEx. The following example writes variable abc.
  • Page 746: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions Item in above formula Meaning Size of variable name of • The size of the variable name is calculated as the total bytes for the ASCII charac- DstDat ters in all structure levels plus two times the number of levels. •...
  • Page 747: Nj-Series Instructions Reference Manual (W502

    • You can use this instruction only through a built-in EtherNet/IP port on an NJ-series CPU Unit or a port on an EtherNet/IP Unit connected to an NJ-series CPU Unit. • If a variable is written to an OMRON Controller, the variable must be published to the network. Pub- lish the variable to the network in advance.
  • Page 748: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions Sample Programming Refer to the sample programming that is provided for the CIPOpen instruction (page 2-684). 2-700 NJ-series Instructions Reference Manual (W502)
  • Page 749: Cipsend

    2 Instruction Descriptions CIPSend The CIPSend instruction sends a class 3 CIP message to a specified device on a CIP network. Instruction Name Graphic expression ST expression CIPSend Send Explicit CIPSend_instance(Execute, CIPSend_instance Message Class Handle, ServiceCode, RqPath, CIPSend ServiceDat, Size, RespService- Execute Done Dat, Done, Busy, Error, ErrorID,...
  • Page 750: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions Times, durations, Bit strings Integers dates, and text strings Handle Refer to Function for details on the structure _sCIP_HANDLE. ServiceCode RqPath Refer to Function for details on the structure _sREQUEST_PATH. ServiceDat OK OK OK OK OK OK OK OK OK OK OK OK OK OK An array, structure member, or union member can also be specified.
  • Page 751: Nj-Series Instructions Reference Manual (W502

    • You can use this instruction only through a built-in EtherNet/IP port on an NJ-series CPU Unit or a port on an EtherNet/IP Unit connected to an NJ-series CPU Unit. • If a variable is written to an OMRON Controller, the variable must be published to the network. Pub- lish the variable to the network in advance.
  • Page 752: Cipclose

    2 Instruction Descriptions CIPClose The CIPClose instruction closes the CIP class 3 connection to the specified handle. Instruction Name Graphic expression ST expression CIPClose Close CIP CIPClose_instance(Execute, CIPClose_instance Class 3 Con- Handle, Done, Busy, Error, CIPClose nection ErrorID, ErrorIDEx); Execute Done Handle Busy...
  • Page 753: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions Related System-defined Variables Data Name Meaning Description type _EIP_EtnOnlineSta Online BOOL Status of built-in EtherNet/IP port communications TRUE: Can be used. FALSE: Cannot be used. Additional Information Refer to the following manuals for details on CIP communications. •...
  • Page 754: Cipucmmread

    2 Instruction Descriptions CIPUCMMRead The CIPUCMMRead instruction uses a UCMM explicit message to read the value of a variable in another Controller on the specified CIP network. Instruction Name Graphic expression ST expression CIPUCMM Read Variable CIPUCMMRead_instance(Execute, CIPUCMMRead_instance Read UCMM Explicit RoutePath, TimeOut, SrcDat, Size, CIPUCMMRead DstDat, Done, Busy, Error, ErrorID,...
  • Page 755: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions Function The CIPUCMMRead instruction reads the value of the network variable specified with source variable name SrcDat from another Controller on a CIP network. The other Controller is specified with route path RoutePath. The read data value is stored in DstDat. Size specifies the number of elements to read.
  • Page 756: Nj-Series Instructions Reference Manual (W502

    • This instruction can be used only through the built-in EtherNet/IP ports on NJ-series CPU Units. • If a variable is read from an OMRON Controller, the variable must be published to the network. Pub- lish the variable to the network in advance.
  • Page 757: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions • The value of Size is outside of the valid range. • The value of DstDat is outside of the valid range. • The value of RcvSize is outside of the valid range. • For this instruction, expansion error code ErrorIDEx gives the CIP message error code. The mean- ings are as follows: Value Error...
  • Page 758: Cipucmmwrite

    2 Instruction Descriptions CIPUCMMWrite The CIPUCMMWrite instruction uses a UCMM explicit message to write the value of a variable in another Controller on a CIP network. Instruction Name Graphic expression ST expression CIPUCMM Write Variable CIPUCMMWrite_instance(Execute, CIPUCMMWrite_instance Write UCMM Explicit RoutePath, TimeOut, DstDat, Size, CIPUCMMWrite SrcDat, Done, Busy, Error, ErrorID,...
  • Page 759: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions Function The CIPUCMMWrite instruction writes the value of the network variable specified with destination vari- able name DstDat at another Controller on a CIP network. The other Controller is specified with route path RoutePath. The content of source data ScrDat is written. Size specifies the number of elements to write.
  • Page 760: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions Item in above formula Meaning Size of variable name of DstDat • The size of the variable name is calculated as the total bytes for the ASCII characters in all structure levels plus two times the number of levels. •...
  • Page 761: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions Item in above formula Meaning Path information size • If there are no hops, the path information size is 0 bytes.* • If there are hops, the path information size is the route path size plus 12 bytes.
  • Page 762: Nj-Series Instructions Reference Manual (W502

    • You can use this instruction only through a built-in EtherNet/IP port on an NJ-series CPU Unit or a port on an EtherNet/IP Unit connected to an NJ-series CPU Unit. • If a variable is written to an OMRON Controller, the variable must be published to the network. Pub- lish the variable to the network in advance.
  • Page 763: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions Value Error 16#20008028 • The specified destination variable is an enumeration and the write data is not the value of an enumerator. • The specified destination variable has a Range Specification attribute and the write data is out of range.
  • Page 764: Cipucmmsend

    2 Instruction Descriptions CIPUCMMSend The CIPUCMMSend instruction sends a UCMM CIP message to a specified device on a CIP network. Instruction Name Graphic expression ST expression CIPUCMM Send Explicit CIPUCMMSend_instance(Execute, CIPUCMMSend_instance Send Message RoutePath, TimeOut, ServiceCode, CIPUCMMSend UCMM RqPath, ServiceDat, Size, Execute Done RespServiceDat, Done, Busy, Error,...
  • Page 765: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions Times, durations, Bit strings Integers dates, and text strings OK OK OK OK OK OK OK OK OK OK OK OK OK OK RespSer- viceDat An array, structure member, or union member can also be specified. RespSize Function The CIPUCMMSend instruction sends command data ServiceDat for the service specified with service code ServiceCode as a UCMM explicit message.
  • Page 766: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions Item in above formula Meaning Path information size • If there are no hops, the path information size is 0 bytes.* • If there are hops, the path information size is the route path size plus 12 bytes.
  • Page 767: Nj-Series Instructions Reference Manual (W502

    • You can use this instruction only through a built-in EtherNet/IP port on an NJ-series CPU Unit or a port on an EtherNet/IP Unit connected to an NJ-series CPU Unit. • If a variable is written to an OMRON Controller, the variable must be published to the network. Pub- lish the variable to the network in advance.
  • Page 768: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions IP address: 192.168.250.2 Built-in EtherNet/IP port Built-in EtherNet/IP port Variable name: WritingDat, Value of variable written. WriteDat global variable with a Network Publish attribute Variable name: OriginalDat, Value of variable read. global variable with a ReadDat Network Publish attribute Message sent to read identity information (product name).
  • Page 769: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions Comment Variable Data type Initial value Processing completed OperatingEnd BOOL False Trigger BOOL Execution condition False Operating Processing BOOL False Write data WriteDat 1234 ReadDat Read data ReqPath Request path _sREQUEST_PATH (ClassID:=0, InstanceID:=0, isAttributeID:=False, AttributeID:=0) ResDat ARRAY[0..10] OF BYTE Response data [11(16#0)] Dummy...
  • Page 770: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions Instruction execution CIPUCMMWrite_instance Operating CIPUCMMWrite Execute Done ‘02\192.168.250.2’ RoutePath Busy UINT#20 TimeOut Error ‘WritingDat’ DstDat ErrorID UINT#1 Size ErrorIDEx WriteDat SrcDat CIPUCMMRead_instance CIPUCMMWrite_instance.Done CIPUCMMRead Execute Done RoutePath Busy ‘02\192.168.250.2’ TimeOut Error UINT#20 SrcDat ErrorID ‘OriginalDat’ Size ErrorIDEx UINT#1 DstDat ReadDat...
  • Page 771: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions Processing after normal end Inline ST Operating CIPUCMMSend_instance.Done 1 // Processing after normal end Processing after error end Inline ST CIPUCMMWrite_instance.Error Operating 1 // Processing after error end CIPUCMMRead_instance.Error CIPUCMMSend_instance.Error NJ-series Instructions Reference Manual (W502) 2-723...
  • Page 772: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions Internal Variable Data type Initial value Comment Variables BOOL False Execution condition Trigger False Processing DoUCMMTrigger BOOL Stage Stage change Write data WriteDat Read data ReadDat (ClassID:=0, InstanceID:=0, ReqPath _sREQUEST_PATH Request path isAttributeID:=False, AttributeID:=0) [11(16#0)] Response data ResDat ARRAY[0..10] OF BYTE 16#0...
  • Page 773: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions // Send message ReqPath.ClassID :=UINT#01; ReqPath.InstanceID :=UINT#01; ReqPath.isAttributeID:=TRUE; ReqPath.AttributeID :=UINT#07; CIPUCMMSend_instance( Execute :=TRUE, // Route path RoutePath :='02\192.168.250.2', // Timeout time TimeOut :=UINT#20, // Service code ServiceCode :=BYTE#16#0E, // Request path RqPath :=ReqPath, // Service data ServiceDat := Dummy, // Number of elements Size...
  • Page 774: Ec_Coesdowrite

    2 Instruction Descriptions EC_CoESDOWrite The EC_CoESDOWrite instruction writes a value to a CoE* object of a specified slave on an EtherCAT network. Instruction Name Graphic expression ST expression EC_CoESDO Write Ether- EC_CoESDOWrite_instance(Execute, EC_CoESDOWrite_instance Write CAT CoE SDO NodeAdr, SdoObj, TimeOut, WriteDat, EC_CoESDOWrite WriteSize, Done, Busy, Error, ErrorID, Execute...
  • Page 775 2 Instruction Descriptions Function The EC_CoESDOWrite instruction writes data to the CoE object of the node specified with slave node address NodeAdr. The content of WriteDat is written to the object. The number of bytes of data to write is specified with WriteSize. The SDO parameter is specified with SdoObj. The data type of SdoObj is structure _sSDO_ACCESS.
  • Page 776: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions Precautions for Correct Use • Execution of this instruction is continued until processing is completed even if the value of Execute changes to FALSE or the execution time exceeds the task period. The value of Done changes to TRUE when processing is completed.
  • Page 777: Ec_Coesdoread

    2 Instruction Descriptions EC_CoESDORead The EC_CoESDORead instruction reads a value from a CoE* object of a specified slave on an Ether- CAT network. Instruction Name Graphic expression ST expression EC_CoESDOR Read EtherCAT EC_CoESDORead_instance(Execute, EC_CoESDORead_instance CoE SDO NodeAdr, SdoObj, TimeOut, ReadDat, EC_CoESDORead Done, Busy, Error, ErrorID, AbortCode, Execute...
  • Page 778 2 Instruction Descriptions Function The EC_CoESDORead instruction reads data from the CoE object of the node specified with slave node address NodeAdr. The read data is stored in ReadDat. Then size of data that was stored is stored in ReadSize. The value of ReadSize is valid only when the data was stored successfully. The SDO parameter is specified with SdoObj.
  • Page 779 • The read data size is larger than the size of ReadDat. Sample Programming This sample uses an EtherCAT SDO message to read the software version of an OMRON V1.02 R88D- KN01L-ECT Servo Drive. The node address of the slave is 1.
  • Page 780 2 Instruction Descriptions Internal Variable Data type Initial value Comment Variables Execution condition Trigger BOOL False SdoObject _sSDO_ACCESS (Index:=0, Subindex:=0, SDO parameter IsCompleteAccess:=False) Read data VersionInfo STRING[256] ‘’ EC_CoESDORead_instance EC_CoESDORead External Variable Data type Comment Constant Variables _EC_MBXSlavTbl ARRAY[1..192] OF BOOL Message Communications Enabled Slave Table Accept trigger.
  • Page 781 2 Instruction Descriptions Internal Variable Data type Initial value Comment Variables Trigger BOOL False Execution condition SdoObject _sSDO_ACCESS (Index:=0, Subindex:=0, SDO parameter IsCompleteAccess:=False) DoSdoRead BOOL False Processing VersionInfo STRING[256] ‘’ Read data NormalEnd UINT Normal end ErrorEnd Error end UINT EC_CoESDORead_instance EC_CoESDORead External...
  • Page 782: Ec_Startmon

    2 Instruction Descriptions EC_StartMon The EC_StartMon instruction starts execution of packet monitoring for EtherCAT communications. Instruction Name Graphic expression ST expression EC_StartMon Start EtherCAT EC_SatrtMon_instance(Execute, Done, EC_StartMon_instance Packet Monitor Busy, Error, ErrorID); EC_StartMon Execute Done Busy Error ErrorID Variables Only common variables are used. Function The EC_StartMon instruction starts execution of packet monitoring for EtherCAT communications.
  • Page 783: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions Precautions for Correct Use • Execution of this instruction is continued until processing is completed even if the value of Execute changes to FALSE or the execution time exceeds the task period. The value of Done changes to TRUE when processing is completed.
  • Page 784: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions Internal Variable Data type Initial value Comment Variables Processing completed OperatingEnd BOOL False Execution condition Operating BOOL False RS_instance EC_StopMon_instance EC_StopMon EC_SaveMon_instance EC_SaveMon EC_CopyMon_instance EC_CopyMon EC_StartMon_instance EC_StartMon External Variable Data type Constant Comment Variables _EC_ErrSta WORD Built-in EtherCAT Error _EC_PktMonStop BOOL Packet Monitoring Stopped...
  • Page 785: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions Instruction execution EC_StopMon_instance EC_SaveMon_instance Operating _Card1Ready EC_StopMon EC_SaveMon Execute Done Execute Done Busy Busy Error Error ErrorID ErrorID EC_CopyMon_instance EC_StartMon_instance EC_CopyMon EC_StartMon Execute Done Execute Done ‘PacketFile’ FileName Busy Busy Error Error ErrorID ErrorID Processing after normal end Inline ST Operating 1 // Processing after normal end...
  • Page 786: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions Internal Variable Data type Initial value Comment Variables Controller error in the EtherCAT Master Function Module. EC_Err BOOL False Detect when EC_Err changes to TRUE. EC_Err_Trigger BOOL False Processing DoEC_PktSave BOOL False Stage change Stage R_TRIG_instance R_TRIG EC_StopMon_instance EC_StopMon EC_SaveMon_instance...
  • Page 787: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions // Restart EtherCAT packet monitor. EC_StartMon_instance( Execute :=TRUE); IF (EC_StartMon_instance.Done=TRUE) THEN Stage:=INT#0; // Normal end ELSIF (EC_StartMon_instance.Error=TRUE) THEN Stage:=INT#40; // Error end END_IF; // Processing after normal end DoEC_PktSave:=FALSE; // Processing after error end ELSE DoEC_PktSave:=FALSE; END_CASE; END_IF;...
  • Page 788: Ec_Stopmon

    2 Instruction Descriptions EC_StopMon The EC_StopMon instruction stops execution of packet monitoring for EtherCAT communications. Instruction Name Graphic expression ST expression EC_StopMon Stop EtherCAT EC_StopMon_instance(Execute, EC_StopMon_instance Packet Monitor Done, Busy, Error, ErrorID); EC_StopMon Execute Done Busy Error ErrorID Variables Only common variables are used. Function The EC_StopMon instruction stops execution of packet monitoring for EtherCAT communications.
  • Page 789: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions • An error occurs in the following case. Error will change to TRUE. • Packet monitoring is already stopped. Sample Programming Refer to the sample programming that is provided for the EC_StartMon instruction (page 2-734). NJ-series Instructions Reference Manual (W502) 2-741...
  • Page 790: Ec_Savemon

    2 Instruction Descriptions EC_SaveMon The EC_SaveMon instruction saves EtherCAT communications packet data to an internal file in the main memory of the CPU Unit. Instruction Name Graphic expression ST expression EC_SaveMon Save Ether- EC_SaveMon_instance(Execute, EC_SaveMon_instance CAT Packets Done, Busy, Error, ErrorID); EC_SaveMon Execute Done...
  • Page 791: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions • You cannot execute this instruction while packet monitoring is in progress. Execute the EC_StopMon instruction in advance to stop packet monitoring. • An error occurs in the following case. Error will change to TRUE. • Packet monitoring is in progress. Sample Programming Refer to the sample programming that is provided for the EC_StartMon instruction (page 2-734).
  • Page 792: Ec_Copymon

    2 Instruction Descriptions EC_CopyMon The EC_CopyMon instruction transfers packet data in an internal file in the main memory of the CPU Unit to a SD Memory Card. Instruction Name Graphic expression ST expression EC_CopyMon Transfer Ether- EC_CopyMon_instance(Execute, File- EC_CopyMon_instance CAT Packets Name, Done, Busy, Error, ErrorID);...
  • Page 793: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions Precautions for Correct Use • Execution of this instruction is continued until processing is completed even if the value of Execute changes to FALSE or the execution time exceeds the task period. The value of Done changes to TRUE when processing is completed.
  • Page 794: Ec_Disconnectslave

    2 Instruction Descriptions EC_DisconnectSlave The EC_DisconnectSlave instruction disconnects the specified slave from the network. Instruction Name Graphic expression ST expression EC_Disconnect Disconnect EC_DisconnectSlave_instance(Execute, EC_DisconnectSlave_instance Slave EtherCAT NodeAdr, Done, Busy, Error, ErrorID); EC_DisconnectSlave Slave Execute Done NodeAdr Busy Error ErrorID Variables Name Meaning Description...
  • Page 795: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions Additional Information Refer to the NJ-series CPU Unit Built-in EtherCAT Port User’s Manual (Cat. No. W505) for details on EtherCAT communications. Precautions for Correct Use • Execution of this instruction is continued until processing is completed even if the value of Execute changes to FALSE or the execution time exceeds the task period.
  • Page 796: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions Internal Variable Data type Initial value Comment Variables Operating1End BOOL False Processing 1 completed. Trigger1 BOOL False Execution condition 1 Operating1 BOOL False Processing 1 RS_instance1 EC_DisconnectSlave_instance EC_DisconnectSlave Operating2End BOOL False Processing 1 completed. Trigger2 BOOL False Execution condition 2 Operating2 BOOL...
  • Page 797: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions Accept trigger 2. RS_instance2 Trigger2 _EC_DisconnSlavTbl[1] Operating2 Operating2End Reset1 Execute EC_ConnectSlave instruction. EC_ConnectSlave_instance Operating2 EC_ConnectSlave Execute Done UINT#1 NodeAdr Busy Error ErrorID Processing after normal end Inline ST Operating2 EC_ConnectSlave_instance.Done 1 // Processing after normal end Processing after error end Inline ST EC_ConnectSlave_instance.Error Operating2...
  • Page 798: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions Internal Variable Data type Initial value Comment Variables Trigger1 Execution condition 1 BOOL False LastTrigger1 Value of Trigger1 from previous task period BOOL False Operating1Start Processing 1 started. BOOL False Operating1 Processing 1 BOOL False EC_DisconnectSlave_instance EC_DisconnectSlave Trigger2 Execution condition 2 BOOL...
  • Page 799: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions // Execute EC_ConnectSlave instruction. IF (Operating2=TRUE) THEN EC_ConnectSlave_instance( Execute :=TRUE, NodeAdr:=UINT#1); IF (EC_ConnectSlave_instance.Done=TRUE) THEN // Processing after normal end Operating2:=FALSE; END_IF; IF (EC_ConnectSlave_instance.Error=TRUE) THEN // Processing after error end Operating2:=FALSE; END_IF; END_IF; NJ-series Instructions Reference Manual (W502) 2-751...
  • Page 800: Ec_Connectslave

    2 Instruction Descriptions EC_ConnectSlave The EC_ConnectSlave instruction connects the specified slave to the EtherCAT network. Instruction Name Graphic expression ST expression EC_ConnectSl Connect Ether- EC_ConnectSlave_instance(Execute, EC_ConnectSlave_instance CAT Slave NodeAdr, Done, Busy, Error, ErrorID); EC_ConnectSlave Execute Done NodeAdr Busy Error ErrorID Variables Name Meaning...
  • Page 801: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions Precautions for Correct Use • Execution of this instruction is continued until processing is completed even if the value of Execute changes to FALSE or the execution time exceeds the task period. The value of Done changes to TRUE when processing is completed.
  • Page 802: Sktudpcreate

    2 Instruction Descriptions SktUDPCreate The SktUDPCreate instruction creates a UDP socket request to open a servo port for the built-in Ether- Net/IP. Instruction Name Graphic expression ST expression SktUDP Create Create UDP None SktUDPCreate_instance(Execute, Socket SrcUdpPort, Done, Busy, Error, ErrorID, Socket); Variables Name Meaning...
  • Page 803: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions The data type of Socket is structure _sSOCKET. The specifications are as follows: Name Meaning Description Data type Valid range Unit Default Socket Socket Socket _sSOCKET Handle Handle Handle for data commu- UDINT Depends on nications data type. SrcAdr* Local address Local IP address and _sSOCKET_...
  • Page 804: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions • The port that is specified with ScrUdpPort is already in use. Sample Programming In this sample, the UDP socket service is used for data communications between the NJ-series Control- ler and a remote node. IP address: 192.168.250.1 IP address: 192.168.250.2 UDP port number: 6000 UDP port number: 6001...
  • Page 805: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions Internal Variable Data type Initial value Comment Variables Trigger BOOL Execution condition False Processing DoSendAndRcv BOOL False Stage change Stage RcvSocketDat ARRAY[0..1999] OF BYTE Receive data [2000(16#0)] Socket WkSocket _sSOCKET (Handle:=0, SrcAdr:=(PortNo:=0, IpAdr:=’’), DstAdr:=(PortNo:=0, IpAdr:=’’)) SendSocketDat ARRAY[0..1999] OF BYTE Send data [2000(16#0)] SktUDPCreate_instance...
  • Page 806: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions // Request receiving data. SktUDPRcv_instance( Execute :=TRUE, Socket :=WkSocket, // Socket TimeOut:=UINT#0, // Timeout time Size :=UINT#2000, // Receive data size RcvDat :=RcvSocketDat[0]); // Receive data IF (SktUDPRcv_instance.Done=TRUE) THEN Stage:=INT#4; // Normal end ELSIF (SktUDPRcv_instance.Error=TRUE) THEN Stage:=INT#30; // Error end END_IF;...
  • Page 807: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions Internal Variable Data type Initial value Comment Variables Trigger BOOL False Execution condition DoSendAndRcv BOOL False Processing Stage Stage change RcvSocketDat ARRAY[0..1999] OF BYTE [2000(16#0)] Receive data WkSocket _sSOCKET (Handle:=0, SrcAdr:=(PortNo:=0, Socket IpAdr:=’’), DstAdr:=(PortNo:=0, IpAdr:=’’)) SendSocketDat ARRAY[0..1999] OF BYTE [2000(16#0)] Send data SktUDPCreate_instance...
  • Page 808: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions // Request sending data. SendSocketDat:=RcvSocketDat; SktUDPSend_instance( Execute :=TRUE, Socket :=WkSocket, // Socket // Send data SendDat:=SendSocketDat[0], Size :=UINT#2000); // Send data size IF (SktUDPSend_instance.Done=TRUE) THEN Stage:=INT#4; // Normal end ELSIF (SktUDPSend_instance.Error=TRUE) THEN // Error end Stage:=INT#30; END_IF; // Request closing.
  • Page 809: Sktudprcv

    2 Instruction Descriptions SktUDPRcv The SktUDPRcv instruction reads the data from the receive buffer for a UDP socket for the built-in Eth- erNet/IP. Instruction Name Graphic expression ST expression SktUDPRcv UDP Socket None SktUDPRcv_instance(Execute, Receive Socket, TimeOut, Size, RcvDat, Done, Busy, Error, ErrorID, RcvSize, SendNodeAdr);...
  • Page 810: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions The data type of Socket is structure _sSOCKET. The specifications are as follows: Name Meaning Description Data type Valid range Unit Default Socket Socket Socket _sSOCKET Handle Handle Handle for data commu- UDINT Depends on nications data type. SrcAdr* Local address Local IP address and _sSOCKET_...
  • Page 811: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions • If the size of data that was received by the specified socket is smaller than the value of Size, then all of the received data is stored in RecDat[]. Then size of data that was stored is stored in RcvSize. •...
  • Page 812: Sktudpsend

    2 Instruction Descriptions SktUDPSend The SktUDPSend instruction sends data from a UDP port for the built-in EtherNet/IP. Instruction Name Graphic expression ST expression SktUDPSend UDP Socket None SktUDPSend_instance(Execute, Send Socket, SendDat, Size, Done, Busy, Error, ErrorID); Variables Name Meaning Description Valid range Unit Default...
  • Page 813: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions The data type of Socket is structure _sSOCKET. The specifications are as follows: Name Meaning Description Data type Valid range Unit Default Socket Socket Socket _sSOCKET Handle Handle Handle for data commu- UDINT Depends on nications data type. SrcAdr* Local address Local IP address and _sSOCKET_...
  • Page 814: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions • Data transmission is in progress for the socket specified with Socket. • The socket specified with Socket is not open. • The remote node for Socket was specified with a domain name and address resolution failed. •...
  • Page 815: Skttcpaccept

    2 Instruction Descriptions SktTCPAccept The SktTCPAccept instruction requests accepting a TCP socket for the built-in EtherNet/IP. Instruction Name Graphic expression ST expression SktTCPAccept Accept TCP None SktTCPAccept_instance(Execute, Socket SrcTcpPort, TimeOut, Done, Busy, Error, ErrorID, Socket); Variables Name Meaning Description Valid range Unit Default SrcTcpPort...
  • Page 816: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions The data type of Socket is structure _sSOCKET. The specifications are as follows: Name Meaning Description Data type Valid range Unit Default Socket Socket Socket _sSOCKET Handle Handle Handle for data commu- UDINT Depends on nications data type. SrcAdr* Local address Local IP address and _sSOCKET_...
  • Page 817: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions • The value of SrcTcpPort is outside of the valid range. • Open processing is in progress for the socket specified with SrcTcpPort. • Close processing is in progress for the socket specified with SrcTcpPort. • A connection is not opened within the time that is specified with TimeOut. Sample Programming Refer to the sample programming that is provided for the SktTCPConnect instruction (page 2-770).
  • Page 818: Skttcpconnect

    2 Instruction Descriptions SktTCPConnect The SktTCPConnect instruction connects to a remote TCP port from the built-in EtherNet/IP. Instruction Name Graphic expression ST expression SktTCP Connect TCP None SktTCPConnect_instance(Execute, Connect Socket SrcTcpPort, DstAdr, DstTcpPort, Done, Busy, Error, ErrorID, Socket); Variables Name Meaning Description Valid range...
  • Page 819: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions Function The SktTCPConnect instruction requests a connection between local TCP port number SrcTcpPort and destination TCP port number DstTcpPort at destination address DstAdr. To do this, it executes the Con- nect() socket function. The connection is established when the instruction is completed normally (i.e., when the value of Done changes to TRUE).
  • Page 820: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions • You can execute a maximum of 32 of the following instructions at the same time: SktUDPCreate, SktUDPRcv, SktUDPSend, SktTCPAccept, SktTCPConnect, SktTCPRcv, SktTCPSend, SktGetTCP- Status, SktClose, and SktClearBuf. • You can open a maximum of 16 sockets combined for UDP and TCP sockets. •...
  • Page 821: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions Internal Variable Data type Initial value Comment Variables Trigger BOOL Execution condition False Processing DoTCP BOOL False Stage change Stage RcvSocketDat ARRAY[0..1999] OF BYTE Receive data [2000(16#0)] Socket WkSocket _sSOCKET (Handle:=0, SrcAdr:=(PortNo:=0, IpAdr:=’’), DstAdr:=(PortNo:=0, IpAdr:=’’)) SendSocketDat ARRAY[0..1999] OF BYTE Send data [2000(16#0)] SktTCPConnect_instance...
  • Page 822: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions // Request reading status. SktGetTCPStatus_instance( Execute:=TRUE, Socket :=WkSocket); // Socket IF (SktGetTCPStatus_instance.Done=TRUE) THEN Stage:=INT#4; // Normal end ELSIF (SktGetTCPStatus_instance.Error=TRUE) THEN Stage:=INT#30; // Error end END_IF; // Request sending data SktTCPSend_instance( Execute :=TRUE, Socket :=WkSocket, // Socket SendDat:=SendSocketDat[0], // Send data Size :=UINT#2000);...
  • Page 823: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions The SktClose instruction is used to close the socket. Internal Variable Data type Initial value Comment Variables Trigger BOOL Execution condition False Processing DoTCP BOOL False Stage Stage change RcvSocketDat ARRAY[0..1999] OF BYTE Receive data [2000(16#0)] Socket WkSocket _sSOCKET (Handle:=0, SrcAdr:=(PortNo:=0,...
  • Page 824: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions // Request sending data. SendSocketDat:=RcvSocketDat; SktTCPSend_instance( Execute :=TRUE, Socket :=WkSocket, // Socket SendDat:=SendSocketDat[0], // Send data Size :=UINT#2000); // Send data size IF (SktTCPSend_instance.Done=TRUE) THEN Stage:=INT#4; // Normal end ELSIF (SktTCPSend_instance.Error=TRUE) THEN Stage:=INT#30; // Error end END_IF; // Request closing.
  • Page 825: Skttcprcv

    2 Instruction Descriptions SktTCPRcv The SktTCPRcv instruction reads the data from the receive buffer for a TCP socket for the built-in Eth- erNet/IP. Instruction Name Graphic expression ST expression SktTCPRcv TCP Socket None SktTCPRcv_instance(Execute, Receive Socket, TimeOut, Size, RcvDat, Done, Busy, Error, ErrorID, RcvSize);...
  • Page 826: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions Function The SktTCPRcv instruction stores the data in the receive buffer for the socket that is specified with Socket in receive data RcvDat[]. The number of bytes to store is specified with Size. The number of bytes that is actually stored is assigned to RcvSize. If there is no data in the receive buffer, the instruc- tion waits for data for the time that is set with timeout time TimeOut.
  • Page 827: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions • If the size of data that was received by the specified socket is smaller than the value of Size, then all of the received data is stored in RecDat[]. Then size of data that was stored is stored in RcvSize. •...
  • Page 828: Skttcpsend

    2 Instruction Descriptions SktTCPSend The SktTCPSend instruction sends data from a TCP port for the built-in EtherNet/IP. Instruction Name Graphic expression ST expression SktTCPSend TCP Socket None SktTCPSend_instance(Execute, Send Socket, SendDat, Size, Done, Busy, Error, ErrorID); Variables Name Meaning Description Valid range Unit Default...
  • Page 829: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions The data type of Socket is structure _sSOCKET. The specifications are as follows: Name Meaning Description Data type Valid range Unit Default Socket Socket Socket _sSOCKET Handle Handle Handle for data commu- UDINT Depends on nications data type. SrcAdr* Local address Local IP address and _sSOCKET_...
  • Page 830: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions • The socket specified with Socket is not connected. • The handle specified by Socket.Handle does not exist. Sample Programming Refer to the sample programming that is provided for the SktTCPConnect instruction (page 2-770). 2-782 NJ-series Instructions Reference Manual (W502)
  • Page 831: Sktgettcpstatus

    2 Instruction Descriptions SktGetTCPStatus The SktGetTCPStatus instruction reads the status of a TCP socket. Instruction Name Graphic expression ST expression SktGetTCP Read TCP None SktGetTCPStatus_instance(Execute, Status Socket Status Socket, Done, Busy, Error, ErrorID, TcpStatus, DatRcvFlag); Variables Name Meaning Description Valid range Unit Default Socket...
  • Page 832: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions Function The SktGetTCPStatus instruction gets the TCP connection status TcpStatus of the socket that is spec- ified with Socket. If there is receive data in the receive buffer, the value of data received flag DatRecv- Flag changes to TRUE. Storage of the data to TcpStatus and DatRcvFlag is completed when the instruction is completed normally (i.e., when the value of Done changes to TRUE).
  • Page 833: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions Additional Information Refer to the NJ-series CPU Unit Built-in EtherNet/IP Port User’s Manual (Cat. No. W506) for details on socket services. Precautions for Correct Use • Execution of this instruction is continued until processing is completed even if the value of Execute changes to FALSE or the execution time exceeds the task period.
  • Page 834: Sktclose

    2 Instruction Descriptions SktClose The SktClose instruction closes the specified TCP or UDP socket for the built-in EtherNet/IP. Instruction Name Graphic expression ST expression SktClose Close None SktClose_instance(Execute, TCP/UDP Socket, Done, Busy, Error, Socket ErrorID); Variables Name Meaning Description Valid range Unit Default Socket...
  • Page 835: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions The data type of Socket is structure _sSOCKET. The specifications are as follows: Name Meaning Description Data type Valid range Unit Default Socket Socket Socket _sSOCKET Handle Handle Handle of the connec- UDINT Depends on tion to close. data type.
  • Page 836: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions • You can execute a maximum of 32 of the following instructions at the same time: SktUDPCreate, SktUDPRcv, SktUDPSend, SktTCPAccept, SktTCPConnect, SktTCPRcv, SktTCPSend, SktGetTCP- Status, SktClose, and SktClearBuf. • An error occurs in the following cases. Error will change to TRUE. •...
  • Page 837: Sktclearbuf

    2 Instruction Descriptions SktClearBuf The SktClearBuf instruction clears the receive buffer for the specified TCP or UDP socket for the built-in EtherNet/IP. Instruction Name Graphic expression ST expression SktClearBuf Clear None SktClearBuf_instance(Execute, TCP/UDP Socket, Done, Busy, Error, Socket Receive ErrorID); Buffer Variables Name...
  • Page 838: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions The data type of Socket is structure _sSOCKET. The specifications are as follows: Name Meaning Description Data type Valid range Unit Default Socket Socket Socket _sSOCKET Handle Handle The handle of the socket UDINT Depends on for which to clear the data type.
  • Page 839: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions Sample Programming Refer to the sample programming that is provided for the SktTCPConnect instruction (page 2-770). NJ-series Instructions Reference Manual (W502) 2-791...
  • Page 840: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions 2-792 NJ-series Instructions Reference Manual (W502)
  • Page 841: Sd Memory Card Instructions

    SD Memory Card Instructions Instruction Name Page FileWriteVar Write Variable to File 2-794 FileReadVar Read Variable from File 2-799 FileOpen Open File 2-803 FileClose Close File 2-806 FileSeek Seek File 2-809 FileRead Read File 2-812 FileWrite Write File 2-819 FileGets Get Text String 2-826 FilePuts...
  • Page 842: Filewritevar

    2 Instruction Descriptions FileWriteVar The FileWriteVar instruction writes the value of a variable to the specified file in the SD Memory Card. The value is written in binary format. Instruction Name FB/FUN Graphic expression ST expression FileWriteVar Write Variable to FileWriteVar_instance(Execute, FileWriteVar_instance File...
  • Page 843: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions The following figure shows a programming example. The contents of array variable abc[0] is written to a file named ‘Temp\f_name.bin.’ FileWriteVar_instance(A, ‘Temp/f_name.bin’, abc, TRUE, def, ghi, jkl, mno); FileWriteVar_instance FileWriteVar Execute Done ’Temp/f_name.bin’ FileName Busy WriteVar Error TRUE OverWrite ErrorID...
  • Page 844: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions Precautions for Correct Use • Execution of this instruction is continued until processing is completed even if the value of Execute changes to FALSE or the execution time exceeds the task period. The value of Done changes to TRUE when processing is completed.
  • Page 845: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions Sample Programming This sample writes all of array variable Var1[] to the file ‘File1.dat.’ Internal Variables Variable Data type Initial value Comment OperatingEnd BOOL False Processing completed. Trigger BOOL False Execution condition Operating BOOL Processing False Var1 ARRAY[0..999] OF INT [1000(0)] Write data...
  • Page 846: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions Internal Variables Variable Data type Initial value Comment Trigger BOOL Execution condition False LastTrigger BOOL False Value of Trigger from previous task period OperatingStart BOOL False Processing started. Operating BOOL Processing False Var1 ARRAY[0..999] OF INT [1000(0)] Variable FileWriteVar_instance FileWriteVar...
  • Page 847: Filereadvar

    2 Instruction Descriptions FileReadVar The FileReadVar instruction reads the contents of the specified file on the SD Memory Card as binary data and writes it to a variable. Instruction Name FB/FUN Graphic expression ST expression FileReadVar Read Variable from FileReadVar_instance(Execute, FileReadVar_instance File FileName, ReadVar, Done, Busy,...
  • Page 848: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions Related System-defined Variables Name Meaning Data type Description _Card1Ready SD Memory Card BOOL This flag indicates if the SD Memory Card is physically Ready Flag inserted and is mounted normally, i.e., if it can be accessed by instructions and communications commands. TRUE: Can be used.
  • Page 849: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions • If more than four SD Memory Card instructions that do not have a FileID variable (i.e., FileWrite- Var, FileReadVar, FileCopy, DirCreate, FileRemove, DirRemove, and FileRename) are executed at the same time. • The value of FileName exceeds the maximum number of bytes allowed in a file name. •...
  • Page 850: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions Internal Variables Variable Data type Initial value Comment Trigger BOOL False Execution condition LastTrigger BOOL False Value of Trigger from previous task period OperatingStart BOOL False Processing started. Operating BOOL False Processing Var1 ARRAY[0..999] OF INT [1000(0)] Variable to read FileReadVar_instance FileReadVar...
  • Page 851: Fileopen

    2 Instruction Descriptions FileOpen The FileOpen instruction opens the specified file in the SD Memory Card. Instruction Name FB/FUN Graphic expression ST expression FileOpen Open File FileOpen_instance(Exe- FileOpen_instance cute, FileName, Mode, FileOpen Done, Busy, Error, ErrorID, Execute Done FileID); FileName Busy Mode Error...
  • Page 852: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions Enumerator Meaning _RDWR_CREATE Use this value to open a file to read and write it. If the file already exists, the contents is discarded and the file size is set to 0. If the file does not exist, a new file is created. The file is read and written from the beginning.
  • Page 853: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions Additional Information The root directory of the file name is the top level of the SD Memory Card. Precautions for Correct Use • Execution of this instruction is continued until processing is completed even if the value of Execute changes to FALSE or the execution time exceeds the task period.
  • Page 854: Fileclose

    2 Instruction Descriptions FileClose The FileClose instruction closes the specified file in the SD Memory Card. Instruction Name FB/FUN Graphic expression ST expression FileClose Close File FileClose_instance(Execute, FileClose_instance FileID, Done, Busy, Error, FileClose ErrorID); Execute Done FileID Busy Error ErrorID Variables Name Meaning...
  • Page 855: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions Name Meaning Data type Description _Card1Protect SD Memory Card Write BOOL This flag indicates if the SD Memory Card is write pro- Protected Flag tected when it is inserted and ready to use. TRUE: Write protected. FALSE: Not write protected. _Card1Err SD Memory Card Error BOOL...
  • Page 856: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions Sample Programming Refer to the sample programming for the following instructions: FileRead (page 2-812), FileWrite (page 2-819), FileGets (page 2-826), and FilePuts (page 2-833). 2-808 NJ-series Instructions Reference Manual (W502)
  • Page 857: Fileseek

    2 Instruction Descriptions FileSeek The FileSeek instruction sets a file position indicator in the specified file in the SD Memory Card. Instruction Name FB/FUN Graphic expression ST expression FileSeek Seek File FileSeek_instance(Exe- FileSeek_instance cute, FileID, Offset, Origin, FileSeek Done, Busy, Error, ErrorID); Execute Done FileID...
  • Page 858: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions The following figure shows a programming example. A file position indicator is set at 100 bytes from the beginning of the file. FileSeek_instance(A, abc, DINT#100, _SEEK_SET, def, FileSeek_instance ghi, jkl, mno); FileSeek Execute Done FileID Busy Offset Error DINT#100 _SEEK_SET...
  • Page 859: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions • The file specified by FileID does not exist. • The file specified by FileID is being accessed. • The position specified by Origin and Offset exceeds the file size. • An error that prevents access occurs during SD Memory Card access. Sample Programming Refer to the sample programming for the following instructions: FileRead (page 2-812) and FileWrite (page 2-819).
  • Page 860: Fileread

    2 Instruction Descriptions FileRead The FileRead instruction reads the data from the specified file in the SD Memory Card. Instruction Name FB/FUN Graphic expression ST expression FileRead Read File FileRead_instance(Exe- FileRead_instance cute, FileID, ReadBuf, Size, FileRead Done, Busy, Error, ErrorID, Execute Done ReadSize, EOF);...
  • Page 861: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions Function The FileRead instruction reads the data from position of the file position indicator in the file specified by file ID FileID in the SD Memory Card. It then stores the data in read buffer ReadBuf[]. The file position indicator is set at the desired location in advance with the FileSeek instruction.
  • Page 862: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions Name Meaning Data type Description _Card1PowerFail SD Memory Card BOOL This flag indicates if an error occurred in complet- Power Interruption Flag ing processing when power was interrupted dur- ing SD Memory Card access. This flag is not cleared automatically.
  • Page 863: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions Internal Variables Variable Data type Initial value Comment Processing completed. OperatingEnd BOOL False Execution condition Trigger BOOL False Processing Operating BOOL False File ID DWORD 16#0 Read data InDat ARRAY[0..999] OF BYTE [1000(16#0)] RS_instance FileOpen_instance FileOpen FileSeek_instance FileSeek FileRead_instance FileRead...
  • Page 864: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions Execute FileSeek instruction. FileSeek_instance FileOpen_instance.Done Operating FileSeek Execute Done FileID Busy DINT#2 Offset Error _SEEK_SET Origin ErrorID Inline ST FileSeek_instance.Error 1 // Processing after error end. Execute FileRead instruction. FileRead_instance FileSeek_instance.Done Operating FileRead Execute Done FileID Busy ReadBuf InDat[0] UINT#4...
  • Page 865: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions Internal Variables Variable Data type Initial value Comment Trigger Execution condition BOOL False Value of Trigger from previous task period LastTrigger BOOL False OperatingStart BOOL Processing started. False Operating Processing BOOL False Read data InDat ARRAY[0..999] OF BYTE [1000(16#0)] Stage Stage change...
  • Page 866: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions // Read file. FileRead_instance( Execute :=TRUE, // File ID FileID :=Fid, // Read buffer ReadBuf:=InDat[0], // Number of elements to read: 4 bytes Size :=UINT#4); IF (FIleRead_instance.Done=TRUE) THEN Stage:=INT#4; // Normal end END_IF; IF (FileRead_instance.Error=TRUE) THEN // Error end Stage:=INT#99;...
  • Page 867: Filewrite

    2 Instruction Descriptions FileWrite The FileWrite instruction writes data to the specified file in the SD Memory Card. Instruction Name FB/FUN Graphic expression ST expression FileWrite Write File FileWrite_instance(Exe- FileWrite_instance cute, FileID, WriteBuf, Size, FileWrite Done, Busy, Error, ErrorID, Execute Done WriteSize);...
  • Page 868: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions The following figure shows a programming example. If the write buffer def[] is BYTE data, 100 bytes of data is written to the file. FileWrite_instance(A, abc, def[0], UINT#100, ghi, jkl, mno, pqr, stu); FileWrite_instance FileWrite Execute Done FileID Busy def[0]...
  • Page 869: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions • If WriteBuf[] is an array of structures, adjustment areas between members may be inserted depend- ing on the composition. • If the operating mode of the CPU Unit is changed to PROGRAM mode or when a major fault level Controller error occurs during instruction execution, the file is closed by the system.
  • Page 870: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions Internal Variables Variable Data type Initial value Comment OperatingEnd BOOL Processing completed. False Trigger Execution condition BOOL False Operating BOOL False Processing DWORD File ID 16#0 OutDat Write data ARRAY[0..999] OF BYTE [1000(16#0)] RS_instance FileOpen_instance FileOpen FileSeek_instance FileSeek FileWrite_instance FileWrite...
  • Page 871: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions Execute FileSeek instruction. FileSeek_instance Operating FileOpen_instance.Done FileSeek Execute Done FileID Busy DINT#2 Offset Error _SEEK_SET Origin ErrorID Inline ST FileSeek_instance.Error 1 // Processing after error end. Execute FileWrite instruction. FileWrite_instance Operating FileSeek_instance.Done FileWrite Execute Done FileID Busy OutDat[0] WriteBuf Error...
  • Page 872: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions Internal Variables Variable Data type Initial value Comment Trigger Execution condition BOOL False Value of Trigger from previous task period LastTrigger BOOL False OperatingStart BOOL Processing started. False Operating Processing BOOL False Source data OutDat ARRAY[0..999] OF BYTE [1000(16#0)] Stage Stage change...
  • Page 873: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions // Write file. FileWrite_instance( Execute :=TRUE, // File ID FileID :=Fid, // Write buffer WriteBuf:=OutDat[0], // Number of elements to write: 4 bytes Size :=UINT#4); IF (FIleWrite_instance.Done=TRUE) THEN Stage:=INT#4; // Normal end END_IF; IF (FileWrite_instance.Error=TRUE) THEN // Error end Stage:=INT#99;...
  • Page 874: Filegets

    2 Instruction Descriptions FileGets The FileGets instruction reads a text string of one line from the specified file in the SD Memory Card. Instruction Name FB/FUN Graphic expression ST expression FileGets Get Text String FileGets_instance(Execute, FileGets_instance FileID, TrimLF, Done, Busy, FileGets Error, ErrorID, Out, EOF);...
  • Page 875: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions The following figure shows a programming example. Here, a text string of one line is read from a file, the line feed code is deleted, and the result is written to pqr. FileGets_instance(A, abc, TRUE, def, ghi, jkl, mno, pqr, stu);...
  • Page 876: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions • You must use the FileOpen instruction to obtain the value for FileID before you execute this instruc- tion. • If the operating mode of the CPU Unit is changed to PROGRAM mode or when a major fault level Controller error occurs during instruction execution, the file is closed by the system.
  • Page 877 2 Instruction Descriptions Internal Variables Data type Initial value Comment Variable OperatingEnd BOOL Processing completed. False Trigger Execution condition BOOL False Processing Operating BOOL False Index InDat[] element index File ID DWORD 16#0 Integer data InDat ARRAY[0..999] OF INT [1000(0)] RS_instance FileOpen_instance FileOpen...
  • Page 878 2 Instruction Descriptions Execute FileGets instruction. FileGets_instance Operating FileOpen_instance.Done FileGets_instance.Busy FileGets_instance.EOF FileGets Execute Done FileID Busy TRUE TrimLF Error ErrorID Inline ST FileGets_instance.Error 1 // Processing after error end. Execute STRING_TO_INT instruction. Operating FileGets_instance.Done STRING_TO_INT FileGets_instance.Out InDat[Index] InOut Index Execute FileClose when EOF is detected. FileClose_instance Operating FileGets_instance.EOF...
  • Page 879 2 Instruction Descriptions Internal Variables Variable Data type Initial value Comment Trigger BOOL False Execution condition LastTrigger BOOL False Value of Trigger from previous task period OperatingStart BOOL False Processing started. Operating BOOL False Processing InDat ARRAY[0..999] OF INT [1000(0)] Integer data Stage Stage change...
  • Page 880 2 Instruction Descriptions // Read text string. FileGets_instance( Execute:=TRUE, FileID :=Fid, TrimLF :=TRUE); IF (FileGets_instance.Done=TRUE) THEN // Convert the text string that was read to an integer. InDat[Index]:=STRING_TO_INT(FileGets_instance.Out); Index:=Index+INT#1; // Reached end of file. IF (FileGets_instance.EOF=TRUE) THEN Stage:=INT#3; // Normal end ELSE FileGets_instance(Execute:=FALSE);...
  • Page 881: Fileputs

    2 Instruction Descriptions FilePuts The FilePuts instruction writes a text string to the specified file in the SD Memory Card. Instruction Name FB/FUN Graphic expression ST expression FilePuts Put Text String FilePuts_instance(Execute, FilePuts_instance FileID, In, Done, Busy, Error, FilePuts ErrorID); Execute Done FileID...
  • Page 882: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions Related System-defined Variables Name Meaning Data type Description _Card1Ready SD Memory Card BOOL This flag indicates if the SD Memory Card is physically Ready Flag inserted and is mounted normally, i.e., if it can be accessed by instructions and communications com- mands.
  • Page 883: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions Sample Programming Here, 100 lines of the contents of INT array variable Dat[0..9,0..99] are stored in a file named 'ABC.csv' in CSV file format. Each line contains ten text strings of numbers. Commas are inserted between them. A CR+LF code is added to the end of the line.
  • Page 884 2 Instruction Descriptions Internal Variables Variable Data type Initial value Comment OperatingEnd BOOL Processing completed. False Execution condition Trigger BOOL False Processing Operating BOOL False Index0 Column index Index1 Row index File ID DWORD 16#0 StrDat STRING[255] Text string data ‘’...
  • Page 885 2 Instruction Descriptions Create a text string for one line. Operating FileOpen_instance.Done FilePuts_instance.Busy Inline ST FileClose_instance.Busy 1 StrDat:=’‘; // Concatenate text strings 0 to 8. 4 FOR Index0:=INT#0 TO INT#8 BY INT#1 DO Temp :=INT_TO_STRING(Dat[Index1, Index0]); Temp :=CONCAT(In1:=Temp, In2:=’,’); StrDat:=CONCAT(IN1:=StrDat, In2:=Temp); 8 END_FOR;...
  • Page 886 2 Instruction Descriptions Internal Variables Variable Data type Initial value Comment Execution condition Trigger BOOL False Value of Trigger from previous task period LastTrigger BOOL False OperatingStart BOOL Processing started. False Processing Operating BOOL False Stage change Stage Index0 Column index Row index Index1 File ID...
  • Page 887 2 Instruction Descriptions // Write text string. FilePuts_instance( Execute:=TRUE, FileID :=Fid, :=StrDat); IF (FilePuts_instance.Done=TRUE) THEN Index1:=Index1+INT#1; IF (Index1>INT#99) THEN // If 100 lines were written... Stage:=INT#4; ELSE FilePuts_instance(Execute:=FALSE); Stage:=INT#2; END_IF; END_IF; IF (FilePuts_instance.Error=TRUE) THEN Stage:=INT#99; // Error end END_IF; // Close file. FileClose_instance( Execute:=TRUE, // File ID...
  • Page 888: Filecopy

    2 Instruction Descriptions FileCopy The FileCopy instruction copies the specified file in the SD Memory Card. Instruction Name FB/FUN Graphic expression ST expression FileCopy Copy File FileCopy_instance(Exe- FileCopy_instance cute, SrcFileName, DstFile- FileCopy Name, OverWrite, Done, Execute Done Busy, Error, ErrorID); SrcFileName Busy DstFileName...
  • Page 889: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions The following figure shows a programming example. Here, the file ‘DEF.bin’ is overwritten with the file ‘ABC.bin.’ FileCopy_instance(A, ’ABC.bin’, ‘DEF.bin’, TRUE, abc, def, ghi, jkl); FileCopy_instance FileCopy Execute Done ‘ABC.bin’ SrcFileName Busy ‘DEF.bin’ DstFileName Error TRUE OverWrite ErrorID Related System-defined Variables Name...
  • Page 890: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions • If a file is open when the operating mode of the CPU Unit is changed to PROGRAM mode or when a major fault level Controller error occurs, the file is closed by the system. Any read/write operations that are in progress are completed to the end.
  • Page 891: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions Sample Programming The following procedure is used to move a file. The DirCreate instruction is used to create a directory called 'Dir1' in the SD Memory Card. The FileCopy instruction is used to copy the file named 'ABC.bin' in the existing directory 'Dir0' to the directory 'Dir1.' The DirRemove instruction is used to delete the directory ‘Dir0’...
  • Page 892: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions Internal Variables Variable Data type Initial value Comment Processing completed. OperatingEnd BOOL False Execution condition Trigger BOOL False Processing Operating BOOL False RS_instance DirCreate_instance DirCreate FileCopy_instance FileCopy DirRemove_instance DirRemove External Variables Variable Data type Comment _Card1Ready BOOL SD Memory Card Ready Flag Determine if instruction execution is completed.
  • Page 893: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions Execute DirRemove instruction. DirRemove_instance Operating FileCopy_instance.Done DirRemove Execute Done ‘Dir0’ DirName Busy TRUE Error ErrorID Inline ST DirRemove_instance.Error 1 // Processing after error end. Processing after normal end. Inline ST FileCopy_instance.Done DirRemove_instance.Done Operating 1 // Processing after normal end. NJ-series Instructions Reference Manual (W502) 2-845...
  • Page 894: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions Internal Variables Variable Data type Initial value Comment Trigger BOOL False Execution condition LastTrigger BOOL False Value of Trigger from previous task period OperatingStart BOOL False Processing started. Operating BOOL False Processing Stage Stage change DirCreate_instance DirCreate FileCopy_instance FileCopy DirRemove_instance...
  • Page 895: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions // Delete directory. DirRemove_instance( Execute :=TRUE, // Directory name DirName:=’Dir0’, // Delete files and subdirectories. :=TRUE); IF (DirRemove_instance.Done=TRUE) THEN // Normal end Operating:=FALSE; END_IF; IF (DirRemove_instance.Error=TRUE) THEN // Error end Stage:=INT#99; END_IF; 99 : // Processing after error end. Operating:=FALSE;...
  • Page 896: Fileremove

    2 Instruction Descriptions FileRemove The FileRemove instruction deletes the specified file from the SD Memory Card. Instruction Name FB/FUN Graphic expression ST expression FileRemove Delete File FileRemove_instance(Execute, FileRemove_instance FileName, Done, Busy, Error, FileRemove ErrorID); Execute Done FileName Busy Error ErrorID Variables Name Meaning...
  • Page 897: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions Name Meaning Data type Description _Card1Protect SD Memory Card Write BOOL This flag indicates if the SD Memory Card is write pro- Protected Flag tected when it is inserted and ready to use. TRUE: Write protected. FALSE: Not write protected. _Card1Err SD Memory Card Error BOOL...
  • Page 898: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions Sample Programming In this sample, the file named 'ABC.bin' is deleted from the SD Memory Card. Internal Variables Variable Data type Initial value Comment OperatingEnd Processing completed. BOOL False Trigger BOOL False Execution condition Operating BOOL Processing False RS_instance FileRemove_instance...
  • Page 899: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions Internal Variables Variable Data type Initial value Comment Trigger BOOL Execution condition False LastTrigger BOOL False Value of Trigger from previous task period OperatingStart BOOL False Processing started. Operating BOOL Processing False FileRemove_instance FileRemove External Variables Variable Data type Comment _Card1Ready BOOL...
  • Page 900: Filerename

    2 Instruction Descriptions FileRename The FileRename instruction changes the name of the specified file or directory in the SD Memory Card. Instruction Name FB/FUN Graphic expression ST expression FileRename Change File Name FileRename_instance(Execute, FileRename_instance FileName, NewName, OverWrite, FileRename Done, Busy, Error, ErrorID); Execute Done FileName...
  • Page 901: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions The following figure shows a programming example. Here, the name of the file ‘ABC.bin’ is changed to ‘DEF.bin.’ FileRename_instance(A, ’ABC.bin’, ‘DEF.bin’, TRUE, abc, def, ghi, jkl); FileRename_instance FileRename Execute Done ‘ABC.bin’ FileName Busy ‘DEF.bin’ NewName Error TRUE OverWrite ErrorID Related System-defined Variables...
  • Page 902: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions Precautions for Correct Use • Execution of this instruction is continued until processing is completed even if the value of Execute changes to FALSE or the execution time exceeds the task period. The value of Done changes to TRUE when processing is completed.
  • Page 903: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions Sample Programming In this sample, the name of the file 'ABC.bin' is changed to 'DEF.bin' on the SD Memory Card. Internal Variables Variable Data type Initial value Comment OperatingEnd Processing completed. BOOL False Trigger BOOL False Execution condition Operating BOOL Processing...
  • Page 904: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions Internal Variables Variable Data type Initial value Comment Trigger BOOL False Execution condition LastTrigger BOOL False Value of Trigger from previous task period OperatingStart BOOL False Processing started. Operating BOOL False Processing FileRename_instance FileRename External Variables Variable Data type Comment _Card1Ready BOOL...
  • Page 905: Dircreate

    2 Instruction Descriptions DirCreate The DirCreate instruction creates a directory with the specified name in the SD Memory Card. Instruction Name FB/FUN Graphic expression ST expression DirCreate Create Directory DirCreate_instance(Execute, DirCreate_instance DirName, Done, Busy, Error, DirCreate ErrorID); Execute Done DirName Busy Error ErrorID...
  • Page 906: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions Related System-defined Variables Name Meaning Data type Description _Card1Ready SD Memory Card BOOL This flag indicates if the SD Memory Card is physi- Ready Flag cally inserted and is mounted normally, i.e., if it can be accessed by instructions and communications com- mands.
  • Page 907: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions • There is insufficient space available on the SD Memory Card. • The maximum number of directories is exceeded. • The directory specified by DirName already exists. • If more than four SD Memory Card instructions that do not have a FileID variable (i.e., FileWrite- Var, FileReadVar, FileCopy, DirCreate, FileRemove, DirRemove, and FileRename) are executed at the same time.
  • Page 908: Dirremove

    2 Instruction Descriptions DirRemove The DirRemove instruction deletes the specified directory from the SD Memory Card. Instruction Name FB/FUN Graphic expression ST expression DirRemove Delete Directory DirRemove_instance(Execute, DirRemove_instance DirName, All, Done, Busy, Error, DirRemove ErrorID); Execute Done DirName Busy Error ErrorID Variables Name...
  • Page 909: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions The following figure shows a programming example. Here, a directory named ‘Dir1’ is deleted. DirRemove_instance(A, ’Dir1’, TRUE, abc, def, ghi, jkl); DirRemove_instance DirRemove Execute Done ‘Dir1’ DirName Busy TRUE Error ErrorID Related System-defined Variables Name Meaning Data type Description _Card1Ready SD Memory Card...
  • Page 910: Nj-Series Instructions Reference Manual (W502

    2 Instruction Descriptions Precautions for Correct Use • Execution of this instruction is continued until processing is completed even if the value of Execute changes to FALSE or the execution time exceeds the task period. The value of Done changes to TRUE when processing is completed.
  • Page 911: Other Instructions

    Other Instructions Instruction Name Page ReadNbit_** N-bit Read Group 2-864 WriteNbit_** N-bit Write Group 2-866 ChkRange Check Subrange Variable 2-868 GetMyTaskStatus Read Current Task Status 2-870 Task_IsActive Determine Task Status 2-873 Lock and Unlock Lock Tasks/Unlock Tasks 2-875 Get**Clk Get Clock Pulse Group 2-880 Get**Cnt Get Incrementing Free-running...
  • Page 912: Readnbit

    2 Instruction Descriptions ReadNbit_** The ReadNbit_** instructions read zero or more bits from a bit string. Instruction Name FB/FUN Graphic expression ST expression ReadNbit_** N-bit Read Group Out:=ReadNbit_**(In, Pos, (@)ReadNbit_** Size); “**” must be a bit string data type. Size "**"...
  • Page 913 2 Instruction Descriptions The following example shows the ReadNbit_BYTE instruction when In is BYTE#16#89, Pos is USINT#2 and Size is USINT#4. abc:=ReadNbit_BYTE(BYTE#16#89, USINT#2, USINT#4); ReadNbit_BYTE BYTE#16#89 USINT#2 USINT#4 Size Size=USINT#4 Bit 0 Bit 7 0 0 1 0 0 1 Pos=USINT#2 Bit 0 Bit 7...
  • Page 914: Writenbit

    2 Instruction Descriptions WriteNbit_** The WriteNbit_** instructions write zero or more bits to a bit string. Instruction Name FB/FUN Graphic expression ST expression WriteNbit_** N-bit Write Group FUN WriteNbit_**(In, Pos, Size, (@)WriteNbit_** InOut); “**” must be a bit string data InOut type.
  • Page 915 2 Instruction Descriptions The following example shows the WriteNbit_BYTE instruction when In is BYTE#16#89, Pos is USINT#2 and Size is USINT#4. WriteNbit_BYTE(BYTE#16#89, abc, USINT#2, USINT#4); WriteNbit_BYTE BYTE#16#89 InOut USINT#2 USINT#4 Size Size=USINT#4 Bit 0 Bit 7 0 0 1 0 1 0 Bit 0 Bit 7 InOut=abc...
  • Page 916: Chkrange

    2 Instruction Descriptions ChkRange The ChkRange instruction determines if the value of a variable is within the valid range of the range type specification. Instruction Name FB/FUN Graphic expression ST expression ChkRange Check Subrange Out:=ChkRange(In, Val); (@)ChkRange Variable Variables Name Meaning Description Valid range...
  • Page 917 2 Instruction Descriptions Precautions for Correct Use • If In is not a range specification variable, the value of Out changes to FALSE. • If this instruction is used in a ladder diagram, the value of Out changes to FALSE if an error occurs in the previous instruction on the rung.
  • Page 918: Getmytaskstatus

    2 Instruction Descriptions GetMyTaskStatus The GetMyTaskStatus reads the status of the current task. Instruction Name FB/FUN Graphic expression ST expression GetMyTaskStatus Read Current Task GetMyTaskStatus( (@)GetMyTaskStatus Status LastExecTime, MaxExecTime, MinExecTime, LastExecTime ExecCount, MaxExecTime MinExecTime Exceeded, ExecCount ExceedCount); Exceeded ExceedCount Variables Name Meaning Description...
  • Page 919 2 Instruction Descriptions Times, durations, Bit strings Integers dates, and text strings ExecCount Exceeded Exceed- Count Function The GetMyTaskStatus reads the status of the current task. The task status includes the last task execu- tion time LastExecTime, maximum task execution time MaxExecTime, minimum task execution time MinExecTime, task execution count ExecCount, task period exceeded flag Exceeded, and task period exceeded count ExceedCount.
  • Page 920 2 Instruction Descriptions Initial Variable Data type Comment value ExecTime_t TIME Previous task execution time (TIME data) T#0s ExecTime_ns Previous task execution time (nanoseconds LINT data) LINT Warning BOOL False Warning P_On GetMyTaskStatus LastExecTime ExecTime_t MaxExecTime MinExecTime ExecCount Exceeded ExceedCount TimeToNanoSec ExecTime_t ExecTime_ns...
  • Page 921: Task_Isactive

    2 Instruction Descriptions Task_IsActive The Task_IsActive instruction determines if the specified task is currently in execution. Instruction Name FB/FUN Graphic expression ST expression Task_IsActive Determine Task Out:=Task_IsActive( (@)Task_IsActive Status TaskName); TaskName Variables Name Meaning Description Valid range Unit Default TaskName Task name Input Task name...
  • Page 922 2 Instruction Descriptions Sample Programming In this sample, the instruction determines whether periodic task Tc2 is active when the value of variable A changes to TRUE. If it is active, the value of variable B changes to TRUE. Initial Variable Data type Comment value...
  • Page 923: Lock And Unlock

    2 Instruction Descriptions Lock and Unlock Lock: Starts an exclusive lock between tasks. Execution of any other task with a lock region with the same lock number is disabled. Unlock: Stops an exclusive lock between tasks. Instruction Name FB/FUN Graphic expression ST expression Lock Lock Tasks...
  • Page 924 2 Instruction Descriptions Normal execution Lock region Execution priority Execution interrupted. High Task T1 Lock(1) Unlock(1) Task T2 Lock(1) Unlock(1) Execution of T2 is started again The priority of T1 is higher than the after T1 completes execution. priority of T2, so T2 is interrupted and execution of T1 is started.
  • Page 925 2 Instruction Descriptions • If Lock instructions are used in more than one task, a deadlock may occur if they are positioned poorly. A Task Execution Timeout Error will occur if there is a deadlock and a total stop is performed. Normal execution Lock region Execution interrupted.
  • Page 926 2 Instruction Descriptions Program P1 Internal Variable Data type Comment Initial value Variables WriteReq BOOL Write request False Write data InDat LREAL External Comment Variable Data type Variables Record storage structure GTable1 USERTABLE WriteReq Lock USINT#1 Index > MOVE InDat INT#100 GTable1.Record[Gtable1.index] GTable1.Index...
  • Page 927 2 Instruction Descriptions Program P2 Internal Variable Data type Comment Initial value Variables ReadReq BOOL Read request False Read data OutDat LREAL External Comment Variable Data type Variables Record storage structure GTable1 USERTABLE ReadReq Lock USINT#1 Index > GTable1.Index InOut GTable1.Index INT#0 MOVE...
  • Page 928: Get**Clk

    2 Instruction Descriptions Get**Clk The Get**Clk instruction outputs a clock pulse at the specified cycle. Instruction Name FB/FUN Graphic expression ST expression Get**Clk Get Clock Pulse Out:=Get**Clk(); Get**Clk Group “**” must be 100 us, 1 ms, "**" must be 100 us, 1 ms, 10 ms, 20 ms, 10 ms, 20 ms, 100 ms, 1 s, 100 ms, 1 s, or 1 min.
  • Page 929: Get**Cnt

    2 Instruction Descriptions Get**Cnt The Get**Cnt instruction gets the values of free-running counters of the specified cycle. Instruction Name FB/FUN Graphic expression ST expression Get**Cnt Get Incrementing Out:=Get**Cnt(); Get**Cnt Free-running Counter Group "**" must be 100 ns, 1 us, 1 ms, 10 ms, 100 ms, or 1 s.
  • Page 930 2 Instruction Descriptions Precautions for Correct Use • Free-running counters start counting as soon as the power supply is turned ON. When the count exceeds the valid range of ULINT data (18,446,744,073,709,551,615), it returns to 0 and counting continues. • This instruction only gets the current value of the free-running counter. It does not reset the counter to 0.
  • Page 931: Appendices

    Appendices A-1 Error Codes Related to Instructions ......A-2 A-2 Error Code Descriptions ........A-18 A-3 Error Code Details .
  • Page 932: Error Codes Related To Instructions

    Appendices Error Codes Related to Instructions Error codes are assigned to the errors that can occur when instructions are executed. If an instruction has an ErrorID output variable, the value of the ErrorID gives you the error code. However, you cannot get the error codes for instructions that do not have an ErrorID output variable.
  • Page 933 Appendices Type Instruction Name Error codes Sequence Control NEXT Repeat End Instructions BREAK Break Loop Comparison Instructions EQ (=) Equal NE (<>) Not Equal LT (<) Less Than LE (<=) Less Than Or Equal GT (>) Greater Than GE (>=) Greater Than Or Equal EQascii Text String Comparison Equal...
  • Page 934 Appendices Type Instruction Name Error codes Counter Instructions CTUD Up-down Counter CTUD_** Up-down Counter Group Math Instructions ADD (+) Addition 16#0410 AddOU (+OU) Addition with Overflow/Underflow Check SUB (-) Subtraction SubOU (-OU) Subtraction with Overflow/Underflow Check MUL (*) Multiplication MulOU (*OU) Multiplication with Overflow/Underflow Check DIV (/)
  • Page 935 Appendices Type Instruction Name Error codes BCD Conversion Instruc- BCD_TO_** BCD Data Type-to-Unsigned Integer 16#0400 tions Conversion Group 16#0403 BCDsToBin Signed BCD-to-Signed Integer 16#0400 Conversion 16#0403 16#0404 BinToBCDs_** Signed Integer-to-BCD Conversion 16#0400 Group AryToBCD Array BCD Conversion 16#0400 16#1006 AryToBin Array Unsigned Integer Conversion 16#0400 16#0403...
  • Page 936 Appendices Type Instruction Name Error codes Data Type Conversion TO_** (Bit String Conversion Bit String Conversion Group 16#0410 Instructions Group) TO_** (Real Number Conver- Real Number Conversion Group 16#0410 sion Group) TRUNC Truncate Round Round Off Real Number RoundUp Round Up Real Number Bit String Processing AND (&) Logical AND...
  • Page 937 Appendices Type Instruction Name Error codes Data Movement Instruc- Clear Initialize tions Copy**ToNum (Bit String to Bit Pattern Copy (Bit String to Signed Signed Integer) Integer) Group Copy**To*** (Bit String to Real Bit Pattern Copy (Bit String to Real Number) Number) Group CopyNumTo** (Signed Integer Bit Pattern Copy (Signed Integer to Bit...
  • Page 938 Appendices Type Instruction Name Error codes Conversion Instructions HexStringToNum_** Hexadecimal Text String-to-Number 16#0410 Conversion Group FixNumToString Fixed-decimal Number-to-Text String Conversion StringToFixNum Text String-to-Fixed-decimal Conversion 16#0407 16#0410 DtToString Date and Time-to-Text String Conversion --- DateToString Date-to-Text String Conversion TodToString Time of Day-to-Text String Conversion GrayToBin_** Gray Code-to-Binary Code Conversion Group...
  • Page 939 Appendices Type Instruction Name Error codes Stack and Table Instruc- RecSearch Record Search 16#0400 tions 16#0406 16#0410 RecRangeSearch Range Record Search 16#0400 16#0401 16#0406 RecSort Record Sort 16#0400 16#0406 RecNum Get Number of Records 16#0410 16#0406 RecMax Maximum Record Search 16#0406 RecMin Minimum Record Search...
  • Page 940 Appendices Type Instruction Name Error codes Time and Time of Day SUB_TIME Subtract Time Instructions SUB_TOD_TIME Subtract Time from Time of Day SUB_TOD_TOD Subtract Time of Day SUB_DATE_DATE Subtract Date SUB_DT_DT Subtract Date and Time SUB_DT_TIME Subtract Time from Date and Time MULTIME Multiply Time DIVTIME...
  • Page 941 Appendices Type Instruction Name Error codes System Control Instruc- ResetECError Reset EtherCAT Error 16#041A tions GetECError Get EtherCAT Error Status SetInfo Create User-defined Information 16#0400 ResetUnit Restart Unit 16#0400 16#040D 16#040F GetNTPStatus Read NTP Status Communications Instruc- ExecPMCR Protocol Macro 16#0400 tions 16#0406...
  • Page 942 Appendices Type Instruction Name Error codes Communications Instruc- CIPWrite Write Variable Class 3 Explicit 16#0400 tions 16#0407 16#1C00 16#1C02 16#1C03 16#1C04 CIPSend Send Explicit Message Class 3 16#0407 16#1C00 16#1C02 16#1C03 16#1C04 CIPClose Close CIP Class 3 Connection 16#1C02 16#1C03 CIPUCMMRead Read Variable UCMM Explicit 16#0400...
  • Page 943 Appendices Type Instruction Name Error codes Communications Instruc- EC_CoESDORead Read EtherCAT CoE SDO 16#0400 tions 16#1800 16#1801 16#1802 16#1803 16#1804 16#1808 EC_StartMon Start EtherCAT Packet Monitor 16#1805 16#1807 16#1808 EC_StopMon Stop EtherCAT Packet Monitor 16#1806 16#1808 EC_SaveMon Save EtherCAT Packets 16#1805 16#1807 16#1808...
  • Page 944 Appendices Type Instruction Name Error codes Communications Instruc- SktUDPSend UDP Socket Send 16#0400 tions 16#0407 16#2002 16#2003 16#2007 16#2008 SktTCPAccept Accept TCP Socket 16#0400 16#2000 16#2002 16#2003 16#2004 16#2006 16#2008 SktTCPConnect Connect TCP Socket 16#0400 16#2000 16#2002 16#2003 16#2008 SktTCPRcv TCP Socket Receive 16#0400 16#0407...
  • Page 945 Appendices Type Instruction Name Error codes SD Memory Card Instruc- FileReadVar Read Variable from File 16#0400 tions 16#1400 16#1403 16#1405 16#140B 16#140D 16#140E FileOpen Open File 16#0400 16#1400 16#1401 16#1403 16#1404 16#1405 16#140A 16#140B 16#140D 16#140E FileClose Close File 16#1403 16#1405 16#140E FileSeek...
  • Page 946 Appendices Type Instruction Name Error codes SD Memory Card Instruc- FilePuts Put Text String 16#1400 tions 16#1401 16#1402 16#1403 16#1405 16#1406 16#140E FileCopy Copy File 16#0400 16#1400 16#1401 16#1402 16#1403 16#1404 16#1405 16#1409 16#140A 16#140B 16#140D 16#140E FileRemove Delete File 16#0400 16#1400 16#1401...
  • Page 947 Appendices Type Instruction Name Error codes SD Memory Card Instruc- DirRemove Delete Directory 16#0400 tions 16#1400 16#1401 16#1405 16#1408 16#140A 16#140B 16#140C 16#140D 16#140E Other Instructions ReadNbit_** N-bit Read Group 16#1405 16#1406 WriteNbit_** N-bit Write Group 16#1405 16#1406 ChkRange Check Subrange Variable GetMyTaskStatus Read Current Task Status Task_IsActive...
  • Page 948: Error Code Descriptions

    Appendices Error Code Descriptions The following table gives the error name, meaning, and assumed cause for each error code. Refer to A-3 Error Code Details for details. Error code Name Meaning Assumed cause Reference 16#0400 Input Value Out of An input parameter for an •...
  • Page 949 Appendices Error code Name Meaning Assumed cause Reference 16#040D Illegal Unit Speci- The Unit specified for an • A Unit that does not exist in the Unit configu- page A-28 fied instruction does not exist. ration information was specified. • A Unit that is in the Unit configuration infor- mation was specified, but the Units does not actually exist in the Controller.
  • Page 950 Appendices Error code Name Meaning Assumed cause Reference 16#1402 SD Memory Card The capacity of the SD • The SD Memory Card has run out of free page A-34 Insufficient Capac- Memory Card was insuffi- space. cient when writing to the SD Memory Card for an instruction.
  • Page 951 Appendices Error code Name Meaning Assumed cause Reference 16#1803 Reception Buffer The receive data from an • The receive data from the slave overflowed page A-39 Overflow EtherCAT slave overflowed the receive buffer. the receive buffer when an instruction was executed. 16#1804 SDO Abort Error An SDO abort error was...
  • Page 952 Appendices Error code Name Meaning Assumed cause Reference 16#1C04 CIP Timeout A CIP timeout occurred • A device does not exist for the specified IP page A-42 during execution of a CIP address. communications instruc- • The CIP connection for the specified handle tion.
  • Page 953 Appendices Error code Name Meaning Assumed cause Reference 16#2006 Socket Timeout A timeout occurred for a • SktTCPAccept instruction: There was no page A-45 socket service instruction. request for a connection from the remote node during the user-set timeout time. •...
  • Page 954: Error Code Details

    Appendices Error Code Details This appendix provides detailed information on error codes. Error Descriptions The items that are used to describe individual errors are described in the following copy of an error table. Name Gives the name of the error. Error code Gives the code of the error.
  • Page 955 Appendices Name Input Value Out of Range Error code 16#0400 Meaning An input parameter for an instruction exceeded the valid range for an input variable. Or, division by an integer of 0 occurred in division or remainder calculations. Effects User program Continues.
  • Page 956 Appendices Name BCD Error Error code 16#0403 Meaning A value that was not BCD was input for a BCD input parameter to an instruction. Effects User program Continues. Operation The relevant instruction will end according to specifica- tions. System-defined Variable Data type Name variables...
  • Page 957 Appendices Name Illegal Data Position Specified Error code 16#0406 Meaning The data position specified for an instruction exceeded the data area range. Effects User program Continues. Operation The relevant instruction will end according to specifica- tions. System-defined Variable Data type Name variables None...
  • Page 958 Appendices Name No User Errors to Clear Error code 16#040B Meaning An instruction to clear user-defined errors was executed when there was no user-defined error. Effects User program Continues. Operation The relevant instruction will end according to specifica- tions. The output or Unit operation is not affected. System-defined Variable Data type...
  • Page 959 Appendices Name Unit Restart Failed Error code 16#040F Meaning Restarting a Special I/O Unit or CPU Bus Unit failed. Effects User program Continues. Operation The relevant instruction will end according to specifica- tions. The output or Unit operation is not affected. System-defined Variable Data type...
  • Page 960 Appendices Name Undefined CJ-series Memory Address Error code 16#0413 Meaning The required specification is missing for a variable for which CJ-series Unit memory must be specified. Effects User program Continues. Operation The relevant instruction will end according to specifica- tions. System-defined Variable Data type...
  • Page 961 Appendices Name Unallowed Task Specification Error code 16#0418 Meaning An unallowed task was specified for an instruction. Effects User program Continues. Operation The relevant instruction will end according to specifica- tions. System-defined Variable Data type Name variables None Cause and Assumed cause Correction Prevention...
  • Page 962 Appendices Name FINS Error Error code 16#0800 Meaning An error occurred when a FINS command was sent or received. Effects User program Continues. Operation The relevant instruction will end according to specifica- tions. System-defined Variable Data type Name variables None Cause and Assumed cause Correction...
  • Page 963 Appendices Name Port Setup Already Busy Error code 16#0C02 Meaning A Change Port Setup instruction was executed during execution of another Change Port Setup instruction. Effects User program Continues. Operation The relevant instruction will end according to specifica- tions. Communications output will follow the specifications of the instruction.
  • Page 964 Appendices Name SD Memory Card Insufficient Capacity Error code 16#1402 Meaning The capacity of the SD Memory Card was insufficient when writing to the SD Memory Card for an instruction. Effects User program Continues. Operation The relevant instruction will end according to specifica- tions.
  • Page 965 Appendices Name File Already in Use Error code 16#1405 Meaning A file specified for an instruction cannot be accessed because it is already being used. Effects User program Continues. Operation The relevant instruction will end according to specifica- tions. The operation of the Unit is not affected. System-defined Variable Data type...
  • Page 966 Appendices Name Directory Not Empty Error code 16#1408 Meaning A directory was not empty when the Delete Directory instruction was executed or when an attempt was made to change the directory name. Effects User program Continues. Operation The relevant instruction will end according to specifica- tions.
  • Page 967 Appendices Name Too Many Files Open Error code 16#140B Meaning The maximum number of open files was exceeded when opening a file for an instruction. Effects User program Continues. Operation The relevant instruction will end according to specifica- tions. The operation of the Unit is not affected. System-defined Variable Data type...
  • Page 968 Appendices Name SD Memory Card Access Failed Error code 16#140E Meaning SD Memory Card access failed. Effects User program Continues. Operation The relevant instruction will end according to specifica- tions. The operation of the Unit is not affected. System-defined Variable Data type Name variables...
  • Page 969 Appendices Name EtherCAT Timeout Error code 16#1802 Meaning A timeout occurred while trying to access an EtherCAT slave when an instruction was executed. Effects User program Continues. Operation The relevant instruction will end according to specifica- tions. System-defined Variable Data type Name variables None...
  • Page 970 Appendices Name Packet Monitoring Function Not Started Error code 16#1806 Meaning A Stop EtherCAT Packet Monitor instruction was executed when EtherCAT packet monitoring was stopped. Effects User program Continues. Operation The relevant instruction will end according to specifica- tions. System-defined Variable Data type Name...
  • Page 971 Appendices Name Communications Resource Overflow Error code 16#1808 Meaning More than 32 EtherCAT communications instructions were executed at the same time. Effects User program Continues. Operation The relevant instruction will end according to specifica- tions. System-defined Variable Data type Name variables None Cause and...
  • Page 972 Appendices Name CIP Handle Out of Range Error code 16#1C02 Meaning The handle that is specified for the CIP communications instruction is not correct. Effects User program Continues. Operation The relevant instruction will end according to specifica- tions. System-defined Variable Data type Name variables...
  • Page 973 Appendices Name Local IP Address Setting Error Error code 16#2000 Meaning An instruction was executed when there was a setting error in the local IP address. Effects User program Continues. Operation The relevant instruction will end according to specifica- tions. System-defined Variable Data type...
  • Page 974 Appendices Name Status Error Error code 16#2003 Meaning The status was not suitable for execution of the instruction. Effects User program Continues. Operation The relevant instruction will end according to specifica- tions. System-defined Variable Data type Name variables None Cause and Assumed cause Correction Prevention...
  • Page 975 Appendices Name Local IP Address Not Set Error code 16#2004 Meaning The local IP address was not set when a socket service instruction was executed. Effects User program Continues. Operation The relevant instruction will end according to specifica- tions. System-defined Variable Data type Name...
  • Page 976 Appendices Name Socket Communications Resource Overflow Error code 16#2008 Meaning The maximum resources that you can use for socket service instructions at the same time was exceeded. Effects User program Continues. Operation The relevant instruction will end according to specifica- tions.
  • Page 977: Sdo Abort Codes

    Appendices SDO Abort Codes As reference information, the following table lists the SDO abort codes for EtherCAT communications. The abort codes that are used in actual communications are specified by the slaves. Refer to the slave manuals when programming communications. Value Meaning 16#05030000...
  • Page 978 Appendices A-48 NJ-series Instructions Reference Manual (W502)
  • Page 979: Index

    Index NJ-series Instructions Reference Manual (W502) Index-1...
  • Page 980 Index Index Symbols Add Time ..............2-544 Add Time to Date and Time ........2-548 Add Time to Time of Day ........... 2-546 & (Logical AND) ............2-286 ADD_DT_TIME (Add Time to Date and Time) ..2-548 * (Multiplication) ............2-161 Addition ..............
  • Page 981 Index Bit Pattern Copy AryCmpGEV (Array Value Comparison Greater Than Or Equal) 2-112 (Bit String to Real Number) Group ......2-341 AryCmpGT Bit Pattern Copy (Array Comparison Greater Than) ......2-107 (Bit String to Signed Integer) Group ....... 2-339 AryCmpGTV Bit Pattern Copy (Array Value Comparison Greater Than) ....
  • Page 982 Index Cmp (Compare) ............2-98 Date and Time-to-Text String Conversion ....2-433 ColmToLine_** DateStructToDt (Join Time) ........2-599 (Column to Line Conversion Group) ....... 2-377 DateToSec (Convert Date to Seconds) ..... 2-576 Column to Line Conversion Group ......2-377 DateToString (Date-to-Text String Conversion) ..2-435 Combine Real Number Mantissa and Exponent ..
  • Page 983 Index GetAlarm (Get User-defined Error Status) ....2-617 EXP (Natural Exponential Operation) ....... 2-185 Exponentiation ............2-187 GetByteLen (Get Byte Length) ........2-535 EXPT (Exponentiation) ..........2-187 GetCJBError (Get I/O Bus Error Status) ....2-626 Extract Date from Date and Time ......2-568 GetDayOfWeek (Get Day of Week) ......
  • Page 984 Index Multiplication .............. 2-161 LE (Less Than Or Equal) ..........2-88 LEascii (Text String Comparison Multiplication with Overflow/Underflow Check ... 2-163 Less Than or Equal) ..........2-95 Multiply Time ............. 2-560 LEFT (Get String Left) ..........2-522 MUX (Multiplexer) ............2-300 LEN (String Length) ...........
  • Page 985 Index Reverse Sign ............. 2-369 Rand (Random Number) ........... 2-191 Random Number ............2-191 Reversible Shift Register ........... 2-354 Range Record Search ..........2-487 RIGHT (Get String Right) .......... 2-522 Read Current Task Status ......... 2-870 ROL (Rotate N-bits Left) ........... 2-364 Read Data Trace Status ..........
  • Page 986 Index SktTCPAccept (Accept TCP Socket) ......2-767 TCP Socket Receive ..........2-777 SktTCPRcv (TCP Socket Receive) ......2-777 TCP Socket Send ............2-780 SktTCPSend (TCP Socket Send) ......2-780 Test A Bit ..............2-43 SktUDP Create (Create UDP Socket) ....... 2-754 Test A Bit NOT .............
  • Page 987 Index Up-counter Group ............. 2-140 Up-down Counter ............2-142 Up-down Counter Group ........... 2-146 While ................2-32 WHILE (While) ............2-32 Write EtherCAT CoE SDO ........2-726 Write File ..............2-819 Write Variable Class 3 Explicit ........2-696 Write Variable to File ..........2-794 Write Variable UCMM Explicit ........
  • Page 988 Index Index-10 NJ-series Instructions Reference Manual (W502)
  • Page 990 The Netherlands IL 60173-5302 U.S.A. Tel: (31)2356-81-300/Fax: (31)2356-81-388 Tel: (1) 847-843-7900/Fax: (1) 847-843-7787 © OMRON Corporation 2011 All Rights Reserved. OMRON (CHINA) CO., LTD. OMRON ASIA PACIFIC PTE. LTD. In the interest of product improvement, Room 2211, Bank of China Tower, No.

This manual is also suitable for:

Nj501-1300Nj501-1400

Table of Contents