Preview only show first 10 pages with watermark. For full document please download

Programming Manual Ad51h-basic (command)

   EMBED


Share

Transcript

AD51H-BASIC P Programming Manual(Command) AD51H-BASIC Programming Manual (Command) AD51H-BASIC Programming Manual(Command) MODEL BASIC-P-COM2-E MODEL CODE 13JF63 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. Specifications subject to change without notice. Mitsubishi Programmable Logic Controller QD51 QD51-R24 A1SD51S AD51H-S3 • 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. For the safety instructions of the programmable controller system, please read the CPU module user's manual. In this manual, the safety instructions are ranked as "DANGER" and "CAUTION". DANGER Indicates that incorrect handling may cause hazardous conditions, resulting in death or severe injury. ! CAUTION Indicates that incorrect handling may cause hazardous conditions, resulting in medium or slight personal injury or physical damage. ! Note that the ! CAUTION level may lead to a serious consequence according to the circumstances. Always follow the instructions of both levels because they are important to personal safety. Please save this manual to make it accessible when required and always forward it to the end user. [Design Precautions] ! DANGER • Make sure to configure the interlock line outside the PLC system so that the system always operates normally when changing the data and control status of the PLC being operated from a peripheral device. Moreover, determine in advance how the system handles with communication errors by poor cable connection, etc. that may occur when performing online operations on the PLC CPU from a peripheral device. ! CAUTION • Please read this manual thoroughly and confirm the safety before starting online operations (especially forced outputs and operating status modifications) performed by connecting a peripheral device to the operating CPU module. Incorrect online operations may cause damage to the machinery or result in accidents. A-1 A-1 REVISIONS * The manual number is given on the bottom left of the back cover. Print Date Apr., 2000 Sep., 2000 * Manual Number SH(NA)-080090-A First printing SH(NA)-080090-B Additions Revision PCRD instruction processing code 516, PCWT instruction processing code 516 Oct., 2003 SH(NA)-080090-C Additions Regarding compiler BASIC, Chapter 5, Chapter 11 (ON COM GOSUB instruction, PCWT instruction, ZCNTL instruction, ZMESSAGE GET instruction), Appendix 4.4.2 Correction WARRANTY Oct., 2006 SH(NA)-080090-D Additions About difference between modules, Appendix 8 Correction How to use this manual, Regarding Compiler BASIC, Chapter 1, Section 2.1, 2.5, Chapter 3, Section 3.3.2, 3.11, 3.13.1, 3.13.2, Section 4.2.2, Section 6.2, Section 7.1, 7.2.1, 7.3.1 to 7.3.4, Section 8.1, Chapter 11, Appendix 1.2, 1.3, 4.1, 4.4, 4.4.2 Deletion Section 3.13.3 Japanese Manual Version SH-080094-D 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. © 2000 MITSUBISHI ELECTRIC CORPORATION A-2 A-2 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 About differences between modules .............................................................................................................A-14 1 OVERVIEW 1- 1 to 1- 3 1.1 Features .................................................................................................................................................. 1- 2 1.2 Symbols Used in This Manual................................................................................................................ 1- 3 2 THE BASICS OF AD51H-BASIC 2- 1 to 2- 24 2.1 Preparation to Use AD51H-BASIC......................................................................................................... 2- 1 2.2 Direct Mode and Program Mode ............................................................................................................ 2- 4 2.3 Line Format ............................................................................................................................................. 2- 4 2.4 Spaces and Keywords ............................................................................................................................ 2- 5 2.5 Characters Used in BASIC ..................................................................................................................... 2- 6 2.6 What are Instructions and Functions?.................................................................................................... 2- 9 2.7 Constants ................................................................................................................................................ 2-10 2.7.1 Character string constants ............................................................................................................... 2-10 2.7.2 Numeric constants............................................................................................................................ 2-10 2.7.3 Single-precision and double-precision numeric constants ............................................................. 2-11 2.8 Variables.................................................................................................................................................. 2-12 2.8.1 Variable names and type declaration characters............................................................................ 2-12 2.8.2 Array variables.................................................................................................................................. 2-13 2.8.3 Special variables (How to use B@ and W@) ................................................................................. 2-14 2.9 Type Conversion ..................................................................................................................................... 2-17 2.10 Expressions and Operators .................................................................................................................. 2-18 2.10.1 Arithmetic operators ....................................................................................................................... 2-18 2.10.2 Relational operators ....................................................................................................................... 2-20 2.10.3 Logical operators............................................................................................................................ 2-21 2.11 Character String Operations................................................................................................................. 2-23 2.12 Priority Order of Operations.................................................................................................................. 2-24 A-3 A-3 3 LET'S CREATE AND EXECUTE A PROGRAM 3- 1 to 3- 46 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 ............................................................................................................................. 3- 6 3.3 Saving and Loading a Program.............................................................................................................. 3-10 3.3.1 Memory cards used for AD51H-BASIC (AD51H-S3 only).............................................................. 3-10 3.3.2 Saving a program ............................................................................................................................. 3-11 3.3.3 Loading programs ............................................................................................................................ 3-15 3.4 Organizing Memory Cards and FDs....................................................................................................... 3-16 3.4.1 Displaying file names ....................................................................................................................... 3-16 3.4.2 Renaming files.................................................................................................................................. 3-18 3.4.3 Deleting files ..................................................................................................................................... 3-19 3.5 Specifying Data ....................................................................................................................................... 3-20 3.5.1 Assignment statements.................................................................................................................... 3-20 3.5.2 Preparing groups of data ................................................................................................................. 3-21 3.6 Jumps and Loops.................................................................................................................................... 3-23 3.6.1 Jump unconditionally........................................................................................................................ 3-23 3.6.2 Jump depending on a value............................................................................................................. 3-23 3.6.3 Loop for the number of times specified ........................................................................................... 3-24 3.6.4 Loop while a certain condition is met............................................................................................... 3-25 3.7 Letting BASIC Make Decisions .............................................................................................................. 3-26 3.7.1 Condition specification ..................................................................................................................... 3-26 3.7.2 Judgment instructions ...................................................................................................................... 3-27 3.8 How to Use Arrays .................................................................................................................................. 3-29 3.8.1 Number of dimensions in an array................................................................................................... 3-30 3.9 Using Subroutines................................................................................................................................... 3-31 3.10 Displaying Characters on the Screen................................................................................................... 3-32 3.10.1 Functions for displaying characters ............................................................................................... 3-33 3.10.2 Displaying characters to an arbitrary position ............................................................................... 3-35 3.11 Entering Data Using the Keyboard....................................................................................................... 3-37 3.12 Printing to the Printer ............................................................................................................................ 3-39 3.13 Character Processing ........................................................................................................................... 3-40 3.13.1 Types of characters........................................................................................................................ 3-40 3.13.2 Half-byte character unit processing ............................................................................................... 3-40 3.14 About Types of Numeric Relationships................................................................................................ 3-43 3.15 Executing a Large Program by Dividing it up....................................................................................... 3-44 A-4 A-4 4 THE EXCHANGE BETWEEN THE PLC AND BUFFER MEMORY 4- 1 to 4- 25 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 ......................................................................................................................... 4- 3 4.2.3 Choosing a process ......................................................................................................................... 4-16 4.2.4 Bit/Word designation ........................................................................................................................ 4-16 4.2.5 Device number designation ............................................................................................................. 4-17 4.2.6 Storage area for reading and writing data....................................................................................... 4-19 4.3 Communication with the Buffer Memory ................................................................................................ 4-24 5 COMMUNICATION USING GENERAL-PURPOSE INPUT/OUTPUT 5- 1 to 5- 7 5.1 Communications Module PLC CPU (About Input Device X) ........................................................... 5- 1 5.2 PLC CPU Communications Module (About Output Device Y)......................................................... 5- 4 6 I/O PROCESSING OF DATA FILES 6- 1 to 6- 13 6.1 File Numbers ........................................................................................................................................... 6- 2 6.2 Sequential File I/O Procedures............................................................................................................... 6- 3 6.3 Random File I/O Procedures .................................................................................................................. 6- 7 6.4 Caution on Handling Data Files.............................................................................................................. 6-12 6.4.1 Handling data files during multitask processing.............................................................................. 6-12 6.4.2 Number of data files that can be handled by each program........................................................... 6-13 7 COMMUNICATION WITH EXTERNAL DEVICES 7- 1 to 7- 13 7.1 Correspondence between the Interface and Channel Number............................................................. 7- 1 7.2 Preparation for the Communication........................................................................................................ 7- 2 7.2.1 Communication parameter setting................................................................................................... 7- 2 7.2.2 Control table ..................................................................................................................................... 7- 4 7.3 Communication Procedure with External Devices................................................................................. 7- 5 7.3.1 Communication with a console........................................................................................................ 7- 5 7.3.2 Communication with a terminal........................................................................................................ 7- 7 7.3.3 Communicating with a printer .......................................................................................................... 7- 9 7.3.4 Communication with other external devices.................................................................................... 7-11 7.4 Interrupt Processing from External Devices........................................................................................... 7-13 8 MULTITASK PROCESSING 8- 1 to 8- 19 8.1 Multitask Processing ............................................................................................................................... 8- 1 8.2 How to Synchronize the Execution (Event Control)............................................................................... 8- 5 8.3 To Use Devices (Resources) in Multitasking (Mutual Exclusive Control of Resources) ...................... 8- 8 8.4 Start Another Program from within a Program....................................................................................... 8-13 8.5 Exchanging Data between Tasks........................................................................................................... 8-14 8.5.1 Common memory and internal devices........................................................................................... 8-14 8.5.2 Message ports.................................................................................................................................. 8-16 A-5 A-5 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................................. 10- 1 10.2 Instructions Used when Debugging Programs .................................................................................. 10- 1 11 INSTRUCTIONS AND FUNCTIONS 11- 1 to 11-454 ABS (Returns the absolute value) ............................................................................................................... 11- 2 ASC (Returns the character code of the starting character) ...................................................................... 11- 3 ATN (Returns arc tangent)........................................................................................................................... 11- 4 AUTO (Automatically displays the line number) ......................................................................................... 11- 5 B@ (Reads and writes bit information)........................................................................................................ 11- 6 BEEP (The buzzer sounds) ......................................................................................................................... 11- 7 BIN$ (Returns a character string of the binary expression of an integer) .................................................. 11- 8 BSWAP (Swaps two values in byte units)................................................................................................... 11-10 CDBI (Converts a double precision real number to a 32-bit integer) ......................................................... 11-13 CDBL (Converts an integer or a single precision real number to a double precision real number).......... 11-15 CHAIN (Reads program or combine to execute) ........................................................................................ 11-17 CHR$ (Returns a character of the specified character code)..................................................................... 11-19 CIDB (Converts a 32-bit integer into a double precision real number) ...................................................... 11-20 CINT (Converts a single precision real number or a double precision real number into an integer) ........ 11-22 CISN (Converts a 32-bit integer into a single precision real number)........................................................ 11-24 CLEAR (Initializes all variables and sets up the memory area) ................................................................. 11-26 CLOSE (Terminates the I/O processing of a file)........................................................................................ 11-27 CLS (Clears the screen) .............................................................................................................................. 11-28 COM ON/OFF/STOP (Controls to enable, prohibit, and stop the interrupt from the communication line) ............................................................................................................... 11-29 COMMON (Sets variable and others to be passed to the program to be read) ........................................ 11-30 CONSOLE (Sets the number of display lines of the console screen) ........................................................ 11-31 CONT (Resumes the program that was stopped) ...................................................................................... 11-32 COS (Returns a cosine value) ..................................................................................................................... 11-33 CSNG (Converts an integer or a double precision real number into a single precision real number) ...... 11-34 CSNI (Converts a single precision real number into a 32-bit integer) ........................................................ 11-35 CVD (Converts a character string, which was converted by the MKD$ function, back to a double precision real number) ............................................................................................ 11-37 CVDMBF (Converts into the IEEE format double precision internal expression) ...................................... 11-38 CVI (Converts a character string, which was converted by the MKI$ function, back to an integer) ......... 11-39 CVS (Converts a character string, which was converted by the MKS$ function, back to a single precision real number) .............................................................................................. 11-40 A-6 A-6 CVSMBF (Converts into the internal expression of a floating point real number that is used by A2A and A3A) ......................................................................................................................... 11-41 ( DATA Specifies data to be read by READ) ............................................................................................... 11-43 DATE$ (Sets year, month, and day to the PLC CPU, and reads) ............................................................. 11-45 DEFDBL (Defines variables that start with a character of the specified range as the double precision real number type).................................................................................................... 11-47 ( DEFFN Defines a user function) ................................................................................................................ 11-48 DEFINT (Defines variables that start with a character of the specified range as the integer type) .......... 11-50 DEFSNG (Defines variables that start with a character of the specified range as the single precision real number type).................................................................................................... 11-51 ( DEFSTR Defines variables that start with a character of the specified range as the character type) ..... 11-52 DEF ZEVENT (Defines an event, and defines an event by bit device) ...................................................... 11-53 DELETE (Deletes the specified range of the program) .............................................................................. 11-56 DIM (Defines the array) ................................................................................................................................ 11-57 END (Terminates the execution of the program and brings to the input wait state or the idling state) ..... 11-59 EOF (End of a sequential file is detected) ................................................................................................... 11-60 ERASE (Deletes the array from memory) ................................................................................................... 11-61 ERL (Returns the line number where an error was detected) .................................................................... 11-62 ERR (Returns the error code of the detected error) ................................................................................... 11-63 ERROR (Generates the error of the specified error code) ......................................................................... 11-64 EXP (Returns the exponential function value) ............................................................................................ 11-65 FIELD (Assigns the area for the specified variable to the random file buffer) ........................................... 11-66 FILES (Displays the file name) .................................................................................................................... 11-67 FIX (Returns only the integer part after truncating the fractional part of the numeric value)..................... 11-68 FOR to NEXT (Executes a series of instructions for the specified number of times) ................................ 11-69 FORMAT (Initializes the file area of a memory card).................................................................................. 11-71 FRE (Returns the size of the unused area of memory in bytes) ................................................................ 11-73 GET (Reads one record from a random file to the random file buffer)....................................................... 11-74 GETMEM (Reads data from the buffer memory, common memory, and internal device ED) .................. 11-75 GOSUB RETURN (Branches to a subroutine) ........................................................................................... 11-79 GOTO (Branches to specified line).............................................................................................................. 11-81 HEX$ (Converts a decimal number to a hexadecimal character string) .................................................... 11-82 IF GOTO ELSE (Selects a branch destination according to the result of an expression) ......................... 11-83 IF THEN ELSE (Selects an instruction according to the result of the expression) .................................... 11-85 INKEY$ (Returns the character input from the keyboard) .......................................................................... 11-87 INPUT (Data entry from the keyboard)........................................................................................................ 11-89 IPUT$ (Returns a character string of the specified length after reading from the keyboard, file and the communication port) ............................................................................................ 11-91 ( INPUT# Reads data from a sequential file) ............................................................................................... 11-94 INSTR (Returns a specified character string in the character string) ......................................................... 11-95 INT (Returns the integer value of the numeric expression) ........................................................................ 11-97 KEY (Defines a character string to a function key of the console) ............................................................. 11-99 KEYLIST (Displays the character string defined to the function key of the console) .............................. 11-100 KILL (Deletes a file) .................................................................................................................................... 11-101 A-7 A-7 LEFT$ (Extracts a character string of the number of characters specified from the left of the character string) ............................................................................................................. 11-103 ( LEN Returns the number of characters of a character string)................................................................. 11-105 LET (Assigns the value of the expression to a variable) .......................................................................... 11-106 LFILES (Prints the filenames to the printer) .............................................................................................. 11-108 LINE INPUT (Stores the key input into a character string variable) ......................................................... 11-109 LINE INPUT# (Reads character from a sequential file into a character string variable) ......................... 11-111 LIST (Displays the program) ...................................................................................................................... 11-112 LLIST (The program will be printed to the printer) .................................................................................... 11-113 LOAD (Reads programs) ........................................................................................................................... 11-114 LOC (Returns the current logical location within a file) ............................................................................. 11-115 LOCATE (Specifies the display position on the console screen) ............................................................. 11-116 LOF (Returns the size of a file in record units).......................................................................................... 11-118 LOG (Returns a natural logarithm value) .................................................................................................. 11-119 LPRINT (Outputs data to the printer)......................................................................................................... 11-120 LPRINT USING (Outputs data in the specified format to the printer) ...................................................... 11-121 LSET (Moves data from memory to the random file buffer and stores left-justified) ............................... 11-122 MERGE (Merges programs in the memory and a read program) ............................................................ 11-123 MID$ (Part 1) (Replaces a section of a character string with another character string) .......................... 11-125 MID$ (Part 2) (Returns the partial character expression that begins with the specified position in a character string) ............................................................................................................. 11-127 MKD$ (Converts a double-precision type numeric value into a character string).................................... 11-128 MKDMBF$ (Converts data of IEEE format internal expression to a character string that can be converted to a numeric value using the CVD function) .......................................... 11-130 ( MKI$ Converts an integer type numeric value into a character string) ................................................... 11-131 MKS$ (Converts a single-precision type numeric value into a character string) ..................................... 11-132 MKSMBF$ (Converts data of floating point real numbers used by the A2A and A3A into a character string that can be converted to a numeric value using the CVS function) ...... 11-133 ( NAME Changes file names) ..................................................................................................................... 11-135 NEW (Erases all programs in memory and initializes all variables) ......................................................... 11-137 OCT$ (Converts a numeric value into a character string variable in octal notation) ............................... 11-138 ON COM GOSUB (Branches to subroutine when an interrupt occurs from a communication line) ....... 11-140 ON ERROR GOTO (Branch to an error handling routine if an error occurs)........................................... 11-145 ON GOSUB (Branches to subroutine depending on the value of the specified expression) .................. 11-147 ON GOTO (Branches to specified line numbers depending on the value of the specified expression) ........................................................................................................................... 11-149 ( OPEN Opens a file and enables it for input/output processing) .............................................................. 11-151 A-8 A-8 PCRD .............................................................................................................................................. 11-153 PCRD - Processing Code 1 - (Reading device memory data) ................................................................. 11-155 PCRD - Processing Code 2 - (Reading device memory registered to be monitored by the PCWT instruction) ..........................................................................................................11-158 PCRD - Processing Code 4 - (Reading extension file register data) ....................................................... 11-162 PCRD - Processing Code 5 - (Reading extension file registers registered to be monitored by the PCWT instruction) ..........................................................................................................11-165 PCRD - Processing Code 7 - (Reading extension file register data by specifying sequential addresses) ............................................................................................................................ 11-168 PCRD - Processing Code 8 - (Loading a sequence program) ................................................................. 11-173 PCRD - Processing Code 9 - (Loading a microcomputer program)......................................................... 11-177 PCRD - Processing Code 10 - (Reading comment data)......................................................................... 11-182 PCRD - Processing Code 11 - (Reading extension comment data) ........................................................ 11-185 PCRD - Processing Code 12 - (Reading a special function module’s buffer memory) ........................... 11-188 PCRD - Processing Code 13 - (Reading the type name of the PLC CPU) ............................................. 11-196 PCRD - Processing Code 14 - (Reading parameter data) ....................................................................... 11-199 PCRD - Processing Code 21 - (Reading network information) ................................................................ 11-204 PCRD - Processing Code 22 - (Reading routing parameters) ................................................................. 11-206 PCRD - Processing Code 513 - (Reading the type name of the Q/QnA series PLC CPU) .................... 11-208 PCRD - Processing Code 515 - (Reading device memory of the Q/QnA series PLC CPU) .................. 11-212 PCRD - Processing Code 516 - (Random read of device memory of the Q/QnA series PLC) .............. 11-218 PCRD - Processing Code 533 - (Reading the buffer memory of the intelligent function module /special function module of the Q/QnA series PLC CPU) ................................................................ 11-229 PCWT .............................................................................................................................................. 11-239 PCRD - Processing Code 1 - (Writing to device memory) ....................................................................... 11-241 PCWT - Processing Code 2 - (Monitor registration of device memory) ................................................... 11-245 PCWT - Processing Code 3 - (Random writing to device memory)......................................................... 11-250 PCWT - Processing Code 4 - (Writing to extension file registers) ........................................................... 11-254 PCWT - Processing Code 5 - (Monitor registration of extension file registers) ....................................... 11-257 PCWT - Processing Code 6 - (Random writing to extension file registers) ............................................. 11-261 PCWT - Processing Code 7 - (Writing data to extension file registers by specifying sequential addresses) ............................................................................................................................ 11-264 PCWT - Processing Code 8 - (Writing a sequence program) .................................................................. 11-269 PCWT - Processing Code 9 - (Writing a microcomputer program).......................................................... 11-275 PCWT - Processing Code 10 - (Writing comment data)........................................................................... 11-280 PCWT - Processing Code 11 - (Writing extension comment data).......................................................... 11-283 PCWT - Processing Code 12 - (Writing to the special function module's buffer memory)...................... 11-286 PCWT - Processing Code 14 - (Writing parameter data) ......................................................................... 11-293 PCWT - Processing Code 15 - (Analyzing parameter data)..................................................................... 11-297 PCWT - Processing Code 16 - (Remote STOP of the PLC CPU) ........................................................... 11-299 PCWT - Processing Code 17 - (Remote RUN of the PLC CPU) ............................................................. 11-301 PCWT - Processing Code 20 - (Interrupting the PLC CPU)..................................................................... 11-303 PCWT - Processing Code 515 - (Writing data to the device memory of a Q/QnA series PLC CPU)..... 11-305 PCWT - Processing Code 516 - (Random data writing to the device memory of a Q/QnA series PLC CPU) ............................................................................................................................. 11-310 A-9 A-9 PCWT - Processing Code 533 - (Writing data to the buffer memory of the intelligent function module special function module of the Q/QnA series PLC CPU)....................................... 11-318 ( PRINT Displays data on the screen) ........................................................................................................ 11-327 PRINT USING (Displays a character string or numeric value in the specified format) ........................... 11-328 PRINT# (Writes data to a sequential file) .................................................................................................. 11-332 PRINT# USING (Writes data to a sequential file in the specified format) ................................................ 11-333 PUT (Writes one record from a random file buffer to a random file) ........................................................ 11-334 PUTMEM (Writes data to buffer memory, common memory, or internal device ED).............................. 11-335 RDSET (Reads one bit data from the specified bit) .................................................................................. 11-340 READ (Reads a value defined by the DATA instruction and assigns it to a variable) ............................. 11-342 REM (Provides comments) ........................................................................................................................ 11-343 RENUM (Reassigns line numbers of a program) ..................................................................................... 11-344 RESTORE (Specifies a data read with READ instruction) ....................................................................... 11-345 RESUME (Execution of the error handling routine is completed) ............................................................ 11-346 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) .......................................... 11-347 ( RND Generates random numbers) .......................................................................................................... 11-348 ROT (Returns the bit-rotated value of the integer value data) ................................................................. 11-349 RSET (Moves data from memory to a random file buffer and stores right-justified) ............................... 11-351 RUN (1) (Starts the execution of the program) ......................................................................................... 11-352 RUN (2) (Executes after loading a program) ............................................................................................ 11-353 SAVE (Saves a program) .......................................................................................................................... 11-354 SEARCH (Searches for the specified value among the elements of the selected array variable and returns the position of the element) ................................................................ 11-355 ( SGN Returns the sign of a value)............................................................................................................. 11-357 SHA (Returns the arithmetically shifted value of the integer data) ........................................................... 11-358 SHT (Returns the logically shifted value of the integer data) ................................................................... 11-360 SIN (Returns the sine)................................................................................................................................ 11-362 SPACE$ (Returns a null string of a specified length) ............................................................................... 11-363 SPC (Returns a specified number of blank spaces) ................................................................................. 11-364 SQR (Returns the square root of the specified value) .............................................................................. 11-365 STOP (Pauses the program execution or puts it in the stop status) ........................................................ 11-366 STR$ (Converts a value to a character string, assuming the value is given as a decimal number)....... 11-367 STRING$ (Returns the specified character for the specified number of times)....................................... 11-369 SYSTEM (Returns to system mode or the main menu screen) ............................................................... 11-371 SWAP (Swaps the values of two variables) .............................................................................................. 11-372 TAB (Moves the current character display position to the specified position) ......................................... 11-373 TAN (Returns the tangent) ......................................................................................................................... 11-374 TIME$ (Sets the time of the PLC CPU's clock and reads) ....................................................................... 11-375 TROFF (Resets the trace in a program) ................................................................................................... 11-377 TRON (Starts a trace in a program) .......................................................................................................... 11-378 VAL (Returns the value represented by a character string) ..................................................................... 11-379 W@ (Reads or writes word information) ................................................................................................... 11-381 WHILE WEND (These instructions are used repeatedly, while the specified condition holds)............... 11-383 WIDTH (Sets the width of data to be output to the printer)....................................................................... 11-385 WTSET (Writes 0 or 1 to the specified bit) ................................................................................................ 11-386 A - 10 A - 10 ZBAS (Returns the number of the BASIC task area in which the program currently being created) ..... 11-388 ZCLOSE (Closes a communication channel) ........................................................................................... 11-389 ZCNTL .............................................................................................................................................. 11-390 ZCNTL - Processing Code 16 - (Specifying communication parameter)................................................. 11-392 ZCNTL - Processing Code 17 - (Reading communication parameters) .................................................. 11-392 ZCNTL - Processing Code 18 - (Specifying communication control parameters)................................... 11-394 ZCNTL - Processing Code 19 - (Reading communication control parameters) ...................................... 11-394 ZCNTL - Processing Code 22 - (Specifying break characters) ................................................................ 11-397 ZCNTL - Processing Code 23 - (Reading break characters) ................................................................... 11-397 ZCNTL - Processing Code 24 - (Specifying continuous break characters) ............................................. 11-399 ZCNTL - Processing Code 25 - (Reading continuous break characters) ................................................ 11-399 ZCNTL - Processing Code 32 - (Turning ON/OFF the RS and ER control signals)................................ 11-401 ZCNTL - Processing Code 33 - (Reading the ON/OFF status of the CS, DR, RS, ER and CD control signals)...................................................................................................................... 11-403 ZCNTL - Processing Code 48 - (Specifying high impedance control) ..................................................... 11-405 ZCNTL - Processing Code 64 - (Reading causes of reception errors) .................................................... 11-406 ZCNTL - Processing Code 80 - (Reading the receive buffer size and the number of characters) ......... 11-408 ZCNTL - Processing Code 128 - (Reading the printer status) ................................................................. 11-409 ZCNTL - Processing Code 136 - (Outputting the initialization signal to the printer) ................................ 11-411 ZEVENT (Enables or disables event generation) ..................................................................................... 11-412 ZIDV (Specifies the data input device for the INPUT instruction, etc)..................................................... 11-413 ZLDV (Selects a communication port for a printer) ................................................................................... 11-414 ZMESSAGE (Defines a message port) ..................................................................................................... 11-415 ZMESSAGE CLOSE (Closes message ports).......................................................................................... 11-418 ZMESSAGE GET (Reads messages from message ports) ..................................................................... 11-419 ZMESSAGE KILL (Deletes the message ports) ....................................................................................... 11-421 ZMESSAGE OPEN (Opens a message port) ........................................................................................... 11-422 ZMESSAGE PUT (Writes messages to a message port) ........................................................................ 11-423 ZMOVE (Transfers data between valiables) ............................................................................................. 11-425 ZODV (Specifies the data output destination for the PRINT instruction, etc) .......................................... 11-430 ZOPEN (Opens a communication channel) .............................................................................................. 11-431 ZRECEIVE (Receives data from a communication channel) ................................................................... 11-433 ZRELEASE (Allows other programs to use a resource to which a resource number is assigned) ........ 11-439 ZRESERVE (Prohibits other programs from using a resource to which a resource number is assigned) .............................................................................................................................. 11-440 ZSEND (Sends data from a communication channel) .............................................................................. 11-442 ZSIGNAL (Generates the specified event)................................................................................................ 11-448 ZSTART (Starts up the specified program) ............................................................................................... 11-449 ZURGENCY (Changes the priority of a program)..................................................................................... 11-451 ZWAIT DELAY (Pauses the program execution until the specified time has elapsed) ........................... 11-452 ZWAIT EVENT (Pauses the program execution until the specified event is generated) ........................ 11-453 A - 11 A - 11 APPENDIX App- 1 to App-44 Appendix 1 Appendix Appendix Appendix Appendix Appendix Appendix Appendix 2 Appendix 3 File Name..............................................................................................................................App- 1 1.1 Drive Number.................................................................................................................App- 2 1.2 System Name ................................................................................................................App- 2 1.3 File Name.......................................................................................................................App- 3 1.4 Wild Cards......................................................................................................................App- 4 1.5 Precautions when Using Wild Cards.............................................................................App- 5 1.6 The Efficient Way to Assign a File Name .....................................................................App- 5 Precautions on Interrupt Processing....................................................................................App- 6 Instructions and Functions that Switch Between Programs to be Executed in Multitasking...........................................................................................................................App- 7 Appendix 4 Code Table ...........................................................................................................................App- 8 Appendix 4.1 Character Code Table ...................................................................................................App- 8 Appendix 4.2 List of Control Keys........................................................................................................App- 9 Appendix 4.3 Control Codes for Screen Display when Using the General-Purpose Console ..........App-10 Appendix 4.4 List of Error Messages and Error Codes.......................................................................App-11 Appendix 4.4.1 Error message list...................................................................................................App-12 Appendix 4.4.2 System error code table .........................................................................................App-16 Appendix 5 How to Obtain Trigonometric Functions not Available in AD51H-BASIC...........................App-23 Appendix 6 Reserved Words...................................................................................................................App-24 Appendix 7 Details of Communication Control .......................................................................................App-26 Appendix 7.1 DC1/DC3 Control...........................................................................................................App-26 Appendix 7.1.1 DC1/DC3 transmission control enabled.................................................................App-26 Appendix 7.1.2 DC1/DC3 reception control enabled ......................................................................App-27 Appendix 7.2 Control by Signals......................................................................................................App-28 Appendix 7.2.1 ER (DTR) control enabled ......................................................................................App-28 Appendix 7.2.2 RS (RTS) control enabled ......................................................................................App-30 Appendix 7.2.3 DR (DSR) control enabled......................................................................................App-32 Appendix 7.2.4 CS (CTS) control enabled ......................................................................................App-33 Appendix 7.2.5 How to connect the communication module to an external device and precautions on specifying control by signals.........................................................App-34 Appendix 7.3 Break Control .................................................................................................................App-36 Appendix 7.3.1 Break character specifying side .............................................................................App-36 Appendix 7.3.2 Flow of received data when a break character is specified...................................App-37 Appendix 7.4 Data Flow When an Error Occurs During Data Reception...........................................App-38 Appendix 7.4.1 Data flow when a transmission error occurs..........................................................App-38 Appendix 7.4.2 Data flow when a receive buffer full error occurs ..................................................App-41 Appendix 7.5 How to Clear Reception Data Stored in the Receive Buffer ........................................App-42 Appendix 7.6 Sending or Receiving Character Data of 256 Bytes or More .......................................App-42 Appendix 8 Starting Address of Each Intelligent Function Module/ Special Function Module..............App-43 A - 12 A - 12 How to use this manual • Please read Chapter 1 through Chapter 11 and the Appendix if the manual should be used with Interpreter BASIC. • Please read the AD51H-BASIC Programming Manual (Debug and Compile) and understand the restrictions of the compiler if the manual should be used with Compiler BASIC. Then proceed to read Chapter 1 through Chapter 11 and the Appendix. Regarding Compiler BASIC • Please be aware that there are many detailed restrictions for each instruction when using Compiler BASIC. See the AD51H-BASIC Programming Manual (Debug and Compile) for details on these restrictions. • An assembler and a linker is required to compile programs. These are not included in the SW1IVDAD51HP-E software package and must be purchased separately. Recommended Products • IBM/AT Compatible Personal Computer Turbo Assembler Ver 5.0 For Turbo Assembler, contact Borland Software Corporation. • MS-DOS is used for the Compiler BASIC. The user must have adequate knowledge about MS-DOS to use it. About Module Names The module model names are abbreviated as follows in this manual. AD51H-S3 A1SD51S QD51 QD51-R24 QD51 (-R24) Communication Module A - 13 ••••• ••••• ••••• ••••• ••••• ••••• Refers to operations only for the AD51H-S3. Refers to operations only for the A1SD51S. Refers to operations only for the QD51. Refers to operations only for the QD51-R24. Refers to common items for both the QD51 and the QD51-R24. Refers to common items for all modules. A - 13 About differences between modules Descriptions in this manual uses AD51H-S3, A1SD51S and QD51(-R24) as module examples. The differences are shown below since the settings differ for each module. QD51 QD51-R24 A1SD51S AD51H-S3 The number of tasks 2 2 2 8 General-purpose input/output Input Output : 23 points Output : 23 points Output : 23 points Output : 17 points The number of I/O points occupied 32 points 32 points 32 points 48 points : 26 points Input : 26 points Input : 27 points Input : 27 points (first 16 points as vacant, second 32 points as special) Interface CH1(RS-232) CH2(RS-232) CH3(RS-422/485) ― ― CH4(parallel) ― ― ― Memory card ― ― ― (Number of loadable cards: 2) Transmission rate 300, 600, 1200, 2400, 4800, 9600, 300, 600, 1200, 2400, 4800, 9600, 14400, 19200, 28800, 38400 bps 19200 bps Character length 7, 8 5, 6, 7, 8 Console setting Set in the "Switch setting for I/O and Set at the mode switch2 of the DIP intelligent function module" screen of switch on the communication module. Mode switching GX Developer. Set in the "Switch setting for I/O and intelligent function module" screen of GX Developer. Set at the mode switch1 of the rotary switch on the communication module. Execution time switching Unsupported Unsupported Unsupported Supported (Set at the mode switch3 of the DIP switch on the AD51H-S3 communication module.) Refer to the user’s manual for each communication module for details. A - 14 A - 14 1 OVERVIEW MELSEC-Q 1 OVERVIEW This programming manual describes how to use instructions and functions of the programming language "AD51H-BASIC" used with the communication module. Please refer to the following manuals as necessary when using AD51H-BASIC. • Intelligent communication module type AD51H-S3 User's Manual • Type A1SD51S Intelligent communication module User's Manual • Q Corresponding Intelligent Communication Module User's Manual • AD51H-BASIC Programming Manual (Debug and Compile) • AD51H-BASIC Package type SW1IVD-AD51HP-E Operating Manual 1-1 : : : : : (IB(NA) - 66401) (IB(NA) - 66551) (SH(NA) - 080089) (SH(NA) - 080091) (IB(NA) - 66698) 1-1 1 1 OVERVIEW MELSEC-Q 1.1 Features 1 The following are features of AD51H-BASIC. (1) Both interpreter-type BASIC and compiler-type BASIC languages can be employed. This allows easy creation of system control programs and programs that perform data linking with a computer without being aware of the complicated internal structure of the module; it is easy to use even for beginners. The execution speed can be made faster by compiling already created programs. (2) Multiple programs can be executed simultaneously by means of multitask processing. 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. (3) Data can be communicated between programs via message ports and communication module internal devices. When multiple programs are executed simultaneously using the multitask processing function, data can be communicated using the following means. 1) Message ports • • • • • • • • • • • • • • • • • • • • • • • 1 to n data communication 2) Communication module internal devices • • • • • 1 to n data communication 3) Shared memory • • • • • • • • • • • • • • • • • • • • • • • 1 to n data communication (4) Execution can be synchronized between programs via events. When multiple programs are executed simultaneously using the multitask processing function, it is possible to synchronize their executions. This is achieved by making programs wait for an event using the ZWAIT EVENT instruction and generating an event by the ZSIGNAL instruction. (5) Instructions for data link with external devices have been unified. Data link with the PLC CPU of the same station as the communication module or other PLC CPUs via MELSECNET can be performed using the PCRD/PCWT instructions. The data link between the various interfaces of the communication module and external devices is performed using the ZRECEIVE/ZSEND instructions. In this way, by creating a single subroutine that performs data link, it is possible to share the arguments of each instruction by passing them to variables in that subroutine. 1-2 1-2 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. Doing so will result in a syntax error. Other symbols and characters have special meanings. Use them according to their descriptions. [ ] (Square brackets) { } (brackets) < > | (vertical line) H Ctrl + Enter 1-3 : [ ] indicates that the arguments inside them are optional. : { } indicates that the arguments inside them are optional or can be repeated. : < > indicates that the single item inside should be entered (specified) by the user. : Indicates that one of the two or more items separated by pipe symbols must be chosen and entered. When the range of options is hard to see, it is underlined. : Indicates a place where at least one space must be entered, or a single space. : Indicates that the alphanumeric string immediately before it is an integer value expressed in hexadecimal format. : Indicates a key operation where the key is pressed while at the same time holding the control key pressed. : Indicates that the enter key should be pressed. 1-3 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 programming mode, then connect the console, and start up BASIC. The procedures and the relevant reference manuals are shown below. 2 (1) Setting the communication module and connecting the console. Perform settings and connections for each communication module. (2) Console preparation Carry out the online programming items according to the Type SW IVDAD51HP/SW NX-AD51HP Software Package Operation Manual. This is not necessary when using a general-purpose console. IBM/AT Compatible Personal Computer SW1IVD-AD51HP-E (3) Editing and running BASIC programs can be started by using the START instruction in the system mode of the communication module, according to the user’s manual for each communication module. E xe c u te the START instruction. 2-1 S>START , En te r 2-1 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 OK 2 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." This mode allows creation of a BASIC program and execution of a single-task program. (5) Execute the SYSTEM instruction or press the Ctrl + D keys to change the mode of the communication module back to system mode after finishing editing and execution with BASIC. Return to system mode. S> REMARK • In order to perform multitask operation of programs, it is necessary to perform multitask settings and specify the execution in system mode of the communication module. See the AD51H-BASIC Programming Manual (Debug and Compile) for details. 2-2 2-2 2 THE BASICS OF AD51H-BASIC MELSEC-Q Note There are two modes for executing BASIC programs in the communication module. • Programming mode (online programming mode) In this mode, BASIC programs can be executed online, and only the BASIC program being edited can be executed. It is not possible to perform multitask execution of BASIC programs while in programming mode. This manual describes examples of programming and execution in programming mode, with the exception of multitask instructions. • Run mode This mode allows multitask execution of BASIC programs that use multitask instructions. It is not possible to create or edit BASIC programs in run mode. Changing between programming mode and run mode of the communication module is performed by the methods shown below. • AD51H-S3, A1SD51S ••••• • QD51 (-R24) ••••• Use the rotary switch of the main module (Mode setting switch) "Switch setting for I/O and intelligent function module" screen of GX Developer See the user’s manual for each communication module for detailed descriptions of each mode and changing between them. 2-3 2-3 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. The results of the operation executed in direct mode will remain in memory, but the instruction line will be cleared. All BASIC instructions with the exception of DEF FN can be executed in direct mode. • Program mode Entering a BASIC instruction preceded by a line number and pressing Enter will store the instruction in the memory of the communication module. Lines are comprised of line numbers and BASIC instructions, and a group of more than one line is referred to as a BASIC program (or simply, a program). A program is comprised of statements that specify a series of operations that the computer performs. Designing and testing a program is referred to as programming. Programs stored in memory can be executed by entering the RUN instruction of BASIC. This execution is referred to as program mode execution, as opposed to direct mode execution. 2.3 Line Format Lines are the smallest components of a program and are comprised of one , a sentence, and a Return symbol that indicates the end of the line. A sentence is a collection of that make sense as an instruction. ( Return is entered by pressing the Enter key while editing the program.) The line format is as follows: Sentence [] {: } Return (1) Line Number are written from the 1st column of the line and are represented by whole numbers between 1 and 65529 (decimal constant). The line numbers are placed in ascending order within the program. Line numbers act as indices for controlling program execution, and at the same time, as line search indices when editing the program. 2-4 2-4 2 THE BASICS OF AD51H-BASIC MELSEC-Q (2) 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