Mitsubishi QD51 Programming Manual
Mitsubishi QD51 Programming Manual

Mitsubishi QD51 Programming Manual

Logic controller
Hide thumbs Also See for QD51:
Table of Contents

Advertisement

Quick Links

AD51H-BASIC
Programming Manual
(Command)
Mitsubishi Programmable
Logic Controller
QD51
QD51-R24
A1SD51S
AD51H-S3

Advertisement

Table of Contents
loading
Need help?

Need help?

Do you have a question about the QD51 and is the answer not in the manual?

Questions and answers

Summary of Contents for Mitsubishi QD51

  • Page 1 AD51H-BASIC Programming Manual (Command) QD51 Mitsubishi Programmable QD51-R24 Logic Controller A1SD51S AD51H-S3...
  • Page 2: Safety Precautions

    • SAFETY PRECAUTIONS • (Always read these instructions before using this equipment.) Before using this product, please read this manual and the relevant manuals introduced in this manual carefully and pay full attention to safety to handle the product correctly. The instructions given in this manual are concerned with this product.
  • Page 3: Revisions

    This manual confers no industrial property rights or any rights of any other kind, nor does it confer any patent licenses. Mitsubishi Electric Corporation cannot be held responsible for any problems involving industrial property rights which may occur as a result of using the contents noted in this manual.
  • Page 4: Table Of Contents

    INTRODUCTION Thank you for purchasing the MELSEC-Q, A series PLC. Please read this manual carefully so that equipment is used to its optimum. CONTENTS SAFETY PRECAUTIONS..........................A- 1 REVISIONS ..............................A- 2 CONTENTS..............................A- 3 How to use this manual..........................A-13 Regarding Compiler BASIC ...........................A-13 About Module Names ............................A-13 1 OVERVIEW 1- 1 to 1- 3...
  • Page 5 3 LET'S CREATE AND EXECUTE A PROGRAM 3 - 1 to 3- 49 3.1 Creating a Program..........................3- 3 3.2 Executing and Editing a Program......................3- 5 3.2.1 Executing a program ........................3- 5 3.2.2 If an error occurs ..........................3- 5 3.2.3 Editing a program ..........................
  • Page 6 4 THE EXCHANGE BETWEEN THE PLC AND BUFFER MEMORY 4-- 1 to 4- 21 4.1 PLC Numeric Data and BASIC Numeric Data ..................4- 1 4.2 The Exchange with the PLC ........................4- 2 4.2.1 Control tables ........................... 4- 2 4.2.2 PLC station number .........................
  • Page 7 9 THE CONCEPT OF ERROR HANDLING 9- 1 to 9- 3 9.1 Definition of Error Handling........................9- 1 9.2 How to Determine the Type of Error and the Location where the Error Occurred ....... 9- 2 9.3 Precautions Regarding Error Handling ....................9- 3 10 PROGRAM DEBUGGING 10- 1 to 10- 3 10.1 Sequence of Debugging Programs Executed Simultaneously in Multitasking.........
  • Page 8 CVSMBF ( Converts into the internal expression of a floating point real number that is used by A2A and A3A ) ........................... 11-42 DATA ( Specifies data to be read by READ ) ....................11-44 DATE$ ( Sets year, month, and day to the PLC CPU, and reads ) .............. 11-46 DEFDBL ( Defines variables that start with a character of the specified range as the double precision real number type ) ......................
  • Page 9 KILL ( Deletes a file ) ............................ 11-106 KINSTR ( Searches through a character string containing full-byte characters for the specified character string and displays the first location in which it is found ) ........11-108 KLEN ( Returns the number of characters of the character string that includes full-byte characters ) ..11-110 KMID$ ( Returns the partial character string that starts at the specified position of a character string that includes full-byte characters ) ................
  • Page 10 OPEN ( Opens a file and enables it for input/output processing ) .............. 11-168 PCRD 11-170 PCRD - Processing Code 1 - (Reading device memory data) ..............11-172 PCRD - Processing Code 2 - (Reading device memory registered to be monitored by the PCWT instruction) ......................
  • Page 11 PCWT - Processing Code 533 - (Writing data to the buffer memory of the intelligent functional module of the Q/QnA series PLC CPU) ................11-335 PRINT ( Displays data on the screen ) ......................11-344 PRINT USING ( Displays a character string or numeric value in the specified format ) ......11-345 PRINT# ( Writes data to a sequential file ) ....................
  • Page 12 ZBAS ( Returns the number of the BASIC task area in which the program currently being created ) ..11-405 ZCLOSE ( Closes a communication channel ) ................... 11-406 ZCNTL 11-407 ZCNTL - Processing Code 16 - (Specifying communication parameter)..........11-409 ZCNTL - Processing Code 17 - (Reading communication parameters) ..........
  • Page 13 APPENDIX App- 1 to App-42 Appendix 1 File Name..........................App- 1 Appendix 1.1 Drive Number.........................App- 1 Appendix 1.2 System Name ........................App- 2 Appendix 1.3 File Name........................App- 3 Appendix 1.4 Wild Cards........................App- 4 Appendix 1.5 Precautions when Using Wild Cards................App- 5 Appendix 1.6 The Efficient Way to Assign a File Name ..............App- 5 Appendix 2 Precautions on Interrupt Processing..................App- 6 Appendix 3 Instructions and Functions that Switch Between Programs to be Executed in Multitasking...........................App- 7...
  • Page 14: How To Use This Manual

    • • • • • Refers to operations only for the QD51-R24. QD51 (-R24) • • • • • Refers to common items for both the QD51 and the QD51-R24. Communication Module • • • • • Refers to common items for all modules.
  • Page 15: Overview

    Please refer to the following manuals as necessary when using AD51H-BASIC. • AD51H-S3 User's Manual (IB (Name) -68350) • A1SD51S User's Manual (Details) (SH (Name) -3523) • QD51 (-R24) User's Manual (Details) (SH (Name) -080092) SW1IVD-AD51HP/SW1NX-AD51HP Operating Manual (IB (Name) -68674) MS-DOS is a trademark of Microsoft Corporation in the U.
  • Page 16: Features

    The communication module supports multitask processing. Because of this, up to 8 BASIC programs can be executed simultaneously on the AD51H-S3, and up to 2 BASIC programs can be executed simultaneously on the A1SD51S/QD51 (- R24). In such cases, the communication module sequentially switches the execution of each program, so it appears to the user as if the multiple programs are running simultaneously.
  • Page 17: Symbols Used In This Manual

    1 OVERVIEW MELSEC-Q 1.2 Symbols Used in This Manual This manual uses the following symbols (used especially within Format ) for descriptive purposes. The symbols and their meanings are described in the following. Be sure to understand them fully before starting to create programs. Note that the symbols shown below should not be entered when actually entering the instructions and arguments related to the description sections that use these symbols.
  • Page 18: The Basics Of Ad51H-Basic

    2 THE BASICS OF AD51H-BASIC MELSEC-Q 2 THE BASICS OF AD51H-BASIC 2.1 Preparation to Use AD51H-BASIC In order to edit or execute a program using AD51H-BASIC (hereinafter referred to as BASIC), it is necessary to change the mode of the communication module to edit mode, then connect the console, and start up BASIC.
  • Page 19 2 THE BASICS OF AD51H-BASIC MELSEC-Q (4) This allows editing and execution of BASIC programs and an ‘OK’ is displayed on the console screen. BASIC can now be used. AD51H-BASIC ON-LINE PROGRAMING Ver X.X Using the START instruction in system mode starts up BASIC and changes the mode of the communication module into a mode referred to as "online programming mode."...
  • Page 20 • AD51H-S3, A1SD51S • • • • • Use the rotary switch of the main module (Mode switch) • QD51 (-R24) • • • • • Perform GPPW switch settings See the user’s manual for each communication module for detailed descriptions of each mode and changing between them.
  • Page 21: Direct Mode And Program Mode

    2 THE BASICS OF AD51H-BASIC MELSEC-Q 2.2 Direct Mode and Program Mode • Direct mode When a BASIC instruction is entered and the Enter key is pressed while “OK” is displayed on the console screen, BASIC will execute the instruction immediately. This is referred to as execution in direct mode.
  • Page 22: Spaces And Keywords

    2 THE BASICS OF AD51H-BASIC MELSEC-Q (2) Labels <Labels> are terms in lines that are specified as branch destinations for instructions such as GOTO, GOSUB, and RESTORE, or lines that are specified as the next data to be read. They are placed next to line numbers. When specifying a line that includes <Label>...
  • Page 23: Characters Used In Basic

    2 THE BASICS OF AD51H-BASIC MELSEC-Q 2.5 Characters Used in BASIC The following characters are used in BASIC. • Uppercase alphabet ABCDEFGHIJKLMNOPQRSTUVWXYZ • Lowercase alphabet abcdefghijklmnopqrstuvwxyz • Numbers 0123456789 • Special characters (Space) ! ” # $ % & ‘ ( ) * + - , . / : ; < > = ? @ [ ] ¥ ^ { } | – •...
  • Page 24 2 THE BASICS OF AD51H-BASIC MELSEC-Q The special characters have the following meanings in BASIC statements. Special Symbol Name Meaning Space Used to separate instructions and parameters. Exclamation Indicates single-precision type. “ Double quotation mark Symbols for enclosing a character string. Number sign File number symbol, indicates double-precision type.
  • Page 25 2 THE BASICS OF AD51H-BASIC MELSEC-Q Equal sign > Greater-than sign Question mark Substitution for the PRINT instruction ? A, B Example ?FRE(0) ?TIME$ Commercial at Left bracket ¥ Yen sign Integer division symbol Right bracket Accent circonflexe Power symbol (upward arrow head) Underscore Accent grave...
  • Page 26: What Are Instructions And Functions

    2 THE BASICS OF AD51H-BASIC MELSEC-Q 2.6 What are Instructions and Functions? Only instructions or functions that follow the BASIC syntax can be written in BASIC statements. The section describes what instructions and functions are. • Instructions Each BASIC instruction instructs a certain processing to take place. For example, when the PRINT instruction is used, characters will be displayed on the screen.
  • Page 27: Constants

    2 THE BASICS OF AD51H-BASIC MELSEC-Q 2.7 Constants Constants are fixed values used when a BASIC program is executed. There are two types of constants: character constants and numeric constants. 2.7.1 Character string constants Character string constants are any character strings that can be contained in a character set up to a maximum of 255 characters enclosed by quotation marks (“).
  • Page 28: Single-Precision And Double-Precision Numeric Constants

    2 THE BASICS OF AD51H-BASIC MELSEC-Q (4) Hexadecimal Constants A hexadecimal number (0 through 9, A through F) is preceded by &H. Example &H76 • • • • • &H32F • • • • • (5) Octadecimal Constants An octadecimal number (0 through 7) is preceded by &0 or &. Example &0347 •...
  • Page 29: Variables

    2 THE BASICS OF AD51H-BASIC MELSEC-Q 2.8 Variables Variables are names that are used to represent values used within BASIC programs. Values of variables can be defined by the programmer or assigned as calculation results. The values of numeric variables are 0 and values of character string variables are empty character strings until their proper values are defined.
  • Page 30: Array Variables

    2 THE BASICS OF AD51H-BASIC MELSEC-Q 2.8.2 Array variables • Arrays are groups of values that can be referenced using the same variable name. • Each element within an array is referred to via the array variable name. Array variable names can be used within BASIC instructions and functions in the same manner as variables.
  • Page 31: Special Variables (How To Use B@ And W@)

    2 THE BASICS OF AD51H-BASIC MELSEC-Q 2.8.3 Special variables (How to use B@ and W@) • These variables are used to read/write from/to each device of the communication module from within BASIC programs. • There are the following 4 types of special variables. B@ (EM, expression) •...
  • Page 32 2 THE BASICS OF AD51H-BASIC MELSEC-Q • Data, when being read, is represented by the value 1 when ON and 0 when OFF. • Only bit 0 of the value stored in the specified value or specified variable is valid for data being written.
  • Page 33 2 THE BASICS OF AD51H-BASIC MELSEC-Q • When writing 32-bit data, the data is first set in array variables of integer format using CDBI and CSNI instructions, then written to each device. Example 100 DIM A%(1) 110 CDBI 123456!,A%(0) • • • • • “123456”...
  • Page 34: Type Conversion

    2 THE BASICS OF AD51H-BASIC MELSEC-Q 2.9 Type Conversion BASIC changes the type of numeric constants to another type as needed. In this case, it follows the following rules. (1) When a numeric constant of a certain type is assigned to a numeric variable of a different type, the value of the constant will be changed to the type declared in the variable name and stored.
  • Page 35: Expressions And Operators

    2 THE BASICS OF AD51H-BASIC MELSEC-Q (4) When a numeric value of fixed decimal point format is converted to an integer, the decimal fraction is disregarded. Example 10 C%=55.88 20 PRINT C% (5) If a single-precision value is assigned to a double-precision variable, only the rounded first seven digits of the converted numeric value will be valid.
  • Page 36 2 THE BASICS OF AD51H-BASIC MELSEC-Q In order to change the order of operations, parentheses are used. When a portion of an expression is surrounded by parentheses, the operation within the parentheses are performed first. When an operator is followed by another operator, parentheses must be used.
  • Page 37: Relational Operators

    2 THE BASICS OF AD51H-BASIC MELSEC-Q • Division when overflow occurs or when the divisor is 0. If a divisor becomes 0 in a division while executing an expression, a “Division by zero” error will occur. Also, if 0 is lifted to a negative power, a “Division by zero” error will occur.
  • Page 38: Logical Operators

    2 THE BASICS OF AD51H-BASIC MELSEC-Q 2.10.3 Logical operators Logical operators perform bitwise operations or Boolean operations. Logical operators provide the value “True” (other than 0) or “False” (0). In an expression, logical operations will be performed after arithmetic calculations and relational calculations.
  • Page 39 2 THE BASICS OF AD51H-BASIC MELSEC-Q Note • Operations involving logical operators are performed after converting the numeric constant or numeric variable to an integer within the range from –32768 to +32767 (expressed as two’s-compliment number if negative). If the value exceeds the range from –32768 to +32767, an Overflow error will occur.
  • Page 40: Character String Operations

    2 THE BASICS OF AD51H-BASIC MELSEC-Q 2.11 Character String Operations Character strings can be connected using the operator +. Example 10 A$=" FILE":B$=" NAME" 20 PRINT A$+B$ 30 PRINT" NEW"+A$+B$ FILENAME NEWFILENAME Also, relational operations can be performed on character strings using the relational operators shown below.
  • Page 41: Priority Order Of Operations

    2 THE BASICS OF AD51H-BASIC MELSEC-Q 2.12 Priority Order of Operations Operations are performed in the following order. Operators on the same level take priority from left to right. Expressions enclosed in parentheses Functions Exponent (power)^ Negative sign (-) ¥ +, - Relational operators (<, >, =, etc.) 2 - 24...
  • Page 42: Let's Create And Execute A Program

    3 LET'S CREATE AND EXECUTE A PROGRAM MELSEC-Q 3 LET'S CREATE AND EXECUTE A PROGRAM This chapter describes how to create and execute a program, as well as how to use basic instructions in AD51H-BASIC. Please try to actually create a program and test it to see if it yields the proper results. The procedures described below assume that the following system configuration is used.
  • Page 43 3 LET'S CREATE AND EXECUTE A PROGRAM MELSEC-Q • If equipment other than an IBM/AT compatible personal computer is used as a console, the keys in the manual should be substituted with the appropriate keys as follows. Enter Carriage Return Key (Typically, corresponds to the CR key) Ctrl Control Key (Typically, corresponds to the CTRL and CNTL keys) Insert...
  • Page 44: Creating A Program

    3 LET'S CREATE AND EXECUTE A PROGRAM MELSEC-Q 3.1 Creating a Program In order to create a program, it is necessary to make the console usable first. Start up the system so that AD51H-BASIC can be used on the console. The outline of the system startup procedures are described in Section 2.1.
  • Page 45 3 LET'S CREATE AND EXECUTE A PROGRAM MELSEC-Q Enter line 10 as shown in the program example and press the Enter key. REM Calculation of compound interest Enter The line number 20 will be displayed on the screen. Enter the instructions until you reach line 70 in the same way.
  • Page 46: Executing And Editing A Program

    3 LET'S CREATE AND EXECUTE A PROGRAM MELSEC-Q 3.2 Executing and Editing a Program 3.2.1 Executing a program Let's execute the program that you entered in Section 3.1. Enter the following while "OK" is displayed on the console. RUN Enter The RUN instruction is used to execute the program stored in the memory.
  • Page 47: Editing A Program

    3 LET'S CREATE AND EXECUTE A PROGRAM MELSEC-Q 3.2.3 Editing a program If there is an error in a created program or if a program requires improvement, the program must be edited. There are two ways of editing a program. (1) Line-by-line edition This is a way of re-entering one line of a program at a time.
  • Page 48 3 LET'S CREATE AND EXECUTE A PROGRAM MELSEC-Q (2) Editing using the screen editor This is a way of editing the program by displaying the program to be edited on the screen and moving around the cursor. It is possible to edit only the necessary areas, so this is easier than line-by-line edition.
  • Page 49 3 LET'S CREATE AND EXECUTE A PROGRAM MELSEC-Q (3) Examples of editing using the screen editor. Overwriting • • • • • • • • • • • • •Change line 20 to B=7. LIST LIST Press the Press the 10 A=2 10 A=2 to move the...
  • Page 50 3 LET'S CREATE AND EXECUTE A PROGRAM MELSEC-Q Changing a line number • • • • Caution is needed when changing line numbers. Line 10 should be changed to line 15. Move the Press and then cursor to key. Enter line 10.
  • Page 51: Saving And Loading A Program

    This area is used to store data files used by programs and File Area A6MEM-512KA-W programs that are saved by the SAVE instruction in BASIC. MITSUBISHI Input and output to these areas can only be performed under the following conditions. Executable program area Programs may be registered in system mode.
  • Page 52: Saving A Program

    3 LET'S CREATE AND EXECUTE A PROGRAM MELSEC-Q 3.3.2 Saving a program Use the SAVE instruction to save the program to the file area of a memory card, floppy disk (FD), or hard disk (HD). The SAVE instruction is entered in the following format. SAVE "[Drive Number] : [System Name¥][File Name]"...
  • Page 53 Total.BAS Line1.BAS Differential.BAS MEMORY CARD A6MEM-512KA-W Composition.BAS DailyReport.BAS MITSUBISHI Assembly.BAS MonthlyReport.BAS The files become easier to manage by defining program groups and saving a program to either one of the groups as follows. Line Monitor Line1.BAS Composition.BAS Assembly.BAS...
  • Page 54 3 LET'S CREATE AND EXECUTE A PROGRAM MELSEC-Q • A system name can contain up to 8 characters. When Kanji characters are used in a system name, one Kanji character is equivalent to two alphabet characters. Therefore, only four kanji characters can be used for a system name. •...
  • Page 55 'KEISAN. No1' in the A drive of the console. MEMORY CARD A6MEM-512KA-W MITSUBISHI Store necessary programs with caution. Also, make sure to periodically back up programs stored on memory cards or FD. See the AD51H-BASIC software package operating manual for how to take backups.
  • Page 56: Loading Programs

    3 LET'S CREATE AND EXECUTE A PROGRAM MELSEC-Q 3.3.3 Loading programs Programs stored in the file area of a memory card, FD, or HD can be read into the communication module's memory using the LOAD instruction. The LOAD instruction is entered in the following format. LOAD "[Drive Name] : [System Name¥][File Name]"...
  • Page 57: Organizing Memory Cards And Fds

    Let's assume that the files are stored in the following manner in the file area of the memory card in MEMORY CARD 2 III.BAS EFG.BAS MEMORY CARD HST.BAS A6MEM-512KA-W JJR.DAT C.BAS MITSUBISHI TEST.BAS H.DAT 123.BAS ……………… FILES"1:" This displays names of files without a system name in the file area of the memory card.
  • Page 58 3 LET'S CREATE AND EXECUTE A PROGRAM MELSEC-Q ………… FILES" 1:ABC@" This displays the names of the files stored under system name ABC in the file area of the memory card. III BAS:EFG BAS: ……… This displays the name of the file JR.DAT FILES"...
  • Page 59: Renaming Files

    Rename file 'NO1.BAS' under system name 'TEST' in the memory card mounted in MEMORY CARD 2 to 'N02.BAS.' NAME"1 : TEST¥NO1.BAS" SAVE"1 : TEST¥NO1" AS"1 : TEST¥NO2.BAS" MEMORY CARD A6MEM-512KA-W MITSUBISHI TEST No1.BAS NAME Instruction TEST No2.BAS LOAD"1 : TEST¥NO2"...
  • Page 60: Deleting Files

    Usage examples Delete file 'NO1.BAS' under system name 'TEST' in the memory card mounted in MEMORY CARD 2 . SAVE"1 : TEST@ NO1" MEMORY CARD A6MEM-512KA-W KILL" 1 : TEST@ NO1.BAS" MITSUBISHI TEST NO1.BAS MEMORY CARD A6MEM-512KA-W TEST MITSUBISHI Files deleted using the KILL instruction cannot be recovered.
  • Page 61: Specifying Data

    3 LET'S CREATE AND EXECUTE A PROGRAM MELSEC-Q 3.5 Specifying Data There are three ways of assigning a value to a BASIC variable. Use an assignment statement. (e.g., A=1, B=120) Input from the keyboard or other device. Use the READ - DATA instructions. Method 2) is described in Section 3.11, and Chapter 4, 6, and 7.
  • Page 62: Preparing Groups Of Data

    3 LET'S CREATE AND EXECUTE A PROGRAM MELSEC-Q 3.5.2 Preparing groups of data Use the READ and DATA instructions in order to prepare a group of data to be assigned. These instructions use the READ instruction to obtain the data specified by the DATA instruction.
  • Page 63 3 LET'S CREATE AND EXECUTE A PROGRAM MELSEC-Q Use the RESTORE instruction in order to use values of the same DATA instruction again. The following illustrates what happens when the RESTORE instruction is used. 10 DATA 7, 8 A value in the DATA 20 READ A, B instruction in line 10 is...
  • Page 64: Jumps And Loops

    3 LET'S CREATE AND EXECUTE A PROGRAM MELSEC-Q 3.6 Jumps and Loops BASIC programs are typically executed in increasing order of line numbers. However, there are instances when it is better that the order of execution is changed. AD51H- BASIC has the following instructions to change the order in which execution is carried out in a program.
  • Page 65: Loop For The Number Of Times Specified

    3 LET'S CREATE AND EXECUTE A PROGRAM MELSEC-Q 3.6.3 Loop for the number of times specified Use the FOR-NEXT instructions to execute certain instructions for a certain number of times. Consider the following program. The FOR-NEXT instructions 10 FOR N=1 TO 5 repeat the instructions between 20 PRINT N;...
  • Page 66: Loop While A Certain Condition Is Met

    3 LET'S CREATE AND EXECUTE A PROGRAM MELSEC-Q 3.6.4 Loop while a certain condition is met Use the WHILE-WEND instructions to repeat execution of instructions only while a certain condition is met. This is a condition that is true as long as N is less than 4. 10 N=0 0 1 2 3 20 WHILE N<4...
  • Page 67: Letting Basic Make Decisions

    3 LET'S CREATE AND EXECUTE A PROGRAM MELSEC-Q 3.7 Letting BASIC Make Decisions In BASIC, a program can be branched into different instructions based on whether or not a specified condition is met. 3.7.1 Condition specification The following symbols are used to specify conditions. Symbol Meaning Example...
  • Page 68: Judgment Instructions

    3 LET'S CREATE AND EXECUTE A PROGRAM MELSEC-Q 3.7.2 Judgment instructions Use the IF instruction to make a judgment. The IF instruction is entered in the format shown below. Instruction Instruction executed when the Condition or executed when the THEN ELSE condition or logical logical expression...
  • Page 69 3 LET'S CREATE AND EXECUTE A PROGRAM MELSEC-Q REMARK When single-precision or double-precision values are compared using the equal sign, there are cases where the result is incorrect. Example 10 A=0 20 FOR I=1 TO 1000 ………………… Since 0.0001 is added 1000 30 A=A+0.0001 times, A should equal 0.1.
  • Page 70: How To Use Arrays

    3 LET'S CREATE AND EXECUTE A PROGRAM MELSEC-Q 3.8 How to Use Arrays Let's assume that a quantity of 100 data must be assigned to variables. Using A1, A2 ... as variables, for example. We need 100 lines of code. 10 A1=52 20 A2=60 30 A3=17...
  • Page 71: Number Of Dimensions In An Array

    3 LET'S CREATE AND EXECUTE A PROGRAM MELSEC-Q Arrays are not limited to just numeric values. There are types of array that handle characters as well. In addition, when using numeric type arrays, different types of numbers can be defined, such as integers, single-precision, and double-precision. (For details on defining variable types, see the sections for the DEFINT, DEFSNG, and DEFDBL instructions.) A$(n)
  • Page 72: Using Subroutines

    3 LET'S CREATE AND EXECUTE A PROGRAM MELSEC-Q 3.9 Using Subroutines There are cases when a certain process is repeatedly performed within a program. For example, if making a bar graph using the character " ," 10 READ A 20 FOR I=1 TO A 30 PRINT "...
  • Page 73: Displaying Characters On The Screen

    3 LET'S CREATE AND EXECUTE A PROGRAM MELSEC-Q 3.10 Displaying Characters on the Screen The PRINT instruction is used to display text on the screen. Since this instruction is mostly used, '?' is read as PRINT in BASIC. Example Using '?' for 'PRINT' is really convenient.
  • Page 74: Functions For Displaying Characters

    3 LET'S CREATE AND EXECUTE A PROGRAM MELSEC-Q The following illustrates cases where "," (comma) is used. Example A=100 A$= " ABCD" B=-50 B$= " EFGH" PRINT A,B,A+B PRINT A$,B$,A$+B$ ABCD EFGH ABCDEFGH characters characters characters characters BASIC manages one line on the screen by separating them into areas of 14 characters.
  • Page 75 3 LET'S CREATE AND EXECUTE A PROGRAM MELSEC-Q 10 INPUT A$ 20 INPUT B$ 30 PRINT A$,B$ 40 PRINT A$;TAB(20);B$ ? 1234567 ? 3478 1234567 3478 1234567 3478 ? 123456789012345 ? 1000 123456789012345 1000 123456789012345 1000 The spacing is always constant if the TAB function is used.
  • Page 76: Displaying Characters To An Arbitrary Position

    3 LET'S CREATE AND EXECUTE A PROGRAM MELSEC-Q 3.10.2 Displaying characters to an arbitrary position Characters can only be controlled in lateral direction on the screen with separating with delimiters ";" and "," as well as the TAB and SPC functions. However, there may be a case where you desire a text to be at any position in vertical direction as well.
  • Page 77 3 LET'S CREATE AND EXECUTE A PROGRAM MELSEC-Q The following shows how to use the LOCATE instruction: LOCATE position in horizontal direction, position in vertical direction This allows the specification of the screen display position, and then the PRINT instruction can be used to display characters. Example 10 CLS This instruction clears the screen...
  • Page 78: Entering Data Using The Keyboard

    3 LET'S CREATE AND EXECUTE A PROGRAM MELSEC-Q 3.11 Entering Data Using the Keyboard There are two methods to notify data entered via keyboard to BASIC. One method is using the INPUT instruction, which BASIC pauses the program and waits for an input. The other is the function INKEY$ that simply checks for keyboard status and doesn't stop the program.
  • Page 79 3 LET'S CREATE AND EXECUTE A PROGRAM MELSEC-Q The INPUT instruction pauses the program until data is entered and the Enter key is pressed. When you don not wish to pause the program, the INKEY$ function is used. the following shows an example program: Example 10 A$=INKEY$ 20 PRINT A$...
  • Page 80: Printing To The Printer

    3 LET'S CREATE AND EXECUTE A PROGRAM MELSEC-Q 3.12 Printing to the Printer The values of constants, variables, and arrays can all be printed to the printer, just as they can be displayed on the screen. When sending data to a printer, the ZLDV instruction checks to see where the printer is connected.
  • Page 81: Character Processing

    3 LET'S CREATE AND EXECUTE A PROGRAM MELSEC-Q 3.13 Character Processing 3.13.1 Types of characters There are three basic categories of characters used in BASIC. • Half-byte characters • • • • • These are characters that can be input from the (1-byte characters) keyboard and include numbers, alphabet characters, English symbols, Katakana, etc.
  • Page 82 3 LET'S CREATE AND EXECUTE A PROGRAM MELSEC-Q (2) Finding the length of a character string The LEN function is used to find the length of a character string. 10 A$= "ABCDE" 20 A= LEN (A$) 30 PRINT A 40 END (3) Converting characters to ASCII code equivalents Each character used in BASIC has a corresponding ASCII code number.
  • Page 83 3 LET'S CREATE AND EXECUTE A PROGRAM MELSEC-Q (4) Conversion of numbers and characters The following calculation cannot be performed even if the character string is fully comprised of numbers. Example A$= " 12345" B=1156 PRINT A$+B Type mismatch The VAL function is used when treating a character string comprised of only numbers as a numeric value.
  • Page 84 3 LET'S CREATE AND EXECUTE A PROGRAM MELSEC-Q (5) Processes using full-byte characters As shown in Section 3.13.1, one full-byte character (Kanji) uses the amount of space required for two half-byte characters both for display and storage. For this reason, the following consideration must be taken when handling a character string containing full-byte characters in half-byte character increments.
  • Page 85: Processes In Full-Byte Character Increments

    3 LET'S CREATE AND EXECUTE A PROGRAM MELSEC-Q 3.13.3 Processes in full-Byte character increments As shown in (5) in Section 3.13.2, a single full-byte character (Kanji character) is considered as taking up the space equivalent to two single-byte characters in the character processing in half-byte character increments.
  • Page 86 3 LET'S CREATE AND EXECUTE A PROGRAM MELSEC-Q (3) Converting full-byte characters to code equivalents Each full-byte character has a corresponding JIS code. JIS$ and KNJ$ are used for conversion between full-byte character and JIS codes. Please note that the character codes for these functions use character strings.
  • Page 87: About Types Of Numeric Relationships

    3 LET'S CREATE AND EXECUTE A PROGRAM MELSEC-Q 3.14 About Types of Numeric Relationships There are functions in BASIC that allow trigonometric functions to be used. The following describes how to express the trigonometric functions that can be used in BASIC.
  • Page 88: Executing A Large Program By Dividing It Up

    3 LET'S CREATE AND EXECUTE A PROGRAM MELSEC-Q 3.15 Executing a Large Program by Dividing it up A large program that doesn't fit into memory cannot be executed. However, if a large program can be divided and saved into smaller programs and then executed one by one, it is possible to yield the same result of running one large program.
  • Page 89 3 LET'S CREATE AND EXECUTE A PROGRAM MELSEC-Q (2) When the contents have to be transferred The CHAIN instruction is used when the variable used in the program currently being executed must be transferred to the next program. When all of the used variables are to be transferred, the ALL option of the CHAIN instruction is used.
  • Page 90 3 LET'S CREATE AND EXECUTE A PROGRAM MELSEC-Q (3) When a portion of the program is shared The MERGE and DELETE options of the CHAIN instruction are used when a certain portion of the current program is to be switched with another program. 70 PRINT "Program B executed!!"...
  • Page 91: The Exchange Between The Plc And Buffer Memory

    4 THE EXCHANGE BETWEEN THE PLC AND BUFFER MEMORY MELSEC-Q 4 THE EXCHANGE BETWEEN THE PLC AND BUFFER MEMORY 4.1 PLC Numeric Data and BASIC Numeric Data Data handled within the PLC are generally integers. It handles integers (not including decimals) between –32768 and 32767 for one word (16 bits) and –2147483648 through 2149483647 for two words (32 bits).
  • Page 92: The Exchange With The Plc

    4 THE EXCHANGE BETWEEN THE PLC AND BUFFER MEMORY MELSEC-Q 4.2 The Exchange with the PLC The following data exchange is performed between the PLC CPU and BASIC. • Read and write of devices within the PLC CPU • Read and write of the buffer memory within the special function module •...
  • Page 93: Plc Station Number

    4 THE EXCHANGE BETWEEN THE PLC AND BUFFER MEMORY MELSEC-Q 4.2.2 PLC station number In AD51H-BASIC, not only can the PLC attached to the communication module be accessed, but PLCs of other stations that are data-linked via the MELSECNET can be accessed as well.
  • Page 94 4 THE EXCHANGE BETWEEN THE PLC AND BUFFER MEMORY MELSEC-Q (c) When the CPU (self station) with the communication module attached is a MELSEC three-tier master station, data from the self station and master station of the two-tier loop and all local stations and remote I/O stations within the three-tier loop can be accessed.
  • Page 95 4 THE EXCHANGE BETWEEN THE PLC AND BUFFER MEMORY MELSEC-Q (2) MELSECNET/10 Network parameter settings using the GPP function will be required for access to PLCs of other stations. For details on network parameter settings, refer to the MELSECNET/10 Network System Reference Manual.
  • Page 96 4 THE EXCHANGE BETWEEN THE PLC AND BUFFER MEMORY MELSEC-Q (a) MELSECNET/10 Multi-Tiered System When the CPU (self station) with the communication module attached is a MELSECNET/10 control station (Mp) or standard station (Ns), data from the self station and all stations can be accessed. Communication Control Station 1Mp1 Standard Station 2Ns2...
  • Page 97 4 THE EXCHANGE BETWEEN THE PLC AND BUFFER MEMORY MELSEC-Q 3) When the CPU (self station) with the communication module attached is a MELSEC/10 remote station (R), data from the self station and the master stations (MR) within the same network, control stations (Mp) and standard stations (Ns, N) from other networks can be accessed.
  • Page 98 4 THE EXCHANGE BETWEEN THE PLC AND BUFFER MEMORY MELSEC-Q (3) Mixed System with MELSECNET/10 and MELSECNET (II) When the CPU (self station) with the communication module attached is a MELSECNET/10 control station (Mp) or a standard station (Ns), data from the self station and all MELSECNET/10 stations can be accessed.
  • Page 99 4 THE EXCHANGE BETWEEN THE PLC AND BUFFER MEMORY MELSEC-Q When the CPU (self station) with the communication module attached is a MELSECNET/10 standard station (N), data from the self station and control stations (Mp) of the same network can be accessed. Local Station L3 Control Station 1Mp1 Standard Station 1N2...
  • Page 100 4 THE EXCHANGE BETWEEN THE PLC AND BUFFER MEMORY MELSEC-Q When the CPU (self station) with the communication module attached is a MELSECNET/10 remote station (R), data from the self station and master station (MR) of the same network and control stations (Mp) and standard stations (Ns, N) of other networks can be accessed.
  • Page 101 4 THE EXCHANGE BETWEEN THE PLC AND BUFFER MEMORY MELSEC-Q When the CPU (self station) with the communication module attached is a MELSECNET (II) local station (L), data from the self station and MELSECNET (II) master stations (M) can be accessed. Communication Module Control Station 1Mp1 Local Station L3...
  • Page 102: Choosing A Process

    4 THE EXCHANGE BETWEEN THE PLC AND BUFFER MEMORY MELSEC-Q 4.2.3 Choosing a process Process requests of PCRD and PCWT instructions are specified using values referred to as process codes. For details, see the descriptions of the PCRD and PCWT instructions.
  • Page 103: Device Number Designation

    4 THE EXCHANGE BETWEEN THE PLC AND BUFFER MEMORY MELSEC-Q 4.2.5 Device number designation The PLC devices are specified using "device codes" and "device numbers." (1) For A series The device codes and usable device numbers are as follows. Device Code Device Usable Device Number 1 (&H1)
  • Page 104 4 THE EXCHANGE BETWEEN THE PLC AND BUFFER MEMORY MELSEC-Q (2) Q/QnA series The device codes and usable device numbers are as follows. Device Code Device Usable Device Number 156 (&H9C) X (Input) 0 to 1FFF 157 (&H9D) Y (Output) 0 to 1FFF 144 (&H90) M (Internal relay)
  • Page 105: Storage Area For Reading And Writing Data

    4 THE EXCHANGE BETWEEN THE PLC AND BUFFER MEMORY MELSEC-Q 4.2.6 Storage area for reading and writing data The method in which data is read and written from the PLC device must be specified. Integer type variables, array/character type variables, and arrays can be used as data storage areas.
  • Page 106 4 THE EXCHANGE BETWEEN THE PLC AND BUFFER MEMORY MELSEC-Q (b) Word Devices When a word device is designated in word units, one point of device number data is stored per variable. A% (0) When an integer array is designated, the data is stored A% (1) and set from element 0.
  • Page 107 4 THE EXCHANGE BETWEEN THE PLC AND BUFFER MEMORY MELSEC-Q • Word Units Continuous device numbers are read in blocks of 16 points when the bit device is designated in word units. The 16 points of data that has been read are separated into 8 points in the first half and 8 points in the second half.
  • Page 108 4 THE EXCHANGE BETWEEN THE PLC AND BUFFER MEMORY MELSEC-Q (b) Word Devices The data that has been read from the designated word device in word units is separated into 8 points in the first half and 8 points in the second half. Then the 8 points of ON/OFF data for the device numbers are treated as a single JIS8 code and it is stored using the corresponding characters.
  • Page 109 4 THE EXCHANGE BETWEEN THE PLC AND BUFFER MEMORY MELSEC-Q (3) When using an internal device as a data storage area (when using ED and EM) (a) Bit device Bit devices are handled in bit units or word units. The following describes each of them.
  • Page 110: Communication With The Buffer Memory

    4 THE EXCHANGE BETWEEN THE PLC AND BUFFER MEMORY MELSEC-Q 4.3 Communication with the Buffer Memory There are 6 Kbytes of buffer memory in the communications module that can be read and written by the FROM and TO instructions from the PLC. Vast amounts of data can be communicated with the PLC CPU using this area.
  • Page 111 4 THE EXCHANGE BETWEEN THE PLC AND BUFFER MEMORY MELSEC-Q • For character data Character Variables, Character Array Variables Buffer Memory character character character character character character RD $ <CR> PLC CPU Device = "A" ="D" = "5" = "1" = "H"...
  • Page 112: Communication Using General-Purpose Input/Output

    5 COMMUNICATION USING GENERAL-PURPOSE INPUT/OUTPUT MELSEC-Q 5 COMMUNICATION USING GENERAL-PURPOSE INPUT/OUTPUT The communication module can communicate with PLC CPU using I/O devices (Input X, Output Y). Output Y Input X (1) The number of I/O devices and their numbers will vary depending on communications module used.
  • Page 113 5 COMMUNICATION USING GENERAL-PURPOSE INPUT/OUTPUT MELSEC-Q The following describes the input device X viewed from the PLC CPU when the starting address is . Values specified by Input Device X of Sequence Program Signal Name Special Variable B@ X00 + to X0F + Not used X10 +...
  • Page 114 5 COMMUNICATION USING GENERAL-PURPOSE INPUT/OUTPUT MELSEC-Q • X10+ through X1A+ , X20+ through X2F+ • • • General-purpose input Controls input X of the sequence program by special variable B@. Example for starting address 40 Communications Module PLC CPU B@(X, &H0A) =1 When "1"...
  • Page 115: Plc Cpu Communications Module (About Output Device Y)

    5 COMMUNICATION USING GENERAL-PURPOSE INPUT/OUTPUT MELSEC-Q 5.2 PLC CPU Communications Module (About Output Device Y) Controls the value of Special Variable (B@) using the output Y in the sequence program. When the output device Y is turned ON/OFF using the sequence program, the next corresponding output device is turned ON/OFF in the communication module.
  • Page 116 5 COMMUNICATION USING GENERAL-PURPOSE INPUT/OUTPUT MELSEC-Q The following describes the output device Y viewed from the PLC CPU when the starting address is . Output Device Y in the Sequence Value designated by Signal Name Program Special Variable B@ Y00 + to Y0F + Not used (However, it can be used as a substitute for internal relay...
  • Page 117 5 COMMUNICATION USING GENERAL-PURPOSE INPUT/OUTPUT MELSEC-Q • Y10+ through Y20+ • • • General-Purpose Output Controls the value of Special Variable (B@) using output Y in the sequence program. Example when the starting address is 00 PLC CPU Communications Module A%=B@(Y,&H00) B@ gives "1"...
  • Page 118 5 COMMUNICATION USING GENERAL-PURPOSE INPUT/OUTPUT MELSEC-Q • Y29+ • • • Program Startup (cannot be used as a general-purpose output) Starts up the program that has been designated as startup programs by output Y in Y21+ through Y28+ . Example : Starts up the programs BASIC Task No. 1 and BASIC Task No. 7. PLC CPU BASIC Task No.
  • Page 119: O Processing Of Data Files

    6 I/O Processing of Data Files MELSEC-Q 6 I/O PROCESSING OF DATA FILES The following two types of data files can be creating by BASIC. These files have the following characteristics. • Sequential Files Data are written in a file continuously. This allows data to be saved on memory cards and FD without wasting space, but portions that are only required cannot be read and written.
  • Page 120: File Numbers

    I/O will be performed on data files that are corresponded using the OPEN instruction by designating a file number. Example Assuming that 1), 2), and 3) of (1) are already running: 1)' PRINT # 1. " MITSUBISHI" "MITSUBISHI" is output to sequential file "0:A-1.DAT" 2)' INPUT # 3. A$ Data is input to variable A$ from the sequential file "0:B-10.DAT."...
  • Page 121: Sequential File I/O Procedures

    6 I/O Processing of Data Files MELSEC-Q 6.2 Sequential File I/O Procedures The following shows an overview of I/O procedures for sequential files. In sequential files, either read operation or write operation can be performed per opening of the file. (1) Writing data to a file 1) Open a file in output mode.
  • Page 122 6 I/O Processing of Data Files MELSEC-Q The following shows the data when performing read or write operation into the sequential file. When handling character data Example A$ = "ABC" B$ = "123" C$= "@@@" • PRINT # n, A$ ; B$ ; C$ @ @ @ [CR] [LF] Contents of data file...
  • Page 123 6 I/O Processing of Data Files MELSEC-Q When handling numeric data When writing numeric data into a sequential file, the numeric value is written after automatically converting into the character data. Also, when reading data from a sequential file as numeric data, the written character data will be automatically converted into the numeric values.
  • Page 124 6 I/O Processing of Data Files MELSEC-Q Example 1 ' Register data to a sequential file 10 OPEN "0:TEST.DAT" FOR OUTPUT AS #1 : 'Generates TEST.DAT file and names it as file number 1 20 INPUT "Date:";D$ 30 LINE INPUT "Item Name:";H$ 40 INPUT "Quantity:";K 50 INPUT "Rate (%):";W 60 PRINT #1,D$;",";...
  • Page 125: Random File I/O Procedures

    6 I/O Processing of Data Files MELSEC-Q 6.3 Random File I/O Procedures Random files can be used to perform input and output once they are opened. The following explains how to input and output the random file data: File buffer MEMORY CARD LSET/RSET instructions A6MEM-512KA-W...
  • Page 126 6 I/O Processing of Data Files MELSEC-Q • When reading data from a random file, the data block from a desired <record number> is placed in the "file buffer" by the GET instruction. The data stored in the "file buffer" is read into general variables using instructions such as the LET instruction.
  • Page 127 6 I/O Processing of Data Files MELSEC-Q The following is an overview of I/O procedures for random files 1) Open the file. OPEN "<filename>" AS #n • n denotes the file number. • For procedures on specifying <filename>, see Appendix 1. 2) Define a file buffer.
  • Page 128 6 I/O Processing of Data Files MELSEC-Q 3)" Read the data into the file buffer using the GET instruction if data is to be read. GET #n, <record number> Random File MEMORY CARD File Buffer Read the data in the file buffer to variables. The numeric data is converted back to numeric D1#= CVD ( A$) •...
  • Page 129 6 I/O Processing of Data Files MELSEC-Q Example 1 ' Register data in a random file 10 OPEN "R-TEST.DAT" AS #1 'Generates R-TEST.DAT file and names it as file number 1 20 FIELD #1,8 AS D$,30 AS H$,2 AS K$,4 AS W$ 'Assigns the file buffer 30 R = 0 40 R = R+1...
  • Page 130: Caution On Handling Data Files

    6 I/O Processing of Data Files MELSEC-Q 6.4 Caution on Handling Data Files 6.4.1 Handling data files during multitask processing When data is input or output to the same data file simultaneously by multiple programs during multitask processing, it is processed as follows. •...
  • Page 131: Number Of Data Files That Can Be Handled By Each Program

    6 I/O Processing of Data Files MELSEC-Q • File numbers specified by the OPEN instruction are managed by each program. Therefore, no problem occurs even if the file number for the data file opened simultaneously has a different number for each program. Drive ABC.DAT 6.4.2 Number of data files that can be handled by each program...
  • Page 132: Communication With External Devices

    CH1(RS-232C) Channel number Channel number CH3(RS-422/485) CH4(PARALEL) 1 QD51-R24 does not have CH2 (RS-232C). 2 A1SD51S does not have CH4 (PARALLEL). REMARK The communication module uses the non-procedure protocol for all communication with external devices and terminals. To perform protocol communication, the user needs to write a protocol control program.
  • Page 133: Preparation For The Communication

    7 COMMUNICATION WITH EXTERNAL DEVICES MELSEC-Q 7.2 Preparation for the Communication Various settings are necessary in order to communicate with external devices and terminals. The preparations required to perform the communication are described below. 7.2.1 Communication parameter setting In order to communicate through the RS-232C (CH1, CH2) or RS-422 (CH3) interface, the following parameters have to be set using the ZOPEN and ZCNIL instructions prior to the actual communication.
  • Page 134 7 COMMUNICATION WITH EXTERNAL DEVICES MELSEC-Q • Stop bit • • • Specify this parameter when using the ZOPEN instruction. Specify the data delimiter. The following values can be set in BASIC: • 1 bit • • • The data delimiter is represented by 1 bit. •...
  • Page 135: Control Table

    7 COMMUNICATION WITH EXTERNAL DEVICES MELSEC-Q • Break character • • • Specify this parameter when using the ZCNTL instruction. It is possible to terminate data reception when receiving data designated as a break character while receiving data from an external device. The break character is meaningless unless the character sent by the transmission side and the character recognized by the communication module match.
  • Page 136 7 COMMUNICATION WITH EXTERNAL DEVICES MELSEC-Q For example, in order to execute the ZOPEN instruction, it is necessary to set the baud rate, character length, parity, and stop bit parameters. If too many parameters are listed after the instruction, however, the program will be hard to read. If a control table is used here, the actual instruction becomes concise and the parameters can be written simply as well.
  • Page 137: Communication Procedure With External Devices

    7 COMMUNICATION WITH EXTERNAL DEVICES MELSEC-Q 7.3 Communication Procedure with External Devices This section explains how to communicate with a console, terminal, printer, other external devices. 7.3.1 Communication with a console The following explains how to communicate with a console connected to either the RS- 232C or the RS-422/RS-485 interface of the communication module, as well as precautions when carrying out the communication.
  • Page 138 7 COMMUNICATION WITH EXTERNAL DEVICES MELSEC-Q (2) To enter data from the keyboard of the console 1) Switch the input source to the console using the ZIDV instruction. ZIDV 0 Always 0 when the console is specified. 2) Use the following instructions to enter data from the console's keyboard. Note, however, that some instructions (functions) cannot handle certain character codes.
  • Page 139: Communication With A Terminal

    7 COMMUNICATION WITH EXTERNAL DEVICES MELSEC-Q 7.3.2 Communication with a terminal The following explains how to communicate with a terminal connected to either the RS- 232C or the RS-422/RS-485 interface of the communication module, as well as precautions when carrying out the communication. Items described in this section do not apply to a terminal connected to an interface that is designated as a console by the DIP switch of the communication module.
  • Page 140 7 COMMUNICATION WITH EXTERNAL DEVICES MELSEC-Q (2) To enter data from the keyboard of a terminal 1) Open the interface and set the communication parameters according to the terminal to be used. ZOPEN # <channel number>, <control table> ZCNTL # <channel number>, 0, <control table> 2) Specify the channel number of the interface to which the terminal used for keyboard input is connected using the ZIDV instruction.
  • Page 141: Communicating With A Printer

    7 COMMUNICATION WITH EXTERNAL DEVICES MELSEC-Q 7.3.3 Communicating with a printer The following explains how to send data to a printer connected to the RS-232Cor RS- 422/RS-485 parallel interface of the communication module, as well as precautions when carrying out the transmissions. Items described in this section do not apply to a printer connected to an interface that is designated as a console by the DIP switch of the communication module.
  • Page 142 7 COMMUNICATION WITH EXTERNAL DEVICES MELSEC-Q 2) Specify the channel number of the interface to which the printer for printing data is connected using the ZLDV instruction. ZLDV <channel number> 3) Use the following instructions to print on the printer: LPRINT Prints data on the specified printer.
  • Page 143: Communication With Other External Devices

    7 COMMUNICATION WITH EXTERNAL DEVICES MELSEC-Q 7.3.4 Communication with other external devices The following explains how to communicate with external devices, other than terminals and printers, which are connected either to the RS-232C or the RS-422/RS-485 interface of the communication module, as well as precautions when carrying out the communication.
  • Page 144 7 COMMUNICATION WITH EXTERNAL DEVICES MELSEC-Q (2) To receive data • • • Use the ZRECEIVE instruction or INPUT$ function. 1) Open the interface and specify the communication parameters according to the external device to be used. ZOPEN # <channel number>, <control table> ZCNTL # <channel number>, 0, <control table>...
  • Page 145: Interrupt Processing From External Devices

    7 COMMUNICATION WITH EXTERNAL DEVICES MELSEC-Q 7.4 Interrupt Processing from External Devices It is possible to define "communication interrupt routines" whose execution can be started when data from the external device is received by the AD51H-BASIC program. The "communication interrupt routine" should be defined beforehand using the ON COM GOSUB instruction.
  • Page 146: Multitask Processing

    • Changing the execution time is supported by the AD51H-S3 only. The execution time is fixed to 50ms for the A1SD51S and QD51 (-R24). • Use the DIP switch of the AD51H module to switch the execution time (to 50ms or 100ms).
  • Page 147 8 MULTITASK PROCESSING MELSEC-Q (1) Status transition of a BASIC program The following describes how the status of one BASIC program changes (status transition) after the start of its execution. The program operation status can be roughly divided into four. Once the execution is started, the program operates in parallel with other programs while changing its status among 1) through 3) described below.
  • Page 148 8 MULTITASK PROCESSING MELSEC-Q (2) Priority of the programs (Task priority) An execution priority can be assigned to each program executed in multitask processing. All programs are set to have the same priority when BASIC is started up, which means that the main CPU executes all programs equally through the scheduling by the OS.
  • Page 149 8 MULTITASK PROCESSING MELSEC-Q (3) Execution order when BASIC programs are executed simultaneously The following explains the execution order of each program when multiple BASIC programs are executed at start-up. In reality, the BASIC programs do not operate (execute) by themselves. Each BASIC program operates together with the system program according to the scheduling by the system of the communication module.
  • Page 150: How To Synchronize The Execution (Event Control)

    8 MULTITASK PROCESSING MELSEC-Q 8.2 How to Synchronize the Execution (Event Control) In the multitask processing, the processing of each program proceeds independently. Therefore, correct data may not be received, depending on the timing, when the data needs to be exchanged between programs. Event control is a method for synchronizing the executions.
  • Page 151 8 MULTITASK PROCESSING MELSEC-Q (1) To perform event control In order to perform event control, the following should first be understood: The event control is enabled by defining the events in one of the BASIC programs in advance and specifying the settings so that event generation is enabled in that program.
  • Page 152 8 MULTITASK PROCESSING MELSEC-Q (2) Execution order of the instructions when the event control is performed The following shows the execution order of the instructions when the execution of the BASIC program is being controlled by the events (execution start, execution resume).
  • Page 153: To Use Devices (Resources) In Multitasking (Mutual Exclusive Control Of Resources)

    8 MULTITASK PROCESSING MELSEC-Q 8.3 To Use Devices (Resources) in Multitasking (Mutual Exclusive Control of Resources) Resources refer to all of the hardware and software that can be used by the programs. For example, they could be screens, printers, files, disks, optional boards, memory, etc.
  • Page 154 8 MULTITASK PROCESSING MELSEC-Q (1) To limit the access to the resource In order to limit the access to resources, the following should first be understood: (a) Mutual exclusive control of the resource is performed strictly under the agreement between the programmers. The mutual exclusive control of the resource is meaningless if such agreement is not followed.
  • Page 155 ZRESERVE instruction. Programmer A Programmer B MEMORY CARD A6MEM-512KA-W MITSUBISHI "ABC.NEW" file An example of the steps for assigning resource numbers to resources is shown below: List all the resources that will be used in the programs to be executed simultaneously.
  • Page 156 8 MULTITASK PROCESSING MELSEC-Q (3) Execution order of instructions when limiting access to the resources The following describes the execution order of instructions when limiting access to the resources in the BASIC program. ZRESERVE: Requests mutual exclusive control of the resource. ZRELEASE: Finishes mutual exclusive control of the resource.
  • Page 157 8 MULTITASK PROCESSING MELSEC-Q Deadlock example BASIC ZRESERVE 1 program (A) Program A requested to use the resource with resource Request In use number 2, but is put into the Request ZRESERVE 2 wait status because program B is using it. Resource with resource number 1 Both programs...
  • Page 158: Start Another Program From Within A Program

    MEMORY CARD The program in the specified A6MEM-512KA-W task area is executed. MITSUBISHI A program can be read from the FD or HD as well. 2) Start a program already residing in the task area, which has currently been put in the stop status by the END instruction.
  • Page 159: Exchanging Data Between Tasks

    8 MULTITASK PROCESSING MELSEC-Q 8.5 Exchanging Data between Tasks The contents of variables and arrays in each task can be referenced only within each program during multitask processing. It is necessary to use a special method to exchange data between programs. Variables Variables and arrays in...
  • Page 160 8 MULTITASK PROCESSING MELSEC-Q Data is stored in the following manner. • For numeric data Common memory Integer variable, integer array 1800 RD%(0) 1801 1802 RD%(1) 1803 GETMEM 1804 RD%(2) /PUTMEM 1805 The data is accessed using addresses 1800 to 1805 •...
  • Page 161: Message Ports

    8 MULTITASK PROCESSING MELSEC-Q 8.5.2 Message ports It is possible to exchange messages, as if sending letters, between the programs, and synchronize the executions by making (defining) a message transfer location (message port) in memory in AD51H-BASIC. To synchronize the executions via a message port, it is not necessary to consider the interlocking of the wait status as required by the event control.
  • Page 162 8 MULTITASK PROCESSING MELSEC-Q • An error occurs if the total number of messages in all message ports exceeds 64. Fortunately, the total number decreases by one each time a message is read. D51H Only 64 messages can be stored. STOP •...
  • Page 163 8 MULTITASK PROCESSING MELSEC-Q 3) To write a message to the message port: ZMESSAGE PUT <message port number>, <transmission data>, • • • 3)' To read a message from the message port: ZMESSAGE GET <message port number>, <variable where the data read is stored>, • • • •...
  • Page 164 8 MULTITASK PROCESSING MELSEC-Q If program B reads a message before program A writes it, the execution is synchronized as follows: 1) ZMESSAGE to ZMESSAGE OPEN to 3) ZMESSAGE PUT Prepare and open Write the message. the message port. Program A ZMESSAGE OPEN to 2) ZMESSAGE GET Read the message.
  • Page 165: The Concept Of Error Handling

    9 THE CONCEPT OF ERROR HANDLING MELSEC-Q 9 THE CONCEPT OF ERROR HANDLING If an error occurs while running the BASIC program, an error message is displayed and the program stops running. If an error occurs, the program no longer runs Although the program is usually created to generate a minimal amount of errors taking as many potential causes into consideration as possible, errors may occur due to causes that are normally difficult to foresee.
  • Page 166: How To Determine The Type Of Error And The Location Where The Error Occurred

    9 THE CONCEPT OF ERROR HANDLING MELSEC-Q 9.2 How to Determine the Type of Error and the Location where the Error Occurred The type of error and the line number where it has occurred can be determined by using the following two functions in the error handling routine. •...
  • Page 167: Precautions Regarding Error Handling

    9 THE CONCEPT OF ERROR HANDLING MELSEC-Q 9.3 Precautions Regarding Error Handling Some precautions when creating an error handling routine are given below. (1) Example of error prevention in a program The error handling routine is the last defense against the program stopping. It is better to create the program so that errors can be prevented in the program itself, if possible, without using an error handling routine.
  • Page 168: Program Debugging

    10 Program Debugging MELSEC-Q 10 PROGRAM DEBUGGING Program debugging refers to the operation of checking whether an edited program will run correctly and revise the program so that it runs correctly. (Debug = removing the bugs) This section shows the sequence of program debugging and the instructions used in debugging.
  • Page 169 10 Program Debugging MELSEC-Q (2) STOP and CONT instructions and operation of the Break ( Ctrl + C ) key The program pauses (interrupts) when a STOP instruction is executed. Also, if the Break ( Ctrl + C ) key is pressed while the program is being executed, the program pauses (interrupts) in the same way as in the case of the STOP instruction.
  • Page 170 50 STOP Break in 50 60 FOR I%=0 TO 2 70 PRINT IN$(I%) PRINT IN$(0) 80 NEXT I% MITUBISHI 90 END IN$(0) = "Mitsubishi" PRINT IN$(2) AD51H IN$(2)="BASIC" CONT Mitsubishi MELSEC BASIC Use the following instructions in a BASIC program to make debugging easier.
  • Page 171: Instructions And Functions

    11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q 11 INSTRUCTIONS AND FUNCTIONS This chapter explains general instructions and functions used by AD51H-BASIC. Each item is described in the following format. Indicates instruction, function, or variable. Indicates the origin of the instruction and how to read it. Name of instructions and functions Describes the purpose of the instruction or function.
  • Page 172: Abs (Returns The Absolute Value )

    11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q Function ABSolute • Returns the absolute value of an arithmetic expression. ABS ( <arithmetic expression> ) Syntax arithmetic expression • • • • Specify the value to calculate the absolute value. A=ABS( 3.14) • • • • Assigns 3.14 (absolute value of 3.14) to A.
  • Page 173 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q AKCNV$ Function Ank Kanji CoNVert $ • Converts half-byte characters to full-byte characters. AKCNV$ ( <character string expression> ) Syntax character string expression • • • • Specify the character string to be converted. A$=AKCNV$(A$) •...
  • Page 174: Asc ( Returns The Character Code Of The Starting Character)

    11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q Function ASCii • Returns the character code corresponding to the starting character of the character string expression. ASC ( <character string expression> ) Syntax character string expression • • • • Specify the character string to return a character code.
  • Page 175: Atn ( Returns Arc Tangent)

    11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q Function TaNgent • Returns arc tangent (tan ) of the arithmetic expression. ATN ( <arithmetic expression> ) Syntax arithmetic expression • • • • Specify an arithmetic expression to calculate the arc tangent. A=(180/3.141592) • • • • Calculates the arc tangent of 1, then converts to Examples ATN(1)
  • Page 176 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q AUTO Instruction AUTOmatic • Automatically displays the line number at the beginning of a line. AUTO <line number>, <increment> Syntax line number • • • • Specify the line number to start the display. increment •...
  • Page 177 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q Variable Bit@ • Reads and writes bit information of the expansion relay (EM), general-purpose input (X), and general-purpose output (Y). B@ ( <device> , <device number> ) Syntax device • • • • Specify the device to read and write. device number •...
  • Page 178: Beep ( The Buzzer Sounds )

    11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q BEEP Instruction BEEP • The buzzer sounds from the console’s built-in speaker. BEEP Syntax BEEP Examples • The BEEP instruction rings the buzzer for a certain duration as executing PRINT CHR$(7). Description • The BEEP instruction can be executed only by the port specified as a console by the DIP switch of the communication module’s main system.
  • Page 179 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q BIN$ Function BINary $ • Returns a character string of the binary expression of an integer. BIN$ ( <arithmetic expression> ) Syntax arithmetic expression • • • • Specify an integer to return a character string. A$=BIN$(10) •...
  • Page 180 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q Program Example 10 ' Converts a decimal number to a binary number 20 A=1234 ' Defines the numeric value 30 A$=BIN$(A) ' Converts to a binary number 40 PRINT "Decimal=";A 50 PRINT "Binary=";A$ 60 END Decimal= 1234 Binary=10011010010 11 - 10...
  • Page 181: Bswap ( Swaps Two Values In Byte Units)

    11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q BSWAP Instruction Byte SWAP • Swaps two values in byte units. BSWAP <variable 1> , <swap starting address of variable 1> , Syntax <variable 2> , <swap starting address of variable 2> , <swap count> variable 1, variable 2 •...
  • Page 182 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q • The BSWAP instruction swaps two values in byte units starting from the address specified Description by the variable. Especially, this instruction is used in order to rearrange the I/O data that is communicated with the external device so that it conforms to the data format of the device used. BSWAP A%( ),0,A%( ),1,1 BSWAP A%( ),2,A%( ),3,1 •...
  • Page 183 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q Before swap A%(0)=&H924 A%(1)=&H1159 After swap A%(0)=&H1159 A%(1)=&H924 11 - 13 11 - 13...
  • Page 184: Cdbi ( Converts A Double Precision Real Number To A 32-Bit Integer)

    11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q CDBI Instruction Convert DouBle to Integer • Converts a double precision real number to a 2-word (32-bit) integer used by the PLC CPU. CDBI <double precision variable> , <array variable> Syntax double precision variable • • • • Specify the double precision variable where the data to be converted is stored.
  • Page 185 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q Program Example 10 ' Converts the double precision real number to a 2-word integer and writes it into D0 and D1 20 DIM B%(1),TBL%(5) ' Defines the array 30 A#=1234567890# ' Defines the double precision real number 40 CDBI A#,B%(0) ' Converts to a 32-bit integer 50 TBL%(0)=255...
  • Page 186: Cdbl ( Converts An Integer Or A Single Precision Real Number To A Double Precision Real Number)

    11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q CDBL Function Convert to DouBLe • Converts an integer or a single precision real number to a double precision real number. CDBL ( <arithmetic expression> ) Syntax arithmetic expression • • • • Specify an integer or a single precision real number to be converted to a double precision real number.
  • Page 187 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q Program Example 10 ' Converts an integer or a single precision real number into a double precision real number 20 A%=256 ' Defines an integer 30 B!=5.78 ' Defines a single precision real number 40 A#=CDBL(A%) ' Converts an integer to a double precision real number 50 B#=CDBL(B!)
  • Page 188: Chain ( Reads Program Or Combine To Execute )

    11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q CHAIN Instruction CHAIN • Erases or partly deletes the program that is currently being executed, and reads and executes the specified program. CHAIN ”[<drive number>:] [<system name> \] <file name>” Syntax [, <line number1> :] [, ALL] CHAIN MERGE ”...
  • Page 189 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q • The CHAIN instruction reads a different program (subsequent program), which is separate Description from the program currently residing on the memory (current program), to the area of the same BASIC number, and hands the variables and their contents of the current program over to the subsequent program, then have the newly read program start its execution.
  • Page 190 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q CHR$ Function CHaRacter $ • Returns a character whose character code is the value of the arithmetic expression. CHR$ ( <arithmetic expression> ) Syntax arithmetic expression • • • • Specify the character code to get a character. PRINT CHR$ (&H41) •...
  • Page 191: Cidb ( Converts A 32-Bit Integer Into A Double Precision Real Number )

    11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q CIDB Function Convert Integer to DouBle • Converts a 2-word (32-bit) integer to be used by the PLC CPU into a double precision real number. CIDB ( <array variable> ) Syntax array variable • • • • Specify a one-dimensional integer array variable where the data to be converted is stored.
  • Page 192 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q Program Example 10 ' Converts 2-word integer in D0, D1 to a double precision real number 20 DIM TBL%(5),A%(1) ' Defines arrays 30 TBL%(0)=255 ' Sets the communication station number to the local station 40 TBL%(1)=1 ' Specifies readout of the device memory 50 TBL%(2)=2 ' Specifies word as the unit...
  • Page 193: Cint ( Converts A Single Precision Real Number Or A Double Precision Real Number Into An Integer )

    11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q CINT Function Convert INTeger • Converts a single precision real number or a double precision real number into an integer. CINT ( <arithmetic expression> ) Syntax arithmetic expression • • • • Specify a single precision real number or a double precision real number to convert into an integer.
  • Page 194 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q REMARK • When assigning a value to an integer variable, the value type is automatically converted into an integer if the instruction or function requires an integer type as its parameter (argument). A%=3042.12! and A%=CINT(3042.12!) will have the same result.
  • Page 195: Cisn ( Converts A 32-Bit Integer Into A Single Precision Real Number)

    11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q CISN Function Convert Integer to SiNgle • Converts a 2-word (32-bit) integer to be used by the PLC CPU into a single precision real number. CISN ( <array variable> ) Syntax array variable • • • • Specify a one-dimensional integer array variable where the converting data is stored.
  • Page 196 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q Program Example 10 ' Converts 2-word integer in D0, D1 to a double precision real number 20 DIM TBL%(5),A%(1) ' Defines arrays 30 TBL%(0)=255 ' Sets the communication station number to the local station 40 TBL%(1)=1 ' Specifies readout of the device memory 50 TBL%(2)=2 ' Specifies word as the unit...
  • Page 197: Clear ( Initializes All Variables And Sets Up The Memory Area )

    11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q CLEAR Instruction CLEAR • Initializes all variables and sets up the memory area. CLEAR [ <arithmetic expression> ] Syntax arithmetic expression • • • • Specify the size of the memory area used for storing the character string by BASIC in number of bytes.
  • Page 198: Close ( Terminates The I/O Processing Of A File )

    11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q CLOSE Instruction CLOSE • Terminates the I/O processing of a file. CLOSE # <file number> [, # <file number> … ] Syntax file number • • • • Specify the file number that was opened by the OPEN instruction.
  • Page 199: Cls ( Clears The Screen )

    11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q Instruction CLear Screen/CLS • Clears the screen. CLS [ <function> ] Syntax function • • • • Specify ‘1’. Examples • • • • Clears the text screen. CLS 1 • The CLS instruction clears the console screen specified by the ZODV instruction and Description moves the cursor to the upper left corner of the screen.
  • Page 200: Com On/Off/Stop

    11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q COM ON/OFF/STOP Instruction COMmunication ON/OFF/STOP • Controls to enable, prohibit, and stop the interrupt from the communication line. COM ( <channel number> ) ON Syntax COM ( <channel number> ) OFF COM ( <channel number> ) STOP channel number •...
  • Page 201: Common ( Sets Variable And Others To Be Passed To The Program To Be Read )

    11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q COMMON Instruction COMMON • Sets variable and others to be passed to the program to be executed by the CHAIN instruction. COMMON <data to be passed> [, <<data to be passed >, … ] Syntax data to be passed •...
  • Page 202: Console ( Sets The Number Of Display Lines Of The Console Screen )

    11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q CONSOLE Instruction CONSOLE • Sets the number of display lines of the console screen. CONSOLE <number of lines> Syntax number of lines • • • • Specify the number of display lines as 20 through 32 depending on the console used.
  • Page 203: Cont ( Resumes The Program That Was Stopped )

    11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q CONT Instruction CONTinue • Resumes the program that was stopped by the Ctrl + C or Break key in edit mode, or by executing the STOP or END instruction. CONT Syntax CONT • • • • Resumes execution of the program from the point Examples where the program execution was stopped.
  • Page 204: Cos ( Returns A Cosine Value )

    11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q Function • Returns a cosine value of the trigonometric function COS ( <arithmetic expression> ) Syntax arithmetic expression • • • • Specify a numeric value in radian. A=COS(3.14159/180 60) • • • • Converts 60° angle to radian, calculates its cosine Examples value, and stores in A.
  • Page 205: Csng ( Converts An Integer Or A Double Precision Real Number Into A Single Precision Real Number )

    11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q CSNG Function Convert SiNGle • Converts an integer or a double precision real number into a single precision real number. CSNG ( <arithmetic expression> ) Syntax arithmetic expression • • • • Specify an integer or a double precision real number to be converted into a single precision real number.
  • Page 206: Csni ( Converts A Single Precision Real Number Into A 32-Bit Integer )

    11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q CSNI Instruction Convert SiNgle to Integer • Converts a single precision real number into a 2-word (32-bit) integer to be used by the PLC CPU. CSNI (single precision variable> , <array variable> Syntax single precision variable •...
  • Page 207 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q Program Example 10 ' Converts the single precision real number to a 2-word integer and writes it into D0 and D1 20 DIM B%(1) ' Defines the array 30 A!=999999! ' Defines the single precision real number 40 CSNI A!,B%(0) ' Converts to a 32-bit integer 70 TBL%(0)=255...
  • Page 208: Cvd

    11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q Function ConVert to Double • Converts a character string, which was converted by the MKD$ function, back to a double precision real number. CVD ( <character string expression> ) [, S] ) Syntax character string expression •...
  • Page 209: Cvdmbf ( Converts Into The Ieee Format Double Precision Internal Expression )

    11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q CVDMBF Function ConVert Double Microsoft Binary Format • Converts a double precision real number of AD51H-BASIC, which was converted by the MKD$ function, into the IEEE format double precision internal expression. CVDMBF ( <character string expression> ) Syntax character string expression •...
  • Page 210: Cvi ( Converts A Character String, Which Was Converted By The Mki$ Function, Back To An Integer )

    11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q Function ConVert to Integer • Converts a character string, which was converted by the MKI$ function, back to an integer. CVI ( <character string expression> ) [, S] ) Syntax character string expression • • • • Specify the character string that was converted by the MKI$ function.
  • Page 211: Cvs

    11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q Function ConVert to Single • Converts a character string, which was converted by the MKS$ function, back to a single precision real number. CVS ( <character string expression> ) [, S] ) Syntax character string expression •...
  • Page 212: A Single Precision Real Number )

    11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q CVSMBF Function ConVert Single Microsoft Binary Format • Converts a single precision real number of AD51H-BASIC, which was converted to the character string by the MKS$ function, to the internal expression of a floating point real number (IEEE format single precision internal expression) that is used by AnA/AnU/AnUSCPU.
  • Page 213 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q Program Example 10 ' Converts a single precision real number to a floating decimal point real number for AnACPU, and writes to D0, D1. 20 DIM TBL%(5),A%(1) ' Defines arrays 30 A!=5.6767 ' Defines a single precision real number 50 A$=MKS$(A!) ' Converts into a character string 70 B!=CVSMBF(A$)
  • Page 214: Data ( Specifies Data To Be Read By Read )

    11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q DATA Instruction DATA • Specifies values and character strings to be read by READ. DATA <constant> [ <, constant> …] Syntax constant • • • • Specify any numeric value constant (fixed point constant, floating point constant, integer constant), or a character string constant.
  • Page 215 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q Program Example 10 ' Reads the data specified in the DATA instruction by the READ instruction and displays it 20 DATA 1,2,"ABC" 30 READ A,B,C$,D$,E :' Reads data 40 DATA "AD51H",90 50 PRINT "A=";A,"B=";B,"C$=;C$ :' Displays data 60 PRINT "D$=";D$,"E=";E 70 END A= 1...
  • Page 216 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q DATE$ Function DATE $ • Sets year, month, and day to the PLC CPU. • Reads year, month, and day from the PLC CPU. DATE$=” <year> / <month> / <day> [/ <day of the week> ]” Syntax DATE$ year...
  • Page 217 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q Program Example 10 ' Sets the calendar and reads out 30 A$="1991/04/01/MON" ' Sets the year, month, and day 40 DATE$=A$ ' Writes the year, month, and day 60 B$=SPACE$(14) ' Stores dummy 70 B$=DATE$ ' Reads year, month, and day 80 PRINT "Contents of the calendar-->";B$ ' Checks the contents after writing...
  • Page 218: Defdbl

    11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q DEFDBL Instruction DEFine DouBle • Defines variables that start with a character of the specified range as the double precision real number type. DEFDBL <alphabetical character> [- <alphabetical character> ] [, <alphabetical character> Syntax [- <alphabetical character> ], … Defines variables starting with A and variables DEFDBL A,C-E •...
  • Page 219: Deffn ( Defines A User Function )

    11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q DEFFN Instruction DEFine FuNction • Defines a user function and names it. DEF FN <name> [( <dummy argument> [, <dummy argument> ], …)] = <function definition Syntax expression> name • • • • Specify a name of the defined function. dummy argument •...
  • Page 220 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q Program Example 10 ' Defines a formula to calculate the area of a triangle as function name FNA 20 DEF FNA(A,B)=(A*B)/2 ' (base*height)/2 30 INPUT "Base=";C ' Input of the base 40 INPUT "Height =";D ' Input of the height 50 E=FNA(C, D) ' Calculation...
  • Page 221: Defint ( Defines Variables That Start With A Character Of The Specified Range As The Integer Type )

    11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q DEFINT Instruction DEFine INTeger • Defines variables that start with a character of the specified range as the integer type. DEFINT <alphabetical character> [- <alphabetical character> ] [, <alphabetical character> Syntax [- <alphabetical character> ], … Defines variables starting with B and variables DEFINT B, F-H •...
  • Page 222: Defsng

    11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q DEFSNG Instruction DEFine SiNGle • Defines variables that start with a character of the specified range as the single precision real number type. DEFSNG <alphabetical character> [- <alphabetical character> ] [, <alphabetical Syntax character> [- <alphabetical character> ], … Defines variables starting with C and variables DEFSNG C, X-Z •...
  • Page 223: Defstr ( Defines Variables That Start With A Character Of The Specified Range As The Character Type )

    11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q DEFSTR Instruction DEFine STRing • Defines variables that start with a character of the specified range as the character type. DEFSTR <alphabetical character> [- <alphabetical character> ] [, <alphabetical character> Syntax [- <alphabetical character> ], … Defines variables starting with M and variables DEFSTR M, P-R •...
  • Page 224: Def Zevent ( Defines An Event, And Defines An Event By Bit Device )

    11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q DEF ZEVENT Instruction DEFine Z EVENT • Defines an event for synchronizing execution between the programs. • Defines an event by the expansion relay (EM) of the communication module. DEF ZEVENT (event number) Syntax DEF ZEVENT (event number), <device>...
  • Page 225 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q • <event number> is used as a number for specifying whether enabling or disabling the defined event to occur, for creating an event, and for waiting for an event to occur. Treat <event number> as the common number between the BASIC programs. A value ranging 0 to 63 can be specified to <event number>, and <event number>...
  • Page 226 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q To perform the event control, it is necessary to process to disable the generation of events which are handled at the startup and shutdown of BASIC, in order to initialize the event information that is managed by the system. Execute one of the following: 1) Power on again or operate the RESET switch of the communication module when starting up BASIC.
  • Page 227: Delete ( Deletes The Specified Range Of The Program )

    11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q DELETE Instruction DELETE • Deletes the specified range of the program. DELETE [ [ <line number 1> ] -] [ <line number 2> ] Syntax line number 1 • • • • Specify the first line to delete. line number 2 •...
  • Page 228: Dim ( Defines The Array )

    11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q Instruction DIMension • Specifies the size of a dimension and assigns a memory area necessary for the array. array variable name (numeric expression [, numeric expression] …) [, array variable Syntax name (numeric expression [, numeric expression] …) ] array variable name •...
  • Page 229 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q • The DIM instruction initializes all element values of the specified numeric value array to 0, and all element values of a character string array to an empty character string. • A “Redimensioned array” error occurs if the DIM instruction defines an array variable specified by the DIM instruction again.
  • Page 230: End ( Terminates The Execution Of The Program And Brings To The Input Wait State Or The Idling State )

    11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q Instruction • Terminates the execution of the program and brings to the input wait state for an instruction in edit mode. • Terminates the execution of the program and brings to the idling state in execution mode. Syntax •...
  • Page 231: Eof ( End Of A Sequential File Is Detected )

    11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q Function End Of File • Returns -1 (True) if the end of a sequential file is detected. EOF ( <file number> ) Syntax file number • • • • Specify the file number specified by the OPEN instruction.
  • Page 232: Erase ( Deletes The Array From Memory )

    11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q ERASE Instruction ERASE • Deletes the array defined by the DIM instruction from memory. ERASE <array variable> [ <, array variable> … ] Syntax array variable • • • • Enter the array variable specified by the DIM instruction.
  • Page 233: Erl ( Returns The Line Number Where An Error Was Detected )

    11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q Function ERror Line • Returns the line number where an error was detected. Syntax E=ERL • • • • Stores the line number where the error was detected Examples to E. • The ERL function returns the line number where the error was detected when an error has Description occurred.
  • Page 234: Err ( Returns The Error Code Of The Detected Error )

    11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q Function ERRor code • Returns the error code of the detected error. Syntax E=ERR • • • • Stores the code of the detected error in E. Examples • The ERR function returns the code of the detected error when an error occurs. Description •...
  • Page 235: Error ( Generates The Error Of The Specified Error Code )

    11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q ERROR Instruction ERROR • Generates the error of the specified error code. ERROR <integer expression> Syntax integer expression • • • • Specify the error code of the error to be generated. E=ERROR 2 • • • • Generates a “Syntax error”...
  • Page 236: Exp ( Returns The Exponential Function Value )

    11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q Function EXPonential • Returns the exponential function value of base e (e=2.718281). EXP ( <numeric expression> ) Syntax Specify the multiplicator n of e numeric expression • • • • E=EXP(10) • • • • Calculates EXP(10) and stores it in E.
  • Page 237: Field ( Assigns The Area For The Specified Variable To The Random File Buffer )

    11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q FIELD Instruction FIELD • Assigns the area for the specified variable to the random file buffer. FIELD <#> <file number> , <field length> AS <character string variable> [, <field length> Syntax AS <character string value> ] … file number •...
  • Page 238: Files ( Displays The File Name )

    11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q FILES Instruction FILES • Displays the file name of a file in a memory card, FD, HD, etc. FILES [“ <drive number> :] [ <system name>\] [ < file name> ] “] [, S] Syntax drive number •...
  • Page 239 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q Function • Returns only the integer part after truncating the fractional part of the numeric value. FIX ( <numeric expression> ) Syntax numeric expression • • • • Specify a numeric value to truncating the fractional part.
  • Page 240: For To Next ( Executes A Series Of Instructions For The Specified Number Of Times )

    11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q FOR to NEXT Instruction FOR to NEXT • Executes a series of instructions for the specified number of times. <variable name> = <initial value> TO <final value> [STEP <increment> ] Syntax NEXT [ <variable name> ] [, <variable name> ] variable name •...
  • Page 241 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q If the nested loops have the same end point, multiple variable names can be described following one NEXT instruction. However, list variable names in the order starting from the one that corresponds to the closest FOR instruction. FOR I=0 TO 10 FOR J=0 TO 10 NEXT J, I...
  • Page 242: Format ( Initializes The File Area Of A Memory Card )

    11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q FORMAT Instruction FORMAT • Initializes (logical format) the file area of a memory card. FORMAT <drive number> Syntax drive number • • • • Specify the memory card to initialize (logical format) the file area. FORMAT 0 •...
  • Page 243 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q When the FORMAT instruction is used to initialize the file area of the memory card, all programs and data in the memory card are lost. There is no way to recover the lost data. Be sure to check the contents of the memory card thoroughly before using the FORMAT instruction.
  • Page 244: Fre ( Returns The Size Of The Unused Area Of Memory In Bytes )

    11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q Function FREe • Returns the size of the unused area of memory in bytes. FRE ( <numeric expression> ) Syntax FRE ( <character string expression> ) numeric expression • • • • Specify an numeric constant or numeric value variable as a dummy.
  • Page 245: Get ( Reads One Record From A Random File To The Random File Buffer )

    11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q Instruction • Reads one record from a random file to the random file buffer. [#] <file number> [, <record number>] Syntax file number • • • • Specify the file number opened by the OPEN instruction.
  • Page 246 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q GETMEM Instruction GET MEMory • Reads data from the buffer memory, common memory, and expansion register (ED) of the communication module. GETMEM <read data store area> , <offset 1> Syntax FROM <read source> , <offset 2>, <number of bytes> read source •...
  • Page 247 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q GETMEM TO A%( ), • • • • Reads data of D2 and ED3 (four bytes) to A%(1) and 2 FROM W@(ED, 2), 4, 4 A%(2). A%( ) Internal device 30 21 3021 4 bytes 68 42 6842 •...
  • Page 248 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q • Specify the variable, etc. where the data read from the buffer memory is stored in <read data store area>. Store dummy data of <number of bytes> or more to the variable specified as <read data store area>...
  • Page 249 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q • Specify the length of data to be read from the starting location specified by <offset 2> to <number of bytes> in bytes. If <read data store area> is an integer variable or integer array, use the following to store the read data to n elements: <number of bytes>...
  • Page 250: Gosub Return ( Branches To A Subroutine )

    11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q GOSUB RETURN Instruction GO to SUBroutine/RETURN • Branches to a subroutine and returns to the specified line number. GOSUB <line number 1> Syntax RETURN [ <line number 2> ] line number 1 • • • • Specify the starting line number of the subroutine to be branched.
  • Page 251 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q Program Example 10 ' Example using a subroutine 20 PRINT "At line 10 of the main routine" 30 GOSUB 100 ' Branches to a subroutine 40 PRINT 50 PRINT "At line 50 of the main routine" 60 END ' End of execution 100 PRINT...
  • Page 252 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q GOTO Instruction GOTO • Moves the program flow to the specified line number unconditionally. GOTO <line number> Syntax line number • • • • Specify the jump destination line number. GOTO 100 • • • • Moves the execution to line number 100.
  • Page 253 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q HEX$ Function HEXadecimal $ • Converts a decimal number to a hexadecimal character string. HEX$ ( <numeric expression> ) Syntax numeric expression • • • • Specify within a range from -32768 to 65535. Values from 32768 to 65535 are the same as values from -32768 to -1 (8000 to FFFF however.
  • Page 254: If Goto Else ( Selects A Branch Destination According To The Result Of An Expression )

    11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q IF GOTO ELSE Instruction IF to GOTO to ELSE • Selects a branch destination according to the result of an expression. <conditional expression> GOTO <line number> [ ELSE <instruction> / <line Syntax number> ] conditional expression •...
  • Page 255 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q Program Example 10 ' Branches according to the condition 20 INPUT "X=";X ' Enter a value 30 IF X>=0 AND X<=10 GOTO 50 ELSE 60 ' Branch to line 50 if X is 0 to 10, 50 PRINT "Within range from 0 to 10!": END ' otherwise branch to line 60 60 PRINT "Out of range!":END...
  • Page 256: If Then Else ( Selects An Instruction According To The Result Of The Expression )

    11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q IF THEN ELSE Instruction IF to THEN toELSE • Selects an instruction to execute according to the result of the expression. <conditional expression> THEN <instruction> / <line number> [: <instruction> / <line Syntax number> ] [ ELSE <instruction>...
  • Page 257 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q Program Example 0 ' Selects an instruction to execute according to the condition 20 INPUT "X=";X ' X input 30 INPUT "Y=";Y ' Y input 40 IF X=Y THEN PRINT "Same" ELSE PRINT "Different" ' Displays 'Same' if X=Y 50 END ' Different' if X<>Y X=? 5...
  • Page 258 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q INKEY$ Function INput KEY $ • Returns the character if there is an input from the keyboard, or returns an empty character string (“ “) if there is no input. INKEY$ Syntax A$=INKEY$ • • • • Assigns the character to A$ if there is a keyboard Examples input, or assigns an empty character string (“...
  • Page 259 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q Program Example 10 ' Pressing any key terminates the program 20 PRINT "*"; 30 A$=INKEY$ ' Checks the key status 40 IF A$="" GOTO 20 ' Returns to line 20 if no key is pressed 50 END *************** REMARK...
  • Page 260: Input ( Data Entry From The Keyboard )

    11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q INPUT Instruction INPUT • Data entry from the keyboard. INPUT [“ <character string to be displayed> “;] <variable name> [, <variable name>, …] Syntax character string to be • • • • Specify a character constant to display when displayed requesting an input.
  • Page 261 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q Program Example 10 ' Data input 20 INPUT "X=";X ' Input 30 PRINT "X^2=";X^2 40 END X=? 2 X^2= 4 REMARK See the INPUT$ function, LINE INPUT instruction, and Section 3.11. 11 - 91 11 - 91...
  • Page 262: Iput

    11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q IPUT$ Function INPUT $ • Returns a character string of the specified length after reading from the keyboard of the console. • Returns a character string of the specified length after reading from a sequential file. •...
  • Page 263 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q If the 03 code (BREAK code) is entered from a keyboard other than the console keyboard (a terminal connected to the communication port), the BASIC program reads it as data. Therefore, note that the BASIC program cannot be stopped. •...
  • Page 264 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q Program Example 10 ' Waits for the input from the keyboard 20 PRINT "Yes or No ?"; 30 A$=INPUT$(1) ' Enters one character from the keyboard 40 IF A$="Y" OR A$="y" THEN PRINT:PRINT "OK!!":GOTO 60 50 PRINT:PRINT "???"...
  • Page 265 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q INPUT# Instruction INPUT # • Reads data from a sequential file. INPUT # <file number>, <variable name> [, <variable name> , …] Syntax file number • • • • Specify the file number of the sequential file that was opened by the OPEN instruction.
  • Page 266: Instr ( Returns A Specified Character String In The Character String )

    11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q INSTR Function IN STRing • Searches a specified character string in the character string and returns the position of the first match. INSTR ([ <numeric expression > ,] <character string expression 1>, < character string Syntax expression 2>...
  • Page 267 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q Program Example 10 ' Searches for the specified characters 20 A$="AD51HMitsubishiPLC" 30 A=INSTR(2,A$,"PLC") ' Searches for PLC from a character string 40 PRINT "A$=";A$ ' Displays the character string 50 PRINT "PLC is the ";A;"th character" ' Displays the position where 'PLC' was detected 60 END...
  • Page 268 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q INT Function INTeger • Returns the integer value of the numeric expression INT ( <numeric expression> ) Syntax numeric expression • • • • Specify the value to be processed. A=INT(B) • • • • Converts the value of B into an integer value and Examples assigns it to A.
  • Page 269 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q Program Example 10 ' Differences of calculation results among INT, FIX and CINT functions 20 DIM A(3) ' Defines an array 30 A(0)=12.34 ' Stores the value 40 A(1)=12.56 50 A(2)=-12.34 60 A(3)=-12.56 70 FOR I=0 TO 3 ' Repeats with I=0 to 3 80 PRINT "A(";I;")=";A(I) ' Displays the original value...
  • Page 270 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q JIS$ Function JIS (Japanese Industrial Standard) $ • Returns the Kanji code of a full-byte character. JIS$ ( <character string expression> ) Syntax character string expression • • • • Specify a full-byte character to return the Kanji code. A$=JIS$ (“@”) •...
  • Page 271 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q KACNV$ Function Kanji Ank CoNVert $ • Converts a full-byte character to a half-byte character. KACNV$ ( <character string expression> ) Syntax character string expression • • • • Specify a character string to be processed. B$=KACNV$(A$) •...
  • Page 272 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q KEXT$ Function Kanji EXTract $ • Returns only full-byte characters or half-byte characters from a character expression. KEXT$ ( <character string expression> , <function> ) Syntax character string expression • • • • Specify a character string to be processed. function •...
  • Page 273 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q Program Example 10 ' Extracts only half-byte characters or full-byte characters from the character string 20 A$="AD51H@" 30 B$=KEXT$(A$, 0) ' Extracts only half-byte characters 40 C$=KEXT$(A$, 1) ' Extracts only full-byte characters 50 PRINT "Original character string-->";A$ 60 PRINT "Half-byte characters------>";B$ 70 PRINT "Full-byte characters------>";C$ 80 END...
  • Page 274: Key ( Defines A Character String To A Function Key Of The Console )

    • • • • Specify the character string to be defined. KEY 1, “MITSUBISHI” • • • • Defines the character string “MITSUBISHI” to the Examples function key ( F1 ) of function key number 1 of the console. • The KEY instruction defines a character string or a control character to a function key of Description the console.
  • Page 275: Keylist ( Displays The Character String Defined To The Function Key Of The Console )

    11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q KEYLIST Instruction KEY LIST • Displays the character string defined to the function key of the console. KEY LIST Syntax KEY LIST • • • • Displays the character string defined to the function Examples key of the console.
  • Page 276: Kill ( Deletes A File )

    11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q KILL Instruction KILL • Deletes a file in the memory card, FD, or HD. • Deletes the system name in the memory card, FD, or HD. KILL” [ <drive number> :] [ <system name>\] [ <file name> ]” Syntax drive number •...
  • Page 277 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q • Specify the file name and identifier of the file to be deleted in <file name>. The identifier cannot be omitted in the KILL instruction. • The KILL instruction cannot be executed when at least one data file is open. A “File already open”...
  • Page 278: Character String And Displays The First Location In Which It Is Found

    11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q KINSTR Function Kanji INSTRing • Searches through a character string containing full-byte characters for the specified character string and displays the first location in which it is found. KINSTR ([ <arithmetic expression > ,] <character string expression 1>, < character string Syntax expression 2>...
  • Page 279 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q Program Example 10 ' Searches full-byte characters "@@@" from the character string 20 A$="@@@@@@@@@@" ' Defines character string 30 A=KINSTR(2,A$,"@@@") ' Searches @@@ from the character string 40 PRINT "Character string-->";A$ 50 PRINT "@@@@";A;"@@@" 60 END @@@-->@@@@@@@@@@ @@@@ 5 @@@ REMARK...
  • Page 280: Klen ( Returns The Number Of Characters Of The Character String That Includes Full-Byte Characters )

    11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q KLEN Function Kanji LENgth • Returns the number of characters of the character string that includes full-byte characters. KLEN (<character string expression> [, <function> ]) Syntax character string expression • • • • Specify the target character string. function •...
  • Page 281 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q Program Example 10 ' Counts the number of overall, half-byte, and full-byte characters 20 A$="AD51H@@@@@@@" ' Defines the character string 30 A=KLEN(A$,0) ' Total number of characters 40 B=KLEN(A$,1) ' Number of half-byte characters 50 C=KLEN(A$,2) ' Number of full-byte characters 60 PRINT "Character string -->";A$ 70 PRINT "Number of overall characters ------>";A...
  • Page 282: Kmid

    11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q KMID$ Function Kanji MiDdle $ • Returns the partial character string that starts at the specified position of a character string that includes full-byte characters. KMID$ ( <character string expression> , <numeric expression 1> [, <numeric expression 2> ]) Syntax character string expression •...
  • Page 283 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q Program Example 10 'Extracts data, considering full-byte characters as one character 20 A$="AD51H@@@@@@@" ' Defines the character string 30 B$=KMID$(A$,6,2) ' Extracts two characters from the 6th character in the character string 40 PRINT "Original character string ------>";A$ 50 PRINT "Extracted character string -->";B$ 60 END Original character string ------>...
  • Page 284: Kmode ( Performs Conversion Settings Of Kanji Code )

    11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q KMODE Instruction Kanji MODE • Performs conversion settings of Kanji code. KMODE <conversion designation> Syntax <conversion designation> • • • • Specify enabling/disabling of Kanji code conversions KMODE 1 • • • • Performs Kanji code conversion using an interface Examples where Kanji conversion is allowed using the ZCNTL instruction.
  • Page 285 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q • The following procedure shows how to perform Kanji code conversion. 1) Open the communication port to be used and perform settings. (ZOPEN and ZCNTL instructions) 2) Perform Kanji shift-in/shift-out code settings. (ZCNTL instruction process code 100 ) 3) Specify the Kanji code conversion of the ZCNTL instruction.
  • Page 286 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q REMARK • See Sections 7.2.1 and 7.3.3. • Since there are a large number of Kanji characters, all the characters cannot be assigned a character number in the 256 different character codes of one byte (8 bits).
  • Page 287 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q KNJ$ Function KaNJi $ • Returns the full-byte character of the specified Kanji code. KNJ$ ( <character string expression> ) Syntax character string expression • • • • Specify a Kanji code. A$=KNJ$(“3441”) • • • • Assigns the Kanji code 3441 @) to A$.
  • Page 288: Ktype

    11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q KTYPE Function Kanji TYPE • Returns the character type of the specified position within the character string that includes full-byte characters. KTYPE ( <character string expression> , <numeric expression> ) Syntax character string expression • • • • Specify the applicable character string for the process numeric expression...
  • Page 289 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q LEFT$ Function LEFT $ • Extracts a character string of the number of characters specified from the left of the character string. LEFT$ ( <character string expression> , <numeric expression> ) Syntax character string expression •...
  • Page 290 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q Program Example 10 ' Extracts 5 characters from the left of the character string 20 A$="AD51H-BASIC" ' Defines the character string 30 B$=LEFT$(A$,5) ' Extracts 5 characters from the left 50 PRINT "5 characters counting from the left --->";B$ : ' Displays extracted character string 60 END 5 characters counting from the left --->...
  • Page 291: Len ( Returns The Number Of Characters Of A Character String )

    11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q Function LENgth • Returns the number of characters of a character string. LEN ( <character string expression> ) Syntax character string expression • • • • Specify the character string for which the number of characters will be counted.
  • Page 292: Let ( Assigns The Value Of The Expression To A Variable )

    Assigns "1" to numeric variable A. Examples LET A$=”MITSUBISHI” • • • • Assigns character string “MITSUBISHI” to character string variable A$ • The LET instruction assigns the value of an expression to a variable. Description • The LET command may be entirely omitted.
  • Page 293 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q Program Example 10 ' Assigns 1 to Variable A and assigns A + 1 to Variable B 20 A=1 ' Stores 1 in A 30 B=A+1 ' Stores A+1 in B 40 PRINT "A=";A, "B=";B ' Displays A and B 50 END A= 1...
  • Page 294: Lfiles ( Prints The Filenames To The Printer )

    11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q LFILES Instruction LFILES • Prints the filenames stored on a memory card, FD or HD to the printer. LFILES [“ [<drive number> :] [ <system name>\] “] [, S] Syntax drive number • • • • Specify the memory card, FD, or HD used to display files.
  • Page 295 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q While printing is in progress, all keys are not be accepted, including the Break and Ctrl + C keys. To stop printing, turn off the printer or set it to the offline status. The printer output process will stop after approximately 5 seconds. 11 - 125 11 - 125...
  • Page 296: Line Input ( Stores The Key Input Into A Character String Variable )

    11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q LINE INPUT Instruction LINE INPUT • Stores the entire line (255 characters or less) of the key input into a character string variable without any delimiters. LINE INPUT [” <display character string> ”;] <character string variable> Syntax display character string •...
  • Page 297 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q Program Example 10 ' Enters the character string until the Enter key is pressed 20 LINE INPUT "Address: ";A$ 30 LINE INPUT "Name: ";B$ : ' Enters the character string 40 PRINT 50 PRINT A$;" : ";B$ ' Displays entered character string 60 END Address : NAGOYA...
  • Page 298 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q LINE INPUT# Instruction LINE INPUT # • Stores the entire line (255 characters or less) from a sequential file into a character string variable without any delimiters. LINE INPUT # <file number> , <character string variable> Syntax file number •...
  • Page 299: List ( Displays The Program )

    11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q LIST Instruction LIST • Displays the entire program or a portion of it within the program area. LIST [ <line number 1> [- [ <line number 2> ] ] ] Syntax line number 1 • • • • Specify the line number to start the program list.
  • Page 300: Llist ( The Program Will Be Printed To The Printer )

    11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q LLIST Instruction LLIST • The entire program area or a portion of the program within the specified range will be printed to the printer. LLIST [ <line number 1> [- [ <line number 2> ] ] ] Syntax line number 1 •...
  • Page 301: Load ( Reads Programs )

    11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q LOAD Instruction LOAD • Reads programs from a memory card, FD, or HD. LOAD ” [ <drive number> :] [ <system name>\] <file name> ” Syntax drive number • • • • Specify the memory card, FD or HD where the file to be loaded is stored.
  • Page 302: Loc ( Returns The Current Logical Location Within A File )

    11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q Function LOCation • Returns the current logical location within a file. LOC ( <file number> ) Syntax file number • • • • Specify the file number of the file in order to detect its current location.
  • Page 303: Locate ( Specifies The Display Position On The Console Screen )

    11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q LOCATE Instruction LOCATE • Specifies the display position on the console screen. LOCATE <horizontal position> , <vertical position> [, <cursor switch> ] Syntax horizontal position • • • • Specify the screen display position in the horizontal direction (X-axis).
  • Page 304 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q Program Example 10 ' Displays the character string at the specified location on the screen 11 CLS ' Clears the screen 12 Y=1 20 A$="AD51H-BASIC" ' Defines the character string 30 FOR X=1 TO 10 40 Y=Y+1 50 LOCATE X,Y ' Specifies display location...
  • Page 305 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q Function Length Of File • Returns the size of a file in record units (number of sectors). LOF ( <file number> ) Syntax file number • • • • Specify the file number specified by the OPEN instruction.
  • Page 306: Log ( Returns A Natural Logarithm Value )

    11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q Function LOGarithm • Returns a natural logarithm value. LOG ( <numeric expression> ) Syntax numeric expression • • • • Specify the value of which natural logarithm is obtained. A=LOG(10) • • • • Stores the natural logarithm of 10 to A. Examples •...
  • Page 307: Lprint ( Outputs Data To The Printer )

    11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q LPRINT Instruction LPRINT • Outputs data to the printer. LPRINT [ <equation> [, <equation> ] ...] [;] Syntax equation • • • • Specify the data to be output to the printer. LPRINT “ABC” • • • • Outputs ABC to the printer.
  • Page 308: Lprint Using ( Outputs Data In The Specified Format To The Printer )

    11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q LPRINT USING Instruction LPRINT USING • Outputs data in the specified format to the printer. LPRINT USING ” <display format> “; <expression> [, <expression> ] ... [;] Syntax display format • • • • Specify the format for the character string or numeric values to be displayed.
  • Page 309: Lset ( Moves Data From Memory To The Random File Buffer And Stores Left-Justified )

    • • • • Specify the character string data to be written. LSET A$=”MITSUBISHI” • • • • Reserves “MITSUBISHI” in A$ justified to the left. Examples Random file buffer LSET • The LSET instruction moves the data from the memory to the random file buffer to prepare Description it for the PUT instruction.
  • Page 310: Merge ( Merges Programs In The Memory And A Read Program )

    11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q MERGE Instruction MERGE • Merges programs in the memory and a program stored in a memory card, FD, or HD. MERGE ” <drive number> : <system name>\<file name> ” Syntax drive number • • • • Specify the memory card, FD or HD where the file to be merged is stored.
  • Page 311 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q • If there is a line with the same number in both the program in the memory and the program to be merged, the line in the program to be merged will take priority. • After the MERGE instruction is complete, BASIC will wait for the next instruction. To use the MERGE instruction in a program, use the CHAIN instruction to specify it.
  • Page 312 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q MID$ (Part 1) Function MIDdle $ • Replaces a section of a character string with another character string. MID$( <character string expression 1> , <integer expression 1> [, <integer expression 2> ] ) Syntax = <character string expression 2> character string expression 1 •...
  • Page 313 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q Program Example 10 ' Replaces character string 20 A$="ABCDEFGHI" ' Defines character string 30 B$="XYZ" ' Defines character string to replace with 40 PRINT "Original Character String-------->";A$ 50 MID$(A$,3,3)=B$ ' Replaces 60 PRINT "Character string after replacement-->";A$ 70 END Original character string -------->ABCDEFGHI Character string after replacement-->ABXYZFGHI...
  • Page 314: Mid$ (Part 2)

    11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q MID$ (Part 2) Function MIDdle $ • Returns the partial character expression that begins with the specified position in a character string. MID$( <character string expression> , <integer expression 1> [, <integer expression 2> ] ) Syntax character string expression 1 •...
  • Page 315 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q MKD$ Function MaKe Double $ • Converts a double-precision type numeric value into a character string. MKD$ ( <double precision expression> [, S] ) Syntax double precision expression • • • • Specify the double precision expression to be converted into a character string.
  • Page 316 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q The CVD function converts the required number of bytes from the left side of each variable area specified by the FIELD instruction. • The data converted to character strings using the MKD$ function may be used for data communication as well as for writing to the random file buffer.
  • Page 317: Mkdmbf

    11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q MKDMBF$ Function MaKe Double Microsoft Binary Format $ • Converts data of IEEE format double-precision internal expression to a character string that can be converted to a numeric value using the CVD function. MKDMBF$ ( <numeric expression> ) Syntax numeric expression •...
  • Page 318 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q MKI$ Function MaKe Integer $ • Converts an integer type numeric value into a character string. MKI$ ( <integer expression> [, S] ) Syntax integer expression • • • • Specify the integer to be converted into a character string.
  • Page 319 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q MKS$ Function MaKe Single $ • Converts a single-precision type numeric value into a character string. MKS$ ( <single precision expression> [, S] ) Syntax single precision expression • • • • Specify the single precision expression to be converted into a character string.
  • Page 320: Mksmbf

    11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q MKSMBF$ Function MaKe Single Microsoft Binary Format $ • Converts data of floating point real numbers used by the AnA/AnU/AnUSCPU (IEEE format single-precision internal expression) into a character string that can be converted to a numeric value using the CVS function.
  • Page 321 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q Program Example 10 ' Reads AnACPU floating point real numbers from D0 and D1 and convert them into single- precision real numbers 30 DIM TBL%(5),A%(3) ' Defines array 40 TBL%(0)=255 ' Sets communication station number to local station 50 TBL%(1)=1 ' Specifies to read the device memory data...
  • Page 322: Name ( Changes File Names )

    11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q NAME Instruction NAME • Changes file names of program and data files stored in a memory card, FD, and HD. NAME ”<drive number>:<system name\> <old file name>” Syntax AS ”<drive number>:<system name\> <new file name>” drive number •...
  • Page 323 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q • Specify the name and extension of the file whose name is to be changed for <old file name>. Specify only the name of the file when specifying a file name without extension. • Specify the new name and extension given to the file for <new file name>. If the extension is omitted, the file name will not contain an extension.
  • Page 324: New ( Erases All Programs In Memory And Initializes All Variables )

    11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q Instruction • Erases all programs in memory and initializes all variables. Syntax • • • • Erases all programs in memory and initializes all Examples variables. • The NEW instruction erases all programs currently resident in memory and initializes Description memory before entering a new program.
  • Page 325 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q OCT$ Function OCTal $ • Converts a numeric value into a character string variable in octal notation. OCT$ (<numeric expression>) Syntax numerical expression • • • • Specify a value within the range between -32768 and 65535.
  • Page 326 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q REMARK See the BIN$, HEX$, and VAL functions. Octal numbers are expressed by placing "&0" in front of the numeric value. Example Decimal number Octal number &O310 Use the VAL function to convert a character string variable in octal notation into a decimal number.
  • Page 327: On Com Gosub ( Branches To Subroutine When An Interrupt Occurs From A Communication Line )

    11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q ON COM GOSUB Instruction ON COMmunication GO to SUBroutine • Defines the starting line of the processing routine to be branched to when an interrupt occurs from a communication line. ON COM(<channel number>) GOSUB <line number> Syntax channel number •...
  • Page 328 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q Program Example (Executed in BASIC on the AD51H) 10 ' This program receives data continually and ends only when an interrupt occurs from CH2 20 ON ERROR GOTO 500 ' Branches to line 500 if an error occurs 30 CLS 40 ON COM(2) GOSUB 340 ' Branches to line 340 when there is an...
  • Page 329 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q 400 ZRECEIVE #CH%,0,TBL2%( ),CTBL%( ) ' Executes the reception operation 410 LOCATE 0,15 420 PRINT "RECEIVE CHARACTER =";TBL2%(1) ' Displays the number of received characters 430 FOR I%=0 TO WOR%-1 440 LOCATE 0,16+I% 450 PRINT "RECEIVE DATA =&H";HEX$(CTBL%(I%)) : ' Displays the data received 460 NEXT I% 470 RETURN 310...
  • Page 330 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q (Executed in BASIC on the LM7000) 10 ' This program sends data to the console (transmission from the LM7000) 20 ON ERROR GOTO 380 'Branches to line 360 if an error occurs 30 ' 40 '***** RS-232C CH.OPEN ***** 50 DIM T%(8) ' Defines the array 60 CH%=18...
  • Page 331 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q REMARK See the CON ON/OFF/STOP and ZOPEN functions, and Section 7.4. 11 - 161 11 - 161...
  • Page 332: On Error Goto ( Branch To An Error Handling Routine If An Error Occurs )

    11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q ON ERROR GOTO Instruction ON ERROR GOTO • Enables interrupt processing if an error occurs and moves the execution to the starting line of an error handling routine. ON ERROR GOTO <line number> Syntax line number •...
  • Page 333 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q Program Example 10 ' This program displays "ERROR" if an error occurs 20 ON ERROR GOTO 50 ' Defines the branch destination at error generation 30 ERROR 10 ' An error occurs 40 END 50 PRINT "ERROR" 60 RESUME 40 ' Ends error processing ERROR...
  • Page 334: On Gosub ( Branches To Subroutine Depending On The Value Of The Specified Expression )

    11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q ON GOSUB Instruction ON to GOSUB • Branches the program execution to one of several specified line numbers depending on the value of the specified expression. ON <expression> GOSUB <line number>[,<line number>…] Syntax expression • • • • Branches to the specified line number depending on the value of the expression.
  • Page 335 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q Program Example 10 ' This program branches to a subroutine depending on the value of variable A 20 INPUT A ' Enters a value 30 ON A GOSUB 100, 200, 300 ' Branches to a subroutine depending on the value 40 END 100 PRINT "This is the subroutine when 1 is entered":RETURN...
  • Page 336: On Goto

    11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q ON GOTO Instruction ON to GOTO • Branches the program execution to one of several specified line numbers depending on the value of the specified expression. ON <expression> GOTO <line number>[,<line number>…] Syntax expression • • • • Branches to the specified line number depending on the value of the expression.
  • Page 337 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q Program Example 10 ' This program branches depending on the value of variable A 20 INPUT A ' Enters a value 30 ON A GOTO 100, 200, 300 ' Branches depending on the value 40 END 100 PRINT "This is the processing when 1 is entered": END 200 PRINT "This is the processing when 2 is entered": END 300 PRINT "This is the processing when 3 is entered": END...
  • Page 338 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q OPEN Instruction OPEN • Opens a file and enables it for input/output processing. OPEN ”[<drive number>:][<system name>\]<file name>” Syntax [ FOR <mode>] AS [#]<file number> drive name • • • • Specify the memory card or FD drive containing the file to be opened.
  • Page 339 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q • If the FOR <mode> part of the instruction is omitted, it is specified that the processing can be performed on a random file. • In INPUT and APPEND modes, if the specified file does not exist, a “File not found” error occurs.
  • Page 340 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q PCRD Instruction PC ReaD • Reads various data from the PLC CPU. PCRD <control table> , <storage area for data read> Syntax control table • • • • Specify the type of data to be read from the PLC CPU.
  • Page 341 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q The number of elements is 10 or less for all the arrays used for <control table>. However, the arrays should always be defined using the DIM instruction. If an array is not defined using the DIM instruction, an error occurs at the execution of the PCRD instruction (usually, an array with 10 or fewer elements can be used without defining it).
  • Page 342 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q Reading device memory data Processing Code 1 Control table format definition Element position Item Description Format 1 Format 2 %(0) • • • • • • • Station number Specify the station number of the PLC. %(0) Control table Specify a control table of format 2.
  • Page 343 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q • When bit units are specified • Bit devices 1 to 256 points • When word units are specified • Bit devices 1 to 32 words • Word devices 1 to 64 points Format 2 control table %(0) •...
  • Page 344 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q Program Example (1) Program example for format 1 control table 100 ' A program example that reads device memory data of the PLC CPU 110 DIM TBL%(10),A%(20) 'Defines arrays 120 TBL%(0)=255 'Specifies the station number to communicate with to the local station 130 TBL%(1)=1 'Specifies to read device memory data...
  • Page 345 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q Reading device memory registered to be monitored by the PCWT instruction Processing Code 2 Control table format definition Element position Item Description Format 1 Format 2 %(0) • • • • • • • Station number Specify a control table of format 2.
  • Page 346 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q (2) If the block number of the file registers has been changed in the PLC CPU, the data in the file registers of the new block number is read. 1) When the block number has been changed using the RSET instruction for extending the file registers of type SW GHP-UTLPC-FN1 utility software package or type SW SRX-FNUP software package.
  • Page 347 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q Program Example (1) Program example for format 1 control table 100 ' A program example that reads data of device memory registered to be monitored by the PCWT instruction 110 DIM TBL%(10), A%(20), TBL2%(10), B%(20) 'Defines arrays 120 A%(0)=1:A%(1)=0 'Registers X000 to X015 to be monitored...
  • Page 348 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q (2) Program example for format 2 control table 100 'A program example that reads device memory registered to be monitored by the PCWT instruction 110 DIM TBL1%(10), A%(20), TBL2%(10), B%(20) 'Defines arrays 120 A%(0)=1:A%(1)=0 'Registers X000 to X015 to be monitored 130 A%(2)=2:A%(3)=16 'Registers Y016 to Y031 to be monitored 140 A%(4)=3:A%(5)=96...
  • Page 349 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q Reading extension file register data Processing Code 4 Control table format definition Element position Item Description Format 1 Format 2 %(0) • • • • • • • Station number Specify the station number of the PLC. %(0) Control table Specify a control table of format 2.
  • Page 350 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q Format 2 control table %(0) • • • • • • Format 2 control table • Specify 256. %(1) • • • • • • Specify the network number of the network to be accessed. See Section 4.2.2 for the allowable specification range.
  • Page 351 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q Program Example (1) Program example for a format 1 control table 100 ' A program example that reads extension file register data 110 DIM TBL%(10),A%(20) 'Defines arrays 120 TBL%(0)=255 'Specifies the station number to communicate with to the local station 130 TBL%(1)=4 'Specifies to read extension file register data...
  • Page 352 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q Reading extension file registers registered to be monitored by the PCWT Processing Code 5 instruction Control table format definition Element position Item Description Format 1 Format 2 %(0) • • • • • • • Station number Specify the station number of the PLC.
  • Page 353 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q Program Example (1) Program example for a format 1 control table 100 'A program example that reads extension file registers registered to be monitored by the PCWT instruction 110 DIM TBL1%(10), A%(20), TBL2%(10), B%(20) 'Defines arrays 120 TBL1%(0)=255 'Specifies the station number to communicate with to the local station...
  • Page 354 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q (2) Program example for a format 2 control table 100 'A program example that reads extension file registers registered to be monitored by the PCWT instruction 110 DIM TBL1%(10), A%(20), TBL2%(10), B%(20) 'Defines arrays 120 TBL1%(0)=256 'Specifies a format 2 control table 130 TBL1%(1)=1 'Specifies network number 1...
  • Page 355 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q Reading extension file register data by specifying sequential addresses (direct Processing Code 7 reading) Control table format definition Only applicable to AnA/AnU/AnUS Element position Item Description Format 1 Format 2 %(0) • • • • • • • Station number Specify the station number of the PLC.
  • Page 356 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q Format 2 control table %(0) • • • • • • Format 2 control table • Specify 256. %(1) • • • • • • Specify the network number of the network to be accessed. See Section 4.2.2 for the allowable specification range.
  • Page 357 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q • The device numbers expressed in sequential addresses are automatically assigned in ascending order, starting with the device number with the smallest block number (number 1). Device No. Area of R0 Area of R1 Area of block No.1 8191 Area of R8191...
  • Page 358 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q • Assign values to %(2) and %(3) ( %(5) and %(6) in case of a control table of format 2) in the following manner. • • • • • • Device number expressed in sequential address •...
  • Page 359 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q (2) Program example for a format 2 control table 100 ' A program example that reads extension file register data by specifying sequential addresses 110 DIM TBL%(7),A%(9) 'Defines arrays 120 TBL%(0)=256 'Specifies a format 2 control table 130 TBL%(1)=1 'Specifies network number 1 140 TBL%(2)=1...
  • Page 360 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q Loading a sequence program Processing Code 8 Control table format definition Element position Item Description Format 1 Format 2 %(0) • • • • • • • Station number Specify the station number of the PLC. %(0) Control table Specify a control table of format 2.
  • Page 361 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q Format 2 control table %(0) • • • • • • Format 2 control table • Specify 256. %(1) • • • • • • Specify the number of the network to be accessed. See Section 4.2.2 for the allowable specification range. %(2) •...
  • Page 362 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q • The maximum number of steps in the sequence program is determined by the capacity set by the parameter. The allowable specification range for the starting step count is as follows. Sequence program Specified step Setting value of T0 &HFE00 Setting value of T1...
  • Page 363 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q Program Example (1) Program example for a format 1 control table 100 ' A program example that reads the sequence program in the PLC CPU and saves it on a memory card 110 ' (Capacity of the main sequence program: 8 k steps) 120 DIM TBL%(10),A%(100) 'Defines arrays 130 OPEN"0:PROG8.DAT"FOR OUTPUT AS #1...
  • Page 364 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q Loading a microcomputer program Processing Code 9 Control table format definition Element position Item Description Format 1 Format 2 %(0) • • • • • • • Station number Specify the station number of the PLC. %(0) Control table Specify a control table of format 2.
  • Page 365 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q Format 2 control table %(0) • • • • • • Format 2 control table • Specify 256. %(1) • • • • • • Specify the number of the network to be accessed. See Section 4.2.2 for the allowable specification range. %(2) •...
  • Page 366 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q • The maximum number of bytes in the microcomputer program is determined by the capacity set by the parameter. The starting addresses that can be specified must be in the appropriate ranges as follows. CPU type Capacity of the microcomputer Microcomputer program address program...
  • Page 367 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q Program Example (1) Program example for a format 1 control table 100 ' A program example that loads the microcomputer program and saves it on a memory card 110 ' (Capacity of the microcomputer program: 8 k bytes) 120 OPEN"0:PROG9.DAT"FOR OUTPUT AS #1 'Opens the sequential file 130 DIM TBL%(4),A%(127)
  • Page 368 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q (2) Program example of a format 2 control table 100 ' A program example that loads the microcomputer program and saves it on a memory card 110 ' (Capacity of the microcomputer program: 8 k bytes) 120 OPEN"0:PROG9.DAT"FOR OUTPUT AS #1 'Opens the sequential file 130 DIM TBL%(7),A%(127)
  • Page 369 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q Reading comment data Processing Code 10 Control table format definition Element position Item Description Format 1 Format 2 %(0) • • • • • • • Station number Specify the station number of the PLC. %(0) Control table Specify a control table of format 2.
  • Page 370 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q %(5) • • • • • • Specify the starting address of the comment to be read. The maximum number of bytes of comment data is the capacity set by the parameter. %(6) • • • • • • Specify the number of bytes to be read.
  • Page 371 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q Program Example (1) Program example for a format 1 control table 100 ' A program example that reads the comment data from the PLC CPU and saves it on a memory card 110 ' (Comment capacity: 3 k bytes) 120 OPEN"0:PROG10.DAT"FOR OUTPUT AS #1 'Opens the sequential file 130 DIM TBL%(10),A%(150)
  • Page 372 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q Reading extension comment data Processing Code 11 Control table format definition Element position Item Description Format 1 Format 2 %(0) • • • • • • • Station number Specify the station number of the PLC. %(0) Control table Specify a control table of format 2.
  • Page 373 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q %(5) • • • • • • Specify the starting address of the extension comment to be read. The maximum number of bytes of extension comment data is the capacity set by the parameter. %(6) •...
  • Page 374 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q Program Example (1) Program example for a format 1 control table 100 ' A program example that reads the extension comment data from the PLC CPU and saves it on a memory card 110 ' (Extension comment capacity: 3 k bytes) 120 OPEN"0:PROG11.DAT"FOR OUTPUT AS #1 'Opens the sequential file 130 DIM TBL%(10),A%(150)
  • Page 375 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q Reading a special function module’s buffer memory Processing Code 12 Control table format definition Element position Item Description Format 1 Format 2 %(0) • • • • • • • Station number Specify the station number of the PLC. %(0) Control table Specify a control table of format 2.
  • Page 376 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q %(3) • • • • • • Detailed error codes are stored here. See Appendix 4.4.2 for the details about the error codes. %(4) • • • • • • Processing code • Specify 12. %(5) •...
  • Page 377 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q • The module number (hexadecimal) of the special function module is the two most significant digits of the 3-digit expression of the last address of the special function module’s I/O addresses seen from the PLC CPU. (a) In case of a single-slot module (e.g., AD61, A68AD) •...
  • Page 378 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q (d) In case of a module where both the special function module and an input/output module are allocated (e.g., A81CPU) (In case of A81CPU) • • • • • • Since the last address is 03F , the special function module number is "03 ."...
  • Page 379 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q (f) Module number of the special function module of a MELSECNET/10 remote I/O station The module number of the special function module of a MELSECNET/10 remote I/O station is always the two most significant digits of the 3-digit expression of the last “I/O address seen from a remote I/O station.”...
  • Page 380 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q • Assign values to %(3) and %(4) ( %(6) and %(7) in case of a format 2 control table) in the following manner. • • • • • • • Address viewed from the communication module •...
  • Page 381 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q 2) If an input element is specified as a character variable or character array variable name: PCRD TBL%( ), RD%( ) Number of bytes to be read • • • • 6 bytes Specify Starting address • • • • • • • • • • • Module number •...
  • Page 382 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q Program Example (1) Program example for a format 1 control table 100 'A program example that reads buffer memory 1 of the special function module (A68AD) 110 '(Starting address of A68AD: &H80) 120 DIM TBL%(5),A%(0) 'Defines arrays 130 TBL%(0)=255 'Specifies the station number to...
  • Page 383 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q Reading the type name of the PLC CPU Processing Code 13 Control table format definition Element position Item Description Format 1 Format 2 %(0) • • • • • • • Station number Specify the station number of the PLC. %(0) Control table Specify a control table of format 2.
  • Page 384 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q • The type name of the PLC CPU is stored using the following codes in <storage area for data read>. PLC CPU type name Code read (hexadecimal) A2UCPU A2USCPU A2UCPU-S1 A2USCPU-S1 A3UCPU A4USCPU AJ72LP25/BR25 A2ACPU A2ASCPU-S1 A3ACPU A0J2HCPU...
  • Page 385 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q Program Example (1) Program example for a format 1 control table 100 'A program example that reads the PLC CPU's type name 110 DIM TBL%(1),A%(0) 'Defines arrays 120 TBL%(0)=255 'Specifies the station number to communicate with to the local station 130 TBL%(1)=13 'Specifies to read PLC CPU's type name 140 PCRD TBL%( ),A%( )
  • Page 386 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q Reading parameter data Processing Code 14 Control table format definition Element position Item Description Format 1 Format 2 %(0) • • • • • • • Station number Specify the station number of the PLC. %(0) Control table Specify a control table of format 2.
  • Page 387 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q Format 2 control table %(0) • • • • • • Format 2 control table • Specify 256. %(1) • • • • • • Specify the number of the network to be accessed. See Section 4.2.2 for the allowable specification range. %(2) •...
  • Page 388 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q • Assign values to %(2) and %(3) ( %(5) and %(6) in case of a format 2 control table) in the following manner. • • • • Starting address of the parameter area • • • • Used as work area.
  • Page 389 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q Program Example (1) Program example for a format 1 control table 100 ' A program example that reads parameters from the PLC CPU and saves them on a memory card 110 ' (Four network modules are connected. All the modules are control stations. Network parameter capacity: 16 k bytes) 120 OPEN "0:PROG14.DAT"...
  • Page 390 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q (2) Program example for a format 2 control table 100 'A program example that reads parameters from the PLC CPU and saves them on a memory card 110 '(Four network modules are connected. All the modules are control stations. Network parameter capacity: 16 k bytes) 120 OPEN "0:PROG14.DAT"...
  • Page 391 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q Reading network information Processing Code 21 Control table format definition Element position Item Description Format 1 Format 2 %(0) • • • • • • • Station number Specify the station number of the PLC. %(0) Control table Specify a control table of format 2.
  • Page 392 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q • The following information is read to <storage area for data read>. (1) Number of link/network modules mounted. (2) System code MELSECNET/10 MELSECNET (II), MELSECNET/B (3) Network number MELSECNET (II), MELSECNET/B Other than 0 Network number set (4) Link/network station number 0 to 64 : Station number of the corresponding data link/network module...
  • Page 393 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q Reading routing parameters Processing Code 22 Control table format definition Element position Item Description Format 1 Format 2 %(0) • • • • • • • Station number Specify the station number of the PLC. %(0) Control table Specify a control table of format 2.
  • Page 394 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q Program Example (1) Program example for a format 1 control table 100 DIM TBL%(10),A%(100) ' Defines arrays 110 TBL%(0)=255 ' Specifies the station number to communicate with to the local station 120 TBL%(1)=22 ' Specifies to read routing parameters 130 RCRD TBL%(),A%() ' Executes the read operation 140 END...
  • Page 395 Description Only Format 1 Format 2 Format 3 applicable %(0) Station number Specify the station number of the PLC. QD51 %(0) %(0) Control table Specify a control table of format 2 or.3. (-R24) %(1) %(1) Network number Specify the network number.
  • Page 396 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q Format 3 control table %(0) • • • • • • Format 3 control table • Specify 257 (&H101). %(1) • • • • • • Specify the network number of the network to be accessed. See Section 4.2.2 for the allowable specification range.
  • Page 397 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q Program Example (1) Program example for a format 1 control table 100 'A program example that reads the type name of the Q/QnA series CPU 110 DIM TBL%(10),A%(31) 'Defines the arrays 120 TBL%(0)=255 'Specifies the station number to communicate with to the local station 130 TBL%(1)=513 'Specifies to read Q/QnA series CPU's type...
  • Page 398 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q (3) Program example for a format 3 control table 100 'A program example that reads the type name of the Q/QnA series CPU 110 DIM TBL%(10),A%(31) 'Defines the arrays 120 TBL%(0)=257 'Specifies a format 3 control table 130 TBL%(1)=1 'Specifies network number 1 140 TBL%(2)=1...
  • Page 399 Only Format 1 Format 2 Format 3 applicable %(0) Station number Specify the station number of the PLC. Specify a control table of format 2. QD51 %(0) %(0) Control table (-R24) %(1) %(1) Network number Specify the network number. %(2)
  • Page 400 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q Format 2 control table %(0) • • • • • • Format 2 control table • Specify 256 (&H100). %(1) • • • • • • Specify the network number of the network to be accessed. See Section 4.2.2 for the allowable specification range.
  • Page 401 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q Format 3 control table %(0) • • • • • • Format 3 control table • Specify 257 (&H101). %(1) • • • • • • Specify the network number of the network to be accessed. See Section 4.2.2 for the allowable specification range.
  • Page 402 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q • Assign values to %(3) and %(4) ( %(6) and %(7) in case of a format 2 control table, %(7) and %(8) in case of a format 3 control table) in the following manner. • • • • Device number of the device to be read •...
  • Page 403 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q (2) Program example for a format 2 control table 100 'A program example that reads the device memory of the Q/QnA series CPU 110 DIM TBL%(10),A%(100) 'Defines the arrays 120 TBL%(0)=256 'Specifies a format 2 control table 130 TBL%(1)=1 'Specifies network number 1 140 TBL%(2)=1...
  • Page 404 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q (3) Program example a for format 3 control table 100 'A program example that reads the device memory of the Q/QnA series CPU 110 DIM TBL%(10),A%(100) 'Defines the arrays 120 TBL%(0)=257 'Specifies a format 3 control table 130 TBL%(1)=1 'Specifies network number 1 140 TBL%(2)=1...
  • Page 405 Description Only Format 1 Format 2 Format 3 applicable %(0) Station number Specify the station number of the PLC. QD51 %(0) %(0) Control table Specify a control table of format 2. (-R24) %(1) %(1) Network number Specify the network number.
  • Page 406 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q Format 1 control table %(0) • • • • • • Specify the station number of the PLC CPU from which data is to be read. See Section 4.2.2 for the allowable specification range. %(1) •...
  • Page 407 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q Format 2 control table %(0) • • • • • • Format 2 control table • Specify 256 (&H100). %(1) • • • • • • Specify the network number of the network to be accessed. See Section 4.2.2 for the allowable specification range.
  • Page 408 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q Format 3 control table %(0) • • • • • • Format 3 control table • Specify 257 (&H101). %(1) • • • • • • Specify the network number of the network to be accessed. See Section 4.2.2 for the allowable specification range.
  • Page 409 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q • Assign values to %(6) and %(7) ( %(9) and %(10) in case of a format 2 control table, %(10) and %(11) in case of a format 3 control table) in the following manner. • • • • Device number of the device to be read •...
  • Page 410 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q Program Example (1) Program example for a format 1 control table 100 'A program example that reads the device memory of the Q/QnA series PLC CPU 110 DIM TBL%(20),A%(10) 'Defines the arrays 120 TBL%(0)=255 'Specifies the station number to communicate with to the local station 130 TBL%(1)=516 'Specifies to read random devices of the...
  • Page 411 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q 400 H!=INT(D!/65536!) 'Splits into lower and higher digits 410 L!=D!-H!*65536! 420 H$=RIGHT$("0000"+HEX$(H!),4) 430 L$=RIGHT$("0000"+HEX$(L!),4) 440 L%=VAL("&H"+L$) 450 H%=VAL("&H"+H$) 460 RETURN 11 - 241 11 - 241...
  • Page 412 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q (2) Program example for a format 2 control table 100 'A program example that reads the device memory of the Q/QnA series PLC CPU 110 DIM TBL%(20),A%(10) 'Defines the arrays 120 TBL%(0)=256 'Specifies a format 2 control table 130 TBL%(1)=1 'Specifies network number 1 140 TBL%(2)=1...
  • Page 413 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q 400 PCRD TBL%(),A%() 'Executes the read operation 410 END 420 H!=INT(D!/65536!) 'Splits into lower and higher digits 430 L!=D!-H!*65536! 440 H$=RIGHT$("0000"+HEX$(H!),4) 450 L$=RIGHT$("0000"+HEX$(L!),4) 460 L%=VAL("&H"+L$) 470 H%=VAL("&H"+H$) 480 RETURN 11 - 243 11 - 243...
  • Page 414 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q (3) Program example for a format 3 control table 100 'A program example that reads the device memory of the Q/QnA series PLC CPU 110 DIM TBL%(20),A%(10) 'Defines the arrays 120 TBL%(0)=256 'Specifies a format 2 control table 130 TBL%(1)=1 'Specifies network number 1 140 TBL%(2)=1...
  • Page 415 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q 400 TBL%(23)=0 'Fixed value 410 PCRD TBL%(),A%() 'Executes the read operation 420 END 430 H!=INT(D!/65536!) 'Splits into lower and higher digits 440 L!=D!-H!*65536! 450 H$=RIGHT$("0000"+HEX$(H!),4) 460 L$=RIGHT$("0000"+HEX$(L!),4) 470 L%=VAL("&H"+L$) 480 H%=VAL("&H"+H$) 490 RETURN 11 - 245 11 - 245...
  • Page 416 Description Only Format 1 Format 2 Format 3 applicable %(0) Station number Specify the station number of the PLC. QD51 %(0) %(0) Control table Specify a control table of format 2. (-R24) %(1) %(1) Network number Specify the network number.
  • Page 417 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q Format 1 control table %(0) • • • • • • Specify the station number of the PLC CPU from which data is to be read. See Section 4.2.2 for the allowable specification range. %(1) •...
  • Page 418 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q Format 3 control table %(0) • • • • • • Format 3 control table • Specify 257 (&H101). %(1) • • • • • • Specify the network number of the network to be accessed. See Section 4.2.2 for the allowable specification range.
  • Page 419 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q • The starting I/O number (hexadecimal) of the intelligent functional module is the two higher digits of the 3-digit expression of the starting address of the intelligent functional module's I/O addresses seen from the Q/QnA PLC CPU. (a) In case of a single-slot module •...
  • Page 420 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q (d) In case of a module where both an intelligent functional module and an input/output module are allocated (e.g., A81CPU) • • • • • • Since the starting address is 000 , the special function module number is "00 ."...
  • Page 421 (-R24) or vice versa, the operation is performed in units of 8 bits (one byte) per one address. The addresses (hexadecimal) to specify in the QD51 (-R24) are obtained by the following conversion from addresses for the FROM/TO instructions. Specified address (hexadecimal) = convert {(address for the FROM/TO instruction...
  • Page 422 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q • Data is stored in <storage area for data read> as follows: Example : When reading data in buffer memory addresses 1 to 3 from an AD61 module whose I/O addresses are X/Y40 to X/Y5F. 1) If an integer variable or array variable is specified for an input element, data is stored as follows: PCRD TBL%( ), RD%( )
  • Page 423 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q Program Example (1) Program example for a format 1 control table 100 'A program example that reads buffer memory 1 of the intelligent functional module (Q68AD) 110 '(Starting address of Q68AD: &H80) 120 DIM TBL%(10),A%(20) 'Defines the arrays 130 TBL%(0)=255 'Specifies the station number to...
  • Page 424 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q (2) Program example for a format 2 control table 100 'A program example that reads buffer memory 1 of the intelligent functional module (Q68AD) 110 '(Starting address of Q68AD: &H80) 120 DIM TBL%(20),A%(10) 'Define arrays 130 TBL%(0)=256 'Specifies a format 2 control table 140 TBL%(1)=1...
  • Page 425 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q (3) Program example for a format 3 control table 100 'A program example that reads buffer memory 1 of the intelligent functional module (Q68AD) 110 '(Starting address of Q68AD: &H80) 120 DIM TBL%(20),A%(10) 'Defines the arrays 130 TBL%(0)=256 'Specifies a format 2 control table 140 TBL%(1)=1...
  • Page 426 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q PCWT Instruction PC WriTe • This instruction is used to write various data to the PLC CPU. • This instruction is used to operate the PLC CPU. PCWT <control table>, <storage area for data to be written> Syntax Control table •...
  • Page 427 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q • <Storage area for data to be written> is a variable or device range that stores the data to be written to the PLC CPU. Specify an integer variable, integer array name, character variable, character array variable, extension registers ED, or extension relays EM.
  • Page 428 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q Writing to device memory Processing Code 1 Control table format definition Element position Item Description Format 1 Format 2 %(0) • • • • • • • Station number Specify the station number of the PLC. %(0) Control table Specify a control table of format 2.
  • Page 429 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q • When word units are specified • Bit devices 1 to 32 words • Word devices 1 to 64 points Format 2 control table %(0) • • • • • • Format 2 control table •...
  • Page 430 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q • The following processing is performed if file registers are specified as the device memory to be written to: (1) If the file registers have never been changed in the PLC CPU, data is written to the file registers of block number 0.
  • Page 431 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q (2) Program example for a format 2 control table 100 ' A program example that writes data to device memory of the PLC CPU 110 DIM TBL%(10),A%(20) 'Defines arrays 120 TBL%(0)=256 'Specifies a format 2 control table 130 TBL%(1)=1 'Specifies network number 1 140 TBL%(2)=1...
  • Page 432 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q Monitor registration of device memory Processing Code 2 Control table format definition Element position Item Description Format 1 Format 2 %(0) • • • • • • • Station number Specify the station number of the PLC. %(0) Control table Specify a control table of format 2.
  • Page 433 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q Format 2 control table %(0) • • • • • • Format 2 control table • Specify 256. %(1) • • • • • • Specify the network number of the network to be accessed. See Section 4.2.2 for the allowable specification range.
  • Page 434 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q • Specify extension devices to be monitored using integer arrays for the number of points monitored in <storage area for data to be written>. When specifying the nth device point × ((n - 1) Specify the device type using the defined code number. See Section 4.2.5 for the code numbers.
  • Page 435 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q Program Example (1) Program example for a format 1 control table 100 ' A program example that reads device memory registered to be monitored by the PCWT instruction 110 DIM TBL1%(10),A%(20),TBL2%(10),B%(20) 'Defines arrays 120 A%(0)=1:A%(1)=0 'Registers X000 to X015 to be monitored 130 A%(2)=2:A%(3)=16 'Registers Y016 to Y031 to be monitored...
  • Page 436 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q (2) Program example for a format 2 control table 100 ' A program example that reads device memory registered to be monitored by the PCWT instruction 110 DIM TBL%(10),A%(20),TBL2%(10),B%(20) 'Defines arrays 120 A%(0)=1:A% (1)=0 'Registers X000 to X015 to be monitored 130 A%(2)=1:A% (3)=16 'Registers Y016 to Y031 to be monitored 140 A%(4)=3:A% (5)=96...
  • Page 437 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q Random writing to device memory Processing Code 3 Control table format definition Element position Item Description Format 1 Format 2 %(0) • • • • • • • Station number Specify the station number of the PLC. %(0) Control table Specify a control table of format 2.
  • Page 438 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q Format 2 control table %(0) • • • • • • Format 2 control table • Specify 256. %(1) • • • • • • Specify the network number of the network to be accessed. See Section 4.2.2 for the allowable specification range.
  • Page 439 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q • Specify the devices to which data is to be written along with the data itself using integer arrays for the number of points to be written in <storage area for data to be written>. When specifying the nth device point ×...
  • Page 440 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q Program Example (1) Program example for a format 1 control table 100 ' A program example that writes data nonsequentially to device memory 110 DIM TBL%(10),A%(20) 'Defines arrays 120 TBL%(0)=255 'Specifies the station number to communicate with to the local station 130 TBL%(1)=3 'Specifies to write data nonsequentially to...
  • Page 441 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q Writing to extension file registers Processing Code 4 Control table format definition Element position Item Description Format 1 Format 2 %(0) • • • • • • • Station number Specify the station number of the PLC. %(0) Control table Specify a control table of format 2.
  • Page 442 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q Format 2 control table %(0) • • • • • • Format 2 control table • Specify 256. %(1) • • • • • • Specify the network number of the network to be accessed. See Section 4.2.2 for the allowable specification range.
  • Page 443 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q Program Example (1) Program example for a format 1 control table 100 ' A program example that writes data to extension file registers 110 DIM TBL%(10),A%(20) 'Defines arrays 120 TBL%(0)=255 'Specifies the station number to communicate with to the local station 130 TBL%(1)=4 'Specifies to write data to extension file...
  • Page 444 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q Monitor registration of extension file registers Processing Code 5 Control table format definition Element position Item Description Format 1 Format 2 %(0) • • • • • • • Station number Specify the station number of the PLC. %(0) Control table Specify a control table of format 2.
  • Page 445 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q • Specify the extension file registers to be monitored using integer arrays for the number of points to be monitored in <storage area for data to be written>. When specifying the nth device point × ((n - 1) Specify the block number of the extension file registers.
  • Page 446 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q Program Example (1) Program example for a format 1 control table 100 ' A program example that monitors extension file registers registered to be monitored by the PCWT instruction 110 DINM TBL1%(10),A%(20),TBL2%(10),B%(20) 'Defines arrays 120 TBL1%(0)=255 'Specifies the station number to communicate with to the local station 130 TBL1%(1)=5...
  • Page 447 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q (2) Program example for a format 2 control table 100 ' A program example that monitors extension file registers registered to be monitored by the PCWT instruction 110 DIM TBL1%(10),A%(20),TBL2%(10),B%(20) 'Defines arrays 120 TBL1%(0)=256 'Specifies a format 2 control table 130 TBL1%(1)=1 'Specifies network number 1 140 TBL1%(2)=1...
  • Page 448 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q Random writing to extension file registers Processing Code 6 Control table format definition Element position Item Description Format 1 Format 2 %(0) • • • • • • • Station number Specify the station number of the PLC. %(0) Control table Specify a control table of format 2.
  • Page 449 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q • Specify the extension file registers to which data is to be written along with the data itself using integer arrays for the number of points to be written in <storage area for data to be written>. When specifying the nth device point ((n - 1) ×...
  • Page 450 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q Program Example (1) Program example for a format 1 control table 100 'A program example that writes data nonsequentially to extension file registers 110 DIM TBL%(10),A%(20) 'Defines arrays 120 TBL%(0)=255 'Specifies the station number to communicate with to the local station 130 TBL%(1)=6 'Specifies to write data nonsequentially to...
  • Page 451 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q Writing data to extension file registers by specifying sequential addresses (direct Processing Code 7 writing) Control table format definition Only applicable to Element position Item Description AnA/AnU/AnUSCPU Format 1 Format 2 %(0) • • • • • • • Station number Specify the station number of the PLC.
  • Page 452 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q Format 2 control table %(0) • • • • • • Format 2 control table • Specify 256. %(1) • • • • • • Specify the network number of the network to be accessed. See Section 4.2.2 for the allowable specification range.
  • Page 453 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q • Device numbers expressed in sequential addresses are automatically assigned in ascending order, starting with the device number with the smallest block number (number 1). Device No. Area of R0 Area of R1 Area of block No.1 8191 Area of R8191...
  • Page 454 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q • Assign values to %(2) and %(3) ( %(5) and %(6) in case of a format 2 control table) in the following manner. • • • • Device number expressed in sequential address • • • • Used as work areas.
  • Page 455 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q (2) Program example for a format 2 control table 100 ' A program example that writes data to extension file registers by specifying sequential addresses 110 DIM TBL%(10),A%(20) 'Defines arrays 120 TBL%(0)=255 'Specifies a format 2 control table 130 TBL%(1)=1 'Specifies network number 1 140 TBL%(2)=1...
  • Page 456 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q Processing Code 8 Writing a sequence program Processing Disabled while Running Control table format definition Element position Item Description Format 1 Format 2 %(0) • • • • • • • Station number Specify the station number of the PLC. %(0) Control table Specify a control table of format 2.
  • Page 457 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q Format 2 control table %(0) • • • • • • Format 2 control table • Specify 256. %(1) • • • • • • Specify the network number of the network to be accessed. See Section 4.2.2 for the allowable specification range.
  • Page 458 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q • The maximum number of steps in the sequence program is determined by the capacity set by the parameter. The allowable specification range for the starting step number is as follows: Sequence program Specified step Setting value of T0 &HFE00 Setting value of T1...
  • Page 459 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q • The timer and counter setting values are stored using the values (hexadecimal) shown in the table below. Example of ladder steps in a program Settings in a program Settings in BASIC & H0000 & H0001 &...
  • Page 460 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q Use the data read from the PLC CPU by using the PCRD instruction for the sequence program to be written. If other data is written, the PLC CPU cannot operate normally. Program Example (1) Program example for a format 1 control table 100 'A program example that writes the sequence program stored in a memory card to the PLC CPU 110 '(Capacity of the main sequence program: 8 k steps) 120 DIM TBL%(10),A%(100)
  • Page 461 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q (2) Program example for a format 2 control table 100 ' A program example that writes the sequence program stored in a memory card to the PLC CPU 110 (Capacity of the main sequence program: 8 k steps) 120 DIM TBL%(10),A%(100) 'Defines arrays 130 OPEN "0:PROG8.DAT"...
  • Page 462 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q Processing Code 9 Writing a microcomputer program Processing Disabled while Running Control table format definition Element position Item Description Format 1 Format 2 %(0) • • • • • • • Station number Specify the station number of the PLC. %(0) Control table Specify a control table of format 2.
  • Page 463 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q Format 2 control table %(0) • • • • • • Format 2 control table • Specify 256. %(1) • • • • • • Specify the network number of the network to be accessed. See Section 4.2.2 for the allowable specification range.
  • Page 464 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q • The maximum number of bytes in the microcomputer program is determined by the capacity set by the parameter. The head addresses that can be specified are as follows: Capacity of the Microcomputer program CPU type name microcomputer program address A0J2HCPU...
  • Page 465 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q Program Example (1) Program example for a format 1 control table 100 ' A program example that writes the microcomputer program stored in a memory card to the PLC 110 ' (Capacity of the microcomputer program: 8 k bytes) 120 DIM TBL%(10),A%(150) 'Defines arrays 130 OPEN "0:PROG9.DAT"...
  • Page 466 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q (2) Program example for a format 2 control table 100 ' A program example that writes the microcomputer program stored in a memory card to the PLC 110 ' (Capacity of the microcomputer program: 8 k bytes) 120 DIM TBL%(10),A%(150) 'Defines arrays 130 OPEN "...
  • Page 467 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q Writing comment data Processing Code 10 Control table format definition Element position Item Description Format 1 Format 2 %(0) • • • • • • • Station number Specify the station number of the PLC. %(0) Control table Specify a control table of format 2.
  • Page 468 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q Format 2 control table %(0) • • • • • • Format 2 control table • Specify 256. %(1) • • • • • • Specify the network number of the network to be accessed. See Section 4.2.2 for the allowable specification range.
  • Page 469 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q Program Example (1) Program example for a format 1 control table 100 ' A program example that writes the comment data stored in a memory card to the PLC CPU 110 ' (Comment capacity: 3 k steps) 120 DIM TBL%(10),A%(150) 'Defines arrays 130 OPEN "0:PROG9.DAT"...
  • Page 470 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q Writing extension comment data Processing Code 11 Control table format definition Element position Item Description Format 1 Format 2 %(0) • • • • • • • Station number Specify the station number of the PLC. %(0) Control table Specify a control table of format 2.
  • Page 471 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q Format 2 control table %(0) • • • • • • Format 2 control table • Specify 256. %(1) • • • • • • Specify the network number of the network to be accessed. See Section 4.2.2 for the allowable specification range.
  • Page 472 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q Program Example (1) Program example for a format 1 control table 100 ' A program example that writes the extension comment data stored in a memory card to the PLC 110 ' (Extension comment capacity: 3 k bytes) 120 DIM TBL%(10),A%(150) 'Defines arrays 130 OPEN "0:PROG9.DAT"...
  • Page 473 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q Writing to the special function module's buffer memory Processing Code 12 Control table format definition Element position Item Description Format 1 Format 2 %(0) • • • • • • • Station number Specify the station number of the PLC. %(0) Control table Specify a control table of format 2.
  • Page 474 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q Format 2 control table %(0) • • • • • • Format 2 control table • Specify 256. %(1) • • • • • • Specify the network number of the network to be accessed. See Section 4.2.2 for the allowable specification range.
  • Page 475 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q • The module number (hexadecimal) of the special function module is the two higher digits of the 3-digit expression of the last address of the special function module's I/O addresses seen from the PLC CPU. (a) In case of a single-slot module (e.g., AD61, A68AD) •...
  • Page 476 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q (d) In case of a module where both the special function module and an input/output module are allocated (e.g., A81CPU) (In case of A81CPU) • • • • • • Since the last address is 03F , the special function module number is "03 ."...
  • Page 477 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q (f) Module number of the special function module of a MELSECNET/10 remote I/O station The module number of the special function module of a MELSECNET/10 remote I/O station is always the two higher digits of the 3-digit expression of the last "I/O address seen from a remote I/O station."...
  • Page 478 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q • Assign values to %(3) and %(4) ( %(6) and %(7) in case of a format 2 control table) in the following manner. • • • Address seen from the communication module Used as work areas. •...
  • Page 479 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q Program Example (1) Program example for a format 1 control table 100 ' A program example that writes data to buffer memory 0 of the special function module (A62DA) 110 ' (Starting address of A62DA: &H0A) 120 DIM TBL%(5),A%(0) 'Defines arrays 130 TBL%(0)=255...
  • Page 480 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q Writing parameter data Processing Code 14 Control table format definition Element position Item Description Format 1 Format 2 %(0) • • • • • • • Station number Specify the station number of the PLC. %(0) Control table Specify a control table of format 2.
  • Page 481 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q • Assign values to %(2) and %(3) ( %(5) and %(6) in case of a format 2 control table) in the following manner. • • • • Head address of the parameter area Used as work areas. •...
  • Page 482 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q Program Example (1) Program example for a format 1 control table 100 ' A program example that writes the parameters stored in a memory card to the PLC CPU 110 ' (Four network modules are connected. All the modules are control stations. Network parameter capacity: 16 k bytes) 120 DIM TBL1%(10),A%(150),TBL2%(10),B%(10) 'Defines arrays...
  • Page 483 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q (2) Program example for a format 2 control table 100 ' A program example that writes the parameters stored in a memory card to the PLC CPU 110 ' (Four network modules are connected. All the modules are control stations. Network parameter capacity: 16 k bytes) 120 DIM TBL1%(10),A%(150),TBL2%(10),B%(10) 'Defines arrays...
  • Page 484 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q Analyzing parameter data Processing Code 15 Control table format definition Element position Item Description Format 1 Format 2 %(0) • • • • • • • Station number Specify the station number of the PLC. %(0) Control table Specify a control table of format 2.
  • Page 485 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q Program Example (1) Program example for a format 1 control table 00 ' A program example that analyzes the parameters of the PLC CPU 110 DIM TBL%(10), A%(10) 'Defines arrays 120 TBL%(0) = 255 'Specifies the station number to communicate with to the local station 130 TBL%(1) = 15 'Specifies to analyze parameter data...
  • Page 486 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q Remote STOP of the PLC CPU Processing Code 16 Control table format definition Element position Item Description Format 1 Format 2 %(0) • • • • • • • Station number Specify the station number of the PLC. %(0) Control table Specify a control table of format 2.
  • Page 487 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q Program Example (1) Program example for a format 1 control table 100 ' A program example that stops a PLC CPU on a remote station 110 DIM TBL%(10), A%(10) ' Defines arrays 120 TBL%(0) = 255 ' Specifies the station number to communicate with to the local station 130 TBL%(1) = 16...
  • Page 488 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q Remote RUN of the PLC CPU Processing Code 17 Control table format definition Element position Item Description Format 1 Format 2 %(0) • • • • • • • Station number Specify the station number of the PLC. %(0) Control table Specify a control table of format 2.
  • Page 489 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q Program Example (1) Program example for a format 1 control table 100 ' A program example that runs a PLC CPU on a remote station 110 DIM TBL%(10), A%(10) 'Defines arrays 120 TBL%(0) = 255 'Specifies the station number to communicate with to the local station 130 TBL%(1) = 17...
  • Page 490 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q Interrupting the PLC CPU Processing Code 20 Control table format definition Element position Item Description Format 1 Format 2 %(0) • • • • • • • Station number Specify the station number of the PLC. %(0) Control table Specify a control table of format 2.
  • Page 491 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q • The PLC CPU executes the following interrupt routines when interrupted from the communication module. AnA/AnU/AnUSCPU • • • • One of the interrupt routines from I16 to I21 CPUs other than Either interrupt routine I16 or interrupt •...
  • Page 492 Only Element position Item Description applicable Format 1 Format 2 Format 3 to QD51 • • • • • • • • • • • • • %(0) Station number Specify the station number of the PLC. (-R24) %(0) %(0) Control table Specify a control table of format 2.
  • Page 493 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q Format 2 control table %(0) • • • • • • Format 2 control table • Specify 256 (&H100). %(1) • • • • • • Specify the network number of the network to be accessed. See Section 4.2.2 for the allowable specification range.
  • Page 494 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q Format 3 control table %(0) • • • • • • Format 3 control table • Specify 257 (&H101). %(1) • • • • • • Specify the network number of the network to be accessed. See Section 4.2.2 for the allowable specification range.
  • Page 495 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q • Assign values to %(3) and %(4) ( %(6) and %(7) in case of a format 2 control table, %(7) and %(8) in case of a format 3 control table) in the following manner. • • • • • • Device number of the device to be written •...
  • Page 496 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q (2) Program example for a format 2 control table 100 'A program example that writes data to a Q/QnA series PLC CPU’s device memory 110 DIM TBL%(10),A%(20) 'Defines arrays 120 TBL%(0)=256 'Specifies a format 2 control table 130 TBL%(1)=1 'Specifies network number 1 140 TBL%(2)=1...
  • Page 497 Only Element position Item Description applicable Format 1 Format 2 Format 3 to QD51 • • • • • • • • • • • • • %(0) Station number Specify the station number of the PLC. (-R24) %(0) %(0) Control table Specify a format 2 or format 3 control table.
  • Page 498 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q Format 1 control table %(0) • • • • • • Specify the station number of the PLC CPU to which data is written. See Section 4.2.2 for the allowable specification range. %(1) • • • • • • Processing code •...
  • Page 499 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q Format 2 control table %(0) • • • • • • Format 2 control table • Specify 256 (&H100). %(1) • • • • • • Specify the network number of the network to be accessed. See Section 4.2.2 for the allowable specification range.
  • Page 500 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q Format 3 control table %(0) • • • • • • Format 3 control table • Specify 257 (&H101). %(1) • • • • • • Specify the network number of the network to be accessed. See Section 4.2.2 for the allowable specification range.
  • Page 501 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q • Assign values to %(6) and %(7) ( %(9) and %(10) in case of a format 2 control table, %(10) and %(11) in case of a format 3 control table) in the following manner. • • • • • • Device number of the device to which data is to be written •...
  • Page 502 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q Program Example (1) Program example for a format 1 control table 100 'A program example that writes data nonsequentially to devices in a Q/QnA series PLC CPU’s device memory 110 DIM TBL%(20),A%(10) 'Defines arrays 120 TBL%(0)=255 'Specifies the station number to communicate with to the local station 130 TBL%(1)=516...
  • Page 503 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q (2) Program example for a format 2 control table 100 'A program example that writes data nonsequentially to devices in a Q/QnA series PLC CPU’s device memory 110 DIM TBL%(20),A%(10) 'Defines arrays 120 TBL%(0)=256 'Specifies a format 2 control table 130 TBL%(1)=1 'Specifies network number 1 140 TBL%(2)=1...
  • Page 504 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q (3) Program example for a format 3 control table 100 'A program example that writes data nonsequentially to devices in a Q/QnA series PLC CPU’s device memory 110 DIM TBL%(20),A%(10) 'Defines arrays 120 TBL%(0)=257 'Specifies a format 3 control table 130 TBL%(1)=1 'Specifies network number 1 140 TBL%(2)=1...
  • Page 505 Only Element position Item Description applicable Format 1 Format 2 Format 3 to QD51 • • • • • • • • • • • • • %(0) Station number Specify the station number of the PLC. (-R24) %(0) %(0) Control table Specify a format 2 control table.
  • Page 506 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q Format 1 control table %(0) • • • • • • Specify the station number of the PLC CPU to which data is written. See Section 4.2.2 for the allowable specification range. %(1) • • • • • • Processing code •...
  • Page 507 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q Format 3 control table %(0) • • • • • • Format 3 control table • Specify 257 (&H101). %(1) • • • • • • Specify the network number of the network to be accessed. See Section 4.2.2 for the allowable specification range.
  • Page 508 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q • The starting I/O number (hexadecimal) of the intelligent functional module is the two higher digits of the 3-digit expression of the starting address of the intelligent functional module’s I/O addresses viewed from the Q/QnA PLC CPU. (a) In case of a single-slot module •...
  • Page 509 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q (d) In case of a module where both an intelligent functional module and an input/output module are allocated (e.g., A81CPU) • • • • • • Since the starting address is 000 , the special function module number is "00 ."...
  • Page 510 FROM/TO instructions. When reading/writing from the special function module’s buffer memory to the QD51 (-R24) or vice versa, the operation is performed in units of 8 bits (one byte) per one address. The addresses (hexadecimal) to specify in the QD51 (-R24) are obtained by the following conversion from addresses for the FROM/TO instructions.
  • Page 511 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q • Data is stored in <storage area for data to be written> as follows: Example: When writing data to buffer memory addresses 1 to 3 of an AD61 module whose I/O addresses are X/Y40 to X/Y5F. 1) If an input element is specified as an integer variable/array, the data is stored as follows: PCRD TBL%( ), SD%( )
  • Page 512 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q Program Example (1) Program example of a format 1 control table 100 'A program example that writes data to buffer memory 1 of the intelligent functional module (Q62DA) 110 ' (Starting address of Q62DA: &H00) 120 DIM TBL%(10),A%(20) 'Defines arrays TBL%(0)=255...
  • Page 513 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q 260 A%(0)=1000 'Specifies the values to be written 270 PCRD TBL%( ),A%( ) 'Executes the write operation 280 END (3) Program example of a format 3 control table 100 'A program example that writes data to buffer memory 1 of the intelligent functional module (Q62DA) 110 ' (Starting address of Q62DA: &H00) 120 DIM TBL%(10),A%(20)
  • Page 514 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q PRINT Instruction PRINT • Displays data on the screen. PRINT [<data to be displayed>][;] Syntax data to be displayed • • • • Specify the numeric values, numeric variables, character strings, or character string variables to be displayed.
  • Page 515 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q PRINT USING Instruction PRINT USING • Displays a character string or numeric value in the specified format. PRINT USING ”<display format>”; <data to be displayed> Syntax display format • • • • Specify the format of the character string or numeric value to be displayed.
  • Page 516 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q [Format specification for a character string] In order to display a character string using the PRINT USING instruction, it is necessary to employ one of the following format characters to determine the format of the character string.
  • Page 517 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q Format character Function Example “.” • A decimal point is inserted. A decimal point can be PRINT USING “ ##.##” ;.78 inserted at any place in the format. 0.78 • If a format string is placed following a decimal point, the corresponding digits are always displayed.
  • Page 518 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q Format character Function Example “,” • If a comma is specified to the left of a decimal point PRINT USING “ ###,.##” ;1234.5 in the format string, digits in the integer part is 1,234.50 divided in three-digit units by commas and then displayed.
  • Page 519 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q PRINT# Instruction PRINT# • Writes data to a sequential file. PRINT #<file number>, <data to be written> Syntax file number • • • • Specify the file number of a file opened as a sequential file using the OPEN instruction. data to be written •...
  • Page 520 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q PRINT# USING Instruction PRINT# USING • Writes data to a sequential file in the specified format. PRINT #<file number>,USING ”<display format>”;<data to be written> Syntax file number • • • • Specify the file number of a file opened as a sequential file using the OPEN instruction.
  • Page 521 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q Instruction • Writes one record from a random file buffer to a random file. PUT #<file number>[,<record number>] Syntax file number • • • • Specify the file number of the file to which data is written.
  • Page 522 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q PUTMEM Instruction PUT MEMory • Writes data to the communication module’s buffer memory, common memory, or extension registers (ED). PUTMEM TO <write destination>,<offset 1>,<FROM> <storage area for data to be Syntax written>,<offset 2>,<number of bytes> write destination •...
  • Page 523 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q • The data specified by <storage area for data to be written>, <offset 2> and <number of Description bytes> is written to buffer memory, common memory, or extension registers (ED) specified by <write destination> and <offset 1>. •...
  • Page 524 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q • Specify a variable or similar that stores the data to be written to buffer memory, etc. for <storage area for data to be written>. In addition, it is necessary that the specified variable stores more data than the amount specified by <offset> and <number of bytes>. An array used as <storage area for data to be written>...
  • Page 525 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q • Specify the length of the data to be written from the starting position specified in <offset 2> for <number of bytes> in byte units. If an integer variable or integer array is specified in <storage area for data to be written>, the number of bytes specified when writing n elements is as follows, since one element (variable) contains 2 bytes: <number of bytes>...
  • Page 526 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q Program Example 10 ' This program writes data to extension registers (TASK 1) 20 ZODV O 'Displays on the console 30 DIM A%(9) 'Defines an array 40 DEF ZEVENT 1 'Defines an event 50 ZEVENT ENABLE 1 'Enables event generation 60 A$="TASK 1 writing data"...
  • Page 527 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q RDSET Function ReaD SET • Reads one bit data from the specified bit of an integer array variable. RDSET(<integer expression>,<array element>) Syntax integer expression • • • • Specify which bit to read from the specified integer array, using an integer from -32768 to 65535.
  • Page 528 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q The range of integers that can be expressed by 16 bits is from -32768 to 32767, which are expressed in hexadecimal as follows. If values from -32768 to -1 are specified in decimal, it is assumed that values from 32768 to 65535 are specified. Decimal Hexadecimal Binary...
  • Page 529 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q READ Instruction READ • Reads a value defined by the DATA instruction and assigns it to a variable. READ <variable name>[,<variable name>]… Syntax variable name • • • • Specify the variable to which the data defined by the DATA instruction is to be assigned.
  • Page 530 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q Instruction REMark • Provides comments (remarks) in a program. [<comment>] Syntax Comment • • • • Write the appropriate comment. REM**AD51H** or • • • • Indicates that the program is related to the AD51H. Examples ‘**AD51H** •...
  • Page 531 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q RENUM Instruction RENUMber • Reassigns line numbers of a program. RENUM [<new start line number>][,[<old start line number>][,<increment>]] Syntax new start line number • • • • Specify the starting number for the line numbers to be assigned anew.
  • Page 532 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q RESTORE Instruction RESTORE • Specifies a line number in such a way that a subsequent READ instruction reads values of the DATA instruction, starting from the first data in the DATA instruction in the specified line number.
  • Page 533 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q RESUME Instruction RESUME • Resumes the program execution after the error handling is completed by the ON ERROR GOTO instruction. RESUME [<position to resume the execution>] Syntax position to resume the • • • • Specify the position where the program execution is execution to be resumed after the error handling.
  • Page 534 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q RIGHT$ Function RIGHT$ • Extracts a character string consisting of the specified number of characters from the right end of a character string and assigns it to a variable. RIGHT$(<character string expression>, <numeric expression>) Syntax character string expression •...
  • Page 535 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q Function RaNDom • Generates random numbers. RND(<numeric expression>) Syntax numeric expression • • • • The generated random number varies depending on whether a positive, 0, or negative number is specified. A=RND(1) • • • • Assigns the value generated by RND(1) to the Examples variable A.
  • Page 536 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q Function ROTation • Returns the bit-rotated value of the memory representation of the specified value. ROT (<numeric expression 1>,<numeric expression 2>) Syntax numeric expression 1 • • • • Specify the value whose bits are rotated, as an integer value.
  • Page 537 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q Program Example 10 ' This program rotates the bits of the value A% 20 A%=&H55FF 30 B%=1 'Specifies the number of bits to be rotated 40 C%=-1 50 D%=ROT(A%,B%) 'Rotates the bits 60 E%=ROT(A%,C%) 70 PRINT "Rotate A%=";A%;" to the left by one bit---> D%=";D% 'Displays the result 80 PRINT "Rotate A%=";A%;"...
  • Page 538 • • • • Specify the character string data to be written. RSET A$=" MITSUBISHI" • • • • Stores " MITSUBISHI" in A$ right-justified. Examples Random file buffer RSET • The RSET instruction moves data from memory to a random file buffer, in preparation for Description the PUT instruction.
  • Page 539 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q RUN (1) Instruction • Starts the execution of the program currently resident in the program area. [<line number>] Syntax line number • • • • Specify the line number where the execution is started. • • • • Starts the execution from the line with the least line Examples number.
  • Page 540 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q RUN (2) Instruction • Executes after loading a program into memory from a memory card, FD, or HD. RUN "[<drive number>:][<system name>\]<file name>" Syntax drive number • • • • Specify the memory card, FD, or HD where the program is saved.
  • Page 541 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q SAVE Instruction SAVE program • Saves a program to a memory card, FD, or HD. SAVE "[<drive number>:][<system name>\]<file name>" Syntax drive number • • • • Specify the memory card, FD, or HD to which the program is saved.
  • Page 542 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q SEARCH Function SEARCH • Searches for the specified value among the elements of the selected array variable and returns the position of the element. SEARCH (<array variable name>,<value to be searched for>[,<start element Syntax position>][,<step value>] ) array variable name •...
  • Page 543 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q Program Example 10 ' This program searches for a value in an array 20 DIM A%(10) 'Defines an array 30 FOR I=0 TO 10 'Repeats from I = 1 to 10 40 A%(I)=I+3 'Stores values in the array variable 50 PRINT "A%(";I;")=";A%(I) 60 NEXT I 70 B=SEARCH(A%,6,0,3)
  • Page 544 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q Function SiGN • Returns the sign of a value. SGN(<numeric expression>) Syntax numeric expression • • • • Specify the value whose sign is to be returned. A=SGN(B%) • • • • Assigns 1 to A if the value of B% is positive, 0 to A if Examples the value of B% is 0, and -1 to A if the value of B% is negative.
  • Page 545 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q Function SHift Arithmetic • Returns the arithmetically shifted value of the memory content of the specified value. SHA(<numeric expression 1>,<numeric expression 2>) Syntax numeric expression 1 • • • • Specify the target value of the arithmetic shift as an integer value.
  • Page 546 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q Program Example 10 ' This program shifts A% arithmetically 20 A%=&H5555 30 B%=1 'Specifies by how many bits the value should be shifte 40 C%=-1 50 D%=SHA(A%,B%) 'Arithmetic shift 60 E%=SHA(A%,C%) 70 PRINT "Shift A%=";A%;" to the left by one bit arithmetically--->D%="; D% Displays the result 80 PRINT "Shift A%=";A%;"...
  • Page 547 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q Function SHifT logical • Returns the logically shifted value of the memory content of the specified value. SHT(<numeric expression 1>,<numeric expression 2>) Syntax numeric expression 1 • • • • Specify the target value of the logical shift as an integer value.
  • Page 548 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q Program Example 10 ' This program shifts A% logically 20 A%=&H5555 30 B%=1 ' Specifies by how many bits the value should be shifted 40 C%=-1 50 D%=SHT(A%,B%) ' Logical shift 60 E%=SHT(A%,C%) 70 PRINT "Shift A%=";A%;" to the left by one bit logically --->D%=";D% ' Displays the result 80 PRINT "Shift A%=";A%;"...
  • Page 549 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q Function SINe • Returns the trigonometric sine function of a value. SIN(<numeric expression>) Syntax numeric expression • • • • Specify a value or numeric variable in radians. A=SIN(3.14159/180*60) • • • • Converts the angle of 60( into radians, calculates the Examples sine value, and assigns it to A.
  • Page 550 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q SPACE$ Function SPACE$ • Returns a null string of a specified length. SPACE$(<numeric expression>) Syntax numeric expression • • • • Specify the length of the null string. A$=SPACE$(10) • • • • Assigns 10 space characters to A$. Examples •...
  • Page 551 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q Function SPaCe • Returns a specified number of blank spaces. SPC(<numeric expression>) Syntax numeric expression • • • • Specify the number of blank spaces to be returned. PRINT SPC(1);A$ • • • • Displays the contents of A$ after one space. Examples •...
  • Page 552 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q Function SQuare Root • Returns the square root of the specified value. SQR(<numeric expression>) Syntax numeric expression • • • • Specify the value for which the square root should be obtained. A=SQR(50) • • • • Assigns 50 (= 7.071067...) to A.
  • Page 553 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q STOP Instruction STOP • Pauses the program execution in edit mode. • Stops the execution of a program, and puts it in the stop status. STOP Syntax STOP • • • • Pauses the program execution and forces it into the Examples status where it waits for further instructions to be entered.
  • Page 554 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q STR$ Function STRing$ • Converts a value to a character string, assuming the value is given as a decimal number. STR$(<numeric expression>) Syntax numeric expression • • • • Specify the value to be converted into a character string.
  • Page 555 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q = 123 = 456 = 1.23456E+07 = 579 A$+B$ = 123 456 = 1.23456E+07 REMARK See the HEX$, OCT$, and VAL functions. 11 - 385 11 - 385...
  • Page 556 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q STRING$ Function STRING$ • Returns the specified character for the specified number of times. STRING$(<numeric expression 1>,<character string expression>) Syntax STRING$(<numeric expression 1>,<numeric expression 2>) numeric expression 1 • • • • Specify the number of characters to be returned. character string expression •...
  • Page 557 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q REMARK See the CHR$, SPACE$, and SPC functions. 11 - 387 11 - 387...
  • Page 558 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q SYSTEM Instruction SYSTEM • Stops BASIC control and returns to system mode of the communication module. • Stops online programming and returns to the main menu screen. SYSTEM Syntax SYSTEM • • • • Stops BASIC control. Examples •...
  • Page 559 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q SWAP Instruction SWAP • Swaps the values of two variables. SWAP <variable 1>,<variable 2> Syntax Variable 1 • • • • Specify the variables whose values are exchanged. Variable 2 • • • • SWAP A%,B% •...
  • Page 560 • • • • Specify the display position relative to the left side of the screen. PRINT TAB(10); • • • • Displays "MITSUBISHI" from the 11th character. Examples "MITSUBISHI" MITSUBISHI 10 blank spaces • The TAB function displays space characters from the current character display position on Description the screen to the character position indicated by <numeric expression>.
  • Page 561 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q Function TANgent • Returns the trigonometric tangent function of a value. TAN(<numeric expression>) Syntax numeric expression • • • • Specify the value or the numeric variable in radians. A=TAN(3.14159/180 45) • • • • Converts the angle of 45( to radians, calculates the Examples tangent value, and assigns it to A.
  • Page 562 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q TIME$ Function TIME$ • Sets the time of the PLC CPU's clock. • Reads the time of the PLC CPU's clock. TIME$="<hour>:<minute>:<second>" Syntax TIME$ Hour • • • • Specify the character string that indicates the hour in the range from "00"...
  • Page 563 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q REMARK •See the User's Manual of the applicable CPU for information about the accuracy of the PLC CPU's clock. • See the DATE$ function. 11 - 393 11 - 393...
  • Page 564 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q TROFF Instruction TRace OFF • Resets the trace (tracking) in a program set by the TRON instruction. TROFF Syntax TROFF • • • • Resets the execution of the trace (tracking). Examples • The TROFF instruction is used to debug programs together with the TRON instruction. Description •...
  • Page 565 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q TRON Instruction TRace ON • Starts a trace (tracking) in a program. TRON Syntax TRON • • • • Executes the trace (tracking). Examples • The TRON instruction is used to debug programs together with the TROFF instruction. Description •...
  • Page 566 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q Function VALue • Returns the value represented by a character string. VAL(<character string expression>) Syntax character string expression • • • • Specify the character string to be converted into a numeric expression. A=VAL("123") • • • • Assigns the value represented by the string "123"...
  • Page 567 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q Program Example 10 ' This program converts character strings to numeric values using the VAL function 20 A$="1234" ' Defines character strings 30 B$="12.34" 40 C$=" 1234" 50 D$="ABC" 60 E$="&H4F 70 F$="&H4F 56" 80 G$=E$+"12" 90 PRINT VAL(A$) ' Converts the character string "1234"...
  • Page 568 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q Variable Word@ • Reads or writes word information in extension registers (ED). W@(<device>,<device number>) Syntax device • • • • Specify the device to be read or written. device number • • • • Specify the number of the device to be read or written.
  • Page 569 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q • In order to write in units of 32 bits, assign data to an integer array variable as 32-bit data using the CIDB and CSNI instructions, and then write to each device. 100 DIM A%(1) Example 110 CDBI 123456!,A%(0) •...
  • Page 570 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q WHILE WEND Instruction WHILE to While END • These instructions are used to execute the group of instructions between WHILE and WEND repeatedly, while the specified condition holds. WHILE <expression> Syntax WEND expression • • • • Specify the condition under which the instructions enclosed by the WHILE to WEND instructions are executed repeatedly.
  • Page 571 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q If the WHILE to WEND instructions are used in combination with the FOR to NEXT instructions, take precautions so that the inner loop is completely contained within the outer loop. (Correct) (Incorrect) FOR to TO FOR to TO WHILE WHILE...
  • Page 572 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q WIDTH Instruction WIDTH • Sets the width of data to be output to the printer. WIDTH LPRINT <output width> Syntax output width • • • • Specify the output width of one line using a value from 30 to 255.
  • Page 573 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q WTSET Instruction WriTe SET • Writes 0 or 1 to the specified bit of an integer array variable. WTSET <integer expression 1>,<integer expression 2>,<array variable> Syntax integer expression 1 • • • • Specify which bit of the specified integer array is to be written to, using an integer from 0 to 65535.
  • Page 574 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q The range of integers that can be expressed by 16 bits is from -32768 to 32767, which are expressed in hexadecimal as follows. If decimal values from -32768 to -1 are specified, it is assumed that values from 32768 to 65535 are specified.
  • Page 575 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q ZBAS Function Z • BASic • Returns the number of the BASIC task area in which the program currently being created or executed resides. ZBAS Syntax A=ZBAS • • • • Assigns the BASIC task number of the program Examples currently being created or executed to A.
  • Page 576 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q ZCLOSE Instruction Z • CLOSE • Closes a communication channel of a communication port used to communicate with an external device. ZCLOSE [#<channel number>], [#<channel number>, • • • ] Syntax channel number • • • • Specify the communication port to be closed.
  • Page 577 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q ZCNTL Instruction Z • CoNTroL • Set communication parameter data for an open communication port and read the status of a communication port. ZCNTL #<channel number>,0,<control table> Syntax channel number • • • • Specify the communication port that is to be set or whose status is to be read.
  • Page 578 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q • Specify which of the communication ports of the communication module is to be used in <channel number>. The channel numbers correspond to the communication ports as follows: Channel number Communication port • • • • CH1 (RS-232C) •...
  • Page 579 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q Specifying communication parameters Processing Code 16 Control table format definition Element position Item Description %(0) Processing code Specify the processing code. %(1) Baud rate Specify the baud rate. %(2) Character length, Specify the character length and parity bit in the parity bit lower and higher bytes, respectively.
  • Page 580 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q Program Example 10 ' This program sets parameters for a communication channel 20 DIM TBL1%(2),TBL2%(3),TBL3%(3),B%(1) ' Defines an arrays 30 A%=1 ' Communication channel CH1 (RS-232C) 40 TBL1%(0)=4800 ' Sets the baud rate 50 TBL1%(1)=&H107 ' Sets the character length and parity bit 60 TBL1%(2)=&H1 ' Sets the stop bit...
  • Page 581 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q Specifying communication control parameters Processing Code 18 Control table format definition Element position Item Description %(0) Processing code Specify the processing code. %(1) DC control, control Specify the DC control method in the lower byte by signals and the signal control method in the higher byte.
  • Page 582 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q Since the DC control and the control by signals require specification using the lower and higher bytes, it is convenient to use hexadecimal numbers as shown below. %(1)=&H Express the lower byte as a 2-digit hexadecimal number. Express the higher byte as a 2-digit hexadecimal number.
  • Page 583 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q Program Example 1 ' This program sets and reads the communication control parameters 10 DIM TBL1%(2),TBL2%(3),TBL3%(3),B%(1) ' Defines arrays 20 CH%=1 ' Defines a channel number 30 TBL1%(0)=4800 ' Sets the baud rate 40 TBL1%(1)=&H8 ' Sets the character length and parity bit 50 TBL1%(2)=&H2 ' Sets the stop bit...
  • Page 584 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q Specifying break characters Processing Code 22 Control table format definition Element position Item Description %(0) Processing code Specify the processing code. %(1) Number of Specify the number of break characters. characters %(2) Break characters 1 Specify the code for break character 1 in the and 2 lower byte and the code for break character 2 in...
  • Page 585 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q If a character equal to one of the set break characters is detected during the execution of the ZRECEIVE instruction, the reception data until the break character is stored in the input element of the receive request, after which the execution of the receive request is ended.
  • Page 586 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q Specifying continuous break characters Processing Code 24 Control table format definition Element position Item Description %(0) Processing code Specify the processing code. %(1) Setting Specify whether or not the setting is to be enabled. %(2) Number of Specify the number of break characters.
  • Page 587 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q Program Example 100 ' This program specifies and reads continuous break characters 110 DIM TBL1%(2),TBL2%(4),TBL3%(4) ' Defines arrays 120 A%=1 ' Communication channel CH1 (RS-232C) 130 TBL1%(0)=9600 ' Sets the baud rate 140 TBL1%(1)=&H107 ' Sets the character length and parity bit 150 TBL1%(2)=&H1 ' Sets the stop bit 160 ZOPEN #A%,TBL1%( )
  • Page 588 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q Turning ON/OFF the RS (RTS) and DTR (ER) control signals Processing Code 32 Control table format definition Element position Item Description %(0) Processing code Specify the processing code. %(1) RS (RTS) and DTR Specify ON/OFF of the RS (RTS) and DTR (ER) control signals (ER) control signals to the lower and higher bytes, respectively.
  • Page 589 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q Program Example 10 ' This program specifies the status of the RS/ER control signals to ON or OFF 20 DIM TBL1%(2),TBL2%(3),TBL3%(1) ' Defines arrays 30 A%=1 ' Defines a channel number 40 TBL1%(0)=9600 ' Sets the baud rate 50 TBL1%(1)=&H108 ' Sets the character length and the parity bit 60 TBL1%(2)=&H1...
  • Page 590 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q Reading the ON/OFF status of the CS (CTR), DSR (DR), RS (RTS), DTR (ER) Processing Code 33 and CD control signals Control table format definition Element position Item Description %(0) Processing code Specify the processing code. %(1) CS (CTS) and DSR Read the status of the CS (CTS) and DSR (DR)
  • Page 591 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q Program Example 10 ' This program reads the ON/OFF status of the CS, DR, RS, ER, and CD control signals 20 DIM TBL1%(2),TBL2%(3) ' Defines arrays 30 CH%=1 ' Specifies the communication channel 40 TBL1%(0)=9600 50 TBL1%(1)=&H108 60 TBL1%(2)=&H1 70 ZOPEN #CH%,TBL1%( )
  • Page 592 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q Specifying high impedance control Processing Code 48 Control table format definition Element position Item Description %(0) Processing code Specify the processing code. %(1) Setting Specify whether or not to set the high impedance control. • This processing code is used to set whether or not the high impedance control is used when the RS-422/485(CH3) and other stations are connected in a 1 : n configuration.
  • Page 593 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q Reading causes of reception errors Processing Code 64 Control table format definition Element position Item Description %(0) Processing code Specify the processing code. %(1) Error causes Read the causes of reception errors into the lower byte. •...
  • Page 594 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q Program Example 5 ' This program reads the causes of reception errors 10 DIM TBL1%(2),TBL2%(1) ' Defines arrays 20 CH%=1 ' Specifies the communication channel 30 TBL1%(0)=9600 40 TBL1%(1)=&H108 50 TBL1%(2)=&H1 60 ZOPEN #CH%,TBL1%( ) ' Opens the communication channel 70 TBL2%(0)=64 ' Specifies to read the causes of reception...
  • Page 595 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q Reading the receive buffer size and the number of characters Processing Code 80 Control table format definition Element position Item Description %(0) Processing code Specify the processing code. %(1) Receive buffer Read the size of the receive buffer. %(2) Number of characters Read the number of characters stored in the...
  • Page 596 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q Specifying Kanji code conversion Processing Code 96 Control table format definition Element position Item Description %(0) Processing code Specify the processing code. %(1) Conversion Specify whether to enable or disable the Kanji specification code conversion. •...
  • Page 597 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q Specifying Kanji shift in/out codes Processing Code 100 Control table format definition Element position Item Description %(0) Processing code Specify the processing code. %(1) Change Specify whether or not to change the Kanji shift in and shift out codes. %(2) Number of shift in Specify the number of characters for the Kanji...
  • Page 598 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q • Specify the characters that actually represent the codes in %(4) to %(8) in case of the shift in codes and in %(9) to %(13) in case of the shift out codes, in units of bytes. Example When the number of characters is specified as 3 (Higher byte) (Lower byte) %(4) (Higher byte) (Lower byte)
  • Page 599 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q Program Example 10 ' This program outputs Kanji code to a printer connected to CH1 20 DIM TBL%(15) ' Defines an array 30 CH%=1 40 TBL%(0)=9600 50 TBL%(1)=&H108 60 TBL%(2)=&H1 70 ZOPEN #CH%,TBL%( ) ' Opens the communication channel 80 TBL%(0)=18 ' Specifies to set the communication control parameters...
  • Page 600 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q Reading the printer status Processing Code 128 Control table format definition Element position Item Description %(0) Processing code Specify the processing code. %(1) Printer status Read the printer status into the lower byte. • It is possible to read the status (terminal error, out of paper, and terminal connection status) of a printer connected to an open parallel interface using this code.
  • Page 601 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q Program Example 10 ' This program reads the printer status 20 DIM TBL%(1) ' Defines an array 30 ZOPEN #4 ' Opens the communication channel 40 TBL%(0)=128 ' Specifies to read the printer status 50 ZCNTL #4,0,TBL%( ) ' Executes the read operation 60 A=RDSET(0,TBL%(1)) ' Reads the bits...
  • Page 602 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q Outputting the initialization signal to the printer Processing Code 136 Control table format definition Element position Item Description %(0) Processing code Specify the processing code. • This processing code is used to send an initialization signal for a duration of 100 ms to a printer connected to the open parallel interface.
  • Page 603 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q Available only in execution mode ZEVENT Instruction Z EVENT • Enables or disables event generation. ZEVENT ENABLE <event number> Syntax ZEVENT DISABLE <event number> ENABLE (enable) • • • • Enable the event generation. DISABLE (disable) •...
  • Page 604 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q ZIDV Instruction Z Input DeVice • Specifies the data input device for the INPUT instruction, etc. ZIDV <channel number> Syntax channel number • • • • Specify the channel number of the communication port to which a console or terminal is connected. ZIDV 1 •...
  • Page 605 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q ZLDV Instruction Z Line printer DeVice • Selects a communication port for a printer. ZLDV <channel number> Syntax channel number • • • • Specify the communication port to which the printer is connected. ZLDV 4 •...
  • Page 606 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q Available only in execution mode ZMESSAGE Instruction Z MESSAGE • Defines a message port. ZMESSAGE <message port number> LEN=<message length> Syntax <message port number> • • • • Specify the number of the message port to be defined.
  • Page 607 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q • Specify the maximum message length that can be transmitted to the message port in <message length>. The specification range is from 1 to 256 bytes. The necessary number of bytes can be found from the following. Note that if several <output element>...
  • Page 608 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q Program Example 10 ' This program exchanges data between tasks via the message ports (TASK 1) 20 DEF ZEVENT 1 ' Defines event 1 30 ZEVENT ENABLE 1 ' Enables the generation of event 1 40 A$=SPACE$(80) ' Stores dummy data in the character variable...
  • Page 609 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q Available only in execution mode ZMESSAGE CLOSE Instruction ZMESSAGE CLOSE • Closes message ports. ZMESSAGE CLOSE [<message port number>] Syntax <message port number> • • • • Specify the number of the message port to be closed.
  • Page 610 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q Available only in execution mode ZMESSAGE GET Instruction ZMESSAGE GET • Reads messages from message ports. ZMESSAGE GET <message port number>, <variable name> • • • [TIMEOUT <timeout Syntax value>] <message port number> • • • • Specify the number of the message port from which the message is to be read.
  • Page 611 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q • If <variable name> is a numeric variable, it is possible to specify multiple <variable name> by separating by commas. In this case, the type of each variable read must correspond correctly to the type of each message written to the message port by the ZMESSAGE PUT instruction.
  • Page 612 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q Available only in execution mode ZMESSAGE KILL Instruction ZMESSAGE KILL • Deletes the defined message ports. ZMESSAGE KILL <message port number> Syntax message port number • • • • Specify the number of the message port to be deleted.
  • Page 613 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q Available only in execution mode ZMESSAGE OPEN Instruction ZMESSAGE OPEN • Opens a previously defined message port. ZMESSAGE OPEN <message port number> Syntax <message port number> • • • • Specify the number of the message port to be opened.
  • Page 614 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q Available only in execution mode ZMESSAGE PUT Instruction ZMESSAGE PUT • Writes messages to a message port. ZMESSAGE PUT <message port number>,<message>, • • • Syntax <message port number> • • • • Specify the number of the message port to which a message is to be written.
  • Page 615 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q REMARK See the ZMESSAGE, ZMESSAGE CLOSE, ZMESSAGE GET, ZMESSAGE KILL and ZMESSAGE OPEN instructions, and Section 8.5.2. 11 - 445 11 - 445...
  • Page 616 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q ZMOVE Instruction ZMOVE • Transfers data between variables. ZMOVE TO <transfer destination>,<offset 1> FROM <transfer source>,<offset Syntax 2>,<number of transferred bytes> transfer destination • • • • Specify the variable, one-dimensional array variable, or one-dimensional numeric array name to which data is to be transferred.
  • Page 617 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q • The ZMOVE instruction is used to transfer data from the area in memory specified in Description <transfer source> in a BASIC program to the area specified in <transfer destination> as is. The transfer is carried out transparently in units of one byte for the amount specified in <number of transferred bytes>.
  • Page 618 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q • Specify the starting location of the data transfer in the memory area of <transfer destination> in <offset 1>. This should be specified as an offset value relative to the starting address of the memory area of <transfer destination>, in byte units. Example Specify 2 for <offset 1>...
  • Page 619 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q • Specify the starting location of the data transfer in the memory area of <transfer source> in <offset 2>. This should be specified as an offset value relative to the starting address of the memory area of <transfer source>, in byte units. Example Specify 1 for <offset 2>...
  • Page 620 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q Program Example 10 ' This program transfers data in the numeric array variable A%( ) to the character string variable B$ 20 DIM A%(9) ' Defines an array 30 A%(0)=&H4241 ' Stores the data 40 A%(1)=&H4443 50 PRINT "A%(0)=";HEX$(A%(0)) ' Displays the data before being transferred 60 PRINT "A%(1)=";HEX$(A%(1))
  • Page 621 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q ZODV Instruction Z Output DeVice • Specifies the data output destination for the PRINT instruction, etc. ZODV <channel number> Syntax channel number • • • • Specify the channel number of the communication port to which a console or terminal is connected. ZODV 1 •...
  • Page 622 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q ZOPEN Instruction Z OPEN • Opens a communication channel of a communication port in preparation for performing communication with an external device. ZOPEN [#]<channel number>[<,control table>] Syntax channel number • • • • Specify the communication port that communicates with the external device.
  • Page 623 Select and set one of the following: 300, 600, 1200, 2400, 4800, 9600, or 19200 bps • In case of QD51 (-R24) Select and set one of the following: 300, 600, 1200, 2400, 4800, 9600, 14400, 19200, 28800, or 38400 (setting value: -384) Character length •...
  • Page 624 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q ZRECEIVE Instruction Z RECEIVE • Receives data from a communication port. ZRECEIVE #<channel number>,0,<control table>,<input element> Syntax channel number • • • • Specify the communication port that receives data. control table • • • • Specify various parameters for receiving data.
  • Page 625 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q Always define an array used in <control table> by the DIM instruction, even though only three array elements are used. If the array is not defined using the DIM instruction, an error occurs at the execution of the ZRECEIVE instruction (usually, an array with 10 or fewer elements can be used without defining it using the DIM instruction).
  • Page 626 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q (1) When an integer variable is specified, it is possible to receive one integer data value. One integer data value is treated as 2 bytes; therefore, specify 2 bytes for the number of bytes requested to be received. [Request to receive 2 bytes] Integer data Reception...
  • Page 627 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q Program Example (Executed in BASIC on the AD51H) 10 ' This program receives data from the LM7000 (AD51H is the reception side) 20 ON ERROR GOTO 360 ' Branches to line 360 if an error occurs 30 ' 40 '***** RS-232C CH.OPEN ***** 50 DIM TBL1%(2)
  • Page 628 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q (Executed in BASIC on the LM7000) 10 ' This program sends data to a console (LM7000 is the transmission side) 20 ON ERROR GOTO 380 ' Branches to line 360 when an error occurs 30 ' 40 '***** RS-232C CH.OPEN ***** 50 DIM T%(8) ' Defines an array...
  • Page 629 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q REMARK See the ZOPEN, ZSEND and ZCNTL instructions, and Section 7.3.4. 11 - 459 11 - 459...
  • Page 630 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q Available only in execution mode ZRELEASE Instruction ZRELEASE • Allows other programs to use a resource to which a resource number is assigned. ZRELEASE [<resource number>] Syntax resource number • • • • Specify the number (0 to 31) allocated among the programmers and assigned to a resource used in a program.
  • Page 631 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q Available only in execution mode ZRESERVE Instruction Z RESERVE • Prohibits other programs from using a resource to which a resource number is assigned. ZRESERVE <resource number>[,<timeout value>] Syntax resource number • • • • Specify the number (0 to 31) allocated among the programmers and assigned to a resource used in a program.
  • Page 632 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q If the specification of <timeout value> is omitted or "0:0:0:0" is specified in <timeout value>, the program waits for an infinite time. • It is possible to prohibit the use of multiple resources at any one time by specifying multiple resource numbers in one program.
  • Page 633 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q ZSEND Instruction Z SEND • Sends data from a communication port. ZSEND #<channel number>,0,<control table>,<output element> Syntax channel number • • • • Specify the communication port that is used to send the data. control table •...
  • Page 634 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q Always define an array used in <control table> by the DIM instruction, even though only three array elements are used. If the array is not defined using the DIM instruction, an error occurs at the execution of the ZRECEIVE instruction (usually, an array with 10 or fewer elements can be used without defining it using the DIM instruction).
  • Page 635 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q (3) When a character array expression is specified, one character in the variable is treated as 1 byte and data characters for the number of bytes requested to be sent are transmitted. Note, however, that if full-byte characters (Kanji) are included, each full-byte character is treated as 2 characters.
  • Page 636 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q Program Example (Executed in BASIC on the AD51H) 10 ' This program sends data to the LM7000 (AD51H is the transmission side) 20 ON ERROR GOTO 330 ' Branches to line 330 if an error occurs 30 ' 40 '***** RS-232C CH.OPEN ***** 50 DIM T%(10)
  • Page 637 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q (Executed in BASIC on the LM7000) 10 ' This program sends data from a console (LM7000 is the reception side) 20 ON ERROR GOTO 390 'Branches to line 360 if an error occurs 30 ' 40 '***** RS-232C CH.OPEN ***** 50 DIM T%(8) ' Defines an array...
  • Page 638 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q REMARK See the ZOPEN, ZRECEIVE and ZCNTL instructions, and Section 7.3.4. 11 - 468 11 - 468...
  • Page 639 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q Available only in execution mode ZSIGNAL Instruction Z SIGNAL • Generates the specified event from within a program. ZSIGNAL <event number> Syntax event number • • • • Specify the event to be generated using the event number from 0 to 63 defined by the DEF ZEVENT instruction.
  • Page 640 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q Available only in execution mode ZSTART Instruction Z START • Starts up the specified program. ZSTART <number> Syntax ZSTART <number>,"[<drive number>:][<system name>\]<file name>" number • • • • Specify the number of the task area where the program is started up.
  • Page 641 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q When reading a program from a memory card, FD or HD, and starting it • If "<drive number>:<system name>\<file name>" is specified after <number>, then the program is read into the task area specified by <number> from the specified memory card, FD, or HD, and started up.
  • Page 642 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q Available only in execution mode ZURGENCY Instruction Z URGENCY • Changes the priority of a program. ZURGENCY <priority> Syntax priority • • • • Specify an execution priority order from 0 to 10 when operating programs in multitask operations. The smaller the number is, the higher the priority is.
  • Page 643 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q Available only in execution mode ZWAIT DELAY Instruction Z WAIT DELAY • Pauses the program execution until the specified time has elapsed. ZWAIT DELAY <time> Syntax time • • • • Specify the time in which the execution is to be paused in the format "HH:MM:SS:R."...
  • Page 644 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q Available only in execution mode ZWAIT EVENT Instruction Z WAIT EVENT • Pauses the program execution until the specified event is generated. ZWAIT EVENT <event number>[,<timeout value>] Syntax event number • • • • Specify the event number of the event whose generation is to be waited for.
  • Page 645 11 INSTRUCTIONS AND FUNCTIONS MELSEC-Q REMARK See the ZEVENT, ZSIGNAL, and DEF ZEVENT instructions. 11 - 475 11 - 475...
  • Page 646 Specify a memory card interface, FD or HD used for saving or reading a program or data for a drive number. A unique number is assigned to each memory card interface, FDD, and HDD; specify these numbers as the drive number. D51H MEMORY CARD A6MEM-512KA-W MITSUBISHI MEMORY CARD 1 Drive Drive A Drive MEMORY CARD...
  • Page 647 APPENDIX MELSEC-Q Appendix 1.2 System Name A system name is used to group and organize programs or data in a memory card, FD or HD. Any name can be used for a system name as long as it conforms to the following conventions.
  • Page 648 APPENDIX MELSEC-Q Appendix 1.3 File Name A file name is a name given to individual programs or data files in a memory card, FD, or HD. A file name is further divided into a file name and an extension. Any name can be used as long as it conforms to the following conventions.
  • Page 649 APPENDIX MELSEC-Q Appendix 1.4 Wild Cards Use wild cards in order to select multiple files at the same time when displaying or deleting file names in a memory card, FD, or HD. Wild cards are only valid for file names. A wild card indicates that any character is acceptable at the place it is specified.
  • Page 650 APPENDIX MELSEC-Q Appendix 1.5 Precautions when Using Wild Cards It would appear that the wild cards can be used in any way but the following restrictions do apply. 1) Wild cards can only be used in the following instructions. FILES, LFILES, KILL 2) A question mark (?) represents one en character.
  • Page 651 APPENDIX MELSEC-Q Appendix 2 Precautions on Interrupt Processing It is possible to activate an interrupt processing routine by the following causes in AD51H-BASIC. 1) Starting up a subroutine due to an interrupt from one of the communication devices connected to the various interfaces of the communication module (ON COM GOSUB instruction) 2) Executing an error handling routine when an error occurs (ON ERROR GOTO instruction)
  • Page 652 APPENDIX MELSEC-Q Appendix 3 Instructions and Functions that Switch Between Programs to be Executed in Multitasking The following table lists instructions and functions that switch between the programs to be executed in multitask processing. Instruction Instruction Instruction Instruction Built-in function AUTO PRINT# KILL...
  • Page 653 APPENDIX MELSEC-Q Appendix 4 Code Table Appendix 4.1 Character Code Table Code for the higher 4 bits (hexadecimal) " & < > • The characters shown in a shaded box vary according to the terminal used; see the manual for the console. •...
  • Page 654 APPENDIX MELSEC-Q Appendix 4.2 List of Control Keys Key input Action Completes the entry for one line. Enter (return) Moves the cursor in the direction the arrow is pointing. Moves all characters to the right of the character at the cursor position to the right by Insert one character.
  • Page 655 APPENDIX MELSEC-Q Appendix 4.3 Control Codes for Screen Display when Using the General-Purpose Console List of control codes for display Code used (ASCII) Function Description BASIC instruction When the VG-620 is set When the VT-382 is set Line feed New line operation CR, LF code CR, LF code —...
  • Page 656 APPENDIX MELSEC-Q Appendix 4.4 List of Error Messages and Error Codes The illustration below shows what happens if an error occurs while an AD51H-BASIC instruction is being executed. During online programming/ During online programming edit mode • • • An error is displayed on the console screen.
  • Page 657 APPENDIX MELSEC-Q Appendix 4.4.1 Error message list The following table lists error messages. If the following messages are displayed, refer to Appendix 4.4.2. System error (nnnn) in xxxx See Appendix 4.4.2 The error codes in the “code” column are passed to the ERR function or displayed in the LED indicator.
  • Page 658 APPENDIX MELSEC-Q Code Error message Meaning Corrective action (hexadecimal) Disk I/O Error 57 (39 • The file area of the specified • Cancel the write protection for memory card is write protected. the memory card. • There is no file area in the specified •...
  • Page 659 APPENDIX MELSEC-Q Code Error message Meaning Corrective action (hexadecimal) Missing operand 22 (16 A parameter required in the Specify the necessary parameter. statement is not specified. Next without FOR 1 (1 There must be a FOR instruction for Modify the program so that FOR each NEXT instruction (there are too and NEXT match correctly.
  • Page 660 APPENDIX MELSEC-Q Code Error message Meaning Corrective action (hexadecimal) Sequential I/O Only 70 (46 Only a sequential input/output can be Perform only sequential executed. input/output when accessing the sequential file. String formula too 16 (10 Character expression is too complex. Reduce the complexity of the complex character expression.
  • Page 661 APPENDIX MELSEC-Q Appendix 4.4.2 System error code table An error code at a system error occurrence is expressed as a 4-digit hexadecimal number. The code is read as follows: System error Indicates the Indicates the task number error code. where an error occurred. The error code given by the ERR function is a decimal number.
  • Page 662 APPENDIX MELSEC-Q Numbers in the 800 range • • •General errors Error code Meaning Corrective action The ON COM GOSUB instruction is registered Use only one ON COM GOSUB instruction. twice. Specified date and time are incorrect. Set the correct time, date, and week. There is no clock function in the CPU.
  • Page 663 APPENDIX MELSEC-Q Numbers in the 900 range • • • Errors related to file processing Error code Meaning Corrective action The specified file cannot be found. Specify the correct file name. The specified system name cannot be found. Specify the correct system name. An illegal operation is performed on a memory Cancel the write protection.
  • Page 664 APPENDIX MELSEC-Q Numbers in the A00 range • • • Errors related to communication processing Error code Meaning Corrective action , A2B Error in communication with the console Reset the communication module. , A62 Memory card verification error Check the memory card size, etc. Cannot be used with the specified interface.
  • Page 665 APPENDIX MELSEC-Q Numbers in the B00 range • • • Errors related to communication with the PLC CPU Error code Meaning Corrective action A station with the specified PC number does not Check the specified station. exist. Communication error between the Check the communication module or CPU.
  • Page 666 APPENDIX MELSEC-Q Numbers in the F00 range • • •Warning errors Error code Meaning Corrective action INIE error Reset the module. Or, replace the hardware. MISE error Memory card 1 battery low Replace the battery with the memory card connected while the power to the AD51H-S3 is on.
  • Page 667 APPENDIX MELSEC-Q Numbers in the 7000 range • • • Detailed errors generated by the intelligent communication module Error code Meaning Corrective action [Processing code error] • Revise the processing code. 7008 • The corresponding processing code cannot be used. •...
  • Page 668 APPENDIX MELSEC-Q Appendix 5 How to Obtain Trigonometric Functions not Available in AD51H-BASIC A trigonometric function not available in AD51H-BASIC can be derived by combining existing trigonometric functions. The table below shows formulas for the derived trigonometric functions. Derived function Expression Arc sine ARCSIN(X)=ATN(X/SQR(–X X+1))
  • Page 669 APPENDIX MELSEC-Q Appendix 6 Reserved Words The following reserved words have special meanings so they must not be used in variable names and others. DATA DEFBYT INIT DEFDBL INIT% DEFINT INKEY$ DEFSNG AUTO DEFSTR INPUT DEF ZEVENT INPUT# BEEP DELETE INPUT$ BIN$ INPUT%...
  • Page 670 APPENDIX MELSEC-Q NAME SAVE ZCLOSE SEARCH ZIDV NEXT ZLDV ZODV SPACE$ ZOPEN OCT$ ZEVENT SPU$ ZMESSAGE ZMESSAGE CLOSE OPEN STEP ZMESSAGE STOP ZMESSAGE KILL STRING$ ZMESSAGE OPEN STR$ ZMESSAGE SWAP ZRELEASE PEEK SYSTEM ZRESERVE PEEK2 ZSIGNAL POKE ZSTART POKE2 ZURGENCY PORT ZWAIT DELAY ZWAIT EVENT...
  • Page 671 APPENDIX MELSEC-Q Appendix 7 Details of Communication Control Appendix 7.1 DC1/DC3 Control The following diagram shows the data flow when the DC1/DC3 control is enabled in the communication channel. Appendix 7.1.1 DC1/DC3 transmission control enabled When the DC1/DC3 control is enabled, DC1/DC3 control signals are sent to an external device based on the size of the free area in the receive buffer specified by the user, allowing the data transmission from the external device to the communication module to be controlled and requested.
  • Page 672 APPENDIX MELSEC-Q Appendix 7.1.2 DC1/DC3 reception control enabled Transmission of data from a BASIC program is controlled by DC1/DC3 control signals received from an external device. If a DC1 control signal is received, data transmission starts or continues. If a DC3 control signal is received, data transmission is stopped. When a data transmission is stopped due to the reception of the DC3 control signal, the remaining data will be sent when a DC1 control signal is received again later.
  • Page 673 APPENDIX MELSEC-Q Appendix 7.2 Control by Signals The following diagram shows the data flow when control by signals is enabled in the communication channel. Appendix 7.2.1 ER (DTR) control enabled When the ER (DTR) control is enabled, ER (DTR) control signals of the RS-232C interface are turned ON/OFF based on the size of the free area in the receive buffer specified by the user, allowing the data transmission from the external device to the communication module to be controlled and requested.
  • Page 674 APPENDIX MELSEC-Q 1 When the communication module is started up, the ER (DTR) control signal is turned OFF. The ER (DTR) control signal turns ON when the communication channel is opened. After that, the ER (DTR) control signal turns ON and OFF when data is received depending on the size of the free area in the receive buffer.
  • Page 675 APPENDIX MELSEC-Q Appendix 7.2.2 RS (RTS) control enabled When the RS (RTS) control is enabled, RS (RTS) control signals of the target interface are turned ON/OFF based on the size of the free area in the receive buffer specified by the user, allowing the data transmission from the external device to the communication module to be controlled and requested.
  • Page 676 APPENDIX MELSEC-Q 1 When the communication module is started up, the RS (RTS) control signal is turned OFF. The RS (RTS) control signal turns ON when the communication channel is opened. After that, the RS (RTS) control signal turns ON and OFF when data is received depending on the size of the free area in the receive buffer.
  • Page 677 APPENDIX MELSEC-Q Appendix 7.2.3 DR (DSR) control enabled The data transmission from the BASIC program is controlled depending on whether the DR (DSR) control signal is ON or OFF at the RS-232C interface on the communication side. When the DR (DSR) control signal is ON, the data transmission starts or continues. When the DR (DSR) control signal turns OFF, the data transmission stops.
  • Page 678 APPENDIX MELSEC-Q Appendix 7.2.4 CS (CTS) control enabled The data transmission from the BASIC program is controlled depending on whether the CS (CTS) control signal is ON or OFF at the target interface on the communication side. When the CS (CTS) control signal is ON, the data transmission starts or continues. When the CS (CTS) control signal turns OFF, the data transmission stops.
  • Page 679 APPENDIX MELSEC-Q Appendix 7.2.5 How to connect the communication module to an external device and precautions on specifying control by signals In the following, some precautions on specifying the control by signals using an interface connection between the communication module and an external device are given using the RS-232C interface as an example.
  • Page 680 APPENDIX MELSEC-Q (3) When the RS (RTS) and CS (CTS) control signal lines as well as the ER (DTR) and DR (DSR) control signal lines are looped back on the communication module side RS-232C Communication External device module Connector Connector (Signal name) RD(RXD) SD(TXD)
  • Page 681 APPENDIX MELSEC-Q Appendix 7.3 Break Control If a BASIC program in the communication module receives data from an external device, only data up to the break character specified by the control interface is stored in the variable. If the break character is not detected within the number of characters requested at a receive request, reception data for the number of requested characters is stored in the variable.
  • Page 682 APPENDIX MELSEC-Q Appendix 7.3.2 Flow of received data when a break character is specified The examples in the following figures illustrate the flow of received data when 0 is specified in the receive buffer specification (no receive buffer) and when 1 to 1024 is specified (receive buffer available) when the communication channel is opened.
  • Page 683 APPENDIX MELSEC-Q Appendix 7.4 Data Flow When an Error Occurs During Data Reception Appendix 7.4.1 Data flow when a transmission error occurs The examples in the following figures illustrate the flow of data when a transmission error (frame error, parity error, overrun error) occurs while receiving data from an external device.
  • Page 684 APPENDIX MELSEC-Q (2) When a receive buffer is available 1) When data for the number of characters requested to be received is not stored in the receive buffer The reception data stored in the receive buffer up to the time the transmission error occurred is returned to the BASIC program.
  • Page 685 APPENDIX MELSEC-Q 2) When data greater than the number of characters requested to be received is stored in the receive buffer Data received after the transmission error is not stored in the receive buffer. (Ignored) Reception data stored in the reception buffer for the amount of characters requested to be received from the BASIC program, is returned to the BASIC program.
  • Page 686 APPENDIX MELSEC-Q Appendix 7.4.2 Data flow when a receive buffer full error occurs The following diagram illustrates the flow of data when 1 to 1024 is specified (receive buffer available) in the receive buffer specification when the communication channel is opened and a receive buffer full error occurs due to the data received from an external device.
  • Page 687 APPENDIX MELSEC-Q Appendix 7.5 How to Clear Reception Data Stored in the Receive Buffer If 1 or greater is specified in the receive buffer specification when the communication channel is opened, the data received from the external device is stored in the receive buffer of the specified size.
  • Page 688 CODE SH(NA)-080090-B(0009)MEE HEAD OFFICE : MITSUBISHI DENKI BLDG MARUNOUCHI TOKYO 100-8310 TELEX : J24532 CABLE MELCO TOKYO NAGOYA WORKS : 1-14 , YADA-MINAMI 5 , HIGASHI-KU, NAGOYA , JAPAN When exported from Japan, this manual does not require application to the Ministry of International Trade and Industry for service transaction permission.

This manual is also suitable for:

Ad51h-s3Qd51-r24A1sd51s

Table of Contents