GE Fanuc Automation Computer Numerical Control Products Series 30i-Model A Series 300i-Model A Series 300is-Model A C Language Executor Operator’s Manual GFZ-63944EN-3/01 January 2004 GFL-001 Warnings, Cautions, and Notes as Used in this Publication Warning Warning notices are used in this publication to emphasize that hazardous voltages, currents, temperatures, or other conditions that could cause personal injury exist in this equipment or may be associated with its use. In situations where inattention could cause either personal injury or damage to equipment, a Warning notice is used. Caution Caution notices are used where equipment might be damaged if care is not taken. Note Notes merely call attention to information that is especially significant to understanding and operating the equipment. This document is based on information available at the time of its publication. While efforts have been made to be accurate, the information contained herein does not purport to cover all details or variations in hardware or software, nor to provide for every possible contingency in connection with installation, operation, or maintenance. Features may be described herein which are not present in all hardware and software systems. GE Fanuc Automation assumes no obligation of notice to holders of this document with respect to changes subsequently made. GE Fanuc Automation makes no representation or warranty, expressed, implied, or statutory with respect to, and assumes no responsibility for the accuracy, completeness, sufficiency, or usefulness of the information contained herein. No warranties of merchantability or fitness for purpose shall apply. ©Copyright 2004 GE Fanuc Automation North America, Inc. All Rights Reserved. Introduction This is a description of C Executor function specification for following FANUC CNC. Applied CNC -----------------------------------------------------MODEL Abbreviated name -----------------------------------------------------FANUC Series 30i-MODEL A 30i-A or Series 30i Notes - It is necessary knowledge of C language programming to develop application program on C Executor. If you don't have experience of C programming, you must study C programming with ordinary C programming reference books. * Microsoft, MS, Windows, NT, and the Windows logo are either trademarks or registered trademarks of Microsoft Corporation. Diab SDS , alone and in combination with D-CC are trademarks of Diab SDS,INC. * Additionally, the described company name and the product name are the registered trademark of each company or trademarks. TABLE OF CONTENTS B-63944EN-3/01 TABLE OF CONTENTS I. SPECIFICATION 1. Overview ...............................................................................................3 1.1 2. System components.............................................................................6 2.1 2.2 2.3 2.4 3. C Executor .....................................................................................................6 C library..........................................................................................................7 Application program .......................................................................................8 The hardwares of CNC which are used in C Executor.................................11 Application program development environment..............................14 3.1 3.2 4. Feature ..........................................................................................................4 Composition of development system ...........................................................14 Development procedure...............................................................................16 C language library function list .........................................................18 4.1 4.2 4.3 4.4 4.5 ANSI C standard library ...............................................................................18 MS-C extended C standard library...............................................................21 Graphic library..............................................................................................22 CNC/PMC window library.............................................................................24 Other libraries ..............................................................................................26 II. PROGRAMMING 0. INDEX ..................................................................................................35 0.1 1. List of Functions.................................................................................38 1.1 1.3 1.4 1.5 2. Required software for application development ...........................................37 ANSI C Standard library...............................................................................38 Graphic library..............................................................................................46 CNC/PMC window library.............................................................................48 Other libraries ..............................................................................................51 How to make application program ....................................................59 2.1 2.2 2.3 2.4 2.5 Outline .........................................................................................................59 Special files..................................................................................................62 MAKEFILE ...................................................................................................63 Installing the Diab C/C++ Power-PC compiler .............................................65 Compatibility related to variables of type 'int' ...............................................66 c-1 TABLE OF CONTENTS 2.6 2.7 2.8 3. ANSI C standard library ...............................................................................70 MS-C extended C standard library.............................................................204 Graphic library............................................................................................207 CNC/PMC window library...........................................................................301 MDI operation library..................................................................................482 CRT operation library.................................................................................507 File Operation Library ................................................................................604 Serial Library..............................................................................................612 Task management library ..........................................................................631 FCA Library................................................................................................659 F-ROM Library ...........................................................................................692 Touch-panel Library ...................................................................................707 Code Tables ......................................................................................713 4.1 4.2 5 Using compiler libraries................................................................................66 Describing 2-byte characters in source-codes .............................................66 Remarks ......................................................................................................67 Function References ..........................................................................68 3.1 3.2 3.3 3.4 3.5 3.6 3.7 3.8 3.9 3.10 3.11 3.12 4 B-63944EN-3/01 Save current environment for non-local jump. <Main,Alarm,Comm> ........111 4.1.1 Keycode ............................................................................................................... 713 4.1.2 Keycode of special keys on MDI panel............................................................... 714 4.1.3 CRT display control characters ........................................................................... 715 4.1.4 Display control escape sequences ....................................................................... 715 Displayable characters...............................................................................719 4.2.1 Single byte characters.......................................................................................... 719 4.2.2 2-byte characters.................................................................................................. 720 4.2.3 Display code for single byte characters............................................................... 723 4.2.4 Kanji character code............................................................................................ 726 Other References..............................................................................727 5.1 5.2 5.3 Multitasking ................................................................................................727 5.1.1 Task classes ......................................................................................................... 727 5.1.2 Difference of each task class ............................................................................... 728 5.1.3 Task switching..................................................................................................... 728 5.1.4 Data access between tasks ................................................................................... 729 5.1.5 Task Management................................................................................................ 730 File system.................................................................................................731 Power-on procedure ..................................................................................734 c-2 TABLE OF CONTENTS B-63944EN-3/01 5.3.1 5.4 5.5 5.6 5.7 5.8 5.9 5.10 Key operation at power on .................................................................................. 734 Parameter setting on CNC.........................................................................735 Dat2mem utility manual .............................................................................738 Conforming O8-digits program number .....................................................744 Window task ..............................................................................................745 5.7.1 Overview.............................................................................................................. 745 5.7.2 Window task's execution ..................................................................................... 745 5.7.3 Usage of the window task.................................................................................... 746 5.7.4 Available functions for the window task............................................................. 747 5.7.5 How to make application program ...................................................................... 748 5.7.6 Notes ................................................................................................................... 748 Conforming CNC screen display................................................................749 5.8.1 Overview.............................................................................................................. 749 5.8.2 How do application program run on each equipment.......................................... 750 5.8.3 Restrictions on specification ............................................................................... 754 5.8.4 Making application program ............................................................................... 755 5.8.5 Function reference ............................................................................................... 757 High-Level Task .........................................................................................760 5.9.1 Overview of High-Level Task ............................................................................. 760 5.9.2 Specification ........................................................................................................ 760 5.9.3 Task execution rule.............................................................................................. 762 5.9.4 Application programming.................................................................................... 764 5.9.5 Function reference ............................................................................................... 765 Programming technique.............................................................................770 5.10.1 Various techniques .............................................................................................. 770 5.10.2 Applying C Executor to machine ........................................................................ 772 c-3 I. SPECIFICATION 1. Overview FANUC Series 30i C Executor enables to add the Machine Tool Builder's original screen into FANUC Series 30i and to customize screen displaying and operation interface of CNC software. It is possible to replace arbitrary screens of CNC with user application's screen. The user application program about screen displaying and operation interface is developed using general C language just like ordinary PC's application program developing. The executable file which is developed by the Machine Tool Builder is built in CNC unit. The user program which is compiled on PC is stored in flash ROM of CNC unit, and it is read into CNC's memory by CNC's start-up procedure, then, executed on C Executor. Application program is developed on PC. +------------+ | +--------+ | | | | | | | PC | | | +--------+ | +------------+ +--------------+ | == == | +--------------+ Application program is stored in flash ROM. CNC software and the user application program is executed simultaneously. +----------------------------------+ | | | Series 30i | | | |----------------------------------| +--------+ | User | C library | CNC | | Memory | | Application | | Soft | -> | Card | -> |----------------------------------| +--------+ +----------------------------------+ | | +--------------------------+ | +----------+ oooooo | Machine Tool Builder's | o |.... | oooooo | original screen is | o |....... | oooooo | displayed | |....... | oooooo | | |----------| oooooo | | +----------+ | | o o o o o | +--------------------------+ (LCD/MDI unit) 1.1 Feature (1) Low-cost customization No addtional hardware is required to use C Executor and application program on FANUC Series 30i. (*) The user application program can be built in your Series 30i as it is. (*) It may be necessary to increase flash ROM or DRAM capacity. (2) Application program development on PC You can develop application program on generic PC (Personal Computer). Designing, editing, compiling, linking and also some debugging works are executed on PC. (3) High level compatibility with C application on PC Function libraries of C language which are provided by C Executor has compatibitily with ANSI and MS-C. Therefore, ordinary application programs on PC can be translated to CNC's as long as they don't depend on specific hardware. (4) Combination of CNC software and application program The application program which is developed by the Machine Tool Builder is executed as a task in CNC softwares. Some arbitrary screens of existing CNC screens can be replaced with user screens which are displayed by the user application program. Application program can read or write various CNC data via libaries which are provided by C Executor. Therefore, the user application program works as a part of CNC software. Additionally, it is possible not only to replace existing CNC screens, but also to add new user's screens. (5) Graphic display and communication (*) Graphic display function, which has 640x480 resolution and 256color/pixel, is used in application program. This graphic screen is imposed on character screen. For graphic display, MS-C compatible graphic functions, such as line, rectangle and arc drawing, painting, etc., are provided. Communication with personal computer, etc. is available using reader/puncher interface (RS-232C) on CNC unit. Communication driver is built in the C library, therefore, communication is processed by just calling communication functions. The user application program can read from or write to FANUC FLOPPY CASSETTE ADAPTER and FANUC HANDY FILE connected to CNC unit. (*) "READER/PUNCHER INTERFACE CONTROL" option is required to use communication function. (6) Using with Macro Executor C Executor can be used with Macro Executor (Execution Macro and also Conversational Macro) of Series 30i-A. The screen displaying part of macro program which has been developed by the Machine Tool Builder can be replaced with C program, therefore, existing software property does not become useless. (C Executor doesn't have Execution Macro function.) (7) Easy installation to CNC unit The user application program which is developed by the Machine Tool Builder is installed to CNC unit using memory card (JEIDA/PCMCIA compatible SRAM card or ATA flash memory card). It is easy to install and update the applicaton program because it isn't need to write EPROM using ROM-writer. (8) Storing various data in flash ROM It is available to store various data (message strings to be displayed, individual parameters for each machines and tool information, etc.) made on PC. The user application program can read them arbitrarily. (9) Supporting touch-panel and input/output via memory card. C Executor memory card. supports hardwares such as touch-panel and input/output via These I/O devices are good for building better user interface. (*) "TOUCH PANEL" option is required to use touch-panel. (10) Simultaneous displaying of CNC and user screen using window display The user application program can display user window on the arbitrary screens including the CNC screens using window display function (VGA window). It is possible to display Machine Tool Builder's original message window or the software machine operation panel on the existing CNC screen. 2. System components The system components that C Executor and the user application program are shown below. +--------------------------------+ +----+ +-------------+ | | | <- | | | User | | | CNC window | -> | | <- | application | | | | *3 | | -> | program | | CNC software |---------------| | | *1 | | | | | | | +-------------+ | | C Executor | <- | +------------------+ | | | -> | C library | | | | *4 | | +--------------------------------+ +-----------------------+ ^ | ^ | *2 | v | v +-------------------------------------------------------------+ | FANUC Series 30i Hardware | +-------------------------------------------------------------+ *1 *2 *3 *4 library function call by user application output to screen, reading MDI key or touch-panel, etc. reading/writing of CNC information task switching, screen switching, etc. 2.1 C Executor C Executor provides following functions. (1) Loading and starting application program C Executor loads the user application program and C library from flash ROM into DRAM in start-up procedure of CNC unit, and starts executing the user application program. (2) Switching CNC screen and user screen C Executor watches screen switching by operator's MDI operation. When any user screen is selected, C Executor switches execution to user application. When CNC screen is selected again, C Executor returns execution to CNC software. (3) Managing CNC task and user task C Executor manages the user application's background task in addtion to switching process by screen switching. 2.2 C library C library provides following functions. (1) Input/output between peripheral equipments (LCD and MDI key) C library executes input/output operations, which are called by the user application program, such as character displaying to screen by "printf" function, reading MDI key by "getch" function, graphic displaying by MS-C compatible function and input/output via reader/puncher interface etc. (2) Input/output CNC information (current position, parameter and tool offset, etc.) C library provides input/output function of various CNC information using CNC window function, and also PMC information using PMC window. (3) ANSI and MS-C compatible C language function library C library provides ANSI compatible C language standard library (there are some exceptions) and MS-C extended C language standard library which doesn't depend on specific hardware and operating system. (4) MS-DOS compatible file system C library provides MS-DOS compatible file system. The user application program can access SRAM disk (max 63KB(standard)/255KB(optional)) on nonvolatile memory (SRAM) or memory card (PC card) via this file system. It is possible to read or write files using functions such as "fopen", "fprintf", "fgets", etc. in application program. 2.3 Application program (1) Program structure Application program consists of three independent tasks. +- USER APPLICATION -------------------------+ | +========================================+ | | | | | | | (A)MAIN TASK | | | | | | | +========================================+ | | +- AUXILIARY TASK -----------------------+ | | | +==============+ +==================+ | | | | | (B)ALARM | | (C)COMMUNI| | | | | | TASK | | CATION TASK | | | | | +==============+ +==================+ | | | +----------------------------------------+ | +--------------------------------------------+ (A) MAIN TASK Almost all processes, such as screen displaying, key input, read/write CNC information, etc., are executed in this task. (B) ALARM TASK This task is periodically started usally and watches various conditions. (C) COMMUNICATION TASK This task is usually used for processing of input/output via reader/puncher interface independently of MAIN TASK. ALARM TASK and COMMUNICATION TASK are called AUXILIARY TASK. (Also called BACKGROUND TASK because these tasks are executed in background of MAIN TASK) AUXILIARY TASKS are limited in their function. MAIN TASK ALARM TASK COMMUNICATION TASK ------------------------------------------------------------------Standard function x x x Key input x Character display x Graphic display x File I/O x x (*1) x (*1) CNC/PMC window x x (*2) Reader/puncher interface x x (*3) x (*3) Reading F-ROM x x (*3) x (*3) Reading touch-panel x x x ("x" means "available" "BLANK" means "not available") (*1) The same file cannot be accessed by two or more tasks simultaneously. It is necessary to control exclusively in application program. (*2) Simultaneous access with MAIN TASK causes BUSY ERROR. (*3) It is necessary to control communication port and F-ROM reading exclusively by the application program itself. Task switching between MAIN TASK and AUXILIARY TASK is done by calling task control library function in application program. Periodically starting of AUXILIARY TASK is also commanded in application program. It is possible to compose application program with only one task. In this case, only MAIN TASK is used. Additionally, the window task is available in addition to the above tree tasks. The window task runs simultaneously with above tree tasks and is used to display windows on arbitrary screen. The following functions are available in the window task. WINDOW TASK ---------------------------------Standard function x Key input Character display x (*1) Graphic display x (*1) File I/O CNC/PMC window x (*2) Reader/puncher interface Reading F-ROM Reading touch-panel x ("x" means "available" "BLANK" means "not available") (*1) The target screen to output is not the ordinary screen but VGA window. (*2) It is necessary to contol exclusively with the other tasks. (2) Executable program model Executable file format is different from EXE-format of MS-DOS. Also execution environment is not compatible with MS-DOS. However, the same function as MS-DOS PC's can be used in application program as long as they are not depend on specific hardware. (3) Example of application program For example, structures. the program which consists of only Main task has following ++---------------++ || main function || ++-------+-------++ | +----------+----------+ | Initialization | +----------+----------+ | +----------+----------+ | Setting of user | | screens | +----------+----------+ | +----------+----------+ | Setting of softkeys | | by which user | | screens are selected| +----------+----------+ | Repetition |<----------------------------------+ +----------+----------+ | | Get current screen | | | index | | +----------+----------+ | | | +----------+----------+ | | Branch to each | | | screen's procedure | | +----------+----------+ | | | +---------------+-------+----------------+--... | | | | | +----------+----------+ +----------+----------+ +---+---+ | | Read CNC information| | Read numeric value | |.... | | | and display them on | | from MDI key and | | | | | screen | | update data | | | | +----------+----------+ +----------+----------+ +---+---+ | | | | | +---------------+-------+----------------+--... | | | +-----------------------------------+ 2.4 The hardwares of CNC which are used in C Executor ITEM SPECIFICATION REMARKS ======================================================================== CPU PowerPC compatible processor It is common with CNC software. -----------------------------------------------------------------------DRAM MAX 1, 2, 3, 4, 5, or 6MB Independent area from CNC software is used. One capacity must be specified optionally. DRAM FOR USER APPLICATION (*1) 384 - 5504KB This is usable capacity of above DRAM size in the user application. Value up to (DRAM capacity - 640KB) is set in parameter. -----------------------------------------------------------------------SRAM 64/256KB(option) SRAM DISK MAX 63/255KB(with SRAM 256KB) Sum of SRAM disk and non-volatile variables NON-VOLATILE MAX 63/255KB(with SRAM 256KB) is up to VARIABLES (SRAM capacity - 1KB). -----------------------------------------------------------------------MEMORY CARD PCMCIA or JEIDA compatible Other cards than SRAM cards 256KB - 2MB specified card aren't ATA Flash memory card supported Supporting MS-DOS format -----------------------------------------------------------------------F-ROM Available to store arbitrary Data size to store is data variable according to Application program can read F-ROM capacity, etc. stored data (Max: about 6MB) -----------------------------------------------------------------------MDI KEY ONG keyboard Key arrangement is or QWERTY keyboard custmizable. -----------------------------------------------------------------------TOUCH-PANEL 640x480 resolution "TOUCH-PANEL" option Reading status and position is required. ------------------------------------------------------------------------ ITEM SPECIFICATION REMARKS ======================================================================== DISPLAY DEVICE 10.4-inch color LCD (*2) 10.4-inch color LCD with touch-panel (*2) - Alphanumeric character (80x25(*3)) - Kanji character (40x25(*3)) - 16-grayscale, reverse, blink, background color, for each character -----------------------------------------------------------------------PRINTABLE - Alphanumeric and Kana CHARACTER (ANK character) - FANUC Kanji character (about 2,400 characters of JIS 1ST LEVEL) - Special signs - User definition character (MAX 256 characters (half)) - JIS Kanji character (1st and 2nd level, about 6,800 characters) COEXISTENCE It is possible to coexist WITH CNC'S with each CNC's screens. SCREEN -----------------------------------------------------------------------DISPLAY DEVICE - 640x400 x1(page), or It is impossible to (GRAPHIC) 640x480 x1(page) coexist with CNC's - 16 or 256-color for each graphic screen. pixel "GRAPHIC DISPLAY" - imposed output on character option is required. screen for 16-color mode, no imposed output for 256color mode ------------------------------------------------------------------------ ITEM SPECIFICATION REMARKS ======================================================================== WINDOW DISPLAY - Max 8 windows on user screen (overlapping only character) - Max 2 windows on arbitrary screen (overlapping both character and graphics) (*4) -----------------------------------------------------------------------READER/PUNCHER 1 or 2 channels "READER/PUNCHER INTERINTERFACE FACE CONTROL" option (RS-232C) is required. -----------------------------------------------------------------------FANUC CASSETTE Available for application "READER/PUNCHER INTERADAPTER, FANUC program FACE CONTROL" option HANDY FILE is required. ( "KB" means "kilo bytes" (1024 bytes), "MB" means "mega bytes" (1024 kilo bytes) ) (*1) Usable memory capacity of Macro Executor is ( (custom soft capacity) - (C Executor capacity) ) (*2) These display devices are VGA graphic devices. "16-color", "256-color" and "16-grayscale" mean number of color palettes which can be simultaneously displayed on the screen. The application program can map the arbitrary color from 4096 colors into each color palette. (*3) 30-line in a screen is also available. (*4) This is available on VGA display device. 3. Application program development environment Application program of C Executor is developed by the Machine Tool Builder. - General PC(personal computer) is used to develop (edit and compile) application program. - Only execution of application program is possible on CNC unit. - Debugging of application program is worked on both PC and CNC. Some parts of application program which can work on PC can be debugged on PC as ordinary PC's software. Whole program is debugged on CNC. 3.1 Composition of development system (1) Goods on the market +------------+ | +--------+ | .... - Executable for Microsoft Windows 2000 | | | | or Windows 98 | | PC | | | +--------+ | +------------+ +--------------+ +---------------+ | == == |----| MEMORY CARD | .... - PCMCIA Rel.1.0, +--------------+ | READER/WRITER | JEIDA V4.0 +---------------+ compatible +-------------+ | MEMORY CARD | .... - 1MB or more capacity | (SRAM CARD) | (Required capacity +-------------+ depends on application program) +----------+ |COMMERCIAL| - Microsoft Windows 2000 or Microsoft | SOFTWARE | .... Windows 98 | +------+ | - Text editor(arbitrary) | | | | - Diab C/C++ Power-PC compiler developed by | | | | WindRiver +-+------+-+ (*) You can use not only SRAM card but also ATA flash memory card as the memory card for the development system. (2) Purchases from FANUC +----------+ | FANUC | | library | | +------+ | | | | | | | | | +-+------+-+ .... - ANSI compatible C standard library - MS-C compatible library - CNC window Software of the Machine Tool Builder +----------+ | | | | | +------+ | ----+ | | | | | | | | | | +-+------+-+ | | +--- ( LINK ) ---> FANUC library | +----------+ | | | | | | | | +------+ | ----+ | | | | | | | | +-+------+-+ +----------+ | | | | | +------+ | | | | | | | | | +-+------+-+ | | | | | v +----------------+ personal computer | | - - - - - - - - - - - - - - - - - | MEMORY CARD | - - - - - FANUC Series 30i-MODEL A +----------------+ | v +--------------------------------+ +-- | Application program & library | | +--------------------------------+ Flash ROM ----+ | C Executor | | +--------------------------------+ +-- | CNC system software | +--------------------------------+ +--------------------------------+ | CNC hardware | +--------------------------------+ 3.2 Development procedure The development procedure of software for C Executor is as follows. +---------------+ --+ | SPECIFICATION | | | DESIGN | | +-------+-------+ | | | +-------+-------+ | | FUNCTION | | | DESIGN | | +-------+-------+ | | | +-------+-------+ | | PROGRAMIMIG | | | CODING, | +-- working on PC | EDITING | | +-------+-------+ | | | +-------+-------+ | | COMPILING, | | | LINKING | | +-------+-------+ | | | +-------+-------+ | --+ | DEBUGGING | | | +-------+-------+ --+ | | +-- working on CNC +-------+-------+ | | TESTING | | +---------------+ ------+ (1) Developing program which works on PC You develop program just like as ordinary PC's program. In this step, some parts of application program which can work on PC are developed. However, only library functions which are provided by C Executor can be used in application program. Some extended functions by compiler maker may not be used on C Executor. Also hardware depending program such as BIOS call is not available on C Executor. (2) Testing on PC Source level debugging of application program on PC can be done by using compiler for PC. Function mudule level testing can be completed even if there are some difference between PC and C Executor. (3) Completing program for C Executor After module level testing on PC, you develop entire application with FANUC library. If any error occured in this step, you confirm usage of C language library. You use makefile which is provided from FANUC to compile, link and make memory card file. (4) Installing to CNC You write application program to flash ROM on CNC via memory card. (5) Testing application program on CNC You test application program on CNC. 4. C language library function list 4.1 ANSI C standard library The following ANSI C language standard functions are provided. (1) Diagnostics assert (2) Character handling isalnum isalpha iscntrl isdigit isgraph islower isprint ispunct isspace isupper isxdigit tolower toupper (3) Non-local jumps setjmp longjmp (4) Valiable arguments va_start va_arg va_end (5) Input/output remove rename tmpnam fclose fflush fopen freopen setbuf setvbuf fprintf fscanf printf scanf sprintf sscanf vfprintf vprintf vsprintf fgetc fgets fputc fputs getc getchar gets putc putchar puts ungetc fread fwrite fgetpos fseek fsetpos ftell rewind clearerr feof ferror perror calloc free malloc realloc bsearch qsort abs div labs ldiv atof strtod strcmp strncmp memchr strchr strcspn strpbrk strrchr strspn strstr strtok memset strlen time localtime difftime gmtime mktime (6) General utilities atoi atol strtol strtoul rand srand (7) String handling memcpy memmove strcpy strncpy strcat strncat memcmp (8) Date and time clock asctime ctime (9) Mathematics acos asin atan atan2 ceil cos cosh exp fabs floor fmod frexp ldexp log log10 modf pow sin sinh sqrt tan tanh 4.2 MS-C extended C standard library The following MS-C extended functions are provided. _chdrive _dos_findfirst _dos_findnext _dos_getdiskfree _expand _fcalloc _fexpand _ffree _fmalloc _fmemchr _fmemcmp _fmemcpy _fmemicmp _fmemmove _fmemset _fmsize _frealloc _fstrcat _fstrchr _fstrcmp _fstrcpy _fstrcspn _fstricmp _fstrlen _fstrlwr _fstrncat _fstrncmp _fstrncpy _fstrnicmp _fstrnset _fstrpbrk _fstrrchr _fstrrev _fstrset _fstrspn _fstrstr _fstrtok _fstrupr _getdrive _lrotl _lrotr _msize _rotl _rotr _tolower _toupper alloca cabs chdir close creat ecvt eof fcvt gcvt getch getcwd hypot isascii itoa kbhit lseek ltoa memicmp mkdir open read rmdir stackavail strcmpi stricmp strlwr strnicmp strnset strrev strset strupr swab tell toascii ultoa write 4.3 Graphic library (1) MS-C compatible graphic functions The following MS-C graphic functions are provided. However, some detail specifications of functions may be different between PC and CNC because both hardwares are not compatible completely. _arc _clearscreen _ellipse _floodfill _getactivepage _getarcinfo _getbkcolor _getcolor _getcurrentposition _getfillmask _getfontinfo _getgtextextent _getgtextvector _getimage _getkanji _getlinestyle _getphyscoord _getpixel _gettextposition _gettextwindow _getvideoconfig _getviewcoord _getvisualpage _getwritemode _grstatus _imagesize _kanjisize _lineto _moveto _outgtext _outmem _outtext _pie _polygon _putimage _rectangle _registerfonts _remapallpalette _remappalette _setactivepage _setbkcolor _setcliprgn _setcolor _setfillmask _setfont _setgtextvector _setlinestyle _setpixel _settextposition _settextrows _settextwindow _setvideomode _setvideomoderows _setvieworg _setviewport _setvisualpage _setwritemode _unregisterfonts _wrapon (2) Original graphic functions These functions are C Executor original graphic functions. NAME FUCNTION -------------------------------------------------------------------------gr_displaychar Draw a standard size character gr_displayfourlarge Draw a quad size character gr_displaysixlarge Draw a hex size character _putpattern Put monochrome image data _getpattern Get monochrome image data gr_dispstr Draw a standard size string gr_disp6str Draw a hex size strings gr_bitblt Copy image data gr_disp4str Draw a quad size string. gr_displaysmlchar Draw a small size character. gr_dispsstr Draw a small size string. gr_displayfchar Draw a FANUC character. gr_dispfstr Draw a FANUC character string. gr_disp9ifchar Draw 9-inch font character. gr_disp9ifstr Draw 9-inch font character string. mmc_line_b Draw a line between specified two points. mmc_polyline Draw a polyline. mmc_circle_b Draw a circle. mmc_ellipse_b Draw an ellipse. mmc_pie_b Draw a pie figure. mmc_arc_b Draw an arc. mmc_gettext Get character in the specified area. mmc_puttext Put character data on memory to text screen. mmc_textsize Get required byte size for getting character. 4.4 CNC/PMC window library The following functions /PMC are provided. which are used to input/output data between CNC (1) CNC window NAME FUCNTION -------------------------------------------------------------------------cnc_sysinfo Read CNC system information cnc_dwnstart Start output of NC program to be registered cnc_download Output NC program to be registered cnc_dwnend Stop output NC program to be registered cnc_vrfstart Start output NC program to be compared cnc_verify Output NC program to be compared cnc_vrfend Stop output NC program to be compared cnc_dncstart Start output NC program to be executed cnc_dnc Output NC program to be executed cnc_dncend Stop output NC program to be executed cnc_upstart Start input NC program cnc_upload Input NC program cnc_upend Stop input NC program cnc_search Search specified program cnc_delall Delete all program cnc_delete Delete specified program cnc_rdprogdir Read program directory cnc_rdproginfo Read program information cnc_rdprgnum Read program number in executing cnc_rdseqnum Read sequence number in executing cnc_actf Read actual feed rate of controlled axes cnc_acts Read actual spindle speed cnc_absolute Read absolute position cnc_machine Read machine position cnc_relative Read relative position cnc_distance Read distance to go cnc_skip Read skipped position cnc_srvdelay Read servo delay amount cnc_accdecdly Read acceleration/deceleration delay amount cnc_rddynamic Read dynamic data cnc_statinfo Read CNC status information cnc_alarm Read alarm status cnc_rdalminfo Read alarm information cnc_rdtofs Read tool offset amount cnc_wrtofs Write tool offset amount cnc_rdtofsr Read tool offset amount (range specified) cnc_wrtofsr Write tool offset amount (range specified) cnc_rdzofs Read work zero offset cnc_wrzofs Write work zero offset cnc_rdzofsr Read work zero offset (range specified) cnc_wrzofsr Write work zero offset (range specified) NAME FUNCTION -------------------------------------------------------------------------cnc_rdparam Read parameter cnc_wrparam Write parameter cnc_rdparar Read parameters (range specified) cnc_wrparas Write parameters (multiple output) cnc_rdset Read setting parameter cnc_wrset Write setting parameter cnc_rdsetr Read setting parameters (range specified) cnc_wrsets Write setting parameters (multiple output) cnc_rdpitchr Read pitch error compensation data (range specified) cnc_wrpitchr Write pitch error compensation data (range specified) cnc_rdmacro Read custom macro variable cnc_wrmacro Write cumtom macro variable cnc_rdmacror Read custom macro variables (range specified) cnc_wrmacror Write custom macro variables (range specified) cnc_rdpmacro Read P-code macro variable cnc_wrpmacro Write P-code macro variable cnc_rdpmacror Read P-code macro variables (range specified) cnc_wrpmacror Write P-code macro variables (range specified) cnc_modal Read modal data cnc_diagnoss Read diagnostics data cnc_diagnosr Read diagnostics data (range specified) cnc_adcnv Read A/D conversion data cnc_rdopmsg Read operator's message cnc_setpath Set path index (multi-path system) cnc_getpath Get path idnex (multi-path system) cnc_settimer Set calendar timer of CNC cnc_rdspload Read load information of serial spindle cnc_rdexecprog Read executing program cnc_rdmovrlap Read manual handle override amount (2) PMC window NAME FUNCTION -------------------------------------------------------------------------pmc_rdpmcrng Read arbitrary PMC data (range specified) pmc_wrpmcrng Write arbitrary PMC data (range specified) pmc_rdpcmsg Read PMC message 4.5 Other libraries (1) MDI operation library These funcitons are used to control key input from CNC's MDI panel. NAME FUNCTION -------------------------------------------------------------------------aux_mdi_getmatrix Get MDI key matrix aux_mdi_putmatrix Put MDI key matrix aux_mdi_rstmatrix Reset MDI key matrix aux_mdi_altmatrix Alter MDI key matrix aux_mdi_putc Put one character to key input buffer aux_mdi_write Write block data to key input buffer aux_mdi_control Test or control key input buffer aux_mdi_repeat Set key repeating interval time aux_mdi_getstat Read inputting status of MDI key. aux_mdi_clrbuf Clear input buffer of MDI key. (2) CRT operation library These functions are used to control CRT display and multiple window display. NAME FUNCTION -------------------------------------------------------------------------crt_getcurscrn Get current screen index crt_setuserscrn Register user screen index crt_isnewscrn Test screen switching status crt_gettype Set CRT information crt_setmode Set CRT screen mode crt_cncscrn Switch to CNC screen crt_fchar Outpout character by FANUC character code crt_setuserskey Customize softkey on CNC screen crt_setswt Set switching method between CNC's screen and user's crt_setscrlarea Set scroll area crt_opengr Open graphic display crt_closegr Close graphic display crt_graphic Enable or disable graphic display crt_readfkey Read the status of function keys crt_2ndcursor Display the secondary cursor crt_settextattr Set attribute of characters on VRAM crt_gettextattr Get attribute of character on VRAM crt_setpalette Set color palette of VGA characters crt_setallpalette Set all color palette of VGA characters NAME FUNCTION -------------------------------------------------------------------------crt_getcncpalette Get color palette of CNC screen crt_fstr Output character string by FANUC character code. crt_gettextimg Get text data from VRAM. crt_puttextimg Put text data into VRAM. crt_setgraphpage Select graphics page to use. crt_set6chmode Select drawing method of 6x sized character. crt_setgsvmode Select saving method of graphic contents. win_open Open window win_close Close window win_select Select window win_activate Activate window win_move Move window win_size Alter window size win_full Let active window be full screen size win_window Let active window be window size win_info Set window information win_col Set color of window frame and title string win_hide Hide window win_show Show window win_setttl Set window title string win_setfrm Set window frame line character win_getstat Get window display status win_redraw Redraw windows. crt_reguserchar Register user character crt_mapuch Map user character crt_getcgpttn Get CG pattern vwin_open Open VGA window vwin_close Close VGA window vwin_select Select VGA window vwin_show Show VGA window vwin_hide Hide VGA window vwin_info Get VGA window information (3) File operation library This function is used to maintain file device. NAME FUNCTION -------------------------------------------------------------------------aux_file_format Format specified drive aux_file_mount Mount memory card aux_file_unmount Unmount memory card aux_file_memcinfo Get memory card information (4) Serial communication library These functions are used to communicate with peripherals via reader/ puncher interface(RS-232C). NAME FUNCTION -------------------------------------------------------------------------rs_open Initialize communication device rs_close Terminate communication rs_putc Put one character to communication buffer rs_getc Get one character from communication buffer rs_write Write block data to communication buffer rs_read Read block data from communication buffer rs_buffer Test or control communication buffer rs_status Get status of communication line and buffer rs_wait Wait communication event (5) Task control library These functions are used to control task execution. NAME FUNCTION -------------------------------------------------------------------------os_show_tim Read timer os_set_tim Set timer os_sync_tim Wait until specified time os_wait_tim Wait until specified term os_make_flg Make event flag os_delt_flg Delete event flag os_sign_flg Signal event flag os_wait_flg Wait event flag signal os_clar_flg Clear event flag os_puls_flg Signal event flag (pulse type) os_make_sem Make counter-type semaphore os_delt_sem Delete semaphore os_sign_sem Signal semaphore os_wait_sem Wait swmaphore signal os_strt_wtsk Start window task (6) FCA library These are the functions which communicate with FCA (FANUC CASSETTE ADAPTOR) or FANUC Handy File. NAME FUNCTION -------------------------------------------------------------------------fca_setparam Initialize communication line fca_bye Close communication line fca_open Open a binary file on FCA device fca_close Close a binary file fca_read Read binary data from the file fca_write Write binary data to the file fca_fopen Open a text file on FCA device fca_fclose Close a text device fca_getc Read a character from the text file fca_putc Write a character to the text file fca_delete Delete a file on FCA device fca_rename Change name of a file on FCA device fca_readdir Read directory information of FCA device fca_status Read status information of FCA device fca_remains Read free space size of a floppy disk (7) F-ROM library These are the functions which read C Executor data stored in the flash ROM module. NAME FUNCTION -------------------------------------------------------------------------aux_from_open Open the specified F-ROM file aux_from_close Close the F-ROM file aux_from_select Select data in the F-ROM file aux_from_moveptr Move read pointer aux_from_read Read data from the F-ROM file aux_from_getdir Read directory information of a F-ROM file aux_from_getinfo Read F-ROM file information aux_from_getc Read a character from the F-ROM file aux_from_gets Read a line from the F-ROM file (8) Touch-panel library This is the function which reads the status and (X,Y) coordinate of the touch-panel. NAME FUNCTION -------------------------------------------------------------------------aux_tpl_read Read the status and (X,Y) coordinate of touch-panel II. PROGRAMMING - This manual is intended to explain the C executor for the FANUC Series 30i. - Do not use the manual for any purpose other than creation of applications for the FS30i C executor. - Some descriptions in the manual include JIS ruled lines and half-size katakana characters. If your PC environment cannot display or print these lines or characters correctly, convert them to appropriate character code. - To display or print descriptions in the manual, set the tab step to "8". - Most pages of the manual are in 80-column ( 60-line format. So they can be printed normally on a typical printer. - To display or print descriptions in the manual, use a fixed-pitch font for both half-size (English) and full-size (Japanese) characters. Microsoft, Windows, Windows NT, MS, and MS-DOS are Microsoft Corporation's trademarks registered in the USA and other countries. * The other corporate names and product names mentioned in the manual are the trademarks or registered trademarks of the respective companies. Description of CNC name, etc. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C Executor works on the following CNC equipments. FS30i In this document, the CNC names are described as the following abbreviated names. Abbreviation CNC -----------------------+-------------------------------------------FANUC Series 30i The generic name of all FS30i on which or FS30i C Executor works. C Executor supports the following display devices. Device Size, Monochrome/Color ---------------+---------------------------------------------------LCD 10.4-inch color, 10.4-inch color(with touch-panel) In this document, the CNC device names may be described as the following abbreviated names. Abbreviation Device -----------------------+-------------------------------------------14-inch CRT The generic name of the display devices which have 10(+2) softkeys and 80-column x 25-line character screen (in standard mode). For more information about display devices, see "3.6 CRT operation library". 0. INDEX ~~~~~~~~ Filename Contents ---------------+---------------------------------------------------00index.man 0. INDEX 01soft.man 0.1 Required software for application development 10functn.man 1. List of Functions 20mkapp.man 2. How to make application program 30fref.man 31ansi_c.man 32ms_c.man 33graph.man 34window.man 35mdi.man 36crt.man 37file.man 38serial.man 39task.man 3afca.man 3bfrom.man 3ctpl.man 3. Function References 3.1 ANSI C Standard library 3.2 MS-C extended C standard library 3.3 Graphic library 3.4 CNC/PMC window library 3.5 MDI operation library 3.6 CRT operation library 3.7 File operation library 3.8 Serial library 3.9 Task management library 3.10 FCA library 3.11 F-ROM library 3.12 Touch-panel library 4. Code Tables 4.1 Keycode, Screen control code 4.2 Displayable characters including Japanese KANJI characters) 41code.man 42char.man (42char_j.man 5. 51mtask.man 52fsys.man 53pwon.man 54cncprm.man 55d2m.man 56o8d.man 57wintsk.man 58cncscr.man 59hilev.man 5aprotec.man cexec01.spc Other References 5.1 Multitasking 5.2 File system 5.3 Power-on procedure 5.4 Parameter setting on CNC 5.5 Manual of dat2mem 5.6 Adaptation for 8-digit program number 5.7 Window task 5.8 Conforming CNC screen display 5.9 High-Level Task 5.10 Programming technique C Executor Specification Update history 2003. 4. 1 1st edition. 0.1 Required software for application development ================================================= The following softwares are required for development of the C Executor application program. Please purchase each package softwares on the market by yourself. (1) C Compiler. Use the WindRiver Diab C/C++ Power-PC compiler. Only the limited compiler versions can be used. Ask FANUC for them. (2) Linker. Use the linker attached to the WindRiver Diab C/C++ Power-PC compiler. (3) OS environment on PC. The C Executor application is developed on the command prompt environment of Microsoft Windows 2000 or MS-DOS prompt environment of Windows 98. (4) Other tools. Developing application software additionally requires the following tools. Get their commercial versions or equivalents. nmake.exe : Microsoft-developed make tool, included in the Microsoft Visual C/C++ package. gawk.exe : GNU's awk tool, available from http://source.redhat.com/cygwin. sed.exe : GNU's sed tool, available from http://source.redhat.com/cygwin. 1. List of Functions ==================== (abbreviation) (mark) CExe ANSI MS-C x blank M MA MAC : : : : : : : : C Executor American National Standards Institute Microsoft Corp. MS-C Ver 6.0, Ver 7.0 or Ver 8.0 available not available available only on Main task available on Main task and Alarm task available on Main task, Alarm task and Communication task 1.1 ANSI C Standard library C language standard functions which are prescribed in ANSI. (1) Diagnostics ( assert.h ) ----------------------------------Name CExe ANSI MS-C -------------------+----+----+----assert M x x ----------------------------------- (2) Character handling ( ctype.h ) ----------------------------------Name CExe ANSI MS-C -------------------+----+----+----isalnum MAC x x isalpha MAC x x iscntrl MAC x x isdigit MAC x x isgraph MAC x x islower MAC x x isprint MAC x x ----------------------------------(3) Localization ( local.h ) ----------------------------------Name CExe ANSI MS-C -------------------+----+----+----localeconv x x setlocale x x ----------------------------------- ----------------------------------Name CExe ANSI MS-C -------------------+----+----+----ispunct MAC x x isspace MAC x x isupper MAC x x isxdigit MAC x x tolower MAC x x toupper MAC x x ----------------------------------- (4) Mathematics ( math.h ) ----------------------------------Name CExe ANSI MS-C -------------------+----+----+----acos MAC x x asin MAC x x atan MAC x x atan2 MAC x x cos MAC x x sin MAC x x tan MAC x x cosh MAC x x sinh MAC x x tanh MAC x x exp MAC x x ----------------------------------(5) Non-local jumps ( setjmp.h ) ----------------------------------Name CExe ANSI MS-C -------------------+----+----+----setjmp MAC x x longjmp MAC x x ----------------------------------(6) Signal handling ( signal.h ) ----------------------------------Name CExe ANSI MS-C -------------------+----+----+----signal x x raise x x ----------------------------------(7) Variable arguments ( stdarg.h ) ----------------------------------Name CExe ANSI MS-C -------------------+----+----+----va_start MAC x x va_arg MAC x x va_end MAC x x ----------------------------------- ----------------------------------Name CExe ANSI MS-C -------------------+----+----+----frexp MAC x x ldexp MAC x x log MAC x x log10 MAC x x modf MAC x x pow MAC x x sqrt MAC x x ceil MAC x x fabs MAC x x floor MAC x x fmod MAC x x ----------------------------------- (8) Input/output ( stdio.h ) ----------------------------------Name CExe ANSI MS-C -------------------+----+----+----remove MAC x x rename MAC x x tmpfile x x tmpnam MAC x x fclose MAC x x fflush MAC x x fopen MAC x x freopen MAC x x setbuf MAC x x setvbuf MAC x x fprintf MAC x x fscanf MAC x x printf M x x scanf M x x sprintf MAC x x sscanf MAC x x vfprintf MAC x x vprintf M x x vsprintf MAC x x fgetc MAC x x fgets MAC x x ----------------------------------- ----------------------------------Name CExe ANSI MS-C -------------------+----+----+----fputc MAC x x fputs MAC x x getc M x x getchar M x x gets M x x putc M x x putchar M x x puts M x x ungetc MAC x x fread MAC x x fwrite MAC x x fgetpos MAC x x fseek MAC x x fsetpos MAC x x ftell MAC x x rewind MAC x x clearerr MAC x x feof MAC x x ferror MAC x x perror M x x ----------------------------------- (9) General utilities ( stdlib.h ) ----------------------------------Name CExe ANSI MS-C -------------------+----+----+----atof MAC x x atoi MAC x x atol MAC x x strtod MAC x x strtol MAC x x strtoul MAC x x rand MAC x x srand MAC x x calloc MAC x x free MAC x x malloc MAC x x realloc MAC x x abort x x atexit x x ----------------------------------- ----------------------------------Name CExe ANSI MS-C -------------------+----+----+----exit x x getenv x x system x x bsearch MAC x x qsort MAC x x abs MAC x x div MAC x x labs MAC x x ldiv MAC x x mblen x mbtowc x wctomb x mbstowcs x wcstombs x ----------------------------------- (10) String handling ( string.h ) ----------------------------------Name CExe ANSI MS-C -------------------+----+----+----memcpy MAC x x memmove MAC x x strcpy MAC x x strncpy MAC x x strcat MAC x x strncat MAC x x memcmp MAC x x strcmp MAC x x strcoll x x strncmp MAC x x strxfrm x x ----------------------------------- ----------------------------------Name CExe ANSI MS-C -------------------+----+----+----memchr MAC x x strchr MAC x x strcspn MAC x x strpbrk MAC x x strrchr MAC x x strspn MAC x x strstr MAC x x strtok MAC x x memset MAC x x strerror x x strlen MAC x x ----------------------------------- (11) Date and time ( time.h ) ----------------------------------Name CExe ANSI MS-C -------------------+----+----+----clock MAC x x difftime MAC x x mktime MAC x x time MAC x x asctime MAC x x ----------------------------------- ----------------------------------Name CExe ANSI MS-C -------------------+----+----+----ctime MAC x x gmtime MAC x x localtime MAC x x strftime x x ----------------------------------- 1.2 MS-C extended C standard library Compatible functions with extended library of Microsoft C Compiler (MS-C Ver 6.0). ----------------------------------Name CExe ANSI MS-C -------------------+----+----+----FP_OFF x FP_SEG x _atold x _bcalloc x _beginthread x _bexpand x _bfree x _bfreeseg x _bheapadd x _bheapchk x _bheapmin x _bheapseg x _bheapset x _bheapwalk x _bios_xxxxxxx x _bmalloc x _bmsize x _brealloc x _cexit x _c_exit x _chain_intr x _chdrive MAC x _clear87 x _control87 x _disable x _dos_xxxxxxxx x _dos_findfirst MAC x _dos_findnext MAC x _dos_getdiskfree MAC x _enable x _endthread x _exit x _expand MAC x _fbtom x _fcalloc MAC x _fexpand MAC x _ffree MAC x _fheapchk x _fheapmin x ----------------------------------- ----------------------------------Name CExe ANSI MS-C -------------------+----+----+----_fheapset x _fheapwalk x _fjstradv x _fjstrchr x _fjstrcmp x _fjstrcspn x _fjstricmp x _fjstrlen x _fjstrlwr x _fjstrmatch x _fjstrncat x _fjstrncmp x _fjstrncpy x _fjstrnicmp x _fjstrnset x _fjstrrchr x _fjstrrev x _fjstrset x _fjstrskip x _fjstrspn x _fjstrstr x _fjstrtok x _fjstrupr x _fmalloc MAC x _fmemccpy x _fmemchr MAC x _fmemcmp MAC x _fmemcpy MAC x _fmemicmp MAC x _fmemmove MAC x _fmemset MAC x _fmsize MAC x _fmtob x _fnthctype x _fpreset x _frealloc MAC x _freect x _fsopen x _fstrcat MAC x ----------------------------------- ----------------------------------Name CExe ANSI MS-C -------------------+----+----+----_fstrchr MAC x _fstrcmp MAC x _fstrcpy MAC x _fstrcspn MAC x _fstrdup x _fstricmp MAC x _fstrlen MAC x _fstrlwr MAC x _fstrncat MAC x _fstrncmp MAC x _fstrncpy MAC x _fstrnicmp MAC x _fstrnset MAC x _fstrpbrk MAC x _fstrrchr MAC x _fstrrev MAC x _fstrset MAC x _fstrspn MAC x _fstrstr MAC x _fstrtok MAC x _fstrupr MAC x _fullpath x _getdcwd x _getdrive MAC x _harderr x _hardresume x _hardretn x _heapadd x _heapchk x _heapmin x _heapset x _heapwalk x _j0l x _j1l x _jnl x _lrotl MAC x _lrotr MAC x _makepath x _matherrl x _memavl x _memmax x _msize MAC x _ncalloc x _nexpand x _nfree x _nheapchk x _nheapmin x _nheapset x _nheapwalk x _nmalloc x ----------------------------------- ----------------------------------Name CExe ANSI MS-C -------------------+----+----+----_nmsize x _nrealloc x _nstrdup x _pclose x _pipe x _popen x _rotl MAC x _rotr MAC x _searchenv x _spilitpath x _status87 x _strdate x _strerror x _strtime x _strtold x _tolower MAC x _toupper MAC x _y0l x _y1l x _ynl x access x acosl x alloca MAC x asinl x atanl x atan2l x bdos x btom MAC x cabs MAC x cabsl x ceill x cgets x chdir MAC x chkctype MAC x chmod x chsize x close MAC x coshl x cosl x cprintf x cputs x creat MAC x cscanf x cwait x dieeetomsbin x dmsbintoieee x dosexterr x dup x dup2 x ecvt MAC x ----------------------------------- ----------------------------------Name CExe ANSI MS-C -------------------+----+----+----eof MAC x execl x execle x execlp x execlpe x execv x execve x execvp x execvpe x expl x fabsl x fcloseall x fcvt MAC x fdopen x fgetchar x fieeetomsbin x filelength x fileno x floorl x flushall x fmodl x fmsbintoieee x fputchar x frexpl x fstat x ftime x gcvt MAC x getch M x getche x getcwd MAC x getpid x getw x halloc x hantozen MAC x hfree x hypot MAC x hypotl x inp x inpw x int86 x int86x x intdos x intdosx x isalkana MAC x isalnmkana MAC x isascii MAC x isatty x iscsym x iscsymf x isgrkana MAC x ----------------------------------- ----------------------------------Name CExe ANSI MS-C -------------------+----+----+----iskana MAC x iskanji MAC x iskanji2 MAC x iskmoji MAC x iskpun MAC x ispnkana MAC x isprkana MAC x itoa MAC x j0 x j1 x jisalpha MAC x jisdigit MAC x jishira MAC x jiskata MAC x jiskigou MAC x jisl0 MAC x jisl1 MAC x jisl2 MAC x jislower MAC x jisprint MAC x jisspace MAC x jistojms MAC x jisupper MAC x jiszen MAC x jmstojis MAC x jn x jstradv x jstrchr x jstrcmp x jstrcspn x jstricmp x jstrlen x jstrlwr x jstrmatch x jstrncat x jstrncmp x jstrncpy x jstrnicmp x jstrnset x jstrrchr x jstrrev x jstrset x jstrskip x jstrspn x jstrstr x jstrtok x jstrupr x jtohira MAC x jtokata MAC x jtolower MAC x ----------------------------------- ----------------------------------Name CExe ANSI MS-C -------------------+----+----+----jtoupper MAC x kbhit M x ldexpl x lfind x locking x logl x log10l x lsearch x lseek MAC x ltoa MAC x matherr x max x memccpy x memicmp MAC x min x mkdir MAC x mktemp x modfl x movedata x mtob MAC x nthctype MAC x onexit (atexit) x open MAC x outp x outpw x powl x putch x putenv x putw x read MAC x rmdir MAC x rmtmp x segread x setmode x sinhl x sinl x sopen x spawnl x spawnle x spawnlp x ----------------------------------- ----------------------------------Name CExe ANSI MS-C -------------------+----+----+----spawnlpe x spawnv x spawnve x spawnvp x spawnvpe x sqrtl x stackavail MAC x stat x strcmpi MAC x strdup x stricmp MAC x strlwr MAC x strnicmp MAC x strnset MAC x strrev MAC x strset MAC x strupr MAC x swab MAC x tanl x tanhl x tell MAC x tempnam x toascii MAC x tzset x u_strtoldltoa x ultoa MAC x umask x ungetch x unlink x utime x wait x write MAC x y0 x y1 x yn x zentohan MAC x ----------------------------------- 1.3 Graphic library (1) MS-C compatible graphic functions Compatible functions with a part of graphic library of Microsoft C Compiler (MS-C Ver 6.0). --------------------------------------------------------------------------Name CExe Function ---------------------+----+-----------------------------------------------_arc M Draw an arc or an elliptic arc. _clearscreen M Clear screen. _ellipse M Draw a circle or an ellipse. _floodfill M Paint the closed region. _getactivepage M Get the current active page number. _getarcinfo M Get the information of the previous arc or pie. _getbkcolor M Get the current back ground color. _getcolor M Get the current fore ground color. _getcurrentposition M Get the current position in the view coordinate. _getfillmask M Get the current fill mask pattern. _getfontinfo M Get the current font information. _getgtextextent M Get the text extent by pixel unit. _getgtextvector M Get the output vector of text. _getimage M Get screen image. _getkanji M Get the font pattern of Kanji character. _getlinestyle M Get the current line style. _getphyscoord M Convert view coordinate into physical. _getpixel M Get color number the pixel. _gettextposition M Get the current output position of text. _gettextwindow M Get the text window border. _getvideoconfig M Get the graphic configuration. _getviewcoord M Convert physical coordinate into view. _getvisualpage M Get the current visual page number. _getwritemode M Get the current writing mode. _grstatus M Get the return status of graphic function. _imagesize M Get image buffer size. _kanjisize M Get font pattern size of Kanji character. _lineto M Draw a line. _moveto M Move the current graphic output position. _outgtext M Draw a text string using the current font. _outmem M Draw a text string in a memory. _outtext M Output a text string in the current position. _pie M Draw a pie figure. _polygon M Draw a polygon. _putimage M Put image data on the screen. _rectangle M Draw a rectangle. _registerfonts M Register font file. _remapallpalette M Map colors into all color palette. _remappalette M Map a color into a color palette. _setactivepage M Set the current active page number. _setbkcolor M Set the current back ground color. _setcliprgn M Set the clipping region. _setcolor M Set the current fore ground color. _setfillmask M Set the current fill mask pattern. _setfont M Set the current font. --------------------------------------------------------------------------Name CExe Function ---------------------+----+-----------------------------------------------_setgtextvector M Set the current output vector of text. _setlinestyle M Set the current line style. _setpixel M Draw a pixel. _settextposition M Set the current output position of text. _settextrows M Set the text row number. _settextwindow M Set the text window. _setvideomode M Set the screen video mode. _setvideomoderows M Set the screen video mode and text row number. _setvieworg M Set the origin of the view port. _setviewport M Set the clipping region and the view coordinate. _setvisualpage M Set the current visual page number. _setwritemode M Set the current writing mode. _unregisterfonts M Delete registered font file. _wrapon M Enable/disable line wrapping. --------------------------------------------------------------------------- (2) C Executor original graphic functions These are graphic drawing functions specific to the C Executer. --------------------------------------------------------------------------Name CExe Function ---------------------+----+-----------------------------------------------gr_displaychar M Draw a standard size character. gr_displayfourlarge M Draw a quad size character. gr_displaysixlarge M Draw a hex size character. _putpattern M Put monochrome image data. _getpattern M Get monochrome image data. gr_dispstr M Draw a standard size string. gr_disp6str M Draw a hex size string. gr_bitblt M Copy image data. gr_disp4str M Draw a quad size string. gr_displaysmlchar M Draw a small size character. gr_dispsstr M Draw a small size string. gr_displayfchar M Draw a FANUC character. gr_dispfstr M Draw a FANUC character string. gr_disp9ifchar M Draw 9-inch font character. gr_disp9ifstr M Draw 9-inch font character string. mmc_line_b M Draw a line between specified two points. mmc_polyline M Draw a polyline. mmc_circle_b M Draw a circle. mmc_ellipse_b M Draw an ellipse. mmc_pie_b M Draw a pie figure. mmc_arc_b M Draw an arc. mmc_gettext M Get character in the specified area. mmc_puttext M Put character data on memory to text screen. mmc_textsize M Get required byte size for getting character. --------------------------------------------------------------------------- 1.4 CNC/PMC window library Functions whish are used to input/output data between CNC/PMC. (1) CNC window library --------------------------------------------------------------------------Name CExe Function ---------------------+----+-----------------------------------------------cnc_sysinfo MA Read CNC system information. cnc_dwnstart MA Start output of NC program to be registered. cnc_download MA Output NC program to be registered. cnc_dwnend MA Stop output NC program to be registered. cnc_vrfstart MA Start output NC program to be compared. cnc_verify MA Output NC program to be compared. cnc_vrfend MA Stop output NC program to be compared. cnc_dncstart MA Start output NC program to be executed. cnc_dnc MA Output NC program to be executed. cnc_dncend MA Stop output NC program to be executed. cnc_upstart MA Start input NC program. cnc_upload MA Input NC program. cnc_upend MA Stop input NC program. cnc_search MA Search specified program. cnc_delall MA Delete all programs. cnc_delete MA Delete specified program. cnc_rdprogdir MA Read program directory. cnc_rdproginfo MA Read program information. cnc_rdprgnum MA Read program number in executing. cnc_rdseqnum MA Read sequence number in executing. cnc_actf MA Read actual feed rate of controlled axes. cnc_acts MA Read actual spindle speed. cnc_absolute MA Read absolute position. cnc_machine MA Read machine position. cnc_relative MA Read relative position. cnc_distance MA Read distance to go. cnc_skip MA Read skipped position. cnc_srvdelay MA Read servo delay amount. cnc_accdecdly MA Read acceleration/deceleration delay amount. cnc_rddynamic MA Read dynamic data. cnc_statinfo MA Read CNC status information. cnc_alarm MA Read alarm status. cnc_rdalminfo MA Read alarm information. cnc_rdtofs MA Read tool offset amount. cnc_wrtofs MA Write tool offset amount. cnc_rdtofsr MA Read tool offset amount (range specified). cnc_wrtofsr MA Write tool offset amount (range specified). cnc_rdzofs MA Read work origin offset. cnc_wrzofs MA Write work origin offset. cnc_rdzofsr MA Read work origin offset (range specified). --------------------------------------------------------------------------Name CExe Function ---------------------+----+-----------------------------------------------cnc_wrzofsr MA Write work origin offset (range specified). cnc_rdparam MA Read parameter. cnc_wrparam MA Write parameter. cnc_rdparar MA Read parameters (range specified). cnc_wrparas MA Write parameters (multiple output). cnc_rdset MA Read setting parameter. cnc_wrset MA Write setting parameter. cnc_rdsetr MA Read setting parameters (range specified). cnc_wrsets MA Write setting parameters (multiple output). cnc_rdpitchr MA Read pitch error compensation data (range specified). cnc_wrpitchr MA Write pitch error compensation data (range specified). cnc_rdmacro MA Read custom macro variable. cnc_wrmacro MA Write custom macro variable. cnc_rdmacror MA Read custom macro variables (range specified). cnc_wrmacror MA Write custom macro variables (range specified). cnc_rdpmacro MA Read P-code macro variable. cnc_wrpmacro MA Write P-code macro variable. cnc_rdpmacror MA Read P-code macro variables (range specified). cnc_wrpmacror MA Write P-code macro variables (range specified). cnc_modal MA Read modal data. cnc_diagnoss MA Read diagnostics data. cnc_diagnosr MA Read diagnostics data (range specified). cnc_adcnv MA Read A/D conversion data. cnc_rdopmsg MA Read operator's message. cnc_setpath MA Set path index (multi-path system). cnc_getpath MA Get path index (multi-path system). --------------------------------------------------------------------------Name CExe Function ---------------------+----+-----------------------------------------------cnc_settime MA Set calendar timer of CNC. cnc_rdspload MA Read load information of serial spindle. cnc_rdexecprog MA Read executing program. cnc_rdmovrlap MA Read manual handle override amount. --------------------------------------------------------------------------- (2) PMC window library --------------------------------------------------------------------------Name CExe Function ---------------------+----+-----------------------------------------------pmc_rdpmcrng MA Read arbitrary PMC data (range specified). pmc_wrpmcrng MA Write arbitrary PMC data (range specified). pmc_rdpcmsg MA Read PMC message. --------------------------------------------------------------------------- 1.5 Other libraries (1) MDI operation library These are the functions which customize key-input from MDI panel, alter key code, enable key repeating and generate key code by the application program. --------------------------------------------------------------------------Name CExe Function ---------------------+----+-----------------------------------------------aux_mdi_getmatrix MA Get MDI key matrix. aux_mdi_putmatrix MA Put MDI key matrix. aux_mdi_rstmatrix MA Reset MDI key matrix. aux_mdi_altmatrix MA Alter MDI key matrix. aux_mdi_putc MA Put one character to key input buffer. aux_mdi_write MA Write block data to key input buffer. aux_mdi_control MA Test or control key input buffer. aux_mdi_repeat MA Set key repeating interval time. aux_mdi_getstat MA Read inputting status of MDI key. aux_mdi_clrbuf MA Clear input buffer of MDI key. --------------------------------------------------------------------------- (2) CRT operation library These are the functions which control CRT display and multiple window display. --------------------------------------------------------------------------Name CExe Function ---------------------+----+-----------------------------------------------crt_getcurscrn MA Get current screen index. crt_setuserscrn M Register user screen index. crt_isnewscrn MA Test screen switching status. crt_gettype MA Get CRT information. crt_setmode MA Set CRT screen mode. crt_cncscrn MA Switch to CNC screen. crt_fchar M Output character by FANUC character code. crt_setuserskey M Customize softkey on CNC screen. crt_setswt MA Set switching method between CNC's screen and user's. crt_setscrlarea M Set scroll area. crt_opengr M Open graphic display. crt_closegr M Close graphic display. crt_graphic MA Enable or disable graphic display. crt_readfkey MA Read the status of function keys. crt_2ndcursor M Display the secondary cursor. crt_settextattr M Set attribute of characters on VRAM. crt_gettextattr M Get attribute of character on VRAM. crt_setpalette M Set color palette of VGA characters. crt_setallpalette M Set all color palette of VGA characters. crt_getcncpalette M Get color palette of CNC screen. crt_fstr M Output character string by FANUC character code. crt_gettextimg M Get text data from VRAM. crt_puttextimg M Put text data into VRAM. crt_setgraphpage M Select graphic page to use. crt_set6chmode M Select drawing method of 6x sized character. crt_setgsvmode M Select saving method of graphic contents. win_open M Open window. win_close M Close window. win_select M Select window. win_activate M Activate window. win_move M Move window. win_size M Alter window size. win_full M Let active window be full screen size. win_window M Let active window be window size. win_info M Get window information. win_col M Set color of window frame and title string. win_hide M Hide window. win_show M Show window. win_setttl M Set window title string. win_setfrm M Set window frame line character. win_getstat M Get window display status. win_redraw M Redraw windows. crt_reguserchar M Register user character. crt_mapuch M Map user character. crt_getcgpttn M Get CG pattern. vwin_open M Open VGA window. vwin_close M Close VGA window. vwin_select M Select VGA window. --------------------------------------------------------------------------Name CExe Function ---------------------+----+-----------------------------------------------vwin_show M Show VGA window. vwin_hide M Hide VGA window. vwin_info M Get VGA window information. --------------------------------------------------------------------------- (3) File operation library These are the functions which maintain file device. --------------------------------------------------------------------------Name CExe Function ---------------------+----+-----------------------------------------------aux_file_format M Format specified drive. aux_file_mount MAC Mount memory card. aux_file_unmount MAC Unmount memory card. aux_file_memcinfo MAC Get memory card information. --------------------------------------------------------------------------- (4) Serial communication library These are the functions which communicate with peripherals via reader/ puncher interface(RS-232C). --------------------------------------------------------------------------Name CExe Function ---------------------+----+-----------------------------------------------rs_open MAC Initialize communication device. rs_close MAC Terminate communication. rs_putc MAC Put one character to communication buffer. rs_getc MAC Get one character from communication buffer. rs_write MAC Write block data to communication buffer. rs_read MAC Read block data from communication buffer. rs_buffer MAC Test or control communication buffer. rs_status MAC Get status of communication line and buffer. rs_wait MAC Wait communication event. --------------------------------------------------------------------------- (5) Task control library These are the functions which control task execution. --------------------------------------------------------------------------Name CExe Function ---------------------+----+-----------------------------------------------os_show_tim MAC Read timer. os_set_tim MAC Set timer. os_sync_tim MAC Wait until specified time. os_wait_tim MAC Wait until specified term. os_make_flg MAC Make event flag. os_delt_flg MAC Delete event flag. os_sign_flg MAC Signal event flag. os_wait_flg MAC Wait event flag signal. os_clar_flg MAC Clear event flag. os_puls_flg MAC Signal event flag. (pulse type) os_make_sem MAC Make counter-type semaphore. os_delt_sem MAC Delete semaphore. os_sign_sem MAC Signal semaphore. os_wait_sem MAC Wait semaphore signal. os_strt_wtsk M Start window task. --------------------------------------------------------------------------- (6) FCA library These are the functions which communicate with FCA (FANUC CASSETTE ADAPTOR) or FANUC Handy File. --------------------------------------------------------------------------Name CExe Function ---------------------+----+-----------------------------------------------fca_setparam MAC Initialize communication line. fca_bye MAC Close communication line. fca_open MAC Open a binary file on FCA device. fca_close MAC Close a binary file. fca_read MAC Read binary data from the file. fca_write MAC Write binary data to the file. fca_fopen MAC Open a text file on FCA device. fca_fclose MAC Close a text device. fca_getc MAC Read a character from the text file. fca_putc MAC Write a character to the text file. fca_delete MAC Delete a file on FCA device. fca_rename MAC Change name of a file on FCA device. fca_readdir MAC Read directory information of FCA device. fca_status MAC Read status information of FCA device. fca_remains MAC Read free space size of a floppy disk. --------------------------------------------------------------------------- (7) F-ROM library These are the functions which read C Executor data stored in the flash ROM module. --------------------------------------------------------------------------Name CExe Function ---------------------+----+-----------------------------------------------aux_from_open MAC Open the specified F-ROM file. aux_from_close MAC Close the F-ROM file. aux_from_select MAC Select data in the F-ROM file. aux_from_moveptr MAC Move read pointer. aux_from_read MAC Read data from the F-ROM file. aux_from_getdir MAC Read directory information of a F-ROM file. aux_from_getinfo MAC Read F-ROM file information. aux_from_getc MAC Read a character from the F-ROM file. aux_from_gets MAC Read a line from the F-ROM file. --------------------------------------------------------------------------- (8) Touch-panel library This is the function which reads the status and (X,Y) coordinate of the touch-panel. --------------------------------------------------------------------------Name CExe Function ---------------------+----+-----------------------------------------------aux_tpl_read MAC Read the status and (X,Y) coordinate of the touch-panel. --------------------------------------------------------------------------- Japanese(Multi-byte character) functions ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Jananese character/string functions (Multi-byte character functions) included in "MS-C extended C standard library" are not available for Series 30i C Executor. Functions not available on FANUC Series 30i (FS30i) C Executor ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ The following functions are available on FS16i/18i C Executor, but not available on FS30i C Executor because of different system configurations and hardware. It is, however, possible to call these functions to create applications. This is intended to maintain compatibility with applications developed for FS16. With the FS30i, when these functions are called, they return a normal end code without processing anything. The values they return are undefined. When using these functions, be sure to bear what is described above in mind. If you find any problem with your application in regard to the functions, modify the application. Libraries for 2-path system crt_getcurscrn2() : Get current screen index. (for 2-path system) crt_setuserscrn2() : Register user screen index. (for 2-path system) crt_setuserskey2() : Customize softkey on CNC screen. (for 2-path system) Task management library os_chng_duty() : set CPU time ratio between user task and CNC task os_chng_wdty() : Change CPU time of window task os_new_mem() : Allocate new memory block os_disp_mem() : Deallocate memory block MS-C extended C standard library _clear87() : Get and clear the floating point status word. _control87() : Get and set the floating point status word. _status87() : Get the floating point status word. Super CAP M window library capm_rdtool() : Read tool data file. capm_wrtool() : Write tool data file. capm_rdpretool() : Read pre-tool list. capm_wrpretool() : Write pre-tool list. capm_rdmcncond() : Read machining condition file. capm_wrmcncond() : Write machining condition file. capm_rddef() : Read default data file. capm_wrdef() : Write default data file. capm_closebge() : Terminate back ground editing. crt_capmaccess() : Set accessing method to Super CAP M. crt_capmscrn() : Switch to Super CAP M screen. CNC window library cnc_windowma() : Call CNC window. CNC window library for punch-press cnc_rd1punchtl() : Read punch-press tool data. (by registration number) cnc_rd2punchtl() : Read punch-press tool data. (by tool number) cnc_wrpunchtl() : Write punch-press tool data. Serial Library rs_dma() : Select DMA transmission channel. 2. How to make application program ================================== Table of contents 2.1 2.2 2.3 2.4 2.5 2.6 2.7 2.8 Outline Special files MAKEFILE Installing the Diab C/C++ Power-PC compiler Compatibility related to variables of type 'int' Using compiler libraries Describing 2-byte characters in source-codes Remarks 2.1 Outline In this documentation we assume that the "C Executor library disk" has been installed in the directory C:\APP. The application program is made by the following procedures. (1) Make the working directory. (2) Copy \APP\TOOL\MAKEFILE, \APP\TOOL\VERSION.C into the working directory. (3) Edit the source files. (4) Modify MAKEFILE to fit to user application. (5) Modify user application's version number in VERSION.C. (6) Execute NMAKE. (1) Making the working directory. Usually, the working directory is made in the directory( C:\APP ) in which the C library has been installed. We assume that the working directory name is PROG1. C:\> md c:\app\prog1 (2) Copying specific files. Copy the necessary files at a minimum from TOOL directory to the working directory. C:\> cd c:\app\prog1 C:\APP\PROG1> copy ..\tool\makefile C:\APP\PROG1> copy ..\tool\version.c (3) Editing the source files. Make the source files ( *.c and *.h files ) of the application program in the working directory. Use an arbitrary text editor to edit the files. You may name the file as you like. Here, we assume that the following source files are made. Main task Alarm task Communication task Common header file main.c sub1.c sub2.c alarm.c alm_sub.c comm.c prog1.h (4) Modifying MAKEFILE to fit to user application. Modify the following parts of makefile. * The top part of makefile #-----------------------------------------------------------------------------# Task definition block. Modify here for your application. #-----------------------------------------------------------------------------TASK1 = TASK2 = TASK3 = TASK4 = TASK5 = <- list of the object filenames task. <- list of the object filenames Communication task. <- list of the object filenames task. <- list of the object filenames task. <- list of the object filenames task. which constitute the Main which constitute the which constitute the Alarm which constitute the Window which constitute the High-Level * The bottom of makefile #-----------------------------------------------------------------------------# .O and .C dependency block. #-----------------------------------------------------------------------------<- relationship of dependence between files. #-----------------------------------------------------------------------------# End of .O and .C dependency block. #-----------------------------------------------------------------------------In this case, modify makefile as follows. #-----------------------------------------------------------------------------# Task definition block. Modify here for your application. #-----------------------------------------------------------------------------TASK1 TASK2 TASK3 TASK4 TASK5 = main.o sub1.o sub2.o = comm.o = alarm.o alm_sub.o = = #-----------------------------------------------------------------------------# .O and .C dependency block. #-----------------------------------------------------------------------------main.o : sub1.o : sub2.o : comm.o : alarm.o : alarm.o : main.c prog1.h sub1.c prog1.h sub2.c prog1.h comm.c prog1.h alarm.c prog1.h alm_sub.c prog1.h #-----------------------------------------------------------------------------# End of .O and .C dependency block. #-----------------------------------------------------------------------------(5) Modifying user application's version number in VERSION.C. Modify the following definition sentence in version.c. char version[] = "TEST0001" ; Here, we assume that the application version number is "PROG-A001". char version[] = "PROGA001" ; (6) Executing NMAKE. Change the working directory as the current directory, then execute nmake command. C:\APP\PROG1> nmake When any compile error or link error occurs, modify the source file and execute nmake again. The memory card file "cexec.mem", which will be stored in the CNC unit, will be generated by completing execution of nmake. Copy this file into the memory card, and write the application program into F-ROM of the CNC unit according to the operating procedure of the CNC's boot software. 2.2 Special files The following files are special files, whose usage is reserved. VERSION.C : Definition file of the user application's version number. (must be required) The user application's version number is defined in this file. For example, version number definition is as follows. char version[] = "TEST0001" ; "TEST" is the series string and "0001" is edition number. You can replace them with your original version number. There are no particular naming rules of version number. You can define them arbitrarily. However, limited characters (such as uppercase and numeric character, some marks) are available in the version string. The version string which is defined in this file is displayed in SYSTEM screen of CNC. DRAMVER.C : Definition file of common variables between tasks. (optional) Define the variables which can be accessed from all tasks. Be sure to define only the variables, but not the functions. SRAMVER.C : Definition file of SRAM variables. (optional) Define the variables which should be allocated into SRAM (static memory) area. The variables defined in this file also can be accessed from all tasks. Be sure to define only the variables, but not the functions. SRAM variables must have the initial values. The initial values are necessary to allocate the variables into SRAM area and not effective in the execution time of the application. 2.3 MAKEFILE Modify two blocks in MAKEFILE. (1) Task definition block #-----------------------------------------------------------------------------# Task definition block. Modify here for your application. #-----------------------------------------------------------------------------TASK1 TASK2 TASK3 TASK4 TASK5 = = = = = #-----------------------------------------------------------------------------# End of task definition block #-----------------------------------------------------------------------------Define the macro TASK to specify the object files which compose the task. In case of the task 1 consists of S1.C and S2.C, define it as follows. TASK1 = s1.o s2.o You can split the long line by '\'. TASK1 = s1.o s2.o \ s3.o For the single task application, you should only define the macro TASK1. TASK1 TASK2 TASK3 TASK4 TASK5 = s1.o s2.o = = = = For the multi-task application, define the macro for all the tasks involved. TASK1 TASK2 TASK3 TASK4 TASK5 = s1.o s2.o = x.o = y1.o y2.o y3.o = = (2) Dependency block #-----------------------------------------------------------------------------# .O and .C dependency block. #-----------------------------------------------------------------------------#-----------------------------------------------------------------------------# End of .O and .C dependency block. #-----------------------------------------------------------------------------The relations between the object file, the source file and the include file are described here. If S1.C includes ABC.H, and S2.C includes DEF.H, describe them as follows. #-----------------------------------------------------------------------------# .O and .C dependency block. #-----------------------------------------------------------------------------s1.o : s1.c abc.h s2.o : s2.c def.h #-----------------------------------------------------------------------------# End of .O and .C dependency block. #------------------------------------------------------------------------------ 2.4 Installing the Diab C/C++ Power-PC compiler How to install the Diab C/C++ Power-PC compiler is described below by taking its version 4.3f as an example. Refer to the applicable compiler reference manual for detailed descriptions about individual items. Inserting the Diab C/C++ Power-PC compiler CD into your PC automatically starts the installer. If the installer fails to start, open the CD folder and click SETUP.EXE in the folder to start it. 1) DIAB Installation Directory Specify a folder in which you want to install the compiler. Any folder can be specified. 2) Installation Options Check all the following check boxes. - Install DIAB Compiler Suites - Set Compiler Defaults - Set Eval Key or License File Location 3) Tools Selection Specify the type of the compiler you are going to install. Check the C Compiler (D-CC) check box. Do not use C++ Compiler, RTA Tools, FastJ Compiler, or Library Source. 4) Target Architectures Select the following target system. Target : PowerPC Components : ELF (EABI) 5) Select program folder Select a program folder that can be specified from the Windows Start menu. Any folder can be specified. 6) License Key Option Selection Select a license key entry method specified when you purchased the compiler. Select: "I have an eval key and I will enter it now." (Note: The entry method may vary depending on the license form. For details, ask the store from which you bought your compiler.) 7) Enter eval key Enter your license key. 8) File Selection Specify a file to which you want to save the license key. 9) Select option for modify .bat file Set up environment variables. Select the following: "Let Setup modify the C:\Autoexec.bat file" 10) PowerPC Select PPC603. 11) PPC603 Select "Hardware Floating Point." 12) ELF(EABI) Select "cross." Note) You may need to set up License Manager (FLEXlm License Manager) depending on the license form. For details, ask the store from which you bought your compiler. 2.5 Compatibility related to variables of type 'int' For the compiler used with the FS30i C Executor, variables of type 'int' are 4-bytes long, while, for the compiler used with the FS16i/18i C Executor, they are 2-bytes long. This difference in size may result in loss of compatibility. The first part of some structures specified in CNC/PMC window functions contains dummy variables of type 'int'. This does not impair compatibility when the structures are used for data input/output. If a data area secured using, for example, the malloc function is used for data input/output, however, the data area may not function normally when its beginning part is offset based on 2-byte conversion. Compatibility can be secured by a 'sizeof(int)' operator instead of 2-byte conversion. 2.6 Using compiler libraries The following functions use the library supplied together with the compiler. To use these functions, add the library to the LD.OPT file in the TOOL folder in your development environment. 1) Functions that use the library supplied together with the compiler setjmp, longjmp va_start, va_arg, va_end vprintf, vprintf, vsprintf 2) Adding library path to LD.OPT <LD.OPT> -m2 -lc <-- Add this line. 2.7 Describing 2-byte characters in source-codes The Diab C/C++ Power-PC compiler does not support Japanese language. If a 2-byte character whose second byte happens to be 5Ch is included directly in a source file, it is not recognized as correct data. 2.8 Remarks C Executor uses the different include files from the compiler's default. So, the object files made for the personal computer debugging cannot be used for execution on CNC. Recompile using include files for C Executor. (The include directory is switched by the macro CC in MAKEFILE) Do not change MAKEFILE except the place mentioned above. When creating application programs, observe the following cautions: 1) Do not perform division by zero. 2) When using data of type float or double, do not perform an arithmetic operation on that data with NaN (nonnumeric) held. 3) Before converting data from type float or double to an integral type, make sure that the resulting data will not fall outside the valid data range of the target integral type. 4) The following restrictions are imposed on the alignment of variables to be placed. One-byte variable : No restriction Two-byte variable : The least significant digit of the address must be 0, 2, 4, 8, a, c, or e. Four-byte variable : The least significant digit of the address must be 0, 4, 8, or c. Eight-byte variable : The least significant digit of the address must be 0 or 8. [**WARNING**] If an application program performs one of the following operations, the CNC may behave in an unexpected manner. - Access to data in an area other than the application data area. - Execution of a program other than an application program (except call the function that the C Executor offers it) 3. Function References ====================== The function specifications that C library provides with are described in this function reference with following format. [Example] > ---------------------------------------------------------------------------> 1. Format specified drive. <Main> > ---------------------------------------------------------------------------> > > [Name] > aux_file_format > > > [Syntax] > #include <auxfile.h> > int aux_file_format( unsigned char drive ) ; > > > [Arguments] > drive Drive name ( ='A' ). > > > [Return] > 0 Successfully. > 9 Invalid drive name. > > > [Description] > Formats specified drive. > > Specify drive name to be formatted in "drive". For formatting S-RAM > disk, execute as follows. > > aux_file_format( 'A' ) ; > > All files in specified drive will be deleted by execution of this > function. > > Automatic initialization of S-RAM disk is done by setting CNC > parameter No.8662, S-RAM capacity setting, and rebooting system. "<Main>" after title shows that this function is available in the MAIN task, not available in the Communication task and the Alarm task. If "<Main,Alarm, Comm>" is in this section, this function is available in all tasks. "[Name]" shows the name of this function. "[Syntax]" shows required header files to use this function, type of return value of this function and sequence and types of all arguments. "[Arguments]" shows meanings of all arguments. "[Return]" shows all possible return values and their types and meanings. "[Description]" shows behavior of this function, concrete values to be specified in arguments and some notices, etc. 3.1 ANSI C standard library =========================== Lists of Functions ~~~~~~~~~~~~~~~~~~ 1. Diagnostics ( assert.h ) -------------------------------------------------------------------------Name Function -------------------------------------------------------------------------1.1 assert Abort by assertion. -------------------------------------------------------------------------- 2. Character handling ( ctype.h ) -------------------------------------------------------------------------Name Function -------------------------------------------------------------------------2.1 isalnum Test for alphanumeric character. 2.2 isalpha Test for alphabetic character. 2.3 iscntrl Test for control character. 2.4 isdigit Test for numeric character. 2.5 isgraph Test for visible character. 2.6 islower Test for lowercase alphabetic character. 2.7 isprint Test for printable character. 2.8 ispunct Test for punctuation character. 2.9 isspace Test for whitespace character. 2.10 isupper Test for uppercase alphabetic character. 2.11 isxdigit Test for hexadecimal numeric character. 2.12 tolower Convert uppercase to lowercase. 2.13 toupper Convert lowercase to uppercase. -------------------------------------------------------------------------- 3. Mathematics ( math.h ) -------------------------------------------------------------------------Name Function -------------------------------------------------------------------------3.1 acos Calculate the arc cosine value. 3.2 asin Calculate the arc sine value. 3.3 atan Calculate the arc tangent value. 3.4 atan2 Calculate the arc tangent value. 3.5 ceil Calculate the smallest integer value. 3.6 cos Calculate the cosine value. 3.7 cosh Calculate the hyperbolic cosine value. 3.8 exp Calculate the exponential function. 3.9 fabs Calculate the absolute value. 3.10 floor Calculate the largest integer value. 3.11 fmod Calculate the floating point remainder value. 3.12 frexp Calculate the mantissa value. 3.13 ldexp Calculate the value multiplied by the power of 2. 3.14 log Calculate the natural (base-e) logarithm value. 3.15 log10 Calculate the base-10 logarithm value. 3.16 modf Get the fractional part and the integer part. 3.17 pow Calculate the raised value. 3.18 sin Calculate the sine value. 3.19 sinh Calculate the hyperbolic sine value. 3.20 sqrt Calculate the square root value. 3.21 tan Calculate the tangent value. 3.22 tanh Calculate the hyperbolic tangent value. -------------------------------------------------------------------------- 4. Non-local jumps ( setjmp.h ) -------------------------------------------------------------------------Name Function -------------------------------------------------------------------------4.1 setjmp Save current environment for non-local jump. 4.2 longjmp Execute a non-local jump. -------------------------------------------------------------------------- 5. Variable arguments ( stdarg.h ) -------------------------------------------------------------------------Name Function -------------------------------------------------------------------------5.1 va_start Initialize arg_ptr. 5.2 va_arg Get a next argument. 5.3 va_end Reset arg_ptr. -------------------------------------------------------------------------- 6. Input/output ( stdio.h ) -------------------------------------------------------------------------Name Function -------------------------------------------------------------------------6.1 remove Delete a file. 6.2 rename Change the name of a file. 6.3 tmpnam Generate a temporary file name. 6.4 fclose Close a stream. 6.5 fflush Flush a stream buffer. 6.6 fopen Open a stream. 6.7 freopen Re-open a same stream. 6.8 setbuf Set a buffer for stream. 6.9 setvbuf Control a buffer for stream. 6.10 fprintf Print formatted data to a stream. 6.11 fscanf Read formatted data from a stream. 6.12 printf Print formatted data to standard output. 6.13 scanf Read formatted data from standard input. 6.14 sprintf Print formatted data to memory. 6.15 sscanf Read formatted data from memory. 6.16 vfprintf Print formatted data to a file using variable arguments. 6.17 vprintf Print formatted data to standard output using variable arguments. 6.18 vsprintf Print formatted data to memory using variable arguments. 6.19 fgetc Read a character from a stream. 6.20 fgets Read a strings from a stream. 6.21 fputc Write a character to a stream. 6.22 fputs Write a string to a stream. 6.23 getc Read a character from a stream. 6.24 getchar Read a character from standard input. 6.25 gets Read a line string from standard input. 6.26 putc Write a character to a stream. 6.27 putchar Write a character to standard output. 6.28 puts Write a string to standard output. 6.29 ungetc Put a character into a steam. 6.30 fread Read data from a stream. 6.31 fwrite Write data to a stream. 6.32 fgetpos Get the current file position of a stream. 6.33 fseek Move the current file pointer. 6.34 fsetpos Set the current file position of stream. 6.35 ftell Get the current file pointer. 6.36 rewind Rewind the current file pointer to the top of file. 6.37 clearerr Reset error indicator of a stream. 6.38 feof Test for end-of-file. 6.39 ferror Test for error on stream. 6.40 perror Print error message. -------------------------------------------------------------------------- 7. General utilities ( stdlib.h ) -------------------------------------------------------------------------Name Function -------------------------------------------------------------------------7.1 atoi Convert string to int value. 7.2 atol Convert string to long value. 7.3 strtol Convert string to long value. 7.4 strtoul Convert string to unsigned long value. 7.5 rand Generate pseudo-random number. 7.6 srand Seed pseudo-random number generator. 7.7 calloc Allocate memory block initialized by 0. 7.8 free Free memory block. 7.9 malloc Allocate memory block. 7.10 realloc Reallocate memory block. 7.11 bsearch Perform binary search. 7.12 qsort Perform quick sort. 7.13 abs Get absolute value. 7.14 div Get quotient and remainder. 7.15 labs Get absolute value. 7.16 ldiv Get quotient and remainder. 7.17 atof Convert string to double value. 7.18 strtod Convert string to double value. -------------------------------------------------------------------------- 8. String handling ( string.h ) -------------------------------------------------------------------------Name Function -------------------------------------------------------------------------8.1 memcpy Copy a memory block. 8.2 memmove Move a memory block. 8.3 strcpy Copy a string. 8.4 strncpy Copy a string. 8.5 strcat Concatenate a string. 8.6 strncat Concatenate a string. 8.7 memcmp Compare two memory blocks. 8.8 strcmp Compare two strings. 8.9 strncmp Compare two strings. 8.10 memchr Find a character in a memory block. 8.11 strchr Find a character in a string. 8.12 strcspn Get string length which doesn't include a character. 8.13 strpbrk Find a character position in a string. 8.14 strrchr Find the last character in a string. 8.15 strspn Get string length composed by specified character. 8.16 strstr Find a string in a string. 8.17 strtok Get a token. 8.18 memset Fill data in a memory block. 8.19 strlen Get string length. -------------------------------------------------------------------------- 9. Date and time ( time.h ) -------------------------------------------------------------------------Name Function -------------------------------------------------------------------------9.1 clock Get the current time. 9.2 mktime Convert local time to calender time. 9.3 time Get the current time. 9.4 asctime Convert time to string. 9.5 ctime Convert time to string. 9.6 gmtime Convert time to Greenwich mean time. 9.7 localtime Convert time to local time. 9.8 difftime Compute the difference between the two times. -------------------------------------------------------------------------- Function Reference ~~~~~~~~~~~~~~~~~~ Refer ANSI C language regulation for detail function specifications. 1. Diagnostics ( assert.h ) -----------------------------------------------------------------------------1.1 Abort by assertion. <Main> -----------------------------------------------------------------------------[Name] assert [Syntax] #include <assert.h> void assert( int expression ) ; [Arguments] expression Expression to be diagnosed. [Return] -----[Description] "assert" is used to debug programs simply. "assert" displays diagnostic message and stops the program when the value of "expression" is false (i.e. "0"). To stop the program, "while(1);" is execute, the next step is never executed. When "expression" is true (i.e. non-zero), "assert" does nothing. "assert" is defined as MACRO, so, define NDEBUG identifier and recompile to remove it. The diagnostic message is displayed with the following format. "Assertion failed : expression [expression] in file [filename] at line linenum" Only programmer can understand this diagnostic message. It is recommended to do user's own error checking and to display error messages for easy application maintenance. 2. Character handling ( ctype.h ) -----------------------------------------------------------------------------2.1 Test for alphanumeric character. <Main,Alarm,Comm> -----------------------------------------------------------------------------[Name] isalnum [Syntax] #include <ctype.h> int isalnum( int c ) ; [Arguments] c Character code to be tested. [Return] Returns non-zero value if "c" is an alphanumeric character, otherwise zero. [Description] "isalnum" tests whether "c" is an alphanumeric character ('A'-'Z', 'a'-'z','0'-'9') or not. This function works correctly for integer value of ASCII character set. The result is not warranted for other input value. -----------------------------------------------------------------------------2.2 Test for alphabetic character. <Main,Alarm,Comm> -----------------------------------------------------------------------------[Name] isalpha [Syntax] #include <ctype.h> int isalpha( int c ) ; [Arguments] c Character code to be tested. [Return] Returns non-zero value if "c" is an alphabetic character, otherwise zero. [Description] "isalpha" tests whether "c" is an alphabetic character ('A'-'Z', 'a'-'z') or not. This function works correctly for integer value of ASCII character set. The result is not warranted for other input value. -----------------------------------------------------------------------------2.3 Test for control character. <Main,Alarm,Comm> -----------------------------------------------------------------------------[Name] iscntrl [Syntax] #include <ctype.h> int iscntrl( int c ) ; [Arguments] c Character code to be tested. [Return] Returns non-zero value if "c" is a control character, otherwise zero. [Description] "iscntrl" tests whether "c" is a control character (0x00-0x1f,0x7f) or not. This function works correctly for integer value of ASCII character set. The result is not warranted for other input value. -----------------------------------------------------------------------------2.4 Test for numeric character. <Main,Alarm,Comm> -----------------------------------------------------------------------------[Name] isdigit [Syntax] #include <ctype.h> int isdigit( int c ) ; [Arguments] c Character code to be tested. [Return] Returns non-zero value if "c" is a numeric character, otherwise zero. [Description] "isdigit" tests whether "c" is a numeric character ('0'-'9') or not. This function works correctly for integer value of ASCII character set. The result is not warranted for other input value. -----------------------------------------------------------------------------2.5 Test for visible character. <Main,Alarm,Comm> -----------------------------------------------------------------------------[Name] isgraph [Syntax] #include <ctype.h> int isgraph( int c ) ; [Arguments] c Character code to be tested. [Return] Returns non-zero value if "c" is a visible character, otherwise zero. [Description] "isgraph" tests whether "c" is a visible character (0x21-0x7e) or not. This function works correctly for integer value of ASCII character set. The result is not warranted for other input value. -----------------------------------------------------------------------------2.6 Test for lowercase alphabetic character. <Main,Alarm,Comm> -----------------------------------------------------------------------------[Name] islower [Syntax] #include <ctype.h> int islower( int c ) ; [Arguments] c Character code to be tested. [Return] Returns non-zero value if "c" is a lowercase alphabetic character, otherwise zero. [Description] "islower" tests whether "c" is a lowercase alphabetic character ('a'-'z') or not. This function works correctly for integer value of ASCII character set. The result is not warranted for other input value. -----------------------------------------------------------------------------2.7 Test for printable character. <Main,Alarm,Comm> -----------------------------------------------------------------------------[Name] isprint [Syntax] #include <ctype.h> int isprint( int c ) ; [Arguments] c Character code to be tested. [Return] Returns non-zero value if "c" is a printable character, otherwise zero. [Description] "isprint" tests whether "c" is a printable character (0x20-0x7e) or not. This function works correctly for integer value of ASCII character set. The result is not warranted for other input value. -----------------------------------------------------------------------------2.8 Test for punctuation character. <Main,Alarm,Comm> -----------------------------------------------------------------------------[Name] ispunct [Syntax] #include <ctype.h> int ispunct( int c ) ; [Arguments] c Character code to be tested. [Return] Returns non-zero value if "c" is a punctuation character, otherwise zero. [Description] "ispunct" tests whether "c" is a punctuation character (0x21-0x2f, 0x3a-0x40,0x5b-0x60,0x7b-0x7e) or not. This function works correctly for integer value of ASCII character set. The result is not warranted for other input value. -----------------------------------------------------------------------------2.9 Test for whitespace character. <Main,Alarm,Comm> -----------------------------------------------------------------------------[Name] isspace [Syntax] #include <ctype.h> int isspace( int c ) ; [Arguments] c Character code to be tested. [Return] Returns non-zero value if "c" is a whitespace character, otherwise zero. [Description] "isspace" tests whether "c" is a whitespace character (0x09-0x0d, 0x20) or not. This function works correctly for integer value of ASCII character set. The result is not warranted for other input value. -----------------------------------------------------------------------------2.10 Test for uppercase alphabetic character. <Main,Alarm,Comm> -----------------------------------------------------------------------------[Name] isupper [Syntax] #include <ctype.h> int isupper( int c ) ; [Arguments] c Character code to be tested. [Return] Returns non-zero value if "c" is an uppercase alphabetic character, otherwise zero. [Description] "isupper" tests whether "c" is an uppercase alphabetic character ('A'-'Z') or not. This function works correctly for integer value of ASCII character set. The result is not warranted for other input value. -----------------------------------------------------------------------------2.11 Test for hexadecimal numeric character. <Main,Alarm,Comm> -----------------------------------------------------------------------------[Name] isxdigit [Syntax] #include <ctype.h> int isxdigit( int c ) ; [Arguments] c Character code to be tested. [Return] Returns non-zero value if "c" is a hexadecimal character, otherwise zero. [Description] "isxdigit" tests whether "c" is a hexadecimal character ('A'-'Z', 'a'-'f','0'-'9') or not. This function works correctly for integer value of ASCII character set. The result is not warranted for other input value. -----------------------------------------------------------------------------2.12 Convert uppercase to lowercase. <Main,Alarm,Comm> -----------------------------------------------------------------------------[Name] tolower [Syntax] #include <ctype.h> int tolower( int c ) ; [Arguments] c Character code to be converted. [Return] Returns a lowercase alphabetic character if "c" is an uppercase, otherwise "c" as it is. [Description] "tolower" converts "c" to a lowercase alphabetic character if "c" is uppercase. -----------------------------------------------------------------------------2.13 Convert lowercase to uppercase. <Main,Alarm,Comm> -----------------------------------------------------------------------------[Name] toupper [Syntax] #include <ctype.h> int toupper( int c ) ; [Arguments] c Character code to be converted. [Return] Returns an uppercase alphabetic character if "c" is a lowercase, otherwise "c" as it is. [Description] "toupper" converts "c" to an uppercase alphabetic character if "c" is lowercase. 3. Mathematics ( math.h ) -----------------------------------------------------------------------------3.1 Calculate the arc cosine value. <Main,Alarm,Comm> -----------------------------------------------------------------------------[Name] acos [Syntax] #include <math.h> double acos( double x ) ; [Arguments] x A floating point value to be calculated arc cosine. [Return] Returns the arc cosine value (in radian) of "x". If argument is out of valid range, returns 0 and sets EDOM in the global variable "errno". [Description] Calculates the arc cosine value of "x". "x" must be in -1 through 1. The result is in 0 through PI radian. -----------------------------------------------------------------------------3.2 Calculate the arc sine value. <Main,Alarm,Comm> -----------------------------------------------------------------------------[Name] asin [Syntax] #include <math.h> double asin( double x ) ; [Arguments] x A floating point value to be calculated arc sine. [Return] Returns the arc sine value (in radian) of "x". If argument is out of valid range, returns 0 and sets EDOM in the global variable "errno". [Description] Calculates the arc sine value of "x". "x" must be in -1 through 1. The result is in -PI/2 through PI/2 radian. -----------------------------------------------------------------------------3.3 Calculate the arc tangent value. <Main,Alarm,Comm> -----------------------------------------------------------------------------[Name] atan [Syntax] #include <math.h> double atan( double x ) ; [Arguments] x A floating point value to be calculated arc tangent. [Return] Returns the arc tangent value (in radian) of "x". [Description] Calculates the arc tangent value of "x". The result is in -PI/2 through PI/2 radian. -----------------------------------------------------------------------------3.4 Calculate the arc tangent value. <Main,Alarm,Comm> -----------------------------------------------------------------------------[Name] atan2 [Syntax] #include <math.h> double atan2( double y, double x ) ; [Arguments] x y A denominator of the value to be calculated arc tangent. A numerator of the value to be calculated arc tangent. [Return] Returns the arc tangent value (in radian) of y/x. If both "y" and "x" are 0, returns 0 and sets EDOM in the global variable "errno". [Description] Calculates the arc tangent value of y/x. Both "x" and "y" are must not be 0. The result is in -PI through PI radian. -----------------------------------------------------------------------------3.5 Calculate the smallest integer value. <Main,Alarm,Comm> -----------------------------------------------------------------------------[Name] ceil [Syntax] #include <math.h> double ceil( double x ) ; [Arguments] x A floating point value whose fractions is raised. [Return] Returns the smallest integer value that is greater than or equal to "x". [Description] Calculates the smallest integer value that is greater than or equal to "x". -----------------------------------------------------------------------------3.6 Calculate the cosine value. <Main,Alarm,Comm> -----------------------------------------------------------------------------[Name] cos [Syntax] #include <math.h> double cos( double x ) ; [Arguments] x A floating point value in radian to be calculated cosine. [Return] Returns the cosine value of "x". If "x" is too large, returns 0 and sets ERANGE in the global variable "errno". [Description] Calculates the cosine value of "x". -----------------------------------------------------------------------------3.7 Calculate the hyperbolic cosine value. <Main,Alarm,Comm> -----------------------------------------------------------------------------[Name] cosh [Syntax] #include <math.h> double cosh( double x ) ; [Arguments] x A floating point value in radian to be calculated hyperbolic cosine. [Return] Returns the hyperbolic cosine value of "x". If the result is too large, returns +/-HUGE_VAL and sets ERANGE in the global variable "errno". [Description] Calculates the hyperbolic cosine value of "x". -----------------------------------------------------------------------------3.8 Calculate the exponential function. <Main,Alarm,Comm> -----------------------------------------------------------------------------[Name] exp [Syntax] #include <math.h> double exp( double x ) ; [Arguments] x A floating point value to be calculated exponential function. [Return] Returns the exponential function value of "x". If the result is too large, returns HUGE_VAL and sets ERANGE in the global variable "errno". If the result is too small, returns 0. [Description] Calculates the exponential function ("e" raised to "x" power) of "x". -----------------------------------------------------------------------------3.9 Calculate the absolute value. <Main,Alarm,Comm> -----------------------------------------------------------------------------[Name] fabs [Syntax] #include <math.h> double fabs( double x ) ; [Arguments] x A floating point value to be calculated the absolute value. [Return] Returns the absolute value of "x". [Description] Calculates the absolute value of "x". -----------------------------------------------------------------------------3.10 Calculate the largest integer value. <Main,Alarm,Comm> -----------------------------------------------------------------------------[Name] floor [Syntax] #include <math.h> double floor( double x ) ; [Arguments] x A floating point value whose frantions is discarded. [Return] Returns the largest integet value that is less than or equal to "x" [Description] Calculates the largest integer value that is less than or equal to "x". -----------------------------------------------------------------------------3.11 Calculate the floating point remainder value. <Main,Alarm,Comm> -----------------------------------------------------------------------------[Name] fmod [Syntax] #include <math.h> double fmod( double x, double y ) ; [Arguments] x y A divident to be calculated remainder. A divosor to be calculated remainder. [Return] Returns the remainder of "x" and "y". If "y" is 0, returns 0 and sets EDOM in the global variable "errno". [Description] Calculates the remainder of "x" and "y". The remainder satisfies "x - i*y ("i" is an integer value)" and its absolute value is smaller than the absolute value of "y". -----------------------------------------------------------------------------3.12 Calculate the mantissa value. <Main,Alarm,Comm> -----------------------------------------------------------------------------[Name] frexp [Syntax] #include <math.h> double frexp( double value, int *exp ) ; [Arguments] value exp A floating point value to be divided. A integer variable in where the exponential part is stored. [Return] Returns the mantissa of a divided floating point value. [Description] Divides "value" into a mantissa part "m" and an exponential part "n" "m" relates with "n" as "value = m * 2^n" and the absolute value of "m" is greater than or equal to 0.5 and less than 1. If "value" is 0, both "m" and "n" are 0. -----------------------------------------------------------------------------3.13 Calculate the value multiplied by the power of 2. <Main,Alarm,Comm> -----------------------------------------------------------------------------[Name] ldexp [Syntax] #include <math.h> double ldexp( double x, int exp ) ; [Arguments] x exp A floating point value of the manttisa. A exponential part. [Return] Returns the raied value. If the result is too large, returns +/-HUGE_VAL and sets ERANGE in the global variable "errno". [Description] Calculates the raised value "x * 2^exp" by the mantissa and the exponent. -----------------------------------------------------------------------------3.14 Calculate the natural (base-e) logarithm value. <Main,Alarm,Comm> -----------------------------------------------------------------------------[Name] log [Syntax] #include <math.h> double log( double x ) ; [Arguments] x A floating point value to be calculated natural logarithm. [Return] Returns the natural logarithm value of "x". If "x" is 0, returns HUGE_VAL and sets ERANGE in the global variable "errno". If "x" is negative, returns HUGE_VAL and sets EDOM in the global variable "errno". [Description] Calculates the natural logarithm (base-e logarithm) value of "x". -----------------------------------------------------------------------------3.15 Calculate the base-10 logarithm value. <Main,Alarm,Comm> -----------------------------------------------------------------------------[Name] log10 [Syntax] #include <math.h> double log10( double x ) ; [Arguments] x A floating point value to be calculated base-10 logarithm. [Return] Returns the base-10 logarithm value of "x". If "x" is 0, returns HUGE_VAL and sets ERANGE in the global variable "errno". If "x" is negative, returns HUGE_VAL and sets EDOM in the global variable "errno". [Description] Calculates the base-10 logarithm value of "x". -----------------------------------------------------------------------------3.16 Get the fractional part and the integer part. <Main,Alarm,Comm> -----------------------------------------------------------------------------[Name] modf [Syntax] #include <math.h> double modf( double value, double *iptr ) ; [Arguments] value iptr A floating point value to be divided. A integer variable in where the integer part is stored. [Return] Returns the fractional part of "value". [Description] Divides "value" into a fractional part and an integer part, both parts have the same sign. -----------------------------------------------------------------------------3.17 Calculate the raised value. <Main,Alarm,Comm> -----------------------------------------------------------------------------[Name] pow [Syntax] #include <math.h> double pow( double x, double y ) ; [Arguments] x y A floating point value to be raised. An exponent value. [Return] Returns "x" raised to the power of "y". If "x" is 0 and "y" is negative, returns HUGE_VAL and sets EDOM in the global variable "errno". If both "x" and "y" are 0 or "x" is negative and "y" is not an integer, returns 0 and sets EDOM in the global variable "errno". If the result is too large, returns +/-HUGE_VAL and sets ERANGE in the global variable "errno". [Description] Calculates "x" raised to the power of "y". -----------------------------------------------------------------------------3.18 Calculate the sine value. <Main,Alarm,Comm> -----------------------------------------------------------------------------[Name] sin [Syntax] #include <math.h> double sin( double x ) ; [Arguments] x A floating point value in radian to be calculated sine. [Return] Returns the sine value of "x". If "x" is too large, returns 0 and sets ERANGE in the global variable "errno". [Description] Calculates the sine value of "x". -----------------------------------------------------------------------------3.19 Calculate the hyperbolic sine value. <Main,Alarm,Comm> -----------------------------------------------------------------------------[Name] sinh [Syntax] #include <math.h> double sinh( double x ) ; [Arguments] x A floating point value in radian to be calculated hyperbolic sine. [Return] Returns the hyperbolic sine value of "x". If the result is too large, returns +/-HUGE_VAL and sets ERANGE in the global variable "errno". [Description] Calculates the hyperbolic sine value of "x". -----------------------------------------------------------------------------3.20 Calculate the square root value. <Main,Alarm,Comm> -----------------------------------------------------------------------------[Name] sqrt [Syntax] #include <math.h> double sqrt( double x ) ; [Arguments] x A floating point value to be calculated square root. [Return] Returns the square root value of "x". If "x" is negative, returns 0 and sets EDOM in the global variable "errno". [Description] Calculates the square root value of "x". -----------------------------------------------------------------------------3.21 Calculate the tangent value. <Main,Alarm,Comm> -----------------------------------------------------------------------------[Name] tan [Syntax] #include <math.h> double tan( double x ) ; [Arguments] x A floating point value in radian to be calculated tangent. [Return] Returns the tangent value of "x". If "x" is too large, returns 0 and sets ERANGE in the global variable "errno". [Description] Calculates the tangent value of "x". -----------------------------------------------------------------------------3.22 Calculate the hyperbolic tangent value. <Main,Alarm,Comm> -----------------------------------------------------------------------------[Name] tanh [Syntax] #include <math.h> double tanh( double x ) ; [Arguments] x A floating point value in radian to be calculated hyperbolic tangent. [Return] Returns the hyperbolic tangent value of "x". [Description] Calculates the hyperbolic tangent value of "x". 4. Non-local jumps ( setjmp.h ) -----------------------------------------------------------------------------4.1 Save current environment for non-local jump. <Main,Alarm,Comm> -----------------------------------------------------------------------------[Name] setjmp [Syntax] #include <setjmp.h> int setjmp( jmp_buf env ) ; [Arguments] env Buffer in which contents of stack is saved. [Return] Returns zero. When "setjmp" is called again by "longjmp", it returns "value", one of arguments of "longjmp". If "value" is zero, it returns 1. [Description] "setjmp" saves contents of stack in "env" for restoring by the later "longjmp". This enables jumping between functions. See also "longjmp" for more information. This function use the library supplied together with the compiler. For details, see "How to make application program." -----------------------------------------------------------------------------4.2 Execute a non-local jump. <Main,Alarm,Comm> -----------------------------------------------------------------------------[Name] longjmp [Syntax] #include <setjmp.h> void longjmp( jmp_buf env, int value ) ; [Arguments] env value Buffer in which contents of stack is saved. Return value of "setjmp". [Return] -----[Description] "longjmp" restores environment which has been saved by "setjmp" before, and jumps to the previous "setjmp" function. This enables jumping between functions. When "setjmp" is called from "longjmp", "setjmp" returns "value" which is an one of arguments of "longjmp". If "value" is zero, "setjmp" returns 1. After re-calling "setjmp", values of all variables are ones at calling "longjmp". Global variables whish has been changed by the other functions are not restored. All register variables are undefined. Usually, "setjmp" is called in the function which calls a function in which "longjmp" is called. That is, "setjmp" must be the outer nested function than "longjmp". When "longjmp" jumps to an inner function, the program doesn't work correctly. outer <-> inner main()-+-- process1() ---- process2() ---- process3() | calls calls calls | setjmp() longjmp() longjmp() | <---------+ | | <-------------------------+ | ^^^ GOOD | ||| | ||| | ||| NO GOOD | ||| | ||+----------------------------+ | |+------------+ | +-- process4() ---- process5() ---- process6() calls calls calls longjmp() longjmp() longjmp() This function use the library supplied together with the compiler. For details, see "How to make application program." 5. Variable arguments ( stdarg.h ) -----------------------------------------------------------------------------5.1 Initialize arg_ptr. <Main,Alarm,Comm> -----------------------------------------------------------------------------[Name] va_start [Syntax] #include <stdarg.h> void va_start( va_list arg_ptr, prev_param ) ; [Arguments] arg_ptr prev_param Pointer to the list of arguments. Previous argument to the first optional argument. [Return] -----[Description] Initialize "arg_ptr" to let it point the first argument of the arguments list. This function is defined as MACRO. There are two definitions of this macro, such as ANSI standard macro defined in stdarg.h and UNIX System V macro defined in varargs.h. Only the ANSI standard macro is defined in C library. This function use the library supplied together with the compiler. For details, see "How to make application program." -----------------------------------------------------------------------------5.2 Get a next argument. <Main,Alarm,Comm> -----------------------------------------------------------------------------[Name] va_arg [Syntax] #include <stdarg.h> type va_arg( va_list arg_ptr, type ) ; [Arguments] arg_ptr type Pointer to the list of arguments. Type of an argument to be gotten. [Return] Returns an argument pointed by "arg_ptr". [Description] Returns a value "arg_ptr", then argument in the size of "type". repeatedly. whose type is "type" in a position pointed by increments "arg_ptr" to let it point the next list. The next argument position is determined by More arguments can be gotten using "arg_ptr" This function use the library supplied together with the compiler. For details, see "How to make application program." -----------------------------------------------------------------------------5.3 Reset arg_ptr. <Main,Alarm,Comm> -----------------------------------------------------------------------------[Name] va_end [Syntax] #include <stdarg.h> void va_end( va_list arg_ptr ) ; [Arguments] arg_ptr Pointer to the list of arguments. [Return] -----[Description] Initializes "arg_ptr" as NULL. This function use the library supplied together with the compiler. For details, see "How to make application program." 6. Input/output ( stdio.h ) -----------------------------------------------------------------------------6.1 Delete a file. <Main,Alarm,Comm> -----------------------------------------------------------------------------[Name] remove [Syntax] #include <stdio.h> int remove( const char *path ) ; [Arguments] path Pathname of a file to be deleted. [Return] Returns zero if a file has been successfully deleted. If not, returns -1 and sets an one of following values in the global variable "errno". Symbol Meaning ---------------+----------------------------------------------------EACCES Specified file is a Read-Only file. ENOENT Specified file or path does not exist, or "path" is a directory. [Description] Deletes a file specified by "path". -----------------------------------------------------------------------------6.2 Change the name of a file. <Main,Alarm,Comm> -----------------------------------------------------------------------------[Name] rename [Syntax] #include <stdio.h> int rename( const char *oldname, const char *newname ) ; [Arguments] oldname newname Pointer to the old name. Pointer to the new name. [Return] Returns zero if file name has been successfully changed. If not, returns -1 and sets an one of following values in the global variable "errno". Symbol Meaning ---------------+----------------------------------------------------EACCES A file or directory whose name is "newname" already exists, "path" is invalid, or a different path is specified in "newname" for a directory. ENOENT Specified file or path does not exist. EXDEV Attempted moving a file to the another device. [Description] Changes a file name or directory name specified by "oldname" to a new name specified by "newname". The old name must be a path name of a file or a directory which already exists. The new name must not be a path name of a file or a directory which already exists. A file can be moved from some directory to another one by specifying a different path name in "oldname" from "newname". But it is impossible to move a file from some device to the another device. For directory, only renaming is available, moving is not available. (Note) The library of the current version can not move any file. rename() function calling to move a file makes an error. (errno=EACCES) -----------------------------------------------------------------------------6.3 Generate a temporary file name. <Main,Alarm,Comm> -----------------------------------------------------------------------------[Name] tmpnam [Syntax] #include <stdio.h> char *tmpnam( char *string ) ; [Arguments] string Pointer to a temporary file name. [Return] Returns a pointer to a generated unique file name if it has been successfully generated. If not, returns NULL. [Description] Generates a file name by which a temporary file can be opened without overwriting existing files. This name is stored in a buffer pointed by "string". If "strings" is NULL, the result is stored in the internal static buffer. So, the following calling destroy this result. At least buffer size must be larger than L-tmpnam bytes (defined in stdio.h). This function can generate up to TMP_MAX of unique file names. The generated string is composed of a path prefix, such as P_tmpdir define in stdio.h, and following sequence of numeric characters. The values of this numeric string are 1 through 65535. A process of "tmpnam" is not changed by modifying L_tmpnam or P_tmpdir. -----------------------------------------------------------------------------6.4 Close a stream. <Main,Alarm,Comm> -----------------------------------------------------------------------------[Name] fclose [Syntax] #include <stdio.h> int fclose( FILE *stream ) ; [Arguments] stream Pointer to a FILE structure. [Return] Returns zero if a stream has been successfully closed. If not, returns EOF. [Description] Closes specified stream. Buffers linked to the stream will be flushed before closing. Buffers allocated by the system will be deallocated. But buffers which has been allocated by user using "setbuf" or "setvbuf" will not be deallocated automatically. -----------------------------------------------------------------------------6.5 Flush a stream buffer. <Main,Alarm,Comm> -----------------------------------------------------------------------------[Name] fflush [Syntax] #include <stdio.h> int fflush( FILE *stream ) ; [Arguments] stream Pointer to a FILE structure. [Return] Returns zero if a buffer has been successfully flushed. Also if specified stream has no buffer, or it has been opened with Read-Only mode, returns zero. If any error occurs, returns EOF. In this case, any data may be missed because of incorrect writing. [Description] Flushes specified stream. If specified stream has been opened for output, contents of the buffer are written to the file. If for input, they are cleard. All streams for output are flushed by specifying NULL in argument. Steams will still exist as they are after calling "fflush". Calling "fflush" makes the result of "ungetc" ineffective. Buffers are automatically flushed when a buffer is full, a stream is closed, or program successfully terminated without closing streams. This function does not influence to the streams without buffering. -----------------------------------------------------------------------------6.6 Open a stream. <Main,Alarm,Comm> -----------------------------------------------------------------------------[Name] fopen [Syntax] #include <stdio.h> FILE *fopen( const char *filename, const char *mode ) ; [Arguments] filename mode Path name of a file. Permitted access type. [Return] Returns a pointer to the opened file. If any error, returns NULL pointer. [Description] Opens a file specified by "filename". Specify access type which is requested to the file in "mode". Type Meaning -----------+----------------------------------------------------r Opens with Read-Only mode. Error if specified file does not exist. w Opens with output mode. Opens an empty file. Contents of the existing file are destroyed. a Opens with output mode, appending to the end of the file. If specified file does not exist, creates it. r+ Opens with both input and output mode. Specified file must exist. w+ Opens an empty file with both input and output mode. Contents of the existing file are destroyed. a+ Opens with both input and output. If no specified file, creates it. Addtionally, the following open mode can also be specified as additional character in the above list. Mode Meaning -----------+----------------------------------------------------t Opens the file in text mode.(default) In this mode, line feed characters are converted as follows. Input CR+LF --> LF Output LF --> CR+LF b Opens the file in binary mode. In this mode, line feed characters are not converted. -----------------------------------------------------------------------------6.7 Re-open a same stream. <Main,Alarm,Comm> -----------------------------------------------------------------------------[Name] freopen [Syntax] #include <stdio.h> FILE *freopen( const char *filename, const char *mode, FILE *stream ) ; [Arguments] filename mode stream Path name of a new file. Permitted access type. Pointer to a FILE structure. [Return] Returns a pointer to the newly opened file. If any error, closes a old file and returns NULL pointer. [Description] Closes a file linked to the stream, then reallocates the stream to the file specified by "filename". This function is usually used to redirect already opened standard input (stdin), standard output (stdout) or standard error output (stderr) to specified file. The new file to be linked the steam is opened with "mode". Specify access type which is requested to the file in "mode". Type Meaning -----------+----------------------------------------------------r Opens with Read-Only mode. Error if specified file does not exist. w Opens with output mode. Opens an empty file. Contents of the existing file are destroyed. a Opens with output mode, appending to the end of the file. If specified file does not exist, creates it. r+ Opens with both input and output mode. Specified file must exist. w+ Opens an empty file with both input and output mode. Contents of the existing file are destroyed. a+ Opens with both input and output. If no specified file, creates it. Addtionally, the following open mode can also be specified as additional character in the above list. Mode Meaning -----------+----------------------------------------------------t Opens the file in text mode.(default) In this mode, line feed characters are converted as follows. Input CR+LF --> LF Output LF --> CR+LF b Opens the file in binary mode. In this mode, line feed characters are not converted. -----------------------------------------------------------------------------6.8 Set a buffer for stream. <Main,Alarm,Comm> -----------------------------------------------------------------------------[Name] setbuf [Syntax] #include <stdio.h> void setbuf( FILE *stream, char *buffer ) ; [Arguments] stream buffer Pointer to a FILE structure. Buffer allocated by user. [Return] -----[Description] Controls buffering of a stream. Specified stream must be already opened file from/to which any input/output has not been done. Buffering is not performed for the stream if "buffer" is NULL. Otherwise, "buffer" must point a buffer whose size is BUFSIZ. BUFSIZ is a buffer size defined in stdio.h. By calling this function, user defined buffer is used as an input/output buffer instead of system defined one. Functions of "setbuf" is included in "setvbuf". It is recommended to use "setvbuf" for newly made programs. "setbuf" is provided for compatibility with existing programs. -----------------------------------------------------------------------------6.9 Control a buffer for stream. <Main,Alarm,Comm> -----------------------------------------------------------------------------[Name] setvbuf [Syntax] #include <stdio.h> int setvbuf( FILE *stream, char *buffer, int mode, size_t size ) ; [Arguments] stream buffer mode size Pointer to a FILE structure. Buffer allocated by user. Buffering mode. Buffer size. [Return] Returns zero if successful. If not (invalid mode or buffer size), returns non-zero. [Description] Controls buffering and buffer size of stream. Specified stream must be already opened file from/to which any input/output has not been done. Buffer pointed by "buffer" is used unless "buffer" is NULL. If NULL, new buffer whose size is "size" is automatically allocated. "mode" is one of follows. Mode Meaning ---------------+----------------------------------------------------_IOFBF Full buffering. "buffer" is a pointer to the buffer, and "size is a size of the buffer. If "buffer" is NULL, new buffer of "size" byte allocated automatically is used. _IONBF No buffer is used regardless of "buffer" and "size". -----------------------------------------------------------------------------6.10 Print formatted data to a stream. <Main,Alarm,Comm> -----------------------------------------------------------------------------[Name] fprintf [Syntax] #include <stdio.h> int fprintf( FILE *stream, const char *format [, argument]... ) ; [Arguments] stream format argument Pointer to a FILE structure. Format control string. Optional arguments. [Return] Returns number of characters which have been output. If any error, returns negative value. [Description] Outputs a series of formatted data to (if exist) are output with conversion specification in "format". Formats of "printf". See "printf" for details of a stream. Each arguments according to the format "format" are same as ones of "format" and "argument". -----------------------------------------------------------------------------6.11 Read formatted data from a stream. <Main,Alarm,Comm> -----------------------------------------------------------------------------[Name] fscanf [Syntax] #include <stdio.h> int fscanf( FILE *stream, const char *format [, argument]... ) ; [Arguments] stream format argument Pointer to a FILE structure. Format control string. Optional arguments. [Return] Returns a number of fields converted successfully. This does not includes fields which has been read and not converted. Returns EOF if any error is detected in a stream before the first conversion, or the end of file is detected. Return value zero means that no fields have been converted. [Description] Reads formatted data to arguments (if exist) from a stream. "argument" are pointer to variables whose types are same as type specification in "format". Formats of "format" are same as "scanf". See "scanf" for details of "format" and "argument". -----------------------------------------------------------------------------6.12 Print formatted data to standard output. <Main> -----------------------------------------------------------------------------[Name] printf [Syntax] #include <stdio.h> int printf( const char *format [, argument]... ) ; [Arguments] format argument Format control string. Optional arguments. [Return] Returns number of characters which have been output. If any error, returns negative value. [Description] Outputs a series of formatted data to the standard output stream (stdout). "format" is composed of ordinary characters, escape sequences and format specifications. Ordinary characters and escape sequences are output to the standard output in order. If any arguments follow the format string, output formatting for the arguments are performed using the format string. The first character of format specification is '%'. Format specification is decoded rightward from the left. The first argument following "format" is output according to the first format specification. The second argument is output according to the second format specification, and so forth. More arguments than the format specifications are ignored. If a number of arguments is short of format specifications, the result of "printf" is not warranted. 1) Format specification format. % [flags] [width] [.precision] [{h|l|L}] type type : Type of argument, character, strings or numeric value. flags : Justification, sign, space, decimal point, prefix of octal/hexadecimal number. width : Minimum width of output column. precision : Maximum number of characters output in whole or a part of output field. h,l,L : Size of argument. 2) "type" field specification. Char Type Output format -----+---------------+--------------------------------------------d int Signed decimal number. i int Signed decimal number. u int Unsigned decimal number. o int Unsigned octal number. x int Unsigned hexadecimal number, using "abcdef". X int Unsigned hexadecimal number, using "ABCDEF". f double Signed floating point value with "[-]dddd.dddd" format. e double Signed floating point value with "[-]d.dddde[sign]ddd" format. E double Signed floating point value with "[-]d.ddddE[sign]ddd" format. g double "f" or "e", shorter one for output string. G double Same as "g" but 'G' before exponent. c int A character. s string String till the first null character(\0) or limit specified by "precision". n pointer to integer A number of characters output up to this point. p pointer to void Address specified by the argument with the format according to the current memory model. 3) "flag" specification flag Meaning Default -------+-------------------------------+--------------------------- Left justification. Right justification. + Sign before a value. Only '-' for a negative value. 0 Padding by '0' till the No padding. minimum width. SPACE Leading space to output value. No leading space. # Prefix "0", "0x" or "0X" No prefix. before non-'0' numeric character for 'o','x' or 'X' format. Forced decimal point for 'e', Decimal point if needed. 'E' or 'f' format. Forced decimal point and Decimal point if needed, no-suppressing trailing '0' suppressing trailing '0'. for 'g' or 'G' format. -----------------------------------------------------------------------------6.13 Read formatted data from standard input. <Main> -----------------------------------------------------------------------------[Name] scanf [Syntax] #include <stdio.h> int scanf( const char *format [, argument]... ) ; [Arguments] format argument Format control string. Optional arguments. [Return] Returns a number of fields converted successfully. This may be less than the requested number to "scanf". This does not includes fields which has been read and not converted. Returns EOF if any error is detected in a stream before the first conversion, or the end of file is detected. Return value zero means that no fields have been converted. [Description] Reads formatted data to arguments from the standard input stream (stdin). "argument" are pointer to variables whose types are same as type specification in "format". Format specification controls decoding input fields. Specify one or more of following characters for format specification. * Whitespace -- space(' '), tab('\t'), newline('\n') Skips whitespace characters in input data till the next non-whitespace character. * Non-whitespace character except a percent sign ('%') Skips non-whitespece character which is same as specified one. If the next character in the standard input (stdin) is not same as specified one, process will be terminated. * Format specification following to a percent sign ('%') Reads input characters, and converts to specified type. Converted value is stored in the variable pointed by the argument. 1) Format specification format % [*] [width] [{h|l}] type type : Type of input argument, character, strings or numeric value. width : Maximum number of characters input from standard input. (positive decimal number) More characters than "width" are not converted, and not stored in the argument. When any whitespace character is detected before reaching to "width", or input characters can not be converted according to specified format, only less characters than "width" are read. h,l : Object size to be read. 'l' is long version and 'h' is short version. * : Only decoding of input field is performed, but no data is stored in the variable. 2) "type" field specification. Char Type of input data Type of argument -----+-------------------------------+----------------------------d Decimal number. Pointer to int. o Octal number. Pointer to int. x Hexadecimal number. Pointer to int. i Octal, decimal or hexadecimal Pointer to int. number u Unsigned decimal number Pointer to unsigned int. U Unsigned decimal number Pointer to unsigned long. e,E Floating point number which is Pointer to float. f composed of one or more g,G sequential decimal number with a sign (+,-) and decimal point (optional), exponent('e' or 'E', optional) and signed integer (optional). c Character. Pointer to char. Even whitespace character can be read. To skip whitespace characters, use "%ls". s String. Pointer to character array whose size if enough for both input field and terminating character (null). n Not read from stream or buffer Pointer to int, in which a number of characters input up to this point is stored. p Value with "xxxx:yyyy" format Pointer to (void _far *). 'x' and 'y' are uppercase hexadecimal number. -----------------------------------------------------------------------------6.14 Print formatted data to memory. <Main,Alarm,Comm> -----------------------------------------------------------------------------[Name] sprintf [Syntax] #include <stdio.h> int sprintf( char *buffer, const char *format [, argument]... ) ; [Arguments] buffer format argument Buffer in which string is stored. Format control string. Optional arguments. [Return] Returns number of characters which have been stored in the buffer. (The last null character is not counted.) [Description] Stores a series of formatted data in a buffer. exist) are stored with conversion according to specification in "format". Formats of "format" "printf". See "printf" for details of "format" Each arguments (if the format are same as ones of and "argument". -----------------------------------------------------------------------------6.15 Read formatted data from memory. <Main,Alarm,Comm> -----------------------------------------------------------------------------[Name] sscanf [Syntax] #include <stdio.h> int sscanf( const char *buffer, const char *format [, argument]... ) ; [Arguments] buffer format argument Stored data. Format control string. Optional arguments. [Return] Returns a number of fields converted successfully. This does not includes fields which has been read and not converted. Returns EOF if the end of string is detected. Return value zero means that no fields have been converted. [Description] Reads formatted data to arguments (if exist) from a buffer. "argument" are pointer to variables whose types are same as type specification in "format". Formats of "format" are same as "scanf". See "scanf" for details of "format" and "argument". -----------------------------------------------------------------------------6.16 Print formatted data to a file using variable arguments. <Main,Alarm,Comm> -----------------------------------------------------------------------------[Name] vfprintf [Syntax] #include <stdio.h> #include <stdarg.h> int vfprintf( FILE *stream, const char *format, va_list argptr ) ; [Arguments] stream format argptr Pointer to a FILE structure. Format control string. Pointer to a list of arguments. [Return] Returns number of characters which have been output. If any error, returns negative value. [Description] Outputs a series of formatted data to a stream. Each arguments are output with conversion according to the format specification in "format". "argptr" is a pointer of va_list type defined in stdarg.h. It points a list of arguments to be converted and output according to format specifications of "format". Formats of "format" are same as ones of "printf". See "printf" for details of "format" and "argument". This function use the library supplied together with the compiler. For details, see "How to make application program." -----------------------------------------------------------------------------6.17 Print formatted data to standard output using variable arguments. <Main> -----------------------------------------------------------------------------[Name] vprintf [Syntax] #include <stdio.h> #include <stdarg.h> int vprintf( const char *format, va_list argptr ) ; [Arguments] format argptr Format control string. Pointer to a list of arguments. [Return] Returns number of characters which have been output. (The last null character is not counted.) If any error, returns negative value. [Description] Outputs a series of formatted data to the standard output. Each arguments are output with conversion according to the format specification in "format". "argptr" is a pointer of va_list type defined in stdarg.h. It points a list of arguments to be converted and output according to format specifications of "format". Formats of "format" are same as ones of "printf". See "printf" for details of "format" and "argument". This function use the library supplied together with the compiler. For details, see "How to make application program." -----------------------------------------------------------------------------6.18 Print formatted data to memory using variable arguments. <Main,Alarm,Comm> -----------------------------------------------------------------------------[Name] vsprintf [Syntax] #include <stdio.h> #include <stdarg.h> int vsprintf( char *buffer, const char *format, va_list argptr ) ; [Arguments] buffer format argptr Buffer in which string is stored. Format control string. Pointer to a list of arguments. [Return] Returns number of characters which have been stored. (The last null character is not counted.) If any error, returns negative value. [Description] Stores a series of formatted data in a buffer pointed "buffer". Each arguments are stored with conversion according to the format specification in "format". "argptr" is a pointer of va_list type defined in stdarg.h. It points a list of arguments to be converted and output according to format specifications of "format". Formats of "format" are same as ones of "printf". See "printf" for details of "format" and "argument". This function use the library supplied together with the compiler. For details, see "How to make application program." -----------------------------------------------------------------------------6.19 Read a character from a stream. <Main,Alarm,Comm> -----------------------------------------------------------------------------[Name] fgetc [Syntax] #include <stdio.h> int fgetc( FILE *stream ) ; [Arguments] stream Pointer to a FILE structure. [Return] Returns a read character. Returns EOF if any error if any error or the end of file is detected. Use "feof" and "ferror" functions to distinguish an error from EOF. [Description] Reads a character from a file linked to "stream". A character is returned with conversion to int. A file pointer is incremented to point the next character. This function is same as "getc" function and is not a macro but a function. -----------------------------------------------------------------------------6.20 Read a strings from a stream. <Main,Alarm,Comm> -----------------------------------------------------------------------------[Name] fgets [Syntax] #include <stdio.h> char *fgets( char *string, int n, FILE *stream ) ; [Arguments] string n stream Buffer in which data is stored. Buffer size. Pointer to a FILE structure. [Return] Returns "string" if successful. Returns NULL if any error or the end of file is detected. Use "feof" and "ferror" functions to distinguish an error from EOF. [Description] Reads characters from a file linked to "stream" and stores them in "string". Reading is repeated until newline character('\n') is detected, the end of the stream is detected, or a length of read character become equivalent to "n-1". The result is stored in "string" adding null character('\0'). If "n" is 1, "string" is empty (""). This function is similar to "gets" function, but "gets" replaces a newline character to a null character. -----------------------------------------------------------------------------6.21 Write a character to a stream. <Main,Alarm,Comm> -----------------------------------------------------------------------------[Name] fputc [Syntax] #include <stdio.h> int putc( int c, FILE *stream ) ; [Arguments] c stream Character to be written. Pointer to a FILE structure. [Return] Returns a written character. If any error, returns EOF. [Description] Writes a character specified by "c" to an output stream. This function is similar to "putc" function, buf this is a function, not a macro. -----------------------------------------------------------------------------6.22 Write a string to a stream. <Main,Alarm,Comm> -----------------------------------------------------------------------------[Name] fputs [Syntax] #include <stdio.h> int fputs( const char *string, FILE *stream ) ; [Arguments] string stream String to be output. Pointer to a FILE structure. [Return] Returns "non-negative value" if successful. If any error, returns EOF. [Description] Write "strings" to a stream. The terminating character, null character ('\0'), is not output. -----------------------------------------------------------------------------6.23 Read a character from a stream. <Main> -----------------------------------------------------------------------------[Name] getc [Syntax] #include <stdio.h> int getc( FILE *stream ) ; [Arguments] stream Current stream. [Return] Returns a read character. Returns EOF if any error or the end of file is detected. Use "feof" and "ferror" functions to distinguish an error from EOF. [Description] Reads a character from a file linked to "stream". A file pointer is incremented to point the next character. This function is same as "fgetc" function and is not a function but a macro. -----------------------------------------------------------------------------6.24 Read a character from standard input. <Main> -----------------------------------------------------------------------------[Name] getchar [Syntax] #include <stdio.h> int getchar( void ) ; [Arguments] -----[Return] Returns a character read from the standard input. Returns EOF if any error or the end of file is detected. Use "feof" and "ferror" functions to distinguish an error from EOF. [Description] Reads a character from the standard input. This is same as "getc" function. This function is same as "_fgetchar" function but is a macro. -----------------------------------------------------------------------------6.25 Read a line string from standard input. <Main> -----------------------------------------------------------------------------[Name] gets [Syntax] #include <stdio.h> char *gets( char *buffer ) ; [Arguments] buffer Pointer to a buffer in which input characters are stored. [Return] Returns address of a buffer specified in argument. Returns NULL if any error or the end of file is detected. Use "feof" and "ferror" functions to distinguish an error from EOF. [Description] Reads a line from the standard input stream (stdin) and stores it in "buffer". A line is composed of all characters until the first newline character('\n'). A newline character is replaced with a null character('\0'). This function is similar to "fgets" function, buf "fgets" doesn't replace a newline character. -----------------------------------------------------------------------------6.26 Write a character to a stream. <Main> -----------------------------------------------------------------------------[Name] putc [Syntax] #include <stdio.h> int putc( int c, FILE *stream ) ; [Arguments] c stream Character to be written. Pointer to a FILE structure. [Return] Returns a written character. If any error, returns EOF. [Description] Writes a character "c" to an output stream. Any integer value whatever can be specified, but the only lower 8 bits are written. -----------------------------------------------------------------------------6.27 Write a character to standard output. <Main> -----------------------------------------------------------------------------[Name] putchar [Syntax] #include <stdio.h> int putchar( int c ) ; [Arguments] c Character to be written. [Return] Returns a written character. If any error, returns EOF. [Description] Writes a character "c" to the standard output (stdout). This is same as "putc( c, stdout )". -----------------------------------------------------------------------------6.28 Write a string to standard output. <Main> -----------------------------------------------------------------------------[Name] puts [Syntax] #include <stdio.h> int puts( const char *string ) ; [Arguments] string String to be written. [Return] Returns "non-positive value" if successful. If any error, returns EOF. [Description] Writes "string" to the standard output (stdout). The last character of the string, null character('\0'), is replaced with a newline character('\n'). -----------------------------------------------------------------------------6.29 Put a character into a steam. <Main,Alarm,Comm> -----------------------------------------------------------------------------[Name] ungetc [Syntax] #include <stdio.h> int ungetc( int c, FILE *stream ) ; [Arguments] c stream Character to be pushed. Pointer to a FILE structure. [Return] Returns a character "c" if successful. Returns EOF if nothing has been read from the stream or the specified character has not be able to pushed into the stream. [Description] Pushes a character "c" into the stream and clears the end of file indicator. The stream must be opened with "Read mode". The next reading from the stream is processed from "c". If "c" is EOF, it is ignored. The pushed character into the stream will be cleared befer it is read from the stream by calling "fflush", "fseek", "fsetpos" or "rewind" functions. The file position indicator is not changed by this function. If "ungetc" function is used for any text stream, the file pointer is undefined until all pushed characters are read or cleared. If "ungetc" function is used for any binary stream, the file point indicator is set to the previous position. In the case that the value of the file point indicator was zero before calling this function, the value after calling is not warranted. When "ungetc" function is calling twice continuously without any reading, the result is unstable. After calling of "fscanf" function, "ungetc" function will be unsuccessful unless one more reading procedure. (Because "fscanf" function calls "ungetc" function itself.) -----------------------------------------------------------------------------6.30 Read data from a stream. <Main,Alarm,Comm> -----------------------------------------------------------------------------[Name] fread [Syntax] #include <stdio.h> size_t fread( void *buffer, size_t size, size_t count, FILE *stream ) ; [Arguments] buffer size count stream Pointer to a data buffer. Item size in byte. Maximum number of item to be read. Pointer to a FILE structure. [Return] Returns number of items which has been read actually. If this value is less than "count", any error or the end of file before reading "count" times might be detected. If any error, the file pointer is undefined. The value read partially is undefined. Use "feof" and "ferror" functions to distinguish an error from EOF. If "size" or "count" is zero, returns zero and doesn't change contents of buffer. [Description] Reads "count" elements of "size" bytes item from an input stream, and stores into "buffer". The file pointer linked to "stream" (if exists) is incremented by bytes number which has been read actually. If the specified stream is opened with text mode, a pair of carriage return and line feed (CR+LF) is replaced with a line feed character (LF). This conversion doesn't affect the file pointer and the return value. -----------------------------------------------------------------------------6.31 Write data to a stream. <Main,Alarm,Comm> -----------------------------------------------------------------------------[Name] fwrite [Syntax] #include <stdio.h> size_t fwrite( void *buffer, size_t size, size_t count, FILE *stream ) ; [Arguments] buffer size count stream Pointer to a data buffer. Item size in byte. Maximum number of item to be written. Pointer to a FILE structure. [Return] Returns number of items which has been written actually. If this value is less than "count", any error might be detected. If any error, the file pointer is undefined. [Description] Writes "count" elements of "size" bytes item from "buffer" to a output stream. The file pointer linked to "stream" (if exists) is incremented by bytes number which has been written actually. If the specified stream is opened with text mode, a line feed character(LF) is replaced with a pair of carriage return and line feed (CR+LF). This conversion doesn't affect the return value. -----------------------------------------------------------------------------6.32 Get the current file position of a stream. <Main,Alarm,Comm> -----------------------------------------------------------------------------[Name] fgetpos [Syntax] #include <stdio.h> int fgetpos( FILE *stream, fpos_t *pos ) ; [Arguments] stream pos Pointer to a FILE structure. Pointer to a position indicator to be stored. [Return] Returns zero if successful. If not, returns non-zero value and sets an one of following values, which are defined in stdio.h, in a global variable "errno". Symbol Meaning ---------------+----------------------------------------------------EBADF File handle linked to the specified stream is invalid, or cannot be accessed. EINVAL Specified stream is invalid. [Description] Gets a file position indicator of the specified stream, and stores it in the buffer pointed by "pos". It is able to restore the pointer of the stream at calling "fgetpos" function by "fsetpos" function using an information stored in "pos". Data format of "pos" is internal one, it is used only by "fgetpos" and "fsetpos" functions. -----------------------------------------------------------------------------6.33 Move the current file pointer. <Main,Alarm,Comm> -----------------------------------------------------------------------------[Name] fseek [Syntax] #include <stdio.h> int fseek( FILE *streem, long offset, int orign ) ; [Arguments] stream offset orign Pointer to a FILE structure. Offset from origin in byte. Origin position. [Return] Returns zero if successful. If not, returns non-zero value. For nonseekable devices, returns unstable value. [Description] Moves a file pointer (if exists) linked to the stream to "offset" bytes position from "orign". The following operations to the stream are performed at this new position. It is possible to both read and write as the next operation to the streams which are opened with updating mode. It is possible to move the pointer to any arbitrary position, also beyond the end of file. Calling this function clears the end of file indicator. "orign" is one of the following constants which are defined in stdio.h. Symbol Meaning ---------------+----------------------------------------------------SEEK_CUR Current position. SEEK_END End of file. SEEK_SET Beginning of file. -----------------------------------------------------------------------------6.34 Set the current file position of stream. <Main,Alarm,Comm> -----------------------------------------------------------------------------[Name] fsetpos [Syntax] #include <stdio.h> int fsetpos( FILE *stream, fpos_t *pos ) ; [Arguments] stream pos Pointer to a FILE structure. Pointer to a position indicator to be stored. [Return] Returns zero if successful. If not, returns non-zero value and sets an one of following values, which are defined in stdio.h, in a global variable "errno". Symbol Meaning ---------------+----------------------------------------------------EBADF File handle linked to the specified stream is invalid, or cannot be accessed. EINVAL Specified stream is invalid. [Description] Restores a file position indicator of the specified stream to "pos" which has been gotten by the previous "fgetpos" function. This function clears the end of file indicator and cancels the result of "ungetc" function to the stream. Data format of "pos" is internal one, it is used only by "fgetpos" and "fsetpos" functions. -----------------------------------------------------------------------------6.35 Get the current file pointer. <Main,Alarm,Comm> -----------------------------------------------------------------------------[Name] ftell [Syntax] #include <stdio.h> long ftell( FILE *stream ) ; [Arguments] stream Pointer to a FILE structure. [Return] Returns the current file pointer. If any error, returns -1L and sets an one of following values, which are defined in stdio.h, in a global variable "errno". Symbol Meaning ---------------+----------------------------------------------------EBADF File handle linked to the specified stream is invalid, or cannot be accessed. EINVAL Specified stream is invalid. For non-seekable devices or not opened files, returns unstable value. [Description] Gets the current file pointer linked to the stream. This value is a offset from the beginning of stream. A file pointer of a stream which is opened with text mode may not coincide with the physical offset, because a pair of carriage return and line feed (CR+LF) is replaced with a line feed character(LF) in text mode. The current file position of the file which has been opened with appending mode is not the next writing position but the last reading/writing operation position. For example, if the last operation to the file which has been opened with appending mode is reading, the file position is not the one in which the next writing operation will be done but the next reading operation. In case that any reading/writing operations have not been done to for appending mode file, the current file position is the beginning of file. -----------------------------------------------------------------------------6.36 Rewind the current file pointer to the top of file. <Main,Alarm,Comm> -----------------------------------------------------------------------------[Name] rewind [Syntax] #include <stdio.h> void rewind( FILE *stream ) ; [Arguments] stream Pointer to a FILE structure. [Return] -----[Description] Rewind a file pointer linked to the stream to the beginning of file. "rewind" function clears an error indicator of the stream, but "fseek" doesn't. "rewind" is equivalent to the following "fseek" except above. (void) fseek ( *stream, 0L, SEEK_SET ) ; Both "rewind" and "fseek" functions clear the end of file indicator. "fseek" function returns a value whether a pointer movement has been done successfully or not, but "rewind" doesn't. It is possible to clear the keyboard buffer by calling "rewind" function to the standard input stream (stdin) linked to the keyboard by default. -----------------------------------------------------------------------------6.37 Reset error indicator of a stream. <Main,Alarm,Comm> -----------------------------------------------------------------------------[Name] clearerr [Syntax] #include <stdio.h> void clearerr( FILE *stream ) ; [Arguments] stream Pointer to a FILE structure. [Return] -----[Description] Rests the error indicator and the end of file indicator. The error indicator is not cleared automatically. If once the error indicator of specified stream is set, operations to the stream return the error code until calling one of "clearerr", "fseek", "fsetpos" and "rewind". -----------------------------------------------------------------------------6.38 Test for end-of-file. <Main,Alarm,Comm> -----------------------------------------------------------------------------[Name] feof [Syntax] #include <stdio.h> int feof( FILE *stream ) ; [Arguments] stream Pointer to a FILE structure. [Return] Returns non-zero value if any input operations have been done beyond the end of file, or zero if not. This function doesn't return any error code. [Description] Tests whether reaching to the end of stream or not. Any operations after once reaching to the end of steam return the end of file indicator until the stream is closed or one of "clearerr", "fseek", "fsetpos" and "rewind" is called. -----------------------------------------------------------------------------6.39 Test for error on stream. <Main,Alarm,Comm> -----------------------------------------------------------------------------[Name] ferror [Syntax] #include <stdio.h> int ferror( FILE *stream ) ; [Arguments] stream Pointer to a FILE structure. [Return] Returns zero if no error on the stream, otherwise non-zero value. [Description] Test whether any read/write error occurs on a file linked to the stream. If once any error has been occurred, the error indicator of the stream is still ON until the stream is closed or one of "clearerr" and "rewind" functions is called. -----------------------------------------------------------------------------6.40 Print error message. <Main> -----------------------------------------------------------------------------[Name] perror [Syntax] #include <stdio.h> void perror( const char *string ) ; [Arguments] string Error message to be displayed. [Return] -----[Description] Displays an error message to the standard error output (stderr). "string" is displayed first, then a colon (':') and a system error message about the library call which has been occurred the latest error, and last a newline is output. If "string" is NULL pointer or a pointer to null string, only system error message is displayed. A error code is stored in a global variable "errno" defined in errno.h. A system error message is read from "sys_errlist", an array of messages sorted by error code. "perror" function uses "errno" as a index of "sys_errlist" to display an error message. "sys_nerr" variable is the maximum element number of "sys_errlist" array. It is necessary to call "perror" function just after library error to display exactly. Otherwise, the following library calls may overwrite "errno". Values which are stored in "errno" at error are original ones of C Executor. These are not compatible with any PCs (MS-DOS machines, etc.) and may be changed in the future. So, programming that "errno" is handling is not recommended because it may not works correctly in the future. 7. General utilities ( stdlib.h ) -----------------------------------------------------------------------------7.1 Convert string to int value. <Main,Alarm,Comm> -----------------------------------------------------------------------------[Name] atoi [Syntax] #include <stdlib.h> int atoi( const char *nptr ) ; [Arguments] nptr Pointer to a string. [Return] Returns a converted value of int type. [Description] Converts a strings pointed by "nptr" to integer value. Format of strings is as follows. (whitespaces)(+,-)numeric_characters -----------------------------------------------------------------------------7.2 Convert string to long value. <Main,Alarm,Comm> -----------------------------------------------------------------------------[Name] atol [Syntax] #include <stdlib.h> long atol( const char *nptr ) ; [Arguments] nptr Pointer to a string. [Return] Returns a converted value of long type. [Description] Converts a strings pointed by "nptr" to long integer value. Format of strings is as follows. (whitespaces)(+,-)numeric_characters -----------------------------------------------------------------------------7.3 Convert string to long value. <Main,Alarm,Comm> -----------------------------------------------------------------------------[Name] strtol [Syntax] #include <stdlib.h> long strtol( const char *nptr, char **endptr, int base ) ; [Arguments] nptr endptr base Pointer to a string. Pointer which points the position where reading is stopped. Base number. [Return] Returns a converted value of long type. If overflow, returns LONG_MAX or LONG_MIN and sets ERANGE in a global variable "errno". [Description] Converts a string pointed by "nptr" to long integer value using "base" as a base number of conversion. Format of strings is as follows. (whitespaces)(+,-)(0)(x,X)(numeric_characters) A pointer which points the position where reading is stopped is stored in "endptr". If "endptr" is NULL, nothing is stored. If a base number is between 2 and 36, conversion is performed using it. If a base number is zero, the top characters decide a base number as follows. if (0)+(0 - 7) else if (0)+(x or X) else if (1 - 9) then octal then hexadecimal then decimal -----------------------------------------------------------------------------7.4 Convert string to unsigned long value. <Main,Alarm,Comm> -----------------------------------------------------------------------------[Name] strtoul [Syntax] #include <stdlib.h> unsigned long strtoul( const char *nptr, char **endptr, int base ) ; [Arguments] nptr endptr base Pointer to a string. Pointer which points the position where reading is stopped. Base number. [Return] Returns a converted value of unsigned long type. If overflow, returns ULONG_MAX and sets ERANGE in a global variable "errno". [Description] Converts a string pointed by "nptr" to unsigned long integer value using "base" as a base number of conversion. Format of strings is as follows. (whitespaces)(+,-)(0)(x,X)(numeric_characters) A pointer which points the position where reading is stopped is stored in "endptr". If "endptr" is NULL, nothing is stored. If a base number is between 2 and 36, conversion is performed using it. If a base number is zero, the top characters decide a base number as follows. if (0)+(0 - 7) else if (0)+(x or X) else if (1 - 9) then octal then hexadecimal then decimal -----------------------------------------------------------------------------7.5 Generate pseudo-random number. <Main,Alarm,Comm> -----------------------------------------------------------------------------[Name] rand [Syntax] #include <stdlib.h> int rand( void ) ; [Arguments] -----[Return] Returns a pseudo random number. [Description] Returns a pseudo random number between 0 and 32767. "srand" function initializes a series of random number. -----------------------------------------------------------------------------7.6 Seed pseudo-random number generator. <Main,Alarm,Comm> -----------------------------------------------------------------------------[Name] srand [Syntax] #include <stdlib.h> void srand( unsigned int seed ) ; [Arguments] seed Number of new series. [Return] -----[Description] Initializes a series of random number generated by "rand" function. -----------------------------------------------------------------------------7.7 Allocate memory block initialized by 0. <Main,Alarm,Comm> -----------------------------------------------------------------------------[Name] calloc [Syntax] #include <stdlib.h> void *calloc( size_t num, size_t size ) ; [Arguments] num size Number of elements. Byte size of element. [Return] Returns pointer to the allocated space. To get other type pointer than (void *), cast the return value. If insufficient memory, returns NULL. [Description] Allocates a memory block initialized by zero. That memory block is composed of "num" elements whose size is "size" bytes. Each element is initialized by zero. Test always the return value even if requested memory size is small. -----------------------------------------------------------------------------7.8 Free memory block. <Main,Alarm,Comm> -----------------------------------------------------------------------------[Name] free [Syntax] #include <stdlib.h> void free( void *memblock ) ; [Arguments] memblock Memory block already allocated. If NULL, it is ignored. [Return] -----[Description] Frees allocated memory block. "memblock" is a memory block which was already allocated by "calloc", "malloc" or "realloc" function. Byte size to be freed is one which was specified at memory allocation. Deallocated memory block will be used for the next memory allocations. If any invalid pointer is specified, any error may occur in the future allocations. "Invalid pointer" is one which was set without correct allocations. -----------------------------------------------------------------------------7.9 Allocate memory block. <Main,Alarm,Comm> -----------------------------------------------------------------------------[Name] malloc [Syntax] #include <stdlib.h> void *malloc( size_t size ) ; [Arguments] size Byte size to be allocated. [Return] Returns a void pointer to the allocated memory block. A return value can align with any object type. To get other type pointer than (void *), cast the return value. If insufficient memory, returns NULL. [Description] Allocates a memory block whose size is "size" bytes at least. More free space than "size" bytes is used for allocation because of a alignment and management information. Test always the return value even if requested memory size is small. -----------------------------------------------------------------------------7.10 Reallocate memory block. <Main,Alarm,Comm> -----------------------------------------------------------------------------[Name] realloc [Syntax] #include <stdlib.h> void *realloc( void *memblock, size_t size ) ; [Arguments] memblock size Memory block already allocated. Byte size to be allocated. [Return] Returns a void pointer to the reallocated memory block. A return value can align with any object type. To get other type pointer than (void *), cast the return value. If "size" is zero and "memblock" is not NULL, the current block is freed and the return value is NULL. If insufficient memory for reallocation, the current block is kept and the return value is NULL. [Description] Reallocates the memory block. This changes size of already allocated memory block. If a new block is placed in the other position, contents in the original block is kept. If "memblock" is NULL, "realloc" function works as same as "malloc" function, allocates a new block of "size" bytes. If "size" is not NULL, it must be a pointer which was returned by "calloc", "malloc" or "realloc" function before. If any invalid pointer is specified, any errors may occur by incorrect allocation. -----------------------------------------------------------------------------7.11 Perform binary search. <Main,Alarm,Comm> -----------------------------------------------------------------------------[Name] bsearch [Syntax] #include <stdlib.h> void *bsearch( const void *key, const void *base, size_t nmemb, size_t size, int (*compar)( const void *, const void *) ) ; [Arguments] key base nmemb size compar Data to be searched. Pointer to the top of the array. Element number of the array. Size of an element of the array. Pointer to the user definition function which compares two elements. [Return] Returns a pointer to the matching element. If not found, returns NULL. [Description] Searches the specified data in the specified array. The array must be already sorted. "bsearch" function calls "compar" function for searching. The return value of "compar" function must follow the following rule. Return Comparison result -----------------+--------------------------less than 0 1st arg. < 2nd arg. equal to 0 1st arg. = 2nd arg. greater than 0 1st arg. > 2nd arg. -----------------------------------------------------------------------------7.12 Perform quick sort. <Main,Alarm,Comm> -----------------------------------------------------------------------------[Name] qsort [Syntax] #include <stdlib.h> void qsort( const void *base, size_t nmemb, size_t size, int (*compar)( const void *, const void *) ) ; [Arguments] base nmemb size compar Pointer to the top of the array (its order will be changed by sorting.) Element number of the array. Size of an element of the array. Pointer to the user definition function which compares two elements. [Return] -----[Description] Performs quick sorting of the specified array. "qsort" function calls "compar" function for searching. The return value of "compar" function must follow the following rule. Return Comparison result -----------------+--------------------------less than 0 1st arg. < 2nd arg. equal to 0 1st arg. = 2nd arg. greater than 0 1st arg. > 2nd arg. -----------------------------------------------------------------------------7.13 Get absolute value. <Main,Alarm,Comm> -----------------------------------------------------------------------------[Name] abs [Syntax] #include <stdlib.h> int abs( int j ) ; [Arguments] j Value which is converted to absolute. [Return] Returns the absolute value of "j". [Description] Returns the absolute value of integer "j". -----------------------------------------------------------------------------7.14 Get quotient and remainder. <Main,Alarm,Comm> -----------------------------------------------------------------------------[Name] div [Syntax] #include <stdlib.h> struct div_t { int quot ; int rem ; } *div( int numer, int denum ) ; [Arguments] numer denum Dividend. Divisor. [Return] Returns a structure "div_t". [Description] Divides integer value "number" by integer value "denum", and returns the quotient and remander. Zero value as "denum" causes a system error. Check values before calling this. -----------------------------------------------------------------------------7.15 Get absolute value. <Main,Alarm,Comm> -----------------------------------------------------------------------------[Name] labs [Syntax] #include <stdlib.h> long labs( long j ) ; [Arguments] j Value which is converted to absolute. [Return] Returns the absolute value of "j". [Description] Returns the absolute value of long integer "j". -----------------------------------------------------------------------------7.16 Get quotient and remainder. <Main,Alarm,Comm> -----------------------------------------------------------------------------[Name] ldiv [Syntax] #include <stdlib.h> struct ldiv_t { long quot ; long rem ; } *ldiv( long numer, long denum ) ; [Arguments] numer denum Dividend. Divisor. [Return] Returns a structure "ldiv_t". [Description] Divides long integer value "number" by long integer value "denum", and returns the quotient and remander. Zero value as "denum" causes a system error. Check values before calling this. -----------------------------------------------------------------------------7.17 Convert string to double value. <Main,Alarm,Comm> -----------------------------------------------------------------------------[Name] atof [Syntax] #include <stdlib.h> double atof( const char *nptr ) ; [Arguments] nptr Pointer to a string. [Return] Returns a converted value of double type. [Description] Converts a strings pointed by "nptr" to double type value. Format of strings is as follows. (whitespaces)(+,-)num(.num)((d,D,e,E )(+,-)num) num: numeric_characters -----------------------------------------------------------------------------7.18 Convert string to double value. <Main,Alarm,Comm> -----------------------------------------------------------------------------[Name] strtod [Syntax] #include <stdlib.h> double strtod( const char *nptr, char **endptr ) ; [Arguments] nptr endptr Pointer to a string. Pointer which points the position where reading is stopped. [Return] Returns a converted value of double type. If overflow, returns +/-HUGE_VAL. If underflow, returns 0. In both case, sets ERANGE in a global variable "errno". [Description] Converts a string pointed by "nptr" to double type value. Format of strings is as follows. (whitespaces)(+,-)num(.num)((d,D,e,E )(+,-)num) num: numeric_characters A pointer which points the position where reading is stopped is stored in "endptr". If "endptr" is NULL, nothing is stored. 8. String handling ( string.h ) -----------------------------------------------------------------------------8.1 Copy a memory block. <Main,Alarm,Comm> -----------------------------------------------------------------------------[Name] memcpy [Syntax] #include <string.h> void *memcpy( void *s1, const void *s2, size_t n ) ; [Arguments] s1 s2 n Pointer to the destination. Pointer to the source. Byte count. [Return] Returns a pointer as same as "s1". [Description] Copies "n" byte data from the location specified by "s2" to the location specified by "s1". If the source and the destination are overlapped, the result is undefined. In this case, use "memmove" function. -----------------------------------------------------------------------------8.2 Move a memory block. <Main,Alarm,Comm> -----------------------------------------------------------------------------[Name] memmove [Syntax] #include <string.h> void *memmove( void *s1, void *s2, size_t n ) ; [Arguments] s1 s2 n Pointer to the destination. Pointer to the source. Byte count. [Return] Returns a pointer as same as "s1". [Description] Moves "n" byte data from the location specified by "s2" to the location specified by "s1". The memory block is copied correctly even if the source and the destination are overlapped. -----------------------------------------------------------------------------8.3 Copy a string. <Main,Alarm,Comm> -----------------------------------------------------------------------------[Name] strcpy [Syntax] #include <string.h> char *strcpy( char *s1, const char *s2 ) ; [Arguments] s1 s2 Pointer to the destination. Pointer to the source. [Return] Returns a pointer as same as "s1". [Description] Copies a string pointed by "s2" to the location pointed by "s1". If the source and the destination are overlapped, the result is undefined. -----------------------------------------------------------------------------8.4 Copy a string. <Main,Alarm,Comm> -----------------------------------------------------------------------------[Name] strncpy [Syntax] #include <string.h> char *strncpy( char *s1, const char *s2, size_t n ) ; [Arguments] s1 s2 n Pointer to the destination. Pointer to the source. Character count. [Return] Returns a pointer as same as "s1". [Description] Copies a string of "n" characters pointed by "s2" to the location pointed by "s1". If the length of "s2" string is longer than "n", a null character is not added to the copied string. If the length of "s2" is shorter than "n", null characters are added to the copied string until "n" bytes in total. If the source and the destination are overlapped, the result is undefined. -----------------------------------------------------------------------------8.5 Concatenate a string. <Main,Alarm,Comm> -----------------------------------------------------------------------------[Name] strcat [Syntax] #include <string.h> char *strcat( char *s1, const char *s2 ) ; [Arguments] s1 s2 Pointer to the destination string. Pointer to the string to be concatenated. [Return] Returns a pointer as same as "s1". [Description] Concatenates a strings pointed by "s2" to the last of a string pointed by "s1". A null character is added at last. -----------------------------------------------------------------------------8.6 Concatenate a string. <Main,Alarm,Comm> -----------------------------------------------------------------------------[Name] strncat [Syntax] #include <string.h> char *strncat( char *s1, const char *s2, size_t n ) ; [Arguments] s1 s2 n Pointer to the destination string. Pointer to the string to be concatenated. Character count to be concatenated. [Return] Returns a pointer as same as "s1". [Description] Concatenates a string of "n" characters pointed by "s2" to the last of a string pointed by "s1". In the case of both the length of "s2" string is longer and shorter than "n", a null character is added to the copied string. This returns a pointer which is specified as "s1". -----------------------------------------------------------------------------8.7 Compare two memory blocks. <Main,Alarm,Comm> -----------------------------------------------------------------------------[Name] memcmp [Syntax] #include <string.h> int memcmp( const void *s1, const void *s2, size_t n ) ; [Arguments] s1 s2 n Pointer to a memory block to be compared. Pointer to a memory block to be compared. Byte count to be compared. [Return] Returns the comparison result. Return Comparison result -----------------+--------------------------< 0 s1 < s2 = 0 s1 = s2 > 0 s1 > s2 [Description] Compare "n" byte data in the location pointed by "s1" with one by "s2". -----------------------------------------------------------------------------8.8 Compare two strings. <Main,Alarm,Comm> -----------------------------------------------------------------------------[Name] strcmp [Syntax] #include <string.h> int strcmp( const char *s1, const char *s2 ) ; [Arguments] s1 s2 Pointer to a string to be compared. Pointer to a string to be compared. [Return] Returns the comparison result. Return Comparison result -----------------+--------------------------< 0 s1 < s2 = 0 s1 = s2 > 0 s1 > s2 [Description] Compares a string pointed by "s1" with one by "s2". -----------------------------------------------------------------------------8.9 Compare two strings. <Main,Alarm,Comm> -----------------------------------------------------------------------------[Name] strncmp [Syntax] #include <string.h> int strncmp( const char *s1, const char *s2, size_t n ) ; [Arguments] s1 s2 n Pointer to a string to be compared. Pointer to a string to be compared. Character count to be compared. [Return] Returns the comparison result. Return Comparison result -----------------+--------------------------< 0 s1 < s2 = 0 s1 = s2 > 0 s1 > s2 [Description] Compares "n" characters of a string pointed by "s1" with one by "s2". -----------------------------------------------------------------------------8.10 Find a character in a memory block. <Main,Alarm,Comm> -----------------------------------------------------------------------------[Name] memchr [Syntax] #include <string.h> void *memchr( const void *s, int c, size_t n ) ; [Arguments] s c n Pointer to a memory block in which data is searched. Data to be searched. Character count to be searched. [Return] Returns a pointer to the first matching data. If not found, returns NULL. [Description] Searches "c" in "n" bytes of the memory block specified by "s", and returns the location of the first matching data. "c" is converted to "unsigned char". -----------------------------------------------------------------------------8.11 Find a character in a string. <Main,Alarm,Comm> -----------------------------------------------------------------------------[Name] strchr [Syntax] #include <string.h> char *strchr( const char *s, int c ) ; [Arguments] s c Pointer to a string in which a character is searched. Character to be searched. [Return] Returns a pointer to the first matching location. If not found, returns NULL. [Description] Searches "c" in a string pointed by "s", and returns the location of the first matching character. "c" is converted to "char". -----------------------------------------------------------------------------8.12 Get string length which doesn't include a character. <Main,Alarm,Comm> -----------------------------------------------------------------------------[Name] strcspn [Syntax] #include <string.h> size_t strcspn( const char *s1, const char *s2 ) ; [Arguments] s1 s2 Pointer to a string. Pointer to a string. [Return] Returns length from the top of "s1" to the part in which any characters of "s2" are not contained. [Description] Returns length from the top of string "s1" to the part of "s1" in which any characters included in "s2" are not contained. -----------------------------------------------------------------------------8.13 Find a character position in a string. <Main,Alarm,Comm> -----------------------------------------------------------------------------[Name] strpbrk [Syntax] #include <string.h> char *strpbrk( const char *s1, const char *s2 ) ; [Arguments] s1 s2 Pointer to a string. Pointer to a string. [Return] Returns a pointer to the first position matching to the one of characters included in string "s2". If not matching character, returns NULL. [Description] Searches one of characters included in string "s2" from the top of the string "s1", and returns the first matching position. -----------------------------------------------------------------------------8.14 Find the last character in a string. <Main,Alarm,Comm> -----------------------------------------------------------------------------[Name] strrchr [Syntax] #include <string.h> char *strrchr( const char *s, int c ) ; [Arguments] s c Pointer to a string in which a character is searched. Character to be searched. [Return] Returns a pointer to the last matching location. If not found, returns NULL. [Description] Searches "c" in a string pointed by "s", and returns the location of the last matching character. "c" is converted to "char". -----------------------------------------------------------------------------8.15 Get string length composed by specified character. <Main,Alarm,Comm> -----------------------------------------------------------------------------[Name] strspn [Syntax] #include <string.h> size_t strspn( const char *s1, const char *s2 ) ; [Arguments] s1 s2 Pointer to a string. Pointer to a string. [Return] Returns length from the top of "s1" to the part in which one of characters of "s2" is contained. [Description] Returns length from the top of string "s1" to the part of "s1" in which one of characters included in "s2" is contained. -----------------------------------------------------------------------------8.16 Find a string in a string. <Main,Alarm,Comm> -----------------------------------------------------------------------------[Name] strstr [Syntax] #include <string.h> char *strstr( const char *s1, const char *s2 ) ; [Arguments] s1 s2 Pointer to a string. Pointer to a string. [Return] Returns a pointer to the first matching location in the string "s1". If not found, returns NULL. [Description] Searches a string "s1" in a string "s1", and returns the pointer to the first matching location. -----------------------------------------------------------------------------8.17 Get a token. <Main,Alarm,Comm> -----------------------------------------------------------------------------[Name] strtok [Syntax] #include <string.h> char *strtok( char *s1, const char *s2 ) ; [Arguments] s1 s2 Pointer to a string. (is changed by processing) Pointer to a string. [Return] Returns a pointer to the token. The token is a string terminated by a null character. If no token, returns NULL. [Description] Divide a string "s1" into tokens using each characters of a string "s2" as delimiters. At the first call, "strtok" searches the first token, and returns a pointer to it. If the first character of the string is any token, "strtok" ignores it. At the following calls, specify NULL as the argument "s1". Note that "strtok" function changes a string "s1". -----------------------------------------------------------------------------8.18 Fill data in a memory block. <Main,Alarm,Comm> -----------------------------------------------------------------------------[Name] memset [Syntax] #include <string.h> void *memset( void *s, int c, size_t n ) ; [Arguments] s c n Pointer to a memory block in where "c" is filled. Data to be filled. Byte count. [Return] Returns a pointer as same as "s". [Description] Fills "c" in the "n" byte space from "s". -----------------------------------------------------------------------------8.19 Get string length. <Main,Alarm,Comm> -----------------------------------------------------------------------------[Name] strlen [Syntax] #include <string.h> size_t strlen( const char *s ) ; [Arguments] s Pointer to a string. [Return] Returns length of string "s". [Description] Returns length of string "s". 9. Date and time ( time.h ) -----------------------------------------------------------------------------9.1 Get the current time. <Main,Alarm,Comm> -----------------------------------------------------------------------------[Name] clock [Syntax] #include <time.h> clock_t clock( void ) ; [Arguments] -----[Return] Returns the current system time counter. [Description] Returns the value of the current system time counter. The system time counter is the accumulated count from the system start-up which is counted up every 8 msec. -----------------------------------------------------------------------------9.2 Convert local time to calender time. <Main,Alarm,Comm> -----------------------------------------------------------------------------[Name] mktime [Syntax] #include <time.h> time_t mktime( struct tm *timeptr ) ; [Arguments] timeptr Pointer to a structure "tm". [Return] Returns a calender tim. [Description] Converts the local time data pointed by *timeptr to a calender time. The specified structure "tm" is converted to the standard setting. -----------------------------------------------------------------------------9.3 Get the current time. <Main,Alarm,Comm> -----------------------------------------------------------------------------[Name] time [Syntax] #include <time.h> time_t time( time_t *timer ) ; [Arguments] timer Pointer to a time. [Return] Returns the current time. [Description] Returns the current time as the accumulated second from 1/1/1970 00:00:00. If "timer" is not NULL, also stores the current time in "*timer". The time returned by this function is read from the calender clock of the CNC device. If the calender clock is not set correctly, -1L is returned. -----------------------------------------------------------------------------9.4 Convert time to string. <Main,Alarm,Comm> -----------------------------------------------------------------------------[Name] asctime [Syntax] #include <time.h> char *asctime( const struct tm *timeptr ) ; [Arguments] timeptr Pointer to a structure "tm". [Return] Returns a pointer to a converted string. [Description] Converts a time data pointed by "timeptr" to a string. The format of string is as follows. "Sun Jan 01 00:00:00 1992\n" | | | | | | | | | | | | | | | +| | | | | | +---| | | | | +--------| | | | +-----------| | | +--------------| | +-----------------| +--------------------+------------------------- Newline Year Second Minute Hour Date Month Day Stored buffer for a converted string is the same static buffer as "ctime" function. -----------------------------------------------------------------------------9.5 Convert time to string. <Main,Alarm,Comm> -----------------------------------------------------------------------------[Name] ctime [Syntax] #include <time.h> char *ctime( const time_t *timer ) ; [Arguments] timer Pointer to a tiemr. [Return] Returns a pointer to a converted string. [Description] Converts a time data pointed by "timer" to a string as the local time. The format of string is as follows. "Sun Jan 01 00:00:00 1992\n" | | | | | | | | | | | | | | | +| | | | | | +---| | | | | +--------| | | | +-----------| | | +--------------| | +-----------------| +--------------------+------------------------- Newline Year Second Minute Hour Date Month Day "ctime( timer )" is equivalent to "asctime( localtime( timer ) )". Stored buffer for a converted string is the same static buffer as "asctime" function. -----------------------------------------------------------------------------9.6 Convert time to Greenwich mean time. <Main,Alarm,Comm> -----------------------------------------------------------------------------[Name] gmtime [Syntax] #include <time.h> struct tm *gmtime( const time_t *timer ) ; [Arguments] timer Pointer to a timer. [Return] Returns a pointer to a converted structure "tm". [Description] Converts a timer pointed by "*timer" to a structure "tm" which represents the Greenwich Mean Time. The second from 1/1/1970 00:00:00 is stored in "*timer". This value is usually the return value of "time" function. The static buffer for the structure "tm" is shared by "localtime" function. -----------------------------------------------------------------------------9.7 Convert time to local time. <Main,Alarm,Comm> -----------------------------------------------------------------------------[Name] localtime [Syntax] #include <time.h> struct tm *localtime( const time_t *timer ) ; [Arguments] timer Pointer to a timer. [Return] Returns a pointer to a converted structure "tm". [Description] Converts a timer pointed by "*timer" to a structure "tm" which represents the local time. The second from 1/1/1970 00:00:00 is stored in "*timer". This value is usually the return value of "time" function. The static buffer for the structure "tm" is shared by "gmtime" function. -----------------------------------------------------------------------------9.8 Compute the difference between the two times. <Main,Alarm,Comm> -----------------------------------------------------------------------------[Name] difftime [Syntax] #include <time.h> double difftime( time_t time1, time_t time2 ) ; [Arguments] time_1 time_2 Beginning time. Ending time. [Return] Returns elapsed time in second between "time2" through "time1". [Description] Calculates the difference of time by subtracting "time1" from "time2". 3.2 MS-C extended C standard library ==================================== Lists of Functions ~~~~~~~~~~~~~~~~~~ -------------------------------------------------------------------------Name Function -------------------------------------------------------------------------_chdrive Change the current drive. _dos_findfirst Find the first file whose attributes match the specified ones. _dos_findnext Find the next file whose attributes match the specified ones. _dos_getdiskfree Get disk informations. _expand Change a memory block size. _fcalloc Allocate an array initialized by 0 in memory. _fexpand Change a memory block size. _ffree Free a memory block. _fmalloc Allocate a memory block. _fmemchr Find a character in a memory block. _fmemcmp Compare two memory blocks. _fmemcpy Copy a memory block. _fmemicmp Compare two memory blocks ignoring cases. _fmemmove Move a memory block. _fmemset Fill a memory block with a character. _fmsize Get memory block size in heap. _frealloc Reallocate memory block. _fstrcat Concatenate a string. _fstrchr Find a character in a string. _fstrcmp Compare two strings. _fstrcpy Copy a string. _fstrcspn Get string length which doesn't include a character. _fstricmp Compare two strings ignoring cases. _fstrlen Get string length. _fstrlwr Convert string to lowercase. _fstrncat Concatenate a string. _fstrncmp Compare two strings. _fstrncpy Copy a string. _fstrnicmp Compare two strings ignoring cases. _fstrnset Fill a string with a character. _fstrpbrk Find a character position in a string. _fstrrchr Find the last character in a string. _fstrrev Reverse characters in a string. _fstrset Fill a string with a character. _fstrspn Get string length composed by specified character. _fstrstr Find a string in a string. _fstrtok Get a token. _fstrupr Convert string to uppercase. _getdrive Get the current drive. -------------------------------------------------------------------------Name Function -------------------------------------------------------------------------_lrotl Rotate an unsigned long left. _lrotr Rotate an unsigned long right. _msize Get memory block size in heap. _rotl Rotate unsigned int left. _rotr Rotate unsigned int right. _tolower Convert to lowercase. _toupper Convert to uppercase. alloca Allocate a memory block in stack. cabs Calculate the absolute value of complex number. chdir Change the current directory. close Close a file. creat Create a file. ecvt Convert double value to string. eof Test the end of file. fcvt Convert floating point value to string. gcvt Convert floating point value and store it in a buffer. getch Get a character from the console. getcwd Get the current directory. hypot Calculate the square root of the sum of two squares. isascii Test for ASCII character. itoa Convert an int value to a string. kbhit Check inputting status of keyboard. lseek Move the current file pointer. ltoa Convert a long value to a string. memicmp Compare two memory blocks ignoring cases. mkdir Create a new directory. open Open a file. read Read data from a file. rmdir Delete a directory. stackavail Get available stack size. strcmpi Compare two strings ignoring cases. stricmp Compare two strings ignoring cases. strlwr Convert string to lowercase. strnicmp Compare two strings ignoring cases. strnset Fill a string with a character. strrev Reverse characters in a string. strset Fill a string with a character. strupr Convert string to uppercase. swab Swap two bytes. tell Get the current position of a file. toascii Convert to a ASCII character. ultoa Convert an unsigned long value to a string. write Write data to a file. btom Count characters. chkctype Determine what the character type of the character of interest is. hantozen Convert a 1-byte character to the corresponding 2-byte character. isalkana Determine whether the character of interest is a half-size alphabetic or katakana character. isalnmkana Determine whether the character of interest is a half-size alphanumeric or katakana character. -------------------------------------------------------------------------- -------------------------------------------------------------------------Name Function -------------------------------------------------------------------------isgrkana Determine whether the character of interest is a printable ASCII character (except a half-size space). iskana Determine whether the character of interest is a printable half-size kana character (except a half-size space). iskanji Determine whether the character of interest is byte 1 of a 2-byte character. iskanji2 Determine whether the character of interest is byte 2 of a 2-byte character. iskmoji Determine whether the character of interest is a half-size katakana character. iskpun Determine whether the character of interest is a half-size kana symbol. ispnkana Determine whether the character of interest is a half-size symbol. isprkana Determine whether the character of interest is a printable character. jisalpha Determine whether the character of interest is a full-size alphabetic character. jisdigit Determine whether the character of interest is a full-size numeric character. jishira Determine whether the character of interest is a full-size hiragana character. jiskata Determine whether the character of interest is a full-size katakana character. jiskigou Determine whether the character of interest is a full-size symbol. jisl0 Determine whether the character of interest is a JIS non-kanji character. jisl1 Determine whether the character of interest is a JIS level 1 kanji character. jisl2 Determine whether the character of interest is a JIS level 2 kanji character. jislower Determine whether the character of interest is a full-size lowercase alphabetic character. jisprint Determine whether the character of interest is a printable character. jisspace Determine whether the character of interest is a full-size space. jistojms Convert a JIS kanji code to the corresponding shifted JIS kanji code. jisupper Determine whether the character of interest is a full-size uppercase alphabetic character. jiszen Determine whether the character of interest is a 2-byte character. jmstojis Convert a shifted JIS kanji code to the corresponding JIS kanji code. jtohira Convert a full-size katakana character to the corresponding full-size hiragana character. jtokata Convert a full-size hiragana character to the corresponding full-size katakana character. jtolower Convert a full-size uppercase alphabetic character to the corresponding full-size lowercase alphabetic character. jtoupper Convert a full-size lowercase alphabetic character to the corresponding full-size uppercase alphabetic character. mtob Determine how many bytes are in a character string. nthctype Determine what the character type of a character in a character string is. zentohan Convert a 2-byte character to the corresponding 1-byte character. -------------------------------------------------------------------------Refer the function reference of MS-C for detail. "getch" and "kbhit" functions are available in the Main task. The other functions are available in the Main, the Alarm and the Communication tasks. 3.3 Graphic library =================== Usage of graphic functions ~~~~~~~~~~~~~~~~~~~~~~~~~~ 1. Kinds of the graphic display device. C Executor for FS30i supports the following graphic display device. (Refer also "36crt.man".) (1) VGA Graphic. This is the display device that is equipped with FS30i. This name is derived from the display control LSI (VGA compatible accelerator chip for PC) used for them. The following 4 display modes are supported. A. 640x400 dots, 16 colors for each dot, overlapped with screen (80-column x 25-line). B. 640x400 dots, 256 colors for each dot, not overlapped character screen. C. 640x480 dots, 16 colors for each dot, overlapped with screen (80-column x 30-line). D. 640x480 dots, 256 colors for each dot, not overlapped character screen. the character with the the character with the The application program can specify the graphic mode by calling "_setvideomode" function. 2. Kinds of the graphic functions. C Library provides the following two kinds of the graphic functions. (1) MS-C compatible graphic functions These are the compatible functions with the graphic functions included in the MS-C Library. (2) C Executor original graphic functions These are the original graphic functions for C Executor. 3. Open and close graphics. Call the crt_opengr function before calling of the other graphic functions in the user application. Call the crt_closegr function after a series of graphic drawings. The flow of the processing is as follows. : if ( crt_opengr() ) { /* open graphics */ /* initialize graphic screen */ _setvideomode( _98RESSCOLOR ) ; : } : : : crt_closegr() ; : /* graphic drawings */ /* close graphic */ The graphic drawings are not done without execution of the crt_opengr function. ( _GRNOOUTPUT status will be returned.) The screen switching is inhibited during opening graphics. It is enabled to switch the screen by the execution of the crt_setswt( CRT_SWT_GREN ) function before opening graphics, however, the graphics is closed by the screen switching during opening graphics and graphic drawings are not done until the crt_opengr function will be called again even if graphic functions are called. The screen switching request during opening graphics (such as the screen selection by MDI key) is being pending state until the graphics will be closed, and the pending screen switching will be performed when the crt_closegr function is called. * Refer "36crt.man" about crt_opengr, crt_closegr and crt_setswt functions. 4. Multi-window display. The multi-window displaying is not available for graphics. The graphic screen is always displayed on the full screen even if the multi-windows of character are being displayed. Lists of MS-C compatible functions ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C Executor supports the following MS-C compatible graphic functions. -------------------------------------------------------------------------Name Function -------------------------------------------------------------------------1. _arc Draw an arc or an elliptic arc. 2. _clearscreen Clear screen. 3. _ellipse Draw a circle or an ellipse. 4. _floodfill Paint the closed region. 5. _getactivepage Get the current active page number. 6. _getarcinfo Get the information of the previous arc or pie. 7. _getbkcolor Get the current back ground color. 8. _getcolor Get the current fore ground color. 9. _getcurrentpositionGet the current position in the view coordinate. 10. _getfillmask Get the current fill mask pattern. 11. _getfontinfo Get the current font information. 12. _getgtextextent Get the text extent by pixel unit. 13. _getgtextvector Get the output vector of text. 14. _getimage Get screen image. 15. _getkanji Get the font pattern of Kanji character. 16. _getlinestyle Get the current line style. 17. _getphyscoord Convert view coordinate into physical. 18. _getpixel Get color number the pixel. 19. _gettextposition Get the current output position of text. 20. _gettextwindow Get the text window border. 21. _getvideoconfig Get the graphic configuration. 22. _getviewcoord Convert physical coordinate into view. 23. _getvisualpage Get the current visual page number. 24. _getwritemode Get the current writing mode. 25. _grstatus Get the return status of graphic function. 26. _imagesize Get image buffer size. 27. _kanjisize Get font pattern size of Kanji character. 28. _lineto Draw a line. 29. _moveto Move the current graphic output position. 30. _outgtext Draw a text string using the current font. 31. _outmem Draw a text string in a memory. 32. _outtext Output a text string on the current position. 33. _pie Draw a pie figure. 34. _polygon Draw a polygon. 35. _putimage Put image data on the screen. 36. _rectangle Draw a rectangle. 37. _registerfonts Register font file. 38. _remapallpalette Map colors into all color palette. 39. _remappalette Map a color into a color palette. 40. _setactivepage Set the current active page number. 41. _setbkcolor Set the current back ground color. 42. _setcliprgn Set the clipping region. 43. _setcolor Set the current fore ground color. 44. _setfillmask Set the current fill mask pattern. 45. _setfont Set the current font. 46. _setgtextvector Set the current output vector of text. 47. _setlinestyle Set the current line style. 48. _setpixel Draw a pixel. -------------------------------------------------------------------------Name Function -------------------------------------------------------------------------49. _settextposition Set the current output position of text. 50. _settextrows Set the text row number. 51. _settextwindow Set the text window. 52. _setvideomode Set the screen video mode. 53. _setvideomoderows Set the screen video mode and text row number. 54. _setvieworg Set the origin of the view port. 55. _setviewport Set the clipping region and the view coordinate. 56. _setvisualpage Set the current visual page number. 57. _setwritemode Set the current writing mode. 58. _unregisterfonts Delete registered font file. 59. _wrapon Enable/disable line wrapping. -------------------------------------------------------------------------- Function Reference ~~~~~~~~~~~~~~~~~~ In the following section, the differences from the graphic functions of MS-C are mainly explained. Refer the function reference manual of MS-C for the details of each functions. The concrete behaviours of each functions which are not clearly mentioned in the reference manual of MS-C are described in "<MS-C Compatible Specification>" part of "[Compatibility]" section. -----------------------------------------------------------------------------1. Draw an arc or an elliptic arc. <Main> -----------------------------------------------------------------------------[Name] _arc [Syntax] #include <graph.h> short _arc( short rsx, short rsy, short rex, short rey, short vsx, short vsy, short vex, short vey ) ; [Description] Draws an arc or an elliptic arc. [Compatibility] <MS-C Non-Compatible Specification> (1) The following status is not returned by "_grstatus" function after the execution of this function. The output is clipped by view port. : _GRCLIPPED In this case, the same graphic status is return as _GRNOOUTPUT, and the return value of this function is always "0". (Could not draw normally) (2) There may be the difference from specified rectangle by the drawing precision of this function. <MS-C Compatible Specification> (1) The following graphic statuses are returned by the "_grstatus" function after the execution of this function. Executed successfully Executed in text mode Invalid parameters Not drawn in clipping region : : : : _GROK _GRNOTINPROPERMODE _GRINVALIDPARAMETER _GRNOOUTPUT -----------------------------------------------------------------------------2. Clear screen. <Main> -----------------------------------------------------------------------------[Name] _clearscreen [Syntax] #include <graph.h> void _clearscreen( short area ) ; [Description] Clears specified region and paint it by the current back ground color. [Compatibility] <MS-C Non-Compatible Specification> (1) "_GWINDOW" is not supported for screen specification because MS-C graphic functions for window are not supported. -----------------------------------------------------------------------------3. Draw a circle or an ellipse. <Main> -----------------------------------------------------------------------------[Name] _ellipse [Syntax] #include <graph.h> short _ellipse( short fill, short rsx, short rsy, short rex, short rey ) ; [Description] Draws a circle or an ellipse. [Compatibility] <MS-C Non-Compatible Specification> (1) The following status is not returned by "_grstatus" function after the execution of this function. The output is clipped by view port. : _GRCLIPPED In this case, the same graphic status is return as _GRNOOUTPUT, and the return value of this function is always "0". (Could not draw normally) However, the right value is not returned in case of the _GFILLINTERIOR attribute is specified. (2) The logical operation of "_setwritemode" is not effective to this function in MS-C, but effective in C Executor. Therefore, the outline (border line) may not be drawn by specified logical color in case that _GFILLINTERIOR is specified and _GPSET is not specified in this function. (3) There may be the difference from specified rectangle by the drawing precision of this function. (4) The painting operation may not be done correctly in case that _GFILLINTERIOR is specfied in this function. <MS-C Compatible Specification> (1) The following graphic statuses are returned by the "_grstatus" function after the execution of this function. Executed successfully : Executed in text mode : Invalid parameters : Not painted due to insufficient memory : Not drawn in clipping region : _GROK _GRNOTINPROPERMODE _GRINVALIDPARAMETER _GRINSUFFICIENTMEMORY _GRNOOUTPUT -----------------------------------------------------------------------------4. Paint the closed region. <Main> -----------------------------------------------------------------------------[Name] _floodfill [Syntax] #include <graph.h> short _floodfill( short sx, short sy, short boundary ) ; [Description] Paints the region, where is enclosed by specified border color, by the current fill mask pattern. [Compatibility] <MS-C Non-Compatible Specification> (1) The error status is not returned in case that the start point is specified out of clipping region. (2) The painting may not be execute correctly in case that the same color region as the current color exists in the enclosed region. -----------------------------------------------------------------------------5. Get the current active page number. <Main> -----------------------------------------------------------------------------[Name] _getactivepage [Syntax] #include <graph.h> short _getactivepage( void ) ; [Description] Gets the page number of the plane to be drawn. [Compatibility] This function is compatible with the "_getactivepage" function of MS-C. -----------------------------------------------------------------------------6. Get the information of the previous arc or pie. <Main> -----------------------------------------------------------------------------[Name] _getarcinfo [Syntax] #include <graph.h> short _getarcinfo( struct _xycoord *start, struct _xycoord *end, struct _xycoord *fillpoint ) ; [Description] Gets the view port coordinates of the arc or pie which has been drawn just previously, and gets the start coordinate to paint a pie. [Compatibility] <MS-C Non-Compatible Specification> (1) This function gets the actual drawing start and end coordinates. (2) The painting start coordinate may be different from what MS-C calculates because the calculation method is different between C-EXE and MS-C. <MS-C Compatible Specification> (1) The start point to paint a pie is calculated by supposing the closed region of the arc which is drawn by the start and end points as same as MS-C. -----------------------------------------------------------------------------7. Get the current back ground color. <Main> -----------------------------------------------------------------------------[Name] _getbkcolor [Syntax] #include <graph.h> long _getbkcolor( void ) ; [Description] Gets the current back ground color. [Compatibility] <MS-C Non-Compatible Specification> (1) In MS-C, the actual behaviour of this function is not corresponding to the explanation in the reference manual. In C Executor, the value of palette 0 or index is returned according to the explanation of the manual. (2) The following graphic statuses are returned by the "_grstatus" function after the execution of this function. Executed in text mode : _GRNOTINPROPERMODE <MS-C Compatible Specification> (1) The following graphic statuses are returned by the "_grstatus" function after the execution of this function. Executed successfully : _GROK -----------------------------------------------------------------------------8. Get the current fore ground color. <Main> -----------------------------------------------------------------------------[Name] _getcolor [Syntax] #include <graph.h> short _getcolor( void ) ; [Description] Gets the palette number of the current fore ground color. [Compatibility] This function is compatible with the "_getcolor" function of MS-C. -----------------------------------------------------------------------------9. Get the current position in the view coordinate. <Main> -----------------------------------------------------------------------------[Name] _getcurrentposition [Syntax] #include <graph.h> struct _xycoord _getcurrentposition( void ) ; [Description] Gets the current position in the view coordinate. [Compatibility] This function is compatible with the "_getcurrentposition" function of MS-C. -----------------------------------------------------------------------------10. Get the current fill mask pattern. <Main> -----------------------------------------------------------------------------[Name] _getfillmask [Syntax] #include <graph.h> unsigned char *_getfillmask( unsigned char *mask ) ; [Description] Gets the current fill mask pattern. [Compatibility] <MS-C Non-Compatible Specification> (1) In C Executor, "_setfillmask" sets the fill mask pattern as the default status when the mask data is "full(-1)" for the painting performance. Therefore, this function may return NULL as the return value if any fill mask pattern is registered. -----------------------------------------------------------------------------11. Get the current font information. <Main> -----------------------------------------------------------------------------[Name] _getfontinfo [Syntax] #include <graph.h> short _getfontinfo( struct _fontinfo *fontbuffer ) ; [Description] Gets the current font information and stores it in the buffer. [Compatibility] <MS-C Non-Compatible Specification> (1) Font name. This function returns the font name of ANK character set. When Kanji character set is defined, this returns "standard". (2) Font filename. This function returns the font name. -----------------------------------------------------------------------------12. Get the text extent by pixel unit. <Main> -----------------------------------------------------------------------------[Name] _getgtextextent [Syntax] #include <graph.h> short _getgtextextent( unsigned char *text ) ; [Description] Gets the extent of the specified font by pixel unit on the current font information [Compatibility] This function is compatible with the "_getgtextextent" function of MS-C. -----------------------------------------------------------------------------13. Get the output vector of text. <Main> -----------------------------------------------------------------------------[Name] _getgtextvector [Syntax] #include <graph.h> struct _xycoord _getgtextvector( void ) ; [Description] Gets the output vector of the font text. [Compatibility] This function is compatible with the "_getgtextvector" function of MS-C. -----------------------------------------------------------------------------14. Get screen image. <Main> -----------------------------------------------------------------------------[Name] _getimage [Syntax] #include <graph.h> void _getimage( short rsx, short rsy, short rex, short rey, char *image ) ; [Description] Gets the screen image and stores it in memory. [Compatibility] <MS-C Non-Compatible Specification> (1) The maximum image size is 64K bytes because "huge" data is unavailable in C Executor. <MS-C Compatible Specification> (1) The following graphic statuses are returned by the "_grstatus" function after the execution of this function. Executed successfully Could not store the image Executed in text mode The left-top and the right-bottom coordinates are exchanged. : : : : _GROK _GRERROR _GRNOTINPROPERMODE _GRPARAMETERALTERED -----------------------------------------------------------------------------15. Get the font pattern of Kanji character. <Main> -----------------------------------------------------------------------------[Name] _getkanji [Syntax] #include <graph.h> short _getkanji( unsigned short code, unsigned char *image ) ; [Description] Gets the font pattern of the specified Kanji character. [Compatibility] The character pattern format of MS-C for PC-9800 series and for PC-AT are different each other. This function adopts the PC-9800 format. The storing order of the character pattern array is as follows. 76543210 ........ .......# .##..### ...#...# ......## .##...#. ...#..## ........ ...#..## ...#.... ...#.### ..#..... ..#....# .##..##. ........ ........ 76543210 ........ ...#.... ######.. ...#.... #####... .#..#... #####... .#...... #####... .#...... ######.. #.#..... ...#.... ....##.. ........ ........ The left-half is stored 1st, then the right-half. Binary data stored actually. 0x10,0x10, 0x00,0x01,0x67,0x11,0x03,0x62,0x13,0x00, 0x13,0x10,0x17,0x20,0x21,0x66,0x00,0x00, 0x00,0x10,0xfc,0x10,0xf8,0x48,0xf8,0x40, 0xf8,0x40,0xfc,0xa0,0x10,0x0c,0x00,0x00 [Remarks] Use "crt_reguserchar" function to register the font pattern. -----------------------------------------------------------------------------16. Get the current line style. <Main> -----------------------------------------------------------------------------[Name] _getlinestyle [Syntax] #include <graph.h> unsigned short _getlinestyle( void ) ; [Description] Gets the current line style. [Compatibility] This function is compatible with the "_getlinestyle" function of MS-C. -----------------------------------------------------------------------------17. Convert view coordinate into physical. <Main> -----------------------------------------------------------------------------[Name] _getphyscoord [Syntax] #include <graph.h> struct _xycoord _getphyscoord( short x, short y ) ; [Description] Converts the view coordinate into the physical coordinate. [Compatibility] This function is compatible with the "_getphyscoord" function of MS-C. -----------------------------------------------------------------------------18. Get color number the pixel. <Main> -----------------------------------------------------------------------------[Name] _getpixel [Syntax] #include <graph.h> short _getpixel( short x, short y ) ; [Description] Gets the color number of the specified pixel. [Compatibility] This function is compatible with the "_getpixel" function of MS-C. -----------------------------------------------------------------------------19. Get the current output position of text. <Main> -----------------------------------------------------------------------------[Name] _gettextposition [Syntax] #include <graph.h> struct _rccoord _gettextposition( void ) ; [Description] Gets the current output position of the text. [Compatibility] This function is compatible with the "_gettextposition" function of MS-C. -----------------------------------------------------------------------------20. Get the text window border. <Main> -----------------------------------------------------------------------------[Name] _gettextwindow [Syntax] #include <graph.h> void _gettextwindow( short *r1, short *c1, short *r2, short *c2 ) ; [Description] Gets the window border of the current text window. [Compatibility] This function is compatible with the "_gettextwindow" function of MS-C. -----------------------------------------------------------------------------21. Get the graphic configuration. <Main> -----------------------------------------------------------------------------[Name] _getvideoconfig [Syntax] #include <graph.h> struct videoconfig *_getvideoconfig( struct videoconfig *config ) ; [Description] Gets the information of the hardware about the graphic environment. [Compatibility] <MS-C Non-Compatible Specification> (1) The installation status of VRAM for analog mode. _98EGA(4000H) is set as fixed value for PC-98's video mode. _VGA(0008H) is set as fixed value for the VGA Graphic and PC-AT's video mode. -----------------------------------------------------------------------------22. Convert physical coordinate into view. <Main> -----------------------------------------------------------------------------[Name] _getviewcoord [Syntax] #include <graph.h> struct _xycoord _getviewcoord( short x, short y ) ; [Description] Converts the physical coordinate into the view coordinate. [Compatibility] This function is compatible with the "_getviewcoord" function of MS-C. -----------------------------------------------------------------------------23. Get the current visual page number. <Main> -----------------------------------------------------------------------------[Name] _getvisualpage [Syntax] #include <graph.h> short _getvisualpage( void ) ; [Description] Gets the page number of the currently displayed page. [Compatibility] This function is compatible with the "_getvisualpage" function of MS-C. -----------------------------------------------------------------------------24. Get the current writing mode. <Main> -----------------------------------------------------------------------------[Name] _getwritemode [Syntax] #include <graph.h> short _getwritemode( void ) ; [Description] Gets the current logical writing mode. [Compatibility] This function is compatible with the "_getwritemode" function of MS-C. -----------------------------------------------------------------------------25. Get the return status of graphic function. <Main> -----------------------------------------------------------------------------[Name] _grstatus [Syntax] #include <graph.h> short _grstatus( void ) ; [Description] Gets the status of the graphic function which has been executed just before. [Compatibility] This function is compatible with the "_grstatus" function of MS-C. -----------------------------------------------------------------------------26. Get image buffer size. <Main> -----------------------------------------------------------------------------[Name] _imagesize [Syntax] #include <graph.h> long _imagesize( short rsx, short rsy, short rex, short rey ) ; [Description] Returns the required buffer size for storing the specified image data by byte unit. [Compatibility] This function is compatible with the "_imagesize" function of MS-C. -----------------------------------------------------------------------------27. Get font pattern size of Kanji character. <Main> -----------------------------------------------------------------------------[Name] _kanjisize [Syntax] #include <graph.h> short _kanjisize( short code ) ; [Description] Returns the required buffer size for storing the specified font pattern by byte unit. [Compatibility] This function is compatible with the "_kanjisize" function of MS-C. -----------------------------------------------------------------------------28. Draw a line. <Main> -----------------------------------------------------------------------------[Name] _lineto [Syntax] #include <graph.h> short _lineto( short x, short y ) ; [Description] Draws a line from the current pixel cursor to the specified coordinate. [Compatibility] <MS-C Non-Compatible Specification> (1) The following status is not returned by "_grstatus" function after the execution of this function. The output is clipped by view port. : _GRCLIPPED In this case, the same graphic status is return as _GRNOOUTPUT, and the return value of this function is always "0". (Could not draw normally) <MS-C Compatible Specification> (1) The following graphic statuses are returned by the "_grstatus" function after the execution of this function. Executed successfully Executed in text mode Not drawn in clipping region : _GROK : _GRNOTINPROPERMODE : _GRNOOUTPUT -----------------------------------------------------------------------------29. Move the current graphic output position. <Main> -----------------------------------------------------------------------------[Name] _moveto [Syntax] #include <graph.h> struct xycoord _moveto( short x, short y ) ; [Description] Moves the current graphic output position to the specified coordinate. [Compatibility] This function is compatible with the "_moveto" function of MS-C. -----------------------------------------------------------------------------30. Draw a text string using the current font. <Main> -----------------------------------------------------------------------------[Name] _outgtext [Syntax] #include <graph.h> void _outgtext( unsigned char *text ) ; [Description] Draws a text string on the specified pixel position of the screen using the current font. [Compatibility] This function is compatible with the "_outgtext" function of MS-C. -----------------------------------------------------------------------------31. Draw a text string in a memory. <Main> -----------------------------------------------------------------------------[Name] _outmem [Syntax] #include <graph.h> void _outmem( char *text, short length ) ; [Description] Draws a text string of the specified length stored in the specified memory buffer. [Compatibility] <MS-C Non-Compatible Specification> (1) The text string is displayed using text character. The graphic output is not used. (2) The control code for only '\n' is processed in the text window. The other contorl code such as '\t' is not processed. (3) Nothing is done in case of graphic mode. -----------------------------------------------------------------------------32. Output a text string on the current position. <Main> -----------------------------------------------------------------------------[Name] _outtext [Syntax] #include <graph.h> void _outtext( char *text ) ; [Description] Outputs a text string on the current text position. [Compatibility] <MS-C Non-Compatible Specification> (1) The text string is displayed using text character. The graphic output is not used. (2) The control code for only '\n' is processed in the text window. The other contorl code such as '\t' is not processed. (3) Nothing is done in case of graphic mode. -----------------------------------------------------------------------------33. Draw a pie figure. <Main> -----------------------------------------------------------------------------[Name] _pie [Syntax] #include <graph.h> short _pie( short fill, short rsx, short rsy, short rex, short rey, short vsx, short vsy, short vex, short vey ) ; [Description] Draws a pie figure. [Compatibility] <MS-C Non-Compatible Specification> (1) The following status is not returned by "_grstatus" function after the execution of this function. The output is clipped by view port. : _GRCLIPPED In this case, the same graphic status is return as _GRNOOUTPUT, and the return value of this function is always "0". (Could not draw normally) However, the right value is not returned in case of the _GFILLINTERIOR attribute is specified. (2) The logical operation of "_setwritemode" is not effective to this function in MS-C, but effective in C Executor. Therefore, the outline (border line) may not be drawn by specified logical color in case that _GFILLINTERIOR is specified and _GPSET is not specified in this function. (3) There may be the difference from specified rectangle by the drawing precision of this function. <MS-C Compatible Specification> (1) The following graphic statuses are returned by the "_grstatus" function after the execution of this function. Executed successfully : Executed in text mode : Invalid parameters : Not painted due to insufficient memory : Not drawn in clipping region : _GROK _GRNOTINPROPERMODE _GRINVALIDPARAMETER _GRINSUFFICIENTMEMORY _GRNOOUTPUT -----------------------------------------------------------------------------34. Draw a polygon. <Main> -----------------------------------------------------------------------------[Name] _polygon [Syntax] #include <graph.h> short _polygon( short fill, struct xycoord *points, short numpoints ) ; [Description] Draws a polygon or paints it. [Compatibility] <MS-C Non-Compatible Specification> (1) The following status is not returned by "_grstatus" function after the execution of this function. The output is clipped by view port. : _GRCLIPPED In this case, the same graphic status is return as _GRNOOUTPUT, and the return value of this function is always "0". (Could not draw normally) However, the right value is not returned in case of the _GFILLINTERIOR attribute is specified. (2) The maximum number of apexes which is available in this function is 1024. (3) The painting operation is not performed even if _GFILLINTERIOR is specified in this function. <MS-C Compatible Specification> (1) The following graphic statuses are returned by the "_grstatus" function after the execution of this function. Executed successfully : Executed in text mode : Invalid parameters : Not painted due to insufficient memory : Not drawn in clipping region : _GROK _GRNOTINPROPERMODE _GRINVALIDPARAMETER _GRINSUFFICIENTMEMORY _GRNOOUTPUT -----------------------------------------------------------------------------35. Put image data on the screen. <Main> -----------------------------------------------------------------------------[Name] _putimage [Syntax] #include <graph.h> void _putimage( short sx, short sy, char *image, short action ) ; [Description] Reads image data from the memory and draws it on the screen. [Compatibility] <MS-C Non-Compatible Specification> (1) The following status is not returned by "_grstatus" function after the execution of this function. The output is clipped by view port. : _GRCLIPPED In this case, the same graphic status is return as _GRNOOUTPUT, and the return value of this function is always "0". (Could not draw normally) (2) If a part of the specified graphic image protrudes out of the clipping region, this function draws only image data in the clipping region. <MS-C Compatible Specification> (1) The following graphic statuses are returned by the "_grstatus" function after the execution of this function. Executed successfully : Executed in text mode : Invalid parameters : Not executed due to insufficient memory : Not drawn in clipping region : _GROK _GRNOTINPROPERMODE _GRINVALIDPARAMETER _GRINSUFFICIENTMEMORY _GRNOOUTPUT -----------------------------------------------------------------------------36. Draw a rectangle. <Main> -----------------------------------------------------------------------------[Name] _rectangle [Syntax] #include <graph.h> short _rectangle( short fill, short rsx, short rsy, short rex, short rey ) ; [Description] Draws a rectangle or paints it. [Compatibility] <MS-C Non-Compatible Specification> (1) The following status is not returned by "_grstatus" function after the execution of this function. The output is clipped by view port. : _GRCLIPPED In this case, the same graphic status is return as _GRNOOUTPUT, and the return value of this function is always "0". (Could not draw normally) However, the right value is not returned in case of the _GFILLINTERIOR attribute is specified. (2) The following graphic statuses are returned by the "_grstatus" function after the execution of this function. The left-top and the right-bottom coordinates are exchanged. : _GRPARAMETERALTERED <MS-C Compatible Specification> (1) The following graphic statuses are returned by the "_grstatus" function after the execution of this function. Executed successfully : Executed in text mode : Invalid parameters : Not painted due to insufficient memory : Not drawn in clipping region : _GROK _GRNOTINPROPERMODE _GRINVALIDPARAMETER _GRINSUFFICIENTMEMORY _GRNOOUTPUT -----------------------------------------------------------------------------37. Register font file. <Main> -----------------------------------------------------------------------------[Name] _registerfonts [Syntax] #include <graph.h> short _registerfonts( unsigned char *pathname ) ; [Description] Registers font file and initializes the font library. [Compatibility] <MS-C Non-Compatible Specification> (1) (2) This function doesn't check the specified file pathname. Therefore, the return value of the "_grstatus" function is always "_GROK". The return value of this function is always "1". This function doesn't actually register the font file. <MS-C Compatible Specification> (1) It is required to call this function before outputting text strings using "_outgtext" function. If this function has not been called, "_outgtext" output nothing. -----------------------------------------------------------------------------38. Map colors into all color palette. <Main> -----------------------------------------------------------------------------[Name] _remapallpalette [Syntax] #include <graph.h> short _remapallpalette( long *colors ) ; [Description] Changes color values of all color palettes. [Compatibility] <MS-C Non-Compatible Specification> (1) In MS-C, the actual behaviour of this function is not corresponding to the explanation in the reference manual. In C Executor, this function returns "0" for successfully execution according to the explanation of the manual. "Abnormal ended" never occured. This function sets the suitable number of the color palettes provided on the current video mode. <MS-C Compatible Specification> (1) The following graphic statuses are returned by the "_grstatus" function after the execution of this function. Executed successfully : _GROK [Remarks] When the video mode is "_98RES16COLOR(101)", the number of the color palette is 256 in C Executor, but this function changes only 16 palettes for compatibility with MS-C. -----------------------------------------------------------------------------39. Map a color into a color palette. <Main> -----------------------------------------------------------------------------[Name] _remappalette [Syntax] #include <graph.h> long _remappalette( short index, long color ) ; [Description] Changes color value of the specified color palette. [Compatibility] <MS-C Non-Compatible Specification> (1) In MS-C, the actual behaviour of this function is not corresponding to the explanation in the reference manual. In C Executor, this function returns the color value according to the explanation of the manual when palette #0 is changed by setting of background color. (2) In MS-C, the return value for successfully execution is always previos set color value regardless of the current video mode, but this function always returns the color value just before execution of this function in C Executor. That is, this function doesn't return 0 but the initial setting value for the 1st calling. <MS-C Compatible Specification> (1) The following graphic statuses are returned by the "_grstatus" function after the execution of this function. Executed successfully Invalid palette number : _GROK : _GRINVALIDPARAMETER -----------------------------------------------------------------------------40. Set the current active page number. <Main> -----------------------------------------------------------------------------[Name] _setactivepage [Syntax] #include <graph.h> short _setactivepage( short page ) ; [Description] Sets the graphic plane to be drawn. [Compatibility] This function is compatible with the "_setactivepage" function of MS-C. -----------------------------------------------------------------------------41. Set the current back ground color. <Main> -----------------------------------------------------------------------------[Name] _setbkcolor [Syntax] #include <graph.h> long _setbkcolor( long color ) ; [Description] Sets the current back ground color. [Compatibility] <MS-C Non-Compatible Specification> (1) In MS-C, the actual behaviour of this function is not corresponding to the explanation in the reference manual. In C Executor, the value of palette 0 or index is returned according to the explanation of the manual. (2) The following status is not returned by "_grstatus" function after the execution of this function. _GRPARAMETERALTERED <MS-C Compatible Specification> (1) The following graphic statuses are returned by the "_grstatus" function after the execution of this function. Executed successfully : _GROK -----------------------------------------------------------------------------42. Set the clipping region. <Main> -----------------------------------------------------------------------------[Name] _setcliprgn [Syntax] #include <graph.h> void _setcliprgn( short rsx, short rsy, short rex, short rey ) ; [Description] Sets the clipping region for the graphic output. [Compatibility] This function is compatible with the "_setcliprgn" function of MS-C. -----------------------------------------------------------------------------43. Set the current fore ground color. <Main> -----------------------------------------------------------------------------[Name] _setcolor [Syntax] #include <graph.h> short _setcolor( short color ) ; [Description] Sets the color which is corresponding to the specified palette number as the current color. [Compatibility] This function is compatible with the "_setcolor" function of MS-C. -----------------------------------------------------------------------------44. Set the current fill mask pattern. <Main> -----------------------------------------------------------------------------[Name] _setfillmask [Syntax] #include <graph.h> void _setfillmask( unsigned char *mask ) ; [Description] Sets the current fill mask pattern. [Compatibility] <MS-C Non-Compatible Specification> (1) In C Executor, this function sets the fill mask pattern as the default status when the mask data is "full(-1)" for the painting performance. -----------------------------------------------------------------------------45. Set the current font. <Main> -----------------------------------------------------------------------------[Name] _setfont [Syntax] #include <graph.h> short _setfont( unsigned char *options ) ; [Description] Sets the current font for "_outgtext" function. [Compatibility] <MS-C Non-Compatible Specification> (1) (2) (3) Only option "t" (Set fontname) is supported. Specify the typename placed in single quotation marks ('') after the option "t". The available typenames are as follows. -----------------------------------------------------------------Typename Character set -----------------------------------------------------------------standard ANK character set (Standard) graph1 ANK character set (Graphic 1) graph2 ANK character set (Graphic 2) graph3 ANK character set (Graphic 3) large ANK character set (Large character) micro ANK character set (Small character) fanuc Kanji character set (FANUC Kanji set) The return code is always "1". -----------------------------------------------------------------------------46. Set the current output vector of text. <Main> -----------------------------------------------------------------------------[Name] _setgtextvector [Syntax] #include <graph.h> struct _xycoord _setgtextvector( short x, short y ) ; [Description] Sets the current output vector of the font text. [Compatibility] <MS-C Non-Compatible Specification> (1) In MS-C, it is possible to specify such as 45[deg](1,1), but impossible in C Executor. "_GRERROR" is returned by "_grstatus" function for the invalid setting values which are not described in the reference manual. The available output directions are as follows. Only "sign" of value has a significance. -----------------------------------------------------------------( x, y ) Output direction -----------------------------------------------------------------( 0, 0 ) Not changed. ( 1, 0 ) Horizontal. (default) ( 0, 1 ) Rotated 90[deg] to CCW. (-1, 0 ) Rotated 180[deg]. ( 0,-1 ) Rotated 247[deg] to CCW. -----------------------------------------------------------------------------47. Set the current line style. <Main> -----------------------------------------------------------------------------[Name] _setlinestyle [Syntax] #include <graph.h> void _setlinestyle( unsigned short mask ) ; [Description] Sets the current line style. [Compatibility] This function is compatible with the "_setlinestyle" function of MS-C. -----------------------------------------------------------------------------48. Draw a pixel. <Main> -----------------------------------------------------------------------------[Name] _setpixel [Syntax] #include <graph.h> short _setpixel( short x, short y ) ; [Description] Draws a pixel in specified position by the current color. [Compatibility] This function is compatible with the "_setpixel" function of MS-C. -----------------------------------------------------------------------------49. Set the current output position of text. <Main> -----------------------------------------------------------------------------[Name] _settextposition [Syntax] #include <graph.h> struct _rccoord _settextposition( short row, short column ) ; [Description] Move the current position for outputting text. [Compatibility] This function is compatible with the "_settextposition" function of MS-C. -----------------------------------------------------------------------------50. Set the text row number. <Main> -----------------------------------------------------------------------------[Name] _settextrows [Syntax] #include <graph.h> short _settextrows( short rows ) ; [Description] Sets the text row number. [Compatibility] <MS-C Non-Compatible Specification> (1) The maximum line number of each video mode is set for every specification. <MS-C Compatible Specification> (1) The maximum line number of the video mode is set by specifying "_MAXTEXTROWS(-1)". (2) "_grstatus" function returns "_GRINVALIDPARAMETER" if "rows" is negative. (3) "_grstatus" function returns "_GRPARAMETERALTERED" if the correct parameter is specified or the current video mode is not text mode. -----------------------------------------------------------------------------51. Set the text window. <Main> -----------------------------------------------------------------------------[Name] _settextwindow [Syntax] #include <graph.h> void _settextwindow( short r1, short c1, short r2, short c2 ) ; [Description] Sets the current text window. [Compatibility] <MS-C Non-Compatible Specification> (1) It is impossible to scroll the contents of the text window. [Remarks] The "crt_setmode" function makes the current text window ineffective. -----------------------------------------------------------------------------52. Set the screen video mode. <Main> -----------------------------------------------------------------------------[Name] _setvideomode [Syntax] #include <graph.h> short _setvideomode( short mode ) ; [Description] Selects the display mode of the screen. [Compatibility] <MS-C Non-Compatible Specification> (1) Specify one of the following video modes. When any mode including parentheses is specified, this function returns "0" (error), but the initialization of graphic screen is done correctly. (In this case, the "_grstatus()" function returns "_GRMODENOTSUPPORTED".) VGA Graphic -------------------------------------------------------------------Mode Size(Text) Palette (Color mode) -------------------------------------------------------------------_98RESS16COLOR 640x400(80x25) 16 colors (PC-98) _98RESS8COLOR (_98RESSCOLOR) -------------------------------------------------------------------_98RES16COLOR 640x400 256 colors (PC-98) _98RES8COLOR (_98RESCOLOR) -------------------------------------------------------------------_VRES16COLOR 640x480(80x30) 16 colors (PC-AT) _VRES16EXCOLOR -------------------------------------------------------------------_VRES256COLOR 640x480 256 colors (PC-AT) -------------------------------------------------------------------_98TEXT80 Text mode(80x25) 16 colors _TEXTC80 -------------------------------------------------------------------This function sets the following modes for "_DEFAULTMODE", "_MAXCOLORMODE" or "_MAXRESMODE". ----------------------------------Mode VGA Graphic ----------------------------------_DEFAULTMODE _98TEXT80,_TEXTC80 _MAXCOLORMODE _VRES256COLOR _MAXRESMODE _VRES16COLOR ----------------------------------- (2) Use "_CEXERES16COLOR" mode for arbitrary plane size and text mode. Symbol "_CEXERES16COLOR" is definded in "graph.h". For the setting of this mode, the function syntax is changed as follows. #include <crt.h> #include <graph.h> short _setvideomode( _CEXERES16COLOR, short origin, short height, short TXmode ) ; origin height TXmode The origin of the graphic plane in Y direction. The origin of the graphic plane in X direction. The text mode. Specify one of following mode for the text mode. CRT_MODE_V25_0 80-column x 25-line (starting CRT_MODE_V25_1 80-column x 25-line (starting CRT_MODE_V25_2 80-column x 25-line (starting CRT_MODE_V25_3 80-column x 25-line (starting CRT_MODE_V25_4 80-column x 25-line (starting CRT_MODE_V25_5 80-column x 25-line (starting CRT_MODE_V30 80-column x 30-line These text mode symbols are defined in "crt.h". line: line: line: line: line: line: 1) 2) 3) 4) 5) 6) "_CEXERES16COLOR" mode is similar to "_VRES16COLOR" mode except the variable display size. (3) If non-supported mode is specified, "_GRMODENOTSUPPORTED" is returned by the "_grstatus" function. This is originally the return value when the analog video mode is specified without analog VRAM system. (4) The cursor current position is initialized and moved to the home position after the execution of this function. If the text screen mode (column or line number in the screen) is changed by this function, the text screen environment is initialized (as same as "crt_setmode" does), and all setting about text screen are set as initial state. Set the text screen environment (cursor display mode, character set, etc.) if necessary. [Remarks] Use "crt_setmode" function or "_setvideomode( _CEXRES16COLOR,.. )" to change the text mode. -----------------------------------------------------------------------------53. Set the screen video mode and text row number. <Main> -----------------------------------------------------------------------------[Name] _setvideomoderows [Syntax] #include <graph.h> short _setvideomoderows( short mode, short rows ) ; [Description] Sets the video mode for the text operation and sets the text row number. [Compatibility] <MS-C Non-Compatible Specification> (1) The details of the video mode are different from MS-C's. Refer "_setvideomode" function for more information. "_CEXERES16COLOR" mode is not allowed in this function. (2) The text row number is always set as the maximum line number of the specified video mode even if any "rows" is specified. (3) If non-supported mode is specified, "_GRMODENOTSUPPORTED" is returned by the "_grstatus" function. This is originally the return value when the analog video mode is specified without analog VRAM system. (4) The cursor current position is initialized and moved to the home position after the execution of this function. [Remarks] Use "crt_setmode" function to change the text mdoe. -----------------------------------------------------------------------------54. Set the origin of the view port. <Main> -----------------------------------------------------------------------------[Name] _setvieworg [Syntax] #include <graph.h> struct xycoord _setvieworg( short x, short y ) ; [Description] Moves the origin of the view port to the specified physical position. [Compatibility] This function is compatible with the "_setvieworg" function of MS-C. -----------------------------------------------------------------------------55. Set the clipping region and the view coordinate. <Main> -----------------------------------------------------------------------------[Name] _setviewport [Syntax] #include <graph.h> void _setviewport( short rsx, short rsy, short rex, short rey ) ; [Description] Restricts to the graphic output in the specified region on the screen and sets the origin of the viewport coordinate on its left-upper corner. [Compatibility] This function is compatible with the "_setviewport" function of MS-C. -----------------------------------------------------------------------------56. Set the current visual page number. <Main> -----------------------------------------------------------------------------[Name] _setvisualpage [Syntax] #include <graph.h> short _setvisualpage( short page ) ; [Description] Set the page number of the currently displayed page. [Compatibility] This function is compatible with the "_setvisualpage" function of MS-C. -----------------------------------------------------------------------------57. Set the current writing mode. <Main> -----------------------------------------------------------------------------[Name] _setwritemode [Syntax] #include <graph.h> short _setwritemode( short action ) ; [Description] Sets the current logical writing mode. [Compatibility] <MS-C Non-Compatible Specification> (1) The effectivity of the logical writing mode is different between PC-98's MS-C and PC-AT's. In C Executor, the effectivity of the logical writing mode is as follows. ( x: effective o: ineffective blank: N/A ) -------------------------------------------------------------------------Name Function Drawing Painting -------------------------------------------------------------------------_setpixel Draw a pixel. x _arc Draw an arc or an elliptic arc. x _lineto Draw a line. x _ellipse Draw a circle or an ellipse. x o _pie Draw a pie figure. x o _polygon Draw a polygon. x _rectangle Draw a rectangle. x x _floodfill Paint the closed region. o -------------------------------------------------------------------------- -----------------------------------------------------------------------------58. Delete registered font file. <Main> -----------------------------------------------------------------------------[Name] _unregisterfonts [Syntax] #include <graph.h> void _unregisterfonts( void ) ; [Description] Delete registered font file and free the font library memory. [Compatibility] <MS-C Non-Compatible Specification> (1) This function doesn't actually delete font file. <MS-C Compatible Specification> (1) "_outgtext" function outputs nothing after calling this function. "_registerfonts" function must be called to output text string by "_outgtext" function again. -----------------------------------------------------------------------------59. Enable/disable line wrapping. <Main> -----------------------------------------------------------------------------[Name] _wrapon [Syntax] #include <graph.h> short _wrapon( short option ) ; [Description] Enable or disable wrapping of the text line. [Compatibility] This function is compatible with the "_wrapon" function of MS-C. MS-C graphic function compatibility list ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ "x" mark: Available C-Card : Character-card Blank: NOT available ---------------------------------------------------------------------------Name Function VGA C-Card ---------------------------------------------------------------+----+------_arc Draw an arc or an elliptic arc. x _clearscreen Clear screen. x _displaycursor Enable/disable the cursor. _ellipse Draw a circle or an ellipse. x _floodfill Paint the closed region. x _getactivepage Get the current active page number. x _getarcinfo Get the information of the previous x arc or pie. _getbkcolor Get the current back ground color. x _getcolor Get the current fore ground color. x _getcurrentposition Get the current position in the view x coordinate. _getfillmask Get the current fill mask pattern. x _getfontinfo Get the current font information. x _getgtextextent Get the text extent by pixel unit. x _getgtextvector Get the output vector of text. x _getimage Get screen image. x _getkanji Get the font pattern of Kanji character. x _getlinestyle Get the current line style. x _getphyscoord Convert view coordinate into physical. x _getpixel Get color number the pixel. x _gettextcolor Get the current text color. _gettextcursor Get the current cursor attribute. _gettextposition Get the current output position of text. x _gettextwindow Get the text window border. x _getvideoconfig Get the graphic configuration. x _getviewcoord Convert physical coordinate into view. x _getvisualpage Get the current visual page number. x _getwritemode Get the current writing mode. x _grstatus Get the return status of graphic x function. _imagesize Get image buffer size. x _kanjisize Get font pattern size of Kanji character. x _lineto Draw a line. x _moveto Move the current graphic output position. x _outgtext Draw a text string using the current font. x _outmem Draw a text string in a memory. x _outtext Output a text string on the current x position. _pie Draw a pie figure. x _polygon Draw a polygon. x _putimage Put image data on the screen. x _rectangle Draw a rectangle. x _registerfonts Register font file. x _remapallpalette Map colors into all color palette. x _remappalette Map a color into a color palette. x _scrolltextwindow Scroll the contents in the text window. _setactivepage Set the current active page number. x _setbkcolor Set the current back ground color. x _setcliprgn Set the clipping region. x ---------------------------------------------------------------------------Name Function VGA C-Card ---------------------------------------------------------------+----+------_setcolor Set the current fore ground color. x _setfillmask Set the current fill mask pattern. x _setfont Set the current font. x _setgtextvector Set the current output vector of text. x _setlinestyle Set the current line style. x _setpixel Draw a pixel. x _settextcolor Set the current text color. _settextcursor Set the current cursor attribute. _settextposition Set the current output position of text. x _settextrows Set the text row number. x _settextwindow Set the text window. x _setvideomode Set the screen video mode. x _setvideomoderows Set the screen video mode and text row x number. _setvieworg Set the origin of the view port. x _setviewport Set the clipping region and the view x coordinate. _setvisualpage Set the current visual page number. x _setwritemode Set the current writing mode. x _unregisterfonts Delete registered font file. x _wrapon Enable/disable line wrapping. x ---------------------------------------------------------------------------- Lists of C Executor original graphic functions ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C Executor graphic library supports the following original graphic functions in addition to MS-C compatible functions. -------------------------------------------------------------------------Name Function -------------------------------------------------------------------------1. gr_displaychar Draw a standard size character. 2. gr_displayfourlargeDraw a quad size character. 3. gr_displaysixlarge Draw a hex size character. 4. _putpattern Put monochrome image data. 5. _getpattern Get monochrome image data. 6. gr_dispstr Draw a standard size string. 7. gr_disp6str Draw a hex size string. 8. gr_bitblt Copy image data. 9. gr_disp4str Draw a quad size string. 10. gr_displaysmlchar Draw a small size character. 11. gr_dispsstr Draw a small size string. 12. gr_displayfchar Draw a FANUC character. 13. gr_dispfstr Draw a FANUC character string. 14. gr_disp9ifchar Draw 9-inch font character. 15. gr_disp9ifstr Draw 9-inch font character string. 16. mmc_line_b Draw a line between specified two points. 17. mmc_polyline Draw a polyline. 18. mmc_circle_b Draw a circle. 19. mmc_ellipse_b Draw an ellipse. 20. mmc_pie_b Draw a pie figure. 21. mmc_arc_b Draw an arc. 22. mmc_gettext Get character in the specified area. 23. mmc_puttext Put character data on memory to text screen. 24. mmc_textsize Get required byte size for getting character. -------------------------------------------------------------------------- Function Reference ~~~~~~~~~~~~~~~~~~ -----------------------------------------------------------------------------1. Draw a standard size character. <Main> -----------------------------------------------------------------------------[Name] gr_displaychar [Syntax] #include <graph.h> void gr_displaychar( int code, short cx, short cy, short fg, short bg ) ; [Arguments] code cx, cy fg bg Character code to be drawn. Coordinate of the left-upper corner at where the character is drawn. Character color. Background color. [Return] -----[Description] Draws the specified character whose size is same as the text's one (i.e. 8 x 16 dots, 16 x 16 dots for Kanji character) on the graphic screen. Specify the character color and the background color using palette index number. Only character is drawn if -32768 (0x8000) is specified as the background color. When specifying a 2-byte character code with the argument code, store the first byte in the upper byte. When drawing, for example, (SHIFT-JIS code 8ABF), specify as follows. gr_displaychar (0x8ABF, ...) -----------------------------------------------------------------------------2. Draw a quad size character. <Main> -----------------------------------------------------------------------------[Name] gr_displayfourlarge [Syntax] #include <graph.h> void gr_displayfourlarge( int code, short cx, short cy, short fg, short bg ) ; [Arguments] code cx, cy fg bg Character code to be drawn. Coordinate of the left-upper corner at where the character is drawn. Character color. Background color. [Return] -----[Description] Draws the specified character whose dot matrix is 16 x 32 dots on the graphic screen. Specify the character color and the background color using palette index number. Only character is drawn if -32768 (0x8000) is specified as the background color. This function can't draw 2-byte characters such as Japanese Kanji characters. It can draw only half-size characters whose codes are 0x20 to 0x7F. -----------------------------------------------------------------------------3. Draw a hex size character. <Main> -----------------------------------------------------------------------------[Name] gr_displaysixlarge [Syntax] #include <graph.h> void gr_displaysixlarge( int code, short cx, short cy, short fg, short bg ) ; [Arguments] code cx, cy fg bg Character code to be drawn. Coordinate of the left-upper corner at where the character is drawn. Character color. Background color. [Return] -----[Description] Draws the specified hex size character whose dot matrix is 24 x 32 dots on the graphic screen. Specify the character color and the background color using palette index number. Only character is drawn if -32768 (0x8000) is specified as the background color. This function can draw only 'SPACE', '0'-'9', 'A'-'Z', '.' and '-'. -----------------------------------------------------------------------------4. Put monochrome image data. <Main> -----------------------------------------------------------------------------[Name] _putpattern [Syntax] #include <graph.h> void _putpattern( short x, short y, void *image, short action, short fg, short bg ) ; [Arguments] x, y image action fg bg Coordinate of the left-upper corner at where the monochrome image is put. Buffer in where monochrome image is stored. Logical writing mode. Foreground color. Background color. [Return] -----[Description] Puts the monochrome image pattern stored in "image" in the rectangle regtion whose left-upper corner is "x,y" on the graphic screen. Specify the logical writing mode, monochrome image data in buffer and image data on the screen are operated according to this command, in "action". The logical writing mode is defined in "graph.h". Specify the character color and the background color using palette index number. Only image data is drawn if -32768 (0x8000) is specified as the background color. The image buffer size must be specified by word (2-byte) unit. The buffer size (for monochrome image data) is calculated by the next equation. Size(byte) = ([WIDTH]+15)/16*2*[HEIGHT]+4 The maximum imaga size that is available for this function is 4K bytes. [Example] The following monochrome image data (19x8 dots) is drawn. The leading 2-word data in the buffer are the height and the width of the image pattern data. 0 1 2 3 4 5 6 7 +---- 19 dots -----+ | | fedcba9876543210 765 ................ ... .####..####..#.. .#. .#...#.#...#.##. ##. .#...#.#...#.#.# .#. .####..####..#.. .#. .#..#..#.....#.. .#. .#...#.#.....#.. .#. ................ ... -+ | | | 8 dots | | | -+ The following program draws the above monochrome image data. #include <graph.h> #define Blue #define White 1 7 unsigned short image_rpm[18] = { 0x0013,0x0008 /* 19 x 8 Dot */ ,0x0000,0x0000 ,0x79e4,0x4000 ,0x4516,0xc000 ,0x4515,0x4000 ,0x79e4,0x4000 ,0x4904,0x4000 ,0x4504,0x4000 ,0x0000,0x0000 } ; void example( short x, short y ) { char *image ; image = (char *)&image_rpm[0] ; _putpattern( x, y, image, _GPSET, Blue, White ) ; return ; } -----------------------------------------------------------------------------5. Get monochrome image data. <Main> -----------------------------------------------------------------------------[Name] _getpattern [Syntax] #include <graph.h> void _getpattern( short rsx, short rsy, short rex, short rey, void *image, short color ) ; [Arguments] rsx, rsy, rex, rey image color Coordinate of the rectangle region from wher the monochrome image data is got. Buffer in where the monochrome image data is stored. Color to be searched. [Return] -----[Description] Gets the monochrome image data, whose color is same as the specified color palette index number, in the specified rectangle region. And stores it in the "image". The buffer size muse be enough big to store the image data. The buffer size is calculated by the next equation. Size(byte) = ([WIDTH]+15)/16*2*[HEIGHT]+4 The maximum imaga size that is available for this function is 4K bytes. [Example] The following program displays a cursor. #include <graph.h> #include <malloc.h> void example( short rsx, short rsy, short ch_num, short OldColor, short ForColor, short BakColor ) { char *image ; long image_size ; short w, h ; w = ch_num*8 ; h = 16 ; image_size = ( w+15 ) / 16 * 2 * h + 4 ; if ( image_size > 4096L ) return ; image = malloc( (short)image_size ) ; if ( image == NULL ) return ; _getpattern( rsx, rsy, rsx+w-1, rsy+h-1, image, OldColor ) ; _putpattern( rsx, rsy, image, _GPSET, ForColor, BakColor ) ; free( image ) ; return ; } -----------------------------------------------------------------------------6. Draw a standard size string. <Main> -----------------------------------------------------------------------------[Name] gr_dispstr [Syntax] #include <graph.h> void gr_dispstr( char *str, short cx, short cy, short fg, short bg ) ; [Arguments] str cx, cy fg bg Character string to be drawn. Coordinate of the left-upper corner at where the character is drawn. Character color. Background color. [Return] -----[Description] Draws character string (also Kanji character is available) on the graphic screen. Specify the character color and the background color using palette index number. Only character is drawn if -32768 (0x8000) is specified as the background color. -----------------------------------------------------------------------------7. Draw a hex size string. <Main> -----------------------------------------------------------------------------[Name] gr_disp6str [Syntax] #include <graph.h> void gr_disp6str( char *str, short cx, short cy, short fg, short bg ) ; [Arguments] str cx, cy fg bg Character string to be drawn. Coordinate of the left-upper corner at where the character is drawn. Character color. Background color. [Return] -----[Description] Draws large-size character (24x32 dots) string on the graphic screen. Specify the character color and the background color using palette index number. Only character is drawn if -32768 (0x8000) is specified as the background color. This function can draw only 'SPACE', '0'-'9', 'A'-'Z', '.' and '-'. -----------------------------------------------------------------------------8. Copy image data. <Main> -----------------------------------------------------------------------------[Name] gr_bitblt [Syntax] #include <graph.h> void gr_bitblt( short rsx, short rsy, short rex, short rey, short cx, short cy ) ; [Arguments] rsx, rsy, rex, rey cx, cy Coordinate of the source rectangle. Destination (upper-left) coordinate. [Return] -----[Description] Copys the image data in the specified rectangle region to the specified destination on the screen. -----------------------------------------------------------------------------9. Draw a quad size string. <Main> -----------------------------------------------------------------------------[Name] gr_disp4str [Syntax] #include <graph.h> void gr_disp4str( char *str, short cx, short cy, short fg, short bg ) ; [Arguments] str cx, cy fg bg Character string to be drawn. Coordinate of the left-upper corner at where the character is drawn. Character color. Background color. [Return] -----[Description] Draws quad-size (16x32 dots) character string on the graphic screen. Specify the character color and the background color using palette index number. Only character is drawn if -32768 (0x8000) is specified as the background color. This function can't draw 2-byte characters such as Japanese Kanji characters. It can draw only half-size characters whose codes are 0x20 to 0x7F. -----------------------------------------------------------------------------10. Draw a small size character. <Main> -----------------------------------------------------------------------------[Name] gr_displaysmlchar [Syntax] #include <graph.h> void gr_displaysmlchar( int code, short cx, short cy, short fg, short bg ) ; [Arguments] code cx, cy fg bg Character code to be drawn. Coordinate of the left-upper corner at where the character is drawn. Character color. Background color. [Return] -----[Description] Draws small size (8x8 dots) character on the graphic screen. Specify the character color and the background color using palette index number. Only character is drawn if -32768 (0x8000) is specified as the background color. This function draws only characters whose codes are 0x20 - 0x5F. If lowercase character is specified, the converted uppercase character is drawn instead. Dot size of drawn character is as follows. Display mode Dot size Note -----------------------+---------------+---------------------------80-column x 25-line(*1) 8 x 8 14" type (*1) 25-line - 30-line -----------------------------------------------------------------------------11. Draw a small size string. <Main> -----------------------------------------------------------------------------[Name] gr_dispsstr [Syntax] #include <graph.h> void gr_dispsstr( char *str, short cx, short cy, short fg, short bg ) ; [Arguments] str cx, cy fg bg Character string to be drawn. Coordinate of the left-upper corner at where the character is drawn. Character color. Background color. [Return] -----[Description] Draws small size (8x8 dots) character string on the graphic screen. Specify the character color and the background color using palette index number. Only character is drawn if -32768 (0x8000) is specified as the background color. This function draws only characters whose codes are 0x20 - 0x5F. If lowercase character is specified, the converted uppercase character is drawn instead. Dot size of drawn character is as follows. Display mode Dot size Note -----------------------+---------------+---------------------------80-column x 25-line(*1) 8 x 8 (*1) 25-line - 30-line -----------------------------------------------------------------------------12. Draw a FANUC character. <Main> -----------------------------------------------------------------------------[Name] gr_displayfchar [Syntax] #include <graph.h> void gr_displayfchar( unsigned int code, short cx, short cy, short fg, short bg ) ; [Arguments] code cx, cy fg bg Character code to be drawn. Coordinate of the left-upper corner at where the character is drawn. Character color. Background color. [Return] -----[Description] Draws a character which is specified by FANUC character code on the graphic screen. Specify the character color and the background color using palette index number. Only character is drawn if -32768 (0x8000) is specified as the background color. -----------------------------------------------------------------------------13. Draw a FANUC character string. <Main> -----------------------------------------------------------------------------[Name] gr_dispfstr [Syntax] #include <graph.h> void gr_dispfstr( unsigned int *code, unsigned int len, short cx, short cy, short fg, short bg ) ; [Arguments] code len cx, cy fg bg Array of FANUC character code (0x0000 - 0xFFFF). Length of character string. Coordinate of the left-upper corner at where the character is drawn. Character color. Background color. [Return] -----[Description] Draws a character string which is specified by FANUC character code on the graphic screen. Store FANUC code (16-bit) of drawn character in each element of the array "code". Store character length in "len". Specify the character color and the background color using palette index number. Only character is drawn if -32768 (0x8000) is specified as the background color. -----------------------------------------------------------------------------14. Draw 9-inch font character. <Main> -----------------------------------------------------------------------------[Name] gr_disp9ifchar [Syntax] #include <graph.h> void gr_disp9ifchar( int code, short cx, short cy, short fg, short bg) ; [Arguments] code cx, cy fg bg Character code to be drawn. Coordinate of the left-upper corner at where the character is drawn. Character color. Background color. [Return] -----[Description] Draws 9-inch font character (16x25 dots or 32x25 dots for Kanji character) on the graphic screen. Specify the character color and the background color using palette index number. Only character is drawn if -32768 (0x8000) is specified as the background color. [Remarks] Specified character is drawn using FANUC character-generator and FANUC Kanji-set. -----------------------------------------------------------------------------15. Draw 9-inch font character string. <Main> -----------------------------------------------------------------------------[Name] gr_disp9ifstr [Syntax] #include <graph.h> void gr_disp9ifstr( unsigned char *str, short cx, short cy, short fg, short bg) ; [Arguments] str cx, cy fg bg Character string to be drawn. Coordinate of the left-upper corner at where the character is drawn. Character color. Background color. [Return] -----[Description] Draws character string (also Kanji character is available) on the graphic screen. Specify the character color and the background color using palette index number. Only character is drawn if -32768 (0x8000) is specified as the background color. [Remarks] Specified character is drawn using FANUC character-generator and FANUC Kanji-set. -----------------------------------------------------------------------------16. Draw a line between specified two points. <Main> -----------------------------------------------------------------------------[Name] mmc_line_b [Syntax] #include <fgraph.h> short mmc_line_b( short x1, short y1, short x2, short y2 ) ; [Arguments] x1, y1 x2, y2 View port coordinates of line start point. View port coordinates of line end point. [Return] Returns non-0 value if successful, or 0 if any error. [Description] Draws a line between specified two points. -----------------------------------------------------------------------------17. Draw a polyline. <Main> -----------------------------------------------------------------------------[Name] mmc_polyline [Syntax] #include <fgraph.h> void mmc_polyline( const struct _xycoord *points, short numpoints ) ; [Arguments] points numpoints Array of view port coordinates of apexes. Number of apexes of polyline. [Return] -----[Description] Draws a polyline. -----------------------------------------------------------------------------18. Draw a circle. <Main> -----------------------------------------------------------------------------[Name] mmc_circle_b [Syntax] #include <fgraph.h> short mmc_circle_b( short control, short xc, short yc, short r ) ; [Arguments] control xc, yc r Control flag. View port coordinates of the circle center. Radius. [Return] Returns non-0 value if successful, or 0 if any error. [Description] Draws a circle. Specify one of the following symbols for "Control flag". Symbol Purpose ---------------+---------------------------------------------_GFILLINTERIOR Fills inside of the object with the current fill mask pattern. _GBORDER Draws only border line, not fills inside. -----------------------------------------------------------------------------19. Draw an ellipse. <Main> -----------------------------------------------------------------------------[Name] mmc_ellipse_b [Syntax] #include <fgraph.h> short mmc_ellipse_b( short control, short xc, short yc, short xr, short yr ) ; [Arguments] control xc, yc xr yr Control flag. View port coordinate of the ellipse center. X-directional radius. Y-directional radius. [Return] Returns non-0 value if successful, or 0 if any error. [Description] Draws an ellipse. Specify one of the following symbols for "Control flag". Symbol Purpose ---------------+---------------------------------------------_GFILLINTERIOR Fills inside of the object with the current fill mask pattern. _GBORDER Draws only border line, not fills inside. -----------------------------------------------------------------------------20. Draw a pie figure. <Main> -----------------------------------------------------------------------------[Name] mmc_pie_b [Syntax] #include <fgraph.h> short mmc_pie_b( short control, short xc, short yc, short xr, short yr, short d1, short d2 ) ; [Arguments] control xc, yc xr yr d1 d2 Control flag. View port coordinate of the circle center. X-directional radius. Y-directional radius. Angle of drawing start point (-3600..3600 [0.1 deg]) Angle of drawing end point (-3600..3600 [0.1 deg]) [Return] Returns non-0 value if successful, or 0 if any error. [Description] Draws a pie figure. Specify one of the following symbols for "Control flag". Symbol Purpose ---------------+---------------------------------------------_GFILLINTERIOR Fills inside of the object with the current fill mask pattern. _GBORDER Draws only border line, not fills inside. "Angles" are specified as follows. Unit of angles is 0.1 degree. "Start angle" <= "End angle". Allowed range to command is -3600..3600 (-360[deg]..360[deg]). The origin of angle is + direction of X axis. Angle increases counter clock wise. (Y) | | 90[deg]|<-----+ | | | |0[deg] ----------------+----------------(X) 180[deg]| | 360[deg] | | +----->|270[deg] | | (Y) | | -270[deg]|<-----+ | | | |-360[deg] ----------------+----------------(X) -180[deg]| | 0[deg] | | +----->|-90[deg] | | Pie figure is drawn counter clock wise (CCW) from the start point to the end point. When the start point is same as the end point, pie figure is not drawn but only a line which connects the circle center and start/end point is drawn. -----------------------------------------------------------------------------21. Draw an arc. <Main> -----------------------------------------------------------------------------[Name] mmc_arc_b [Syntax] #include <fgraph.h> short mmc_arc_b( short xc, short yc, short xr, short yr, short d1, short d2 ) ; [Arguments] xc, yc xr yr d1 d2 View port coordinate of the circle center. X-directional radius. Y-directional radius. Angle of drawing start point (-3600..3600 [0.1 deg]) Angle of drawing end point (-3600..3600 [0.1 deg]) [Return] Returns non-0 value if successful, or 0 if any error. [Description] Draws an arc. "Angles" are specified as follows. Unit of angles is 0.1 degree. "Start angle" <= "End angle". Allowed range to command is -3600..3600 (-360[deg]..360[deg]). The origin of angle is + direction of X axis. Angle increases counter clock wise. (Y) | | 90[deg]|<-----+ | | | |0[deg] ----------------+----------------(X) 180[deg]| | 360[deg] | | +----->|270[deg] | | (Y) | | -270[deg]|<-----+ | | | |-360[deg] ----------------+----------------(X) -180[deg]| | 0[deg] | | +----->|-90[deg] | | Arc is drawn counter clock wise (CCW) from the start point to the end point. When the start point is same as the end point, arc is not drawn but only a pixel is drawn at the start/end point. -----------------------------------------------------------------------------22. Get character in the specified area. <Main> -----------------------------------------------------------------------------[Name] mmc_gettext [Syntax] #include <fgraph.h> short mmc_gettext( short x1, short y1, short x2, short y2, _MCHRBUF *chr_buf ) ; [Arguments] x1,y1,x2,y2 chr_buf Screen area (left-upper, right-lower) Buffer memory in where data are stored. [Return] 0 -1 2 Successful. Warning. (Out of screen) Error. (No work memory) [Description] Reads characters in the specified screen area to the memory. Specify screen area to read as left-upper point of screen (Home position) is (1,1). The first character is read at the start point (left-upper position), and continuously reads rightward, jumps to the next line at the right end, the last character is read at the rightlower position. The required byte size to read is calculated by "mmc_textsize()" function. Character code and attribute are stored by internal format. The structure of output buffer is as follows. +----------------------------+ | Column size | -----------------------------+ 2 | Line size | +----------------------------+ 4 | 1st character - code | --+ +----------------------------+ +--- data for one character 6 | 1st character - attribute | --+ +----------------------------+ : +----------------------------+ m | n-th character - code | +----------------------------+ m+2 | n-th character - attribute | +----------------------------+ 0 If the specified area overruns the screen like below, SPACE character and WHITE attribute is stored in the overruned region and "Warning" is returned as result. +---------------------------------+ |(1,1) | | | | screen | | | specified area | +---------------------------+ | |(x1,y1) |//////////| | | |//////////| | | |//////////| | | (80,30)|//////////| +----------------|----------------+//////////| |///////////////////////////| |////////////////////(x2,y2)| +---------------------------+ If the start position is at the right-half of double-sized character, only lower byte of the character code is read. If the end position is at the left-half of double-sized character, only upper byte of the character code is read. In these case, operation is done successfully. -----------------------------------------------------------------------------23. Put character data on memory to text screen. <Main> -----------------------------------------------------------------------------[Name] mmc_puttext [Syntax] #include <fgraph.h> short mmc_puttext( short x, short y, _MCHRBUF *chr_buf ) ; [Arguments] x, y chr_buf Start position to write. Buffer memory in where data are stored. [Return] 0 -1 2 Successful. Warning. (Out of screen) Error. (No work memory) [Description] Writes characters stored on memory to the text screen. This function writes character data on memory which has been read by "mmc_gettext()" function. Specify screen area to write as left-upper point of screen (Home position) is (1,1). If the specified area overruns the screen, the overruned region is not written. -----------------------------------------------------------------------------24. Get required byte size for getting character. <Main> -----------------------------------------------------------------------------[Name] mmc_textsize [Syntax] #include <fgraph.h> short mmc_textsize( short x1, short y1, short x2, short y2 ) ; [Arguments] x1,y1,x2,y2 Screen area (left-upper, right-lower) [Return] Required byte size to read the specified area. [Description] Returns the required byte size to read the specified area. The required byte size is calculated by the following formula. Byte size = (Column size * Line size) * 4 + 4 [byte] Column size = x2 - x1 + 1 Line size = y2 - y1 + 1 (Example) For reading whole screen (80 x 30). (80 * 30) * 4 + 4 = 9604 byte 3.4 CNC/PMC window library ========================== Lists of Functions ~~~~~~~~~~~~~~~~~~ 1. CNC window library -------------------------------------------------------------------------Name Function -------------------------------------------------------------------------1.1 cnc_sysinfo Read CNC system information. 1.2 cnc_dwnstart Start output of NC program to be registered. 1.3 cnc_download Output NC program to be registered. 1.4 cnc_dwnend Stop output NC program to be registered. 1.5 cnc_vrfstart Start output NC program to be compared. 1.6 cnc_verify Output NC program to be compared. 1.7 cnc_vrfend Stop output NC program to be compared. 1.8 cnc_dncstart Start output NC program to be executed. 1.9 cnc_dnc Output NC program to be executed. 1.10 cnc_dncend Stop output NC program to be executed. 1.11 cnc_upstart Start input NC program. 1.12 cnc_upload Input NC program. 1.13 cnc_upend Stop input NC program. 1.14 cnc_search Search specified program. 1.15 cnc_delall Delete all programs. 1.16 cnc_delete Delete specified program. 1.17 cnc_rdprogdir Read program directory. 1.18 cnc_rdproginfo Read program information. 1.19 cnc_rdprgnum Read program number in executing. 1.20 cnc_rdseqnum Read sequence number in executing. 1.21 cnc_actf Read actual feed rate of controlled axes. 1.22 cnc_acts Read actual spindle speed. 1.23 cnc_absolute Read absolute position. 1.24 cnc_machine Read machine position. 1.25 cnc_relative Read relative position. 1.26 cnc_distance Read distance to go. 1.27 cnc_skip Read skipped position. 1.28 cnc_srvdelay Read servo delay amount. 1.29 cnc_accdecdly Read acceleration/deceleration delay amount. 1.30 cnc_rddynamic Read dynamic data. 1.31 cnc_statinfo Read CNC status information. 1.32 cnc_alarm Read alarm status. 1.33 cnc_rdalminfo Read alarm information. 1.34 cnc_rdtofs Read tool offset amount. 1.35 cnc_wrtofs Write tool offset amount. 1.36 cnc_rdtofsr Read tool offset amount (range specified). 1.37 cnc_wrtofsr Write tool offset amount (range specified). 1.38 cnc_rdzofs Read work origin offset. 1.39 cnc_wrzofs Write work origin offset. 1.40 cnc_rdzofsr Read work origin offset (range specified). 1.41 cnc_wrzofsr Write work origin offset (range specified). -------------------------------------------------------------------------Name Function -------------------------------------------------------------------------1.42 cnc_rdparam Read parameter. 1.43 cnc_wrparam Write parameter. 1.44 cnc_rdparar Read parameters (range specified). 1.45 cnc_wrparas Write parameters (multiple output). 1.46 cnc_rdset Read setting parameter. 1.47 cnc_wrset Write setting parameter. 1.48 cnc_rdsetr Read setting parameters (range specified). 1.49 cnc_wrsets Write setting parameters (multiple output). 1.50 cnc_rdpitchr Read pitch error compensation data (range specified). 1.51 cnc_wrpitchr Write pitch error compensation data (range specified). 1.52 cnc_rdmacro Read custom macro variable. 1.53 cnc_wrmacro Write custom macro variable. 1.54 cnc_rdmacror Read custom macro variables (range specified). 1.55 cnc_wrmacror Write custom macro variables (range specified). 1.56 cnc_rdpmacro Read P-code macro variable. 1.57 cnc_wrpmacro Write P-code macro variable. 1.58 cnc_rdpmacror Read P-code macro variables (range specified). 1.59 cnc_wrpmacror Write P-code macro variables (range specified). 1.60 cnc_modal Read modal data. 1.61 cnc_diagnoss Read diagnostics data. 1.62 cnc_diagnosr Read diagnostics data (range specified). 1.63 cnc_adcnv Read A/D conversion data. 1.64 cnc_rdopmsg Read operator's message. 1.65 cnc_setpath Set path index (multi-path system). 1.66 cnc_getpath Get path index (multi-path system). 1.67 cnc_settimer Set calendar timer of CNC. 1.68 cnc_rdspload Read load information of serial spindle. 1.69 cnc_rdexecprog Read executing program. 1.70 cnc_rdmovrlap Read manual handle override amount. -------------------------------------------------------------------------2. PMC window library -------------------------------------------------------------------------Name Function -------------------------------------------------------------------------2.1 pmc_rdpmcrng Read arbitrary PMC data (range specified). 2.2 pmc_wrpmcrng Write arbitrary PMC data (range specified). 2.3 pmc_rdpcmsg Read PMC message. -------------------------------------------------------------------------- Function Reference ~~~~~~~~~~~~~~~~~~ 1. CNC window library -----------------------------------------------------------------------------1.1 Read CNC system information. <Main,Alarm> -----------------------------------------------------------------------------[Name] cnc_sysinfo [Syntax] #include <data.h> #include <fwindow.h> short cnc_sysinfo( struct odbsys *buf ) ; struct odbsys { int dummy[2] ; char cnc_type[2] ; char mt_type[2] ; char series[4] ; char version[4] ; char axes[2] ; } ; [Arguments] buf /* /* /* /* /* /* /* Not used. */ Kind of CNC (ASCII string). */ Kind of M/T/TT (ASCII string). */ Series number (ASCII string). */ Version number (ASCII string). */ Amount of controllable axes */ (ASCII string). */ Buffer in which system information is stored. [Return] EW_OK( 0) Successful. [Description] Reads system information such as kind of CNC (for example, "30" as series name), kind of CNC system such as Machining(M) or Turning(T), series and version number of CNC system software in ROM and an amount of controllable axes. Use this function to confirm compatibility of CNC's system software and PMC's software or to get an amount of controllable axes before reading axis coordinate data such as absolute, machine or skipped position. Note that a null character ('\x00') is not added at the end of each strings. [Example] The following informations are gotten by execution of this function on FS30 (G001-01) system with 4 servo axes. buf.cnc_type buf.mt_type buf.series buf.version buf.axes = = = = = "30" " M" "G001" "0001" "4 " -----------------------------------------------------------------------------1.2 Start output of NC program to be registered. <Main,Alarm> -----------------------------------------------------------------------------[Name] cnc_dwnstart [Syntax] #include <data.h> #include <fwindow.h> short cnc_dwnstart( void ) ; [Arguments] -----[Return] EW_OK( 0) EW_PROT( 7) EW_BUSY(-1) Successful. Tape memory of CNC is protected. Start command for output of NC program to be registered has been rejected. This code is returned if any of the following conditions exists when this command is executed. - The CNC is performing other command processing (downloading, collating, uploading, or program number - list reading). Background editing is in progress or the MDI mode has - been entered. A P/S 000 or P/S 101 alarm condition has occurred. [Description] Requests CNC to start registering of NC program (downloading). [Example] See example of "Output NC program to be registered(cnc_download)". -----------------------------------------------------------------------------1.3 Output NC program to be registered. <Main,Alarm> -----------------------------------------------------------------------------[Name] cnc_download [Syntax] #include <data.h> #include <fwindow.h> short cnc_download( char *data, short number ) ; [Arguments] data number NC program data (ASCII string). Character number of NC program data (1 - 256). [Return] EW_OK( 0) EW_FUNC( 1) EW_LENGTH( 2) EW_DATA( 5) EW_OVRFLOW( 8) Successful. The start-up procedure of CNC for registering NC program has not been completed, or no start-up command has been commanded. Incorrect character number "number". Incorrect NC program data. This code is returned under one of following conditions. - The same program number is already registered. - A character which is unavailable for NC program is detected. - When TV check is effective, a block which includes odd characters (including 'LF' at the end of the block) is detected. - No more programs can be registered because there is no space for them. No more NC program can be stored because tape memory of CNC is full. [Description] Outputs NC program to be registered to CNC. NC program output is a string of ASCII code characters. "Start output of NC program to be registered(cnc_dwnstart)" must be called before outputting NC program to be registered to CNC, and "Stop output NC program to be registered(cnc_dwnend)" after outputting. If any program whose program number is same as newly registering NC program's is already registered in CNC, one of following procedure will be done according to CNC parameter No.3201#1 REP. REP = "0" Return code "5" will be returned, and the new program will be not registered. REP = "1" The new program will be registered with deleting already registered one, i.e., the new program will replace the old one. (Caution) It is impossible to write a program over a program that has been selected. To replace a program that has been selected with another program, delete the selected program or select a different program, and then register the new program. NC program format ~~~~~~~~~~~~~~~~~ NC program to be registered to CNC is a string composed of ASCII characters as following format. LF Oxxxx LF Block1 LF Block2 LF ... LF Mxx LF % LF Oxxxx Mxx 0x0A ('\n'). Program number. M code at the end of the program (M02,M30, etc.). 'LF' must be placed at the top of the whole program, and '%' at the end. Data before 'LF' at the top are ignored. Address 'O' and program number must be placed in the program to be registered. For example, to register a program such as O1234 ; G1 F0.3 W10. ; M30 ; % send a following string using cnc_download function. "\nO1234\nG1F0.3W10.\nM30\n%" The string data can be sent by multiple cnc_download functions. For above example, the program can be sent block by block like this. "\n" "O1234\n" "G1F0.3W10.\n" "M30\n" "%" And more, it is possible to send one block by multiple cnc_download functions. It is possible also to send multiple programs continuously as follows. "\n" "O1234\nG1F0.3W10.\nM30\n" "O5678\nM3S1200\nT11\nG0X10.Z0\nM30\n" "%" There is one buffer (256 bytes) between CNC and C library. It is used as a ring. Buffer size = 256 bytes +--------------------------------------------------+ +-->| 1st output | 2nd output | ... | | --+ | +--------------------------------------------------+ | | | +----------------------------------------------------------+ When any data can not be output because registration process has not been completed (i.e. the buffer is full), the C library waits until it can be output. ERROR 5 and 8 may be returned late because NC program is sent to CNC via buffers. That is, the return code of an output process may be one of it several times before. Moreover, return codes of several output before the last one may be returned by "Stop output NC program to be registered(cnc_dwnend)". [Example] The following program registers the next NC program to CNC. O1234 ; M3 S1200 ; G0 Z0 ; G0 X0 Y0 ; G1 F500 X120. Y-30. ; M30 ; #include <data.h> #include <fwindow.h> short example( void ) { char *prg[] = { "\n", "O1234\n", "M3 S1200\n", "G0 Z0\n", "G0 X0 Y0\n", "G1 F500 X120. Y-30.\n", "M30\n", "%" } ; short ret, idx ; ret = cnc_dwnstart() ; if ( ret ) return ( ret ) ; for ( idx = 0 ; idx < sizeof(prg)/sizeof(char *) ; idx++ ) { ret = cnc_download( prg[idx], strlen( prg[idx] ) ) ; if ( ret ) { cnc_dwnend() ; return ( ret ) ; } } ret = cnc_dwnend() ; return ( ret ) ; } -----------------------------------------------------------------------------1.4 Stop output NC program to be registered. <Main,Alarm> -----------------------------------------------------------------------------[Name] cnc_dwnend [Syntax] #include <data.h> #include <fwindow.h> short cnc_dwnend( void ) ; [Arguments] -----[Return] EW_OK( 0) EW_FUNC( 1) EW_DATA( 5) EW_OVRFLOW( 8) Successful. The start-up procedure of CNC for registering NC program has not been completed, or no start-up command has been commanded. Incorrect NC program data in previous output. This code is returned under one of following conditions. - The same program number is already registered. - A character which is unavailable for NC program is detected. - When TV check is effective, a block which includes odd characters (including 'LF' at the end of the block) is detected. - No more programs can be registered because there is no space for them. NC programs which have been output previously could not registered because tape memory of CNC is full. [Description] Notices the end of NC program registration to CNC. '%' must be output as NC program data before calling this function. 5 or 8 which has been issued during processing of "Output NC program to be registered" may be returned. This function doesn't return until the registration process of CNC is completed. The registration process is completed even if the return code is not "0". [Example] See example of "Output NC program to be registered(cnc_download)". -----------------------------------------------------------------------------1.5 Start output NC program to be compared. <Main,Alarm> -----------------------------------------------------------------------------[Name] cnc_vrfstart [Syntax] #include <data.h> #include <fwindow.h> short cnc_vrfstart( void ) ; [Arguments] -----[Return] EW_OK( 0) EW_BUSY(-1) Successful. Start command for output of NC program to be compared has been rejected. This code is returned if any of the following conditions exists when this command is executed. - The CNC is performing other command processing (downloading, collating, uploading, or program number list reading). - Background editing is in progress or the MDI mode has been entered. - A P/S 000 or P/S 101 alarm condition has occurred. [Description] Requests CNC to start comparing of NC program. It is possible to compare already registered NC program in CNC and a program which is output by the application program. [Example] See example of "Output NC program to be compared(cnc_verify)". -----------------------------------------------------------------------------1.6 Output NC program to be compared. <Main,Alarm> -----------------------------------------------------------------------------[Name] cnc_verify [Syntax] #include <data.h> #include <fwindow.h> short cnc_verify( char *data, int number ) ; [Arguments] data number NC program data (ASCII string). Character number of NC program data (1 - 256). [Return] EW_OK( 0) EW_FUNC( 1) EW_LENGTH( 2) EW_DATA( 5) Successful. The start-up procedure of CNC for comparing NC program has not been completed, or no start-up command has been commanded. Incorrect character number "number". Incorrect NC program data. This code is returned under one of following conditions. - Any difference has been detected during comparing process. - A CNC-side program to be compared has been selected in foreground processing. - A character which is unavailable for NC program is detected. - When TV check is effective, a block which includes odd characters (including 'LF' at the end of the block) is detected. [Description] Outputs NC program to be compared with already registered one to CNC. NC program output is a string of ASCII code characters. "Start output of NC program to be compared(cnc_vrfstart)" must be called before outputting NC program to be compared to CNC, and "Stop output NC program to be compared(cnc_vrfend)" after outputting. Format of NC program to be compared is same as one of "Output NC program to be registered(cnc_download)" Refer description of "cnc_download" function for format of output data, etc. There is one buffer (256 bytes) between CNC and C library. It is used as a ring. Buffer size = 256 bytes +--------------------------------------------------+ +-->| 1st output | 2nd output | ... | | --+ | +--------------------------------------------------+ | | | +----------------------------------------------------------+ When any data can not be output because comparing process has not been completed (i.e. the buffer is full), the C library waits until it can be output. EW_DATA may be returned late because NC program is sent to CNC via buffers. That is, the return code of an output process may be one of it several times before. Moreover, return codes of several output before the last one may be returned by "Stop output NC program to be compared(cnc_vrfend)". [Example] The following program compares the next NC program and "O1234" which is already registered in CNC. O1234 ; M3 S1200 ; G0 Z0 ; G0 X0 Y0 ; G1 F500 X120. Y-30. ; M30 ; #include <data.h> #include <fwindow.h> short example( void ) { char *prg[] = { "\n", "O1234\n", "M3 S1200\n", "G0 Z0\n", "G0 X0 Y0\n", "G1 F500 X120. Y-30.\n", "M30\n", "%" } ; short ret, idx ; ret = cnc_vrfstart() ; if ( ret ) return ( ret ) ; for ( idx = 0 ; idx < sizeof(prg)/sizeof(char *) ; idx++ ) { ret = cnc_verify( prg[idx], strlen( prg[idx] ) ) ; if ( ret ) { cnc_vrfend() ; return ( ret ) ; } } ret = cnc_vrfend() ; return ( ret ) ; } -----------------------------------------------------------------------------1.7 Stop output NC program to be compared. <Main,Alarm> -----------------------------------------------------------------------------[Name] cnc_vrfend [Syntax] #include <data.h> #include <fwindow.h> short cnc_vrfend( void ) ; [Arguments] -----[Return] EW_OK( 0) EW_FUNC( 1) EW_DATA( 5) Successful. The start-up procedure of CNC for comparing NC program has not been completed, or no start-up command has been commanded. The previously output NC program data is incorrect. This code is returned under one of following conditions. - Any difference has been detected during comparing process. - A CNC-side program to be compared has been selected in foreground processing. - A character which is unavailable for NC program is detected. - When TV check is effective, a block which includes odd characters (including 'LF' at the end of the block) is detected. [Description] Notices the end of comparison of NC program to CNC. '%' must be output as NC program data before calling this function. 5 or 8 which has been issued during processing of "Output NC program to be compared" may be returned. This function doesn't return until the comparing process of CNC is completed. The comparing process is completed even if the return code is not "0". [Example] See example of "Output NC program to be compared(cnc_verify)". -----------------------------------------------------------------------------1.8 Start output NC program to be executed. <Main,Alarm> -----------------------------------------------------------------------------[Name] cnc_dncstart [Syntax] #include <data.h> #include <fwindow.h> short cnc_dncstart( void ) ; [Arguments] -----[Return] EW_OK( 0) EW_BUSY(-1) Successful. Start command for output of NC program to be executed has been rejected. This code is returned under one of following conditions. - CNC is executing other requested command (downloading, comparing, uploading or reading program directory). - Any alarms are set. - CNC is executing the other program. [Description] It is possible to get CNC software to run a NC program (NC command data), which is made by the application program, directly (DNC operation). This is DNC operation, which is ordinarily executed via RS-232C, via CNC window from C language application. The application program requests CNC to start DNC operation by this function. In addition to calling functions about DNC operation by the application program, it is necessary for executing DNC operation to operate signals by the LADDER software of PMC. Execute the following steps. (1) Set CNC's mode as MEM mode. [LADDER] (2) Set the DMMC signal (G42#7) to "1". [LADDER] (3) Execute "cnc_dncstart" function. [C application] (4) Start automatic operation by operating "ST" signal(G7#2) "0"->"1"->"0". [LADDER] (5) Send NC commands by "cnc_dnc" function. [C application] (6) Execute "cnc_dncend" function after sending all NC commands. [C application] (7) Reset CNC when the program is completed (i.e., the M-code which means the end of the program is detected.) [LADDER] (8) Reset the DMMC signal to "0". [LADDER] The CNC software goes on waiting NC commands sent by "cnc_dnc" function from starting of DNC operation. To stop the operation in this state, reset the CNC. [Example] See example of "Output NC program to be executed(cnc_dnc)". -----------------------------------------------------------------------------1.9 Output NC program to be executed. <Main,Alarm> -----------------------------------------------------------------------------[Name] cnc_dnc [Syntax] #include <data.h> #include <fwindow.h> short cnc_dnc( char *data, short number ) ; [Arguments] data number NC program data (ASCII string). Character number of NC program data (1 - 256). [Return] EW_OK( 0) EW_FUNC( 1) EW_LENGTH( 2) EW_DATA( 5) EW_RESET(-2) Successful. The start-up procedure of CNC for executing NC program has not been completed, or no start-up command has been commanded. Incorrect character number "number". Incorrect NC program data. The CNC has been reset. In this case, stop outputting of NC command data to be executed and perform the end operation of outputting of NC command. [Description] Outputs NC command data to be directly executed to CNC (for DNC operation). NC command data output is a string of ASCII code characters. "Start output NC program to be executed(cnc_dncstart)" must be called and cycle start must be performed before outputting NC command data to be executed to CNC. To execute the cnc_dncstart function, select the MEM mode and turn on the DMMC signal <G042#7>. "Stop output NC program to be executed(cnc_dncend)" must be called after outputting. Format of NC command data to be executed ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ NC command data to be executed to CNC is a string composed of ASCII characters as following format. LF Oxxxx LF Block1 LF Block2 LF ... LF Mxx LF % LF NC command1 LF NC command2 LF ... LF Mxx LF % LF Mxx 0x0A ('\n'). M code at the end of the DNC operation (M02, M30,etc.). 'LF' must be placed at the top of the whole NC commands, and '%' at the end. 'LF's are added after each NC commands. For example, to execute commands such as M3 S2000 ; T14 ; G0 X10. ; G0 Z-5. ; M30 ; send a following string using cnc_dnc function. cnc_dnc( "\nM3S2000\nT14\nG0X10.\nG0Z-5.\nM30\n%", 32 ) ; The string data can be sent by multiple cnc_dnc functions. For above example, the commands can be sent block by block like this. cnc_dnc( cnc_dnc( cnc_dnc( cnc_dnc( cnc_dnc( cnc_dnc( cnc_dnc( "\n", 1 ) ; "M3S2000\n", 8 ) ; "T14\n", 4 ) ; "G0X10.\n", 7 ) ; "G0Z-5.\n", 7 ) ; "M30\n", 4 ) ; "%", 1 ) ; There is one buffer (256 bytes) between CNC and C library. It is used as a ring. Buffer size = 256 bytes +--------------------------------------------------+ +-->| 1st output | 2nd output | ... | | --+ | +--------------------------------------------------+ | | | +----------------------------------------------------------+ When any data can not be output because operating process has not been completed (i.e. the buffer is full), the C library waits until it can be output. EW_DATA may be returned late because NC program is sent to CNC via buffers. That is, the return code of an output process may be one of it several times before. Moreover, return codes of several output before the last one may be returned by "Stop output NC program to be executed(cnc_dncend)". The DNC operation is intended to execute NC commands simply block by block. For this reason, it cannot be used to execute commands which require that two or more blocks of commands be loaded for execution, as with multiple repetitive canned cycles used for lathes, or commands which reference a block other than those they belong to, as with macro branch instructions. If it is necessary to execute a command which requires that information about two or more blocks be loaded for execution, take the following steps. (1) Program the multiple-block NC command using macro program format. (2) Store the above program in the tape memory of CNC unit. (It is possible to store compiled code of program in ROM using Macro Compiler.) (3) Execute macro-call command (such as M98) to execute registerd macro program in DNC operation. (It is possible to call registered macro program in the memory for DNC operation.) [Example] The following program executes the next NC commands by DNC operation. M3 S1500 ; G28 U0 W0 ; T0101 ; G0 X35. Z-10. ; M30 ; #include <data.h> #include <fwindow.h> short example( void ) { char *prg[] = { "\n", "M3S1500\n", "G28U0W0\n", "T0101\n", "G0X35.Z-10.\n", "M30\n", "%" } ; short ret, idx ; ret = cnc_dncstart() ; if ( ret ) return ( ret ) ; for ( idx = 0 ; idx < sizeof(prg)/sizeof(char *) ; idx++ ) { ret = cnc_dnc( prg[idx], strlen( prg[idx] ) ) ; if ( ret ) break ; } if ( ret ) cnc_dncend() ; else ret = cnc_dncend() ; return ( ret ) ; } In the real DNC operation, it is necessary to operate some signals by the LADDER software. So, any communication processes with the LADDER software are added in above example program. -----------------------------------------------------------------------------1.10 Stop output NC program to be executed. <Main,Alarm> -----------------------------------------------------------------------------[Name] cnc_dncend [Syntax] #include <data.h> #include <fwindow.h> short cnc_dncend( void ) ; [Arguments] -----[Return] EW_OK( 0) EW_FUNC( 1) EW_DATA( 5) EW_RESET(-2) Successful. The start-up procedure of CNC for executing NC program has not been completed, or no start-up command has been commanded. Incorrect NC program data. The CNC has been reset. [Description] Notices the end of DNC operation to CNC. '%' must be output as NC command data before calling this function. Execute this stopping command after the CNC's operation has been completed and reset. If this command is executed during CNC is operating, the function-call waits until the end of operation and resetting. Check "OP" signal(F000#7) to find whether CNC has been reset or not. When "OP" signal is "0", CNC is has been reset. EW_DATA which has been issued during processing of "Output NC program to be executed" may be returned. The return value of this function is usually "-2" because CNC is reset at the end of DNC operation. [Example] See example of "Output NC program to be executed(cnc_dnc)". -----------------------------------------------------------------------------1.11 Start input NC program. <Main,Alarm> -----------------------------------------------------------------------------[Name] cnc_upstart [Syntax] #include <data.h> #include <fwindow.h> short cnc_upstart( long number ) ; [Arguments] number Program number. [Return] EW_OK( 0) EW_DATA( 5) EW_PROT( 7) EW_BUSY(-1) Successful. The specified NC program is not registered in CNC. Tape memory of CNC is protected. Start command for input of NC program to be uploaded has been rejected. This code is returned under one of following conditions. - CNC is executing other requested command (downloading, comparing, uploading or reading program directory). - An NC program is running (automatic operation signal OP<F000#7> is on). - Background editing is in progress or the MDI mode has been selected. - A P/S 000 or P/S 101 alarm condition has occurred. [Description] Requests CNC to start reading of NC program (uploading). Specify the program number of NC program to be uploaded in "number" with binary format. [Example] See example of "Input NC program(cnc_upload)". -----------------------------------------------------------------------------1.12 Input NC program. <Main,Alarm> -----------------------------------------------------------------------------[Name] cnc_upload [Syntax] #include <data.h> #include <fwindow.h> short cnc_upload( struct odbup *buf, short *number ) ; struct odbup { short dummy[2] ; char data[N] ; } ; [Arguments] buf number /* Not used. */ /* NC program data (ASCII string). */ /* N: max 256 */ Buffer in which NC program data are stored. Size of the above buffer, amount of characters included in input NC command data characters. [Return] EW_OK( 0) EW_FUNC( 1) EW_LENGTH( 2) Successful. The start-up procedure of CNC for reading NC program has not been completed, or no start-up command has been commanded. Incorrect buffer size "number". [Description] Inputs contents of NC program specified by "cnc_upstart" function from CNC. NC program data input is a string of ASCII code characters. "Start input NC program(cnc_upstart)" must be called before uploading NC program from CNC, and "Stop input NC program(cnc_upend)" after uploading. Specify a buffer whose maximum size is 256 bytes, and the minimum size is 3 bytes. This buffer size can be either shorter or longer than the NC program. If the NC program is longer than the buffer, this function is called multiple times. Store the buffer size in "number" before calling this function. The real length of read NC program will be stored in "number". When any data can not be input because transfer process has not been completed (i.e. the buffer is empty), the C library waits until any data are written in the buffer Format of input data ~~~~~~~~~~~~~~~~~~~~ NC program which is read from CNC is a string composed of ASCII characters as following format. % LF Oxxxx LF Block1 LF Block2 LF ... LF Mxx LF % LF Oxxxx Mxx 0x0A ('\n'). Program number. M code at the end of the program (M02,M30, etc.). A null character ('\x00') is not added at the end of each strings stored in the buffer. The last character of read NC program is '%'. Only '%' can be read by attempting to read more data beyond this last '%'. For example, when you read the following NC program using this function, O1234 ; G1 F0.3 W10. ; M30 ; % you will get the following strings. In case of fully large buffer. 1st time "%\nO1234\nG1F0.3W10.\nM30\n%" (24 chars) 2nd and after "%" (1 char) And in case that the buffer size is less than 24 bytes, you will get the following strings. In case that the buffer size is 1st time "%\nO1234\nG1" 2nd time "F0.3W10.\nM" 3rd time "30\n%" 4th and after "%" 10 bytes. (10 characters) (10 characters) (4 characters) (1 character) [Example] The following program reads the specified NC program registered in CNC, and displays its contents on the screen. #include <data.h> #include <fwindow.h> #include <stdio.h> #define BUFSIZE 40 /* prgnum is NC program number to be read. */ short example( long prgnum ) { char buf[BUFSIZE+4] ; short ret, number ; ret = cnc_upstart( prgnum ) ; if ( ret ) return ( ret ) ; for (;;) { number = BUFSIZE - 1 ; ret = cnc_upload( (struct odbup *)(&buf), &number ) ; if ( ret ) { cnc_upend() ; return ( ret ) ; } buf[4+number] = '\x00' ; printf( "%s", &buf[4] ) ; if ( buf[4+number-1] == '%' ) break ; } putchar( '\n' ) ; ret = cnc_upend() ; return ( ret ) ; } -----------------------------------------------------------------------------1.13 Stop input NC program. <Main,Alarm> -----------------------------------------------------------------------------[Name] cnc_upend [Syntax] #include <data.h> #include <fwindow.h> short cnc_upend( void ) ; [Arguments] -----[Return] EW_OK( 0) EW_FUNC( 1) Successful. The start-up procedure of CNC for reading NC program has not been completed, or no start-up command has been commanded. [Description] Notices the end of NC program uploading to CNC. Confirm that a '%' character is added at the end of the input NC program before calling this function. The uploading process is completed in CNC even if the return code is not "0". [Example] See example of "Input NC program(cnc_upload)". -----------------------------------------------------------------------------1.14 Search specified program. <Main,Alarm> -----------------------------------------------------------------------------[Name] cnc_search [Syntax] #include <data.h> #include <fwindow.h> short cnc_search( long number ) ; [Arguments] number Program number. [Return] EW_OK( 0) EW_DATA( 5) EW_PROT( 7) EW_BUSY(-1) Successful. The specified NC program is not registered in CNC. Tape memory of CNC is protected. The program search command was rejected. This code is returned if any of the following conditions exists when this command is executed. - The CNC is performing other window command processing (downloading, collating, uploading, or program number list reading). - In the EDIT or memory mode, the automatic operation signal OP<F000 #7> is on. - In the EDIT or memory mode, a P/S 000 or P/S 101 alarm condition has occurred. [Description] Searches the NC program already registered in CNC. This function is used to select one NC program before memory operation is executed in CNC. Foreground search is preformed for EDIT or MEM mode and background search (only checks whether the specified program exists or not.) for the other mode. Specify the program number of NC program to be searched in "number" with binary format. [Example] The following program searches the program whose program number is same as specified one, and displays the result. #include <data.h> #include <fwindow.h> #include <stdio.h> /* num is program number to be searched. */ void example( long num ) { short ret ; ret = cnc_search( num ) ; switch ( ret ) { case 0: printf( "PROGRAM O%d has been searched.\n", num ) ; break ; case 5: printf( "PROGRAM O%d doesn't exist.\n", num ) ; break ; case 7: printf( "PROTECTED.\n" ) ; break ; case -1: printf( "REJECTED.\n" ) ; break ; } } -----------------------------------------------------------------------------1.15 Delete all programs. <Main,Alarm> -----------------------------------------------------------------------------[Name] cnc_delall [Syntax] #include <data.h> #include <fwindow.h> short cnc_delall( void ) ; [Arguments] -----[Return] EW_OK( 0) EW_PROT( 7) EW_BUSY(-1) Successful. Tape memory of CNC is protected, or the target program is protected. In the CNC, the all-program delete command was rejected. This code is returned if any of the following conditions exists when this command is executed. - The CNC is performing other window command processing (downloading, collating, uploading, or program number list reading). - An NC program is running (automatic operation signal OP<F000#7> is on). - A P/S 000, P/S 101, or BP/S alarm condition has occurred. [Description] Deletes all NC programs registered in CNC. Even the selected program in foreground editing is deleted by this function. But when any automatic operation is being executed, program deletion is not performed. [Example] The following program deletes all programs and displays the result. #include <data.h> #include <fwindow.h> #include <stdio.h> void example( void ) { short ret ; ret = cnc_delall() ; switch ( ret ) { case 0: printf( "ALL PROGRAMS has been deleted.\n", num ) ; break ; case 7: printf( "PROTECTED.\n" ) ; break ; case -1: printf( "REJECTED.\n" ) ; break ; } } -----------------------------------------------------------------------------1.16 Delete specified program. <Main,Alarm> -----------------------------------------------------------------------------[Name] cnc_delete [Syntax] #include <data.h> #include <fwindow.h> short cnc_delete( long number ) ; [Arguments] number Program number. [Return] EW_OK( 0) EW_DATA( 5) EW_PROT( 7) EW_BUSY(-1) Successful. The specified NC program is not registered in CNC. Tape memory of CNC is protected, or the target program is protected. In the CNC, the specified-program delete command was rejected. This code is returned if any of the following conditions exists when this command is executed. - The CNC is performing other window command processing (downloading, collating, uploading, or program number list reading). - An NC program is running (automatic operation signal OP<F000#7> is on). - A P/S 000, P/S 101, or BP/S alarm condition has occurred. [Description] Deletes the specified NC program registered in CNC. If the specified program is used for the current automatic operation, it can't be deleted. Specify the program number of NC program to be deleted in "number" with binary format. [Example] The following program deletes the program whose program number is same as specified one, and displays the result. #include <data.h> #include <fwindow.h> #include <stdio.h> /* num is program number to be deleted. */ void example( long num ) { short ret ; ret = cnc_delete( num ) ; switch ( ret ) { case 0: printf( "PROGRAM O%d has been deleted.\n", num ) ; break ; case 5: printf( "PROGRAM O%d doesn't exist.\n", num ) ; break ; case 7: printf( "PROTECTED.\n" ) ; break ; case -1: printf( "REJECTED.\n" ) ; break ; } } -----------------------------------------------------------------------------1.17 Read program directory. <Main,Alarm> -----------------------------------------------------------------------------[Name] cnc_rdprogdir [Syntax] #include <data.h> #include <fwindow.h> short cnc_rdprogdir( short type, long datano_s, long datano_e, short length, struct prgdir *buf ) ; struct prgdir { char prg_data[N] ; } ; [Arguments] type datano_s datano_e length buf /* Contents of directory (ASCII */ /* string). N: max 256 */ Format of program list (0,1,2). Start program number to be read. End program number to be read. Size of the following buffer for the program directory. Buffer in which the program directory list is stored. [Return] EW_OK( 0) EW_LENGTH( 2) EW_NUMBER( 3) EW_DATA( 5) EW-BUSY(-1) Successful. Incorrect buffer size "length". The specified type is invalid. The specified program number is invalid. In the CNC, read processing for program number list data was rejected. This code is returned if any of the following conditions EW_RESET(-2) exists when this command is executed. - The CNC is performing other command processing (downloading, collating, uploading, or program number list reading). - Background editing is in progress or the MDI mode has been entered. - A P/S 000 or P/S 101 alarm condition has occurred. The CNC was reset. Even in this case, the CNC completes program number list reading normally. [Description] Reads the list of program numbers (program directory) of all NC programs registered in CNC. Program numbers, comments and character numbers of programs included in specified program number range are read with ASCII string format. Specify the start program number to be read in "datano_s" and the end one in "datano_e". Store "datano_s=1" and "datano_e"=9999 to read all programs. Specify the format of program list in "type". type Format of list -------+--------------------------------------------0 Only program number. 1 Program number and comment. 2 Program number, comment and character number If the size of the buffer in which the program list is stored is insufficient, only informations whose total size is same or less than the buffer size is stored. Format of input data ~~~~~~~~~~~~~~~~~~~~ The program directory list which is read from CNC is a string composed of ASCII characters as following format. type=0 Oxxxx Oxxxx ... % type=1 % LF Oxxxx (COMMENT) LF Oxxxx (COMMENT) LF ... LF % type=2 Oxxxx (COMMENT) CHAR_NUMBER Oxxxx (COMMENT) CHAR_NUMBER ... % LF Oxxxx CHAR_NUMBER COMMENT 0x0A ('\n') Program number. This is a ASCII string without the leading '0' of numeric part sorted in numeric order. ("O1" "O9999") Character number of the program. This is a ASCII string without the leading '0'. The number is raised to 80-character unit. The comment which is written just after the program number is stored. The maximum character number of the comment body is 48. (50 for the body and the before and the behind parentheses.) Only beginning 48 characters are stored for the comment which is longer than 48 characters. If the program has no comment, only parentheses ("()") are stored. For all cases, when no program is registered or there is no program in the specified range, only '%' is stored. A null character ('\x00') is not added at the end of each strings stored in the buffer. For example, when the next programs are registered in CNC, the result of this function, in case that datano_s=1 and datano_e=9999, is as follows. Program number (COMMENT) Character number -------------------------------+---------------O0012 (TEST) ; 420 O0200 (WORK1) ; 352 O0201 ; 537 O9001 (SUB-PRO1) ; 781 type Contents to be read. -------+----------------------------------------------------------0 "O12O200O201O9001%" 1 "%\nO12(TEST)\nO200(WORK1)\nO201()\nO9001(SUB-PRO1)\n%" 2 "O12(TEST)420O200(WORK1)352O201()537O9001(SUB-PRO1)781%" If the buffer size is less than 15 bytes, the result is as follows. type Contents to be read. -------+----------------------------------------------------------0 "O12O200O201O900" 1 "%\nO12(TEST)\nO20" 2 "O12(TEST)420O20" [Example] The following program reads the registration information of NC program included specified by the arguments, and displays program number list. #include <data.h> #include <fwindow.h> #include <stdio.h> #include <string.h> #define BUFSIZE 256 /* start/end specify program number range. */ short example( long start, long end ) { char buf[BUFSIZE] ; short ret, idx ; memset( buf, '\x00', BUFSIZE ) ; ret = cnc_rdprogdir( 0, start, end, BUFSIZE-1, (struct prgdir *)(&buf) ) ; if ( ret ) { printf( "ERROR: %d\n", ret ) ; return ( ret ) ; } for ( idx = 0 ; idx < strlen( buf ) ; idx++ ) { if ( buf[idx] == 'O' ) putchar( '\n' ) ; putchar( buf[idx] ) ; } putchar( '\n' ) ; } -----------------------------------------------------------------------------1.18 Read program information. <Main,Alarm> -----------------------------------------------------------------------------[Name] cnc_rdproginfo [Syntax] #include <data.h> #include <fwindow.h> short cnc_rdproginfo( short type, short length, struct odbnc *buf ) ; struct odbnc { union { struct { short short long long reg_prg ; /* Amount of registered programs. */ unreg_prg ;/* Amount of available programs.*/ used_mem ; /* Character size of used memory.*/ unused_mem ;/* Character size of unused */ } bin ; /* memory. */ char asc[31] ; /* Buffer for ASCII string format. */ } u ; } ; [Arguments] type length buf Data type ( =0(binary), 1(ASCII) ). Data block length ( =16(binary), 35(ASCII) ). Buffer in which the program information is stored. [Return] EW_OK( 0) EW_LENGTH( 2) EW_NUMBER( 3) Successful. Incorrect data block length "length". Incorrect data type "type". [Description] Reads the management data of NC programs already registered in CNC. The management data of NC program are Amount of registered programs, Amount of available programs, Character number of used memory, Character number of unused memory. This function returns these data with binary format or ASCII string format. These informations are same as ones which are displayed in PROGRAM/LIB screen (in EDIT mode) of CNC. Specify arguments as follows for each formats. Format type length ---------------+-------+------binary 0 16 ASCII 1 35 Format of input data ~~~~~~~~~~~~~~~~~~~~ - type=0 Each data are stored in each members of the structure with binary format. - type=1 ASCII strings are stored in "buf.u.asc" with following format. % LF d1 LF d2 LF d3 LF d4 LF % LF 0x0A ('\n'). d1 Amount of registered programs. d2 Amount of available programs. d3 Character number of used memory. d4 Character number of unused memory. d1 - d4 are ASCII strings without the leading '0'. [Example] The following program reads the management data of NC program, and displays them. #include <data.h> #include <fwindow.h> #include <stdio.h> void example( void ) { struct odbnc buf ; short ret ; ret = cnc_rdproginfo( 0, 16, &buf ) ; if ( ret ) printf( "ERROR: %d\n", ret ) ; else { printf( "Registered program number buf.u.bin.reg_prg ) ; printf( "Registerable program number buf.u.bin.unreg_prg ) ; printf( "Used memory buf.u.bin.used_mem ) ; printf( "Free memory buf.u.bin.unused_mem ) ; } } = %d\n", = %d\n", = %ld\n", = %ld\n", -----------------------------------------------------------------------------1.19 Read program number in executing. <Main,Alarm> -----------------------------------------------------------------------------[Name] cnc_rdprgnum [Syntax] #include <data.h> #include <fwindow.h> short cnc_rdprgnum( struct odbpro *buf ) ; struct odbpro { short dummy[2] ; long data ; long mdata ; /* Not used. */ /* Program number in executing. */ /* Program number of the main program. */ } ; [Arguments] buf Buffer in which program numbers are stored. [Return] EW_OK( 0) Successful. [Description] Reads program number of the program which is being currently executed in CNC. If that program is a sub-program, the program number of the main program of it is also read. The program number which can be read is one of the root program. If the program in executing is not a sub-program, the main program number is set as 0. This function is used for management of NC programs in CNC by the application program, etc. The program numbers are stored in "buf.data" and 'buf.mdata" with unsigned binary format. [Example] The next program displays "CURRENT(O9876) MAIN(O1234)" while the block "O9876/N210" of the following NC program is being executed. #include <data.h> #include <fwindow.h> #include <stdio.h> void example( void ) { struct odbpro buf ; cnc_rdprgnum( &buf ) ; printf( "CURRENT(O%d) MAIN(O%d)\n", buf.data, buf.mdata ) ; } O1234 ; N10 M98 P5678 ; N20 M30 ; O5678 ; N110 M98 P9876 ; N120 M99 ; O9876 ; N210 M45 ; N220 M99 ; -----------------------------------------------------------------------------1.20 Read sequence number in executing. <Main,Alarm> -----------------------------------------------------------------------------[Name] cnc_rdseqnum [Syntax] #include <data.h> #include <fwindow.h> short cnc_rdseqnum( struct odbact *buf ) ; struct odbact { short dummy[2] ; long data ; /* Not used. */ /* Sequence number in executing. */ } ; [Arguments] buf Buffer in which sequence number is stored. [Return] EW_OK( 0) EW_BUSY(-1) Successful. It was impossible to read the sequence number of an NC program being executed because the CNC was updating that sequence number. [Description] Reads the sequence number of the NC program which is being currently executed in CNC. If the NC program has no sequence numbers in its all blocks, the sequence number of the last executed block is read. This function is used for watch the block being executed or the current process by the application program, or only displaying the current sequence number. The sequence number is stored in "buf.data" with unsigned binary format. [Example] The following program displays "CURRENT N30" while the block "O1234/N30" of the following NC program is being executed. #include <data.h> #include <fwindow.h> #include <stdio.h> void example( void ) { struct odbact buf ; cnc_rdseqnum( &buf ) ; printf( "CURRENT N%ld\n", buf.data ) ; } O1234 ; N10 M3 S1500 ; N20 T12 ; N30 G0 X110. ; N40 ... -----------------------------------------------------------------------------1.21 Read actual feed rate of controlled axes. <Main,Alarm> -----------------------------------------------------------------------------[Name] cnc_actf [Syntax] #include <data.h> #include <fwindow.h> short cnc_actf( struct odbact *buf ) ; struct odbact { short dummy[2] ; long data ; /* Not used. */ /* Actual feed rate (F). */ } ; [Arguments] buf Buffer in which the actual feed rate (F) is stored. [Return] EW_OK( 0) EW_BUSY(-1) Successful. It was impossible to read the actual feed rate of a controlled axis because the CNC was updating that actual feed rate. [Description] Reads the actual feed rate of the controlled axes of CNC. This actual feed rate is a composite feed rate. Therefore, in case that only basic axes, such as X, Y, or Z-axis, are being moved, the accurate feed rate can be read. But if any additional axes to the basic axes, such as the rotary 4th axis or the parallel axes, are being moved, the actual feed rate to be read is the composite one of all moving axes is read. This function is used for display the actual feed rate of the controlled axes of CNC by the application program, etc. The actual feed rate data is stored in "buf.data" with unsigned binary format. The unit of the actual feed rate is as follows. mm input inch input 1 [mm/min] 0.01 [inch/min] Even when a lathe is rotating in the feed-per-revolution mode, movement is measured in "per-minute" units. [Example] The message "CURRENT F=1200" is displayed if the following program is executed while the O1234/N20 block in the following NC program is being executed (on the assumption that the lathe is running in the metric input mode). #include <data.h> #include <fwindow.h> #include <stdio.h> void example( void ) { struct odbact buf ; cnc_actf( &buf ) ; printf( "CURRENT F=%ld\n", buf.data ) ; } O1234 ; N10 G98 F1200 ; N20 G1 U10. W200. N30 ... -----------------------------------------------------------------------------1.22 Read actual spindle speed. <Main,Alarm> -----------------------------------------------------------------------------[Name] cnc_acts [Syntax] #include <data.h> #include <fwindow.h> short cnc_acts( struct odbact *buf ) ; struct odbact { short dummy[2] ; long data ; /* Not used. */ /* Actual spindle speed. */ } ; [Arguments] buf Buffer in which the actual spindle speed is stored. [Return] EW_OK( 0) Successful. [Description] Reads the actual rotational speed of the spindle connected to CNC. The actual spindle speed data is stored in "buf.data" with unsigned binary format. [Example] The following program displays "CURRENT S=2470" while the actual rotational speed of the main spindle is 2470. #include <data.h> #include <fwindow.h> #include <stdio.h> void example( void ) { struct odbact buf ; cnc_acts( &buf ) ; printf( "CURRENT S=%ld\n", buf.data ) ; } -----------------------------------------------------------------------------1.23 Read absolute position. <Main,Alarm> -----------------------------------------------------------------------------[Name] cnc_absolute [Syntax] #include <data.h> #include <fwindow.h> short cnc_absolute( short axis, short length, struct iodbaxis *buf ) ; struct iodbaxis { short dummy ; short type ; long data[N] ; } ; [Arguments] axis length buf /* Not used. */ /* Axis number. */ /* Absolute position data of */ /* controlled axis. */ /* N is a maximum controlled axis number.*/ Axis number ( =(1,..,amount of controlled axes),or -1 ). Data block length ( =4+4*(Number of axes for which data is to be read) ). Buffer in which the absolute position data are stored. [Return] EW_OK( 0) EW_LENGTH( 2) EW_ATTRIB( 4) EW_BUSY(-1) Successful. Incorrect data block length "length". Incorrect axis number "axis". Any data other than -1 or (1,..,amount of controlled axes) has been specified. It was impossible to read the absolute position data for a controlled axis because the CNC was updating that absolute position data. [Description] Reads the absolute position data of the controlled axis of CNC. This absolute position data is identical to that in the absolute coordinate system displayed on the current position display screen of the CNC. This function is used for displaying the absolute positions of the controlled axes of CNC by the application program, etc. Specify one of (1,..,amount of controlled axes) for each axis or -1 for all axes as axis number in "axis". The absolute position format. (The negative The absolute position "buf.data[0]" in case data is stored in "buf.data" with signed binary value is represented as 2's complement.) data of specified axis is stored in of reading one axis's data. The unit of the absolute position data is as follows. IS-B IS-C -----------------------+---------------+--------------Linear axis(mm input) 0.001 [mm] 0.0001 [mm] Linear axis(inch input) 0.0001 [inch] 0.00001 [inch] Rotation axis 0.001 [deg] 0.0001 [deg] [Example] The following program displays 1: 120005 2: -50119 3: 80 while the absolute position data for each axes are The 1st axis 120.005 The 2nd axis -50.119 The 3rd axis 0.080 in 3-axis system. (in case of "mm input" and "IS-B".) #include <data.h> #include <fwindow.h> #include <stdio.h> void example( void ) { struct iodbaxis buf ; cnc_absolute( -1, 4+4*3, &buf ) ; printf( "1:%8ld\n2:%8ld\n3:%8ld\n", buf.data[0], buf.data[1], buf.data[2] ) ; } -----------------------------------------------------------------------------1.24 Read machine position. <Main,Alarm> -----------------------------------------------------------------------------[Name] cnc_machine [Syntax] #include <data.h> #include <fwindow.h> short cnc_machine( short axis, short length, struct iodbaxis *buf ) ; struct iodbaxis { short dummy ; short type ; long data[N] ; } ; [Arguments] axis length buf /* Not used. */ /* Axis number. */ /* Machine position data of */ /* controlled axis. */ /* N is a maximum controlled axis number.*/ Axis number ( =(1,..,amount of controlled axes),or -1 ). Data block length ( =4+4*(Number of axes for which data is to be read) ). Buffer in which the machine position data are stored. [Return] EW_OK( 0) EW_LENGTH( 2) EW_ATTRIB( 4) EW_BUSY(-1) Successful. Incorrect data block length "length". Incorrect axis number "axis". Any data other than -1 or (1,..,amount of controlled axes) has been specified. It was impossible to read the machine position data for a controlled axis because the CNC was updating that machine position data. [Description] Reads the machine position data of the controlled axis of CNC. This machine position data is identical to that in the machine coordinate system displayed on the current position display screen of the CNC. This function is used for displaying the machine positions of the controlled axes of CNC by the application program, etc. Specify one of (1,..,amount of controlled axes) for each axis or -1 for all axes as axis number in "axis". The machine position data is stored in "buf.data" with signed binary format. (The negative value is represented as 2's complement.) The machine position data of specified axis is stored in "buf.data[0]" in case of reading one axis's data. The unit of the machine position data is as follows. IS-B IS-C -----------------------+---------------+--------------Linear axis(mm output) 0.001 [mm] 0.0001 [mm] Linear axis(inch output)0.0001 [inch] 0.00001 [inch] Rotation axis 0.001 [deg] 0.0001 [deg] [Example] The following program displays "MACHINE 2: -265593" while the machine position data of the 2nd axis is -26.5593. (in case of "inch output" and "IS-B".) #include <data.h> #include <fwindow.h> #include <stdio.h> void example( void ) { struct iodbaxis buf ; cnc_machine( 2, 4+4*1, &buf ) ; printf( "MACHINE 2:%8ld\n", buf.data[0] ) ; } -----------------------------------------------------------------------------1.25 Read relative position. <Main,Alarm> -----------------------------------------------------------------------------[Name] cnc_relative [Syntax] #include <data.h> #include <fwindow.h> short cnc_relative( short axis, short length, struct iodbaxis *buf ) ; struct iodbaxis { short dummy ; short type ; long data[N] ; } ; [Arguments] axis length buf /* Not used. */ /* Axis number. */ /* Relative position data of */ /* controlled axis. */ /* N is a maximum controlled axis number.*/ Axis number ( =(1,..,amount of controlled axes),or -1 ). Data block length ( =4+4*(Number of axes for which data is to be read) ). Buffer in which the relative position data are stored. [Return] EW_OK( 0) EW_LENGTH( 2) EW_ATTRIB( 4) EW_BUSY(-1) Successful. Incorrect data block length "length". Incorrect axis number "axis". Any data other than -1 or (1,..,amount of controlled axes) has been specified. It was impossible to read the relative position data for a controlled axis because the CNC was updating that relative position data. [Description] Reads the relative position data of the controlled axis of CNC. This relative position data is identical to that in the relative coordinate system displayed on the current position display screen of the CNC. This function is used for displaying the relative positions of the controlled axes of CNC by the application program, etc. Specify one of (1,..,amount of controlled axes) for each axis or -1 for all axes as axis number in "axis". The relative position format. (The negative The relative position "buf.data[0]" in case data is stored in "buf.data" with signed binary value is represented as 2's complement.) data of specified axis is stored in of reading one axis's data. The unit of the relative position data is as follows. IS-B IS-C -----------------------+---------------+--------------Linear axis(mm input) 0.001 [mm] 0.0001 [mm] Linear axis(inch input) 0.0001 [inch] 0.00001 [inch] Rotation axis 0.001 [deg] 0.0001 [deg] [Example] The following program displays "RELATIVE 4: 900051" while the relative position data of the 4th axis(rotation axis) is 90.0051. (in case of "IS-C".) #include <data.h> #include <fwindow.h> #include <stdio.h> void example( void ) { struct iodbaxis buf ; cnc_relative( 4, 4+4*1, &buf ) ; printf( "RELATIVE 4:%8ld\n", buf.data[0] ) ; } -----------------------------------------------------------------------------1.26 Read distance to go. <Main,Alarm> -----------------------------------------------------------------------------[Name] cnc_distance [Syntax] #include <data.h> #include <fwindow.h> short cnc_distance( short axis, short length, struct iodbaxis *buf ) ; struct iodbaxis { short dummy ; short type ; long data[N] ; } ; [Arguments] axis length buf /* Not used. */ /* Axis number. */ /* Amount of distance to go of */ /* controlled axis. */ /* N is a maximum controlled axis number.*/ Axis number ( =(1,..,amount of controlled axes),or -1 ). Data block length ( =4+4*(Number of axes for which data is to be read) ). Buffer in which the amounts of distance to go are stored. [Return] EW_OK( 0) EW_LENGTH( 2) EW_ATTRIB( 4) EW_BUSY(-1) Successful. Incorrect data block length "length". Incorrect axis number "axis". Any data other than -1 or (1,..,amount of controlled axes) has been specified. It was impossible to read data about the distance-yet-to-go of a controlled axis because the CNC was updating that data. [Description] Reads the amount of distance to go of the controlled axis of CNC. This amount of distance to go is same as one which is displayed on the current position screen of CNC. This function is used for displaying the amount of distance to go of the controlled axes of CNC by the application program, etc. Specify one of (1,..,amount of controlled axes) for each axis or -1 for all axes as axis number in "axis". The amount of distance to go is stored in "buf.data" with signed binary format. (The negative value is represented as 2's complement.) The amount of distance to go of specified axis is stored in "buf.data[0]" in case of reading one axis's data. -----------------------------------------------------------------------------1.27 Read skipped position. <Main,Alarm> -----------------------------------------------------------------------------[Name] cnc_skip [Syntax] #include <data.h> #include <fwindow.h> short cnc_skip( short axis, short length, struct iodbaxis *buf ) ; struct iodbaxis { short dummy ; short type ; long data[N] ; } ; [Arguments] axis length buf /* Not used. */ /* Axis number. */ /* Skipped position data of */ /* controlled axis. */ /* N is a maximum controlled axis number.*/ Axis number ( =(1,..,amount of controlled axes),or -1 ). Data block length ( =4+4*(Number of axes for which data is to be read) ). Buffer in which the skipped position data are stored. [Return] EW_OK( 0) EW_LENGTH( 2) EW_ATTRIB( 4) EW_BUSY(-1) Successful. Incorrect data block length "length". Incorrect axis number "axis". Any data other than -1 or (1,..,amount of controlled axes) has been specified. It was impossible to read data about a skipped position for a controlled axis because the CNC was updating that data. [Description] Reads the absolute position data of the controlled axis at the position where the machine has stopped by "ON" of the skip signal during the CNC was executing the skip command (G31) block. It is possible to make the application program which tool length measurement by the application program. The application program can take a tool length measurement and so on by reading the skipped position of the controlled axis of CNC. Specify one of (1,..,amount of controlled axes) for each axis or -1 for all axes as axis number in "axis". The skipped position data is stored in "buf.data" with signed binary format. (The negative value is represented as 2's complement.) The skipped position data of specified axis is stored in "buf.data[0]" in case of reading one axis's data. The skipped position of the axis which has not been completed skip operation is undefined. The unit of the skipped position data is as follows. IS-B IS-C -----------------------+---------------+--------------Linear axis(mm input) 0.001 [mm] 0.0001 [mm] Linear axis(inch input) 0.0001 [inch] 0.00001 [inch] Rotation axis 0.001 [deg] 0.0001 [deg] [Example] The following program displays the skipped position of the 1st and 2nd axes. #include <data.h> #include <fwindow.h> #include <stdio.h> void example( void ) { struct iodbaxis buf ; unsigned int idx ; cnc_skip( 1, 4+4*1, &buf printf( "SKIP 1:%8ld\n", cnc_skip( 2, 4+4*1, &buf printf( "SKIP 2:%8ld\n", } ) ; buf.data[0] ) ; ) ; buf.data[0] ) ; -----------------------------------------------------------------------------1.28 Read servo delay amount. <Main,Alarm> -----------------------------------------------------------------------------[Name] cnc_srvdelay [Syntax] #include <data.h> #include <fwindow.h> short cnc_srvdelay( short axis, short length, struct iodbaxis *buf ) ; struct iodbaxis { short dummy ; hort type ; long data[N] ; } ; [Arguments] axis length buf /* Not used. */ /* Axis number. */ /* Servo delay amount of */ /* controlled axis. */ /* N is a maximum controlled axis number.*/ Axis number ( =(1,..,amount of controlled axes),or -1 ). Data block length ( =4+4*(Number of axes for which data is to be read) ). Buffer in which the servo delay amounts are stored. [Return] EW_OK( 0) EW_LENGTH( 2) EW_ATTRIB( 4) EW_BUSY(-1) Successful. Incorrect data block length "length". Incorrect axis number "axis". Any data other than -1 or (1,..,amount of controlled axes) has been specified. It was impossible to read the servo delay amount for a controlled axis because the CNC was updating that servo delay amount. [Description] Reads the difference between the commanded position and the actual servo position of the CNC's controlled axis, i.e. the servo delay amount. Specify one of (1,..,amount of controlled axes) for each axis or -1 for all axes as axis number in "axis". The servo delay amount is stored in "buf.data" with signed binary format. (The negative value is represented as 2's complement.) The servo delay amount of specified axis is stored in "buf.data[0]" in case of reading one axis's data. The unit of the servo delay amount is detection unit. [Example] The following program displays the servo delay amount of all axes (amount of axes = MAX). #include <data.h> #include <fwindow.h> #include <stdio.h> void example( void ) { struct iodbaxis buf ; unsigned int idx ; cnc_srvdelay( -1, 4+4*MAX, &buf ) ; for ( idx = 0 ; idx < MAX ; idx++ ) printf( "%u:%8ld\n", idx, buf.data[idx] ) ; } -----------------------------------------------------------------------------1.29 Read acceleration/deceleration delay amount. <Main,Alarm> -----------------------------------------------------------------------------[Name] cnc_accdecdly [Syntax] #include <data.h> #include <fwindow.h> short cnc_accdecdly( short axis, short length, struct iodbaxis *buf ) ; struct iodbaxis { short dummy ; short type ; long data[N] ; } ; [Arguments] axis length buf /* Not used. */ /* Axis number. */ /* Acceleration/deceleration delay */ /* amount of controlled axis. */ /* N is a maximum controlled axis number.*/ Axis number ( =(1,..,amount of controlled axes),or -1 ). Data block length ( =4+4*(Number of axes for which data is to be read) ). Buffer in which the acceleration/deceleration delay amounts are stored. [Return] EW_OK( 0) EW_LENGTH( 2) EW_ATTRIB( 4) EW_BUSY(-1) Successful. Incorrect data block length "length". Incorrect axis number "axis". Any data other than -1 or (1,..,amount of controlled axes) has been specified. It was impossible to read the acceleration/deceleration delay amount for a controlled axis because the CNC was updating that acceleration/deceleration delay amount. [Description] Reads the difference between the position commanded by the program and the one processed by acceleration/deceleration procedure of the CNC's controlled axis, i.e. the acceleration/deceleration delay amount. Specify one of (1,..,amount of controlled axes) for each axis or -1 for all axes as axis number in "axis". The acceleration/deceleration delay amount is stored in "buf.data" with signed binary format. (The negative value is represented as 2's complement.) The acceleration/deceleration delay amount of specified axis is stored in "buf.data[0]" in case of reading one axis's data. The unit of the acceleration/deceleration delay amount is as follows. IS-B IS-C -----------------------+---------------+--------------Linear axis(mm output) 0.001 [mm] 0.0001 [mm] Linear axis(inch output)0.0001 [inch] 0.00001 [inch] Rotation axis 0.001 [deg] 0.0001 [deg] [Example] The following program displays the acceleration/deceleration delay amount of all axes (amount of axes = MAX). #include <data.h> #include <fwindow.h> #include <stdio.h> void example( void ) { struct iodbaxis buf ; unsigned int idx ; cnc_accdecdly( -1, 4+4*MAX, &buf ) ; for ( idx = 0 ; idx < MAX ; idx++ ) printf( "%u:%8ld\n", idx, buf.data[idx] ) ; } -----------------------------------------------------------------------------1.30 Read dynamic data. <Main,Alarm> -----------------------------------------------------------------------------[Name] cnc_rddynamic [Syntax] #include <data.h> #include <fwindow.h> short cnc_rddynamic( short axis, short length, struct odbdy *buf ) ; struct } ; odbdy { short dummy ; /* Not used. */ short axis ; /* Axis number. */ short alarm ; /* Alarm status. */ long prgnum ; /* Program number in executing. */ long prgmnum ; /* Program number of the main prog. */ long seqnum ; /* Sequence number. */ long actf ; /* Actual feed rate. */ long acts ; /* Actual spindle speed. */ union { struct { long absolute[32] ; /* Absolute position */ /* data of controlled*/ /* axis. */ long machine[32] ; /* Machine position */ /* data of controlled*/ /* axis. */ long relative[32] ; /* Relative position */ /* data of controlled*/ /* axis. */ long distance[32] ; /* Amount of distance*/ /* to go of */ /* controlled axis. */ } faxis ; /* For all axes. */ struct { long absolute ; /* Absolute position */ /* data of controlled*/ /* axis. */ long machine ; /* Machine position */ /* data of controlled*/ /* axis. */ long relative ; /* Relative position */ /* data of controlled*/ /* axis. */ long distance ; /* Amount of distance*/ /* to go of */ /* controlled axis. */ } oaxis ; /* For one axis. */ } pos ; [Arguments] axis Axis number ( =(1,..,amount of controlled axes),or -1 ). (This is effective to only data who have axis attribute.) Data block length ( =22+4*4*(Number of axes for which data is to be read) ). Buffer in which the dynamic data are stored. length buf [Return] EW_OK( 0) EW_LENGTH( 2) EW_ATTRIB( 4) EW_BUSY(-1) Successful. Incorrect data block length "length". Incorrect axis number "axis". Any data other than -1 or (1,..,amount of controlled axes) has been specified. It was impossible to read dynamic data because the CNC was updating part of that data. [Description] Reads various data which are changing every second while NC program is executing at the same time. This function is used for getting data to display the current position screen or the monitoring screen, etc. This function reads the following data. Function used for reading Data individually -----------------------------------------------+-------------Alarm status cnc_alarm Program number in executing cnc_rdprgnum Program number of the main program cnc_rdprgnum Sequence number cnc_rdseqnum Actual feed rate cnc_actf Actual spindle speed cnc_acts Absolute position data of controlled axis cnc_absolute Machine position data of controlled axis cnc_machine Relative position data of controlled axis cnc_relative Amount of distance to go of controlled axis cnc_distance The formats of each data are same as "Function used for reading individually". Refer each functions for formats of data, etc. Specify one of (1,..,amount of controlled axes) for each axis or -1 for all axes as axis number in "axis". The array size of each member of odbdy.pos.faxis, which is used to read data related to all axes at a time, is fixed at 32 no matter how high the maximum controlled-axis number is. If the maximum controlled-axis number is lower than 32, no data is stored to the members that correspond to axis Nos. "maximum controlled-axis number + 1" to 32. [Example] The following program reads the dynamic data of all axes (amount of axes = MAX) and displays them on the screen. #include <data.h> #include <fwindow.h> #include <stdio.h> void example( void ) { struct odbdy buf ; unsigned int idx ; cnc_rddynamic( -1, sizeof(buf), &buf ) ; printf( "Current program = %d Main program = %d\n", buf.prgnum, buf.prgmnum ) ; printf( "Sequence number = %ld\n", buf.seqnum ) ; printf( "actf = %ld acts = %ld\n", buf.actf, buf.acts ) ; printf( "Alarm status = %d\n", buf.alarm ) ; printf( "AXIS Absolute Relative Machine Distance\n" ) ; printf( "----+---------+---------+---------+--------\n" ) ; for ( idx = 0 ; idx < MAX ; idx++ ) printf( " %u %8ld %8ld %8ld %8ld\n", idx, buf.pos.faxis.absolute[idx], buf.pos.faxis.relative[idx], buf.pos.faxis.machine[idx], buf.pos.faxis.distance[idx] ) ; } -----------------------------------------------------------------------------1.31 Read CNC status information. <Main,Alarm> -----------------------------------------------------------------------------[Name] cnc_statinfo [Syntax] #include <data.h> #include <fwindow.h> short cnc_statinfo( struct odbst *buf ) ; struct odbst { short short short short short short short short } ; [Arguments] buf dummy[2]; aut; run; motion; mstb; emergency; alarm; edit; /* /* /* /* /* /* /* /* Not used OPERATION Status of Status of Status of Status of Status of Status of mode selection automatic operation axis movement,dwell M,S,T,B function emergency stop, rest alarm program editing */ */ */ */ */ */ */ */ Buffer in which the status informations are stored. [Return] EW_OK( 0) Successful. [Description] Reads the status informations of CNC which are displayed in the bottom of the NC's screen. This function reads the following status informations. (1) Operation mode (aut) Value Display Description -------+-------+----------------------------------0 MDI Manual data input mode 1 MEM Automatic operation mode 2 **** Not used 3 EDIT Memory editing mode 4 HND Manual handle feed mode 5 JOG Jog feed mode 6 TJOG TEACH IN JOG mode 7 THND TEACH IN HANDLE mode 8 INC Manual incremental feed mode 9 REF Manual reference position return mode 10 RMT Automatic operation (part program operation) mode (2) Automatic operation status (run) Value Display Description -------+-------+----------------------------------0 **** Reset 1 STOP Automatic operation stopped 2 HOLD Automatic operation suspended 3 STRT Automatic operation started (3) Axis moving/dwelling status (motion) Value Display Description -------+-------+----------------------------------0 *** Axis neither moving nor dwelling 1 MTN Axis moving 2 DWL Axis dwelling (4) M, S, T, or B function status (mstb) Value Display Description -------+-------+----------------------------------0 *** FIN signal not awaited. 1 FIN Auxiliary function being executed (FIN signal awaited) Emergency stop or reset status (emergency) Value Display Description -------+-------+----------------------------------0 Not Neither at emergency stop nor at reset displayed 1 --EMG-- At emergency stop 2 -RESET- At reset (5) (6) Alarm status (alarm) Value Display Description -------+-------+----------------------------------0 *** No alarm/warning 1 ALM Alarm 2 BAT Low battery voltage (7) Program editing status (edit) Value Display Description -------+-------+----------------------------------0 Not Editing not in progress displayed 1 EDIT Editing (such as insertion or updating) in progress 2 SRCH Search in progress 3 OUTPUT Data output in progress 4 INPUT Data input in progress 5 COMPARE Data comparison in progress 6 LSK Label skip at data input 7 OFT Offset input in progress 8 WSFT Work shift amount input in progress 9 RSTR Program restarted (*) Generally, because the CNC continuously performs editing if buf.edit is not 0, control is not passed to an application task. For this reason, an attempt by any application task to read buf.edit only results in 0 being read. -----------------------------------------------------------------------------1.32 Read alarm status. <Main,Alarm> -----------------------------------------------------------------------------[Name] cnc_alarm [Syntax] #include <data.h> #include <fwindow.h> short cnc_alarm( struct odbapb *buf ) ; struct odbapb { short dummy[2] ; short data ; /* Not used. */ /* Alarm status. */ } ; [Arguments] buf Buffer in which the alarm status is stored. [Return] EW_OK( 0) Successful. [Description] Reads the alarm status of CNC. This function is used for watching CNC's alarm status, displaying the maintenance information or guidance of how to reset the alarm, etc. The alarm status is stored in each bits of "buf.data" as follows. buf.data bit0 bit1 bit2 bit3 bit4 bit5 bit6 bit7 bit8 bit9 bit10 bit11 bit12 bit13 bit14 bit15 The parameter write switch is on. A parameter that requires turning off the power was input. I/O error Foreground P/S Overtravel/external data input error Overheat Servo alarm Data input/output error Macro alarm Spindle alarm OT alarm that will not lead to a PS alarm Alarm related to malfunction prevention Background P/S Synchronization error too high Reserved External alarm message (SW) (PW) (IO) (PS) (OT) (OH) (SV) (SR) (MC) (SP) (DS) (IE) (BG) (SN) (EX) When any alarm is arising, the correspondent bit of "buf.data" is set as "1". If no alarm, each bit is "0". -----------------------------------------------------------------------------1.33 Read alarm information. <Main,Alarm> -----------------------------------------------------------------------------[Name] cnc_rdalminfo [Syntax] #include <data.h> #include <fwindow.h> short cnc_rdalminfo( short type, short alm_type, short length, struct alminfo *buf ) ; struct alminfo { union { struct { struct { long axis ; /* Axis information. */ short alm_no ; /* Alarm number. */ } alm[N] ; /* N is number of messages to be read. */ long data_end ; } alm1 ; struct { struct { long axis ; /* Axis information. */ short alm_no ; /* Alarm number. */ short msg_len ; /* Message length. */ char alm_msg[32] ; /* Alarm message. */ } alm[N] ; /* N is number of messages to be read. */ long data_end ; }alm2 ; } u ; } ; [Arguments] type alm_type length buf Data format ( =0(without message), 1(with message) ). Kind of alarm ( =0,..,31 ). Data block length ( =4+6*N(without message), 4+40*N(with message) ). Buffer in which the alarm information is stored. [Return] EW_OK( 0) EW_LENGTH( 2) EW_NUMBER( 3) EW_DATA( 5) Successful. Incorrect data block length "length". Incorrect data format type "type". Incorrect kind of alarm "alm_type". [Description] Reads the detail informations of currently arising CNC alarms. This function is used for displaying the alarm numbers or messages of the currently arising alarms by the application program, etc. Specify the kind of alarm to be read in "alm_type". alm_type Kind of alarm ---------------+----------------------------------------------0 The parameter write switch is on. (SW) 1 A parameter that requires turning off the power was input. (PW) 2 I/O error (IO) 3 Foreground P/S (PS) 4 Overtravel/external data input error (OT) 5 Overheat (OH) 6 Servo alarm (SV) 7 Data input/output error (SR) 8 Macro alarm (MC) 9 Spindle alarm (SP) 10 OT alarm that will not lead to a PS alarm (DS) 11 Alarm related to malfunction prevention (IE) 12 Background P/S (BG) 13 Synchronization error too high (SN) 14 Reserved 15 External alarm message (EX) 16 External alarm message (EX2) 17 External alarm message (EX3) 18 External alarm message (EX4) 19 20 PMC error Not used : Not used (PC) 31 Specify data format in "type". type Contents of read data -------+------------------------------------------------0 Axis information and alarm number 1 Axis information, alarm number and alarm message Format of input data ~~~~~~~~~~~~~~~~~~~~ - type = 0 +-----------------------+ | Axis information 1 | <-- buf.u.alm1.alm[0].axis |-----------------------| | Alarm number 1 | <-- buf.u.alm1.alm[0].alm_no |-----------------------| : |-----------------------| | Axis information n | |-----------------------| | Alarm number n | |-----------------------| | 0xFFFF (End of data) | +-----------------------+ Maximum value of n is N. - type = 1 +-----------------------+ | Axis information 1 | |-----------------------| | Alarm number 1 | |-----------------------| | Message length 1 | |-----------------------| | Alarm message 1 | |-----------------------| : |-----------------------| | Axis information n | |-----------------------| | Alarm number n | |-----------------------| | Message length n | |-----------------------| | Alarm message n | |-----------------------| | 0xFFFF (End of data) | +-----------------------+ Maximum value of n is N. <-- buf.u.alm2.alm[0].axis <-- buf.u.alm2.alm[0].alm_no <-- buf.u.alm2.alm[0].msg_len <-- buf.u.alm2.alm[0].alm_msg "Axis information" indicates axes in which any alarm is arising by each bits. bit0 The 1st axis. bit1 The 2nd axis. : : bit31 The 32nd axis. "1" of each bit indicates any alarm is arising the corresponding axis. When all bits are "0", the alarm is not axis-type one but any ordinary one. When the same alarm is arising for the multiple axes, the corresponding multiple bits of the axis information are set as "1". "Alarm number" is the alarm number (binary format). "Message length" is a length of the alarm message. A value between 0 and 32 is stored with binary format. "Alarm message" the alarm message. It is ASCII string which is same as one displayed in the CNC's alarm screen. 2-byte characters such as Japanese Kanji character are represented using SHIFT-JIS code. A null character ('\x00') is added at the end of the string only when the string length is less than or equal to 32 bytes. A blank character is stored in the message of any axis-type alarm instead of the axis name character. The application program must store the suitable axis-name character in it. When no alarms which belong to specified kind arise, only "End of data" is stored. This function can't read the alarm mesages (numbers 1000 to 1999) issued by PMC. -----------------------------------------------------------------------------1.34 Read tool offset amount. <Main,Alarm> -----------------------------------------------------------------------------[Name] cnc_rdtofs [Syntax] #include <data.h> #include <fwindow.h> short cnc_rdtofs( short number, short type, short length, struct odbtool *buf ) ; struct odbtool short short long { datano ; type ; data ; /* Offset number. */ /* Offset type. */ /* Offset data. */ } ; [Arguments] number type length buf Offset number. Offset type. Data block length ( =8 ). Buffer in which the offset amount is stored. [Return] EW_OK( 0) EW_LENGTH( 2) EW_NUMBER( 3) EW_ATTRIB( 4) EW_NOOPT( 6) EW_BUSY(-1) Successful. Incorrect data block length "length". Incorrect offset number "number". (This return code is returned in case that any value except 1,..,(maximum number of offset) was specified in offset number "number". Incorrect offset type "type". There are no additional tool offset options required for the specified offset number to be read. Related options (M Series) - Number of tool compensation values (32)/64/99/200/400/499/999 sets - Tool compensation memory (A)/B/C Related options (T Series) - Number of tool compensation values (32)/64/99/200/400/499/999 sets - Tool-nose radius compensation - Tool geometry compensation and wear compensation - Y-axis offset Marked item by "()" is the basic function. It has been failed to read tool offset amount because the other application program has already started writing tool offset amount. [Description] Reads the tool offset amount stored in the CNC. Tool wear/geometry offset amounts and cutter radius/tool length offset amounts, etc. can be read. This function is used for the automatic programming function by the application program, for example, which reads the required cutter radius offset amount for calculation of cutter radius compensation by the automatic programming function. Also, this is used for maintenance of CNC as follows. Saves tool offset amounts stored in CNC to the application's memory, Clears CNC's memory, Restores them. Specify the kind of offset amount to be read in "type". Machining Center Series type Kind of offset amount -------+-----------------------------------------------------0 Cutter radius compensation/wear offset amount 1 Cutter radius compensation/geometry offset amount 2 Tool length compensation/wear offset amount 3 Tool length compensation/geometry offset amount Specify "0" in case without distinctions of cutter radius/tool length and wear/geometry. Lathe Series type Kind of offset amount -------+---------------------0 X-axis wear offset amount 1 X-axis geometry offset amount 2 Z-axis wear offset amount 3 Z-axis geometry offset amount 4 Tool-nose radius wear offset amount 5 Tool-nose radius geometry offset amount 6 Virtual tool tip direction 7 Virtual tool tip direction 8 Y-axis wear offset amount 9 Y-axis geometry offset amount If there is no tool geometry compensation option, specify a wear compensation option. The offset amount is stored in "buf.data" with signed binary format. (The negative value is represented as 2's complement.) The unit of offset amount is as follows. IS-B IS-C -------------------------------+---------------+--------------Linear axis (metric input) 0.001 [mm] 0.0001 [mm] Linear axis (inch input) 0.0001 [inch] 0.00001 [inch] Rotation axis 0.001 [deg] 0.0001 [deg] [Example] The following program reads the wear offset amount for an axis related to each specified tool number. (Lathe series) #include <data.h> #include <fwindow.h> #include <stdio.h> /* tidx is tool index. */ void example( short tidx ) { struct odbtool buf ; short ret ; ret = cnc_rdtofs( tidx, 0, if ( !ret ) printf( "X(%d) ret = cnc_rdtofs( tidx, 2, if ( !ret ) printf( "Z(%d) ret = cnc_rdtofs( tidx, 8, if ( !ret ) printf( "Y(%d) } 8, &buf ) = %ld\n", 8, &buf ) = %ld\n", 8, &buf ) = %ld\n", ; tidx, buf.data ) ; ; tidx, buf.data ) ; ; tidx, buf.data ) ; -----------------------------------------------------------------------------1.35 Write tool offset amount. <Main,Alarm> -----------------------------------------------------------------------------[Name] cnc_wrtofs [Syntax] #include <data.h> #include <fwindow.h> short cnc_wrtofs( short number, short type, short length, long data ) ; [Arguments] number type length data Offset number. Offset type. Data block length ( =8 ). Offset data. [Return] EW_OK( 0) EW_LENGTH( 2) EW_NUMBER( 3) EW_ATTRIB( 4) EW_NOOPT( 6) EW_BUSY(-1) Successful. Incorrect data block length "length". Incorrect offset number "number". (This return code is returned in case that any value except 1,..,(maximum number of offset) was specified in offset number "number". Incorrect offset type "type". There are no additional tool offset options required for the specified offset number to be written. (See "Read tool offset amount(cnc_rdtofs)" for details.) An attempt was made to execute this command when other window processing of a low-speed type was in progress. Execute the command after the window processing has ended. [Description] Alters the tool offset amount stored in the CNC. Tool wear/geometry offset amounts and cutter radius/tool length offset amounts, etc. can be written in. This function is used for the preparation of machining or the tool offset measurement by the application program, to write the result of those processing into the CNC's memory. Also, this is used for restoring the tool offset amounts which are already saved into the application's memory, etc. Specify the kind of offset amount to be written in "type". Machining Center Series type Kind of offset amount -------+-----------------------------------------------------0 Cutter radius compensation/wear offset amount 1 Cutter radius compensation/geometry offset amount 2 Tool length compensation/wear offset amount 3 Tool length compensation/geometry offset amount Specify "0" in case without distinctions of cutter radius/tool length and wear/geometry. Lathe Series type Kind of offset amount -------+-----------------------------------------------------0 X-axis wear offset amount 1 X-axis geometry offset amount 2 Z-axis wear offset amount 3 Z-axis geometry offset amount 4 Tool-nose radius wear offset amount 5 Tool-nose radius geometry offset amount 6 Virtual tool tip direction 7 Virtual tool tip direction 8 Y-axis wear offset amount 9 Y-axis geometry offset amount If there is no tool geometry compensation option, specify a wear compensation option. Store the offset amount in "buf.data" with signed binary format. (The negative value is represented as 2's complement.) The unit of offset amount is as follows. IS-B IS-C -------------------------------+---------------+--------------Linear axis (metric input) 0.001 [mm] 0.0001 [mm] Linear axis (inch input) 0.0001 [inch] 0.00001 [inch] Rotation axis 0.001 [deg] 0.0001 [deg] [Example] The following program rewrites an offset amount having a specified number. (Machining center series) #include <data.h> #include <fwindow.h> /* tidx is tool index. */ /* offset is new offset value. */ short example( short tidx, long offset ) { short ret ; ret = cnc_wrtofs( tidx, 0, 8, offset ) ; return ( ret ) ; } -----------------------------------------------------------------------------1.36 Read tool offset amount (range specified). <Main,Alarm> -----------------------------------------------------------------------------[Name] cnc_rdtofsr [Syntax] #include <data.h> #include <fwindow.h> short cnc_rdtofsr( short s_number, short type, short e_number, short length, struct iodbto *buf ) ; struct iodbto { short datano_s ; /* Start offset number. */ short type ; /* Offset type. */ short datano_e ; /* End offset number. */ union { long m_ofs[N] ; /* M Series individual. */ long m_ofs_a[N] ; /* M Series Memory A all. */ long m_ofs_b[2*N] ; /* M Series Memory B all. */ long m_ofs_c[4*N] ; /* M Series Memory C all. */ short t_tip[N] ; /* T Series individual, */ /* direction of imaginary */ /* tool nose. */ long t_ofs[N] ; /* T Series individual. */ struct { short tip ; long data[4] ; } t_ofs_a[N] ; /* T Series Memory A all. */ struct { short tip ; long data[8] ; } t_ofs_b[N] ; /* T Series Memory B all. */ } u ; } ; /* N is number of the offset amounts to be read. */ [Arguments] s_number type e_number length buf Start offset number. Offset type. End offset number. Data block length. Buffer in which the offset amounts are stored. [Return] EW_OK( 0) EW_LENGTH( 2) EW_NUMBER( 3) EW_ATTRIB( 4) EW_NOOPT( 6) EW_BUSY(-1) Successful. Incorrect data block length "length". Incorrect offset number "s_number" or "e_number". (This return code is returned in case that any value except 1,..,(maximum number of offset) was specified in offset number "s_number" or "e_number". Incorrect offset type "type". There are no additional tool offset options required for the specified offset number to be read. (See "Read tool offset amount(cnc_rdtofs)" for details.) It was impossible to read a tool offset amount because a command from another application program to write the tool offset amount was already being executed. [Description] Reads the tool offset amount stored in the CNC within the specified range. Specify the start offset number in "s_number" and the end one in "e_number". Specify the kind of offset amount to be read in "type". The combinations of the value specified in "type", the data block length "length", the kind of offset amount to be read and the member where the result is stored in are as follows. Machining Center Series/Tool offset Memory A type length Attribute Offset type Member to be stored in -------+-------+---------------+-----------------------+---------------------0 6+4*N individual Tool offset buf.u.m_ofs[i] -------+-------+---------------+-----------------------+----------------------1 6+4*N all Tool offset buf.u.m_ofs_a[i] Machining Center Series/Tool offset Memory B type length Attribute Offset type Member to be stored in -------+-------+---------------+-----------------------+---------------------0 6+4*N individual Tool geometry offset buf.u.m_ofs[i] 1 6+4*N individual Tool wear offset buf.u.m_ofs[i] -------+-------+---------------+-----------------------+----------------------2 6+8*N all Tool geometry offset buf.u.m_ofs_b[8*i+0] Tool wear offset buf.u.m_ofs_b[8*i+4] Machining Center Series/Tool offset Memory C type length Attribute Offset type Member to be stored in -------+-------+---------------+-----------------------+---------------------0 6+4*N individual Tool length/geometry buf.u.m_ofs[i] 1 6+4*N individual Tool length/wear buf.u.m_ofs[i] 2 6+4*N individual Cutter radius/geometry buf.u.m_ofs[i] 3 6+4*N individual Cutter radius/wear buf.u.m_ofs[i] -------+-------+---------------+-----------------------+----------------------3 6+16*N all Tool length/geometry buf.u.m_ofs_c[16*i+0] Tool length/wear buf.u.m_ofs_c[16*i+4] Cutter radius/geometry buf.u.m_ofs_c[16*i+8] Cutter radius/wear buf.u.m_ofs_c[16*i+12] Lathe Series/Tool offset Memory A type length Attribute Offset type Member to be stored in -------+-------+---------------+-----------------------+---------------------0 6+2*N individual Virtual tool tip direction buf.u.t_tip[i] 1 6+4*N individual X-axis offset amount buf.u.t_ofs[i] 2 6+4*N individual Y-axis offset amount buf.u.t_ofs[i] 3 6+4*N individual Z-axis offset amount buf.u.t_ofs[i] 4 6+4*N individual Tool-nose radius offset amount buf.u.t_ofs[i] -------+-------+---------------+-----------------------+----------------------1 6+18*N all Virtual tool tip direction buf.u.t_ofs_a[i].tip X-axis offset amount buf.u.t_ofs_a[i].data[0] Y-axis offset amount buf.u.t_ofs_a[i].data[1] Z-axis offset amount buf.u.t_ofs_a[i].data[2] Tool-nose radius offset amount buf.u.t_ofs_a[i].data[3] Lathe Series/Tool offset Memory B type length Attribute Offset type Member to be stored in -------+-------+---------------+-----------------------+---------------------0 6+2*N individual Virtual tool tip direction buf.u.t_tip[i] 1 6+4*N individual X-axis geometry offset amount buf.u.t_ofs[i] 2 6+4*N individual Y-axis geometry offset amount buf.u.t_ofs[i] 3 6+4*N individual Z-axis geometry offset amount buf.u.t_ofs[i] 4 6+4*N individual Tool-nose radius geometry offset amount buf.u.t_ofs[i] 5 6+4*N individual X-axis wear offset amount buf.u.t_ofs[i] 6 6+4*N individual Y-axis wear offset amount buf.u.t_ofs[i] 7 6+4*N individual Z-axis wear offset amount buf.u.t_ofs[i] 8 6+4*N individual Tool-nose radius wear offset amount buf.u.t_ofs[i] -------+-------+---------------+-----------------------+----------------------2 6+34*N all Virtual tool tip direction buf.u.t_ofs_b[i].tip X-axis geometry offset amount buf.u.t_ofs_b[i].data[0] Y-axis geometry offset amount buf.u.t_ofs_b[i].data[1] Z-axis geometry offset amount buf.u.t_ofs_b[i].data[2] Tool-nose radius geometry offset amount buf.u.t_ofs_b[i].data[3] X-axis wear offset amount buf.u.t_ofs_b[i].data[4] Y-axis wear offset amount buf.u.t_ofs_b[i].data[5] Z-axis wear offset amount buf.u.t_ofs_b[i].data[6] Tool-nose radius wear offset amount buf.u.t_ofs_b[i].data[7] N is number of offset to be read, i = 0,..,(N-1). The offset amounts are stored in "buf.u.xxx[i]" with signed binary format. (The negative value is represented as 2's complement.) The unit of offset amount is as follows. IS-B IS-C -------------------------------+---------------+--------------Linear axis (metric input) 0.001 [mm] 0.0001 [mm] Linear axis (inch input) 0.0001 [inch] 0.00001 [inch] Rotation axis 0.001 [deg] 0.0001 [deg] [Example] The following program reads and displays the tool offset amounts for all tools on a lathe (memory B/64 sets). #include <data.h> #include <fwindow.h> #include <stdio.h> #include <stdlib.h> #define MAXTOOL 64 short example( void ) { struct iodbto *buf ; short ret, idx ; buf = (struct iodbto *)malloc( 6+34*MAXTOOL ) ; ret = cnc_rdtofsr( 1, -2, MAXTOOL, 6+34*MAXTOOL, buf ) ; if ( !ret ) { printf( "No X:wear Z:wear Y:wear X:geom " "Z:geom Y:geom R:wear R:geom T\n" ) ; printf( "---+-------+-------+-------+-------+" "-------+-------+-------+------+-\n" ) ; for ( idx = 0 ; idx < MAXTOOL ; idx++ ) { printf( "%02d%8ld%8ld%8ld%8ld%8ld%8ld%8ld%8ld%2d\n", idx, buf->u.t_ofs_b[idx].data[4], buf->u.t_ofs_b[idx].data[5], buf->u.t_ofs_b[idx].data[6], buf->u.t_ofs_b[idx].data[0], buf->u.t_ofs_b[idx].data[1], buf->u.t_ofs_b[idx].data[2], buf->u.t_ofs_b[idx].data[7], buf->u.t_ofs_b[idx].data[3], buf->u.t_ofs_b[idx].tip ) ; } } free( buf ) ; return ( ret ) ; } -----------------------------------------------------------------------------1.37 Write tool offset amount (range specified). <Main,Alarm> -----------------------------------------------------------------------------[Name] cnc_wrtofsr [Syntax] #include <data.h> #include <fwindow.h> short cnc_wrtofsr( short length, struct iodbto *buf ) ; struct iodbto { short datano_s ; /* Start offset number. */ short type ; /* Offset type. */ short datano_e ; /* End offset number. */ union { long m_ofs[N] ; /* M Series individual. */ long m_ofs_a[N] ; /* M Series Memory A all. */ long m_ofs_b[2*N] ; /* M Series Memory B all. */ long m_ofs_c[4*N] ; /* M Series Memory C all. */ short t_tip[N] ; /* T Series individual, */ /* direction of imaginary */ /* tool nose. */ long t_ofs[N] ; /* T Series individual. */ struct { short tip ; long data[4] ; } t_ofs_a[N] ; /* T Series Memory A all. */ struct { short tip ; long data[8] ; } t_ofs_b[N] ; /* T Series Memory B all. */ } u ; } ; /* N is number of the offset amounts to be read. */ [Arguments] length buf Data block length. Buffer in which the offset amounts are stored. [Return] EW_OK( 0) EW_LENGTH( 2) EW_NUMBER( 3) EW_ATTRIB( 4) EW_NOOPT( 6) EW_BUSY(-1) Successful. Incorrect data block length "length". Incorrect offset number "buf.datano_s" or "buf.datano_e". (This return code is returned in case that any value except 1,..,(maximum number of offset) was specified in offset number "s_number" or "e_number". Incorrect offset type "buf.type". There are no additional tool offset options required for the specified offset number to be written. (See "Read tool offset amount(cnc_rdtofs)" for details.) An attempt was made to execute this command when other window processing of a low-speed type was in progress. Execute the command after the window processing has ended. [Description] Alters the tool offset amount stored in the CNC within the specified range. Specify the start offset number in "buf.datano_s" and the end one in "buf.datano_e". Specify the kind of offset amount to be read in "type". The combinations of the value specified in "type", the data block length "length", the kind of offset amount to be read and the member where the result is stored in are same as "Read tool offset amount(range specified)(cnc_rdtofsr)". Refer description of it. Store the offset amount in "buf.u.xxx[i]" with signed binary format. (The negative value is represented as 2's complement.) The unit of offset amount is as follows. IS-B IS-C -------------------------------+---------------+--------------Linear axis (metric input) 0.001 [mm] 0.0001 [mm] Linear axis (inch input) 0.0001 [inch] 0.00001 [inch] Rotation axis 0.001 [deg] 0.0001 [deg] [Example] The following program stores all tool offset amounts of Machining-Series(Memory A/64 sets). #include <data.h> #include <fwindow.h> #include <stdlib.h> #include <string.h> #define MAXTOOL 64 /* offset is array of new offset value. */ short example( long *offset ) { struct iodbto *buf ; short ret ; buf = (struct iodbto *)malloc( 6+4*MAXTOOL ) ; buf->datano_s = 1 ; buf->datano_e = MAXTOOL ; buf->type = -1 ; memcpy( &(buf->u.m_ofs_a[0]), offset, 4*MAXTOOL ) ; ret = cnc_wrtofsr( 6+4*MAXTOOL, buf ) ; free( buf ) ; return ( ret ) ; } -----------------------------------------------------------------------------1.38 Read work origin offset. <Main,Alarm> -----------------------------------------------------------------------------[Name] cnc_rdzofs [Syntax] #include <data.h> #include <fwindow.h> short cnc_rdzofs( short number, short axis, short length, struct iodbaxis *buf ) ; struct } ; iodbaxis { short datano ; short type ; long data[N] ; Offset number. */ Axis number. */ Offset data. */ N is the amount of controlled axes. */ Maximum controlled-axis number 32 [Arguments] number axis length buf /* /* /* /* Offset number ( 0, 1,..,6, 7,..,306 ). Axis number ( =(1,..,amount of controlled axes),or -1 ). Data block length ( =4+4*(amount of axes to be read)). Buffer in which the offset amount is stored. [Return] EW_OK( 0) EW_LENGTH( 2) EW_NUMBER( 3) EW_ATTRIB( 4) EW_NOOPT( 6) EW_BUSY(-1) Successful. Incorrect data block length "length". Incorrect of offset number "number". (Any data other than 0,..,6 or 7,..,306 has been specified.) Incorrect axis number "axis". Any data other than -1 or (1,..,amount of controlled axes) has been specified. There are no required options. The related options; - Work coordinate system ( G54 to G59 ) - Work coordinate system 48 sets ( G54.1P1-P48 ) - Work coordinate system 300 sets ( G54.1P1-P300 ) - Controlled axis expansion It was impossible to read a work origin offset because a command from another application program to write the work origin offset was already being executed. [Description] Reads the work origin offset amount stored in the CNC. In the CNC, a work origin offset amount is provided for each controlled axis (the first to 32nd controlled axes). The work origin offset amount can be read either for individual axes separately or for all axes at a time. If there is no controlled axis expansion option, however, it is impossible to read a work origin offset amount for additional axes. This function is used for maintenance of CNC as follows, etc. Saves work origin offset amounts stored in CNC to the application's memory, Clears CNC's memory, Restores them. Specify one of (1,..,amount of controlled axes) for each axis or -1 for all axes as axis number in "axis". Specify one of following value as offset number in "number". number Kind of work origin offset amount ---------------+-------------------------------------------0 External work origin offset amount 1,..,6 Work origin offset amount of G54 through G59 7,..,306 Work origin offset amount of G54.1P1 through G54.1P300 The work origin offset amount is stored in "buf.data" with signed binary format. (The negative value is represented as 2's complement.) The work origin offset amount of specified axis is stored in "buf.data[0]" in case of reading one axis's data. The unit of the work origin offset amount is as follows. IS-B IS-C -------------------------------+---------------+--------------Linear axis (metric input) 0.001 [mm] 0.0001 [mm] Linear axis (inch input) 0.0001 [inch] 0.00001 [inch] Rotation axis 0.001 [deg] 0.0001 [deg] [Example] The following program displays the work origin offset amounts of the specified number for all axes ( MAX (amount of axes = 32) ). #include <data.h> #include <fwindow.h> #include <stdio.h> /* ofs is offset number to be displayed. */ void example( short ofs ) { struct iodbaxis buf ; unsigned int idx ; cnc_rdzofs( ofs, -1, 4+4*MAX, &buf ) ; for ( idx = 0 ; idx < MAX ; idx++ ) printf( "%u:%8ld\n", idx, buf.data[idx] ) ; } -----------------------------------------------------------------------------1.39 Write work origin offset. <Main,Alarm> -----------------------------------------------------------------------------[Name] cnc_wrzofs [Syntax] #include <data.h> #include <fwindow.h> short cnc_wrzofs( short length, struct iodbaxis *buf ) ; struct } ; iodbaxis { short datano ; short type ; long data[N] ; Offset number. */ Axis number. */ Offset data. */ N is the amount of controlled axes. */ Maximum controlled-axis number 32 [Arguments] length buf /* /* /* /* Data block length ( =4+4*(amount of axes to be read)). Buffer in which the offset amount is stored. [Return] EW_OK( 0) EW_LENGTH( 2) EW_NUMBER( 3) EW_ATTRIB( 4) EW_NOOPT( 6) EW_BUSY(-1) Successful. Incorrect data block length "length". Incorrect of offset number "number". (Any data other than 0,..,6 or 7,..,306 has been specified.) Incorrect axis number "axis". Any data other than -1 or (1,..,amount of controlled axes) has been specified. There are no required options. (See "Read work origin offset(cnc_rdzofs)" for details.) An attempt was made to execute this command when other window processing of a low-speed type was in progress. Execute the command after the window processing has ended. [Description] Alters the work origin offset amount stored in the CNC. In the CNC, a work origin offset amount is provided for each controlled axis (the first to 32nd controlled axes). The work origin offset amount can be rewritten either for individual axes separately or for all axes at a time. If there is no controlled axis expansion option, however, it is impossible to rewrite the work origin offset amount for additional axes. This function is used for adjustment of the workpiece position using the work origin offset by the application program, to write the result of those processing into the CNC's memory. Also, this is used for restoring the work origin offset amounts which are already saved into the application's memory, etc. Specify one of (1,..,amount of controlled axes) for each axis or -1 for all axes as axis number in "buf.type". Specify one of following value as offset number in "buf.datano". datano Kind of work origin offset amount ---------------+-------------------------------------------0 External work origin offset amount 1,..,6 Work origin offset amount of G54 through G59 7,..,306 Work origin offset amount of G54.1P1 through G54.1P300 Store the work origin offset amount in "buf.data" with signed binary format. (The negative value is represented as 2's complement.) Store the work origin offset amount of specified axis in "buf.data[0]" in case of altering one axis's data. The unit of the work origin offset amount is as follows. IS-B IS-C -------------------------------+---------------+--------------Linear axis (metric input) 0.001 [mm] 0.0001 [mm] Linear axis (inch input) 0.0001 [inch] 0.00001 [inch] Rotation axis 0.001 [deg] 0.0001 [deg] [Example] The following program alters the work origin offset amount of the specified offset number and axis number. #include <data.h> #include <fwindow.h> /* ofs is offset number to be altered. */ /* axis is the axis number, offset is new offset value. */ short example( short ofs, short axis, long offset ) { struct iodbaxis buf ; short ret ; buf.datano = ofs ; buf.type = axis ; buf.data[0] = offset ; ret = cnc_wrzofs( 4+4*1, &buf ) ; return ( ret ) ; } -----------------------------------------------------------------------------1.40 Read work origin offset (range specified). <Main,Alarm> -----------------------------------------------------------------------------[Name] cnc_rdzofsr [Syntax] #include <data.h> #include <fwindow.h> short cnc_rdzofsr( short s_number, short axis, short e_number, short length, struct iodbzo *buf ) ; struct iodbzo { short datano_s ; short type ; short datano_e ; long data[32*M] ; } ; [Arguments] s_number axis e_number length buf /* /* /* /* /* /* Start offset number. */ Axis number. */ End offset number. */ Offset data. */ M is number of work origin */ offset amounts to be read. */ Start offset number ( 0, 1,..,6, 7,..,306 ). Axis number ( =(1,..,amount of controlled axes),or -1 ). End offset number Data block length ( =6+4*(amount of axes to be read)* (number of offset to be read) ). Buffer in which the offset amounts are stored. [Return] EW_OK( 0) EW_LENGTH( 2) EW_NUMBER( 3) EW_ATTRIB( 4) EW_NOOPT( 6) EW_BUSY(-1) Successful. Incorrect data block length "length". Incorrect of offset number "s_number" or "e_number". (Any data other than 0,..,6 or 7,..,306 has been specified.) Incorrect axis number "axis". Any data other than -1 or (1,..,amount of controlled axes) has been specified. There are no required options. (See "Read work origin offset(cnc_rdzofs)" for details.) It was impossible to read a work origin offset amount because a command from another application program to write the work origin offset amount was already being executed. [Description] Reads the work origin offset amount stored in the CNC within the specified range. In the CNC, a work origin offset amount is provided for each controlled axis (the first to 32nd controlled axes). The work origin offset amount can be read either for individual axes separately or for all axes at a time. If there is no controlled axis expansion option, however, it is impossible to read a work origin offset amount for additional axes. Specify one of (1,..,amount of controlled axes) for each axis or -1 for all axes as axis number in "axis". Specify one of following value as start/end offset number in "s_number"/"e_number". number Kind of work origin offset amount ---------------+-------------------------------------------0 External work origin offset amount 1,..,6 Work origin offset amount of G54 through G59 7,..,306 Work origin offset amount of G54.1P1 through G54.1P300 The work origin offset amount is stored in "buf.data" with signed binary format. (The negative value is represented as 2's complement.) The storing order is as follows. Reading for one axis Member Work origin offset -----------------------+-------------------------------buf.data[0] Start number buf.data[1] Start number+1 : : buf.data[M-1] End number Reading for all axes Member Work origin offset -----------------------+-------------------------------buf.data[0] The 1st axis of start number : : buf.data[N-1] The Nth axis of start number : : buf.data[31] The 32nd axis of start number buf.data[32] The 1st axis of (start number+1) : : buf.data[32+(N-1)] The Nth axis of (start number+1) : : buf.data[63] The 32nd axis of (start number+1) : : buf.data[32*(M-1)] The 1st axis of end number : : buf.data[32+M+N-33] The Nth axis of end number : : buf.data[32*M-1] The 32nd axis of end number N is the amount of axis and M is the number of offset to be read. If the maximum controlled-axis number is lower than 32, no data is stored to the members that correspond to axis Nos. "maximum controlled-axis number + 1" to 32. The unit of the work origin offset amount is as follows. IS-B IS-C -------------------------------+---------------+--------------Linear axis (metric input) 0.001 [mm] 0.0001 [mm] Linear axis (inch input) 0.0001 [inch] 0.00001 [inch] Rotation axis 0.001 [deg] 0.0001 [deg] [Example] The following program reads and displays the work origin offset amounts of G54 to G59 for all the axes (up to 32 axes). #include #include #include #include <data.h> <fwindow.h> <stdio.h> <stdlib.h> short example( void ) { struct iodbzo *buf ; short ret, idx1, idx2 ; buf = (struct iodbzo *)malloc( 6+4*32*6 ) ; ret = cnc_rdzofsr( 1, -1, 6, 6+4*32*6, buf ) ; if ( !ret ) { for ( idx1 = 0 ; idx1 < 6 ; idx1++ ) { printf( "G%d", idx1+54 ) ; for ( idx2 = 0 ; idx2 < MAX ; idx2++ ) printf( " %8ld", buf->data[idx1*32+idx2] ) ; putchar( '\n' ) ; } } free( buf ) ; return ( ret ) ; } -----------------------------------------------------------------------------1.41 Write work origin offset (range specified). <Main,Alarm> -----------------------------------------------------------------------------[Name] cnc_wrzofsr [Syntax] #include <data.h> #include <fwindow.h> short cnc_wrzofsr( short length, struct iodbzo *buf ) ; struct iodbzo { short datano_s ; short type ; short datano_e ; long data[32*M] ; } ; [Arguments] length buf /* /* /* /* /* /* Start offset number. */ Axis number. */ End offset number. */ Offset data. */ M is number of work origin */ offset amounts to be written. */ Data block length ( =6+4*(amount of axes to be read)* (number of offset to be written) ). Buffer in which the offset amounts are stored. [Return] EW_OK( 0) EW_LENGTH( 2) EW_NUMBER( 3) EW_ATTRIB( 4) EW_NOOPT( 6) EW_BUSY(-1) Successful. Incorrect data block length "length". Incorrect of offset number "datano_s" or "datano_e". (Any data other than 0,..,6 or 7,..,306 has been specified.) Incorrect axis number "type". Any data other than -1 or (1,..,amount of controlled axes) has been specified. There are no required options. (See "Read work origin offset(cnc_rdzofs)" for details.) An attempt was made to execute this command when other window processing of a low-speed type was in progress. Execute the command after the window processing has ended. [Description] Alters the work origin offset amount stored in the CNC within the specified range. The work origin offset amounts are provided for all controlled axes (the 1st axis,..,the 32nd axis) of the CNC. It is possible to alter one offset amount for each axis or the whole for all axes at the same time. However, in case of no controlled axes expansion option, the work origin offset amounts for the additional axes can't be altered. Specify one of (1,..,amount of controlled axes) for each axis or -1 for all axes as axis number in "buf.type". Specify one of following value as start/end offset number in "buf.datano_s"/"buf.datano_e". datano Kind of work origin offset amount -------+-------------------------------------------0 External work origin offset amount 1,..,6 Work origin offset amount of G54 through G59 7,..,306Work origin offset amount of G54.1P1 through G54.1P300 Store the work origin offset amount in "buf.data" with signed binary format. (The negative value is represented as 2's complement.) The storing order is as follows. Writing for one axis Member Work origin offset -----------------------+-------------------------------buf.data[0] Start number buf.data[1] Start number+1 : : buf.data[M-1] End number Writing for all axes Member Work origin offset -----------------------+-------------------------------buf.data[0] The 1st axis of start number : : buf.data[N-1] The Nth axis of start number : : buf.data[31] The 32nd axis of start number buf.data[32] The 1st axis of (start number+1) : : buf.data[32+(N-1)] The Nth axis of (start number+1) : : buf.data[63] The 32nd axis of (start number+1) : : buf.data[32*(M-1)] The 1st axis of end number : : buf.data[32*M+N-33] The Nth axis of end number : : buf.data[32*M-1] The 32nd axis of end number N is the amount of axis and M is the number of offset to be written. In case that the amount of controlled axes is less than 32, no data are stored in the members corresponding with the axes No. (amount of controlled axes + 1),..,32. The unit of the work origin offset amount is as follows. IS-B IS-C -------------------------------+---------------+--------------Linear axis (metric input) 0.001 [mm] 0.0001 [mm] Linear axis (inch input) 0.0001 [inch] 0.00001 [inch] Rotation axis 0.001 [deg] 0.0001 [deg] [Example] The following program alters the work origin offset amount of G54 through G59 for the specified axis. #include <data.h> #include <fwindow.h> #include <string.h> /* axis is axis index to be altered. */ /* offset is array of new offset value. */ short example( short axis, long *offset ) { struct iodbzo buf ; short ret ; buf.datano_s = 1 ; buf.datano_e = 6 ; buf.type = axis ; memcpy( &buf.data[0], offset, 4*6 ) ; ret = cnc_wrzofsr( 6+4*1*6, &buf ) ; return ( ret ) ; } -----------------------------------------------------------------------------1.42 Read parameter. <Main,Alarm> -----------------------------------------------------------------------------[Name] cnc_rdparam [Syntax] #include <data.h> #include <fwindow.h> short cnc_rdparam( short number, short axis, short length, struct iodbpsd *buf ) ; typedef struct realprm { long prm_val; long dec_val; } REALPRM; /* real parameter */ /* value of variable */ /* number of places of decimals */ struct iodbpsd { short datano; short type; /* parameter number */ /* upper byte:type */ /* lower byte:axis */ union { char short long REALPRM char cdata; /* bit/byte parameter */ idata; /* word parameter */ ldata; /* 2-word parameter */ rdata; /* real parameter */ cdatas[MAX_AXIS]; /*bit/byte parameter with axis*/ short idatas[MAX_AXIS]; /* word parameter with axis */ long ldatas[MAX_AXIS]; /* 2-word parameter with axis */ REALPRM rdatas[MAX_AXIS]; /* real parameter with axis */ } u; } ; MAX_AXIS [Arguments] number axis length buf 32 Parameter number. Axis number ( =(1,..,amount of controlled axes), or -1, 0 ). Data block length ( =4+(byte size of the parameter)* (MAX_AXIS) ) Buffer in which the parameter is stored. [Return] EW_OK( 0) EW_LENGTH( 2) EW_NUMBER( 3) EW_ATTRIB( 4) Successful. Incorrect data block length "length". Incorrect parameter number "number". Incorrect axis number "axis". Any data other than -1, 0 or (1,..,amount of controlled axes) has been specified. [Description] Reads the parameter data stored in the CNC. This function is used for reading the various settings of CNC to execute any processes which are equivalent to CNC's by the application program, etc. The attribute of CNC parameter depends on the type and axis, and it is different for each parameter. Parameter type Meaning Byte size --------------------------+---------------------------------+--------Bit parameter Every bits have each definition. 1 Bit parameter with axis Every bits have each definition. 1 (each axis) Byte parameter 1-byte data is stored. 1 Byte parameter with axis 1-byte data is stored.(each axis) 1 Word parameter 2-byte data is stored. 2 Word parameter with axis 2-byte data is stored.(each axis) 2 2-Word parameter 4-byte data is stored. 4 2-Word parameter with axis 4-byte data is stored.(each axis) 4 Real parameter 4-byte data which indicates value of variable and 4-byte data which indicates number of places of 8 decimals are stored. Real parameter with axis 4-byte data whidh indicates value of variable and 4-byte data which indicates number of places of 8 decimals are stored.(each axis) It is impossible to read any bit parameter bit by bit. 8 bits(i.e. 1 byte) which belong to the same parameter number are read at the same time. Refer "PARAMETER MANUAL" of CNC for details of each parameters. Specify the parameter number in "number" with binary format. Specify one of following values corresponding with each parameter as axis number in "axis". axis Parameter type -----------------------+-----------------------------------0 Ordinary (none axis type) parameter -1 All axes data of axis type parameter 1,..,amount of One specified axis data of controlled axis axis type parameter The parameter data of none axis type parameter or the axis type parameter data which was read for one specified axis is stored in "buf.u.cdata/idata/ldata/rdata". The axis type parameters which were read for all axes are stored in "buf.u.cdatas/idatas/ldatas/rdatas". The data format depends on each parameter. The format of Byte/Word/ 2-Word parameter is generally signed binary. [Example] The following program reads axis names of all controlled axes and displays them. #include #include #include #include <data.h> <fwindow.h> <stdio.h> <stdlib.h> void example( void ) { struct iodbpsd buf ; short ret, idx ; ret = cnc_rdparam( 1020, -1, 4+10, &buf ) ; /* standard 10axes */ for ( idx = 0 ; idx < axno ; idx++ ) { printf( "#%d", idx+1 ) ; if ( buf.u.cdatas[idx] == 0 ) printf( "\033[7m%c\033[27m\n", idx+'1' ) ; else printf( "%c\n", buf.u.cdatas[idx] ) ; } } -----------------------------------------------------------------------------1.43 Write parameter. <Main,Alarm> -----------------------------------------------------------------------------[Name] cnc_wrparam [Syntax] #include <data.h> #include <fwindow.h> short cnc_wrparam( short length, struct iodbpsd *buf ) ; typedef struct realprm { long prm_val; long dec_val; } REALPRM; /* real parameter */ /* value of variable */ /* number of places of decimals */ struct iodbpsd { short datano; short type; /* parameter number */ /* upper byte:type */ /* lower byte:axis */ union { char short long REALPRM char cdata; /* bit/byte parameter */ idata; /* word parameter */ ldata; /* 2-word parameter */ rdata; /* real parameter */ cdatas[MAX_AXIS]; /*bit/byte parameter with axis*/ short idatas[MAX_AXIS]; /* word parameter with axis */ long ldatas[MAX_AXIS]; /* 2-word parameter with axis */ REALPRM rdatas[MAX_AXIS]; /* real parameter with axis */ } u; } ; MAX_AXIS [Arguments] length buf 32 Data block length ( =4+(byte size of the parameter)* (MAX_AXIS) ) Buffer in which the parameter is stored. [Return] EW_OK( 0) EW_LENGTH( 2) EW_NUMBER( 3) EW_ATTRIB( 4) EW_PROT( 7 ) Successful. Incorrect data block length "length". Incorrect parameter number "datano". Incorrect axis number "type". Any data other than -1, 0 or (1,..,amount of controlled axes) has been specified. Write operation is prohibited. [Description] Alters the parameter data stored in the CNC. This function is used for changing the various settings of CNC by the application program, etc. Even if "PARAMETER WRITE" is "DISABLE" in setting data, it is possible to alter CNC's parameter data. The attribute of CNC parameter depends on the type and axis, and it is different for each parameter. It is as follows, and can be got by cnc_rdparainfo() function. Parameter type Meaning Byte size --------------------------+---------------------------------+--------Bit parameter Every bits have each definition. 1 Bit parameter with axis Every bits have each definition. 1 (each axis) Byte parameter 1-byte data is stored. 1 Byte parameter with axis 1-byte data is stored.(each axis) 1 Word parameter 2-byte data is stored. 2 Word parameter with axis 2-byte data is stored.(each axis) 2 2-Word parameter 4-byte data is stored. 4 2-Word parameter with axis 4-byte data is stored.(each axis) 4 Real parameter 4-byte data which indicates value of variable and 4-byte data which indicates number of places of 8 decimals are stored. Real parameter with axis 4-byte data whidh indicates value of variable and 4-byte data which indicates number of places of 8 decimals are stored.(each axis) It is impossible to write any bit parameter bit by bit. 8 bits(i.e. 1 byte) which belong to the same parameter number are written at the same time. PW000 alarm :"PLEASE TURN OFF POWER" may be issued when some specific parameters are written. Refer "PARAMETER MANUAL" of CNC for details of each parameters. Specify the parameter number in "buf.datano" with binary format. Specify one of following values corresponding with each parameter as axis number in "buf.type". buf.type Parameter type -----------------------+-----------------------------------0 Ordinary (none axis type) parameter -1 All axes data of axis type parameter 1,..,amount of One specified axis data of controlled axis axis type parameter Store the parameter data of none axis type parameter or the axis type parameter data which will be written for one specified axis in "buf.u.cdata/idata/ldata/rdata". Store the axis type parameters which will be written for all axes in "buf.u.cdatas/idatas/ldatas/rdatas". The data format depends on each parameter. The format of Byte/Word/ 2-Word parameter is generally signed binary. [Example] The following program rewrites the stroke limit setting for a specified axis. #include <data.h> #include <fwindow.h> /* axis is axis index. */ /* plus and minus are plus and minus position of stroke limit. */ short example( short axis, logn plus, long minus ) { struct iodbpsd buf ; short ret ; buf.datano = 1320 ; buf.type = axis ; buf.u.ldata = plus ; ret = cnc_wrparam( 4+4*1, &buf ) ; if ( ret ) return ( ret ) ; buf.datano = 1321 ; buf.type = axis ; buf.u.ldata = minus ; ret = cnc_wrparam( 4+4*1, &buf ) ; return ( ret ) ; } -----------------------------------------------------------------------------1.44 Read parameters (range specified). <Main,Alarm> -----------------------------------------------------------------------------[Name] cnc_rdparar [Syntax] #include <data.h> #include <fwindow.h> short cnc_rdparar( short s_number, short axis, short e_number, short length, struct iodbpsdr *buf ) ; typedef struct realprm { long prm_val; long dec_val; } REALPRM; /* real parameter */ /* value of variable */ /* number of places of decimals */ struct iodbpsdr { short datano; short type; /* parameter number */ /* upper byte:type */ /* lower byte:axis */ union { char short long REALPRM char cdata; /* bit/byte parameter */ idata; /* word parameter */ ldata; /* 2-word parameter */ rdata; /* real parameter */ cdatas[MAX_AXIS]; /*bit/byte parameter with axis*/ short idatas[MAX_AXIS]; /* word parameter with axis */ long ldatas[MAX_AXIS]; /* 2-word parameter with axis */ REALPRM rdatas[MAX_AXIS]; /* real parameter with axis */ } u; } ; MAX_AXIS [Arguments] s_number axis e_number length buf 32 Start parameter number. Axis number ( =(1,..,amount of controlled axes), or -1, 0 ). End parameter number. Data block length ( = Sum of [4+(byte size of the parameter)*(MAX_AXIS)] ) Buffer in which the parameters are stored. [Return] EW_OK( 0) EW_LENGTH( 2) EW_NUMBER( 3) EW_ATTRIB( 4) Successful. Incorrect data block length "length". Incorrect parameter number "s_number" or "e_number". Incorrect axis number "axis". Any data other than -1, 0 or (1,..,amount of controlled axes) has been specified. [Description] Reads the parameter data stored in the CNC within the specified range. The attribute of CNC parameter depends on the type and axis, and it is different for each parameter. Parameter type Meaning Byte size --------------------------+---------------------------------+--------Bit parameter Every bits have each definition. 1 Bit parameter with axis Every bits have each definition. 1 (each axis) Byte parameter 1-byte data is stored. 1 Byte parameter with axis 1-byte data is stored.(each axis) 1 Word parameter 2-byte data is stored. 2 Word parameter with axis 2-byte data is stored.(each axis) 2 2-Word parameter 4-byte data is stored. 4 2-Word parameter with axis 4-byte data is stored.(each axis) 4 Real parameter 4-byte data which indicates value of variable and 4-byte data which indicates number of places of 8 decimals are stored. Real parameter with axis 4-byte data whidh indicates value of variable and 4-byte data which indicates number of places of 8 decimals are stored.(each axis) It is impossible to read any bit parameter bit by bit. 8 bits(i.e. 1 byte) which belong to the same parameter number are read at the same time. Refer "PARAMETER MANUAL" of CNC for details of each parameters. Specify the start parameter number in "s_number" and the end one in "e_number" with binary format. The new parameter will may be added according to updating CNC software, addition of the new functions, etc. If the new parameters will be added within reading range, ERROR 2 ( Incorrect data block length) will be returned or the application program will not work correctly. To avoid these mistakes, specify the continuous numbers of existing parameters as the reading range. Specify one of following values corresponding with each parameter as axis number in "axis". axis Parameter type -----------------------+-----------------------------------0 Ordinary (none axis type) parameter -1 All axes data of axis type parameter 1,..,amount of One specified axis data of controlled axis axis type parameter Any values are allowed for "axis" to read none axis type parameters. In case that any axis type parameter exists in the specified range, error will be returned by specifying "axis=0". The read parameters are stored in "buf" in following order. +-----------------------+ | Parameter number 1 | |-----------------------| | Type 1 | |-----------------------| | Data 1 | | | |-----------------------| : |-----------------------| | Parameter number n | |-----------------------| | Type n | |-----------------------| | Data n | | | <-- buf[0].datano <-- buf[0].type <-- buf[0].u.cdata/idata/ldata/rdata cdatas/idatas/ldatas/rdatas <-- buf[n].datano <-- buf[n].type <-- buf[n].u.cdata/idata/ldata/rdata cdatas/idatas/ldatas/rdatas +-----------------------+ "Type" includes both parameter type in the upper byte and axis type in the lower byte. Type (upper byte) Parameter type -----------------------+---------------0 Bit 1 Byte 2 Word 3 2-Word Axis type (lower byte) Parameter type -----------------------+--------------------------------0 Ordinary (none axis type) parameter -1 All axes data of axis type parameter 1,..,amount of One specified axis data of controlled axis axis type parameter The parameter data is stored in "Data". The parameter data of none axis type parameter or the axis type parameter data which was read for one specified axis is stored in "buf[i].u.cdata/idata/ldata/rdata". The axis type parameters which were read for all axes are stored in "buf[i].u.cdatas/idatas/ldatas/ rdatas" in axis number order. The array size of each members of "iodbpsdr.u.cdatas/idatas/ldatas/rdatas" which is used for reading all axes's data is always MAX_AXIS regardless of the amount of controlled axes. In case that the amount of controlled axes is less than MAX_AXIS, no data are stored in the members corresponding with the axes No. (amount of controlled axes + 1),..,MAX_AXIS. Each buf[i] is suffixed with dummy data so that the total data size is a multiple of 4-bytes. The data format depends on each parameter. The format of Byte/Word/2-Word parameter is generally signed binary. [Example] The following program reads parameters in a specified range for a specified axis and displays them on the screen. #include #include #include #include <data.h> <fwindow.h> <stdio.h> <stdlib.h> /* start/end are start/end number to be read, axis is axis number. */ short example( short start, short end, short axis ) { struct odbsys info ; struct iodbpsdr *buf, *ptr ; short ret, idx1, idx2, axno, inc ; cnc_sysinfo( &info ) ; axno = atoi( info.axes ) ; buf = (struct iodbpsdr *)calloc( 1, 1000 ) ; ret = cnc_rdparar( start, axis, end, 1000, buf ) ; ptr = buf ; if ( !ret ) { for ( idx1 = start ; idx1 <= end ; idx1++ ) { if ( ( idx1 != 0 ) && ( ptr->datano == 0 ) ) break ; printf( "No.%05d ", ptr->datano ) ; switch ( ptr->type >> 8 ) { case 0: printf( "BIT " ) ; break ; case 1: printf( "BYTE" ) ; break ; case 2: printf( "WORD" ) ; break ; case 3: printf( "2WRD" ) ; break ; } switch ( ptr->type & 0xff ) { case 0xff : for ( idx2 = 0 ; idx2 < axno ; idx2++ ) { printf( " #%d:", idx2+1 ) ; switch ( ptr->type >> 8 ) { case 0: printf( "0x%02X", (unsigned char)(ptr->u.cdatas[idx2]) ) ; inc = 1 ; break ; case 1: printf( "%d", ptr->u.cdatas[idx2] ) ; inc = 1 ; break ; case 2: printf( "%d", ptr->u.idatas[idx2] ) ; inc = 2 ; break ; case 3: printf( "%ld", ptr->u.ldatas[idx2] ) ; inc = 4 ; break ; } } putchar( '\n' ) ; ptr = (struct iodbpsdr *)(((char *)ptr)+4+8*inc) ; break ; /* to be continued on the next page... */ default : printf( " #%d:", ptr->type & 0xff ) ; case 0 : switch ( ptr->type >> 8 ) { case 0: printf( " 0x%02X\n", (unsigned char)(ptr->u.cdata) ) ; inc = 1+1 ; break ; case 1: printf( " %d\n", ptr->u.cdata ) ; inc = 1+1 ; break ; case 2: printf( " %d\n", ptr->u.idata ) ; inc = 2 ; break ; case 3: printf( " %ld\n", ptr->u.ldata ) ; inc = 4 ; break ; } ptr = (struct iodbpsdr *)(((char *)ptr)+4+inc) ; break ; } } } else printf( "ERROR!(%d)\n", ret ) ; free( buf ) ; return ( ret ) ; } -----------------------------------------------------------------------------1.45 Write parameters (multiple output). <Main,Alarm> -----------------------------------------------------------------------------[Name] cnc_wrparas [Syntax] #include <data.h> #include <fwindow.h> short cnc_wrparas( short length, struct iodbpsdr *buf ) ; typedef struct realprm { long prm_val; long dec_val; } REALPRM; /* real parameter */ /* value of variable */ /* number of places of decimals */ struct iodbpsdr { short datano; short type; /* parameter number */ /* upper byte:type */ /* lower byte:axis */ union { char short long REALPRM char cdata; /* bit/byte parameter */ idata; /* word parameter */ ldata; /* 2-word parameter */ rdata; /* real parameter */ cdatas[MAX_AXIS]; /*bit/byte parameter with axis*/ short idatas[MAX_AXIS]; /* word parameter with axis */ long ldatas[MAX_AXIS]; /* 2-word parameter with axis */ REALPRM rdatas[MAX_AXIS]; /* real parameter with axis */ } u; } ; MAX_AXIS [Arguments] length buf 32 Data block length ( = Sum of [4+(byte size of the parameter)*(MAX_AXIS)] ) Buffer in which the parameters are stored. [Return] EW_OK( 0) EW_LENGTH( 2) EW_NUMBER( 3) EW_ATTRIB( 4) EW_PROT( 7 ) Successful. Incorrect data block length "length". Incorrect parameter number "buf.datano". Incorrect axis number "buf.type". Any data other than -1, 0 or (1,..,amount of controlled axes) has been specified. Write operation is prohibited. [Description] Alters the multiple parameter data stored in the CNC. Even if "PARAMETER WRITE" is "DISABLE" in setting data, it is possible to alter CNC's parameter data. The attribute of CNC parameter depends on the type and axis, and it is different for each parameter. It is as follows, and can be got by cnc_rdparainfo() function. Parameter type Meaning Byte size --------------------------+---------------------------------+--------Bit parameter Every bits have each definition. 1 Bit parameter with axis Every bits have each definition. 1 (each axis) Byte parameter 1-byte data is stored. 1 Byte parameter with axis 1-byte data is stored.(each axis) 1 Word parameter 2-byte data is stored. 2 Word parameter with axis 2-byte data is stored.(each axis) 2 2-Word parameter 4-byte data is stored. 4 2-Word parameter with axis 4-byte data is stored.(each axis) 4 Real parameter 4-byte data which indicates value of variable and 4-byte data which indicates number of places of 8 decimals are stored. Real parameter with axis 4-byte data whidh indicates value of variable and 4-byte data which indicates number of places of 8 decimals are stored.(each axis) It is impossible to write any bit parameter bit by bit. 8 bits(i.e. 1 byte) which belong to the same parameter number are written at the same time. PW000 alarm :"PLEASE TURN OFF POWER" may be issued when some specific parameters are written. Refer "PARAMETER MANUAL" of CNC for details of each parameters. Store the parameters to be written in "buf" in following order. The data structure is same as "Read parameters(range specified) (cnc_rdparar)". +-----------------------+ | Parameter number 1 | |-----------------------| | Type 1 | |-----------------------| | Data 1 | | | |-----------------------| : |-----------------------| | Parameter number n | |-----------------------| | Type n | |-----------------------| | Data n | | | <-- buf[0].datano <-- buf[0].type <-- buf[0].u.cdata/idata/ldata/rdata cdatas/idatas/ldatas/rdatas <-- buf[n].datano <-- buf[n].type <-- buf[n].u.cdata/idata/ldata/rdata cdatas/idatas/ldatas/rdatas +-----------------------+ Store the parameter number in "Parameter number i"(buf[i].datano) with binary format. Store the parameter type in the upper byte of "Data i"(buf[i].type) and the axis type in the lower byte. Type (upper byte) Parameter type -----------------------+---------------0 Bit 1 Byte 2 Word 3 2-Word 4 real Axis type (lower byte) Parameter type -----------------------+-----------------------------------0 Ordinary (none axis type) parameter -1 All axes data of axis type parameter 1,..,amount of One specified axis data of controlled axis axis type parameter Store the parameter data to be written in "Data i". Store the parameter data of none axis type parameter or the axis type parameter data which will be written for one specified axis in "buf[i].u.cdata/idata/ldata/rdata". Store the axis type parameters which will be written for all axes in "buf[i].u.cdatas/idatas/ldatas/ rdatas" in axis number order. The array size of each members of "iodbpsdr.u.cdatas/idatas/ldatas/ rdatas" which is used for writing all axes's data is always MAX_AXIS regardless of the amount of controlled axes. In case that the amount of controlled axes is less than MAX_AXIS, any data need not to be stored in the members corresponding with the axes No. (amount of controlled axes + 1),..,MAX_AXIS. The data format depends on each parameter. The format of Byte/Word/2-Word/Real parameter is generally signed binary. Each buf[i] is suffixed with dummy data so that the total data size is a multiple of 4-bytes. [Example] The following program specifies that M code Nos. 6080 to 6089 be subjected to a macro call. #include <data.h> #include <fwindow.h> #include <stdlib.h> /* mcode is 10 M-code values to be set. */ short example( short *mcode ) { struct iodbpsdr *buf, *ptr ; short ret, idx ; buf = (struct iodbpsdr *)calloc( 1, 1000 ) ; ptr = buf ; for ( idx = 0 ; idx < 10 ; idx++ ) { ptr->datano = 6080 + idx ; ptr->type = 0 ; ptr->u.cdata = mcode[idx] ; ptr = (struct iodbpsdr *)(((char *)ptr)+6) ; } ret = cnc_wrparar( 6*10, buf ) ; free( buf ) ; return ( ret ) ; } -----------------------------------------------------------------------------1.46 Read setting parameter. <Main,Alarm> -----------------------------------------------------------------------------[Name] cnc_rdset [Syntax] #include <data.h> #include <fwindow.h> short cnc_rdset( short number, short axis, short length, struct iodbpsd *buf ) ; typedef struct realprm { long prm_val; long dec_val; } REALPRM; /* real setting data */ /* value of variable */ /* number of places of decimals */ struct iodbpsd { short datano; short type; /* setting data number */ /* upper byte:type */ /* lower byte:axis */ union { char short long REALPRM char cdata; /* bit/byte setting data */ idata; /* word setting data */ ldata; /* 2-word setting data */ rdata; /* real setting data */ cdatas[MAX_AXIS]; /*bit/byte set. data with axis*/ short idatas[MAX_AXIS]; /* word set. data with axis */ long ldatas[MAX_AXIS]; /* 2-word set. data with axis */ REALPRM rdatas[MAX_AXIS]; /* real set. data with axis */ } u; }; MAX_AXIS [Arguments] number axis length buf 32 Setting parameter number. Axis number ( =(1,..,amount of controlled axes), or -1, 0 ). Data block length ( =4+(byte size of the setting parameter)*(MAX_AXIS) ) Buffer in which the setting parameter is stored. [Return] EW_OK( 0) EW_LENGTH( 2) EW_NUMBER( 3) EW_ATTRIB( 4) Successful. Incorrect data block length "length". Incorrect setting parameter number "number". Incorrect axis number "axis". Any data other than -1, 0 or (1,..,amount of controlled axes) has been specified. [Description] Reads the setting parameter stored in the CNC. This function is used for getting the information of I/O device from the setting parameter to input/output via Reader/Puncher interface of CNC by the application program, etc. The attribute of setting data depends on the type and axis, and it is different for each setting data. Setting data type Meaning Byte size ---------------------------+---------------------------------+--------Bit setting data Every bits have each definition. 1 Bit setting data with axis Every bits have each definition. 1 (each axis) Byte setting data 1-byte data is stored. 1 Byte setting data with axis 1-byte data is stored.(each axis) 1 Word setting data 2-byte data is stored. 2 Word setting data with axis 2-byte data is stored.(each axis) 2 2-Word setting data 4-byte data is stored. 4 2-Word setting data with ax.4-byte data is stored.(each axis) 4 Real setting data 4-byte data which indicates value of variable and 4-byte data which indicates number of places of 8 decimals are stored. Real setting data with ax. 4-byte data whidh indicates value of variable and 4-byte data which indicates number of places of 8 decimals are stored.(each axis) It is impossible to read any bit setting data bit by bit. 8 bits(i.e. 1 byte) which belong to the same setting data number are read at the same time. Refer "PARAMETER MANUAL" of CNC for details of each setting parameter. Specify the setting parameter number in "number" with binary format. Specify one of following values corresponding with each setting parameter as axis number in "axis". axis Setting parameter type -----------------------+-----------------------------------0 Ordinary (none axis type) parameter -1 All axes data of axis type parameter 1,..,amount of One specified axis data of controlled axis axis type parameter The setting parameter of none axis type setting parameter or the axis type setting parameter which was read for one specified axis is stored in "buf.u.cdata/idata/ldata/rdata". The axis type setting parameter which were read for all axes are stored in "buf.u.cdatas/idatas/ldatas/ rdatas". The data format depends on each setting parameter. The format of Byte/Word/2-Word/Real setting parameter is generally signed binary. [Example] The following program changes the input unit to inch. #include <data.h> #include <fwindow.h> void example( void ) { struct iodbpsd buf ; cnc_rdset( 0, 0, 4+1*1, &buf ) ; *buf.u.cdata |= 0x04 ; cnc_wrset( 4+1*1, &buf ) ; } -----------------------------------------------------------------------------1.47 Write setting parameter. <Main,Alarm> -----------------------------------------------------------------------------[Name] cnc_wrset [Syntax] #include <data.h> #include <fwindow.h> short cnc_wrset( short length, struct iodbpsd *buf ) ; typedef struct realprm { long prm_val; long dec_val; } REALPRM; /* real setting data */ /* value of variable */ /* number of places of decimals */ struct iodbpsd { short datano; short type; /* setting data number */ /* upper byte:type */ /* lower byte:axis */ union { char short long REALPRM char cdata; /* bit/byte setting data */ idata; /* word setting data */ ldata; /* 2-word setting data */ rdata; /* real setting data */ cdatas[MAX_AXIS]; /*bit/byte set. data with axis*/ short idatas[MAX_AXIS]; /* word set. data with axis */ long ldatas[MAX_AXIS]; /* 2-word set. data with axis */ REALPRM rdatas[MAX_AXIS]; /* real set. data with axis */ } u; } ; MAX_AXIS [Arguments] length buf 32 Data block length ( =4+(byte size of the setting parameter)*(MAX_AXIS) ) Buffer in which the setting parameter is stored. [Return] EW_OK( 0) EW_LENGTH( 2) EW_NUMBER( 3) EW_ATTRIB( 4) Successful. Incorrect data block length "length". Incorrect setting parameter number "datano". Incorrect axis number "type". Any data other than -1, 0 or (1,..,amount of controlled axes) has been specified. [Description] Alters the setting parameter stored in the CNC. Even if "PARAMETER WRITE" is "DISABLE" in setting parameter, it is possible to alter CNC's setting parameter. This function is used for changing the setting of I/O device by the application program, etc. The attribute of setting data depends on the type and axis, and it is different for each setting data. It is as follows, and can be got by cnc_rdsetinfo() function. Setting data type Meaning Byte size ---------------------------+---------------------------------+--------Bit setting data Every bits have each definition. 1 Bit setting data with axis Every bits have each definition. 1 (each axis) Byte setting data 1-byte data is stored. 1 Byte setting data with axis 1-byte data is stored.(each axis) 1 Word setting data 2-byte data is stored. 2 Word setting data with axis 2-byte data is stored.(each axis) 2 2-Word setting data 4-byte data is stored. 4 2-Word setting data with ax.4-byte data is stored.(each axis) 4 Real setting data 4-byte data which indicates value of variable and 4-byte data which indicates number of places of 8 decimals are stored. Real setting data with ax. 4-byte data whidh indicates value of variable and 4-byte data which indicates number of places of 8 decimals are stored.(each axis) It is impossible to write any bit setting data bit by bit. 8 bits(i.e. 1 byte) which belong to the same setting data number are written at the same time. Refer "PARAMETER MANUAL" of CNC for details of each setting parameters. Specify the setting parameter number in "buf.datano" with binary format. Specify one of following values corresponding with each setting parameter as axis number in "buf.type". buf.type Setting parameter type -----------------------+-----------------------------------0 Ordinary (none axis type) parameter -1 All axes data of axis type parameter 1,..,amount of One specified axis data of controlled axis axis type parameter Store the setting parameter data of none axis type setting parameter or the axis type setting parameter data which will be written for one specified axis in "buf.u.cdata/idata/ldata/rdata". Store the axis type setting parameters which will be written for all axes in "buf.u.cdatas/idatas/ldatas/rdatas". The data format depends on each setting parameter. The format of Byte/Word/2-Word/Real setting parameter is generally signed binary. [Example] See [Example] in "Read setting parameter (cnc_rdset)." -----------------------------------------------------------------------------1.48 Read setting parameters (range specified). <Main,Alarm> -----------------------------------------------------------------------------[Name] cnc_rdsetr [Syntax] #include <data.h> #include <fwindow.h> short cnc_rdsetr( short s_number, short axis, short e_number, short length, struct iodbpsdr *buf ) ; typedef struct realprm { long prm_val; long dec_val; } REALPRM; struct /* real setting data */ /* value of variable */ /* number of places of decimals */ iodbpsdr { short datano; short type; /* setting data number */ /* upper byte:type */ /* lower byte:axis */ union { char short long REALPRM char cdata; /* bit/byte setting data */ idata; /* word setting data */ ldata; /* 2-word setting data */ rdata; /* real setting data */ cdatas[MAX_AXIS]; /*bit/byte set. data with axis*/ short idatas[MAX_AXIS]; /* word set. data with axis */ long ldatas[MAX_AXIS]; /* 2-word set. data with axis */ REALPRM rdatas[MAX_AXIS]; /* real set. data with axis */ } u; } ; MAX_AXIS [Arguments] s_number axis e_number length buf 32 Start setting parameter number. Axis number ( =(1,..,amount of controlled axes), or -1, 0 ). End setting parameter number. Data block length ( = Sum of [4+(byte size of the setting parameter)*(MAX_AXIS)] ) Buffer in which the setting parameters are stored. [Return] EW_OK( 0) EW_LENGTH( 2) EW_NUMBER( 3) EW_ATTRIB( 4) Successful. Incorrect data block length "length". Incorrect setting parameter number "s_number" or "e_number". Incorrect axis number "axis". Any data other than -1, 0 or (1,..,amount of controlled axes) has been specified. [Description] Reads the setting parameter data stored in the CNC within the specified range. The attribute of setting data depends on the type and axis, and it is different for each setting data. Setting data type Meaning Byte size ---------------------------+---------------------------------+--------Bit setting data Every bits have each definition. 1 Bit setting data with axis Every bits have each definition. 1 (each axis) Byte setting data 1-byte data is stored. 1 Byte setting data with axis 1-byte data is stored.(each axis) 1 Word setting data 2-byte data is stored. 2 Word setting data with axis 2-byte data is stored.(each axis) 2 2-Word setting data 4-byte data is stored. 4 2-Word setting data with ax.4-byte data is stored.(each axis) 4 Real setting data 4-byte data which indicates value of variable and 4-byte data which indicates number of places of 8 decimals are stored. Real setting data with ax. 4-byte data whidh indicates value of variable and 4-byte data which indicates number of places of 8 decimals are stored.(each axis) It is impossible to read any bit setting data bit by bit. 8 bits(i.e. 1 byte) which belong to the same setting data number are read at the same time. Refer "PARAMETER MANUAL" of CNC for details of each setting parameters. Specify the start setting parameter number in "s_number" and the end one in "e_number" with binary format. The new setting parameter will may be added according to updating CNC software, addition of the new functions, etc. If the new setting parameters will be added within reading range, ERROR 2 (Incorrect data block length) will be returned or the application program will not work correctly. To avoid these mistakes, specify the continuous numbers of existing setting parameters as the reading range. Specify one of following values corresponding with each setting parameter as axis number in "axis". axis Setting parameter type -----------------------+-----------------------------------0 Ordinary (none axis type) parameter -1 All axes data of axis type parameter 1,..,amount of One specified axis data of controlled axis axis type parameter Any values are allowed for "axis" to read none axis type setting parameters. In case that any axis type setting parameter exists in the specified range, error will be returned by specifying "axis=0". The read setting parameters are stored in "buf" in following order. +-----------------------+ |Setting param. Number 1| |-----------------------| | Type 1 | |-----------------------| | Data 1 | | | |-----------------------| : |-----------------------| |Setting param. Number n| |-----------------------| | Type n | |-----------------------| | Data n | | | +-----------------------+ <-- buf[0].datano <-- buf[0].type <-- buf[0].u.cdata/idata/ldata/rdata cdatas/idatas/ldatas/rdatas <-- buf[n].datano <-- buf[n].type <-- buf[n].u.cdata/idata/ldata/rdata cdatas/idatas/ldatas/rdatas "Type" includes both parameter type in the upper byte and axis type in the lower byte. Type (upper byte) Parameter type -----------------------+---------------0 Bit 1 Byte 2 Word 3 2-Word 3 Real Axis type (lower byte) Parameter type -----------------------+-----------------------------------0 Ordinary (none axis type) parameter -1 All axes data of axis type parameter 1,..,amount of One specified axis data of controlled axis axis type parameter The setting parameter data is stored in "Data". The setting parameter data of none axis type setting parameter or the axis type setting parameter data which was read for one specified axis is stored in "buf[i].u.cdata/idata/ldata/rdata". The axis type setting parameters which were read for all axes are stored in "buf[i].u.cdatas/idatas/ldatas/rdatas" in axis number order. The array size of each members of "iodbpsdr.u.cdatas/idatas/ldatas/ rdatas" which is used for reading all axes's data is always MAX_AXIS regardless of the amount of controlled axes. In case that the amount of controlled axes is less than MAX_AXIS, no data are stored in the members corresponding with the axes No. (amount of controlled axes + 1),..,MAX_AXIS. Each buf[i] is suffixed with dummy data so that the total data size is a multiple of 4-bytes. The data format depends on each setting parameter. The format of Byte/Word/2-Word/Real setting parameter is generally signed binary. [Example] This function can be used in the same manner as described in "Read parameters (range specified) (cnc_rdparar)." See [Example] in this section. -----------------------------------------------------------------------------1.49 Write setting parameters (multiple output). <Main,Alarm> -----------------------------------------------------------------------------[Name] cnc_wrsets [Syntax] #include <data.h> #include <fwindow.h> short cnc_wrsets( short length, struct iodbpsdr *buf ) ; typedef struct realprm { long prm_val; long dec_val; } REALPRM; struct /* real setting data */ /* value of variable */ /* number of places of decimals */ iodbpsdr { short datano; short type; /* setting data number */ /* upper byte:type */ /* lower byte:axis */ union { char short long REALPRM char cdata; /* bit/byte setting data */ idata; /* word setting data */ ldata; /* 2-word setting data */ rdata; /* real setting data */ cdatas[MAX_AXIS]; /*bit/byte set. data with axis*/ short idatas[MAX_AXIS]; /* word set. data with axis */ long ldatas[MAX_AXIS]; /* 2-word set. data with axis */ REALPRM rdatas[MAX_AXIS]; /* real set. data with axis */ } u; } ; MAX_AXIS [Arguments] length buf 32 Data block length ( = Sum of [4+(byte size of the setting parameter)*(MAX_AXIS)] ) Buffer in which the setting parameters are stored. [Return] EW_OK( 0) EW_LENGTH( 2) EW_NUMBER( 3) EW_ATTRIB( 4) Successful. Incorrect data block length "length". Incorrect setting parameter number "buf.datano". Incorrect axis number "buf.type". Any data other than -1, 0 or (1,..,amount of controlled axes) has been specified. [Description] Alters the multiple setting parameter data stored in the CNC. Even if "PARAMETER WRITE" is "DISABLE" in setting data, it is possible to alter CNC's setting parameter data. The attribute of setting data depends on the type and axis, and it is different for each setting data. It is as follows, and can be got by cnc_rdsetinfo() function. Setting data type Meaning Byte size ---------------------------+---------------------------------+--------Bit setting data Every bits have each definition. 1 Bit setting data with axis Every bits have each definition. 1 (each axis) Byte setting data 1-byte data is stored. 1 Byte setting data with axis 1-byte data is stored.(each axis) 1 Word setting data 2-byte data is stored. 2 Word setting data with axis 2-byte data is stored.(each axis) 2 2-Word setting data 4-byte data is stored. 4 2-Word setting data with ax.4-byte data is stored.(each axis) 4 Real setting data 4-byte data which indicates value of variable and 4-byte data which indicates number of places of 8 decimals are stored. Real setting data with ax. 4-byte data whidh indicates value of variable and 4-byte data which indicates number of places of 8 decimals are stored.(each axis) It is impossible to write any bit setting data bit by bit. 8 bits(i.e. 1 byte) which belong to the same setting data number are written at the same time. Refer "PARAMETER MANUAL" of CNC for details of each setting parameters. Store the setting parameters to be written in "buf" in following order. The data structure is same as "Read setting parameters (range specified) (cnc_rdsetr)". +-----------------------+ |Setting param. Number 1| |-----------------------| | Type 1 | |-----------------------| | Data 1 | | | |-----------------------| : |-----------------------| |Setting param. Number n| |-----------------------| | Type n | |-----------------------| | Data n | | | +-----------------------+ <-- buf[0].datano <-- buf[0].type <-- buf[0].u.cdata/idata/ldata/rdata cdatas/idatas/ldatas/rdatas <-- buf[n].datano <-- buf[n].type <-- buf[n].u.cdata/idata/ldata/rdata cdatas/idatas/ldatas/rdatas Store the setting parameter number in "Setting param. Number i" (buf[i].datano) with binary format. Store the setting parameter type in the upper byte of "Data i" (buf[i].type) and the axis type in the lower byte. Type (upper byte) Parameter type -----------------------+---------------0 Bit 1 Byte 2 Word 3 2-Word 4 Real Axis type (lower byte) Parameter type -----------------------+-----------------------------------0 Ordinary (none axis type) parameter -1 All axes data of axis type parameter 1,..,amount of One specified axis data of controlled axis axis type parameter Store the setting parameter data to be written in "Data i". Store the setting parameter data of none axis type setting parameter or the axis type setting parameter data which will be written for one specified axis in "buf[i].u.cdata/idata/ldata/rdata". Store the axis type setting parameters which will be written for all axes in "buf[i].u.cdatas/idatas/ldatas/rdaats" in axis number order. The array size of each members of "iodbpsdr.u.cdatas/idatas/ldatas/ rdatas" which is used for writing all axes's data is always MAX_AXIS regardless of the amount of controlled axes. In case that the amount of controlled axes is less than MAX_AXIS, any data need not to be stored in the members corresponding with the axes No. (amount of controlled axes + 1),..,MAX_AXIS. The data format depends on each setting parameter. The format of Byte/Word/2-Word/Real setting parameter is generally signed binary. Each buf[i] is suffixed with dummy data so that the total data size is a multiple of 4-bytes. [Example] This function can be used in the same manner as described in "Write parameters (multiple output) (cnc_wrparas)." See [Example] in this section. -----------------------------------------------------------------------------1.50 Read pitch error compensation data (range specified). <Main,Alarm> -----------------------------------------------------------------------------[Name] cnc_rdpitchr [Syntax] #include <data.h> #include <fwindow.h> short cnc_rdpitchr( short s_number, short e_number, short length, struct iodbpi *buf ) ; struct iodbpi { short datano_s ; short short dummy ; datano_e ; char data[N] ; } ; [Arguments] s_number e_number length buf /* /* /* /* /* /* /* /* Start pitch error compensation */ data number. */ Not used. */ End pitch error compensation */ data number. */ Pitch error compensation data. */ N is the amount of compensation */ data to be read. */ Start pitch error compensation number. End pitch error compensation number. Data block length ( =6+(number of compensation data to be read) ) Buffer in which the pitch error compensation data are stored. [Return] EW_OK( 0) EW_LENGTH( 2) EW_NUMBER( 3) Successful. Incorrect data block length "length". Incorrect pitch error compensation number "s_number" or "e_number". [Description] Reads the pitch error compensation data stored in the CNC within the specified range. Specify the start pitch error compensation data number in "s_number" and the end one in "e_number" with binary format. The pitch error compensation data are stored in "buf.data" with signed binary format. (The negative value is represented as 2's complement.) [Example] The following program reads the pitch error compensation data within the specified number range and displays them. #include #include #include #include <data.h> <fwindow.h> <stdio.h> <stdlib.h> /* start/end are start/end number to be read. */ short example( short start, short end ) { struct iodbpi *buf ; short ret, idx ; buf = (struct iodbpi *)malloc( 1024 ) ; ret = cnc_rdpitchr( start, end, 6+(end-start+1), buf ) ; if ( !ret ) for ( idx = 0 ; idx < end-start+1 ; idx++ ) printf( "#%04d %+d\n", idx+start, buf->data[idx] ) ; free( buf ) ; return ( ret ) ; } -----------------------------------------------------------------------------1.51 Write pitch error compensation data (range specified). <Main,Alarm> -----------------------------------------------------------------------------[Name] cnc_wrpitchr [Syntax] #include <data.h> #include <fwindow.h> short cnc_wrpitchr( short length, struct iodbpi *buf ) ; struct iodbpi { short datano_s ; short short dummy ; datano_e ; char data[N] ; } ; [Arguments] length buf /* /* /* /* /* /* /* /* Start pitch error compensation */ number. */ Not used. */ End pitch error compensation */ number. */ Pitch error compensation data. */ N is number of compensation data */ to be written. */ Data block length ( =6+(number of compensation data to be written) ) Buffer in which the pitch error compensation data are stored. [Return] EW_OK( 0) EW_LENGTH( 2) EW_NUMBER( 3) EW_BUSY(-1) Successful. Incorrect data block length "length". Incorrect pitch error compensation number "buf.datano_s" or "buf.datano_e". An attempt was made to execute this command when other window processing of a low-speed type was in progress. Execute the command after the window processing has ended. [Description] Alters the pitch error compensation data stored in the CNC within the specified range. Specify the start pitch error compensation data number in "buf.datano_s" and the end one in "buf.datano_e" with binary format. Store the pitch error compensation data "buf.data" with signed binary format. (The negative value is represented as 2's complement.) [Example] The following program alters the pitch error compensation data within the specified number range. #include <data.h> #include <fwindow.h> #include <stdlib.h> /* start/end are start/end number to be written. */ /* data is array of value to be written. */ short example( short start, short end, char *data ) { struct iodbpi *buf ; short ret, idx ; buf = (struct iodbpi *)malloc( 1024 ) ; buf->datano_s = start ; buf->datano_e = end ; for ( idx = 0 ; idx < end-start+1 ; idx++ ) buf->data[idx] = data[idx] ; ret = cnc_wrpitchr( 6+(end-start+1), buf ) ; free( buf ) ; return ( ret ) ; } -----------------------------------------------------------------------------1.52 Read custom macro variable. <Main,Alarm> -----------------------------------------------------------------------------[Name] cnc_rdmacro [Syntax] #include <data.h> #include <fwindow.h> short cnc_rdmacro( short number, short length, struct odbm *buf ) ; struct odbm { short short long short dummy ; datano ; mcr_val ; dec_val ; /* /* /* /* Not used. */ Custom macro variable number. */ Custom macro variable value. */ Digit number after decimal point.*/ } ; [Arguments] number length buf Custom macro variable number. Data block length ( =10 ). Buffer in which the custom macro variable data is stored. [Return] EW_OK( 0) EW_LENGTH( 2) EW_NUMBER( 3) EW_DATA( 5) EW_NOOPT( 6) EW_BUSY(-1) Successful. Incorrect data block length "length". Incorrect custom macro variable number "number". Value of the custom macro variable is out of the limit. There are no required options. The related options; - Custom macro. - Custom macro common variable addition (#100 to #199 and #500 to #999) It was impossible to read a custom macro variable because a command from another application program to write the custom macro variable was already being executed. Alternatively, an attempt was made to execute this command when other window processing of a low-speed type was in progress. Execute the command after the window processing has ended. [Description] Reads the custom macro variable data stored in the CNC. This function is used for controlling flow of the machining program of CNC by the application program exchanging data between the custom macro program in CNC and the application program, etc. Types of custom macro variable are as follows. (1) Local variables ( #1,..,#33 ) Readable. The local variables which belong to the macro program just being executed when the application program calls this function are read. (2) Common variables ( #100,..,#149, #500,..,#531 ) Readable. In case that Custom macro common variable 900 sets option is added, #100,..,#199 and #500,..,#999 are available to be read. (3) System variables ( #1000,.. ) Readable. Refer "USER'S MANUAL" of CNC for details of custom macro variables. Specify the custom macro variable number to be read in "number" with binary format. The variable data is stored in both "buf.mcr_val" and "buf.dec_val". mcr_val dec_val 4-byte singed binary format data. (The negative value is represented as 2's complement.) Variable value converted into integer. 2-byte signed binary format data. (The negative value is represented as 2's complement.) Digit number after decimal point. The following values are read concretely. Variable data displayed in CNC screen mcr_val dec_val ---------------+---------------+--------------Blank(void) 0 -1 0.000 0 3 0.0000001 1 7 0000.0001 1 4 00000.100 100 3 00001.000 1000 3 00010.000 10000 3 100000.00 10000000 2 99999999. 99999999 0 00123.000 123000 3 -00123.000 -123000 3 [Example] The following program reads the custom macro variable data of specified number and displays it. #include #include #include #include <data.h> <fwindow.h> <stdio.h> <string.h> /* number is variable number to be read. */ short example( short number ) { struct odbm buf ; char strbuf[11] ; short ret ; ret = cnc_rdmacro( number, 10, &buf ) ; if ( !ret ) { sprintf( &strbuf[1], "%09ld", buf.mcr_val ) ; if ( strbuf[1] == '0' ) strbuf[1] = ' ' ; strncpy( &strbuf[0], &strbuf[1], 9 - buf.dec_val ) ; strbuf[9-buf.dec_val] = '.' ; printf( "%s\n", strbuf ) ; } else printf( "**********\n" ) ; return ( ret ) ; } -----------------------------------------------------------------------------1.53 Write custom macro variable. <Main,Alarm> -----------------------------------------------------------------------------[Name] cnc_wrmacro [Syntax] #include <data.h> #include <fwindow.h> short cnc_wrmacro( short number, short length, long mcr_val , short dec_val ) ; [Arguments] number length mcr_val dec_val Custom macro variable number. Data block length ( =10 ). Custom macro variable value. Digit number after decimal point. [Return] EW_OK( 0) EW_LENGTH( 2) EW_NUMBER( 3) EW_DATA( 5) EW_NOOPT( 6) EW_BUSY(-1) Successful. Incorrect data block length "length". Incorrect custom macro variable number "number". Value of the custom macro variable is out of the limit. There are no required options. The related options; - Custom macro. - Custom macro common variable addition (#100 to #199 and #500 to #999) An attempt was made to execute this command when other window processing of a low-speed type was in progress. Execute the command after the window processing has ended. [Description] Writes the custom macro variable data in the CNC. This function is used for controlling flow of the machining program of CNC by the application program exchanging data between the custom macro program in CNC and the application program, etc. Types of custom macro variable are as follows. (1) Local variables ( #1,..,#33 ) Writable. The local variables which belong to the macro program just being executed when the application program calls this function are altered. (2) Common variables ( #100,..,#149, #500,..,#531 ) Writable. In case that Custom macro common variable 900 sets option is added, #100,..,#199 and #500,..,#999 are available to be written. (3) System variables ( #1000,.. ) Writable for only changeable variables. Refer "USER'S MANUAL" of CNC for details of custom macro variables. Specify the custom macro variable number to be written in "number" with binary format. Specify variable data to be written in both "mcr_val" and "dec_val". mcr_val dec_val 4-byte singed binary format data. (The negative value is represented as 2's complement.) Variable value converted into integer. 2-byte signed binary format data. (The negative value is represented as 2's complement.) Digit number after decimal point. The following values are stored concretely. (These are same as format of cnc_rdmacro() function.) Value to be written mcr_val dec_val ---------------+---------------+-------void 0 -1 0.000 0 3 0.0000001 1 7 0000.0001 1 4 00000.100 100 3 00001.000 1000 3 00010.000 10000 3 100000.00 10000000 2 99999999. 99999999 0 00123.000 123000 3 -00123.000 -123000 3 When "123." is written, "mcr_val=123000, dec_val=3" isn't only available format like above but also "mcr_val=123, dec_val=0" or "mcr_val=1230, dec_val=1", etc, are available. "void" can be written. [Example] The following program writes the specified value in the specified custom macro variable. #include <data.h> #include <fwindow.h> /* number is variable number to be written. */ /* value is value to be written. */ /* dec is decimal digit number. */ short example( short number, long value, short dec ) { short ret ; ret = cnc_wrmacro( number, 10, value, dec ) ; return ( ret ) ; } -----------------------------------------------------------------------------1.54 Read custom macro variables (range specified). <Main,Alarm> -----------------------------------------------------------------------------[Name] cnc_rdmacror [Syntax] #include <data.h> #include <fwindow.h> short cnc_rdmacror( short s_number, short e_number, short length, struct iodbmr *buf ) ; struct iodbmr { short datano_s ; /* Start custom macro variable number.*/ short dummy ; /* Not used. */ short datano_e ; /* End custom macro variable number.*/ struct { long mcr_val ; /* Custom macro variable value. */ short dec_val ; /* Digit number after decimal */ /* point. */ } data[N] ; /* N is number of variables to be read. */ } ; [Arguments] s_number e_number length buf Start custom macro variable number. End custom macro variable number. Data block length ( =6+6*(number of variables to be read) ) Buffer in which the custom macro variable data are stored. [Return] EW_OK( 0) EW_LENGTH( 2) EW_NUMBER( 3) EW_DATA( 5) EW_NOOPT( 6) EW_BUSY(-1) Successful. Incorrect data block length "length". Incorrect custom macro variable number "datano_s" or "datano_e". Value of the custom macro variable is out of the limit. There are no required options. The related options; - Custom macro. - Custom macro common variable addition (#100 to #199 and #500 to #999) It was impossible to read a custom macro variable because a command from another application program to write the custom macro variable was already being executed. Alternatively, an attempt was made to execute this command when other window processing of a low-speed type was in progress. Execute the command after the window processing has ended. [Description] Reads the custom macro variable data stored in the CNC within the specified range. Types of custom macro variable are as follows. (1) Local variables ( #1,..,#33 ) Not readable. (Use cnc_rdmacro function.) (2) Common variables ( #100,..,#149, #500,..,#531 ) Readable. In case that Custom macro common variable 900 sets option is added, #100,..,#199 and #500,..,#999 are available to be read. (3) System variables ( #1000,.. ) Not readable. (Use cnc_rdmacro function.) Refer "USER'S MANUAL" of CNC for details of custom macro variables. Specify the start custom macro variable number in "s_number" and the end one in "e_number" with binary format. The variable data is stored in both "buf.data[i].mcr_val" and "buf.data[i].dec_val". The formats of "mcr_val" and "dec_val" are same as ones of "Read custom macro variable(cnc_rdmacro)". See description of "cnc_rdmacro". [Example] The following program reads the custom macro variables within the specified range and displays them. #include #include #include #include #include <data.h> <fwindow.h> <stdio.h> <stdlib.h> <string.h> /* start/end are start/end variable number to be read. */ short example( short start, short end ) { struct odbmr *buf ; char strbuf[11] ; short ret, idx ; buf = (struct iodbmr *)malloc( 1000 ) ; ret = cnc_rdmacror( start, end, 1000, buf ) ; if ( !ret ) for ( idx = 0 ; idx <= end-start ; idx++ ) { sprintf( &strbuf[1], "%09ld", buf->data[idx].mcr_val ) ; if ( strbuf[1] == '0' ) strbuf[1] = ' ' ; strncpy( &strbuf[0], &strbuf[1], 9 - buf->data[idx].dec_val ) ; strbuf[9-buf->data[idx].dec_val] = '.' ; printf( "#%04d %s\n", start+idx, strbuf ) ; } else printf( "ERROR!(%d)\n", ret ) ; free( buf ) ; return ( ret ) ; } -----------------------------------------------------------------------------1.55 Write custom macro variables (range specified). <Main,Alarm> -----------------------------------------------------------------------------[Name] cnc_wrmacror [Syntax] #include <data.h> #include <fwindow.h> short cnc_wrmacror( short length, struct iodbmr *buf ) ; struct iodbmr { short datano_s ; /* Start custom macro variable number. */ short dummy ; /* Not used. */ short datano_e ; /* End custom macro variable number. */ struct { long mcr_val ; /* Custom macro variable value. */ short dec_val ; /* Digit number after decimal */ /* point. */ } data[N] ; /* N is number of variables to be written. */ } ; [Arguments] length buf Data block length ( =6+6*(number of variables to be written) ) Buffer in which the custom macro variable data are stored. [Return] EW_OK( 0) EW_LENGTH( 2) EW_NUMBER( 3) EW_DATA( 5) EW_NOOPT( 6) EW_BUSY(-1) Successful. Incorrect data block length "length". Incorrect custom macro variable number "datano_s" or "datano_e". Value of the custom macro variable is out of the limit. There are no required options. The related options; - Custom macro. - Custom macro common variable addition (#100 to #199 and #500 to #999) An attempt was made to execute this command when other window processing of a low-speed type was in progress. Execute the command after the window processing has ended. [Description] Writes the custom macro variable data stored in the CNC within the specified range. Types of custom macro variable are as follows. (1) Local variables ( #1,..,#33 ) Not writable. (Use cnc_wrmacro function.) (2) Common variables ( #100,..,#149, #500,..,#531 ) Writable. In case that Custom macro common variable 900 sets option is added, #100,..,#199 and #500,..,#999 are available to be written. (3) System variables ( #1000,.. ) Not writable. (Use cnc_wrmacro function.) Refer "USER'S MANUAL" of CNC for details of custom macro variables. Specify the start custom macro variable number in "buf.datano_s" and the end one in "buf.datano_e" with binary format. Store the variable data to be written in both "buf.data[i].mcr_val" and "buf.data[i].dec_val". The formats of "mcr_val" and "dec_val" are same as ones of "Write custom macro variable(cnc_wrmacro)". See description of "cnc_wrmacro". [Example] The following program writes the integer values into the custom macro variables within the specified range. #include <data.h> #include <fwindow.h> #include <stdlib.h> /* start is start variable number to be written. */ /* value is array of value to be written. */ /* number is number of variable. */ short example( short start, long *value, short number ) { struct odbmr *buf ; short ret, idx ; buf = (struct iodbmr *)malloc( 6+6*number ) ; buf->datano_s = start ; buf->datano_e = start + number - 1 ; for ( idx = 0 ; idx < number ; idx++ ) { buf->data[idx].mcr_val = value[idx] ; buf->data[idx].dec_val = 0 ; } ret = cnc_wrmacror( 6+6*number, buf ) ; free( buf ) ; return ( ret ) ; } -----------------------------------------------------------------------------1.56 Read P-code macro variable. <Main,Alarm> -----------------------------------------------------------------------------[Name] cnc_rdpmacro [Syntax] #include <data.h> #include <fwindow.h> short cnc_rdpmacro( long number, struct odbpm *buf ) ; struct odbpm { long datano ; short dummy ; union { struct { long mcr_val short dec_val } p6 ; struct { short short /* P-code macro variable number. */ /* Not used. */ ; /* P-code macro variable value. */ ; /* Digit number after decimal */ /* point. */ mcr_val ; /* P-code macro variable value. */ dec_val ; /* Digit number after decimal */ /* point. */ } p2 ; } u ; } ; [Arguments] number buf P-code macro variable number. ( >= 10000 ) Buffer in which the P-code macro variable data is stored. [Return] EW_OK( 0) EW_NUMBER( 3) EW_DATA( 5) EW_NOOPT( 6) EW_BUSY(-1) Successful. Incorrect P-code macro variable number "number". Value of the P-code macro variable is out of the limit. Macro executor option isn't added, or macro module isn't loaded. An attempt was made to execute this command when other window processing of a low-speed type was in progress. Execute the command after the window processing has ended. [Description] Reads the macro executor variable (P-code macro variable) data of specified number. This function is used for controlling flow of the machining program of CNC or interactive macro function by the application program exchanging data between the macro executor program in CNC and the application program, etc. Specify the P-code macro variable number to be read in "number" with binary format. The variable data is stored in both "buf.u.p6.mcr_val" and "buf.u.p6.dec_val". mcr_val dec_val 4-byte singed binary format data. (The negative value is represented as 2's complement.) Variable value converted into integer. 2-byte signed binary format data. (The negative value is represented as 2's complement.) Digit number after decimal point. The following values are read concretely. Variable data displayed in CNC screen mcr_val dec_val ---------------+---------------+--------------Blank(void) 0 -1 0.000 0 3 0.0000001 1 7 0000.0001 1 4 00000.100 100 3 00001.000 1000 3 00010.000 10000 3 100000.00 10000000 2 99999999. 99999999 0 00123.000 123000 3 -00123.000 -123000 3 [Example] The following program reads and displays a P code macro variable having a specified number. #include #include #include #include <data.h> <fwindow.h> <stdio.h> <string.h> /* number is variable number to be read. */ short example( long number ) { struct odbpm buf ; char strbuf[11] ; short ret ; ret = cnc_rdpmacro( number, &buf ) ; if ( !ret ) { sprintf( &strbuf[1], "%09ld", buf.u.p6.mcr_val ) ; if ( strbuf[1] == '0' ) strbuf[1] = ' ' ; strncpy( &strbuf[0], &strbuf[1], 9 - buf.u.p6.dec_val ) ; strbuf[9-buf.u.p6.dec_val] = '.' ; printf( "%s\n", strbuf ) ; } else printf( "**********\n" ) ; return ( ret ) ; } -----------------------------------------------------------------------------1.57 Write P-code macro variable. <Main,Alarm> -----------------------------------------------------------------------------[Name] cnc_wrpmacro [Syntax] #include <data.h> #include <fwindow.h> short cnc_wrpmacro( long number, long mcr_val, short dec_val ) ; [Arguments] number mcr_val dec_val P-code macro variable number. ( >= 10000 ) P-code macro variable value. Digit number after decimal point. [Return] EW_OK( 0) EW_NUMBER( 3) EW_NOOPT( 6) EW_BUSY(-1) Successful. Incorrect P-code macro variable number "number". Macro executor option isn't added, or macro module isn't loaded. An attempt was made to execute this command when other window processing of a low-speed type was in progress. Execute the command after the window processing has ended. [Description] Writes the macro executor variable (P-code macro variable) data of specified number. This function is used for controlling flow of the machining program of CNC or interactive macro function by the application program exchanging data between the macro executor program in CNC and the application program, etc. Specify the P-code macro variable number to be written in "number" with binary format. Specify variable data to be written in both "mcr_val" and "dec_val". mcr_val dec_val 4-byte singed binary format data. (The negative value is represented as 2's complement.) Variable value converted into integer. 2-byte signed binary format data. (The negative value is represented as 2's complement.) Digit number after decimal point. The following values are stored concretely. (These are same as format of cnc_rdpmacro() function.) Value to be written mcr_val dec_val ---------------+---------------+-------void 0 -1 0.000 0 3 0.0000001 1 7 0000.0001 1 4 00000.100 100 3 00001.000 1000 3 00010.000 10000 3 100000.00 10000000 2 99999999. 99999999 0 00123.000 123000 3 -00123.000 -123000 3 When "123." is written, "mcr_val=123000, dec_val=3" isn't only available format like above but also "mcr_val=123, dec_val=0" or "mcr_val=1230, dec_val=1", etc, are available. "void" can be written. Also expanded P-code macro variables (after #20000) which are used as fixed integer are written as floating point variables. The window internal routine converts floating format into fixed integer format. This function can write only P-code macro variables whose number are equal to or more than 10000. [Example] The following program writes the specified value in the specified P-code macro variable. #include <data.h> #include <fwindow.h> /* number is variable number to be written. */ /* value is value to be written. */ /* dec is decimal digit number. */ short example( long number, long value, short dec ) { short ret ; ret = cnc_wrpmacro( number, value, dec ) ; return ( ret ) ; } -----------------------------------------------------------------------------1.58 Read P-code macro variables (range specified). <Main,Alarm> -----------------------------------------------------------------------------[Name] cnc_rdpmacror [Syntax] #include <data.h> #include <fwindow.h> short cnc_rdpmacror( long s_number, long e_number, short length, struct iodbpr *buf ) ; struct iodbpr { long datano_s ; /* Start P-code macro variable number. */ short dummy ; /* Not used. */ long datano_e ; /* End P-code macro variable number. */ union { struct { long mcr_val ; /* P-code macro variable value. */ short dec_val ; /* Digit number after decimal */ /* point. */ } p6_r ; struct { short mcr_val ; /* P-code macro variable value. */ short dec_val ; /* Digit number after decimal */ /* point. */ } p2_r ; } pm_r[N] ; /* N is number of variables to be read. */ } ; [Arguments] s_number e_number length buf Start P-code macro variable number. End P-code macro variable number. Data block length ( =10+6*(number of variables to be read) ) Buffer in which the P-code macro variable data are stored. [Return] EW_OK( 0) EW_LENGTH( 2) EW_NUMBER( 3) EW_DATA( 5) EW_NOOPT( 6) EW_BUSY(-1) Successful. Incorrect data block length "length". Incorrect P-code macro variable number "s_number" or "e_number". Value of the P-code macro variable is out of the limit. Macro executor option isn't added, or macro module isn't loaded. It was impossible to read a P code macro variable because the CNC was updating the P code macro variable. [Description] Reads the macro executor variable (P-code macro variable) data within the specified range. Specify the start P-code macro variable number in "s_number" and the end one in "e_number" with binary format. The variable data is stored in both "buf.pr_m[i].p6_r.mcr_val" and "buf.pr_m[i].p6_r.dec_val". The formats of "mcr_val" and "dec_val" are same as ones of "Read P-code macro variable(cnc_rdpmacro)". See description of "cnc_rdpmacro". Also expanded P-code macro variables (after #20000) which are used as fixed integer are read as floating point variables. This function can read only P-code macro variables whose number are equal to or more than 10000. "pr_m[i].p2_r.mcr_val" and "pr_m[i].p2_r.dec_val", members of the structure "odbpr", are definition for compatibility with the past specification. These are not used now. [Example] The following program reads and displays P code macro variables in a specified range. #include #include #include #include #include <data.h> <fwindow.h> <stdio.h> <stdlib.h> <string.h> /* start/end are start/end variable number to be read. */ short example( long start, long end ) { struct iodbpr *buf ; char strbuf[11] ; short length, ret ; long idx ; length = 10 + 6 * ( end - start + 1 ) ; buf = (struct iodbpr *)malloc( length ) ; ret = cnc_rdpmacror( start, end, length, buf ) ; if ( !ret ) for ( idx = 0 ; idx <= end-start ; idx++ ) { sprintf( &strbuf[1], "%09ld", buf->pm_r[idx].p6_r.mcr_val ) ; if ( strbuf[1] == '0' ) strbuf[1] = ' ' ; strncpy( &strbuf[0], &strbuf[1], 9 - buf->pm_r[idx].p6_r.dec_val ) ; strbuf[9-buf->pm_r[idx].p6_r.dec_val] = '.' ; printf( "#%04ld %s\n", start+idx, strbuf ) ; } else printf( "ERROR!(%d)\n", ret ) ; free( buf ) ; return ( ret ) ; } -----------------------------------------------------------------------------1.59 Write P-code macro variables (range specified). <Main,Alarm> -----------------------------------------------------------------------------[Name] cnc_wrpmacror [Syntax] #include <data.h> #include <fwindow.h> short cnc_wrpmacror( short length, struct iodbpr *buf ) ; struct iodbpr { long datano_s ; /* Start P-code macro variable number. */ short dummy ; /* Not used. */ long datano_e ; /* End P-code macro variable number. */ union { struct { long mcr_val ; /* P-code macro variable value. */ short dec_val ; /* Digit number after decimal */ /* point. */ } p6_r ; struct { short mcr_val ; /* P-code macro variable value. */ short dec_val ; /* Digit number after decimal */ /* point. */ } p2_r ; } pm_r[N] ; /* N is number of variables to be read. */ } ; [Arguments] length datano_s datano_e mcr_val dec_val Data block length ( =10+6*(number of variables to be written) ) Start P-code macro variable number. ( >= 10000 ) End P-code macro variable number. P-code macro variable value. Digit number after decimal point. [Return] EW_OK( 0) EW_LENGTH( 2) EW_NUMBER( 3) EW_NOOPT( 6) EW_BUSY(-1) Successful. Incorrect data block length "length". Incorrect P-code macro variable number "s_number" or "e_number". Macro executor option isn't added, or macro module isn't loaded. An attempt was made to execute this command when other window processing of a low-speed type was in progress. Execute the command after the window processing has ended. [Description] Writes the macro executor variable (P-code macro variable) data within the specified range. Specify the start custom macro variable number in "buf.datano_s" and the end one in "buf.datano_e" with binary format. Store the variable data to be written in both "buf.pm_r[i].p6_r.mcr_val" and "buf.pm_r[i].p6_r.dec_val". The formats of "mcr_val" and "dec_val" are same as ones of "Write P-code macro variable(cnc_wrpmacro)". See description of "cnc_wrpmacro". Also expanded P-code macro variables (after #20000) which are used as fixed integer are written as floating point variables. The window internal routine converts floating format into fixed integer format. This function can write only P-code macro variables whose number are equal to or more than 10000. "pr_m[i].p2_r.mcr_val" and "pr_m[i].p2_r.dec_val", members of the structure "odbpr", are definition for compatibility with the past specification. These are not used now. [Example] The following program writes the integer values into the P-code macro variables within the specified range. #include <data.h> #include <fwindow.h> #include <stdlib.h> /* start is start variable number to be written. */ /* value is array of value to be written. */ /* number is number of variable. */ short example( long start, long *value, short number ) { struct iodbpr *buf ; short ret ; long idx ; buf = (struct iodbpr *)malloc( 10+6*number ) ; buf->datano_s = start ; buf->datano_e = start + number - 1 ; for ( idx = 0 ; idx < number ; idx++ ) { buf->pm_r[idx].p6_r.mcr_val = value[idx] ; buf->pm_r[idx].p6_r.dec_val = 0 ; } ret = cnc_wrpmacror( 10+6*number, buf ) ; free( buf ) ; return ( ret ) ; } -----------------------------------------------------------------------------1.60 Read modal data. <Main,Alarm> -----------------------------------------------------------------------------[Name] cnc_modal [Syntax] #include <data.h> #include <fwindow.h> short cnc_modal( short type, short block, struct odbmdl *buf ) ; struct odbmdl { short datano; /* Kind of modal data. */ short type; /* Objective block. */ union { char g_data; /* Modal data of G code. */ char g_rdata[35]; /* Modal data of G code. */ char g_1shot[4];/* 1 shot Modal data of G code.*/ struct { long aux_data; /* Modal data other than G code.*/ char flag1; /* Flag1. */ char flag2; * Flag2. */ }aux; struct { long aux_data; /* Modal data other than G code.*/ char flag1; /* Flag1. */ char flag2; /* Flag2. */ }raux1[27]; struct { long aux_data; /* Modal data other than G code.*/ char flag1; /* Flag1. */ char flag2; /* Flag2. */ }raux2[MAX_AXIS]; /* MAX_AXIS : Maximum */ }modal; /* controlled-axis number */ }; [Arguments] type Specifies the type of modal data. (Details are described later.) -4 -3 : All one-shot G codes are read at a time. : All axis data except for G codes is read at a time. -2 : All codes other than G codes are read at a time. -1 : All G codes are read at a time. 0 to 20 : GIndividual G codes are read separately. 100 to 126 : Individual codes other than G codes are read separately. 200 to 207 : Axis data except for G codes is read separately. 300 : Individual one-shot G codes are read separately. block Specifies a block for which data is to be read. 0 : Block being currently executed 1 : Next block modal Modal data storage area [Return] EW_OK( 0) EW_NUMBER( 3) EW_ATTRIB( 4) EW_BUSY(-1) Successful. Incorrect kind of data "type". Incorrect objective block "block". It was impossible to read modal information because the CNC was updating the modal information. [Description] Reads the modal information of CNC. The readable modal data are modal G code, M/S/T code or commanded data such as F. The type of a union for storing modal data varies depending on the type of the modal data. When accessing read results, use a union that matches the data type. (1) Reading modal G code. The G code group listed below can be specified as the type. Machining Lathe Series Center Series -------+-------+---------------+-----------------------+ G code type g_data G code System A System B System C -------+-------+---------------+---------------+-------+ 0 0 G00 G00 G00 G00 1 G01 G01 G01 G01 2 G02 G02 G02 G02 3 G03 G03 G03 G03 4 G33 G32 G33 G33 5 G75 G90 G77 G20 6 G77 G92 G78 G21 7 G78 G94 G79 G24 9 G79 G34 G34 G34 10 G02.2 11 G03.2 12 G02.3 13 G03.3 14 G06.2 G35 G35 G35 15 G02.4 G36 G36 G36 16 G03.4 17 G06.2 G06.2 G06.2 18 G02.4 G02.4 G02.4 19 G03.4 G03.4 G03.4 20 G02.2 G02.2 G02.2 21 G03.2 G03.2 G03.2 22 G35 G02.3 G02.3 G02.3 23 G36 G03.3 G03.3 G03.3 24 G34 G06.1 G06.1 G06.1 25 G32.2 G32.2 G32.2 -------+-------+---------------+---------------+------1 0 G17 G97 G97 G97 1 G96 G96 G96 4 G19 8 G18 10 G17.1 -------+-------+---------------+---------------+-------+ 2 0 G90 G90 G90 1 G91 G91 G91 -------+-------+---------------+---------------+------3 0 G23 G69 G69 G69 1 G22 G68 G68 G68 -------+-------+---------------+---------------+------4 0 G94 G98 G94 G94 1 G95 G99 G95 G95 2 G93 G93 G93 G93 2 G93.2 G93 G93 G93 -------+-------+---------------+---------------+------5 0 G20(G70) G20 G20 G70 1 G21(G71) G21 G21 G71 -------+-------+---------------+---------------+------(Continued on the next page) Machining Lathe Series Center Series -------+-------+---------------+-----------------------+ G code type g_data G code System A System B System C -------+-------+---------------+---------------+-------+ 6 0 G40 G40 G40 G40 1 G41 G41 G41 G41 2 G42 G42 G42 G42 3 G41.2 G41.2 G41.2 G41.2 4 G42.2 G42.2 G42.2 G42.2 5 G41.3 G41.3 G41.3 G41.3 6 G41.4 G41.4 G41.4 G41.4 7 G42.4 G42.4 G42.4 G42.4 8 G41.5 G41.5 G41.5 G41.5 9 G42.5 G42.5 G42.5 G42.5 10 G40.3 G40.3 G40.3 -------+-------+---------------+---------------+------7 0 G49(G49.1) G25 G25 G25 1 G43 G26 G26 G26 2 G44 3 G43.1 4 G43.4 5 G43.5 6 G43.2 7 G43.3 -------+-------+---------------+---------------+------8 0 G80 G23 G23 G23 1 G81 G22 G22 G22 2 G82 3 G83 4 G84 5 G85 6 G86 7 G87 8 G88 9 G89 10 G73 11 G74 12 G76 13 G84.2 14 G84.3 15 G81.2 -------+-------+---------------+---------------+------9 0 G98 G80 G80 G80 1 G99 G83 G83 G83 2 G84 G84 G84 3 G85 G85 G85 4 G86 G86 G86 5 G87 G87 G87 6 G88 G88 G88 7 G89 G89 G89 -------+-------+---------------+---------------+------10 0 G50 G98 G98 1 G51 G99 G99 -------+-------+---------------+---------------+------(Continued on the next page) Machining Lathe Series Center Series -------+-------+---------------+-----------------------+ G code type g_data G code System A System B System C -------+-------+---------------+---------------+-------+ 11 0 G67 G67 G67 G67 1 G66 G66 G66 G66 2 G66.1 G66.1 G66.1 G66.1 -------+-------+---------------+---------------+------12 0 G97 G49 G49 G49 1 G96 G43 G43 G43 -------+-------+---------------+---------------+------13 0 G54(G54.1) G54 G54 G54 1 G55 G55 G55 G55 2 G56 G56 G56 G56 3 G57 G57 G57 G57 4 G58 G58 G58 G58 5 G59 G59 G59 G59 -------+-------+---------------+---------------+------14 0 G64 G64 G64 G64 1 G61 G61 G61 G61 2 G62 G62 G62 G62 3 G63 G63 G63 G63 -------+-------+---------------+---------------+------15 0 G69 G17 G17 G17 1 G68 2 G68.2 4 G18 G18 G18 8 G19 G19 G19 10 G17.1 G17.1 G17.1 -------+-------+---------------+---------------+-------+ 16 0 G15 G69.1 G69.1 G69.1 1 G16 G68.1 G68.1 G68.1 2 G68.2 G68.2 G68.2 -------+-------+---------------+---------------+------17 0 G40.1(G150) G50 G50 1 G41.1(G151) G51 G51 2 G42.1(G152) -------+-------+---------------+---------------+------18 0 G25 1 G26 -------+-------+---------------+---------------+------19 0 G160 G50.2 G50.2 G50.2 1 G161 G51.2 G51.2 G51.2 -------+-------+---------------+---------------+------20 0 G13.1(G113) G13.1 G13.1 G13.1 1 G12.1(G112) G12.1 G12.1 G12.1 -------+-------+---------------+---------------+------- The numbers in the g_data column of the above table are stored to bits 0 to 6 of buf.modal.g_data in binary form. Bit 7 of buf.modal.g_data is used to store information about whether this G code is specified in a read target block specified in "block". 7 6 5 4 3 2 1 0 ┌─┬─┬─┬─┬─┬─┬─┬─┐ ┌┼・│ Code in each group │ 1 byte │└─┴─┴─┴─┴─┴─┴─┴─┘ └─┬──→ 0 : The G code is not specified in the current │ block. └──→ 1 : The G code is specified in the current block. If this function is executed when the N100 block in the following NC program is executed, for example, the result is as listed below. N090 G18 ; N100 G1 Z100. ; N110 G17 G2 X10. Y-20. R12. ; type block g_data Modal state -------+-------+---------------+--------------------0 0 0x81 G1 is specified. 0 1 0x82 G2 is specified. 1 0 0x08 G18 mode (no specification) 1 1 0x80 G17 is specified. To read all types related to the G code at a time, specify -1. The g_data array is set to buf.modal.g_rdata. Data of type 0 to data of type 20 are set, respectively in, in g_rdata[0] to g_rdata[20]. (2) Reading modal data other than B code. type Address -------+-----------------------100 B (2nd auxiliary function) 101 D 102 (Reserved) 103 F 104 H [M] 105 L 106 M 107 S 108 T 109 R [M] 110 P [M] 111 Q [M] 112 A 113 C 114 I 115 J 116 K 117 N 118 O 119 U 120 V 121 W 122 X 123 Y 124 Z 125 M (2nd M code) 126 M (3rd M code) -------+-----------------------200 1st axts 201 2nd axts 202 3rd axts 203 4th axts 204 5th axts 205 6th axts 206 7th axts 207 8th axts -------+-----------------------Data of a type indicated [M] is read as modal data for the machining center series and command data for the lathe series. To read data of The data is set To read data of The data is set types 100 to 199 at a time, specify -2. in the buf.modal.raux1 array. types 200 to 299 at a type, specify -3. in the buf.modal.raux2 array. ┌───────────────┐ │ Data │ : 4 bytes ├───────────────┤ ┌─│ FLAG1 │ : 1 byte │ ├───────────────┤ ┌┼─│ FLAG2 │ : 1 byte ││ └───────────────┘ ││ 7 6 5 4 3 2 1 0 ││ ┌─┬─┬─┬─┬─┬─┬─┬─┐ │└→│ │ │ │-│Number of │ │ │ │ │ │ │input digits │ │ └─┴─┴─┴─┴─┴─┴─┴─┘ │ │ │ ├─→ 0 : The data is positive. │ │ │ └─→ 1 : The data is negative. │ │ ├───→ 0 : No decimal point is specified for the data. │ │ └───→ 1 : A decimal point is specified for the data. │ ├─────→ 0 : The data is not specified as the current │ │ block. │ └─────→ 1 : The data is specified as the current block. │ ┌─┬─┬─┬─┬─┬─┬─┬─┐ └─→│Number of digits after │ │the decimal point │ └─┴─┴─┴─┴─┴─┴─┴─┘ * Even if no decimal point is specified, the number of digits after the decimal point may not be 0. * For the command addresses M, S, T, and B, a parameter-specified allowable number of digits is returned as the number of input digits. M S T B parameter parameter parameter parameter No. No. No. No. 3030: 3031: 3032: 3033: Allowable Allowable Allowable Allowable number number number number of of of of digits digits digits digits for for for for the the the the M S T B code code code code (3) Reading modal data for one-shot G codes Machining Lathe Series Center Series -------+-------+---------------+-----------------------+ G code type g_data G code System A System B System C -------+-------+---------------+---------------+-------+ 300 0 G04 G04 G04 G04 1 G10 G27 G27 G27 2 G28 G28 G28 3 G29 G29 G29 4 G27 G30 G30 G30 5 G28 G50 G92 G92 6 G29 G70 G70 G72 7 G30 G71 G71 G73 8 G38 G72 G72 G74 9 G39 G73 G73 G75 10 G74 G74 G76 11 G75 G75 G77 12 G76 G76 G78 13 G10 G10 G10 14 G92 G37.1 G37.1 G37.1 15 G37 G37 G37 16 G31(G31.1) G31 G31 G31 17 G60 G65 G65 G65 18 G65 19 G05 G05 G05 20 G05 G11 G11 G11 21 G11 G07.1 G07.1 G07.1 22 G52 G52 G52 G52 23 G53 G53 G53 G53 24 G37 G30.1 G30.1 G30.1 25 G07.1(G107) G10.6 G10.6 G10.6 26 G30.1 G50.3 G92.1 G92.1 27 G10.6 G08 G08 G08 28 G72.1 29 G72.2 G39 G39 G39 30 G92.1 G60 G60 G60 31 G08 32 80 81 100 G81.1 G07 G07 G07 101 G09 G09 G09 102 G73.1 G73.1 G73.1 103 G73.2 G73.2 G73.2 104 G05.1 G74.1 G74.1 G74.1 105 G07 106 G31.8 G80.4 G80.4 G80.4 107 G31.9 G81.4 G81.4 G81.4 108 G12.4 G82.4 G82.4 G82.4 109 G13.4 G83.4 G83.4 G83.4 110 G05.4 G84.4 G84.4 G84.4 111 G10.9 G05.1 G05.1 G05.1 112 G31.2 G72.1 G72.1 G72.1 113 G31.3 G72.2 G72.2 G72.2 114 G31.4 G53.1 G53.1 G53.1 -------+-------+---------------+-----------------------+ (Continued on the next page) Machining Lathe Series Center Series -------+-------+---------------+-----------------------+ G code type g_data G code System A System B System C -------+-------+---------------+---------------+-------+ 116 G91.1 G38 G38 G38 119 G43.6 G43.6 G43.6 120 G50.4 G50.4 G50.4 121 G50.5 G50.5 G50.5 122 G50.6 G50.6 G50.6 123 G51.4 G51.4 G51.4 124 G51.5 G51.5 G51.5 125 G51.6 G91.1 G91.1 126 G28.2 G28.2 G28.2 127 G30.2 G30.2 G30.2 -------+-------+---------------+---------------+------The numbers in the g_1shot column of the above table are stored to bits 0 to 6 of buf.modal.g_1shot in binary form. Bit 7 of buf.modal.g_1shot is used to store information about whether this G code is specified in a read target block specified in "block". 7 6 5 4 3 2 1 0 ┌─┬─┬─┬─┬─┬─┬─┬─┐ ┌┼* │ Code in each group │ 1 byte │└─┴─┴─┴─┴─┴─┴─┴─┘ └─┬──→ 0: The G code is not specified in the current │ block. └──→ 1: The G code is specified in the current block. To read data of all types related to one-shot G codes, specify -4. The data of type 300 is set in the buf.modal.g_1shot[0]. -----------------------------------------------------------------------------1.61 Read diagnostics data. <Main,Alarm> -----------------------------------------------------------------------------[Name] cnc_diagnoss [Syntax] #include <data.h> #include <fwindow.h> short cnc_diagnoss( short number, short axis, short length, struct iodbpsd *buf ) ; struct iodbpsd { short datano; short type; union { char short long char short long /* diagnosis number */ /* axis number */ cdata; /* bit/byte diagnosis */ idata; /* word diagnosis */ ldata; /* 2-word diagnosis */ cdatas[N]; /*bit/byte diagnosis with axis*/ idatas[N]; /* word diagnosis with axis */ ldatas[N]; /* 2-word diagnosis with axis */ } u ; } ; /* N : max. controlled axes */ [Arguments] number axis length buf Diagnostic number. Axis number ( =(1,..,amount of controlled axes), or -1, 0 ). Data block length ( =4+(byte size of the diagnostics data)*(amount of axes to be read) ) Buffer in which the diagnostics data are stored. [Return] EW_OK( 0) EW_LENGTH( 2) EW_NUMBER( 3) EW_ATTRIB( 4) EW_NOOPT( 6) EW_BUSY(-1) Successful. Incorrect data block length "length". Incorrect diagnostic number "number". Incorrect axis number "axis". Any data other than -1, 0 or (1,..,amount of controlled axes) has been specified. An option (such as a remote buffer) required to use data having a specified diagnose data number has not been added. An attempt was made to execute this command when other window processing of a low-speed type was in progress. Execute the command after the window processing has ended. [Description] Reads the contents of data displayed in the diagnostics screen of CNC. The attribute of diagnosis depends on the type and axis, and it is different for each diagnosis. Diagnosis type Use Byte size -----------------------+-------------------------------+--------Byte type data To display 1-byte data 1 Word type data To display 2-byte data 2 2-word type data To display 4-byte data 4 The data that is displayed in bit form on the CNC diagnostic screen is of byte type. Axis type data can be read either for individual axes separately or for all axes at a time. Refer "MAINTENANCE MANUAL" of CNC for details of each diagnostics data. Specify the diagnostic number in "number" with binary format. Specify one of following values corresponding with each diagnostic data as axis number in "axis". axis Diagnostics data type -----------------------+--------------------------------0 Ordinary (none axis type) data -1 All axes data of axis type data 1,..,amount of One specified axis data of controlled axis axis type data The diagnostics data of none axis type data or the axis type data which was read for one specified axis is stored in "buf.u.cdata/idata/ldata". The axis type data which were read for all axes are stored in "buf.u.cdatas/idatas/ldatas". The data format depends on each diagnostics data. The format of Byte/Word/2-Word data is generally signed binary. This function reads the "raw" diagnostics data. In case of reading bit data, also the masked bit on the CNC's diagnostics screen can be read without masking. Therefore, there may be difference between the contents of displayed data on the CNC's screen and ones read by this function. Reference ~~~~ Types of diagnostics data displayed on the CNC screen Diagnosis number Type -----------------------+--------------000 to 006 Byte 010 to 015 Byte 020 to 025 Byte 030 to 031 Byte 200 to 204 Byte axis 280 Byte axis 300 to 302 2-word axis 380 to 381 Word axis 400 to 402 Byte 408 to 409 Byte 410 to 413 Word 414 to 416 2-word 417 Word 418 2-word 419 Word 420 2-word [Example] The following program reads information about what operation status the CNC is in and displays the information on the screen. #include <data.h> #include <fwindow.h> #include <stdio.h> void example( void ) { short dgn_no[] = { 0,1,2,3,4,5,6,10,11,12,13,14,15 } ; char *dgn_msg[] = { "WAITING FOR FIN SIGNAL", "MOTION", "DWELL", "IN-POSITION CHECK", "FEEDRATE OVERRIDE 0%", "INTERLOCK/STARTLOCK", "SPINDLE SPEED ARRIVAL CHECK", "PUNCHING", "READING", "WAITING FOR (UN) CLAMP", "JOG FEEDRATE OVERRIDE 0%", "WAITING FOR RESET. ESP. RRW. OFF", "EXTERNAL PROGRAM NUMBER SEARCH" } ; short idx, count = 0 ; struct iodbpsd buf ; printf( "\033[1;1H<< CNC DIAGNOSTICS >>\n\n" ) ; for ( idx = 0 ; idx < sizeof(dgn_no)/sizeof(short) ; idx++ ) { cnc_diagnoss( dgn_no[idx], 0, 4+1*1, &buf ) ; if ( buf.u.cdata ) { printf( "%03d %s\n", dgn_no[idx], dgn_msg[idx] ) ; count++ ; } } for ( idx = 0 ; idx < 10 - count ; idx++ ) printf( "\033[K\n" ) ; } -----------------------------------------------------------------------------1.62 Read diagnostics data (range specified). <Main,Alarm> -----------------------------------------------------------------------------[Name] cnc_diagnosr [Syntax] #include <data.h> #include <fwindow.h> short cnc_diagnosr( short s_number, short axis, short e_number, short length, struct iodbpsdr *buf ) ; struct iodbpsdr { short datano; short type; /* diagnosis number */ /* upper byte:type */ /* lower byte:axis */ union { char short long char short long cdata; /* bit/byte diagnosis */ idata; /* word diagnosis */ ldata; /* 2-word diagnosis */ cdatas[32]; /*bit/byte diagnosis with axis*/ idatas[32]; /* word diagnosis with axis */ ldatas[32; /* 2-word diagnosis with axis */ } u ; } ; [Arguments] s_number axis e_number length buf Start diagnostic number. Axis number ( =(1,..,amount of controlled axes), or -1, 0 ). End diagnostic number. Data block length ( = Sum of [4+(byte size of the diagnostics data)*( amount of axes to be read)] ) Buffer in which the diagnostics data are stored. [Return] EW_OK( 0) EW_LENGTH( 2) EW_NUMBER( 3) EW_ATTRIB( 4) EW_NOOPT( 6) EW_BUSY(-1) Successful. Incorrect data block length "length". Incorrect diagnostic number "s_number" or "e_number". Incorrect axis number "axis". Any data other than -1, 0 or (1,..,amount of controlled axes) has been specified. An option (such as a remote buffer) required to use data having a specified diagnose data number has not been added. An attempt was made to execute this command when other window processing of a low-speed type was in progress. Execute the command after the window processing has ended. [Description] Reads the contents of data displayed in the diagnostics screen of CNC within the specified range. The attribute of diagnosis depends on the type and axis, and it is different for each diagnosis. Diagnosis type Use Byte size -----------------------+-------------------------------+--------Byte type data To display 1-byte data 1 Word type data To display 2-byte data 2 2-word type data To display 4-byte data 4 The data that is displayed in bit form on the CNC diagnostic screen is of byte type. Axis type data can be read either for individual axes separately or for all axes at a time. Refer "MAINTENANCE MANUAL" of CNC for details of each diagnostics data. Specify the start diagnostic number in "s_number" and the end one in "e_number" with binary format. The new diagnostics data will may be added according to updating CNC software, addition of the new functions, etc. If the new diagnostics data will be added within reading range, ERROR 2 (Incorrect data block length) will be returned or the application program will not work correctly. To avoid these mistakes, specify the continuous numbers of existing diagnostics data as the reading range. Specify one of following values corresponding with each diagnostic data as axis number in "axis". axis Diagnostics data type -----------------------+--------------------------------0 Ordinary (none axis type) data -1 All axes data of axis type data 1,..,amount of One specified axis data controlled axis of axis type data Any values are allowed for "axis" to read none axis type diagnostics data. In case that any axis type diagnostics data exists in the specified range, error will be returned by specifying "axis=0". The read diagnostics data are stored in "buf" in following order. +-----------------------+ | Data number 1 | |-----------------------| | Type 1 | |-----------------------| | Data 1 | | | |-----------------------| : |-----------------------| | Data number n | |-----------------------| | Type n | |-----------------------| | Data n | | | +-----------------------+ <-- buf[0].datano <-- buf[0].type <-- buf[0].u.cdata/idata/ldata/ cdatas/idatas/ldatas <-- buf[n].datano <-- buf[n].type <-- buf[n].u.cdata/idata/ldata/ cdatas/idatas/ldatas "Type" includes both diagnostics data type in the upper byte and axis type in the lower byte. Type (upper byte) Diagnostics data type -----------------------+--------------------0 Byte 1 Word 2 2-Word Axis type (lower byte) Diagnostics data type -----------------------+--------------------------------0 Ordinary (none axis type) data -1 All axes data of axis type data 1,..,amount of One specified axis data controlled axis of axis type data The diagnostics data is stored in "Data". The diagnostics data of none axis type data or the axis type data which was read for one specified axis is stored in "buf[i].u.cdata/idata/ldata". The axis type data which were read for all axes are stored in "buf[i].u.cdatas/idatas/ldatas" in axis number order. The array size of each members of "iodbpsdr.u.cdatas/idatas/ldatas" which is used for reading all axes's data is always 32 regardless of the amount of controlled axes. In case that the amount of controlled axes is less than 32, no data are stored in the members corresponding with the axes No. (amount of controlled axes + 1),..,32. Each buf[i] is suffixed with dummy data so that the total data size is a multiple of 4-bytes. The data format depends on each diagnostics data. The format of Byte/Word/2-Word data is generally signed binary. In case of reading bit data, also the masked bit on the CNC's diagnostics screen can be read without masking. Therefore, there may be difference between the contents of displayed data on the CNC's screen and ones read by this function. [Example] The following program reads diagnose data in a specified range for a specified axis and displays it on the screen. #include #include #include #include <data.h> <fwindow.h> <stdio.h> <stdlib.h> /* start/end are start/end number to be read. */ /* axis is axis number. */ short example( short start, short end, short axis ) { struct odbsys info ; struct iodbpsdr *buf, *ptr ; short ret, idx1, idx2, axno, inc ; cnc_sysinfo( &info ) ; axno = atoi( info.axes ) ; buf = (struct iodbpsdr *)calloc( 1, 1000 ) ; ret = cnc_diagnosr( start, axis, end, 1000, buf ) ; ptr = buf ; if ( !ret ) { for ( idx1 = start ; idx1 <= end ; idx1++ ) { if ( ( idx1 != 0 ) && ( ptr->datano == 0 ) ) break ; printf( "No.%05d ", ptr->datano ) ; switch ( ptr->type >> 8 ) { case 0: printf( "BYTE" ) ; break ; case 1: printf( "WORD" ) ; break ; case 2: printf( "2WRD" ) ; break ; } switch ( ptr->type & 0xff ) { case 0xff : for ( idx2 = 0 ; idx2 < axno ; idx2++ ) { printf( " #%d:", idx2+1 ) ; switch ( ptr->type >> 8 ) { case 0: printf( "%02X", ptr->u.cdatas[idx2] ) ; inc = 1 ; break ; case 1: printf( "%d", ptr->u.idatas[idx2] ) ; inc = 2 ; break ; case 2: printf( "%ld", ptr->u.ldatas[idx2] ) ; inc = 4 ; break ; } } putchar( '\n' ) ; ptr = (struct iodbpsdr *)(((char *)ptr)+4+8*inc) ; break ; /* to be continued on the next page... */ default : printf( " #%d:", ptr->type & 0xff ) ; case 0: switch ( ptr->type >> 8 ) { case 0: printf( " %02X\n", ptr->u.cdata ) ; inc = 2 ; break ; case 1: printf( " %d\n", ptr->u.idata ) ; inc = 2 ; break ; case 2: printf( " %ld\n", ptr->u.ldata ) ; inc = 4 ; break ; } ptr = (struct iodbpsdr *)(((char *)ptr)+4+inc) ; break ; } } } else printf( "ERROR!(%d)\n", ret ) ; free( buf ) ; return ( ret ) ; } -----------------------------------------------------------------------------1.63 Read A/D conversion data. <Main,Alarm> -----------------------------------------------------------------------------[Name] cnc_adcnv [Syntax] #include <data.h> #include <fwindow.h> short cnc_adcnv( short inp_type, short av_type, struct odbad *buf ) ; struct odbad { short datano ; /* Kind of analog voltage. */ short type ; /* Input channel or controlled axis number. */ short data ; /* Voltage data. */ } ; [Arguments] inp_type av_type buf Kind of analog voltage ( =0, 2 ). Controlled axis number of CNC. ( 1,..,(amount of controlled axes) ) Buffer in which the A/D conversion data is stored. [Return] EW_OK( 0) EW_ATTRIB( 4) Successful. Incorrect input channel or controlled axis number "av_type". [Description] Reading the load information of the controlled axis of the CNC. Reads the load current data of the controlled axis of the CNC which is converted into analog voltage via A/D converter. Specify "2" in "inp_type". Specify the controlled axis number of the CNC whose load information is read in "av_type". av_type Objective axis -------+--------------------------------1 Axis connected to connector "JV1" 2 Axis connected to connector "JV2" 3 Axis connected to connector "JV3" 4 Axis connected to connector "JV4" 5 Axis connected to connector "JV5" 6 Axis connected to connector "JV6" 7 Axis connected to connector "JV7" 8 Axis connected to connector "JV8" This axis number is the servo axis number, and may be different from the controlled axis number of the CNC. The digital value (0,..,+/-6554) which is converted from the load current is stored in "buf.data" with binary format. It is possible to get the load current using this value as following formula. The load current = buf.data * N / 6554 [Apeak] where N takes the following value. Value of parameter No. 2165 Value of N ----------------------------+-------------------------------Less than 20 [Value of parameter No. 2165] Greater than or equal to 20 [Value of parameter No. 2165]/ 10 * 10 (rounded down to the tens digit) -----------------------------------------------------------------------------1.64 Read operator's message. <Main,Alarm> -----------------------------------------------------------------------------[Name] cnc_rdopmsg [Syntax] #include <data.h> #include <fwindow.h> short cnc_rdopmsg( short type , short length, struct msg *buf ) ; struct msg { short short short char datano ; type ; char_num ; data[N] ; } ; [Arguments] type length buf /* /* /* /* /* Operator's message number. */ Kind of operator's message. */ Message length. */ Operator's message. */ N is maximum length of string. */ Kind of the operator's message ( =0,1,2,3 ). Data block length ( =6+(maximum length of string) ) Buffer in which the operator's message is stored. [Return] EW_OK( 0) EW_ATTRIB( 4) EW_NOOPT( 6) Successful. Incorrect kind of the operator's message "type". External message or option of external data input isn't added. [Description] Reads the contents of the operator's message displayed in the CNC's screen. Be sure to set "0" to "type". The operator's message number (100,..,999 or 2000,..,2099) is stored in "buf.datano" with binary format. When no operator's message is displayed, "-1" is stored. Always "0" is stored in "buf.data". The ASCII strings which terminated by a null character ('\x00') is stored in "buf.data". The length of string stored in "buf.data" is stored in "buf.char_num" with binary format. This function cannot read any of PMC alarm messages 1000 to 1999. [Example] The following program reads the operator's message and displays it. #include <data.h> #include <fwindow.h> #include <stdio.h> void example( void ) { struct msg buf ; cnc_rdopmsg( 0, 6+256, &buf ) ; if ( buf.datano != -1 ) printf( "%04d %s\n", buf.datano, buf.data ) ; else printf( "No operator message.\n" ) ; } -----------------------------------------------------------------------------1.65 Set path index (multi-path system). <Main,Alarm> -----------------------------------------------------------------------------[Name] cnc_setpath [Syntax] #include <data.h> #include <fwindow.h> short cnc_setpath( int path_no ) ; [Arguments] path_no Path number. [Return] EW_OK( 0) EW_PATH(11) Successful. Incorrect path number "path_no". [Description] Selects the path number which is objective path of the CNC window functions in the multi-path system. All CNC window functions inputs from/outputs to the CNC's path selected by this function. Specify the path number in "path_no" with binary format. path_no Objective path ---------------+----------------0 or 1 The 1st path The 1st path is selected during this function has never been called since power-on. [Example] The following program sets up a specified path and processing target path. #include <data.h> #include <fwindow.h> #include <stdio.h> /* path is new path number to be set. */ short example( short path ) { short ret ; ret = cnc_setpath( path ) ; if ( !ret ) printf( "PATH #%d has been set as new target path.\n", path ) ; else printf( "ERROR!(%d)\n", ret ) ; return ( ret ) ; } -----------------------------------------------------------------------------1.66 Get path index (multi-path system). <Main,Alarm> -----------------------------------------------------------------------------[Name] cnc_getpath [Syntax] #include <data.h> #include <fwindow.h> short cnc_getpath( short *path_no, short *maxpath_no ) ; [Arguments] path_no maxpath_no Current selected path number. Maximum path number. [Return] EW_OK( 0) Successful. [Description] Reads the current selected path number which is the objective path of the CNC window functions. The current selected path number ("1" or "2") is stored in "path_no" with binary format. The maximum selectable path number is stored in "maxpath_no" with binary format. [Example] The following program reads and displays information about the current processing target path. #include <data.h> #include <fwindow.h> #include <stdio.h> void example( void ) { short path, max ; cnc_getpath( &path, &max ) ; printf( "Current target path is PATH #%d (max:%d).\n", path, max ) ; } -----------------------------------------------------------------------------1.67 Set calendar timer of CNC. <Main,Alarm> -----------------------------------------------------------------------------[Name] cnc_settimer [Syntax] #include <data.h> #include <fwindow.h> short cnc_settimer( struct iodbtimer *buf ) ; struct iodbtimer { short type ; short dummy ; union { struct { /* Spec. of date or time. */ /* Not used. */ short short short year ; /* Year. */ month ; /* Month. */ date ; /* Date. */ } date ; struct { short short short hour ; /* Hour. */ minute ;/* Minute. */ second ;/* Second. */ } time ; } data ; } ; [Arguments] buf Buffer in which the date or time data are stored. [Return] EW_OK( 0) EW_NUMBER( 3) EW_DATA( 5) EW_BUSY(-1) Successful. Incorrect spec. of date or time "buf.type". Incorrect date or time data. Failed to set the data to the calendar timer device. Any hardware may be out of order. [Description] Sets the date or time data to the calendar timer device of the CNC unit. CNC software and C library read date and time from the calendar timer device of the CNC unit. This function set the date and time data to that calendar timer device. Specify one of following values in "buf.type". (It is impossible to set both date and time simultaneously.) buf.type Data to be set ---------------+----------------0 Sets date 1 Sets time Store the date value or time value in each member of "buf.data.date" or "buf.data.time" with binary format as follows. Member Setting data Range of value -----------------------+---------------+--------------buf.data.date.year Year 1987 - 2037 buf.data.date.month Month 1 - 12 buf.data.date.date Date 1 - 31 buf.data.time.hour Hour 0 - 23 buf.data.time.minute Minute 0 - 59 buf.data.time.second Second 0 - 59 That is, the time "00:00:00, Jan. 1, 1987" through "23:59:59, Dec. 31, 2037" can be set. This function doesn't check strictly validity of date format (buf.data.date.*). For example, "Feb. 31" can be set. In this case, "Mar. 3" is read by "time()" function (not a leap year), "Feb. 31" is displayed in the setting scrren of CNC. [Example] The following program sets the calendar/timer with the date and time entered using keys. #include <data.h> #include <fwindow.h> #include <stdio.h> short example( void ) { struct iodbtimer buf ; short ret, year, month, date, hour, minute, second ; printf( "Year =" ) ; scanf( "%d", &year ) ; printf( "Month =" ) ; scanf( "%d", &month ) ; printf( "Date =" ) ; scanf( "%d", &date ) ; printf( "Hour =" ) ; scanf( "%d", &hour ) ; printf( "Minute=" ) ; scanf( "%d", &minute ) ; printf( "Second=" ) ; scanf( "%d", &second ) ; buf.type = 0 ; buf.data.date.year = year ; buf.data.date.month = month ; buf.data.date.date = date ; ret = cnc_settimer( &buf ) ; if ( ret == 5 ) printf( "Error while writing DATE.\n" ) ; buf.type = 1 ; buf.data.time.hour = hour ; buf.data.time.minute = minute ; buf.data.time.second = second ; ret = cnc_settimer( &buf ) ; if ( ret == 5 ) printf( "Error while writing TIME.\n" ) ; } -----------------------------------------------------------------------------1.68 Read load information of serial spindle. <Main,Alarm> -----------------------------------------------------------------------------[Name] cnc_rdspload [Syntax] #include <data.h> #include <fwindow.h> short cnc_rdspload( short sp_no, struct odbspn *buf ) ; struct odbspn { short datano ; short type ; short data[2] ; } ; [Arguments] sp_no buf /* Spindle number. */ /* Not used. */ /* Spindle load data. */ Spindle number. Buffer in which the spindle load data are stored. [Return] EW_OK( 0) EW_NUMBER( 3) EW_NOOPT( 6) Successful. Incorrect spindle number "sp_no". The required option (Spindle serial output) is not added. [Description] Reads the load information of the serial spindle controlled by the CNC. This function is used for displaying the spindle load information by the application program, etc. Specify one of (1 or 2)(for one specified spindle) or -1 (for all spindles) in "sp_no" as spindle number. The spindle load information is stored in "buf.data" with binary format. In case that 1 or 2 is specified in "sp_no", the spindle load information is stored in data[0]. In case of -1 in "sp_no", data is stored in both data[0] and data[1]. The spindle load ratio (%) can be calculated from this value using the following expression. (This is conversion expression of the spindle load meter value displayed in the CNC screen.) Load ratio = buf.data / 32767 * (CNC parameter No.3127) [Example] The following program reads information about the load on the first spindle and displays the load ratio on the screen. #include <data.h> #include <fwindow.h> #include <stdio.h> short example( void ) { struct iodbpsd prm ; struct odbspn buf ; short ret ; long val ; cnc_rdparam( 4127, 1, 4+2*1, &prm ) ; ret = cnc_rdspload( 1, &buf ) ; if ( !ret ) { val = (long)buf.data[0] * prm.u.idata * 100 / 32767 ; printf( "Current spindle load value is %ld [%]\n", val ) ; } else printf( "ERROR!(%d)\n", ret ) ; return ( ret ) ; } -----------------------------------------------------------------------------1.69 Read executing program. <Main,Alarm> -----------------------------------------------------------------------------[Name] cnc_rdexecprog [Syntax] #include <fwindow.h> short cnc_rdexecprog( unsigned short *length, short *blknum , char *data ) ; [Arguments] length Size of the buffer for storing executing program, character number of read executing program. Number of buffered blocks. Buffer in which executing program text is stored (ASCII string). blknum data [Return] EW_OK( 0) EW_LENGTH( 2) Successful. Incorrect buffer size "length". [Description] Reads the contents of the NC program followig the currently executing block. This function is used for building the original screen like "Program Check Screen" of CNC, etc. Specify the byte-size of the buffer "data" for the storing executing program in "length". The contents of the currently executing NC program are stored in "data". The character length of read program is stored in "length". The number of buffered block including the current block is stored in "blknum". The typical bufferd block number is as follows. Operation mode Bufferd block number ----------------------------+--------------------Normal continuous mode. 2 Normal continuous mode with 3 Tool radius compensation C or Nose-R compensation. Single block mode. 1 The format of the read NC program is the following ASCII string. (Current block) LF (Next block) LF ... ... (Last block) LF % For example, while the following NC program is being executed, the next string is got by this function. * Executing NC program. O1234 ; N10 G0 X10. Y20. N20 G0 X20. Y30. N30 G0 X30. Y40. N40 G0 X40. Y50. M30 ; % Z30. Z40. Z50. Z60. ; ; ; ; <-- This function is called when this block is being executed. * String to be read. "N10G0X10.Y20.Z30.\n" "N20G0X20.Y30.Z40.\n" "N30G0X30.Y40.Z50.\n" "N40G0X40.Y50.Z60.\n" "M30\n" "%" In this case, 77 is returned in "length". Also 2 is returned in "blknum" during continuous operation. If buffer size is too small, the next string is got. * String to be read by this function (length=40). "N10G0X10.Y20.Z30.\n" "N20G0X20.Y30.Z40.\n" "N30" In this case, 39 is returned in "length". In case that M-code by which the prgram is rewinded to the top such as M02 or M30 is programmed in the tail of the NC program, the following string is returned while the block of M-code is being executed. "M30\n" "O1234\n" "...." <- Executing the last M-code. <- Leading part of the program. This is caused by the process of CNC. The CNC software rewinds the program when the NC program is read by this function. This function reads the contents of executing program only when the operating mode of CNC is "MEM" or "MDI". When the other mode, "length=0" and "blknum=0" are returned. [Example] The following program displays an NC program being currently executed on the screen. #include #include #include #include <data.h> <fwindow.h> <stdio.h> <conio.h> #define BUFLEN 200 void example( void ) { short ret, blknum ; unsigned short length, idx, lcount, num1, num2 ; char ch, data[BUFLEN] ; printf( "\033[2J\033[1;1H" ) ; printf( "< cnc_rdexecprog > press [CAN] to exit" ) ; for (;;) { length = BUFLEN ; ret = cnc_rdexecprog( &length, &blknum, data ) ; printf( "\033[2;1Hret=%2d length=%3u blknum=%d\n\n", ret, length, blknum ) ; if ( length ) printf( "\033[33;7m" ) ; lcount = num1 = num2 = 0 ; for ( idx = 0 ; idx < length ; idx++ ) { ch = data[idx] ; if ( ( ch == '\n' ) || ( ch == '%' ) ) { if ( ch == '\n' ) printf( " ;" ) ; else putchar( '%' ) ; printf( "\033[0m\033[K\n" ) ; lcount++ ; if ( lcount < blknum ) printf( "\033[33m" ) ; num1 = num2 = 0 ; } else { if ( ( ( ch >= '0' ) && ( ch <= '9' ) ) || ( ch == '.' ) || ( ch == '#' ) || ( ch == '+' ) || ( ch == '-' ) || ( ch == ']' ) ) num2 = 1 ; else num2 = 0 ; if ( ( num1 == 1 ) && ( num2 == 0 ) ) putchar( ' ' ) ; putchar( ch ) ; num1 = num2 ; } } if ( kbhit() ) { ch = getch() ; if ( ch == MDIKEY_CAN ) break ; } printf( "\033[J" ) ; } } -----------------------------------------------------------------------------1.70 Read manual handle override amount. <Main,Alarm> -----------------------------------------------------------------------------[Name] cnc_rdmovrlap [Syntax] #include <data.h> #include <fwindow.h> short cnc_rdmovrlap( short axis, short length, struct iodbovl *buf ) ; struct iodbovl short short long { datano ; type ; data[2][32] ; /* Not used. */ /* Axis number. */ /* Override amount. */ } ; [Arguments] axis length buf Axis number ( =-1:for only all axes). Data block length ( =4+4*32*2 ). Buffer in which the override amount are stored. [Return] EW_OK( 0) EW_LENGTH( 2) EW_ATTRIB( 4) EW_NOOPT( 6) Successful. Incorrect data block length "length". Incorrect axis number "axis". There are no required options (Manual handle override). [Description] Reads the manual handle override amount of the CNC controlled axis. This function is used for displaying the manual handle override amount of the CNC's axis by the application program, etc. Always specify -1 (all axes data) for the axis number in "axis", and 260 (=4+4*32*2) for the data block length in "length". The manual handle override amount is stored in "buf.data" with signed binary format. (The negative value is represented as 2's complement.) The override amounts of the (i+1)th axis both in the input unit and the output unit are stored in each data[0][i] and data[1][i]. The both are the same override amount though their units are different. The manual override amount is represented in one of the units listed below. data[0][0] - data[0][31] (Input unit) IS-B IS-C -------------------------------+---------------+--------------Linear axis (metric input) 0.001 [mm] 0.0001 [mm] Linear axis (inch input) 0.0001 [inch] 0.00001 [inch] Rotation axis 0.001 [deg] 0.0001 [deg] data[1][0] - data[1][7] (Output unit) IS-B IS-C -------------------------------+---------------+--------------Linear axis (metric output) 0.001 [mm] 0.0001 [mm] Linear axis (inch output) 0.0001 [inch] 0.00001 [inch] Rotation axis 0.001 [deg] 0.0001 [deg] The array size of each members of "iodbovl.data" is always 32 regardless of the amount of controlled axes. In case that the amount of controlled axes is less than 32, no data are stored in the members corresponding with the axes No. (amount of controlled axes + 1),..,32. [Example] Assume that each axis of a three-axis system has a manual override amount listed below: Input unit Output unit First axis 4.7246 120.005 Second axis -1.9732 -50.119 Third axis 0.0031 0.080 On the assumption stated above, the following program displays the values listed below (on the assumption that the inch input, metric output, and increment system conform to IS-B): 0: 47246 120005 1: -19732 -50119 2: 31 80 #include <data.h> #include <fwindow.h> #include <stdio.h> void example( void ) { struct iodbovl buf ; short idx; cnc_rdmovrlap ( -1, 260, &buf ) ; for ( idx = 0 ; idx < 3 ; idx ++ ) { printf ( "%d:%8ld %8ld\n", idx, buf.data[0][idx], buf.data[1][idx] ) ; } } 2. PMC window library -----------------------------------------------------------------------------2.1 Read arbitrary PMC data (range specified). <Main,Alarm> -----------------------------------------------------------------------------[Name] pmc_rdpmcrng [Syntax] #include <data.h> #include <fwindow.h> short pmc_rdpmcrng( short adr_type, short data_type, short s_number, short e_number, short length, struct iodbpmc *buf ) ; struct iodbpmc short short short short union { } u ; { type_a ; type_d ; datano_s ; datano_e ; /* /* /* /* char short long /* PMC data (Byte) */ /* (Word) */ /* (2-Word) */ number of data to be read. */ cdata[N] ; idata[N] ; ldata[N] ; /* N is Kind of PMC address. */ Type of PMC data. */ Start PMC address. */ End PMC address. */ } ; [Arguments] adr_type data_type s_number e_number length buf Kind of PMC address. Type of PMC data. Start PMC address. End PMC address. Data block length ( =8+(byte size of data)*(number of data to be read)). Buffer in which the PMC data are stored. [Return] EW_OK( 0) EW_LENGTH( 2) EW_NUMBER( 3) EW_ATTRIB( 4) Successful. Incorrect data block length "length". Incorrect PMC address "s_number" or "e_number". Incorrect kind of PMC address "adr_type" or type of PMC data "data_type". [Description] Reads the PMC data within the specified address range. This function is used for exchanging various data between the C application and the PMC ladder software. Specify the discrimination code corresponding to the PMC address to be read in "adr_type". The discrimination code is either a binary numeric value of 0,..,9 or an alphabetic character such as 'G' or 'R', etc. (described later) Specify the type of PMC data to be read in "data_type" with binary format. data_type Type of PMC data Byte size ---------------+-----------------------+-------------0 Byte type 1 1 Word type 2 2 2-Word type 4 Specify the start PMC address in "s_number" and the end one in "e_number" with binary format. The read data are stored in one of "buf.u.cdata[i]", "buf.u.idata[i]" or "buf.u.ldata[i]" according to its type. The data format is same as the one in the PMC. The data format of Timer (T0000-T0079) is as follows. Timer number Unit ---------------+---------T0000 - T0007 48 [msec] T0008 - T0079 8 [msec] For example, when 800 [msec] is set in T0010, 100 is read by this fucntion. Example of arguments specification ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ (1) Reading "D0100" (Word type data). adr_type 9 or 'D' data_type 1 s_number 100 e_number 101 length 8+2*1 (=10) buf.u.idata[0] Content of "D0100" will be stored. (2) Reading "R0200" through "R0209" (Byte type data). adr_type 5 or 'R' data_type 0 s_number 200 e_number 209 length 8+1*10 (=18) buf.u.cdata[0] Contents of "R0200",..,"R0209" will be stored. ,..,buf.u.cdata[9] The referenceable range of PMC data of FANUC Series 30i ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ I.D. code Kind of PMC address ---------------+----------------------0,'G' G (PMC->CNC) 1,'F' F (CNC->PMC) 2,'Y' Y (PMC->Machine) 3,'X' X (Machine->PMC) 4,'A' A (Message request) 5,'R' R (Relay) 6,'T' T (Timer) 7,'K' K (Keep relay) 8,'C' C (Counter) 9,'D' D (Data table) (Note 1) It is not "R9000 to written. (Note 2) Addresses addresses possible to write to all areas of address 'F' and 'X', and R9099", "R9118 to R9199", and "K0017 to K0019" must not be G1xxx and F1xxx are an I/O area for the second path, and G2xxx and F2xxx, for third path. [Example] The following program reads and displays the feed rate override value (G0012). #include <data.h> #include <fwindow.h> #include <stdio.h> void example( void ) { unsigned short fov ; struct iodbpmc buf ; pmc_rdpmcrng( 'G', 0, 12, 12, 8+1*1, &buf ) ; fov = (unsigned char)~buf.u.cdata[0] ; printf( "Current feedrate override is %u[%].\n", fov ) ; } -----------------------------------------------------------------------------2.2 Write arbitrary PMC data (range specified). <Main,Alarm> -----------------------------------------------------------------------------[Name] pmc_wrpmcrng [Syntax] #include <data.h> #include <fwindow.h> short pmc_wrpmcrng( short length, struct iodbpmc *buf ) ; struct iodbpmc short short short short union { { type_a ; type_d ; datano_s ; datano_e ; char short long } u ; cdata[N] ; idata[N] ; ldata[N] ; /* N is number /* /* /* /* Kind of PMC address. */ Type of PMC data. */ Start PMC address. */ End PMC address. */ /* PMC data (Byte) */ /* (Word) */ /* (2-Word) */ of data to be written. */ } ; [Arguments] length buf Data block length ( =8+(byte size of data)*(number of data to be written) ). Buffer in which the PMC data are stored. [Return] EW_OK( 0) EW_LENGTH( 2) EW_NUMBER( 3) EW_ATTRIB( 4) Successful. Incorrect data block length "length". Incorrect PMC address "buf.datano_s" or "buf.datano_e". Incorrect kind of PMC address "buf.type_a" or type of PMC data "buf.type_d". [Description] Writes the PMC data within the specified address range. This function is used for exchanging various data between the C application and the PMC ladder software. Specify the discrimination code corresponding to the PMC address to be written in "buf.type_a". The discrimination code is either a binary numeric value of 0,..,9 or an alphabetic character such as 'G' or 'R', etc. (See "Read arbitrary PMC data (range specified)(pmc_rdpmcrng)") Specify the type of PMC data to be written in "buf.type_d" with binary format. data_type Type of PMC data Byte size ---------------+-----------------------+-------------0 Byte type 1 1 Word type 2 2 2-Word type 4 Specify the start PMC address in "buf.datano_s" and the end one in "buf.datano_e" with binary format. Store the written data in one of "buf.u.cdata[i]", "buf.u.idata[i]" or "buf.u.ldata[i]" according to its type. The data format is same as the one in the PMC. The data format of Timer (T0000-T0079) is as follows. Timer number Unit ---------------+---------T0000 - T0007 48 [msec] T0008 - T0079 8 [msec] For example, when you want to set 800 [msec] in T0010, specify 100 in this fucntion. It is inhibited to write to the all data of address 'F' and 'X', "R9000",..,"R9099", "R9118",..,"R9199" and "K0017",..,"K0019". (Writing data to address 'F' results in a write occurring to the 'F' area of the CNC rather than that of the PMC.) Refer "The referenceable range of PMC data of FANUC Series 16/18" of "Read arbitrary PMC data (range specified)(pmc_rdpmcrng)" for writable address, etc. (Caution) When this function is used to write PMC data, it does not perform exclusive control for the PMC ladder. When both an application program and PMC ladder are expected to write to the same PMC address, therefore, the application program must perform exclusive control. When writing to a PMC address especially bit by bit, you should avoid allowing both program entities to write simultaneously. This is because the NC and PMC processors operate asynchronously to each other. Example of arguments specification ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ (1) Writing 250 to "D0100" (Word type data). buf.type_a 9 or 'D' buf.type_d 1 buf.datano_s 100 buf.datano_e 101 length 8+2*1 (=10) buf.u.idata[0] 250 (2) Writing 0 to every "R0200" through "R0209" (Byte type data). buf.type_a 5 or 'R' buf.type_d 0 buf.datano_s 200 buf.datano_e 209 length 8+1*10 (=18) buf.u.cdata[0] all 0 ,..,buf.u.cdata[9] [Example] The following program sets the specified bit of a specified internal relay (R) to "1". #include <data.h> #include <fwindow.h> #include <stdio.h> /* number is index number of R. */ /* bit is target bit index to be set. */ short example( short number, short bit ) { short ret ; struct iodbpmc buf ; ret = pmc_rdpmcrng( 'R', 0, number, number, 8+1*1, &buf ) ; if ( !ret ) { buf.u.cdata[0] |= ( 1 << bit ) ; ret = pmc_wrpmcrng( 8+1*1, &buf ) ; } return ( ret ) ; } -----------------------------------------------------------------------------2.3 Read PMC message. <Main,Alarm> -----------------------------------------------------------------------------[Name] pmc_rdpcmsg [Syntax] #include <data.h> #include <fwindow.h> short pmc_rdpcmsg( unsigned short adr_no, unsigned short adr_bit, struct pmcmsg *buf ) ; struct pmcmsg { unsigned short unsigned char msg_len ; /* Length of message. */ pmc_msg[256] ; /* PMC message string. */ } ; [Arguments] adr_no adr_bit buf PMC address A. ( =0 - 24 ) Bit of PMC address A. ( =0 - 7 ) Buffer in which PMC message is stored. [Return] EW_OK( 0) EW_NUMBER( 3) EW_ATTRIB( 4) EW_DATA( 5) Successful. Incorrect PMC address A. Incorrect bit of PMC address A. No message for specified address. [Description] Reads the specified PMC message data. This function reads the corrsponding message to the specified PMC address A and bit number. Specify the number of address A in "adr_no" with binary format. Specify the bit number 0 - 7 in "adr_bit" with binary format. The PMC message is stored in "buf.pmc_msg". The PMC message is the ASCII string as same as one which is displayed in the CNC's alarm message screen. The 2-byte character such as Japanese Kanji character is stored by Shift-JIS code. A 'null' character ('\x00') is added at the end of the string. The length of the string stored in "buf.pcm_msg" is stored in "buf.msg_len" with binary format. [Example] The following program reads all PMC message character strings and displays them on the screen. #include #include #include #include <data.h> <fwindow.h> <stdio.h> <stdlib.h> void example( void ) { short ret ; unsigned short idx, bit ; struct pmcmsg *buf ; buf = (struct pmcmsg *)malloc( sizeof( struct pmcmsg ) ) ; for ( idx = 0 ; idx <= 24 ; idx++ ) { for ( bit = 0 ; bit <= 7 ; bit++ ) { ret = pmc_rdpcmsg( idx, bit, buf ) ; if ( !ret ) printf( "A%02u.%u \"%s\"\n", idx, bit, buf->pmc_msg ) ; } } free( buf ) ; } 3.5 MDI operation library ========================= Library outline ~~~~~~~~~~~~~~~ 1. Outline The application program can control the MDI-KEY using the MDI operation library. 2. MDI key matrix (1) Structure of matrix MDI key matrix is a table where the relationship of the MDI key bit matrix which is defined by the hardware specification and the key attributes and the key code is defined. This is referenced to convert the MDI key bit matrix data read from MDI panel into key code for the application program. The MDI Key matrix consists of the key function table which defines key attributes and the key code table which defines key codes. There are both matrix for the user application program and one for CNC software. The relationship of the MDI key bit matrix and the MDI key matrix is as follows. MDI key bit Function flag Key code matrix table table ---------------+---------------+------------0th byte 0th bit 0th byte 0th word 1st bit 1st byte 1st word : : : 7th bit 7th byte 7th word : : : n-th byte m-th bit (n*8+m)-th byte (n*8+m)-th word Each words of the key code table include both "Main code" and "Sub code". Upper byte Lower byte Main code Sub code Code generated by pushing individually. Code generated by pushing next to the SHIFT key. It is impossible to push the SHIFT key and any ordinary keys simultaneously. To input sub code, operate as following sequence. Push the SHIFT key, and then release it. Push any ordinary key. (2) Structure of function flag The function flag is one byte flag which defines attributes of key for every key. This flag defines following items bit by bit. Bit Symbol definition -------+-------+---------------------------------------------------7 F Enabling/disabling key repeat. (effective when FUNC=0000) 0: Disable key repeat. 1: Enable key repeat. 6 - 5 OUT Destination of key code. (effective when FUNC=0000) 00: Screen selected side. (default setting) 01: Always C application. 10: Always CNC software. 11: Both c application and CNC software. (for only "RESET" key) 4 S Enabling/disabling SHIFT key. (effective when FUNC=0000) 0: Enable SHIFT key. 1: Disable SHIFT key. 3 - 0 FUNC Kind of key. 0000: Ordinary key. 1011: SHIFT key. 1111: Invalid key. Others: Not used. (These are handled as same as ordinary keys.) (3) Uppercase/Lowercase There is no special key to select uppercase/lowercase of alphabetic character on MDI panel of CNC. Usually, all alphabetic characters are input as uppercase characters. Lowercase characters can be input by the following operation. Operation Input mode -----------------------+---------------------SHIFT + Cursor[UP] Uppercase (default) SHIFT + Cursor[DOWN] Lowercase Call "aux_mdi_contrl" function to enable this operation. aux_mdi_control( MDI_CASE_ON ) aux_mdi_control( MDI_CASE_OFF ) Enable changing uppercase/lowercase. Disable changing uppercase/lowercase. The initial status is "disabled changing uppercase/lowercase". This function is made ineffective by altering MDI key matrix of "Cursor[UP]" or "Cursor[DOWN]". Only uppercase characters are always input to the CNC software regardless of this operation. Also "Key input by application program" described in next section isn't influenced by this operation. 3. Key input by application program (1) Functions The application program can send an arbitrary character or string to the key input buffer of the MDI-KEY by calling following functions. aux_mdi_putc() aux_mdi_write() Output one character. Output a string. These character and string are received regardless of any operation to the screen or MDI panel. (2) Arguments The application program sends a pair of the function flag and the key code to be output to the above functions. The format of the function flag is same as the MDI key matrix. Any arbitrary value is allowed to be specified for key code. Also any key code which isn't registered in the standard key matrix. (It is possible to send a key code as a message from any auxiliary task to the main task.) (3) Relation to the MDI panel The key input from the application program is handled more preferentially than one from the MDI panel. Therefore, when any key is input from both the application and the MDI panel simultaneously, the former is given to the software. Usually, inhibit the key input from the MDI panel during inputting key from the application program using following functions. aux_mdi_control( MDI_LOK_PNL ) Disable key input from the MDI panel. aux_mdi_control( MDI_ULK_PNL ) Enable key input from the MDI panel. Only RESET key is accepted during being inhibited key input from the MDI panel. 4. MDI key control in case that both C Executor and Open-CNC or Intelligent Terminal exist. When one of Open-CNC or Intelligent Terminal is present, MDI key data is processed as follows. (A) When Open-CNC is present. MDI operation library of C Library can handle only key information input to C User application. C User application can execute all MDI operation library functions. However, only operations for the key inputting to the user application is effective. It is impossible to operate key inputting information to the CNC software by specifying MAIN_MDI_MATRIX for each function. (No error is issued.) The Open-CNC application execute the operations for key inputting information to the CNC software and the Open-CNC application software. (B) When Intelligent Terminal is present. It is impossible to handle key inputting for C User application on the system with Intelligent Terminal. C User application can execute all MDI operation library functions. However, all functions do nothing when they are called. (No error is issued.) The Intelligent Terminal application execute all of the operations for key inputting information. Lists of Functions ~~~~~~~~~~~~~~~~~~ ---------------------------------------------------------------------Name Function ---------------------------------------------------------------------1. aux_mdi_getmatrix Get MDI key matrix. 2. aux_mdi_putmatrix Put MDI key matrix. 3. aux_mdi_rstmatrix Reset MDI key matrix. 4. aux_mdi_altmatrix Alter MDI key matrix. 5. aux_mdi_putc Put one character to key input buffer. 6. aux_mdi_write Write block data to key input buffer. 7. aux_mdi_control Test or control key input buffer. 8. aux_mdi_repeat Set key repeating interval time. 9. aux_mdi_getstat Read inputting status of MDI key. 10. aux_mdi_clrbuf Clear input buffer of MDI key. ---------------------------------------------------------------------[CAUTION] Use "aux_mdi_getmatrix" and "aux_mdi_putmatrix" functions in case that you must needs them anyway. These functions are very flexible, but very dangerous if you mistake those usage. Function Reference ~~~~~~~~~~~~~~~~~~ -----------------------------------------------------------------------------1. Get MDI key matrix. <Main,Alarm> -----------------------------------------------------------------------------[Name] aux_mdi_getmatrix [Syntax] #include <bios.h> int aux_mdi_getmatrix( void *matrix_ptr, int matrix_len, int module_id ) ; [Arguments] matrix_ptr matrix_len module_id Buffer in which key matrix is stored. Byte size of key matrix buffer. Class of matrix. [Return] 0 -1 Successful. Incorrect byte size of key matrix buffer "matrix_len". Or incorrect class of matrix "module_id". [Description] Reads the current key matrix (function flag table and key code table) of MDI key, and stores them in the specified buffer. This function is used to read the original key matrix for altering the part of the key matrix. Specify pointer to the matrix buffer area in "matrix_ptr". Specify byte size of key matrix area buffer. Specify one of following matrix class. module_id Matrix class -----------------------+-------------------------------MAIN_MDI_MATRIX Matrix of CNC software MMC_MDI_MATRIX Matrix of application program Get the required table size of the key matrix before calling this function, and allocate buffer area for reading. -----------------------------------------------------------------------------2. Put MDI key matrix. <Main,Alarm> -----------------------------------------------------------------------------[Name] aux_mdi_putmatrix [Syntax] #include <bios.h> int aux_mdi_putmatrix( void *matrix_ptr, int matrix_len, int module_id ) ; [Arguments] matrix_ptr matrix_len module_id Buffer in which key matrix is stored. Byte size of key matrix buffer. Class of matrix. [Return] 0 -1 Successful. Incorrect byte size of key matrix buffer "matrix_len". Or incorrect class of matrix "module_id". [Description] Registers the specified key matrix as the new matrix. This function is used to restore the modified key matrix. Specify pointer to the matrix buffer area in "matrix_ptr". Specify byte size of key matrix area buffer. Specify one of following matrix class. module_id Matrix class -----------------------+-------------------------------MAIN_MDI_MATRIX Matrix of CNC software MMC_MDI_MATRIX Matrix of application program This function is very dangerous. If there are any mistakes in the specified key matrix, the key inputting process may not work correctly. Take care to use this function. All keys can be customized by this function. But you should not customize the important key for CNC operation such as RESET key. -----------------------------------------------------------------------------3. Reset MDI key matrix. <Main,Alarm> -----------------------------------------------------------------------------[Name] aux_mdi_rstmatrix [Syntax] #include <bios.h> int aux_mdi_rstmatrix( int module_id ) ; [Arguments] module_id Class of matrix. [Return] 0 Negative Successful. Incorrect class of matrix "module_id". [Description] Restore the MDI key matrix to the initial (power-on) setting. This function is used to restore te MDI key matrix which is modified by "aux_mdi_putmatrix" function to the initial setting. Specify one of following matrix class. module_id Matrix class -----------------------+-------------------------------MAIN_MDI_MATRIX Matrix of CNC software MMC_MDI_MATRIX Matrix of application program -----------------------------------------------------------------------------4. Alter MDI key matrix. <Main,Alarm> -----------------------------------------------------------------------------[Name] aux_mdi_altmatrix [Syntax] #include <bios.h> int aux_mdi_altmatrix( int module_id, int category, int update ) ; [Arguments] module_id category update Class of matrix. Kind of key to be altered. New specification. [Return] 0 Positive -1 -2 -3 -4 -5 -6 -7 Successful (No alteration was applied.). Successful ("Positive" is number of applied alteration.). Incorrect class of matrix "module_id". Incorrect kind of key to be altered "category". Incorrect new specification "update". Incorrect "MDI_SHIFT_xx" specification. Incorrect "MDI_TO_xx" specification. Incorrect "MDI_REPEAT_xx" specification. Attempted to alter the RESET key. [Description] Alters character code or character attribute which is assigned to the specified MDI key. This function is used to alter character code assigned to the key or to enable automatic key repeating of the cursor key or the page key, etc. Specify one of following matrix class. The specified matrix will be altered. module_id Matrix class -----------------------+-------------------------------MAIN_MDI_MATRIX Matrix of CNC software MMC_MDI_MATRIX Matrix of application program (1) Altering character code. Replaces the specified code in the current matrix with the new code. When there are multiple specified codes in the matrix, all codes are replaced. This alteration can't be executed with alteration of character attribute simultaneously. Specify "MDI_ALT_CODE" (altering character code) in "category". Specify updating specification of key in "update". upper byte of "update" <- current code lower byte of "update" <- new code The specified key is set as "invalid key" by specifying "NULL(0x00)" as new code. It is impossible to alter the RESET key. (2) Altering character attribute. Alters the attribute of the specified key in the current matrix. This alteration can't be executed with replacement of character code simultaneously. Specify kind of key to be altered in "category". All keys are classified into the following category by the "main character code". category Kind of key Character code ---------------+----------------+-------------MDI_ALT_ALPH Alphanumeric key 0x20,..,0x7F MDI_ALT_CURS Cursor key 0x88,..,0x8B MDI_ALT_PAGE Page key 0x8E,..,0x8F MDI_ALT_DELE DELETE key 0x08, 0x95 MDI_ALT_INPT INPUT key 0x0D, 0x94 MDI_ALT_REST RESET key 0x90 MDI_ALT_HELP HELP key 0x9A MDI_ALT_FUNC Function key 0xE1,..,0xE7 MDI_ALT_SOFT Soft key 0xF0,..,0xFF The multiple classes can be specified simultaneously in "category". Specify the following control attribute in "update". The multiple attributes can be specified simultaneously. The non-specified attributes is kept as it is. (1) Enable/disable shift function. MDI_SHIFT_OK Enable shift function. MDI_SHIFT_NO Disable shift function. (2) Enable/disable automatic key repeating. MDI_REPEAT_OK Enable automatic key repeating. MDI_REPEAT_NO Disable automatic key repeating. (3) Specify software which can read MDI key. MDI_TO_ETHER Either CNC software or application program according to the current displayed screen. MDI_TO_MMC Application program. MDI_TO_MAIN CNC software. MDI_TO_BOTH Both CNC software and application program. (Note) It is impossible to set the RESET key being inhibited to be read by CNC software. -----------------------------------------------------------------------------5. Put one character to key input buffer. <Main,Alarm> -----------------------------------------------------------------------------[Name] aux_mdi_putc [Syntax] #include <bios.h> int aux_mdi_putc( int c ) ; [Arguments] c Output data. [Return] 1 0 Successful. Key input buffer is full. [Description] Output the specified 1-byte character to the key input buffer. Specify a function in the lower byte. upper byte lower byte flag in the upper byte of "c" and a character code For example, specify as follows to output 'A'. <- 0x20 (function flag) <- 0x41 (character code) This function outputs data to the key input buffer. Check buffer emptiness by calling "aux_mdi_control" function to confirm completion of outputting data from the buffer. -----------------------------------------------------------------------------6. Write block data to key input buffer. <Main,Alarm> -----------------------------------------------------------------------------[Name] aux_mdi_write [Syntax] #include <bios.h> int aux_mdi_write( void *buffer, int size ) ; [Arguments] buffer size [Return] Positive 0 Buffer in which the output data are stored. Byte size of output data. Successful. (Byte size of actually output data.) This value will be smaller than the specified size in case that there are not enough room for specified size in the key input buffer. Key input buffer is full. [Description] Output data for specified byte size from the specified buffer to the key input buffer. Store the output data in output order in "buffer". The format of each output data is same as "aux_mdi_putc" function. Specify one character by 2 bytes. (upper byte: function flag, lower byte: character code) This function outputs data to the key input buffer. Check buffer emptiness by calling "aux_mdi_control" function to confirm completion of outputting data from the buffer. -----------------------------------------------------------------------------7. Test or control key input buffer. <Main,Alarm> -----------------------------------------------------------------------------[Name] aux_mdi_control [Syntax] #include <bios.h> int aux_mdi_control( int control ) ; [Arguments] control Control code. [Return] (1) In case of successful. MDI_CHK_BUF Returns MDI_GET_MTXLEN Returns MDI_CASE_ON Returns MDI_CASE_OFF Returns MDI_CHK_FKEY Returns Others Returns number of data in the buffer. byte size of MDI key matrix. the previous status. the previous status. the key code of pushed function key. "0". (2) In case of error. Returns "-1" for all instructions. [Description] Test the key input buffer, or execute specified operation to the key input buffer. Specify one of the following control code in "control". control Operation ---------------+-------------------------------------------MDI_CHK_BUF Returns number of data in the application key input buffer. MDI_CLR_BUF Clears the application key input buffer. MDI_LOK_PNL Locks MDI key input except RESET key. MDI_ULK_PNL Unlocks MDI key input. MDI_GET_MTXLEN Return byte size of the MDI key matrix table. MDI_CASE_ON Enables uppercase/lowercase character input from the MDI panel. MDI_CASE_OFF Disables uppercase/lowercase character input from the MDI panel. MDI_CHK_FKEY If the screen switching was disabled while any user screen was displaying for some reason and any function key was pushed during disabling screen switching, returns key code of that function key. Returns 0 if no function key was pushed while the screen switching was disabled. -----------------------------------------------------------------------------8. Set key repeating interval time. <Main,Alarm> -----------------------------------------------------------------------------[Name] aux_mdi_repeat [Syntax] #include <bios.h> int aux_mdi_repeat( int delay, int repeat ) ; [Arguments] delay repeat Delay time of automatic repeating. Interval time of automatic repeating. [Return] 0 -1 -2 Successful. Incorrect delay time "delay". Incorrect interval time "repeat". [Description] Set the delay time and the interval time of automatic key repeating. Specify one of the following delay times in "delay". delay Delay time -----------------------+-----------------------MDI_KEY_DELAY1 256 [msec] (default setting) MDI_KEY_DELAY2 512 [msec] MDI_KEY_DELAY3 768 [msec] MDI_KEY_DELAY4 1024 [msec] Specify the interval time 32 through 1024 [msec] in "repeat" with binary format. The unit of the interval time is "millisecond". Only multiple of "32[msec]" are allowed to set. The default setting value of the interval time is "MDI_KEY_REPEAT" (32[msec]). -----------------------------------------------------------------------------9. Read inputting status of MDI key. <Main,Alarm> -----------------------------------------------------------------------------[Name] aux_mdi_getstat [Syntax] #include <bios.h> unsigned int aux_mdi_getstat( void ) ; [Arguments] -----[Return] Returns inputting status of MDI key. [Description] Gets the inputting status of MDI key. Each bits of returned value mean following information. bit0 bit1 - bit7 bit8 - bit15 SHIFT state. (MDI_ST_SHIFT) 0: Not SHIFT state. 1: SHIFT state. Undefined. Number of characters read in the MDI key input buffer. "SHIFT state" means the following state. Once push [SHIFT] key, and then release it. v <- This period is "SHIFT state". Push any other key. (Sub code is read in this case.) That is, once pushing [SHIFT] key makes "SHIFT state" ON, then, pushing any other key makes "SHIFT state" released. Pushing [SHIFT] key again during "SHIFT state" makes "SHIFT released. It is impossible to input Sub code by pushing any key and [SHIFT] key simultaneously. Bit8 through bit15 of return value indicate a number of characters input from the MDI panel and not read yet by the application program. This function gets the status of key input buffer while the C Executor's user screen is being displayed. It can't get the status of the key input buffer of the CNC software. [Example] The following program reads a line of alpha-numeric characters from the MDI panel. Inputting operation is completed by inputting [INPUT] key. It displays one of '_' (in normal state) and '^' as cursor. #include <bios.h> #include <ctype.h> #include <stdio.h> #define BUFSIZE 80 unsigned char buf[BUFSIZE] ; void example( void ) { unsigned int idx = 0, stat = 0 ; unsigned char ch ; printf( "\033[>5h_" ) ; for (;;) { if ( kbhit() ) { ch = getch() ; if ( ch == MDIKEY_INPUT ) { buf[idx] = 0x00 ; return ; } else if ( ( ch == MDIKEY_CAN ) && idx ) { buf[--idx] = 0x00 ; printf( "\010 \010\010_" ) ; stat = 0 ; } else if ( isalnum( ch ) && ( idx < BUFSIZE - 1 ) ) { buf[idx++] = ch ; printf( "\010%c_", ch ) ; stat = 0 ; } } else { if ( aux_mdi_getstat() & MDI_ST_SHIFT ){ if ( !( stat & MDI_ST_SHIFT ) ) { printf( "\010^" ) ; stat = MDI_ST_SHIFT ; } } else if ( stat & MDI_ST_SHIFT ) { printf( "\010_" ) ; stat = 0 ; } } } } -----------------------------------------------------------------------------10. Clear input buffer of MDI key. <Main,Alarm> -----------------------------------------------------------------------------[Name] aux_mdi_clrbuf [Syntax] #include <bios.h> void aux_mdi_clrbuf( void ) ; [Arguments] -----[Return] -----[Description] Clears input buffer of MDI key. This function clears all characters which are input from MDI panel and not read by the application program yet, and makes "SHIFT state" at the same time. This function makes no effects to the key input buffer of the CNC software. Key code table ~~~~~~~~~~~~~~ The following are the key code table of various keyboard which are supported by C Executor. Lines and columns of "Key bit matrix", "Key function flag table" and "Key code table" are correspond each other in every keyboard. For example, to get key code and function flag for C application of "X" key in the machining system's full key, search as follows. (1) Search "X" key in "Key bit matrix". (7th line, 4th column) (2) See the 7th line and 4th column of "Key function flag table" and "Key code table" for C application. (3) You get 0x10 for key function flag and "58 55" for key code. This means that a code 0x58 will be generated by pushing "X" key individually, and 0x55 by pushing SHIFT + "X". To change this function flag and key code, do as follows. (1) Get the matrix by "aux_mdi_getmatrix" function. (2) Change the function flag in 0x3D from the top of the matrix and the key code in 0xC8 and 0xC9. (3) Restore the matrix by "aux_mdi_putmatrix" function. "F0-F9,FL,FR" mean SOFT key. 10-SOFT key type (14inchCRT) [FL] [F0][F1][F2][F3][F4] [F5][F6][F7][F8][F9] [FR] Reading extension MDI keys ~~~~~~~~~~~~~~~~~~~ Setting bit 2 (EKY) of parameter No. 8650 in the NC to 1 causes the key BIOS of the C executor to scan the extension MDI keys. If a user application assigns key codes to the extension of the key matrix, the assigned keys can be read. (If no key code is specified, it is impossible to read the extension keys.) Key bit matrix 0 1 2 3 4 5 6 7 +---+---+---+---+---+---+---+---+ Line 0 | | | | | | | | | 1 | | | | | | | | | 2 | | | | | | | | | 3 | | | | | | | | | 4 | | | | | | | | | --> Normally scanned range 5 | | | | | | | | | 6 | | | | | | | | | 7 | | | | | | | | | 8 | | | | | | | | | +---+---+---+---+---+---+---+---+ 9 | | | | | | | | | A | | | | | | | | | --> Extension B | | | | | | | | | +---+---+---+---+---+---+---+---+ Rows A and B are added to the matrix. 1. 30i QWERTY MDI Key bit matrix bit= 0 1 2 3 4 5 6 7 +------+------+------+------+------+------+------+------+ 0 | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | +------+------+------+------+------+------+------+------+ 1 | 8 | 9 | - + | . , | CTRL |DELETE| EOB | ALT | +------+------+------+------+------+------+------+------+ 2 |ALTER |INSERT| ABC |INPUT | HELP |SHIFT | → | ← | +------+------+------+------+------+------+------+------+ 3 |POSITN|PROGRM|OFFSET|SYSTEM|MESSAG|GRAPH |CUSTM1|CUSTM2| +------+------+------+------+------+------+------+------+ 4 | ↓ | ↑ |Page↓|Page↑| F ; | D _ | H " | B / | +------+------+------+------+------+------+------+------+ 5 | FL | F9 | F8 | F7 | AUX | | SKV9 | RESET| +------+------+------+------+------+------+------+------+ 6 | F6 | F5 | F4 | F3 | F2 | F1 | F0 | FR | +------+------+------+------+------+------+------+------+ 7 | O ) | N ? | G : | P \ | X | Y & | Z | Q ! | +------+------+------+------+------+------+------+------+ 8 | I ( | J ' | K [ | R $ | M SP| S ~ | T % | L ] | +------+------+------+------+------+------+------+------+ 9 | A | C < | E # | U * | V > | W @ | TAB | CAN | +------+------+------+------+------+------+------+------+ A | ---- | ---- | ---- | ---- | ---- | ---- | ---- | ---- | +------+------+------+------+------+------+------+------+ B | SKV8 | SKV7 | SKV6 | SKV5 | SKV4 | SKV3 | SKV2 | SKV1 | +------+------+------+------+------+------+------+------+ Key function flag table for CNC +0 +1 +2 +3 +4 +5 +6 +7 ----+------+------+------+------+------+------+------+-----00 | 10 10 10 10 10 10 10 10 08 | 10 10 10 10 10 10 10 10 10 | 0D 10 10 10 10 0B 10 10 18 | 10 10 10 10 10 10 10 10 20 | 10 10 10 10 10 10 10 10 28 | 00 00 00 00 10 0F 00 60 30 | 00 00 00 00 00 00 00 00 38 | 10 10 10 10 10 10 10 10 40 | 10 10 10 10 10 10 10 10 48 | 10 10 10 10 10 10 10 10 50 | 0F 0F 0F 0F 0F 0F 0F 0F 58 | 00 00 00 00 00 00 00 00 Key code table for CNC +0 +2 +4 +6 +8 +A +C +E ----+------+------+------+------+------+------+------+-----60 | 30 3D 31 82 32 83 33 8C 34 8D 35 A9 36 00 37 00 70 | 38 AA 39 AB 2D 2B 2E 2C 9B 9B 95 95 0A 0A 97 97 80 | 96 99 94 94 9C 9C 98 98 9A 9A 84 85 88 88 89 89 90 | E8 E1 E9 E1 EA E1 EB E1 EC E1 ED E1 EE E1 EF E1 A0 | 8A FB 8B FD 8E 8E 8F 8F 46 3B 44 5F 48 22 42 2F B0 | 00 00 00 00 00 00 00 00 E4 E4 00 00 00 00 90 90 C0 | 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 D0 | 4F 29 4E 3F 47 3A 50 5C 58 00 59 26 5A 00 51 21 E0 | 49 28 4A 27 4B 5B 52 24 4D 20 53 7F 54 25 4C 5D F0 | 41 00 43 3C 45 23 55 2A 56 3E 57 40 09 09 86 87 100 | 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 110 | 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 Key function flag table for C application +0 +1 +2 +3 +4 +5 +6 +7 ----+------+------+------+------+------+------+------+-----00 | 10 10 10 10 10 10 10 10 08 | 10 10 10 10 10 10 10 10 10 | 0D 10 10 10 10 0B 10 10 18 | 10 10 10 10 10 10 10 10 20 | 10 10 10 10 10 10 10 10 28 | 00 00 00 00 10 0F 00 60 30 | 00 00 00 00 00 00 00 00 38 | 10 10 10 10 10 10 10 10 40 | 10 10 10 10 10 10 10 10 48 | 10 10 10 10 10 10 10 10 50 | 0F 0F 0F 0F 0F 0F 0F 0F 58 | 00 00 00 00 00 00 00 00 Key code table for C application +0 +2 +4 +6 +8 +A +C +E ----+------+------+------+------+------+------+------+-----60 | 30 3D 31 82 32 83 33 8C 34 8D 35 A9 36 00 37 00 70 | 38 AA 39 AB 2D 2B 2E 2C 9B 9B 95 95 0A 0A 97 97 80 | 96 99 94 94 9C 9C 98 98 9A 9A 84 85 88 88 89 89 90 | E8 E1 E9 E1 EA E1 EB E1 EC E1 ED E1 EE E1 EF E1 A0 | 8A FB 8B FD 8E 8E 8F 8F 46 3B 44 5F 48 22 42 2F B0 | 00 00 00 00 00 00 00 00 E4 E4 00 00 00 00 90 90 C0 | 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 D0 | 4F 29 4E 3F 47 3A 50 5C 58 00 59 26 5A 00 51 21 E0 | 49 28 4A 27 4B 5B 52 24 4D 20 53 7F 54 25 4C 5D F0 | 41 00 43 3C 45 23 55 2A 56 3E 57 40 09 09 86 87 100 | 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 110 | 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 2. 30i ONG MDI (M series) Key bit matrix bit= 0 1 2 3 4 5 6 7 +------+------+------+------+------+------+------+------+ 0 | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | +------+------+------+------+------+------+------+------+ 1 | 8 | 9 | - | ・ | CTRL |DELETE| EOB | ALT | +------+------+------+------+------+------+------+------+ 2 |ALTER |INSERT| ABC |INPUT | HELP |SHIFT | → | ← | +------+------+------+------+------+------+------+------+ 3 |POSITN|PROGRM|OFFSET|SYSTEM|MESSAG|GRAPH |CUSTM1|CUSTM2| +------+------+------+------+------+------+------+------+ 4 | ↓ | ↑ |Page↓|Page↑| F [ | D ] | H & | B SP | +------+------+------+------+------+------+------+------+ 5 | FL | F9 | F8 | F7 | AUX | | SKV9 | RESET| +------+------+------+------+------+------+------+------+ 6 | F6 | F5 | F4 | F3 | F2 | F1 | F0 | FR | +------+------+------+------+------+------+------+------+ 7 | O ( | N ) | G E | P C | X U | Y V | Z W | Q ? | +------+------+------+------+------+------+------+------+ 8 | I , | J A | K @ | R _ | M # | S = | T * | L + | +------+------+------+------+------+------+------+------+ 9 | | | | | | / | TAB | CAN | +------+------+------+------+------+------+------+------+ A | ---- | ---- | ---- | ---- | ---- | ---- | ---- | ---- | +------+------+------+------+------+------+------+------+ B | SKV8 | SKV7 | SKV6 | SKV5 | SKV4 | SKV3 | SKV2 | SKV1 | +------+------+------+------+------+------+------+------+ Key function flag table for CNC +0 +1 +2 +3 +4 +5 +6 +7 ----+------+------+------+------+------+------+------+-----00 | 10 10 10 10 10 10 10 10 08 | 10 10 10 10 10 10 10 10 10 | 0D 10 10 10 10 0B 10 10 18 | 10 10 10 10 10 10 10 10 20 | 10 10 10 10 10 10 10 10 28 | 00 00 00 00 10 0F 00 60 30 | 00 00 00 00 00 00 00 00 38 | 10 10 10 10 10 10 10 10 40 | 10 10 10 10 10 10 10 10 48 | 0F 0F 0F 0F 0F 10 10 10 50 | 0F 0F 0F 0F 0F 0F 0F 0F 58 | 00 00 00 00 00 00 00 00 Key code table for CNC +0 +2 +4 +6 +8 +A +C +E ----+------+------+------+------+------+------+------+-----60 | 30 00 31 82 32 83 33 8C 34 8D 35 A9 36 00 37 00 70 | 38 AA 39 AB 2D 2D 2E 2E 9B 9B 95 95 0A 0A 97 97 80 | 96 99 94 94 9C 9C 98 98 9A 9A 84 85 88 88 89 89 90 | E8 E1 E9 E1 EA E1 EB E1 EC E1 ED E1 EE E1 EF E1 A0 | 8A FB 8B FD 8E 8E 8F 8F 46 5B 44 5D 48 26 42 20 B0 | 00 00 00 00 00 00 00 00 E4 E4 00 00 00 00 90 90 C0 | 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 D0 | 4F 28 4E 29 47 45 50 43 58 55 59 56 5A 57 51 3F E0 | 49 2C 4A 41 4B 40 52 5F 4D 23 53 3D 54 2A 4C 2B F0 | 00 00 00 00 00 00 00 00 00 00 2F 2F 09 09 86 87 100 | 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 110 | 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 Key function flag table for C application +0 +1 +2 +3 +4 +5 +6 +7 ----+------+------+------+------+------+------+------+-----00 | 10 10 10 10 10 10 10 10 08 | 10 10 10 10 10 10 10 10 10 | 0D 10 10 10 10 0B 10 10 18 | 10 10 10 10 10 10 10 10 20 | 10 10 10 10 10 10 10 10 28 | 00 00 00 00 10 0F 00 60 30 | 00 00 00 00 00 00 00 00 38 | 10 10 10 10 10 10 10 10 40 | 10 10 10 10 10 10 10 10 48 | 0F 0F 0F 0F 0F 10 10 10 50 | 0F 0F 0F 0F 0F 0F 0F 0F 58 | 00 00 00 00 00 00 00 00 Key code table for C application +0 +2 +4 +6 +8 +A +C +E ----+------+------+------+------+------+------+------+-----60 | 30 00 31 82 32 83 33 8C 34 8D 35 A9 36 00 37 00 70 | 38 AA 39 AB 2D 2D 2E 2E 9B 9B 95 95 0A 0A 97 97 80 | 96 99 94 94 9C 9C 98 98 9A 9A 84 85 88 88 89 89 90 | E8 E1 E9 E1 EA E1 EB E1 EC E1 ED E1 EE E1 EF E1 A0 | 8A FB 8B FD 8E 8E 8F 8F 46 5B 44 5D 48 26 42 20 B0 | 00 00 00 00 00 00 00 00 E4 E4 00 00 00 00 90 90 C0 | 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 D0 | 4F 28 4E 29 47 45 50 43 58 55 59 56 5A 57 51 3F E0 | 49 2C 4A 41 4B 40 52 5F 4D 23 53 3D 54 2A 4C 2B F0 | 00 00 00 00 00 00 00 00 00 00 2F 2F 09 09 86 87 100 | 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 110 | 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 3. 30i ONG MDI (T series) Key bit matrix bit= 0 1 2 3 4 5 6 7 +------+------+------+------+------+------+------+------+ 0 | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | +------+------+------+------+------+------+------+------+ 1 | 8 | 9 | - | ・ | CTRL |DELETE| EOB | ALT | +------+------+------+------+------+------+------+------+ 2 |ALTER |INSERT| ABC |INPUT | HELP |SHIFT | → | ← | +------+------+------+------+------+------+------+------+ 3 |POSITN|PROGRM|OFFSET|SYSTEM|MESSAG|GRAPH |CUSTM1|CUSTM2| +------+------+------+------+------+------+------+------+ 4 | ↓ | ↑ |Page↓|Page↑| I [ | K ] | R & | F SP | +------+------+------+------+------+------+------+------+ 5 | FL | F9 | F8 | F7 | AUX | | SKV9 | RESET| +------+------+------+------+------+------+------+------+ 6 | F6 | F5 | F4 | F3 | F2 | F1 | F0 | FR | +------+------+------+------+------+------+------+------+ 7 | O ( | N ) | G E | P Q | X A | Z B | C D | Y ? | +------+------+------+------+------+------+------+------+ 8 | U , | W J | H @ | V _ | M # | S = | T * | L + | +------+------+------+------+------+------+------+------+ 9 | | | | | | / | TAB | CAN | +------+------+------+------+------+------+------+------+ A | ---- | ---- | ---- | ---- | ---- | ---- | ---- | ---- | +------+------+------+------+------+------+------+------+ B | SKV8 | SKV7 | SKV6 | SKV5 | SKV4 | SKV3 | SKV2 | SKV1 | +------+------+------+------+------+------+------+------+ Key function flag table for CNC +0 +1 +2 +3 +4 +5 +6 +7 ----+------+------+------+------+------+------+------+-----00 | 10 10 10 10 10 10 10 10 08 | 10 10 10 10 10 10 10 10 10 | 0D 10 10 10 10 0B 10 10 18 | 10 10 10 10 10 10 10 10 20 | 10 10 10 10 10 10 10 10 28 | 00 00 00 00 10 0F 00 60 30 | 00 00 00 00 00 00 00 00 38 | 10 10 10 10 10 10 10 10 40 | 10 10 10 10 10 10 10 10 48 | 0F 0F 0F 0F 0F 10 10 10 50 | 0F 0F 0F 0F 0F 0F 0F 0F 58 | 00 00 00 00 00 00 00 00 Key code table for CNC +0 +2 +4 +6 +8 +A +C +E ----+------+------+------+------+------+------+------+-----60 | 30 00 31 82 32 83 33 8C 34 8D 35 A9 36 00 37 00 70 | 38 AA 39 AB 2D 2D 2E 2E 9B 9B 95 95 0A 0A 97 97 80 | 96 99 94 94 9C 9C 98 98 9A 9A 84 85 88 88 89 89 90 | E8 E1 E9 E1 EA E1 EB E1 EC E1 ED E1 EE E1 EF E1 A0 | 8A FB 8B FD 8E 8E 8F 8F 49 5B 4B 5D 52 26 46 20 B0 | 00 00 00 00 00 00 00 00 E4 E4 00 00 00 00 90 90 C0 | 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 D0 | 4F 28 4E 29 47 45 50 51 58 41 5A 42 43 44 59 3F E0 | 55 2C 57 4A 48 40 56 5F 4D 23 53 3D 54 2A 4C 2B F0 | 00 00 00 00 00 00 00 00 00 00 2F 2F 09 09 86 87 100 | 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 110 | 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 Key function flag table for C application +0 +1 +2 +3 +4 +5 +6 +7 ----+------+------+------+------+------+------+------+-----00 | 10 10 10 10 10 10 10 10 08 | 10 10 10 10 10 10 10 10 10 | 0D 10 10 10 10 0B 10 10 18 | 10 10 10 10 10 10 10 10 20 | 10 10 10 10 10 10 10 10 28 | 00 00 00 00 10 0F 00 60 30 | 00 00 00 00 00 00 00 00 38 | 10 10 10 10 10 10 10 10 40 | 10 10 10 10 10 10 10 10 48 | 0F 0F 0F 0F 0F 10 10 10 50 | 0F 0F 0F 0F 0F 0F 0F 0F 58 | 00 00 00 00 00 00 00 00 Key code table for C application +0 +2 +4 +6 +8 +A +C +E ----+------+------+------+------+------+------+------+-----60 | 30 00 31 82 32 83 33 8C 34 8D 35 A9 36 00 37 00 70 | 38 AA 39 AB 2D 2D 2E 2E 9B 9B 95 95 0A 0A 97 97 80 | 96 99 94 94 9C 9C 98 98 9A 9A 84 85 88 88 89 89 90 | E8 E1 E9 E1 EA E1 EB E1 EC E1 ED E1 EE E1 EF E1 A0 | 8A FB 8B FD 8E 8E 8F 8F 49 5B 4B 5D 52 26 46 20 B0 | 00 00 00 00 00 00 00 00 E4 E4 00 00 00 00 90 90 C0 | 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 D0 | 4F 28 4E 29 47 45 50 51 58 41 5A 42 43 44 59 3F E0 | 55 2C 57 4A 48 40 56 5F 4D 23 53 3D 54 2A 4C 2B F0 | 00 00 00 00 00 00 00 00 00 00 2F 2F 09 09 86 87 100 | 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 110 | 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 3.6 CRT operation library ========================= Supported display device ~~~~~~~~~~~~~~~~~~~~~~~~ C Executor supports the following display devices. VGA Display Character Display device 80-column x 25-line/half-size (40-column x 25-line/ full-size) x 16-color. 80-column x 30-line/half-size (40-column x 30-line/ full-size) x 16-color. Dot matrix (HxV): 8x16 dots(half-size). 10.4-inch color LCD, 10.4-inch color LCD(with touch-panel) All display devices have 12 softkeys under its screen. (Touch-panel works like softkeys on "LCD with touch-panel" device. This is equivalent to 12(10+2)-softkey type.) +---------------------------------------+ | 80-column | | | | | | | | | | | |25-line (or 30-line) | | | | | | | | | | | | | +---------------------------------------+ [L] [0][1][2][3][4] [5][6][7][8][9] [R] <- 12 softkeys (10+2) For every display device, it is possible to specify display color on the monochrome display device. In this case, the intensity of character is changed by color specification. Lists of Functions ~~~~~~~~~~~~~~~~~~ 1. CRT operation library -------------------------------------------------------------------------Name Function -------------------------------------------------------------------------1.1 crt_getcurscrn Get current screen index. 1.2 crt_setuserscrn Register user screen index. 1.3 crt_isnewscrn Test screen switching status. 1.4 crt_gettype Get CRT information. 1.5 crt_setmode Set CRT screen mode. 1.6 crt_cncscrn Switch to CNC screen. 1.7 crt_fchar Output character by FANUC character code. 1.8 crt_setuserskey Customize softkey on CNC screen. 1.9 crt_setswt Set switching method between CNC's screen and user's. 1.10 crt_setscrlarea Set scroll area. 1.11 crt_opengr Open graphic display. 1.12 crt_closegr Close graphic display. 1.13 crt_graphic Enable or disable graphic display. 1.14 crt_readfkey Read the status of function keys. 1.15 crt_2ndcursor Display the secondary cursor. 1.16 crt_settextattr Set attribute of characters on VRAM. 1.17 crt_gettextattr Get attribute of character on VRAM. 1.18 crt_setpalette Set color palette of VGA characters. 1.19 crt_setallpalette Set all color palette of VGA characters. 1.20 crt_getcncpalette Get color palette of CNC screen. 1.21 crt_fstr Output character string by FANUC character code. 1.22 crt_gettextimg Get text data from VRAM. 1.23 crt_puttextimg Put text data into VRAM. 1.24 crt_setgraphpage Select graphic page to use. 1.25 crt_set6chmode Select drawing method of 6x sized character. 1.26 crt_setgsvmode Select saving method of graphic contents. -------------------------------------------------------------------------- 2. Multiple window display library -------------------------------------------------------------------------Name Function -------------------------------------------------------------------------2.1 win_open Open window. 2.2 win_close Close window. 2.3 win_select Select window. 2.4 win_activate Activate window. 2.5 win_move Move window. 2.6 win_size Alter window size. 2.7 win_full Let active window be full screen size. 2.8 win_window Let active window be window size. 2.9 win_info Get window information. 2.10 win_col Set color of window frame and title string. 2.11 win_hide Hide window. 2.12 win_show Show window. 2.13 win_setttl Set window title string. 2.14 win_setfrm Set window frame line character. 2.15 win_getstat Get window display status. 2.16 win_redraw Redraw windows. -------------------------------------------------------------------------- 3. User definition character library -------------------------------------------------------------------------Name Function -------------------------------------------------------------------------3.1 crt_reguserchar Register user character. 3.2 crt_mapuch Map user character. 3.3 crt_getcgpttn Get CG pattern. -------------------------------------------------------------------------- 4. VGA window display library -------------------------------------------------------------------------Name Function -------------------------------------------------------------------------4.1 vwin_open Open VGA window. 4.2 vwin_close Close VGA window. 4.3 vwin_select Select VGA window. 4.4 vwin_show Show VGA window. 4.5 vwin_hide Hide VGA window. 4.6 vwin_info Get VGA window information. -------------------------------------------------------------------------- Function Reference ~~~~~~~~~~~~~~~~~~ 1. CRT operation library -----------------------------------------------------------------------------1.1 Get current screen index. <Main,Alarm> -----------------------------------------------------------------------------[Name] crt_getcurscrn [Syntax] #include <crt.h> int crt_getcurscrn( void ) ; [Arguments] -----[Return] Returns the index number of the currently displayed screen. [Description] Gets the index number of the currently displayed screen. The format of the screen index number is as follows. Upper byte Lower byte ---------------+--------------Small Large classification classification Refer the following screen index number list for index numbers of each screens. All available index values are defined in crt.h as "CRT_xxx_xxx". Screen index number of FS30i Symbol Index number Screen ---------------+---------------+------------------------------<POSITION> CRT_POS_ABS 0x0100 ABS CRT_POS_REL 0x0200 REL CRT_POS_ALL 0x0300 ALL CRT_POS_HNDL 0x0400 HNDL CRT_POS_MONI 0x0600 MONITOR CRT_POS_5AX 0x0700 5AXMAN CRT_POS_CEXE 0x3200 C Executor CRT_POS_CEXE2 0x3300 C Executor 2 CRT_POS_CEXE3 0x3400 C Executor 3 CRT_POS_CEXE4 0x3500 C Executor 4 CRT_POS_CEXE5 0x3600 C Executor 5 <PROGRAM> CRT_PRG_PRG 0x0101 PROG CRT_PRG_LIB 0x0201 FOLDER CRT_PRG_NEXT 0x0301 NEXT CRT_PRG_PCHK 0x0401 CHECK CRT_PRG_REST 0x0601 RSTR CRT_PRG_JOG 0x0701 JOG CRT_PRG_HOST 0x0b01 HOST CRT_PRG_CONHOST 0x0c01 CONECT CRT_PRG_CEXE 0x3201 C Executor CRT_PRG_CEXE2 0x3301 C Executor 2 CRT_PRG_CEXE3 0x3401 C Executor 3 CRT_PRG_CEXE4 0x3501 C Executor 4 CRT_PRG_CEXE5 0x3601 C Executor 5 <OFFSET> CRT_OFS_OFS 0x0102 OFFSET CRT_OFS_SETP 0x0202 SETTING CRT_OFS_WORK 0x0302 WORK CRT_OFS_MCR 0x0602 MACRO CRT_OFS_OPR 0x0802 OPR CRT_OFS_TOOLMNG 0x0902 TOOL MANAGER CRT_OFS_YOFS 0x0b02 OFST.2 CRT_OFS_WSFT 0x0c02 W.SHFT CRT_OFS_GEOM2 0x0d02 GEOM.2 CRT_OFS_TLFM 0x0e02 TOOL.F CRT_OFS_MODEM 0x1002 MODEM CRT_OFS_PRELEV 0x1102 PR-LEV CRT_OFS_CHOP 0x1302 CHOP CRT_OFS_CHUCK 0x1502 CHUCK TAIL CRT_OFS_LANG 0x1602 LANG. CRT_OFS_PROTECT 0x1702 PROTECT CRT_OFS_SAFEGUARD 0x1802 GUARD CRT_OFS_CEXE 0x3202 C Executor CRT_OFS_CEXE2 0x3302 C Executor 2 CRT_OFS_CEXE3 0x3402 C Executor 3 CRT_OFS_CEXE4 0x3502 C Executor 4 CRT_OFS_CEXE5 0x3602 C Executor 5 ---------------+---------------+------------------------------(continued) CRT_SYS_PRM CRT_SYS_DGN CRT_SYS_SRVGUID CRT_SYS_SYS CRT_SYS_MEM CRT_SYS_PIT CRT_SYS_SVPR CRT_SYS_SPPR CRT_SYS_MAINTENANCE CRT_SYS_LADDER CRT_SYS_PMCCONFIG CRT_SYS_MTUNE CRT_SYS_ALIO CRT_SYS_ALIO2 CRT_SYS_OHIS CRT_SYS_COLOR CRT_SYS_MAINT CRT_SYS_MINFO CRT_SYS_WANL CRT_SYS_FSSB CRT_SYS_PARAMTUNE CRT_SYS_EMB_ETH CRT_SYS_PCM_ETH CRT_SYS_BOARD_ETH CRT_SYS_MAS_PROFI CRT_SYS_REMOTEDGN CRT_SYS_MCOD CRT_SYS_CEXE CRT_SYS_CEXE2 CRT_SYS_CEXE3 CRT_SYS_CEXE4 CRT_SYS_CEXE5 0x0103 0x0203 0x0303 0x0403 0x0603 0x0703 0x0803 0x0903 0x0b03 0x0c03 0x0d03 0x1003 0x1103 0x1203 0x1303 0x1503 0x1603 0x1703 0x1803 0x1b03 0x1c03 0x1f03 0x2003 0x2103 0x2203 0x2403 0x2503 0x3203 0x3303 0x3403 0x3503 0x3603 CRT_MSG_ALM CRT_MSG_EMSG CRT_MSG_AHIS CRT_MSG_MHIS CRT_MSG_EMB_ETHLOG CRT_MSG_PCM_ETHLOG CRT_MSG_BOARD_ETHLOG CRT_MSG_CEXE CRT_MSG_CEXE2 CRT_MSG_CEXE3 CRT_MSG_CEXE4 CRT_MSG_CEXE5 0x0104 0x0204 0x0304 0x0404 0x0604 0x0704 0x0804 0x3204 0x3304 0x3404 0x3504 0x3604 CRT_GRH_PRM CRT_GRH_GRP CRT_GRH_CEXE CRT_GRH_CEXE2 CRT_GRH_CEXE3 CRT_GRH_CEXE4 CRT_GRH_CEXE5 0x0105 0x0205 0x3205 0x3305 0x3405 0x3505 0x3605 <SYSTEM> PARAM DGNOS SERVO GUIDEM SYSTEM MEMORY PITCH SV-PRM SP.SET PMC MAINTE PMC LADDER PMC CONFIG M-TUN ALL IO ALL IO OPEHIS COLOR MAINTE M-INFO W.DGNS FSSB PRMTUN EMBED PORT PCMCIA LAN ETHER BOARD PROFI MASTER RMTDGN M CODE C Executor C Executor 2 C Executor 3 C Executor 4 C Executor 5 <MESSAGE> ALARM MSG HISTRY MSGHIS EMBED LOG PCMCIA LOG BOARD LOG C Executor C Executor 2 C Executor 3 C Executor 4 C Executor 5 <GRAPHIC> PARAMETER GRAPH C Executor C Executor 2 C Executor 3 C Executor 4 C Executor 5 [Example] The following program displays the index number of the current screen. #include <crt.h> #include <stdio.h> void example( void ) { int scrn ; scrn = crt_getcurscrn() ; printf( "Current screen index is %02X-%02X\n", scrn & 0xFF, scrn >> 8 ) ; } -----------------------------------------------------------------------------1.2 Register user screen index. <Main> -----------------------------------------------------------------------------[Name] crt_setuserscrn [Syntax] #include <crt.h> int crt_setuserscrn( int num, int *scrntbl ) ; [Arguments] num scrntbl Number of screen index to be registered. Pointer to the user screen index table. [Return] Returns zero if successful. If any error, returns -1 and sets the following error code in the global variable "errno". EUCRT Number of the screen index "num" is 0 or above 200. [Description] Registers the screen index numbers of the CNC screens which is replaced by the user application program. The index numbers of the user screens are registered in CNC by calling of this function. Then, the user application will be called by selection of registered screens. Store the screen index numbers in "scrntbl" with the following format. The storing order is arbitrary. Upper byte Lower byte ---------------+--------------Small Large classification classification Refer the screen index number list of "Get current screen index (crt_getcurscrn)" for index numbers of each screens. All available index values are defined in crt.h as "CRT_xxx_xxx". At the start time of the application program, no user screen is registered. In this condition, screen switching from the user screen to the CNC's is not allowed because it is impossible to return to the user screen from the CNC screen again if no user screen is registered. So, this function must be called in the beginning of the main task of the user application program. This function doesn't check integrity of the screen index numbers to be registered. Re-registration of the user screen index numbers by calling of this function again is allowable. In this case, this function must be called under condition that any screen switching is disabled by "crt_setswt" function. For FS30i, "C Executor screen" is added to each large classification of CNC screens. (CEXE-screen) CEXE-screen is exclusive screen for C Executor. The CNC software doesn't use this screen. By registering this CEXE-screen as user screen using this function, the new user screen is added without replacing any existing CNC screens. [Example] The following program registers all position screens ([ALL]/[REL]/[ABS]/[MCN]) as user's screen. #include <crt.h> void example( void ) { int crt_table[] = { CRT_POS_ALL, /* CRT_POS_REL, /* CRT_POS_ABS, /* CRT_POS_MCN /* } ; crt_setuserscrn( scrn_tbl_size(crt_table), } POSITION/ALL */ POSITION/RELATIVE */ POSITION/ABSOLUTE */ POSITION/MACHINE */ crt_table ) ; -----------------------------------------------------------------------------1.3 Test screen switching status. <Main,Alarm> -----------------------------------------------------------------------------[Name] crt_isnewscrn [Syntax] #include <crt.h> int crt_isnewscrn( void ) ; [Arguments] -----[Return] Returns non-zero value if any screen switching has been done after the last calling this function. If not, returns zero. [Description] Test whether any screen switching has been done or not. This function is used to check the new entrance to the user screen by screen switching such as (any user screen) -> (CNC screen) -> (the same user screen). In this case, it is impossible to get screen switching status by only calling "crt_getcurscrn" function. [Example] The following program displays whether any screen switching has been done or not. #include <crt.h> #include <stdio.h> void example( void ) { if ( crt_isnewscrn() ) printf( "Any" ) ; else printf( "No" ) ; printf( " screen switching has been done.\n" ) ; } -----------------------------------------------------------------------------1.4 Get CRT information. <Main,Alarm> -----------------------------------------------------------------------------[Name] crt_gettype [Syntax] #include <crt.h> unsigned int crt_gettype( void ) ; [Arguments] -----[Return] Returns CRT information. [Description] Gets the equipped CRT specification and the current display mode. This function is used to get whether CRT is 9 inch or 14 inch, etc. The following informations are returned on each bits of the return value. bit0 bit1 bit2 bit3 bit4 bit5 bit6 bit7 bit8 0: 9 inch CRT. 1: 14 inch CRT. (CRT_TYPE_14) (This bit is always set as "1".) 0: 40-column x 16-line. 1: 80-column x 25-line. (CRT_TYPE_80X25) (This bit is always set as "1".) 0: Graphic function is unavailable. 1: Graphic function is available. (CRT_TYPE_GRAPH) (This bit is always set as "1".) 0: Graphic function is not in use. 1: Graphic function is in use. (CRT_TYPE_GAUTH) Undefined. 0: CRTC Display. 1: VGA Display. (CRT_TYPE_VGA) (This bit is always set as "1".) 0: 80-column x 25-line. 1: 80-column x 30-line. (CRT_TYPE_V30) (This bit is always set as "1".) 0: 16-color mode 1: 256-color mode (CRT_TYPE_VGAMD) 0: 40-column x 16-line. 1: 40-column x 19-line. (CRT_TYPE_V19) (This bit is always set as "0".) bit9 bit10 0: 7.2-inch or 8.4-inch LCD. 1: 9-inch CRT. (CRT_TYPE_VCRT) (This bit indicates the kind of display device of 9-inch VGA display. This bit is always set as "0".) 0: Normal display 1: Extended and reduced display (CRT_TYPE_V9MD2) (This bit is always set as "0".) 0: VGA Display 1: Character Card Display bit11 bit12-15 Undefined. [Example] The following program displays information of the current display equipment. #include <crt.h> #include <stdio.h> void example( void ) { unsigned int crt ; crt = crt_gettype() ; printf( "Current screen mode is %s on %sinchCRT with%s " "Graphic device.\n", (crt&CRT_TYPE_80X25)?"80x25":"40x16", (crt&CRT_TYPE_14)?"14":"9", (crt&CRT_TYPE_GRAPH)?"":"out" ) ; } -----------------------------------------------------------------------------1.5 Set CRT screen mode. <Main,Alarm> -----------------------------------------------------------------------------[Name] crt_setmode [Syntax] #include <crt.h> int crt_setmode( unsigned int mode ) ; [Arguments] mode CRT screen mode. [Return] Returns zero if successful. If any error, returns non-zero value. [Description] Set the screen mode such as character size and color/monochrome mode. The screen mode is changed into the specified one and the screen is initialized by the successful calling of this function. Specify following values in "mode". CRT_MODE_80X25 CRT_MODE_MONO CRT_MODE_V25_0 CRT_MODE_V25_1 CRT_MODE_V25_2 CRT_MODE_V25_3 CRT_MODE_V25_4 CRT_MODE_V25_5 CRT_MODE_V30 CRT_MODE_CFLAG CFLAG_KEISEN 80-column x 25-line mode. Monochrome mode (without brightness conversion). (This is specified with "CRT_MODE_80X25".) VGA, 80-column x 25-line(Upper blank:0) VGA, 80-column x 25-line(Upper blank:1) VGA, 80-column x 25-line(Upper blank:2) VGA, 80-column x 25-line(Upper blank:3) VGA, 80-column x 25-line(Upper blank:4) VGA, 80-column x 25-line(Upper blank:5) VGA, 80-column x 30-line mode. Specify display action flag. Enable replacement JIS-Keisen/98-Keisen FANUC-Keisen. mode. mode. mode. mode. mode. mode. with "Upper blank:n" in VGA Display is, +| | | | 30 lines | (19 lines)| | | | | | +- +---------------------------------+ | Blank of n lines | |---------------------------------| |Start line ^ | | | | | | | | | | | | Display region | | | | | | | | | | | | | | v | |---------------------------------| +---------------------------------+ -+ | | | | 25 lines |(16 lines) | | | -+ It specifies in where the 25-line (or 16-line) region is placed in the whole screen (30-line or 19-line) like above. The available combinations are as follows. CRT_MODE_V25_0 80x25(UB:0), color CRT_MODE_V25_0 + CRT_MODE_MONO 80x25(UB:0), monochrome CRT_MODE_V25_1 80x25(UB:1), color CRT_MODE_V25_1 + CRT_MODE_MONO 80x25(UB:1), monochrome CRT_MODE_V25_2 80x25(UB:2), color CRT_MODE_V25_2 + CRT_MODE_MONO 80x25(UB:2), monochrome CRT_MODE_V25_3 80x25(UB:3), color (default) CRT_MODE_V25_3 + CRT_MODE_MONO 80x25(UB:3), monochrome CRT_MODE_V25_4 80x25(UB:4), color CRT_MODE_V25_4 + CRT_MODE_MONO 80x25(UB:4), monochrome CRT_MODE_V25_5 80x25(UB:5), color CRT_MODE_V25_5 + CRT_MODE_MONO 80x25(UB:5), monochrome CRT_MODE_V30 80x30, color CRT_MODE_V30 + CRT_MODE_MONO 80x30, monochrome CRT_MODE_CFLAG + CFLAG_KEISEN Enable replacement JIS-Keisen/ 98-Keisen with FANUC-Keisen. The color selection by the escape sequences code are ineffective on monochrome mode. Characters are always displayed by WHITE (or the maximum brightness on monochrome display equipment). The console driver is initialized by this function. All setting about CRT are initialized. So re-initialization is required if needed. If this function is called while the graphic grawing are displayed, the graphic drawing contents will be initialized. The condition of graphics is initialized like "Text mode" specified by _setvideomode function. -----------------------------------------------------------------------------1.6 Switch to CNC screen. <Main,Alarm> -----------------------------------------------------------------------------[Name] crt_cncscrn [Syntax] #include <crt.h> int crt_cncscrn( int index ) ; [Arguments] index Index number of the CNC screen to be switched to. [Return] Returns zero if successful. If not, returns one of following values and sets the same value in the global variable "errno". ER_CNC_DATA (=5) ER_CNC_OPTION (=6) ER_CNC_BUSY (=-1) Incorrect screen index number "index". There are no additional options/board required for the specified screen. CNC window is busy. [Description] Changes into the CNC screen which is specified by the application program. Also execution of program is switched from the application task to the CNC task. This is the same operation as switching to CNC screen by pressing of the function keys on MDI panel. The CRT display will be switched into the specified CNC screen by the successful calling of this function. At the same time, the control of software will be switches to the CNC side, and then, the application program is put into sleep state. When the screen will be changed from the CNC side into the user's screen again, the application program will restart from the next instruction to this function call. Specify the screen index numbers in "index" with the following format. Upper byte Lower byte ---------------+--------------Small Large classification classification Refer the screen index number list of "Get current screen index(crt_getcurscrn)" for index numbers of each screens. All available index values are defined in crt.h as "CRT_xxx_xxx". It is possible to switch to any user's screen by specifying the index number of the user screen. [Example] The following program changes into "PROGRAM CHECK" screen if the current mode is "MEM". #include <crt.h> #include <data.h> #include <fwindow.h> void example( void ) { struct odbst stat ; cnc_statinfo( &stat ) ; if ( stat.aut == 1 ) crt_cncscrn( CRT_PRG_PCHK ) ; } -----------------------------------------------------------------------------1.7 Output character by FANUC character code. <Main> -----------------------------------------------------------------------------[Name] crt_fchar [Syntax] #include <crt.h> int crt_fchar( unsigned int code ) ; [Arguments] code FANUC character code ( 0x0000 through 0x1fff ), or FANUC character code | 0x8000 (0x8000 through 0x9fff). [Return] Returns always zero. [Description] Outputs a character that is included in FANUC character set and is specified by FANUC character code on the current cursor position. A character which is specified by FANUC character code is displayed on the current cursor position. In case that (FANUC code | 0x8000) is specified, the function works as follows. In case of "ESC (A" mode (JIS Kanji set mode) is specified. Character codes 0x0000 through 0xFFFF can be accepted. This function must display the specified half-size character. In case of other than "ESC (A" mode is specified. Two characters are displayed continuously, the first one is (specified code), and the next one is (specified code + 1). This function works like putchar() function except character code format. That is, displaying a half-size character on the current curosr position with the specified character attribute, and then forwarding a cursor for one character. [Example] The following program displays the specified integer value using bold numeric characters. #include <crt.h> #include <stdio.h> #include <string.h> void example( unsigned int val ) { int idx ; char buf[6] ; sprintf( buf, "%u", val ) ; for ( idx = 0 ; idx < strlen( buf ) ; idx++ ) crt_fchar( 0x1D20 + buf[idx] - '0' ) ; } -----------------------------------------------------------------------------1.8 Customize softkey on CNC screen. <Main> -----------------------------------------------------------------------------[Name] crt_setuserskey [Syntax] #include <crt.h> int crt_setuserskey( unsigned int index, unsigned int num, struct user_softkey *skey ) ; struct user_softkey { unsigned int int unsigned int unsigned int index ; op ; submode ; *string ; /* /* /* /* /* Softkey index number. */ Operation code. */ Small classification of */ user's screen. */ Display string. */ } ; [Arguments] index num skey Softkey table index number to be customized. Number of customizing item. Customizing data table. [Return] Returns zero if successful. If any error, returns -1 and sets the following error code in the global variable "errno". EUSKEY Incorrect softkey table index number "index" or softkey index number "skey.index". [Description] Alters the softkey displayed on the CNC screen as follows, adds new items, by which any user screens are selected, moves the existent items, by which the CNC screens are selected,deletes the existent items. Specify the softkey table index number to be customized in "index". There are the softkey tables for each large classifications of the CNC screen (and more, for each modes in the PROGRAM screen). All available table index values are defined in crt.h as "SKEY_xxxx". Store multiple customizing data in "skey". The customizing data includes the following items. index op submode string Softkey index number to be customized. Operation code. Small classification of the user's screen. User specified display string. Softkey index number is the sequential number for each softkey tables. For example, the following sequential numbers are assigned to the softkeys on the POSITION screen. Key Softkey index number ---------------+--------------------[ ABS ] 1 [ REL ] 2 [ ALL ] 3 [ HNDL ] 4 Available operations are "Deletion", "User specified" and "Moving". Operation code Action ---------------+--------------------------------------------SKEY_OP_DEL makes the specified softkey ineffective. Blank is displayed for the softkey. SKEY_OP_USER makes the specified softkey effective forcibly. The user specified string is displayed on the screen. The user specified (small classification) screen will be selected by pushing the specified softkey. Other value moves the softkey which is specified by the operation code to the specified position. Specify the small classification number of the screen which is selected by the specified softkey in "submode" when the operation code is "SKEY_OP_USER". "submode" is not referenced when the operation code is "SKEY_OP_DEL" or moving softkey. Specify display string of the softkey in "string" by FANUC code when the operation code is "SKEY_OP_USER". The maximum string length is 12 characters (6 characters x 2-line) . Register the small classification number of the screen which is specified in "submode" as the user's screen using "crt_setuserscrn" function when "SKEY_OP_USER" is specified. Call this function before calling "crt_setuserscrn" function. CNC original softkey table ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ The following list includes the original softkey display items of FS30i. Softkeys shown in the left side are defined for screen selection in each screens (and each modes). The numbers shown in the right side are the small classification numbers of the screen which is selected by each softkeys. POSITION [ ABS [ MONITOR [ CEXE ][ ][ ][ REL 5AXMAN CEXE2 ][ ][ ][ ALL CEXE3 ][ ][ ][ HANDLE ][ ][ ][ ][ CHECK CEXE4 ][ ][ ][ CEXE5 ] ] ] CEXE5 ] ] ] ] CEXE5 ] ] ] ] ] ] [01][02][03][04][ ] [06][07][ ][ ][ ] [50][51][52][53][54] PROGRAM [ PROG [ RSTR [ HOST [ CEXE ][ ][ ][ ][ FOLDER JOG CONECT CEXE2 ][ ][ ][ ][ NEXT CEXE3 CEXE4 ][ ][ ][ ][ [01][02][03][04][ ] [06][07][ ][ ][ ] [11][12][ ][ ][ ] [50][51][52][53][54] OFFSET/SETTING [ OFFSET [ MACRO [ OFST.2 [ MODEM [ CHUCK TAIL [ CEXE ][ ][ ][ ][ ][ ][ SETTING W.SHFT PR-LEV LANG. CEXE2 [01][02][03][ ][ ] [06][ ][08][09][ ] [11][12][13][14][ ] [16][17][ ][19][ ] [21][22][23][24][ ] [50][51][52][53][54] (continued) ][ ][ ][ ][ ][ ][ WORK OPR GEOM.2 ][ ][ ][TOOL MANAGER][ ][ TOOL.F ][ ][ CHOP ][ PROTECT ][ GUARD ][ CEXE3 ][ CEXE4 ][ SYSTEM [ PARAM [ MEMORY [ PMC MAINTE [ M-TUN [ COLOR [ [ EMBED PORT [ RMTDGN [ CEXE ][ DGNOS ][SERVO GUIDEM][ SYSTEM ][ ][ PITCH ][ SV-PRM ][ SP.SET ][ ][ PMC LADDER ][ PMC CONFIG ][ ][ ][ ALL IO ][ ALL IO ][ OPEHIS ][ ][ MAINTE ][ M-INFO ][ W.DGNS ][ ][ FSSB ][ PRMTUN ][ ][ ][ PCMCIA LAN ][ETHER BOARD ][PROFI MASTER][ ][ M CODE ][ ][ ][ ][ CEXE2 ][ CEXE3 ][ CEXE4 ][ CEXE5 ] ] ] ] ] ] ] ] ] CEXE4 ][ ][ ][ CEXE5 ] ] ] CEXE4 ][ ][ CEXE5 ] ] [01][02][03][04][ ] [06][07][08][09][ ] [11][12][13][ ][ ] [16][17][18][19][ ] [21][22][23][24][ ] [ ][27][28][ ][ ] [31][32][33][34][ ] [36][37][ ][ ][ ] [50][51][52][53][54] MESSAGE [ ALARM [ EMBED LOG [ CEXE ][ MSG ][ HISTRY ][ ][ PCMCIA LOG ][ BOARD LOG ][ ][ CEXE2 ][ CEXE3 ][ MSGHIS [01][02][03][04][ ] [06][07][08][ ][ ] [50][51][52][53][54] GRAPH [ PARAMETER ][ [ CEXE ][ GRAPH CEXE2 [01][02][ ][ ][ ] [50][51][52][53][54] ][ ][ CEXE3 ][ ][ How to define display string of the softkey ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ The display string of the softkey must be defined by FANUC code when softkey item is customized using this function. (1) Define array of "int" type(or "unsigned int" type). The total number of elements is 12( 6 characters x 2-line). The exceeded elements are ignored. (2) Store one code for a character in each "int"-type element. For double-sized character (such as Japanese Kanji character), store the codes for the left-side and the right-side of the character continuously. (Example 1) Define a string " USER ". unsigned int skey_user[] = { 0x0020,0x0055,0x0053,0x0045,0x0052,0x0020 } ; /* " USER " */ (Example 2) Define a string "TOOL# seting" unsigned int skey_kougu[] = { 0x0054,0x004F,0x004F,0x004C,0x0023,0x0020, 0x0073,0x0065,0x0074,0x0069,0x006e,0x0067 } ; /* "TOOL# " */ /* "seting" */ [Example] This is procedure to customize the softkey of POSITION screen as follows. Original After customizing [ ALL ][ REL ][ ABS ][ MCN ] [ USER ][ ALL ][ ABS ][ ] 1. Define a string " USER " by FANUC character code. unsigned int skey_str[] = { 0x0020,0x0055,0x0053,0x0045,0x0052,0x0020, 0x0020,0x0020,0x0020,0x0020,0x0020,0x0020 } ; /* " USER " */ /* " " */ 2. Define customizing data. struct user_softkey skey_table[] = { /* Delete [ MCN ] key. */ { 4, SKEY_OP_DEL, 0, NULL }, /* Move [ ALL ] to [ REL ]'s position. */ { 2, 1, 0, NULL }, /* Define new user key at [ ALL ]'s position, the small classification is 3. Register the small classification 3 screen in POS function as user's screen using "crt_setuserscrn" function. */ { 1, SKEY_OP_USER, 3, skey_str } } ; 3. Call "crt_setuserskey" function. crt_setuserskey( SKEY_POSITION, skey_tbl_size(skey_table), skey_table ) ; After customizing, the small classification 3 user's screen is displayed by pushing [ USER ] key, the ordinary all position screen screen by [ ALL ] key, and the absolute position screen by [ ABS ] key. The above procedures are described in the following program. #include <crt.h> void example( void ) { unsigned int skey_str[] = { 0x0020,0x0055,0x0053,0x0045,0x0052,0x0020, /* " USER " */ 0x0020,0x0020,0x0020,0x0020,0x0020,0x0020 /* " " */ } ; struct user_softkey skey_table[] = { { 4, SKEY_OP_DEL, 0, NULL }, { 2, 1, 0, NULL }, { 1, SKEY_OP_USER, 3, skey_str } } ; crt_setuserskey( SKEY_POSITION, skey_tbl_size(skey_table), skey_table ) ; } -----------------------------------------------------------------------------1.9 Set switching method between CNC's screen and user's. <Main,Alarm> -----------------------------------------------------------------------------[Name] crt_setswt [Syntax] #include <crt.h> unsigned int crt_setswt( unsigned int mode ) ; [Arguments] mode Screen switching mode. [Return] Returns the old setting value. [Description] Set switching method such as, disable/enable to switch to the CNC screen from the user's, disable/enable to output video signal at switching to the user screen from the CNC's. Specify the following setting value in each bits of "mode". It is possible to specify the multiple bits simultaneously. bit0 bit1 bit2 bit3 bit4 0: Enables switching to the CNC screen from the user's. (default) 1: Disable switching to the CNC screen from the user's. (CRT_SWT_DIS) 0: Video beam is ON at switching to the user screen from the CNC's (default) 1: Video beam is OFF at switching to the user screen from the CNC's. (CRT_SWT_VOFF) 0: Disable switching screen during graphic drawing. (default) 1: Enable switching screen during graphic drawing. (CRT_SWT_GREN) When any CNC alarm occurred in the CNC screen, the screen is switched to the CNC's alarm screen automatically or not 0: according to the ordinary CNC setting. (Parameter No.3111#7) 1: according to the user screen's setting. (Parameter No.8650#1) (CRT_SWT_ACNC) The function keys on MDI panel are 0: read by the CNC software. (default) 1: not read by the CNC software. (The CNC software can't switch the screen.) bit5 bit6 The automatic graphic beam ON when the screen is switched from the CNC to the user's is 0: not executed. 1: executed. (only when the graphic beam is enabled on the previous user's screen.) (CRT_SWT_GRON) For VGA Display, the contents of the user screen is saved and restored at the switching screen between the NC's and the user's or not. 0: saved/restored. 1: not saved/restored. (This makes the screen switching fast a little.) (CRT_SWT_NOSV) Setting by this function goes on being effective until this function will be called newly. "CRT_SWT_DIS" disables switching to the CNC screen by MDI key operation, so take care of usage of this function. Under condition that "CRT_SWT_DIS" is set, also screen switching by "crt_cncscrn" function is disabled. Under condition that "CRT_SWT_VOFF" is set, nothing is displayed on the screen after screen switching from the CNC screen to the user's until the application program enables video beam output. Output escape sequence "ESC [>9l" to console, or clear whole screen by "ESC [2J" to enable beam output. ("ESC [2J" enables video beam output.) Under condition that "CRT_SWT_MFKY" is set, the screen switching by the function keys is disabled. When this bit is set, the user application must read the status of the function keys using "crt_readfkey" function and switch the screen. This setting is effective on the CNC's screen. During the CNC screen is being displayed, execute reading the function keys and switching the screen in the auxiliary task. When the application program manages the screen switching with setting this bit ON, set CNC parameter No.8650#1 CNA as "1" and manages also screen switching at CNC alarm rising by the application program. [Example] The following program disables screen switching, executes foo() function and restores the original status again. #include <crt.h> void example( void ) { unsigned int save_mode ; save_mode = crt_setswt( CRT_SWT_DIS ) ; foo() ; crt_setswt( save_mode ) ; } -----------------------------------------------------------------------------1.10 Set scroll area. <Main> -----------------------------------------------------------------------------[Name] crt_setscrlarea [Syntax] #include <crt.h> int crt_setscrlarea( unsigned int start, unsigned int height ) ; [Arguments] start height Start line of the scroll area (1 - max line). Height of the scroll area (1 - max line). "max line" is 30 . (in case of line extended) [Return] Returns zero if successful. If any error (for example, the scroll area is out of the screen, etc.), returns "1". [Description] Set the scroll area for automatic scrolling by line-feeding. Only specified scroll area is scrolled by line-feeding by this function. This function doesn't clear the screen, and doesn't change the current cursor position. The whole screen is scroll area on the start-up time. The scroll area which is specified by this function is effective to both automatic scrolling by line-feeding and scroll-up/scroll-down by escape-sequence ("ESC [nL", "ESC [nM"). [Example] The following program sets the scroll area in 2 through 24th line. (The top line and the bottom line are not scrolled.) #include <crt.h> void example( void ) { crt_setscrlarea( 2, 24 ) ; } -----------------------------------------------------------------------------1.11 Open graphic display. <Main> -----------------------------------------------------------------------------[Name] crt_opengr [Syntax] #include <crt.h> int crt_opengr( void ) ; [Arguments] -----[Return] Returns "0" or "1" if successful. If any error (Graphic board is not equipped, or the graphic function option is not set.), returns "-1". The difference between return code "0" and "1" is as follows. 0 1 The authorization to use graphic display has not been given to another application after the last calling of crt_closegr() function. So, initialization of graphic screen is not required because the state of graphic display on the last calling of crt_closegr() is being kept. The authorization to use graphic display has been given to another application after the last calling of crt_closegr() function. So, initialization of graphic screen is required because the state of graphic display on the last calling of crt_closegr() is not being kept. [Description] Acquire authorization to use graphic display and become ready for the graphic display. After successful completion of this function, the authorization of graphic display is given to the C Executor application program and the application program become capable of drawing on the graphic screen. After the execution of this function, screen switching is disabled until crt_closegr() function is executed. Calling crt_setswt(CRT_SWT_GREN) prior to crt_opengr() enables screen switching while graphics display is open. When screen is switched from the user screen to the CNC screen while displaying application graphics, graphic display to the CRT is disabled (BEAM OFF). However, the graphics drawn by the user application program is retained as is, provided no graphic screen is displayed by CNC. When screen is switched back to the user screen, the function crt_opengr() returns the value '0' if graphics is retained. But , to re-display the graphics on the CRT, beam should be made on by the function crt_graphic(). If the "CRT_SWT_GRON" bit is set by the crt_setswt() function, "BEEM ON" is automatically done when returned from the CNC screen to the user screen. [Example] Following program draws a line defined by two specified end points. #include <crt.h> #include <graph.h> void example( int x1, int y1, int x2, int y2 ) { int ret ; ret = crt_opengr() ; if ( ret == -1 ) return ; if ( ret ) _setvideomode( 81 ) ; _moveto( x1, y1 ) ; _lineto( x2, y2 ) ; crt_closegr() ; } -----------------------------------------------------------------------------1.12 Close graphic display. <Main> -----------------------------------------------------------------------------[Name] crt_closegr [Syntax] #include <crt.h> void crt_closegr( void ) ; [Arguments] -----[Return] -----[Description] Stop using graphic display and become ready to release authorization for graphic display. By calling this function, access to the graphic display function from the user application program is disabled, and no user graphics display can be done until the crt_opengr() function is called again. This function, at the same time, enables screen switching, and the screen switching which has been suspended during open graphic display mode is executed after the execution of this function.. This function does not always release authorization for graphic display at it's execution. If there are no other application programs requiring authorization for graphic display when this function is called, this function only prepares for releasing the authorization of graphic display. [Example] Refer to the example of "Open graphic display (crt_opengr)". -----------------------------------------------------------------------------1.13 Enable or disable graphic display. <Main,Alarm> -----------------------------------------------------------------------------[Name] crt_graphic [Syntax] #include <crt.h> int crt_graphic( int mode ) ; [Arguments] mode Specify graphic output ON or OFF. [Return] Returns zero if successful and returns non zero if any error (graphic function is not ready for use). [Description] Specify whether to display graphics on the CRT or not (GRAPHIC BEAM ON or OFF). One of the following should be specified for the "mode". CRT_ON_BEAM CRT_OFF_BEAM Enable graphic display on the CRT. Disable graphic display on the CRT. This function controls whether the graphics drawn by the user application program is displayed on the CRT or not , and has no effect on the display of characters, while BEAM ON/OFF command by using the escape sequences, "ESC [>9l"/"ESC [>9h", affects both graphics and characters. Graphics can be drawn even while the display of the graphics to the CRT is disabled. The default state of the "GRAPHIC BEAM" right after the graphic screen is initialized (i.e. when returned from the "_setvideomode" function) is "ON". Screen switching from the user screen to the CNC screen automatically turns the "GRAPHIC BEAM" off. After switching the screen to the user's again, turn the "GRAPHIC BEAM" on by this function to get graphic display on the CRT. [Example] Following program tests the current screen, and turns the "GRAPHIC BEAM" on if it is POSITION display screen. Turns the "GRAPHIC BEAM" off if else. #include <crt.h> void example( void ) { int scrn ; scrn = crt_getcurscrn() ; if ( ( scrn & 0xFF ) == ( CRT_POS_ABS & 0xFF ) ) crt_graphic( CRT_ON_BEAM ) ; else crt_graphic( CRT_OFF_BEAM ) ; } -----------------------------------------------------------------------------1.14 Read the status of function keys. <Main,Alarm> -----------------------------------------------------------------------------[Name] crt_readfkey [Syntax] #include <crt.h> int crt_readfkey( void ) ; [Arguments] -----[Return] Returns zero if no function keys are depressed or CRT_SWT_MFKY bit of the "crt_setswt" function is set to "0". When CRT_SWT_MFKY bit is set to "1", keycode for the function key being depressed is returned. Keycodes are shown below. KEY SYMBOL CODE -----------------------+---------------+-----POSITION MDIKEY_POS 0xE8 PROGRAM MDIKEY_PROG 0xE9 OFFSET/SETTING MDIKEY_OFFSET 0xEA SYSTEM MDIKEY_SYSTEM 0xEB MESSAGE MDIKEY_MESSAGE 0xEC GRAPH MDIKEY_GRAPH 0xED CUSTOM MDIKEY_CUSTOM 0xEE CUSTOM2 MDIKEY_CUSTOM2 0xEF [Description] This function reads the status of the function keys on the MDI panel, and is used by the user application program to switch screens according to the status of the function keys. If function key is depressed, corresponding keycode is read and returned. When reading the status of the function keys, set "CRT_SWT_MFKY" bit of the crt_setswt() function to "1". This disables the ordinary screen switching caused by the function keys. User application program reads the status of the function keys by means of this function and switch the screens by using crt_cncscrn() function. [Example] Following is a sample program which, when a function key is pressed, switches the screen to the corresponding CNC screen.(Execute as auxiliary task) #include <crt.h> #include <oscall.h> void main( void ) { unsigned int idx, fkey, newscrn, curscrn, savescrn[8] ; for ( idx = 0 ; idx < 8 ; idx++) savescrn[idx] = idx ; for (;;) { os_wait_tim( 5 ) ; curscrn = crt_getcurscrn() ; /* initialize savescrn[8] */ /* run every 40msec */ /* get current screen index */ /* number */ savescrn[curscrn % 0x100] = curscrn ; /* save index including small classification */ if ( fkey = crt_readfkey() ) { /* if function key is pressed */ /* restore previous small classification number */ newscrn = savescrn[fkey - MDIKEY_POS] ; if ( newscrn != curscrn ) { crt_cncscrn( newscrn ) ; crt_setswt( CRT_SWT_MFKY ) ; } } } } -----------------------------------------------------------------------------1.15 Display the secondary cursor. <Main> -----------------------------------------------------------------------------[Name] crt_2ndcursor [Syntax] #include <crt.h> int crt_2ndcursor( unsigned int attrib, unsigned int start, unsigned int end, unsigned int position, unsigned int width ) ; [Arguments] attrib start end position width cursor cursor cursor cursor cursor attribute start raster end raster position width [Return] Returns zero if successful and returns "-1" if any error( invalid argument). [Description] The crt_2ndcursor() sets cursor display ON/OFF or other attributes for the 2nd cursor. The 2nd cursor is a cursor which can freely be controlled by the user application program independent of the usual character cursor. The 2nd cursor is set to OFF(non display) state, after the screen is initialized by crt_swtmode() function or "ESC [2J". Other than these two methods, crt_2ndcursor() is the only means to control ON/OFF of the 2nd cursor. Specify following values for each arguments in binary form. attrib start end Specify one of the following. CUR2_ON non-blink CUR2_OFF no cursor display CUR2_FBLINK fast blink CUR2_SBLINK slow blink Specify cursor start raster. Specify cursor end raster. Cursor start raster and cursor end raster specifies the top and bottom raster position of the cursor respectively. This defines the shape of the cursor,box or underline. position width Specify cursor position. To display cursor on the Mth column of the Nth line, specify as (N-1)*(columns per line)+(M-1). (Both line number and column number starts from "1" which corresponds to the top line and the left-most column. Columns are the number of single column character.) Specify width of the cursor in the unit of single column character width. Allowable maximum width is the number of columns per line. (80) Cursor cannot be displayed across the lines. Allowable parameter range of each argument argument ------------+-------------------+------------------------------start 0 - 15 end 0 - 15 (must satisfy end>=start) position 0 - 2399 width 1 - 80 [Example] Following program modifies the specified lines to be underlined. #include <crt.h> void example( unsigned int line ) { if ( crt_gettype() & CRT_TYPE_80X25 ) crt_2ndcursor( CUR2_ON, 15, 15, (line-1)*80, 80 ) ; else crt_2ndcursor( CUR2_ON, 24, 24, (line-1)*40, 40 ) ; } -----------------------------------------------------------------------------1.16 Set attribute of characters on VRAM. <Main> -----------------------------------------------------------------------------[Name] crt_settextattr [Syntax] #include <crt.h> int crt_settextattr( unsigned int y1, unsigned int x1, unsigned int y2, unsigned int x2, unsigned int attr, unsigned int op ) ; [Arguments] y1 x1 y2 x2 attr op Line number of the upper-left position of the attribute setting region. Column number of the upper-left position of the attribte setting region. Line number of the lower-right position of the attribute setting region. Column number of the lower-right position of the attribute setting region. Set attribute value. Logical operation specification. [Return] Returns zero if successful. If any error (incorrect coordinate spec or incorrect logical operation spec), returns non-zero value. [Description] Sets the specified attributes to the characters displayed on the screen. This function doesn't change the already displayed character code but changes only its attributes. Specify line and column number of the upper-left and the lower-right position in "y1", "x1" and "y2", "x2". (The upper-left position of the screen is (1st-column, 1st-line).) +-----------------------------------+ |(1,1) Whole screen| | | | +-------------------+ | | |(y1,x1) | | | | | | | | | | | | (y2,x2)| | | +-------------------+ | | Attribute setting region | | | | (ymax,xmax)| +-----------------------------------+ ymax=30, xmax=80 This function changes the attributes of all characters included in the rectangle region specified by y1,x1,y2,x2. Specify the bit pattern of newly set attributes in "attr" as follows. 15 8 7 0 +------------------------+------------------------+ | 0 0 0 Ib Bb Gb Rb I | B G R r b 0 0 0 | +------------------------+------------------------+ B: Blue r: Reverse G: Green b: Blink R: Red I: Low intensity Bb:Background Blue Gb:Background Green Rb:Background Red Ib:Background Low intensity The available setting values are as follows. Black Red Green Yellow Blue Magenta Cyan White Normal 0x0000 0x0020 0x0040 0x0060 0x0080 0x00a0 0x00c0 0x00e0 Reverse 0x0010 0x0030 0x0050 0x0070 0x0090 0x00b0 0x00d0 0x00f0 Blink 0x0008 0x0028 0x0048 0x0068 0x0088 0x00a8 0x00c8 0x00e8 Reverse+Blink 0x0018 0x0038 0x0058 0x0078 0x0098 0x00b8 0x00d8 0x00f8 Actually, 4-bits of "IRGB" and "IbRbGbBb" indicate the palette index number of character and background. Specify the logical operation method of attribute setting in "op". op Operation Set attributes -------+---------------+----------------3 Set attr 2 Set negative ~attr 0 Or Char_attr | attr 1 And Char_attr & attr 4 Xor Char_attr ^ attr [Example] The following program make the top line of the screen "REVERSE" for a moment. #include <crt.h> void example( void ) { crt_settextattr( 1, 1, 1, 80, 0x0010, 0 ) ; crt_settextattr( 1, 1, 1, 80, ~0x0010, 1 ) ; } -----------------------------------------------------------------------------1.17 Get attribute of character on VRAM. <Main> -----------------------------------------------------------------------------[Name] crt_gettextattr [Syntax] #include <crt.h> unsigned int crt_gettextattr( unsigned int y, unsigned int x ) ; [Arguments] y x Line position of the character to be got the attribute. Column position of the character to be got the attribute. [Return] Returns the attribute of the character at the specified position. If incorrect position specification, returns -1. [Description] Gets the attribute of the character at the specified position. Specify line and column position of the character to be got the attribute in "y" and "x". (The top-left position of the screen is (1st-column, 1st-line).) The read attribute is returned as the return code of this function. The attribute bits are same as the specification of "crt_settextattr" fucntion. Refer the description of "crt_settextattr" functioin. [Example] The following program reads the attribute of the character at (3rd-line, 30th-column) of the screen. #include <stdio.h> #include <crt.h> void example( void ) { unsigned int attr ; attr = crt_gettextattr( 3, 30 ) ; printf( "attribute is 0x%04X\n", attr ) ; } -----------------------------------------------------------------------------1.18 Set color palette of VGA characters. <Main> -----------------------------------------------------------------------------[Name] crt_setpalette [Syntax] #include <crt.h> #include <graph.h> int crt_setpalette( unsigned int index, unsigned long color ) ; [Arguments] index color Index of color palette. (0..15,_PAL_COMP,_PAL_RVS) Color value. [Return] Returns zero if successful. If any error (incorrect color palette index or not a VGA display device), returns non-zero value. [Description] Sets the color value to the color palette for character. Specify the color palette index number (0..15) in "index" and the color value in "color". The format of the color value specified in "color" is same as the color value used in a graphic function "_remappalette". (The symbols of the color value defined in the header file "graph.h" such as _98GREEN are available for "color"'s specification.) 32 0 +--------+--------+--------+--------+ |00000000|00BBBBBB|00GGGGGG|00RRRRRR| +--------+--------+--------+--------+ R Red data (Lower byte) G Green data (2nd byte) B Blue data (3rd byte) Each data mean the intensity of each color in range 0x00 - 0x3F. The larger value means more intensity color. The color values of each palettes are initialized at the application start-up as follows. (System initial values) Palette ESC sequence index Color value Displayed color Char Back -------+---------------+---------------+-------------------0 0x00000000 Black 30 40 1 0x0000003F Red 31 41 2 0x00003F00 Green 32 42 3 0x00003F3F Yellow 33 43 4 0x003F0000 Blue 34 44 5 0x003F003F Magenta 35 45 6 0x003F3F00 Cyan 36 46 7 0x003F3F3F White 37 47 8 0x00181818 Gray 1;30 3;40 9 0x000C0C1C Dark Red 1;31 3;41 10 0x000C1C0C Dark Green 1;32 3;42 11 0x000C1C1C Dark Yellow 1;33 3;43 12 0x001C0C0C Dark Blue 1;34 3;44 13 0x001C0C1C Dark Magenta 1;35 3;45 14 0x001C1C0C Dark Cyan 1;36 3;46 15 0x00282828 Dark White 1;37 3;47 While "Without brightness conversion" (CRT_MODE_MONO) is specified by "crt_setmode" function, the palette index 0 is initialized as 0x00000000 and all of the other palettes as 0x003F3F3F. In the above table, for example, output "ESC [43;1;31m" to print dark red characters on the yellow background. Once "low intensity (dark)" mode is set by "ESC [1m" or "ESC [3m", all of the following color specifications are assumed to be low intensity. For example, printf( "\033[1;31mDARK RED\n" ) ; // Dark Red. printf( "\033[34mDARK BLUE\n" ) ; // Blue. printf( "\033[22;34mBLUE\n" ) ; // Cancel low intensity, // Blue. this displays DARK RED DARK BLUE BLUE <-- Dark Red. <-- Dark Blue. <-- Blue. To dispay normal intensity color after once low intensity mode was specified, cancel low intensity mode positively. (similarly about background color.) For LCD device, the lower 2 bits of each color are masked. That is, 0x00,0x04,0x08,..,0x3C are valid setting value for each color. Even if the application program specifies "1" at the lower 2 bits, the VGA firmware masks them. (In this case, max.4,096 colors are representable.) The color values set by the C application program are effective to only the C user screen. The other screens such as the CNC's screen are not affected by this setting. Similarly, the color setting in the other screens are not effective to the C user screen. The color palettes used for graphics are different from the palettes for characters, they are not affected by this function's setting. Use "remappalette" or "_remapallpalette" function to set the color palettes for graphics. It is possible to set the priority of the palette of characters and graphics by specifying "_PAL_COMP" in "index". In this case, specify the palette priority in "color". color Palette priority ---------------+----------------------CRT_PAL_COMP Composite (default) CRT_PAL_CHAR Character over graphics CRT_PAL_GRPH Graphics over character "Composite" means that the intensity of each color of character and one of graphic pixel are mixed. (logical OR). For example, in case that Character color Graphic color R/G/B = 0x30/0x00/0x20 R/G/B = 0x00/0x20/0x38 Composite color R/G/B = 0x30/0x20/0x38 is output on the screen. The displayed colors on the screen are for each setting as follows. Character Graphics palette index palette index Dot color ---------------+---------------+---------------+---------------Composite 0 0 Composite color Not 0 0 Composite color 0 Not 0 Composite color Not 0 Not 0 Composite color ---------------+---------------+---------------+---------------Character 0 0 Graphic color over Graphics Not 0 0 Character color 0 Not 0 Graphic color Not 0 Not 0 Character color ---------------+---------------+---------------+---------------Graphics 0 0 Character color over Character Not 0 0 Character color 0 Not 0 Graphic color Not 0 Not 0 Graphic color This table indicates that the palette index 0 is the special part for overlapping the character and the graphics. Allocate "Black" to the palette 0 as same as initial value so far as there are no exceptional reasons. It is possible to specify "Normal" or "Reverse" display for the monochrome LCD by specifying "_PAL_RVS" in "index". In this case, specify "Normal"/"Reverse" in "color". color Setting Display(Standard) ---------------+-----------------------+--------------------CRT_PAL_RVS Reverse (default) Black char on white. CRT_PAL_NML Normal White char on black. This setting is effective to only monochrome LCD. It is impossible to change the display condition of CRT or color LCD. This setting is effective to only the C user screen. The other screens (such as the CNC's screens) are not affected by this setting. -----------------------------------------------------------------------------1.19 Set all color palette of VGA characters. <Main> -----------------------------------------------------------------------------[Name] crt_setallpalette [Syntax] #include <crt.h> #include <graph.h> int crt_setallpalette( unsigned long *colors ) ; [Arguments] colors Pointer to the color value array. [Return] Returns zero if successful. If any error (not a VGA display device), returns non-zero value. [Description] Sets the color values to the all color palette for character. Store 16 color values in "color". The format of the color value is same as data used in "crt_setpalette" function. This function stores 16 color values to the all 16 color palettes, and set the palette priority as "Composite". This function doesn't affect the color palettes of the other screen and the color palettes of graphics. All palette are set as the system initial values by specifying NULL in "color". The system initial values is listed in the description of "crt_setpalette" function. -----------------------------------------------------------------------------1.20 Get color palette of CNC screen. <Main> -----------------------------------------------------------------------------[Name] crt_getcncpalette [Syntax] #include <crt.h> int crt_getcncpalette( unsigned long *cnccol ) ; [Arguments] cnccol Color palette table of CNC screen. (32 elements) [Return] Returns zero if successful. If any error (one of following cases), returns non-zero value. - Not VGA display device. [Description] Gets the color palette setting values of the CNC screen. This function is used to display the user's screen with the same color as the CNC's screen or to get the colors of the base CNC screen by the window task. The color palette values of the CNC screen are stored in "cnccol" as follows cnccol[0] - cnccol[15] Color palette No.0 through 15 for character. cnccol[16] - cnccol[31] Color palette No.0 through 15 for graphics. The format of color value is same as "crt_setpalette" function. The color value got by this function is used in "crt_setallpalette" and "_remapallpalette" function as it is, like this; crt_setallpalette( &cnccol[0] ) ; _remapallpalette( &cnccol[16] ) ; Color palette of the CNC screen both for character and for graphics is set as follows. Palette index Color --------------+--------------0 Black 1 Red 2 Green 3 Yellow 4 Blue 5 Magenta 6 Cyan 7 White 8 Dark Gray 9 Dark Green 10 Dark Blue 11 Dark Magenta 12 Light Gray 13 Black 14 Dark Cyan 15 Light Gray Take care of palette index handling when VGA window screen is overlapped on any CNC screen by the window task. [Example] The following program sets all color palettes as same as the CNC's screen. #include <crt.h> #include <graph.h> void example( void ) { unsigned long cnccol[32] ; if ( !crt_getcncpalette( cnccol ) ) { crt_setallpalette( &cnccol[0] ) ; _remapallpalette( &cnccol[16] ) ; } } -----------------------------------------------------------------------------1.21 Output character string by FANUC character code. <Main> -----------------------------------------------------------------------------[Name] crt_fstr [Syntax] #include <crt.h> int crt_fstr( unsigned int *code, unsigned int len ) ; [Arguments] code len Array of FANUC character code ( 0x0000 - 0xffff ). Length of the character string. [Return] Returns always zero. [Description] Outputs a character string that is included in FANUC character set and is specified by FANUC character code on the current cursor position. Store "len" of FANUC code (16-bit) for each half-size character in an array "code". Store the character string length in "len". The behavior of this function is equivalent to the following program. (This function is faster to display.) unsigned int i ; for ( i = 0 ; i < len ; i++ ) crt_fchar( code[i] ) ; [Example] The following program displays an icon of a tester on the current cursor position. #include <crt.h> void example( void ) { static unsigned int tester[] = { 0x1E64, 0x1E65, 0x1E66, 0x1E67 } ; crt_fstr( tester, sizeof( tester )/sizeof( unsigned int ) ) ; } -----------------------------------------------------------------------------1.22 Get text data from VRAM. <Main> -----------------------------------------------------------------------------[Name] crt_gettextimg [Syntax] #include <crt.h> int crt_gettextimg( unsigned int y1, unsigned int len x1, unsigned int y2, unsigned int len x2, unsigned long *buf ) ; [Arguments] y1 x1 y2 x2 buf Left,upper position of the area from where characters are got. Left,lower position of the area from where characters are got. Right,lower position of the area from where characters are got. Right,upper position of the area from where characters are got. Area that characters data are stored. [Return] Returns zero when terminated normally, not zero when error, i.e. specified coordinates is not correct, is occurred. [Description] Gets character codes, displayed on the screen, with their attribute. This function is used with the function "crt_puttextimg" to backup or restore the text image on the screen. y1,x1 is top,left, y2,x2 is bottom,right position of the area from where characters are got as follows. (The top of left side shows raw-1, and column-1.) +-----------------------------------+ |(1,1) Full screen | | | | +-------------------+ | | |(y1,x1) | | | | | | | | | | | | | | | | (y2,x2)| | | +-------------------+ | | Area for getting character | | | | | | (ymax,xmax)| +-----------------------------------+ ymax=30, xmax=80 All character codes and their attributes, included the rectangular area that is enclosed by (y1,x1)-(y2,x2),can be got. (The characters which are enclosed in above area)*4 bytes area must be reserved as "BUF". The data form, stored in "BUF", is as follows. Upper word Lower word +-----------------+-------------------+ | Attribute | Character code | +-----------------+-------------------+ The character code is FANUC character code, and the type of the attribute is explained the same as that of "crt_settextattr". The position on the memory is corresponding to the position on the screen as follows. Position on the memory Position on the screen -------------------------------+--------------------------buf+0 y1 , x1 (Top,left) buf+1 y1 , x1+1 : : buf+(x2-x1) y1 , x2 buf+(x2-x1)+1 y1+1 , x1 : : buf+(x2-x1+1)*(y2-y1+1)-1 y2 , x2 (Bottom,right) [Example] The following program backs up and restores the displayed characters of upper 3 rows on the 14 inch screen. #include <crt.h> #include <stdlib.h> void example( void ) { unsigned long *buf ; /* allocate (3-line)*(80-column)*(4-byte) buffer */ buf = (unsigned long *)malloc( 3*80*4 ) ; /* get text image */ crt_gettextimg( 1, 1, 3, 80, buf ) ; ...... (another process) /* restore text image */ crt_puttextimg( 1, 1, 3, 80, buf, 0 ) ; /* free buffer */ free( buf ) ; } -----------------------------------------------------------------------------1.23 Put text data into VRAM. <Main> -----------------------------------------------------------------------------[Name] crt_puttextimg [Syntax] #include <crt.h> int crt_puttextimg( unsigned int y1, unsigned int len x1, unsigned int y2, unsigned int len x2, unsigned long *buf, unsigned int op ) ; [Arguments] y1 x1 y2 x2 buf op Left,upper position of the area where characters are put. Left,lower position of the area where characters are put. Right,lower position of the area where characters are put. Right,upper position of the area where characters are put. Area that characters data are stored. The way to put characters or attributes into VRAM. [Return] Returns zero when terminated normally, not zero when error, i.e. specified coordinates is not correct, is occurred. [Description] Puts character codes on the screen, with their attribute. This function is used with the function "crt_gettextimg" to back up or restore the text image on the screen. y1,x1 is top,left, y2,x2 is bottom,right position of the area into where characters are put. (The top of left side shows raw-1, and column-1.) This position specification is same as "crt_gettextimg" function. Character codes and their attributes are read out from "buf" where is regarded that the data, got by "crt_gettextimg" function, exist. The data, got by "crt_gettextimg" function, is put on the screen usually but it is also possible to put originally prepared data if they have the same type as the data, got by "crt_gettextimg" function. It is possible to put the data, got by "crt_gettextimg" function, into the different area from where they are got, if the size of the rectangular area is the same. Put data is selected from character codes or attributes or both of them by "op" as follows. op Put Data -------+------------------------------0 Character codes and attributes 1 Character codes 2 Attributes [Example] The following program makes the characters and attributes that are displayed on the specified area to move to right by 3 digit. #include <crt.h> #include <stdio.h> #include <stdlib.h> void example( unsigned int y1, unsigned int x1, unsigned int y2, unsigned int x2 ) { unsigned long *buf ; unsigned int i ; buf = (unsigned long *)malloc( (y2-y1+1)*(x2-x1+1)*4 ) ; crt_gettextimg( y1, x1, y2, x2, buf ) ; crt_puttextimg( y1, x1+3, y2, x2+3, buf, 0 ) ; free( buf ) ; /* erase disused characters */ for ( i = y1 ; i <= y2 ; i++ ) printf( "\033[%u;%uH ", i, x1 ) ; } -----------------------------------------------------------------------------1.24 Select graphic page to use. <Main> -----------------------------------------------------------------------------[Name] crt_setgraphpage [Syntax] #include <crt.h> int crt_setgraphpage( int page ) ; [Arguments] page Graphic page number to use. (0, 1 or -1) [Return] Returns zero if successful. If any error (i.e. invalid page number was specified), returns non-zero value. [Description] Select graphic page to use for graphic drawing. The graphic system of FS30i has two pages for graphic drawing. "_setactivepage" and "_setvisualpage" functions select graphic page for drawing and displaying. "_setvideomode" function initializes both two pages. This function selects the page that is initialized by "_setvideomode" function. Specify one of 0, 1 and -1 in "page". Each value means as follows. page behavior of "_setvideomode" function -------+--------------------------------------------------0 initializes only page #0, sets display/draw page=#0 1 -1 initializes only page #1, sets display/draw page=#1 initializes both page #0 and #1 (default), sets display/draw page=#0 When "_setvideomode" function initializes one of page #0 and #1, the contents of the other page are kept. This function affects only behavior of "_setvideomode" function which is called after calling of this function. Even if any value is specified by this function, you can specify an arbitrary page number in "_setactivepage" and "_setvisualpage" function. By calling this function with "page=1", both drawing and displaying pages are set as #1 after calling "_setvideomode" function. With "page=0" or "page=-1", both drawing and displaying page are #0. [Example] The following program draws graphics using only graphic page #1. #include <crt.h> #include <graph.h> void example( void ) { if ( crt_opengr() == 1 ) { crt_setgraphpage( 1 ) ; _setvideomode( _VRES16COLOR ) ; } << Calling graphic function >> crt_closegr() ; } -----------------------------------------------------------------------------1.25 Select drawing method of 6x sized character. <Main> -----------------------------------------------------------------------------[Name] crt_set6chmode [Syntax] #include <crt.h> int crt_set6chmode( int mode ) ; [Arguments] mode Drawing method of 6x sized character. 0: High speed mode 1: Complete mode [Return] 0 1 2 Successful. Invalid value (other than 0 and 1) is specified. Ineffective in the current display mode. [Description] Selects drawing method of 6x sized character. This function selects the drawing method of 6x sized character that is displayed over "CNC screen display function" application program on PC side of FS300i. Specify one of the followings. mode = 0 High speed mode (default). This is effective for displaying the frequently updated information such as the current position of NC using 6x sized character. The character is updated without flicker. mode = 1 Complete mode. Each elements of 6x sized character are individually drawn. Normally "High speed mode" of the default setting is used. Use "Complete mode" in case of following. * The text window displayed by "win_***" functions overlaps 6x sized characters drawn over the base screen. In this case, any elements of 6x sized character which adjoins the window border may not be drawn correctly. To avoid this, select "Complete mode" by this function. This setting is not effective for NC side screen. 6x sized character is always drawn by "Complete mode" on NC side screen. Setting by this function is effective to all 6x sized character drawing until terminating the current "CNC screen display function" session. Setting by this function is effective to drawing method of 6x sized character on the text screen by "printf" function etc., not effective to 6x sized character drawing by graphic functions. [Remarks] This function is available only with the CNC screen display function at the PC side on the FS300i system. -----------------------------------------------------------------------------1.26 Select saving method of graphic contents. <Main> -----------------------------------------------------------------------------[Name] crt_setgsvmode [Syntax] #include <crt.h> int crt_setgsvmode( unsigned int flag ) ; [Arguments] flag CRT_GSV_SAVE0 CRT_GSV_SAVE1 CRT_GSV_SAVE01 CRT_GSV_NOSAVE Save contents of page #0. Save contents of page #1. Save contents of page #0 and #1. Not save any contents. [Return] 0 1 2 Successful. Invalid value of "flag". Insufficient memory for graphic contents. [Description] Selects whether graphic contents are saved or not. Graphic contents drawn by the application program on C-EXE screen will be cleared if the NC software draws any graphics after switching to NC screen. This is due to that the graphic buffer is shared by all softwares on the NC equipment. The application program must draw the graphics again after switching the screen. If you select "Save graphic contents" by this function, the graphic contents will be saved and restored every time the screen is switched between NC and C-EXE. The screen switching procedure executes the following process under selected "Save graphic contents" by this function. * C-EXE -> NC (1) Save contents of text screen. (2) Save contents of graphic page into memory if "crt_opengr()" function has been executed. (3) Save graphic environment. * NC -> C-EXE (1) Restore contents of text screen. (2) Execute equivalent process to "crt_opengr()". (3) Execute equivalent process to "_setvideomode()". (4) Restore graphic environment. (5) Restore saved contents of graphic page. After this process, the application program can continue to draw any graphics without reconfigure graphic environment. The following memory is required to save contents of graphic page. 16-color mode 256-color mode Approx. 150KB per page. Approx. 300KB per page. Required memory is allocated when "Save graphic contents" is specified by this function. Memory area is provided from free memory region of DRAM memory allocated for C Executor. Therefore, you must include this graphic data area for calculating DRAM size of C Executor. After changing graphic drawing mode (16/256-color), this function's setting is ineffective ("Not save graphic contents" is forcibly selected). Screen switching with saving/restoring graphic data takes more time than ordinary case. Saving/restoring graphic data of one page takes approx. 0.5 ... 1 second Only graphic contents drawn in the base screen are saved. Graphic contents drawn in the VGA window are not saved. Saving/restoring graphic contents is not available for FS300i (both "CNC equipment with PC function type" and "Connected via HSSB/ Ethernet type"). 2. Multiple window display library -----------------------------------------------------------------------------2.1 Open window. <Main> -----------------------------------------------------------------------------[Name] win_open [Syntax] #include <crt.h> whandle win_open( winfo *spec, char *title, int flag ) ; typedef int whandle ; typedef struct _winfo { unsigned int posl ; unsigned int posc ; unsigned int sizev ; unsigned int sizeh ; } winfo ; [Arguments] spec title flag /* window handle */ /* /* /* /* window window window window line position */ column position */ vertical size */ horizontal size */ window geometry(position& size) structure window title string window attribute [Return] Returns window handle if successful. When failed, returns "-1" and sets following error code to the global variable "errno". EW_SPEC Invalid window position or size is specified. EW_MAX Attempted to open a window beyond the limit of maximum number of windows(MAX-WIN). [Description] Creates new window on the screen. A window of the specified size is created and placed on the screen at the specified position. Values set for each member of the structure "spec" are as follows.. posl posc sizev sizeh line number of the upper left corner of the window ( >=2) (top line of the screen being "1") column number of the upper left corner of the window ( >=2) (left-most column of the screen being "1") number of lines of the window ( >=1) number of columns of the window( >=1) (=number of single byte characters per window) +-----------------------------------------------+ | Full screen |<- Line 1 | | | +--------------------------------+ | | |#<-(posl,posc) ^ window| | | | | | | | | | | | | | | | | | | | sizev | | | | | | | | |<------------------+----------->| | | | sizeh | | | | | | | | | | | | | | | v | | | +--------------------------------+ | | ^ | | Window frame | | |<- Line N +-----------------------------------------------+ ^ ^ Column 1 Column M N=30,M=80 Specify window title string by the argument "title". The length of the window title string should be less than 32 single byte characters. (single byte alpha-numeric and Katakana characters, symbols and double byte alpha-numeric, Hirakana, Kanji characters and symbols can be used.) Specify one of the following window attributes by the argument "flag". ( "0" is equivalent to WIN_F_FULL.) WIN_F_FULL WIN_F_FRM0 WIN_F_FRM1 Full screen window Frame line style: Normal (Thin line) Frame line style: Bold WIN_F_FRM2 Frame line style: White space (When using this mode, specify reverse attribute for frame color by win_col() function.) Frame line style: User defined line (define line style by win_setfrm() function) Frame-less window: Window size of the frame-less window can be expanded to full screen size, without specifying WIN_F_FUL attribute. WIN_F_FRM3 WIN_F_NOFRM A new window is placed over existing windows and both screen output and key input are bound to this window (active window). When new window is opened, cursor is placed on the upper-left corner (home position) of the window and cursor display attribute is set to non-display state. While more than one windows are open, access to the screen areas other than window areas is disabled. Generally, full screen should be cleared before opening the first window, or the first window should be full-screen window. When opening windows over the usual screen display, display the base usual screen in the full-screen window. Calling this function at the start of the application program as shown in the following example will do this. winfo mainwin ; whandle win_main ; mainwin.posl = 2 ; mainwin.posc = 2 ; mainwin.sizev = 23 ; mainwin.sizeh = 78 ; win_main = win_open( &mainwin, "Main Window", WIN_F_FULL ) ; -----------------------------------------------------------------------------2.2 Close window. <Main> -----------------------------------------------------------------------------[Name] win_close [Syntax] #include <crt.h> int win_close( void ) ; [Arguments] -----[Return] Returns zero if successful. When failed, returns "-1" and sets following error code to the global variable "errno". EW_CLOS E no open window [Description] Close active window. When the last window is closed, screen display returns to the default screen state where no windows are open. Otherwise, the window underneath the closed window become active and whole screen is redrawn. -----------------------------------------------------------------------------2.3 Select window. <Main> -----------------------------------------------------------------------------[Name] win_select [Syntax] #include <crt.h> int win_select( whandle handle ) ; [Arguments] handle window handle of the window to be selected [Return] Returns zero if successful. When failed, returns "-1" and sets following error code to the global variable "errno". EW_NOTOPEN specified window not exist [Description] Select one of the open windows on the screen for display window. After this function is called and a window is selected, all succeeding screen output is drawn on the selected window. This function does not change the overlapping order of the window. When window is selected by this function, former cursor position of that window is restored. -----------------------------------------------------------------------------2.4 Activate window. <Main> -----------------------------------------------------------------------------[Name] win_activate [Syntax] #include <crt.h> int win_activate( whandle handle ) ; [Arguments] handle window handle for the window to be activated [Return] Returns zero if successful. When failed, returns "-1" and sets following error code to the global variable "errno". EW_NOTOPEN specified window not exist [Description] Select one of the open windows on the screen for keyboard input. After this function is called, succeeding input from MDI keyboard is valid only while the window is selected for display by win_select(). The window selected by this function is also selected as display window. This function changes the overlapping order of the windows so that the selected window comes on top of other windows. Whole screen is redrawn by this function call. -----------------------------------------------------------------------------2.5 Move window. <Main> -----------------------------------------------------------------------------[Name] win_move [Syntax] #include <crt.h> int win_move( int dy, int dx ) ; [Arguments] dy dx vertical displacement horizontal displacement [Return] Returns zero if successful. When failed, returns "-1" and sets following error code to the global variable "errno". EW_DISP invalid displacement specified [Description] Move active window . Whole screen is redrawn after the window is moved. Overlapping order does not change. Displacement value which would cause whole or a part of the window to be off the screen cannot be specified. -----------------------------------------------------------------------------2.6 Alter window size. <Main> -----------------------------------------------------------------------------[Name] win_size [Syntax] #include <crt.h> int win_size( int dy, int dx ) ; [Arguments] dy dx vertical expansion/reduction value horizontal expansion/reduction value [Return] Returns zero if successful. When failed, returns "-1" and sets following error code to the global variable "errno". EW_DISP invalid size value specified [Description] Change active window size. Window size expansion or reduction takes place so that the bottom or the right side border is moved by the specified value relative to the upper-left corner of the window. The size expansion value which would cause a part of the window to be off the screen cannot be specified. Also the size reduction value which would shrink the window less than the size of 1 line/1 column cannot be specified. After the window size is expanded or reduced, whole screen is redrawn. Win_size() does not change overlapping order of the windows. -----------------------------------------------------------------------------2.7 Let active window be full screen size. <Main> -----------------------------------------------------------------------------[Name] win_full [Syntax] #include <crt.h> int win_full( void ) ; [Arguments] -----[Return] Returns zero if successful. When failed, returns "-1" and sets following error code to the global variable "errno". EW_CHANGE specified window is already in full screen window mode [Description] Let the size of the active window be full screen size. Full screen window is placed underneath all other open windows. -----------------------------------------------------------------------------2.8 Let active window be window size. <Main> -----------------------------------------------------------------------------[Name] win_window [Syntax] #include <crt.h> int win_window( void ) ; [Arguments] -----[Return] Returns zero if successful. When failed, returns "-1" and sets following error code to the global variable "errno". EW_CHANGE specified window is not a full screen window [Description] Active full screen window is shrunk to be a normal window. Size and position of the shrunk window is that of original window before being expanded to be full size window. Win_windows() redraws whole screen. -----------------------------------------------------------------------------2.9 Get window information. <Main> -----------------------------------------------------------------------------[Name] win_info [Syntax] #include <crt.h> int win_info( whandle handle, winfo *spec ) ; [Arguments] handle spec window handle of the target window pointer to the window geometry(size&position) structure [Return] Returns zero if successful. When failed, returns "-1" and sets following error code to the global variable "errno". EW_NOTOPEN specified window not exist [Description] Get the position and size of the specified window. Position and size is set to the corresponding member of the structure "spec". -----------------------------------------------------------------------------2.10 Set color of window frame and title string. <Main> -----------------------------------------------------------------------------[Name] win_col [Syntax] #include <crt.h> void win_col( int colf, int colt, int colh, int colfa, int colta, int colha ) ; [Arguments] colf colt colh colfa colta colfa [Return] ------ window window window active active active frame color title color handle color window frame color window title color window handle color [Description] Set color for window frame and window title string. Specify colors and attribute for each argument as follows. 15 8 7 0 +------------------------+------------------------+ | 0 0 0 Ib Bb Gb Rb I | B G R r b 0 0 0 | +------------------------+------------------------+ B: Blue r: Reverse video G: Green b: Blink R: Red I: Low intensity Bb:Background Blue Gb:Background Green Rb:Background Red Ib:Background Low intensity Valid color value is as follows. Black Red Green Yellow Blue Magenta Cyan White normal 0x0000 0x0020 0x0040 0x0060 0x0080 0x00a0 0x00c0 0x00e0 reverse 0x0010 0x0030 0x0050 0x0070 0x0090 0x00b0 0x00d0 0x00f0 blink 0x0008 0x0028 0x0048 0x0068 0x0088 0x00a8 0x00c8 0x00e8 reverse+blink 0x0018 0x0038 0x0058 0x0078 0x0098 0x00b8 0x00d8 0x00f8 Actually, 4-bits of "IRGB" and "IbRbGbBb" indicate the palette index number of character and background. If "0x000" is specified for the window handle, it will not be displayed. Colors and attributes set by this function are applied to the window frames, titles or window handles which are displayed after this function call. Colors or attributes of those already displayed when this function is called is not affected. To change them, redraw the window by calling functions to move, change size or hide/show the window. This function affects all windows. -----------------------------------------------------------------------------2.11 Hide window. <Main> -----------------------------------------------------------------------------[Name] win_hide [Syntax] #include <crt.h> int win_hide( whandle handle ) ; [Arguments] handle window handle for the window to be hidden [Return] Returns zero if successful. When failed, returns "-1" and sets following error code to the global variable "errno". EW_NOTOPEN specified window not exist [Description] Win_hide() hides specified window. Hidden window continues to be invisible until it is shown again by win_show() function. Overlapping order of other windows is not changed. Even while a window is hidden, data can be written in the window by selecting the window by win_select(). Calling this function redraws whole screen. -----------------------------------------------------------------------------2.12 Show window. <Main> -----------------------------------------------------------------------------[Name] win_show [Syntax] #include <crt.h> int win_show( whandle handle ) ; [Arguments] handle window handle of the window to be hidden [Return] Returns zero if successful. When failed, returns "-1" and sets following error code to the global variable "errno". EW_NOTOPEN specified window not exist [Description] Windows hidden by win_hide() function become visible by this function. Overlapping order of the windows is not changed. Calling this function redraws whole screen. -----------------------------------------------------------------------------2.13 Set window title string. <Main> -----------------------------------------------------------------------------[Name] win_setttl [Syntax] #include <crt.h> int win_setttl( whandle handle, char *title ) ; [Arguments] handle title window handle of the window whose title string is to be changed window title string [Return] Returns zero if successful. When failed, returns "-1" and sets following error code to the global variable "errno". EW_NOTOPEN specified window not exist [Description] Change title string for a window. The length of the window title string should be less than 32 single byte characters. (single byte alpha-numeric and Katakana characters, symbols and double byte alpha-numeric, Hirakana, Kanji characters and symbols can be used.) Calling this function redraws whole screen. -----------------------------------------------------------------------------2.14 Set window frame line character. <Main> -----------------------------------------------------------------------------[Name] win_setfrm [Syntax] #include <crt.h> void win_setfrm( unsigned int *frame ) ; [Arguments] frame character code array which defines window frame line style [Return] -----[Description] Set user defined line style for window frame. Set the FANUC character code for each window frame line to the argument "frame" in the following order(horiz.-0, horiz.-1, vert.-2, vert.-3, upper-left corner-4......). [4]-----[0]-----[6] | | | | [2] [3] | | | | [5]-----[1]-----[7] For example, following character cord array is to be specified to set usual frame line. unsigned char waku[] = { 0x01ED,0x01ED,0x01EE,0x01EE, 0x01EC,0x01EA,0x01E6,0x01E8 } ; Window frame lines set by this function are applied to the windows which are opened with WIN_F_FRM3 attribute after this function call. Frame lines of those windows already opened with WIN_F_FRM3 attribute are changed to the specified style when they are redrawn. The line style set by this function is applied to all windows with WIN_F_FRM3 attribute. -----------------------------------------------------------------------------2.15 Get window display status. <Main> -----------------------------------------------------------------------------[Name] win_getstat [Syntax] #include <crt.h> void win_getstat( struct winstat *stat ) ; struct winstat { whandle selected ; whandle unsigned int unsigned int /* Window handle of the currently selected window*/ active ; /* Window handle of the currently active window. */ numwin ; /* Number of opened window. */ winstack[MAX_WIN] ; /* Stacking order of opened windows. */ } ; [Arguments] stat Windows status information. [Return] -----[Description] Gets the current window display status. The window handle the currently selected window and the currently active window are stored in each "stat.selected" and "stat.active". The number of the currently opend windows is stored in "stat.numwin". The number in "stat.numwin" includes the windows hidden by "win_hide" function. The stacking order of the all opened windows is stored in "stat.winstack". The handles of all of the opened windows are stored like this, the window handle of the top window is stored in "winstack[0]", the next in "winstack[1]". For example, three windows are opened now as below. This function returns the following result. +[1]-------------+ |Selected | +[2]---| | | | | | | +[3]-------------+ | | |Active | | +------| | | | | | | | +-------------| | +----------------+ stat.selected = 1 stat.active = 3 stat.numwin = 3 stat.winstack[0] = 3 stat.winstack[1] = 1 stat.winstack[2] = 2 (stat.winstack[3] and later are undefined.) When "stat.numwin" = 0, that is, no window is opend, the contents of "selected", "active" and "winstack" are undefined. [Example] The following program tests if the currently active window is selected or not, then, if not, selects it. #include <crt.h> void example( void ) { struct winstat stat ; win_getstat( &stat ) ; if ( ( numwin != 0 ) && ( stat.selected != stat.active ) ) win_select( stat.active ) ; } -----------------------------------------------------------------------------2.16 Redraw windows. <Main> -----------------------------------------------------------------------------[Name] win_redraw [Syntax] #include <crt.h> void win_redraw( void ) ; [Arguments] -----[Return] -----[Description] Redraws all opening windows. This function just redraw the opening and displayed window keeping the current window status (open/close, displayed/hidden, overlapping order of windows). This function does nothing when no window is opened. When the screen has been switched from/to NC side and PC side on "CNC screen display function", use function to redraw windows. 3. User defined character library 3-1. scope User defined character is a character which is defined by machine tool builders. (usually referred to as extended character) C Executor allows the user application program to define and use extended characters. Up to 256 single byte characters can be defined and registered. Arbitrary character code in single byte character set dedicated for user defined characters or in standard JIS Kanji character set can be assigned to the registered extended character. 3-2. Character dot pattern * Dot pattern size single byte character 2-byte character 8 dots |<-------->| +----------+ | | | | | | | | | | | | | | | | | | +----------+ 16 dots |<----------------->| +-------------------+ | | | | | | | | | | | | | | | | | | +-------------------+ ^ | | | |16 dots | | | v - ^ | | | |16 dots | | | v - 2-byte character is composed of two consecutive single byte character patterns. * Binary notation Horizontally aligned 8 bits(dots) are represented by one byte data. Single byte character bit order-> #7 #0 +----------+ | byte 1 | | | | | | | | | | | | | | | | | | | | v | | byte 16 | +----------+ 2-byte character #7 #0 #7 #0 +-------------------+ | byte 1 | byte 17 | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | v | v | | byte 16 | byte 32 | +-------------------+ * Example - Single byte character 'A' pattern Binary notation ........ ........ ........ ..###... .#...#.. #.....#. #.....#. #.....#. #######. #.....#. #.....#. #.....#. ........ ........ ........ ........ 0x00,0x00,0x00,0x38,0x44,0x82,0x82,0x82, 0xFE,0x82,0x82,0x82,0x00,0x00,0x00,0x00 - 2-byte character ("KAN" of Japanese KANJI character) pattern Binary notation ................ .......#...#.... .##..#########.. ...#...#...#.... ......#######... .##...#..#..#... ...#..#######... .........#...... ...#..#######... ...#.....#...... ...#.#########.. ..#.....#.#..... ..#....#...#.... .##..##.....##.. ................ ................ 0x00,0x01,0x67,0x11,0x03,0x62,0x13,0x00, 0x13,0x10,0x17,0x20,0x21,0x66,0x00,0x00, 0x00,0x10,0xFC,0x10,0xF8,0x48,0xF8,0x40, 0xF8,0x40,0xFC,0xA0,0x10,0x0C,0x00,0x00 3-3. Character code (1) FANUC code Character codes from 0x4100 to 0x41FF in FANUC code set are reserved for user defined characters and automatically assigned to the user defined character in the order of its registration. In case of 2-byte characters, two consecutive codes are assigned to a 2-byte character, one for left half of the dot pattern and the other for the right half, where the latter code being the former plus one. The registered user defined characters can be accessed and displayed on the screen by using FANUC code. (2) JIS code Also, JIS code can be assigned to the registered user defined characters. Available codes are, from 0x20 to 0xDF for single byte characters and from 0x8140 to 0xEFDF shift JIS codes for 2-byte characters. The above single byte character codes are those in single byte user defined character mode that can be selected by the sequence "ESC (8" . In case of 2-byte characters, one of the following two methods can be employed. (1) When registering the JIS Kanji characters ,which are not included in the FANUC Kanji character set, as user defined characters. Assuming that the character "TORA" ,not included in the FANUC Kanji character set, is to be displayed on the screen , make dot pattern for the character, register it as an user defined character, and assign the standard shift JIS code for the character "TORA" (0x8CD5) to it. Thus, printing "TORA" by using printf() function as usual will display the character "TORA" on the CNC screen. (2) When registering new characters. When registering new characters which are not included in the standard JIS Kanji character set, any shift JIS code can be assigned to the characters. However, considering future expansion of the FANUC Kanji character set, it is recommended to assign the codes greater than 0xEB9F which are not used in Standard JIS Kanji character set. 3-4. How to register user defined characters (1) Making dot pattern for a character Make dot pattern of the user defined character referring to the section 3.2. (2) Binary notation of the user defined character After making dot patterns for all user defined characters, describe them in binary notation and store in an unsigned character string. (Example) unsigned char char_pattern[] = { 0x00, 0x03, .... } ; Whole character patterns for all user defined characters to be registered have to be stored in one unsigned character string. User defined characters cannot be registered separately. They can only be registered all characters at one time. Put this character string in the user application program. (3) Procedures in user application program Register the user defined characters by using crt_reguserchar() function. And assign JIS codes to the characters by using crt_mapuch() function if necessary. These procedures should be executed before any of the user defined characters are referred to in the user application program. Also, once these procedures are executed, registered character set will never be changed or modified by screen switching command or the like. 3-5. How to use user defined characters (1) Specifying the character by the FANUC code Registered user defined characters can be displayed by using crt_fchar() function. The character code given to this function as an argument is the code automatically assigned to the character in the order of its registration (0x4100,..). (2) Specifying the character by JIS code If JIS code is assigned to the user defined character by using crt_mapuch() function, standard character output functions as putchar(), printf(),etc., can be used to display the character. In the case of single byte character, switch the code set to the single byte user character mode by the sequence "ESC (8" to specify the user character. (Example) printf( "\033(8ABC\033(4" ) ; Display user defined characters assigned to the code 0x41, 0x42 and 0x43. "ESC (4" is the sequence to select standard mode. In the case of 2-byte character, directly output the shift JIS code assigned to the user defined character. (Example) printf( "\x93\xC8\x96\xD8" ) ; (This is Japanese string "TOCHI-GI".) If the dot pattern of the character "TOCHI" is registered as an user defined character and the code 0x93C8, which is the shift JIS code for the standard JIS character "TOCHI",is assigned to the character, the character "TOCHI" can be output to the screen as if it were included in the FANUC Kanji character set. printf( "\xEB\xA0" ) ; When the code greater than 0xEB9F (0xEBA0 in this case), which is vacant in shift JIS code area, is assigned, directly specify the code. Function reference ~~~~~~~~~~~~~~~~~~ -----------------------------------------------------------------------------3.1 Register user character. <Main> -----------------------------------------------------------------------------[Name] crt_reguserchar [Syntax] #include <crt.h> int crt_reguserchar( unsigned int number, unsigned char *table ) ; [Arguments] number table the number of registered user defined characters in bytes ( 1-- 256) pointer to the character pattern table [Return] 0 1 normal completion invalid number of user defined characters [Description] Register the character pattern of the user defined character. After the execution of this function, user defined characters will become available for the user application program. Character pattern table must be statically allocated. Such kind of usage that storing the character pattern table in the memory area reserved by the malloc() function, specifying the table as an argument of this function, and after that releasing the memory area by free() function, is not allowed. The character pattern table should be defined as, for example, usual constant data array. This is because the character table is sometimes referred to again internally, when re-registration of the character pattern become necessary inside the library as a result of screen switching. -----------------------------------------------------------------------------3.2 Map user character. <Main> -----------------------------------------------------------------------------[Name] crt_mapuch [Syntax] #include <crt.h> int crt_mapuch( unsigned int code, unsigned int ucode ) ; [Arguments] code ucode code to be assigned 0x0020 through 0x00DF for single byte character 0x8140 through 0xEFFF for 2-byte character (limited to those allowed in shift JIS code) FANUC code for the user defined character (0x4100 through 0x41FF) [Return] 0 1 normal completion illegal character code assigned [Description] Assign single byte character code or JIS Kanji code for the user defined character. To put a character on the screen by using the assigned JIS code, select either "ESC (8" mode (single byte mode) or "ESC (B" mode ( 2 bytes mode). This function does not check the validity of the specified character code. Care should be taken not to specify wrong character codes. -----------------------------------------------------------------------------3.3 Get CG pattern. <Main> -----------------------------------------------------------------------------[Name] crt_getcgpttn [Syntax] #include <crt.h> int crt_getcgpttn( unsigned int code, unsigned char *buf ) ; [Arguments] code buf the FANUC code for the character of which the character pattern is to be get buffer area where character pattern is stored ( 16 bytes ) [Return] 0 1 normal completion reading the character pattern is not supported by this version of Hardware [Description] Read the character pattern data stored in the character generator. This function does not check the validity of the specified character code. Care should be taken not to specify wrong character codes. 3-6. Sample application program #define UCH_NUM 10 /* number of defined characters( single byte equivalent) */ /* Character pattern */ unsigned char pattern[ UCH_NUM * CHAR_SIZE_14 ] = { 0x00,0x3F,0x02,0x02,0x02,0x3F,0x22,0x22, /* 0x22,0x22,0x22,0x3F,0x02,0x02,0x02,0x7F, 0x00,0xFE,0x20,0x20,0x20,0xFE,0x22,0x22, /* 0x22,0x22,0x22,0xFE,0x20,0x20,0x20,0xFF, 0x00,0x01,0x3C,0x24,0x24,0x25,0x25,0x25, /* 0x25,0x25,0x25,0x25,0x3C,0x00,0x00,0x03, 0x00,0xFE,0x48,0x48,0x48,0xCE,0x02,0x02, /* 0x02,0x02,0x02,0xCE,0x48,0x48,0x48,0xFF, 0x10,0x10,0x10,0x7E,0x12,0x12,0x12,0x22, /* 0x22,0x24,0x24,0x14,0x08,0x14,0x22,0x41, 0x10,0x10,0x10,0xFE,0x10,0x10,0x10,0xFF, /* 0x00,0x10,0x10,0xFE,0x10,0x10,0x10,0xFF, 0x00,0x3E,0x22,0x22,0x24,0x24,0x28,0x24, /* 0x22,0x22,0x22,0x22,0x3C,0x20,0x20,0x20, 0x00,0xFF,0x02,0x02,0x02,0xFA,0x8A,0x8A, /* 0x8A,0x8A,0x8A,0xFA,0x02,0x02,0x02,0x0E, 0x00,0x00,0x7F,0x00,0x1F,0x10,0x10,0x10, /* 0x1F,0x02,0x04,0x1C,0x64,0x04,0x07,0x1C, 0x80,0x80,0xFF,0x00,0xFC,0x04,0x04,0x04, /* 0xFC,0x80,0x44,0x48,0x30,0x10,0x8C,0x03, } ; 0x4100 */ 0x4101 */ 0x4102 */ 0x4103 */ 0x4104 */ 0x4105 */ 0x4106 */ 0x4107 */ 0x4108 */ 0x4109 */ /* Registering the Character pattern */ crt_reguserchar( UCH_NUM, pattern ) ; /* Assigning character code */ crt_mapuch( 0xEBA0, 0x4100 ) ; crt_mapuch( 0xEBA1, 0x4102 ) ; crt_mapuch( 0xEBA2, 0x4104 ) ; crt_mapuch( 0x41, 0x4106 ) ; crt_mapuch( 0x42, 0x4107 ) ; crt_mapuch( 0x43, 0x4108 ) ; crt_mapuch( 0x44, 0x4109 ) ; /* /* /* /* /* /* /* 2-byte 2-byte 2-byte single single single single character */ character */ character */ byte character byte character byte character byte character */ */ */ */ /* display user defined character */ printf( "\xEB\xA0\xEB\xA1\xEB\xA2" ) ; /* 2-byte character */ printf( "\033(8ABCD\033(4" ) ; /* single byte character */ 4. VGA window display library Outline of VGA window display ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ "VGA window" is an overlapping window provided by VGA display device. This VGA window has the following features. * Overlapping on any arbitrary screen such as CNC, PMC and C-EXE screen. * Both graphics and character overlapping. * Simultaneous updating of the base screen and VGA window screen. * Two independent windows. * Arbitrary size window on arbitrary position. (with a little limitation) * Coexistence with character windows (which displayed by "win_xxx()" functions). Character window is a part of the base screen for VGA window. +---------------------------------------------------+ | Full screen | | | | +--------------------------+ | | |VGA window #0 | | | | | | | | +--------------------+ | | |Also VGA win- |VGA window #1 | | | |dow is over- | | | | |lapped on the | | | | |other window. |Both character and | | | | |graphics are over- | | | +--------------|lapped. | | | | | | | | | | | +--------------------+ | | | | Displaying on the base screen is | | not affected by any VGA window. | +---------------------------------------------------+ Each two VGA windows have their own screen buffers of character and graphics display It is possible to output to the base screen during displaying VGA windows. Output operation to hidden area of the base screen displays nothing to the real screen but writes to the screen buffer memory. When the VGA window closed, all contents of the base screen, including on the hidden area, are output automatically. VGA window has the following restrictions. * Color palettes are common with the base screen. So, if any color palette is changed in the base screen or the VGA window, the corresponding color palette of the other screen is changed. * The control of graphic display enabling/disabling is common with the base screen. So, if the graphic display is disabled in the base screen, the contents of graphics in the VGA window are disabled at the same time. * VGA window is available on only 16-color mode, unavailable on 256-color mode. While the following modes are specified in "_setvideomode()" function, VGA window is unavailable. _98RES16COLOR, _98RES8COLOR, _98RESCOLOR ,_VRES256COLOR * Size and position of VGA window are specified by character size unit. * VGA window size (colomn x line) is limited as follows. Total size of all opened windows <= Full screen size * When the screen mode is changed, all VGA windows are closed automatically. * The VGA window cannot be used together with the CNC subscreen/help screen. To use the VGA window, set parameter NSH(No.8654#0)=1 to hide the subscreen/help screen. * If the VGA window is used, it is impossible to use the debug function of the macro compiler/executor. Set parameter DBG(No.8502#3)=0. Using VGA window ~~~~~~~~~~~~~~~~ Usually VGA window is used in the window task. It is possible to only output to VGA window in the window task. VGA window is used in also the main task. In the following section, usages of VGA window is described for each cases. (A) VGA window display in the window task. Execute the following procedures to display VGA window in the window task. (1) Call "vwin_open()" function to open VGA window. "vwin_open()" function doesn't always succeed. Checking the return value of this function is needed. (2) After successful execution of "vwin_open()" function, it is enabled to output characters to the VGA window. Character display by "printf()" function, etc. is available as same as the ordinary screen. (3) Call "crt_opengr()" and "_setvideomode()" functions to draw graphics. Specify one of following video mode for "_setvideomode()". _98RESS16COLOR, _98RESS8COLOR, _VRES16COLOR, _VRES16EXCOLOR After successful execution of "_setvideomode()" function, it is enabled to draw graphics using graphic functions. (4) Call "vwin_close()" function to close the VGA window after required displays. Don't execute both character and graphics output before calling "vwin_open()" function and after calling "vwin_close()" function. Color palettes are common with the base screen. Changing color palette in the VGA window makes changing the same color palette in the base screen, and vice versa. Especially, take care to change and to refer the color palettes in the VGA window on the CNC and the PMC screen. To get the contents of color palettes in the CNC screen, use "crt_getcncpalette()" function. Also enabling/disabling graphic output status is common with the base screen. Graphic output must always be enable in the base screen for graphic drawing in VGA window. Note, however, that if tool path drawing is underway in tool path drawing or background drawing processing or if a tool path that was drawn before has not been erased, enabling graphics drawing causes the tool path to appear on the CNC screen. Once VGA window is opened, it keeps opened until calling "vwin_close()" function by the application program. (except in case of changing screen mode.) Call "vwin_close()" function positively to close the VGA window by the application program. (B) VGA window display in the main task. The procedures to display VGA window in the main task is basically same as in the window task. There are some differences as follows. (1) Once "vwin_open()" function is called, all of the following output are displayed in the VGA window. (both character and graphics) After closing all VGA window, output is displayed to the base screen again. (2) Various settings about display are taken over between the base screen and the VGA window as they are. Generally, it is necessary to reinitialize the display environment after changing display between the base screen and the VGA winodw. Call "_setvideomode()" function after opening the VGA window, "crt_setmode()" and "_setvideomode()" functions after returning the base window from the VGA window. (3) The opened VGA window is still displayed as it is even if the base screen is changed to another screen (CNC screen, etc.). It is impossible to control the VGA window on the CNC screen by the main task. So, it is beter to disable screen switching during opening the VGA window. How to operate VGA window ~~~~~~~~~~~~~~~~~~~~~~~~~ (1) How to resize VGA window. It is impossible to resize the opened VGA window. Close the VGA window by "vwin_close()" function first, then open with new size specification again. (Redrawing is required.) (2) How to move VGA window. Hide the VGA window by "vwin_hide()" function once, then call "vwin_show()" function with the new position. (3) How to change overlapping order. Hide the VGA window which you want display on the top by "vwin_hide()" function once, then display it by "vwin_show()" with the same position again. Function Reference ~~~~~~~~~~~~~~~~~~ -----------------------------------------------------------------------------4.1 Open VGA window. <Main,Win> -----------------------------------------------------------------------------[Name] vwin_open [Syntax] #include <crt.h> int vwin_open( unsigned int widx, unsigned int posl, unsigned int posc, unsigned int sizev, unsigned int sizeh ) ; [Arguments] widx posl posc sizev sizeh VGA window index. (=0,1) Line number of the upper left corner of VGA window. (the top line in the screen = 0) Column position of the upper left corner of VGA window. (the left-end column in the screen = 0) Line size of VGA window. (=1 - LMAX) Column size of VGA window. (=1 - CMAX) LMAX = 30 CMAX = 80 [Return] 0 Non-0 Successful. Error. (one - Incorrect - Specified - Incorrect - The other of the following cases) window index (widx). window has been already opened. position or size of window. software already uses the VGA window. [Description] Makes a VGA window and displays it on the screen. A VGA window with the specified size is opened and displayed on the screen at the specified position. It is allowed to specify position that a part of the window is put out of the screen. The window created by this function is selected and is put on the other window which is already displayed. After successful execution of this function, the following printing and drawing are output to the window opened by this function until closing this window or the other window is selected. -----------------------------------------------------------------------------4.2 Close VGA window. <Main,Win> -----------------------------------------------------------------------------[Name] vwin_close [Syntax] #include <crt.h> int vwin_close( unsigned int widx ) ; [Arguments] widx VGA window index. (=0,1) [Return] 0 Non-0 Successful. Error. (one of the following cases) - The window specified by "widx" is not opened. [Description] Closes the opened VGA window. The contents of characters and graphics in the window are destroyed. If the other VGA window is opened, that window is selected. When all VGA windows are closed in the main task, the base screen (ordinary screen) is selected. -----------------------------------------------------------------------------4.3 Select VGA window. <Main,Win> -----------------------------------------------------------------------------[Name] vwin_select [Syntax] #include <crt.h> int vwin_select( unsigned int widx ) ; [Arguments] widx VGA window index. (=0,1) [Return] 0 Non-0 Successful. Error. (one of the following cases) - The window specified by "widx" is not opened. [Description] Selects the specified VGA window as the target screen of character and graphics output. After successful execution of this function, the following printing and drawing are output to the window opened by this function until closing this window or the other window is selected. -----------------------------------------------------------------------------4.4 Show VGA window. <Main,Win> -----------------------------------------------------------------------------[Name] vwin_show [Syntax] #include <crt.h> int vwin_show( unsigned int widx, unsigned int posl, unsigned int posc ) ; [Arguments] widx posl posc VGA window index. (=0,1) Line number of the upper left corner of VGA window. (the top line in the screen = 0) Column position of the upper left corner of VGA window. (the left-end column in the screen = 0) [Return] 0 Non-0 Successful. Error. (one of the following cases) - The window specified by "widx" is not opened. - The window specified by "widx" is not hidden window. [Description] Redisplays the invisible VGA window. The specified VGA window is displayed on the specified position again. To move VGA window on the screen, once hide the window by "vwin_hide" function, then display with a new position by this function again. This function doesn't select the specified VGA window. The VGA window redisplyed by this function is put on the top. -----------------------------------------------------------------------------4.5 Hide VGA window. <Main,Win> -----------------------------------------------------------------------------[Name] vwin_hide [Syntax] #include <crt.h> int vwin_hide( unsigned int widx ) ; [Arguments] widx VGA window index. (=0,1) [Return] 0 Non-0 Successful. Error. (one of the following cases) - The window specified by "widx" is not opened. [Description] Hides the specified VGA window. This function makes the opened VGA window invisible with keeping the window's status. It is possible to output characters and graphics to the invisible window. By executing "vwin_show" function to the invisible window, the contents of the window including contents output during being hidden are redisplayed. This function doesn't changes selection status of VGA windows. -----------------------------------------------------------------------------4.6 Get VGA window information. <Main,Win> -----------------------------------------------------------------------------[Name] vwin_info [Syntax] #include <crt.h> int vwin_info( unsigned int widx, struct vwinfo *buf ) ; struct vwinfo { unsigned unsigned unsigned unsigned unsigned int int int int int stat ; posl ; posc ; sizev ; sizeh ; /* /* /* /* /* status */ line position */ column position */ vertical size */ horizontal size */ } ; [Arguments] widx buf VGA window index. (=0,1) Window iformation buffer. [Return] 0 Non-0 Successful. Error. (one of the following cases) - Incorrect window index (widx). [Description] Gets the status information of the specified VGA window. The position, size and status of the specified window are stored into "buf". The meanings of each bit of the status flag "buf.stat" are as follows. bit0 VW_OPEN = 0 Not opened. = 1 Opened. bit1 VW_HIDDEN = 0 Visible. = 1 Invisible. (VW_HIDDEN is effective when VW_OPEN=1.) bit2 - bit15 Undefined. 3.7 File Operation Library ========================== Using Memory Card ~~~~~~~~~~~~~~~~~ The application program can access a memory card which is inserted in the card slot equipped on the LCD/MDI panel of FS30i as a disk device. To read/write a memory card, execute the following procedures. (1) Insert a memory card into the slot. (2) Mount the memory card as a disk device by the application program. (Call "aux_file_mount" function.) (3) Open files using "fopen", "fcreate" function, etc. with drive name "B:". (4) Read/write contents of the memory card using "fgets", "fprintf", "fread", "fwrite", etc. (5) Close the files using "fclose" function. (6) Unmount the memory card. (Call "aux_file_unmount" function.) (7) Remove the memory card from the slot. Supported memory card and format ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Supported memory cards are as follows. PCMCIA or JEIDA compatible 256KB, 512KB, 1MB, 2MB, 4MB S-RAM card. ATA compatible memory card. Logical format of a memory card that this library can handle is MS-DOS format used on the generic MS-DOS Personal computers. C library doesn't support formatting function of a memory card. It can read/write only formatted memory cards. Format memory cards using a personal computer with PC card slots or the boot software of FS30i. [Note] * The drive name to aceess a memory card is "B:". It is fixed. * The C application program can't access the memory card while the other software (CNC software, etc.) is accessing it. * The C application program may fail to access the memory card just after insertion the memory card (for a few minutes). ("aux_file_mount" function returns "EAUTHREJ".) The CNC program causes this problem because it always poring the card slot to detect card insertion. In this case, the application program must retry to access. Lists of Functions ~~~~~~~~~~~~~~~~~~ -------------------------------------------------------------------------Name Function -------------------------------------------------------------------------1. aux_file_format Format specified drive 2. aux_file_mount Mount memory card. 3. aux_file_unmount Unmount memory card. 4. aux_file_memcinfo Get memory card information. -------------------------------------------------------------------------- Function Reference ~~~~~~~~~~~~~~~~~~ -----------------------------------------------------------------------------1. Format specified drive <Main> -----------------------------------------------------------------------------[Name] aux_file_format [Syntax] #include <auxfile.h> int aux_file_format( unsigned char drive ) ; [Arguments] drive Drive name ( ='A' ) [Return] 0 9 normal completion invalid drive name [Description] This function formats the drive specified by the argument. Specify the name of the drive to be formatted by the argument "drive". When formatting S-RAM disk, call this function as aux_file_format( 'A' ) ; . When this function is called, whole data stored in the specified drive is lost. -----------------------------------------------------------------------------2. Mount memory card. <Main,Alarm,Comm> -----------------------------------------------------------------------------[Name] aux_file_mount [Syntax] #include <auxfile.h> int aux_file_mount( unsigned char drive ) ; [Arguments] drive Drive name. ( ='B' ) [Return] Returns 0 if successfully mounted the memory card. If failed, returns non-0, and store one of the following values in the global variable "errno". Symbol Meaning ---------------+----------------------------------------------------ENOTMOUNT Failed to mount. ENOTINSERT No memory card inserted. EBATVOLDEC Battery voltage is low. ENOTSRAM Not supported card. (Not S-RAM card.) EDRIVENAME Invalid drive name. EAUTHREJ The other software already uses the memory card slot. [Description] Mounts the memory card. The drive name "drive" is always "B:". After successful execution of this function, input/output functions (such as "fopen", "fread", "remove", "fclose", etc.) are available to use. Don't remove or re-insert the memory card after calling this function. Use "aux_file_memcinfo" function to check whether write-protected or not. [Example] The following program reads character by character from "TESTFILE.DAT" in the memory card and writes them to the stdout. #include <stdio.h> #include <auxfile.h> int example( void ) { FILE signed char int unsigned int *fp ; ch ; ret ; stat ; ret = aux_file_mount( 'B' ) ; if ( ret ) { return ( ret ) ; } ret = aux_file_memcinfo( &stat ) ; if ( !ret ) { if ( stat & 0x02 ) { printf( "Write protect. \n" ) ; } } if ( ( fp = fopen( "B:\\TESTFILE.DAT", "r" ) ) != NULL ) { if ( ( ch = fgetc( fp ) ) != EOF ) { if ( ( ch < '\t' ) || ( ch == 0x0B ) || ( ch == 0x0C ) || ( ( ch > '\r' ) && ( ch < ' ' ) ) || ( ch == 0x7F ) || ( (unsigned char)ch == 0x80 ) || ( (unsigned char)ch == 0xA0 ) || ( (unsigned char)ch > 0xFC ) ) { ch = '.' ; } putchar( ch ) ; } fclose( fp ) ; } ret = aux_file_unmount( 'B' ) ; return ( ret ) ; } -----------------------------------------------------------------------------3. Unmount memory card. <Main,Alarm,Comm> -----------------------------------------------------------------------------[Name] aux_file_unmount [Syntax] #include <auxfile.h> int aux_file_unmount( unsigned char drive ) ; [Arguments] drive Drive name. ( ='B' ) [Return] Returns 0 if successfully unmounted the memory card. If failed, returns non-0, and store one of the following values in the global variable "errno". Symbol Meaning ---------------+----------------------------------------------------ENOTMOUNT Failed to unmount. ENOTINSERT No memory card inserted. EBATVOLDEC Battery voltage is low. ENOTSRAM Not supported card. (Not S-RAM card.) EDRIVENAME Invalid drive name. EAUTHREJ The other software already uses the memory card slot. [Description] Unmounts the memory card. The drive name "drive" is always "B:". Call this function to finish accessing the memory card using input/ output functions (such as "fopen", "fread", "remove", "fclose", etc.). [Example] See example of "Mount memory card (aux_file_mount)". -----------------------------------------------------------------------------4. Get memory card information. <Main,Alarm,Comm> -----------------------------------------------------------------------------[Name] aux_file_memcinfo [Syntax] #include <auxfile.h> int aux_file_memcinfo( unsigned int *stat ) ; [Arguments] stat Buffer in which memory card information is stored. [Return] Returns 0 if successfully got the memory card information. If failed, returns non-0. [Description] Reads the status of the memory card. Call this function after mouting the memory card. (using "aux_file_mount" function.) The contents of "stat" are as follows. bit0 = 0 1 bit1 = 0 1 bit2 = 0 1 bit5,bit4,bit3 = 0, 0, 0 0, 0, 1 bit6 - bit15 A memory card is inserted. No memory card is inserted. Write enable. Write protect. Battery voltage normal. Battery voltage low. Kind of memory card. SRAM card ATA card Undefined. [Example] See example of "Mount memory card (aux_file_mount)". 3.8 Serial Library ================== Library outline ~~~~~~~~~~~~~ 1. Outline Serial Library is a set of general functions which are used to send/receive data to/from devices via RS-232C communication interface. Character or block type data can be handled by these functions. To utilize communication function with Serial Library, "Reader/Punch Interface A" option has to be equipped in the CNC. [1] Protocol start-stop synchronization transmission ( 2 channels max.) data bits stop bits baud rate parity check flow control 7 or 8 bits 1 or 2 bits 600, 1200, 2400, 4800, 9600 bits /sec none, even, odd none, CS/RS control , DC code control [2] Data path +------------------------------------------------+ | | | application |-------+ | | | +------------------------------------------------+ | | | | +----------------+ +----------------+ | | | -+ | | -+ | | Tx buffer | | | Rx buffer | | Status | | | | | | check +----------------+ | +----------------+ | | +----------------+ +----------------+ | | | | +------------------------------------------------+ | | | | | Serial device |<------+ | | +------------------------------------------------+ Application program sends data to the serial device via transmit buffer (Tx buffer) and receives data from the serial device through receive buffer (Rx buffer). Status information is directly read from the serial device. [3] Authorization to access communication channel Each communication channels have authorization control mechanism independent of each other. Application program has to get authorization to use a channel by calling rs_open() function, before using the serial communication interface. If the channel is already occupied by CNC control program or any other task, that channel can neither be opened by rs_open() nor used. It is allowed for the application program to use two channels at the same time. Also, two channels can be used simultaneously if one is used by application program and the other by CNC control program. But , while CNC control program is using serial interface, generally whole CPU resources are dedicated to the program, so that the execution of the application program will be stopped. When a communication channel is opened by rs_open(), the state of the signal ER becomes ON to announce external device that the channel is ready for communication. While ER is ON, connecting or detaching the communication cable should not be done so as not to give damage to the hardware. When a communication channel is closed by rs_close() function, the channel is released and becomes free for other tasks, and the signal ER becomes OFF. [4] Flow control Two flow control methods are supported: one uses hardware signals (CS,ER) for handshaking and the other uses DC code for it ( referred to as "hardware flow ctrl" and " DC code flow ctrl" respectively). Following parameters can be selected. Hardware flow ctrl DC code flow ctrl none, bi-directional none, bi-directional, transmit only, receive only Usually one of the following combination is selected. Hardware flow control DC code flow control -----------------------+-----------------------+-------------------Flow control yes yes Hardware flow ctrl bi-directional none DC code flow ctrl none bi-directional (Note) When "none" is selected for hardware flow ctrl, RS signal becomes always ON. When "DC code flow ctrl" is selected, data transmission is controlled by the DC codes as follows. (1) Transmission handshake Stop or restart sending data, according to the DC code received from destination device. DC1 received : restart sending data is requested DC3 received : stop sending data is requested Received DC code is not passed to the application program. (2) Receiving handshake DC code is used to request the source device to stop or restart sending data according to the state of receiving buffer. Send DC1 : Send DC3 : request to restart sending data request to stop sending data These DC1 or DC3 codes are automatically transmitted by the serial communication driver. [5] Communication mode Application program can select one of the three communication modes, "transmit only", "receive only", and "transmit and receive" (1) Transmit only mode Only data transmission from application program to external device can take place in this mode. Application program cannot use library functions for receiving data. Data received from external device are ignored except DC codes. (2) Receive only mode Only data transmission from external device to application program can take place in this mode. Application program cannot use library functions for sending data. All received data from external devices are passed to application program. (3) Transmit and receive mode Both data sending and receiving can take place in this mode. Application program can use all serial library functions. Received data code from external device is interpreted as follows in accordance with the selected flow control mode. (a) "DC code flow ctrl" is ON for transmission DC codes included in the receiving data from external device are interpreted as flow control characters and they are not passed to the application program. (b) "DC code flow ctrl" is OFF for transmission Because external device would not send DC codes to the application program for flow control purposes in this mode, all receiving data including DC codes are passed to the application program. In this mode, care should be taken for the relationship between flow control method and transmitted data. When bi-directional "DC code flow ctrl" is employed, DC codes in transmitted data, if included as data, cannot be discriminated from flow control DC characters. And these data not only are blocked to pass to the application program but cause flow control failure. Moreover, the DC code to announce "send stop/send restart" cannot be sent to the destination, if "send data" is inhibited by the hardware signal. For these reasons, only text data should be transmitted when "DC code flow ctrl" is employed. If hardware signal handshake is employed, there is no restriction in the code of transmitted data. 2. Interface [1] Connection CNC Serial device ----------+ +-----------| | SD ------------------------------------------------> RD RD <------------------------------------------------ SD | | RS ------------------------------------------------> CS CS <------------------------------------------------ RS | | ER ------------------------------------------------> DR DR <------------------------------------------------ ER | | CD <------------------------------------------------ CD | | SG --+-------------------------------------------+-- SG FG --+-------------------------------------------+-- FG | | ----------+ +-----------SD : Send data [output] RD : Receive data [input] RS : Request to send [output] This signal is used for flow control by hardware signal handshake. This signal requests or allows external serial device to send data. The serial communication driver will bring this signal OFF , when receive buffer is full. External device must not send more than 10 characters after RS is OFF. CS : Clear to send [input] This signal is used for flow control by hardware signal handshake. This signal indicates that external serial device is requesting or allowing data to be sent. The serial communication driver sends data while this signal is ON. ER : Data terminal ready [output] This signal announces that the device is ready for operation. The serial communication driver makes this signal ON, when communication channel is successfully opened. If receive buffer overflows, ER is brought OFF to inform data loss to external device. DR : Data set ready [input] This signal indicates that external device is ready for operation. Application program can examine the state of this signal by using status check function, rs_status(). [2] Signal state Only difference between "hardware flow ctrl" and "no hardware flow ctrl" is that signals CS and DR are deemed always ON if "no hardware flow ctrl" is selected. (1) After channel is open hardware flow ctrl no hardware flow ctrl -------+-----------------------+--------------------SD RD RS ON <CS don't care ER ON <DR ON CD (2) While sending data hardware flow ctrl no hardware flow ctrl -------+-----------------------+--------------------SD send data <RD RS ON <CS flow control don't care ER ON <DR external device status ON CD (3) While receiving data hardware flow ctrl no hardware flow ctrl -------+-----------------------+--------------------SD RD receive data <RS flow control(*1) ON CS ER error report(*2) <DR external device status ON CD (*1) RS becomes OFF when receive buffer is full and returns to ON when there are free space in the buffer (*2) ER becomes OFF when receive data overflows the receive buffer. This happens, for example, when data transmission does not stop even if RS is brought OFF to request stopping data transmission. (4) After channel is closed hardware flow ctrl no hardware flow ctrl -------+-----------------------+--------------------SD RD RS OFF <CS ER OFF <DR CD List of functions ~~~~~~~~~~~~~~~~~ -------------------------------------------------------------------------Name Function -------------------------------------------------------------------------1. rs_open Initialize communication channel 2. rs_close Close communication channel 3. rs_putc Put one byte data into transmit buffer 4. rs_getc Get one byte data from receive buffer 5. rs_write Put block of data into transmit buffer 6. rs_read Get block of data from receive buffer 7. rs_buffer Test or clear transmit/receive buffer 8. rs_status Get status of communication buffer and interface 9. rs_wait Wait for communication interface event -------------------------------------------------------------------------(Note 1) Even if communication interface is in erroneous state, the serial library functions do not return errors. The functions, rs_putc(), rs_getc(), rs_write(), rs_read() returns error only when inadequate manipulation of send or receive buffer is attempted. To know the state of the communication interface, use the function, rs_status(). (Note 2) The serial library functions do not check the signal, DR. It should be checked by application program if necessary. Function Reference ~~~~~~~~~~~~~~~~~~ -----------------------------------------------------------------------------1. Initialize communication channel <Main,Alarm,Comm> -----------------------------------------------------------------------------[Name] rs_open [Syntax] #include <bios.h> int rs_open( int channel, ser_t *param, char *mode ) ; struct RS_PACKET { unsigned baud ; unsigned stop_bit ; unsigned parity ; unsigned data_bit ; unsigned hardflow ; unsigned dc_enable ; unsigned dc_put ; unsigned dc1_code ; unsigned dc2_code ; unsigned dc3_code ; unsigned dc4_code ; } ; typedef struct [Argument] channel param mode RS_PACKET /* /* /* /* /* /* /* /* /* /* /* baud rate */ stop bit length */ parity check */ character length */ hardware flow ctrl */ DC code flow ctrl */ send DC code */ DC1 code */ DC2 code */ DC3 code */ DC4 code */ ser_t ; channel number ( = 1, 2 ) communication parameter communication mode [Return] Returns zero if successful. If any error, returns non-zero value. [Description] Specified communication channel is initialized with specified condition and opened for data transmission. Specify channel number, 1 or 2, by the argument "channel". Specify communication conditions in the structure "param". param->baud baud rate -----------------------+-----------------------BAUD_0600 600 bits/sec BAUD_1200 1200 bits/sec BAUD_2400 2400 bits/sec BAUD_4800 4800 bits/sec BAUD_9600 9600 bits/sec param->stop_bit stop bit length -----------------------+-----------------------STOP_1 1 bit STOP_2 2 bits param->parity parity check -----------------------+-----------------------PARITY_N no parity check PARITY_E even parity PARITY_O odd parity param->data_bit character length -----------------------+-----------------------DATA_7 7 bits DATA_8 8 bits param->hardflow hardware flow ctrl -----------------------+-----------------------0 no 1 both send and receive 2 send only 3 receive only param->dc_enable DC code flow ctrl -----------------------+-----------------------0 no 1 both send and receive 2 send only 3 receive only param->dc_put send DC code -----------------------+-----------------------0 no 1 yes If "1" is specified for "dc_put", following DC code is sent to the external device whenever the channel is opened or closed. open mode when open when close -----------------------+---------------+-----------receive mode DC1 DC3 send mode DC2 DC4 send/receive mode no DC code transmitted param->dc1_code param->dc2_code param->dc3_code param->dc4_code define define define 0x93: define DC1 code (usually 0x11 ) DC2 code (usually 0x12 ) DC3 code (usually 0x13; when using ISO code ) DC4 code (usually 0x14 ) Specify open mode of the communication interface by the argument "mode". mode open mode -------+--------------"r" receive mode "w" send mode "rw" send/receive mode Every parameter must have it's value specified. If not, correct communication will not be done. To utilize communication function with Serial Library, "Reader/Punch Interface A" option has to be equipped in the CNC. If "1" is specified for param->dc_put, DC1 code(for receive mode) or DC2 code (for send mode) is sent via communication channel. -----------------------------------------------------------------------------2. Close communication channel <Main,Alarm,Comm > -----------------------------------------------------------------------------[Name] rs_close [Syntax] #include <bios.h> int rs_close( int channel ) ; [Argument] channel channel number ( = 1, 2 ) [Return] Returns zero if successful. If any error, returns non-zero value. [Description] Stops using specified communication channel. If "1" is specified for param->dc_put of rs_open() function, DC3 code (for receive mode) or DC4 code (for send mode) is sent via communication channel. -----------------------------------------------------------------------------3. Put one byte data into transmit buffer <Main,Alarm,Comm> -----------------------------------------------------------------------------[Name] rs_putc [Syntax] #include <bios.h> int rs_putc( int c, int channel ) ; [Argument] c channel data to be sent channel number ( = 1, 2 ) [Return] Returns "1" if successful. Returns zero if transmit buffer is full and has no room to accept new data. Returns "-1" if any error. The error comes from transmit buffer and has nothing to do with the state of communication interface. [Description] Puts one byte data into the transmit buffer of the specified communication channel. This function outputs data to the transmit buffer. To know if the data is actually transmitted , read the status of the transmit buffer by rs_buffer() function and check the vacancy of the buffer. -----------------------------------------------------------------------------4. Get one byte data from receive buffer <Main,Alarm,Comm> -----------------------------------------------------------------------------[Name] rs_getc [Syntax] #include <bios.h> int rs_getc( int channel ) ; [Argument] channel channel number ( = 1, 2 ) [Return] Returns a data read from receive buffer if successful. Returns "-1" if any error occurs or if there is no data in the buffer. The error comes from receive buffer and has nothing to do with the state of communication interface. [Description] Gets one byte data from the receive buffer of the specified communication channel. -----------------------------------------------------------------------------5. Put block of data into transmit buffer <Main,Alarm,Comm> -----------------------------------------------------------------------------[Name] rs_write [Syntax] #include <bios.h> int rs_write ( char *buffer, int size, int channel ) ; [Argument] buffer size channel output data storage area output data size channel number ( = 1, 2 ) [Return] Returns the size of the data output to the transmit buffer if successful. If free space of the transmit buffer is smaller than the specified data size, returned value will be smaller than the specified data size. Returns "-1" if any error. The error comes from the transmit buffer and has nothing to do with the state of communication interface. [Description] Gets specified bytes of data from the specified buffer area and puts them into the transmit buffer of the specified channel This function outputs data to the transmit buffer. To know if the data is actually transmitted, read the status of the transmit buffer by rs_buffer() function and check the vacancy of the buffer. -----------------------------------------------------------------------------6. Get block of data from receive buffer <Main,Alarm,Comm> -----------------------------------------------------------------------------[Name] rs_read [Syntax] #include <bios.h> int rs_read ( char *buffer, int size, int channel ) ; [Argument] buffer size channel input data storage area input data size channel number ( = 1, 2 ) [Return] Returns the number of data bytes read from the receive buffer if successful. If size of the data in the receive buffer is less than specified size, return value will be smaller than specified size. Returns "-1" if any error. This error comes from receive buffer and has nothing to do with the state of communication interface. [Description] Gets specified bytes of data from the receive buffer of the specified channel and puts them into the specified buffer area. -----------------------------------------------------------------------------7. Test or clear transmit/receive buffer <Main,Alarm,Comm> -----------------------------------------------------------------------------[Name] rs_buffer [Syntax] #include <bios.h> int rs_buffer( int channel, int cmnd ) ; [Argument] channel cmnd Channel number ( = 1, 2 ) buffer command [Return] If successful; RS_GET_BUF_R, RS_GET_BUF_W commands return buffer size, RS_CHK_BUF_R, RS_CHK_BUF_W commands return data size in the buffer RS_CLR_BUF_R, RS_CLR_BUF_W commands return zero. Returns "-1", if any error. [Description] Tests or clears the specified buffer of the specified channel. Select the communication channel (1 or 2) by the argument "channel". Specify following buffer command in the argument "cmnd". cmnd function ---------------+----------------------------------RS_GET_BUF_R return receive buffer size RS_GET_BUF_W return transmit buffer size RS_CHK_BUF_R return data size in receive buffer RS_CHK_BUF_W return data size in transmit buffer RS_CLR_BUF_R clear receive buffer RS_CLR_BUF_W clear transmit buffer -----------------------------------------------------------------------------8. Get status of communication buffer and interface <Main,Alarm,Comm> -----------------------------------------------------------------------------[Name] rs_status [Syntax] #include <bios.h> int rs_status( int channel ) ; [Argument] channel channel number ( = 1, 2 ) [Return] Returns status of the communication interface and communication buffers. bit position Meaning ---------------+-----------------------+---------0x8000 transmission stopped (send) 0x4000 ( reserved ) (send) 0x2000 Buffer full (send) 0x1000 ( reserved ) (send) 0x0800 0x0400 0x0200 0x0100 receiving stopped ( reserved ) Buffer empty Buffer overrun (receive) (receive) (receive) (receive) 0x0080 0x0040 0x0020 0x0010 0x0008 0x0004 0x0002 0x0001 DR ON ( reserved ) Framing error Overrun error Parity error ( reserved ) ( reserved ) ( reserved ) (LSI) (LSI) (LSI) (LSI) (LSI) (LSI) (LSI) (LSI) [Description] Gets status information of the communication interface and communication buffers of the specified channel. -----------------------------------------------------------------------------9. Wait for communication interface event <Main,Alarm,Comm> -----------------------------------------------------------------------------[Name] rs_wait [Syntax] #include <bios.h> #include <oscall.h> int rs_wait( int channel, int param, int mode, unsigned long time_out ) ; [Arguments] channel param mode time_out channel number ( = 1, 2 ) character code or number of characters operation mode maximum time to wait [Return] Returns zero if specified condition is satisfied. Returns "EC_TIMOUT" if time limit set by time_out has elapsed.. When mode = rtx_size, this function returns "rtx_size_ok" if the number of data bytes in the receive buffer is greater than or equal to the specified value. When mode = trx_size, this function returns "trx_size_ok" if the number of data bytes in the transmit buffer is less than or equal to the specified value. Returns the value other than described above if any error. T[Description] Waits for the specified communication channel to become given state. Specify the number of the channel ( 1 or 2 ) to wait for events. Specify one of the following for the argument "mode". mode operation mode ---------------+--------------------------------------rtx_size wait for data to be received trx_size wait for data to be sent rtx_code wait for specified character to come According to the operation mode described above, either the number of data characters or a character code should be specified for the argument "param". mode param ---------------+-----------------------------------------rtx_size number of data characters in the receive buffer trx_size number of data characters in the transmit buffer rtx_code character code The maximum wait time is specified by the argument "time_out". The unit of the wait time is Tick ( 1 Tick = 8 msec). After this function call, the task from which this function is called is switched to the "wait state" until specified condition is satisfied. For this reason, this function especially suits with communication tasks. This function is used for following purposes. (1) Wait for transmit completion ret = rs_wait( channel, param, trx_size, time_out ) ; This waits for the number of untransmitted characters in the transmit buffer to become less than or equal to the specified value given by "param". If param = 0, above function call waits for the completion of transmission. This is used to know that whole data is sent to the destination. By setting param as param="Tx buffer size" - "Tx data size", above function call informs that there is enough space in the transmit buffer to accept new data. This is useful for efficient data transmission. (2) Wait for data to come ret = rs_wait( channel, param, rtx_size, time_out ) ; This waits for the number of received characters in the receive buffer to become greater than or equal to the specified value given by "param". This is efficient compared to the polling method. In case of fixed length data communication, specify as param="packet size" to know that a set of data has been received. If it is expected to know that a data of whatever size has been received, specify param as "1". (3) Wait for specified character ret = rs_wait( channel, param, rtx_code, time_out ) ; This function call waits for the character specified by "param" to arrive. This function is used for the case to know the arrival of the data packet which ends with specific code. Above wait state finishes when receiving data ,which arrives after rs_wait() is called, matches the character specified by "param". Those data, which have arrived before the execution of this function and are not yet read by the application, are not examined for character matching. Specifying the maximum wait time by "time_out" avoids application program to hang up when no answer comes back from the external device. There can be some problem in the communication interface when time-out error occurs. In this case, examine the state of the interface by using rs_buffer() function or rs_status() function. 3.9 Task management library =========================== Library outline ~~~~~~~~~~~~~~~ Following functions are provided to control execution of the application programs or to manage execution of multiple tasks. 1. Time management 2. Semaphore control 3. Event flag 1. Time management The time management functions can suspend execution of tasks for specified period of time or can make tasks wait for events with limited wait time option which avoids tasks to become dead-locked. The timer which can be used by the application program is a local timer dedicated for the task. Time unit of the timer is "Tick"(1 Tick = 8 msec). name function ---------------+--------------------------------------------------os_show_tim read timer os_set_tim set timer os_sync_tim suspend execution of task until specified time of timer os_wait_tim suspend execution of task for specified time period * os_set_tim() sets specified value to the timer. This function sets the timer of it's own task, the timer of another task cannot be set. * os_show_tim() reads time value from the timer of current task. * Execution of the current task is suspended by os_sync_tim() until the timer reaches the specified time. ( Absolute wait) * os_wait_tim() function suspends execution of the current task for specified period of time ,like waiting for time-out. ( Relative wait) The time referred to in all task management library functions is based on the software-timer of 8 msec unit. This timer is the basis of the operation of the task management programs. Note that the contents of this timer does not always agree with the actual passage of time. This is because the task management programs are suspended while the CNC task of higher priority is being executed and the timer is not updated during this period. 2. Synchronization of tasks (semaphore management) The semaphore is used to synchronize or arbitrate execution of tasks. The semaphore consists of semaphore counter and semaphore queue. Suspended tasks which are waiting for the semaphore to be signaled are queued in the semaphore queue, and when the semaphore is signaled the task at the top of the queue is awaked to run. Multiple tasks can share a semaphore. task synchronization ~~~~~~~~~~~~~~~~~~~~ TASK A TASK B | : | SEM : Wait---->* : : ^ | : +--- Signal | : | : task arbitration ~~~~~~~~~~~~~~~~ TASK A TASK B | wait for| | get SEM release | Wait-----> * <---+ | | ^ | +-- Wait | | | : Signal----+ +-------->| | release get | Following functions are used for semaphore management. Name Function ---------------+-------------------------------------os_make_sem create semaphore os_delt_sem delete semaphore os_wait_sem wait until semaphore is signaled os_sign_sem signal semaphore * The semaphore is used to synchronize or arbitrate execution of tasks. * The semaphore is not exclusively given to a task. ( The system does not register the task which has gotten the semaphore.) So, the semaphore can be signaled by even a task that did not get the semaphore. * os_make_sem() creates the semaphore. Initial value of the semaphore counter represents total number of the tasks which can get semaphore. Waiting for signal ~~~~~~~~~~~~~~~~~~ * os_wait_sem() decrements the semaphore counter, and suspends the execution of the calling task if the value of the semaphore counter is negative. sem-if( sem < 0 ) Wait ==> decrement semaphore counter ==> if negative counter value ==> queue the task into the semaphore queue and suspend execution operation semaphore counter semaphore queue ------------+-----------------+------------------------1 none Wait 0 none Wait -1 ==> ----X Wait -2 ==> ----O----X Wait -3 ==> ----O----O----X Signaling semaphore ~~~~~~~~~~~~~~~~~~~ * os_sign_sem() signals the semaphore. * If there are any suspended tasks, the task at the top of the semaphore queue is awaked to run. sem++ if( sem <= 0 ) Ready ==> increment semaphore counter ==> if counter value is 0 or negative ==> awake the task at the top of the semaphore queue operation semaphore counter semaphore queue ----------+------------------+-------------------------3 ==> ----O----O----X Signal -2 ==> ----O----X Signal -1 ==> ----X Signal 0 none Signal 1 none [ Example of task arbitration ] As an example, here it is assumed that there are three sets of resources which are shared between five tasks. The following example shows a method to manage assignment of these resources among tasks. +-----------+ Signal | resources | Task Queue Wait <====== | TASK-A | <=== (TASK-D)==(TASK-E)== | TASK-B | | TASK-C | +-----------+ 1) Create semaphore by os_make_sem() and specify "3" , which is the number of available resource set, for the initial value of the semaphore counter. 2) Before using a set of resources , get semaphore by os_wait_sem() function. If resources are not available, the execution of the calling task is suspended. 3) When resources have become unnecessary, release the semaphore by os_sign_sem() function. If there are suspended tasks waiting for semaphore, the task at the top of the queue gets semaphore and awaked from the suspended state. In the following example, maximum three tasks can have resources assigned, and the execution of the other tasks, for which there are no available resources, are suspended to wait for the release of resources. semaphore TASK-A TASK-B TASK-C TASK-D TASK-E counter value | | | | | 3 Wait SEM | | | | 2 X Wait SEM | | | 1 X X Wait SEM | | 0 X X X Wait SEM | -1 X X X (Wait) Wait SEM -2 X X X (Wait) Signal SEM X X X -1 | Signal SEM X X X 0 | | Signal SEM X X 1 | | | Signal SEM X 2 | | | | Signal SEM 3 | | | | | V V V V V [Semaphore counter value (semval) and what it represents] initial value : total number of resource sets if semval=+n : n= number of available resource sets if semval=-n : n= number of suspended tasks (n>=0) [Example of task synchronization] This is a sample case that a task is waiting for another task to complete, and assumes that TASK-A waits for TASK-B and TASK-B waits for TASK-C. This task synchronization can be achieved by using two semaphores. * Priority of each task is assumed to be A>B>C (C being lowest) in the following example. TASK-A TASK-B TASK-C | | Wait D ----| | Wait E ----| | TASK-C running | | <-----Signal E TASK-B running | | <----Signal D | TASK-A running | SEM-D 0 SEM-E 0 -1 -1 0 0 [ Example of inter task communication ] A method of sending or receiving data between tasks by means of ring buffer ( or circulating buffer) is considered in the following example. Assume that the TASK-A writes a data into the buffer and the TASK-B reads the data from the buffer. Writing a data into the buffer where a data is remaining unread, or reading the buffer when no data is written, is not allowed. Above operation is controlled by using two semaphores. +-------+ +------------> | SEM C | <--------------+ | +-------+ | | +-------+ | | +------> | SEM D | <-------+ | | | +-------+ | | Wait Signal Wait Signal | | buffer(shared memory) | | +--------+ +--------+ Read +--------+ | TASK A | | | =====> | TASK B | +--------+ |--------| +--------+ | | | | Write |--------| +=====> | | +--------+ TASK A TASK B SEM C SEM D ---------------+---------------+---------------+-------3 0 Wait D -1 Wait C (wait) 2 Write data Signal D 0 Read data Wait C (Ready) 1 Write data Signal D 1 Wait C 0 Write data Signal D 2 Wait C -1 Signal C 0 [semaphore counter value initial value of SEM C positive value of SEM C positive value of SEM D negative value of SEM C negative value of SEM D and what it represents] = number of entry in the buffer = number of available entry = number of data written = waiting for data to be read = waiting for data to be written 3. Synchronizing tasks ( Event flag) Event flag is used to relating to the specific (For example, consider a to other tasks.) Maximum synchronize execution of tasks. The event flags operation are grouped and it forms an event group. case that a task detects a signal and notifies that 32 flags can be grouped for an event group. Execution of tasks can be suspended until the state of an event group matches a specific data pattern. MSB LSB 31 0 +---------------+---------------+---------------+---------------+ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | +---------------+---------------+---------------+---------------+ | | | +-> flag 1 | : | : | : +---------------------------------------------------------------> flag 32 Event group ~~~~~~~~~~~ A signal can wake all of the suspended tasks of which the triggering condition is satisfied. +--------------------------+ +----------------> | event flag | | +--------------------------+ signal | waiting for event | | +---------------+---------------+ | | | | +---------+ +---------+ +---------+ +---------+ | TASK A | | TASK B | | TASK C | | TASK D | +---------+ +---------+ +---------+ +---------+ Following functions are used for event flag management. Name Function ---------------+---------------------------------------------os_make_flg create event flag os_delt_flg delete event flag os_sign_flg signal event flag ( modal type) os_puls_flg signal event flag ( pulse type) os_wait_flg wait for being signaled os_clar_flg clear event flag (Note) The event flag signaled by modal type signal is memorized in the event flag image. This image is retained until it is cleared by os_clar_flg(). (1) Create event flag os_make_flg() function creates event flag. Initial state of the event flag is OFF. (2) Wait for being signaled os_wait_flg() sets the wait condition and suspends execution of the calling task. For example, to wait for the event flag 1,2,3 to become ON, specify 0x00000007 for the parameter of os_wait_flg(). (This parameter is referred to as "wait message".) In addition, specify "AND wait" or "OR wait" by the argument of os_wait_flg(). (a) OR wait The execution of the flags 1,2 or the flags 1,2 or is called. (This before.) the calling task is suspended until at leased one of 3 is signaled. The task is not suspended, if any of 3 in the event flag image is set before the function is the case that a flag is signaled by os_sign_flg() Operation ~~~~~~~~~ if( wait message & image == 0 ) Wait ==> wait until "wait massage" is satisfied image wait message 0..0000XXX 0..0000111 | | +-------> AND <-------+ | | !=0 0..0XXX -----> NO wait | | ==0 V wait for signal (b) AND wait The execution of the calling task is suspended until all three flags 1,2 and 3 are signaled. Flags, set ON in the event flag image before the function is called, are not accounted as flags to be waited. For example, if flags 1 and 2 are ON in the event flag image, the task waits for only flag 3 to be signaled. If three flags 1,2 and 3 are all ON in the event flag image before the function is called, the calling task is not suspended. operation ~~~~~~~~~ wait message = ~image & wait message if( wait message != 0 ) Wait ==> wait until "wait massage" is satisfied image wait message 0..0000XXX 0..0000111 NOT | | 1..1111XXX -> AND <------+ | | ==0 0..0XXX -----> NO wait | !=0 V wait for signal (Note) Those flags signaled in the past by os_sign_flg() is memorized in the event flag image. Whether the execution of the task is suspended or not depends on the contents of the event flag image. (3) Signaling the event flag Functions os_sign_flg() or os_puls_flg() signals the event flag. For example, to signal the event flag 1,2 and 3 to become ON, specify 0x00000007 for the parameter of os_sign_flg(). (This parameter is referred to as "signal message".) The suspended tasks which are waiting for the flags, that are specified by this function call, to be signaled are waked. * os_sign_flg (modal type) os_sign_flg() memorizes the signaled flags in the event flag image. As a result, subsequent os_wait_flg() function call specifying the signaled flags as "wait message" would not suspend the calling task unless the event flag image is cleared. * os_puls_flg (pulse type) os_puls_flg() does not memorize the signaled flags in the event flag image. Accordingly, subsequent 0s_wait_flg() function call specifying the signaled flags as "wait message" will suspend the calling task again. (a) Signaling the "OR waiting" task operation ~~~~~~~~~ if( signal message & wait message != 0 ) Ready ===> waked signal message wait message 0..0000XXX 0..0000111 | | +-----> AND <------+ | | !=0 0..0XXX -----> waked | | ==0 V suspended (b) Signaling the "AND waiting" task operation ~~~~~~~~~ wait message = ~signal message & wait message if( wait message == 0 ) Ready ===> waked signal message wait message 0..0000XXX 0..0000111 NOT | | 1..1111XXX -> AND <------+ | | ==0 0..0XXX -----> waked | !=0 V suspended (4) Clearing the event flag os_clar_flg() function call clears specified bit of the event flag image. For example, to clear flag 1 ,specify "0x00000001" for the parameter of os_clar_flg(). (This parameter is referred to as "clear message".) operation ~~~~~~~~~ flag image = ~clear message & flag image clear message event flag image 0..0000001 0..0000111 NOT | | 1..1111110 -> AND <-----+ | new event flag image 0..0110 (Note) Clearing the event flag image does not affect the state of suspending tasks. [Transition of flags to be waited and event flag image by signals] Following example explains the state transition of the flags to be waited and the event flag image when they are signaled by modal type and pulse type signaling functions. Parameter flags to be event flag Function (message) waited image ---------------+---------------+---------------+------------os_wait_flg 11111111 11111110 00000001 (*1) (AND wait) V V os_sign_flg 00000110 -> 11111000 00000111 (*2) V V os_puls_flg 00011000 -> 11100000 00000111 (*3) V V os_clar_flg 00000011 -> 11100000 00000100 (*4) V V os_sign_flg 01100000 -> 10000000 01100100 (*5) V V os_puls_flg 10000000 -> 00000000 01100100 (*6) V wake up from suspended state (*1) - os_wait_flg() specifies to wait for flags 1 to 8 to be all signaled. However, because the flag 1 in the event flag image is already set, flag 1 is not accounted as a flag to be waited for being signaled. (*2) - Signal the flags 2 and 3 by modal type function os_sign_flg(). - Waiting state of the flags 2 and 3 are canceled. - It is registered in the event flag image that flags 2 and 3 are signaled. (*3) - Signal the flags 4 and 5 by pulse type function os_puls_flg(). - Waiting state of the flags 4 and 5 are canceled. - Flags 4 and 5 are not registered in the event flag image. (*4) - Clear flags 1 and 2 in the event flag image. - No change in the flags to be waited. (*5) - Signal the flags 6 and 7 by modal type function os_sign_flg(). - Waiting state of the flags 6 and 7 are canceled. - It is registered in the event flag image that flags 6 and 7 are signaled. (*6) - Signal the flag 8 by pulse type function os_puls_flg(). Waiting state of the flags 8 is canceled. Flag 8 is not registered in the event flag image. Because all the flags from 1 to 8 have been signaled and as a result there are no flags to be waited for being signaled, suspended task wakes up and starts running. Lists of Functions ~~~~~~~~~~~~~~~~~~ -------------------------------------------------------------------------Name Function -------------------------------------------------------------------------1. os_show_tim read timer 2. os_set_tim set timer 3. os_sync_tim suspend execution of task until specified time of timer 4. os_wait_tim suspend execution of task for specified time period 5. os_make_flg create event flag 6. os_delt_flg delete event flag 7. os_sign_flg signal event flag 8. os_wait_flg wait for being signaled 9. os_clar_flg clear event flag 10. os_puls_flg signal event flag (pulse type) 11. os_make_sem create semaphore 12. os_delt_sem delete semaphore 13. os_sign_sem signal semaphore 14. os_wait_sem wait until semaphore is signaled 15. os_strt_wtsk Start window task -------------------------------------------------------------------------- Function Reference ~~~~~~~~~~~~~~~~~~ -----------------------------------------------------------------------------1. Read timer <Main,Alarm,Comm> -----------------------------------------------------------------------------[Name] os_show_tim [Syntax] #include <oscall.h> void os_show_tim( unsigned long *current_timer_value ) ; [Argument] current_timer_value value read from the timer [Return] -----[Description] Reads current value of the timer. The unit of the timer value is Tick while 1 Tick is 8 ms. The time value read by this function is that of local timer dedicated for the calling task. The contents of the timer read by this function does not always agree with the actual passage of time. To read the time of day, use clock() function which is more accurate. -----------------------------------------------------------------------------2. Set timer <Main,Alarm,Comm> -----------------------------------------------------------------------------[Name] os_set_tim [Syntax] #include <oscall.h> void os_set_tim( unsigned long new_timer_value, unsigned long *old_timer_value ) ; [Argument] new_timer_value old_timer_value new timer value old timer value [Return] -----[Description] This function sets the specified value to the timer. The timer set by this function is the local timer dedicated for the calling task. The contents of the timer read by this function does not always agree with the actual passage of time. To read the time of day, use clock() function which is more accurate. -----------------------------------------------------------------------------3. Suspend execution of task until specified time of timer <Main,Alarm,Comm> -----------------------------------------------------------------------------[Name] os_sync_tim [Syntax] #include <oscall.h> unsigned short os_sync_tim( unsigned long wakeup_time ) ; [Argument] wakeup_time time to wake up [Return] 0 EC_TIMOUT successful completion Time Out [Description] This function suspends the execution of the calling task until timer reaches the specified time value. This function cannot suspend the execution of tasks other than the calling task. This function does not return error value, zero. When the timer reaches the specified time, returns error value, EC_TIMOUT. Internally, this function suspends execution of the task for a period of time given by subtracting current time from the wakeup_time . (wakeup_time - current time) If wakeup_time is less than current time, the task is not suspended. Before calling this function, current time must be read by os_show_tim() function. The maximum value of the wakeup_time is 7FFFFFFFh which corresponds to 198 days, 20 hours, 11 minutes, 9 seconds, and 180 milli seconds. The unit of the value wakeup_time is Tick (=8 msec). -----------------------------------------------------------------------------4. Suspend execution of task for specified time period <Main,Alarm,Comm> -----------------------------------------------------------------------------[Name] os_wait_tim [Syntax] #include <oscall.h> unsigned short os_wait_tim( unsigned long timeout_value ) ; [Argument] timeout_value time period to wait [Return] 0 EC_TIMOUT successful completion Time Out [Description] Suspends execution of the calling task for the specified time period. This function cannot suspend the execution of tasks other than the calling task. This function does not return error value, zero. When specified time period is elapsed, returns error value, EC_TIMOUT. The calling task is suspended for the period of "timeout_value" time. The maximum value of the timeout_value is FFFFFFFFh which corresponds to 397 days, 16 hours, 22 minutes, 18 seconds, and 360 milli seconds. The unit of the timeout_value is Tick (=8 msec). -----------------------------------------------------------------------------5. Create event flag <Main,Alarm,Comm> -----------------------------------------------------------------------------[Name] os_make_flg [Syntax] #include <oscall.h> unsigned short os_make_flg( unsigned char event_flag_id ) ; [Argument] event_flag_id event flag ID [Return] 0 EC_FLGID EC_EXSTFLG successful completion Event-flag ID error Already existing event-flag [Description] Creates event group with specified event flag ID . Event group is composed of 32 event flags. This function must be called before using event flags. -----------------------------------------------------------------------------6. Delete event flag <Main,Alarm,Comm> -----------------------------------------------------------------------------[Name] os_delt_flg [Syntax] #include <oscall.h> unsigned short os_delt_flg( unsigned char event_flag_id ) ; [Argument] event_flag_id event flag ID [Return] 0 EC_FLGID EC_NXSTFLG successful completion Event-flag ID error Non-existent event-flag [Description] This function deletes the event group specified by "event_flag_id". Error code, "EC_DELFLG", is returned to the tasks that have been waiting for the deleted event flags to be signaled. -----------------------------------------------------------------------------7. Signal event flag <Main,Alarm,Comm> -----------------------------------------------------------------------------[Name] os_sign_flg [Syntax] #include <oscall.h> unsigned short os_sign_flg( unsigned char event_flag_id, unsigned long flag_on_message ) ; [Argument] event_flag_id flag_on_message event flag ID signal message [Return] 0 EC_FLGID EC_NXSTFLG successful completion Event-flag ID error Non-existent event-flag [Description] Signals event flags specified by "event_flag_id" and signal message. Signaled flags are registered in the event flag image. -----------------------------------------------------------------------------8. Wait for being signaled <Main,Alarm,Comm> -----------------------------------------------------------------------------[Name] os_wait_flg [Syntax] #include <oscall.h> unsigned short os_wait_flg( unsigned char event_flag_id, unsigned long wait_message, unsigned short and_or, long wait_limit, unsigned long *return_message ) ; [Argument] event_flag_id wait_message and_or wait_limit return_message event flag ID wait message AND -- 0, OR -- 1 Set 0. [Return] 0 EC_FLGID EC_NXSTFLG EC_DELFLG EC_TIMOUT successful completion Event-flag ID error Non-existent event-flag Event-flag was deleted Time out [Description] Waits for specified signals to be signaled. When the value of the argument "and_or" is AND_W(0), this function suspends the calling task and waits for all the signals specified by wait_message to be signaled. This is referred to as "AND wait" mode. Always, "0" is returned as return_message in this mode.. When the value of the argument "and_or" is OR_W(1), this function suspends the calling task and waits for at least one of the signals specified by wait_message to be signaled. This is referred to as "OR wait" mode. Signaled flag is returned as return_message in this mode.. -----------------------------------------------------------------------------9. Clear event flag <Main,Alarm,Comm> -----------------------------------------------------------------------------[Name] os_clar_flg [Syntax] #include <oscall.h> unsigned short os_clar_flg( unsigned char event_flag_id, unsigned long clear_message ) ; [Argument] event_flag_id clear_message event flag ID clear message [Return] 0 EC_FLGID EC_NXSTFLG successful completion Event-flag ID error Non-existent event-flag [Description] Clears the event flag image. This function clears the flags in the event flag image which are specified by the clear_message.. -----------------------------------------------------------------------------10. Signal event flag (pulse type) <Main,Alarm,Comm> -----------------------------------------------------------------------------[Name] os_puls_flg [Syntax] #include <oscall.h> unsigned short os_puls_flg( unsigned char event_flag_id, unsigned long puls_message ) ; [Argument] event_flag_id puls_message event flag ID signal message [Return] 0 EC_FLGID EC_NXSTFLG successful completion Event-flag ID error Non-existent event-flag [Description] Signals the event flags specified by the puls_message argument. Signaled flags are not registered in the event flag image. -----------------------------------------------------------------------------11. Create semaphore <Main,Alarm,Comm> -----------------------------------------------------------------------------[Name] os_make_sem [Syntax] #include <oscall.h> unsigned short os_make_sem( unsigned char semaphore_id, char initial_value ) ; [Argument] semaphore_id initial_value semaphore ID initial value of the semaphore counter [Return] 0 EC_SEMID EC_EXSTSEM successful completion Semaphore ID error Already existing semaphore [Description] Creates a counter type semaphore. Initial value of the semaphore counter represents the number of resources managed by the semaphore. -----------------------------------------------------------------------------12. Delete semaphore <Main,Alarm,Comm> -----------------------------------------------------------------------------[Name] os_delt_sem [Syntax] #include <oscall.h> unsigned short os_delt_sem( unsigned char semaphore_id ) ; [Argument] semaphore_id semaphore ID [Return] 0 EC_SEMID EC_NXSTSEM successful completion Semaphore ID error Non-existent semaphore [Description] Deletes semaphore. Error code "EC_DELSEM" is returned to the tasks which have been waiting for the deleted semaphore. -----------------------------------------------------------------------------13. Signal semaphore <Main,Alarm,Comm> -----------------------------------------------------------------------------[Name] os_sign_sem [Syntax] #include <oscall.h> unsigned short os_sign_sem( unsigned char semaphore_id ) ; [Argument] semaphore_id semaphore ID [Return] 0 EC_SEMID EC_NXSTSEM EC_SEMOVF successful completion Semaphore ID error Non-existent semaphore Semaphore overflow [Description] Signals the semaphore specified by the "semaphore_id" argument. This function increments the semaphore counter, and runs the task at the top of the semaphore queue if the value of the semaphore counter becomes less than or equal to zero. -----------------------------------------------------------------------------14. Wait until semaphore is signaled <Main,Alarm,Comm> -----------------------------------------------------------------------------[Name] os_wait_sem [Syntax] #include <oscall.h> unsigned short os_wait_sem( unsigned char semaphore_id, long wait_limit ) ; [Argument] semaphore_id wait_limit semaphore ID Set 0. [Return] 0 EC_SEMID EC_NXSTSEM EC_DELSEM EC_TIMOUT EC_SEMUDF successful completion Semaphore ID error Non-existent semaphore Semaphore was deleted Time out Semaphore underflow [Description] Waits until semaphore is signaled. os_wait_sem() decrements the semaphore counter, and suspends the execution of the calling task if the value of the semaphore counter is negative. -----------------------------------------------------------------------------15. Start window task <Main> -----------------------------------------------------------------------------[Name] os_strt_wtsk [Syntax] #include <oscall.h> unsigned short os_strt_wtsk( unsigned int wghs ) ; [Argument] wghs Global heap size of the window task in kilo-byte. [Return] 0 0x010C 0x011B Successful. No window task exists. Not enough memory to start the window task. [Description] Starts the window task. This function starts the window task. Until calling this function, the window task keeps "start pending" status and is not executed. Specify the global heap size for the window task in "wghs". Generally, 100KB is enough size. This function must be called in the main task. [Example] The following program which is called in the main task starts the window task. #include <oscall.h> #include <stdio.h> void example( void ) { unsigned short ret ; ret = os_strt_wtsk( 100 ) ; if ( ret ) printf( "ERROR, can't start Window TASK.\n" ) ; else printf( "Window TASK has started.\n" ) ; } 3.10 FCA Library ================ Library outline ~~~~~~~~~~~~~~~ 1. Outline FCA(FANUC CASSETTE ADAPTOR) Library is a library of functions which are used to send or receive data between CNC and FANUC's peripheral devices like FANUC Handy File or FANUC CASSETTE ADAPTOR. To utilize communication function with FCA Library, "Reader/Punch Interface A" option has to be equipped in the CNC. [1] Function Available functions are listed below. Note that actually available functions are limited by the function of the connected peripheral device. For more details refer to the operating manuals for each FCA devices. Data Transmission File Handling Directory Handling Read Status : : : : Binary, Text Search, Delete or Rename file Get file name and file size Get status of FCA devices [2] Protocol Following configuration is recommended. Data bits : 8 bits Stop bits : 2 bits Data transmission rate : 2400, 4800(default), 9600 [bits/sec] Parity check : none Flow control : CNC side = Hardware control(for sending) + DC control(for receiving) : FCA side = Protocol B Data code : no conversion [3] How it works +---------------------------------------+ | | | Application | | | +-------------------+-------------------+ | +-------------------+-------------------+ | | | FCA Library | | | +-------------------+-------------------+ | +-------------------+-------------------+ | | | Serial Library | | | +-------------------+-------------------+ | +-------------------+-------------------+ | | | Serial Device | | | +---------------------------------------+ FCA Library controls serial devices via Serial Library. [4] FCA mode When the FCA Library Function, fca_setparam(), is called, the serial port is switched to the FCA mode. In this mode, it is recommended not to use standard Serial Library Functions, rs_xxx. Though these functions can be used in the FCA mode, detailed understandings of the FCA devices are required to do that. When a serial port is switched to the FCA mode, the port becomes being under control of the application program and the signal "ER" becomes "ON". In this state, communication cable should not be disconnected or connected to protect devices from hardware damage. By calling the FCA Library Function, fca_bye(), the serial port is returned to the idle state. That is, the port is released from the control of the application program and the signal "ER" becomes "OFF". +----------------+ +------------------+ | | | +--------------+ | | | | | | | | -----fca_setparam()------> | | | | | | FCA mode | | | <-------fca_bye()--------| | | | | | | | | Idle state | | +--------------+ | | | | | | --------rs_open()--------> | | | | | | <-------rs_close()-------| | | | General mode | | | | | +----------------+ +------------------+ While in FCA mode, other FCA Library Functions, fca_xxx(), can be called. If they are called prior to the fca_setparam() function, the operation of those functions are not guaranteed. One task can put multiple serial ports into FCA mode, but the port actually used is the one which is specified by the last fca_setparam() function called. [5] Flow control Though "Protocol B" is the standard protocol, the FCA Library Function does not set the protocol automatically, because protocols other than that can also be set on the FCA devices. Select appropriate protocol according to the setting of the connected device. As to the setting method of the protocol, refer to the General mode function, rs_open(). [6] Communication mode Transmit and receive mode is selected and data can be sent or received at any time when required. List of Functions ~~~~~~~~~~~~~~~~~ -------------------------------------------------------------------------Name Function -------------------------------------------------------------------------1. fca_setparam Initialize communication line. 2. fca_bye Close communication line. 3. fca_open Open a binary file on FCA device. 4. fca_close Close a binary file. 5. fca_read Read binary data from the file. 6. fca_write Write binary data to the file. 7. fca_fopen Open a text file on FCA device. 8. fca_fclose Close a text device. 9. fca_getc Read a character from the text file. 10. fca_putc Write a character to the text file. 11. fca_delete Delete a file on FCA device. 12. fca_rename Change name of a file on FCA device. 13. fca_readdir Read directory information of FCA device. 14. fca_status Read status information of FCA device. 15. fca_remains Read free space size of a floppy disk. -------------------------------------------------------------------------(Note 1) Even when an error occurs in FCA device, FCA functions do not return error status. Function Reference ~~~~~~~~~~~~~~~~~~ -----------------------------------------------------------------------------1. Initialize communication line. <Main,Alarm,Comm> -----------------------------------------------------------------------------[Name] fca_setparam [Syntax] #include <bios.h> int fca_setparam( int channel, ser_t *param ) ; struct RS_PACKET { unsigned baud ; unsigned stop_bit ; unsigned parity ; unsigned data_bit ; unsigned hardflow ; unsigned dc_enable ; unsigned dc_put ; unsigned dc1_code ; unsigned dc2_code ; unsigned dc3_code ; unsigned dc4_code ; } ; typedef struct [Argument] channel param RS_PACKET /* /* /* /* /* /* /* /* /* /* /* baud rate */ stop bit length */ parity check */ character length */ hardware flow ctrl */ DC code flow ctrl */ send DC code */ DC1 code */ DC2 code */ DC3 code */ DC4 code */ ser_t ; Channel number. ( = 1 or 2 ) Communication parameter. [Return] Returns zero if successful. If any error, returns non-zero value. [Description] Specified communication channel is initialized with specified condition and opened for data transmission. When this function is called, the serial port is switched to the FCA mode. In this mode, it is recommended not to use standard Serial Library functions, rs_xxx. Though these functions can be used in the FCA mode, detailed understandings of the FCA devices are required to do that. When a serial port is switched to the FCA mode, the port becomes being under control of the application program and the signal "ER" becomes "ON". In this state, communication cable should not be disconnected or connected to protect devices from hardware damage. While in FCA mode, other FCA Library Functions, fca_xxx(), can be called. If they are called prior to the fca_setparam() function, the operation of those functions are not guaranteed. By calling fca_bye(), the serial port is returned to the idle state. For the parameters set in the structure, ser_t, refer to the rs_open function. In case "Protocol B" is used for data transmission, following settings are recommended. param->baud param->stop_bit param->parity param->data_bit param->hardflow param->dc_enable param->dc_put param->dc1_code param->dc2_code param->dc3_code param->dc4_code = = = = = = = = = = = BAUD_4800 ; STOP_2 ; PARITY_N ; DATA_8 ; 2 ; 3 ; 0 ; 0x11 ; 0x12 ; 0x93 ; 0x14 ; [Example] Refer to the example in "Read binary data from the file.(fca_read)". -----------------------------------------------------------------------------2. Close communication line. <Main,Alarm,Comm> -----------------------------------------------------------------------------[Name] fca_bye [Syntax] #include <bios.h> int fca_bye( int channel ) ; [Argument] channel Channel number. ( = 1, 2 ) [Return] Returns zero if successful. If any error, returns non-zero value. [Description] This function releases the serial port which has been put in the FCA mode by the fca_setparam() function. Signals "RS" and "ER" of the port is set "OFF". Call this function in the following cases. 1) When disconnecting FCA devices from the port. 2) When it become unable to recover FCA devices from error state. 3) When you use Serial Library, rs_xxx. [Example] Refer to the example in "Read binary data from the file.(fca_read)". -----------------------------------------------------------------------------3. Open a binary file on FCA device. <Main,Alarm,Comm> -----------------------------------------------------------------------------[Name] fca_open [Syntax] #include <bios.h> int fca_open( char *name, int mode ) ; [Argument] name mode File name on FCA device. (max. 17 characters) Access mode. ( = 0: read, 1: write ) [Return] Returns zero if successful. Returns -1 if any error occurs. [Description] This function opens a binary file in the FCA device under control. This function is used in conjunction with fca_close() function. Only functions, fca_read() and fca_write(), can be used in between fca_open() and fca_close() functions. When the character '#' is used for the first character of the argument "name", which passes the file name of the FCA device, it is assumed that file number is designated. Following formats are available. #xxxx ( xxxx is max. 4 digit number ) #0 #N #E (Note) : : : : xxxxth file first file next file last file This function can be used only when the device connected to the port is FANUC Handy File. It cannot be used for FANUC CASSETTE ADAPTOR etc.. [Example] Refer to the example in "Read binary data from the file.(fca_read)". -----------------------------------------------------------------------------4. Close a binary file. <Main,Alarm,Comm> -----------------------------------------------------------------------------[Name] fca_close [Syntax] #include <bios.h> int fca_close( void ) ; [Argument] -----[Return] Returns zero if successful. Returns -1 if any error occurs. [Description] This function closes the binary file which has been opened by fca_open() function. This function is used in conjunction with fca_open() function. Only functions, fca_read() and fca_write(), can be used in between fca_open() and fca_close() functions. (Note) This function can be used only when the device connected to the port is FANUC Handy File. It cannot be used for FANUC CASSETTE ADAPTOR etc.. [Example] Refer to the example in "Read binary data from the file.(fca_read)". -----------------------------------------------------------------------------5. Read binary data from the file. <Main,Alarm,Comm> -----------------------------------------------------------------------------[Name] fca_read [Syntax] #include <bios.h> int fca_read( char *buffer, unsigned int bytes ) ; [Argument] buffer bytes Memory area to store read data. Number of data bytes to be read. ( = 1 - 65534 ) [Return] Returns the number of data bytes actually read when successfully completed. Returns -1 if any error occurs. [Description] When called this function reads data from the binary file opened by the fca_open() function. Because the FCA devices require the size of the transmitted data to exactly match with the size of its unit input/output data block, it can happen, when returned from this function call, that extra null characters ('\0') are added at the end of the data read. When a value smaller than the specified byte count is returned, it should be assumed that the last block of the file is read by that function call. (Note) This function can be used only when the device connected to the port is FANUC Handy File. It cannot be used for FANUC CASSETTE ADAPTOR etc.. [Example] Following sample program displays the specified file in the FCA device connected to the first channel in binary dump format. #include <stdio.h> #include <crt.h> #include <data.h> #include <bios.h> #define BUFSIZE 256 int example( void ) { ser_t r_para ; int ret, mode = 0, i, c ; char name[ 18 ], buffer[ BUFSIZE ] ; long count = 0 ; unsigned int bytes = BUFSIZE - 2 ; r_para.baud = BAUD_4800 ; r_para.stop_bit = STOP_2 ; r_para.parity = PARITY_N ; r_para.data_bit = DATA_8 ; r_para.hardflow = 2 ; r_para.dc_enable = 3 ; r_para.dc_put = 0 ; r_para.dc1_code = 0x11 ; r_para.dc2_code = 0x12 ; r_para.dc3_code = 0x93 ; r_para.dc4_code = 0x14 ; ret = fca_setparam( 1, &r_para ) ; if ( ret ) { printf( "error in fca_setparam\n" ) ; return( ret ) ; } printf( " name?(max 17 )\n" ); scanf( "%s" , &name ) ; ret = fca_open ( name, mode ) ; if ( ret ) { printf( "error in fca_open\n" ) ; fca_bye( 1 ) ; return ( ret ) ; } for ( ;; ){ ret = fca_read( buffer, bytes ) ; if ( ret == -1 ) { printf( "error in fca_read\n" ) ; fca_close() ; fca_bye( 1 ) ; return( ret ) ; } for( i = 0 ; i < ret ; i++ ) { c = buffer[ i ] ; c &= 0x00ff ; printf( "%02X", c ) ; count++ ; } if ( ret < bytes ) { printf( "\n" ) ; printf( "ret = %d\n", ret ) ; printf( "bytes = %d\n", bytes ) ; printf( "ret < bytes\n", ret ) ; break ; } } printf( "\n" ) ; printf( "%ld bytes\n", count ) ; ret = fca_close() ; if ( ret ) { printf( "error in fca_close\n" ) ; fca_bye( 1 ) ; return ( ret ) ; } ret = fca_bye( 1 ) ; if ( ret ) { printf( "error in fca_bye\n" ) ; } return ( ret ) ; } -----------------------------------------------------------------------------6. Write binary data to the file. <Main,Alarm,Comm> -----------------------------------------------------------------------------[Name] fca_write [Syntax] #include <bios.h> int fca_read( char *buffer, unsigned int bytes ) ; [Argument] buffer bytes Memory area to store write data. Number of data bytes to be written. ( = 1 - 65534 ) [Return] Returns the number of data bytes actually written when successfully completed. Returns -1 if any error occurs. [Description] This function is called to write data into a binary file opened by the fca_open() function. Because the FCA devices require the size of the transmitted data to exactly match with the size of its unit input/output data block, the data is padded with null characters, '\0', when it is shorter than the unit size. As a result, it can happen that extra null characters, '\0', are added at the end of the destination file. (Note) This function can be used only when the device connected to the port is FANUC Handy File. It cannot be used for FANUC CASSETTE ADAPTOR etc.. [Example] Following sample program writes the NC part program of specified program number into the device connected to the first channel as a file with specified name. #include <stdio.h> #include <crt.h> #include <data.h> #include <bios.h> #define BUFSIZE 256 int example( void ) { int ret, number, i, o_num, mode = 1 ; char name[ 18 ], c, buf[BUFSIZE+4] ; ser_t r_para; r_para.baud = BAUD_4800 ; r_para.stop_bit = STOP_2 ; r_para.parity = PARITY_N ; r_para.data_bit = DATA_8 ; r_para.hardflow = 2 ; r_para.dc_enable = 3 ; r_para.dc_put = 0 ; r_para.dc1_code = 0x11 ; r_para.dc2_code = 0x12 ; r_para.dc3_code = 0x93 ; r_para.dc4_code = 0x14 ; ret = fca_setparam( 1, &r_para ) ; if ( ret ) { printf( "error in fca_setparam\n" ) ; return ( ret ) ; } printf( " name?(max 17 )\n" ) ; scanf( "%s", &name ) ; printf( "prog. no?( ex. O1234 -> 1234 )\n" ) ; scanf( "%d" , &o_num ) ; ret = fca_open ( name, mode ) ; if ( ret ) { printf( "error in fca_open\n" ) ; fca_bye ( 1 ) ; return ( ret ) ; } ret = cnc_upstart( o_num ) ; if ( ret ) { printf( "error in cnc_upstart\n" ) ; fca_close() ; fca_bye( 1 ) ; return ( ret ) ; } for (;;) { number = BUFSIZE - 1 ; ret = cnc_upload( (struct odbup *)(&buf), &number ) ; if ( ret ) { printf( "error in cnc_upload\n" ) ; cnc_upend() ; fca_close() ; fca_bye( 1 ) ; return ( ret ) ; } ret = fca_write( &buf[4], number ) ; if ( ret == -1 ) { printf( "error in fca_write\n" ) ; cnc_upend() ; fca_close() ; fca_bye( 1 ) ; return ( ret ) ; } for ( i = 0 ; i < number ; i++ ) { printf( "%c", buf[4+i] ) ; } if ( buf[4+number-1] == '%' ) { printf( "\n" ) ; break ; } } ret = cnc_upend() ; if ( ret ) { printf( "error in cnc_upend\n" ) ; fca_close() ; fca_bye( 1 ) ; return ( ret ) ; } ret = fca_close() ; if ( ret ) { printf( "error in fca_close\n" ) ; fca_bye( 1 ) ; return ( ret ) ; } ret = fca_bye( 1 ) ; if ( ret ) { printf( "error in fca_bye\n" ) ; } return ( ret ) ; } -----------------------------------------------------------------------------7. Open a text file on FCA device. <Main,Alarm,Comm> -----------------------------------------------------------------------------[Name] fca_fopen [Syntax] #include <bios.h> int fca_fopen( char *name, char *mode ) ; [Argument] name mode File name on FCA device. (max. 17 characters) Access mode. ( = "r": read, "w": write ) [Return] Returns zero if successful. Returns -1 if any error occurrs. [Description] This function opens a text file in the FCA device under control. This function is used in conjunction with fca_fclose() function. Only functions, fca_getc() and fca_putc(), can be used in between fca_fopen() and fca_fclose() functions. When the character '#' is used for the first character of the argument "name", which passes the file name of the FCA device, it is assumed that file number is designated. Following formats are available. #xxxx ( xxxx is max. 4 digit number ) #0 #N #E (Note) : : : : xxxxth file first file next file last file When MS-DOS format is used in the FANUC Handy File, this function cannot be used. ISO code and EIA code are the only codes that this function and fca_putc() and fca_getc() functions can handle. [Example] Refer to the example in "Read a character from the text file. (fca_getc)". -----------------------------------------------------------------------------8. Close a text device. <Main,Alarm,Comm> -----------------------------------------------------------------------------[Name] fca_fclose [Syntax] #include <bios.h> int fca_fclose( void ) ; [Argument] -----[Return] Returns zero if successful. Returns -1 if any error occurrs. [Description] This function closes the text file which has been opened by fca_open() function. This function is used in conjunction with fca_fopen() function. Only functions, fca_getc() and fca_putc(), can be used in between fca_fopen() and fca_fclose() functions. (Note) When MS-DOS format is used in the FANUC Handy File, this function cannot be used. ISO code and EIA code are the only codes that this function and fca_putc() and fca_getc() functions can handle. [Example] Refer to the example in "Read a character from the text file. (fca_getc)". -----------------------------------------------------------------------------9. Read a character from the text file. <Main,Alarm,Comm> -----------------------------------------------------------------------------[Name] fca_getc [Syntax] #include <bios.h> int fca_getc( void ) ; [Argument] -----[Return] Returns the number of characters read when successful. Return -1 if any error occurrs or EOF is detected. [Description] When called, this function reads one character from the text file opened by the fca_fopen() function. (Note) When MS-DOS format is used in the FANUC Handy File, this function cannot be used. ISO code and EIA code are the only codes that this function can handle. [Example] Following sample program reads and displays a file, character by character, from the device connected to the first channel. #include #include #include #include <stdio.h> <crt.h> <data.h> <bios.h> int example( void ) { ser_t r_para ; int ret ; char name[ 18 ], mode = 'r', c ; r_para.baud = BAUD_4800 ; r_para.stop_bit = STOP_2 ; r_para.parity = PARITY_N ; r_para.data_bit = DATA_8 ; r_para.hardflow = 2 ; r_para.dc_enable = 3 ; r_para.dc_put = 0 ; r_para.dc1_code = 0x11 ; r_para.dc2_code = 0x12 ; r_para.dc3_code = 0x93 ; r_para.dc4_code = 0x14 ; ret = fca_setparam( 1, &r_para ) ; if ( ret ) { printf( "error in fca_setparam\n" ) ; return( ret ) ; } printf( " name?(max 17 )\n" ) ; scanf( "%s" , &name ) ; ret = fca_fopen( name, &mode ) ; if ( ret ) { printf( "error in fca_fopen\n" ) ; fca_bye( 1 ) ; return ( ret ) ; } while( ( c = fca_getc() ) != EOF ) { if ( c != 0 ) { printf( "%c", c ) ; } } printf( "\n" ) ; ret = fca_fclose() ; if ( ret ) { printf( "error in fca_fclose\n" ) ; fca_bye( 1 ) ; return ( ret ) ; } ret = fca_bye( 1 ) ; if ( ret ) { printf( "error in fca_bye\n" ) ; } return ( ret ) ; } -----------------------------------------------------------------------------10. Write a character to the text file. <Main,Alarm,Comm> -----------------------------------------------------------------------------[Name] fca_putc [Syntax] #include <bios.h> int fca_putc( int c ) ; [Argument] c A character data to be written. [Return] Returns the written character if successful. Returns -1 if any error occurrs. [Description] When called, this function writes one character into the text file opened by the fca_fopen() function. (Note) When MS-DOS format is used in the FANUC Handy File, this function cannot be used. ISO code and EIA code are the only codes that this function can handle. [Example] Following sample program writes the NC part program of specified program number, character by character, into the device connected to the first channel as a file with the specified name. #include <stdio.h> #include <crt.h> #include <data.h> #include <bios.h> #define BUFSIZE 256 int example( void ) { int ret, number ,i ; int o_num ; char name[ 18 ], mode = 'w', c, buf[BUFSIZE+4] ; ser_t r_para ; r_para.baud = BAUD_4800 ; r_para.stop_bit = STOP_2 ; r_para.parity = PARITY_N ; r_para.data_bit = DATA_8 ; r_para.hardflow = 2 ; r_para.dc_enable = 3 ; r_para.dc_put = 0 ; r_para.dc1_code = 0x11 ; r_para.dc2_code = 0x12 ; r_para.dc3_code = 0x93 ; r_para.dc4_code = 0x14 ; ret = fca_setparam( 1, &r_para ) ; if ( ret ) { printf( "error in fca_setparam\n" ) ; return( ret ) ; } printf( " name?(max 17 )\n" ) ; scanf( "%s", &name ) ; printf( "prog. no?( ex. O1234 -> 1234 )\n" ) ; scanf( "%d", &o_num ) ; ret = fca_fopen( name, &mode ) ; if ( ret ) { printf( "error in fca_fopen\n" ) ; fca_bye( 1 ) ; return ( ret ) ; } ret = cnc_upstart( o_num ) ; if ( ret ) { printf( "error in cnc_upstart\n" ) ; fca_fclose() ; fca_bye( 1 ) ; return ( ret ) ; } for (;;) { number = BUFSIZE - 1 ; ret = cnc_upload( (struct odbup *)(&buf), &number ) ; if ( ret ) { printf( "error in cnc_upload\n" ) ; cnc_upend() ; fca_fclose() ; fca_bye( 1 ) ; return ( ret ) ; } for ( i = 0 ; i < number ; i++ ) { ret = fca_putc( buf[4+i] ) ; if ( ret == -1 ){ printf( "error in fca_putc\n" ) ; cnc_upend() ; fca_fclose() ; fca_bye( 1 ) ; return ( ret ) ; } printf( "%c", buf[4+i] ) ; } if ( buf[4+number-1] == '%' ) break ; } printf( "\n" ) ; ret = cnc_upend() ; if ( ret ){ printf( "error in cnc_upend()\n" ) ; fca_fclose() ; fca_bye( 1 ) ; return ( ret ) ; } ret = fca_fclose() ; if ( ret ) { printf( "error in fca_close()\n" ) ; fca_bye( 1 ) ; return ( ret ) ; } ret = fca_bye( 1 ) ; if ( ret ) { printf( "error in fca_bye()\n" ) ; } return ( ret ) ; } -----------------------------------------------------------------------------11. Delete a file on FCA device. <Main,Alarm,Comm> -----------------------------------------------------------------------------[Name] fca_delete [Syntax] #include <bios.h> int fca_delete( char *name ) ; [Argument] name Name of the file to be deleted. (max. 17 characters) [Return] Returns zero if successful. Returns -1 if any error occurrs. [Description] This function deletes a file from the FCA device. When the character '#' is used for the first character of the argument "name", which passes the file name of the FCA device, it is assumed that file number is designated. #xxxx ( xxxx is max. 4 digit number ) : xxxxth file [Example] Following sample program deletes the specified file from the FCA device connected to the first channel. #include #include #include #include <stdio.h> <crt.h> <data.h> <bios.h> int example( void ) { ser_t r_para ; char name[18], steetas[2] ; int ret, c ; r_para.baud = BAUD_4800 ; r_para.stop_bit = STOP_2 ; r_para.parity = PARITY_N ; r_para.data_bit = DATA_8 ; r_para.hardflow = 2 ; r_para.dc_enable = 3 ; r_para.dc_put = 0 ; r_para.dc1_code = 0x11 ; r_para.dc2_code = 0x12 ; r_para.dc3_code = 0x93 ; r_para.dc4_code = 0x14 ; ret = fca_setparam( 1, &r_para ) ; if ( ret ) { printf( "error in fca_setparam\n" ) ; return ( ret ) ; } printf( "file name?(max 17 or #xxxx (file no ))\n" ) ; scanf( "%s", &name ) ; ret = fca_delete( name ) ; if ( ret ) { printf( "error in fca_delete\n" ) ; fca_bye( 1 ) ; return ( ret ) ; } ret = fca_status( steetas ) ; if ( ret ) { printf( "error in fca_status\n" ) ; fca_bye( 1 ) ; return ( ret ) ; } c = steetas[ 1 ] ; c &= 0x00ff ; printf( "status is %02X", c ) ; c = steetas[ 0 ] ; c &= 0x00ff ; printf( "%02X\n", c ) ; ret = fca_bye( 1 ) ; if ( ret ) { printf( "error in fca_bye\n" ) ; } return ( ret ) ; } -----------------------------------------------------------------------------12. Change name of a file on FCA device. <Main,Alarm,Comm> -----------------------------------------------------------------------------[Name] fca_rename [Syntax] #include <bios.h> int fca_rename( char *oldname, char *newname ) ; [Argument] oldname newname Old file name. (max. 17 characters) New file name. (max. 17 characters) [Return] Returns zero if successful. Returns -1 if any error occurrs. [Description] This function changes the name of the file in the FCA devices. [Example] Following sample program changes the name of the specified file in the device connected to the first channel. #include #include #include #include <stdio.h> <crt.h> <data.h> <bios.h> int example( void ) { ser_t r_para ; char oldname[18], newname[18], steetas[2] ; int ret, c ; r_para.baud = BAUD_4800 ; r_para.stop_bit = STOP_2 ; r_para.parity = PARITY_N ; r_para.data_bit = DATA_8 ; r_para.hardflow = 2 ; r_para.dc_enable = 3 ; r_para.dc_put = 0 ; r_para.dc1_code = 0x11 ; r_para.dc2_code = 0x12 ; r_para.dc3_code = 0x93 ; r_para.dc4_code = 0x14 ; ret = fca_setparam( 1, &r_para ) ; if ( ret ) { printf( "error in fca_setparam\n" ) ; return ( ret ) ; } printf( "old ret = scanf( printf( "new ret = scanf( name?(max 17 )\n" ) ; "%s", &oldname ) ; name?(max 17 )\n" ) ; "%s", &newname ) ; ret = fca_rename( oldname, newname ) ; if ( ret ) { printf( "error in fca_rename\n" ) ; fca_bye( 1 ) ; return ( ret ) ; } ret = fca_status( steetas ) ; if ( ret ) { printf( "error in fca_status\n" ) ; fca_bye( 1 ) ; return ( ret ) ; } c = steetas[ 1 ] ; c &= 0x00ff ; printf( "status is %02X", c ) ; c = steetas[ 0 ] ; c &= 0x00ff ; printf( "%02X\n", c ) ; ret = fca_bye( 1 ) ; if ( ret ) { printf( "error in fca_bye\n" ) ; } return ( ret ) ; } -----------------------------------------------------------------------------13. Read directory information of FCA device. <Main,Alarm,Comm> -----------------------------------------------------------------------------[Name] fca_readdir [Syntax] #include <bios.h> int fca_readdir( fca_dir *buffer, int ndir, int NFILE ) ; typedef struct { char file_name[18] ;/* file name (max. 17 alpha numeric */ /* characters+null) */ /* first byte:0xFF->not used */ /* :0x00->deleted file */ char file_size[9] ; /* file size(8 digit + null character) */ char wrt_protect ; /* write protect */ /* 'P'-> ON */ /* ' '-> OFF */ char record_code ; /* code */ /* 'B'->Binary */ /* 'E'->EIA */ /* ' '->ISO */ char vol_no[3] ; /*volume number(2 digit+null character)*/ /* ' '->single volume */ char multi_vol ; /* multi volume */ /* ' '->single volume */ /* 'C'->succeeding volume exists */ /* 'L'->last volume */ } fca_dir; [Argument] buffer ndir NFILE Pointer to the buffer which directory information is stored in. Starting file number. Number of files to read. [Return] Returns the number of directory information read if successful. Returns -1 if any error occurrs. [Description] This function acquires the directory information from the FCA devices. Follow the procedure below, to use this function. (1) Call the function with the argument (buffer,ndir,NFILE) specified as (NULL,1,0). (2) (3) The number of directory information from the "ndir"th file to the last file is given as the return value. Allocate memory area sufficient to store above directory information and specify the pointer to this memory area as the argument "buffer". Call this function again with the number of directory information given in (2) specified as the argument "NFILE". (Note) When using MS-DOS format on FANUC Handy File, information other than file name and file size are not valid, and file size value differs from the value gotten when read by personal computer. [Example] Following sample program acquires and displays the directory information of the device connected to the first channel. #include #include #include #include <stdio.h> <crt.h> <data.h> <bios.h> int example( void ) { ser_t r_para ; int i, n, ret ; fca_dir buf[1] ; r_para.baud = BAUD_4800 ; r_para.stop_bit = STOP_2 ; r_para.parity = PARITY_N ; r_para.data_bit = DATA_8 ; r_para.hardflow = 2 ; r_para.dc_enable = 3 ; r_para.dc_put = 0 ; r_para.dc1_code = 0x11 ; r_para.dc2_code = 0x12 ; r_para.dc3_code = 0x93 ; r_para.dc4_code = 0x14 ; ret = fca_setparam( 1, &r_para ) ; if ( ret ) { printf( "error in fca_setparam\n" ) ; return( ret ) ; } ret = fca_readdir( NULL, 1, 0 ) ; if ( ret == -1 ) { printf( "error in fca_readdir 1\n" ) ; fca_bye( 1 ) ; return ( ret ) ; } printf ( "file num = %d\n", ret ) ; printf ( "+--+-----------------+--------+-+-+--+-+\n" ) ; n = ret ; for ( i = 0 ; i < n ; i++ ) { ret = fca_readdir( &buf[0], i + 1, 1 ) ; if ( ret == -1 ) { printf( "error in fca_readdir 2\n" ) ; fca_bye( 1 ) ; return ( ret ) ; } else{ printf( " %02d %-17s %-8s %c %c %-2s %c\n" , i+1 , buf[0].file_name , buf[0].file_size , buf[0].wrt_protect , buf[0].record_code , buf[0].vol_no , buf[0].multi_vol ) ; } } ret = fca_bye( 1 ) ; if ( ret ) { printf( "error in fca_bye\n" ) ; } return ( ret ) ; } -----------------------------------------------------------------------------14. Read status information of FCA device. <Main,Alarm,Comm> -----------------------------------------------------------------------------[Name] fca_status [Syntax] #include <bios.h> int fca_status( char *buffer ) ; [Argument] buffer Memory area to store status information. (Two bytes are required for this area.) [Return] Returns zero if successful. Returns -1 if any error occurrs. [Description] This function reads status information of the FCA devices. Followings are the contents of the status data. First byte: status information 7 6 5 4 3 2 1 0 +----+----+----+----+----+----+----+----+ | SD | 0 | PT | ERROR CODE | +----+----+----+----+----+----+----+----+ | | | +----------> 0: write protect OFF | 1: write protect ON +--------------------> 0: completed sending whole data of a file 1: being sending data of a file * For 'ERROR CODE', refer to the ERROR CODE TABLE. The error code corresponding to the latest error is read as "ERROR CODE". Second byte: type of Floppy Disk 7 6 5 4 3 2 1 0 +----+----+----+----+----+----+----+----+ | - | - | - | C5 | - | C3 | C2 | - | +----+----+----+----+----+----+----+----+ | | | v v v 0 0 1 : single sided double density(1D) 0 1 0 : double sided double density(2D) 1 0 0 : double sided high density (2HD) (Note) It can happen that "ERROR CODE" does not indicate correct error code. ERROR CODE TABLE ERROR CODE CAUSE ---------------+----------------------------------00000(= 0) no error 00001(= 1) file search error 00010(= 2) (not used) 00011(= 3) (not used) 00100(= 4) (not used) 00101(= 5) (not used) 00110(= 6) (not used) 00111(= 7) record size over 01000(= 8) (not used) 01001(= 9) protocol error 01010(=10) (not used) 01011(=11) (not used) 01100(=12) write protect error 01101(=13) (not used) 01110(=14) (not used) 01111(=15) overrun, flaming error 10000(=16) (not used) 10001(=17) FD hard error 10010(=18) RAM error 10011(=19) ROM sum check error 10100(=20) volume sequence error 10101(=21) format error 10110(=22) label error 10111(=23) door open 11000(=24) (not used) 11001(=25) (not used) 11010(=26) code error 11011(=27) (not used) 11100(=28) file read error 11101(=29) drive not ready 11110(=30) system error 11111(=31) power off error [Example] Refer to the example in "Delete a file on FCA device.(fca_delete)". -----------------------------------------------------------------------------15. Read free space size of a floppy disk. <Main,Alarm,Comm> -----------------------------------------------------------------------------[Name] fca_remains [Syntax] #include <bios.h> int fca_remains( long *remains ) ; [Argument] remains Memory area to store the amount of remaining free space of Floppy Disk. [Return] Returns zero if successful. Returns -1 if any error occurrs. [Description] This function reads the amount of remaining free space ( byte count of the free space) in Floppy Disk. (Note) When using MS-DOS format on FANUC Handy File, file size differs from that given by a personal computer. [Example] Following sample program reads and displays the amount of remaining free Tsapce in the Floppy Disk connected to the first channel. #include #include #include #include <stdio.h> <crt.h> <data.h> <bios.h> int example( void ) { int ret ; ser_t r_para ; long remains = 0 ; r_para.baud = BAUD_4800 ; r_para.stop_bit = STOP_2 ; r_para.parity = PARITY_N ; r_para.data_bit = DATA_8 ; r_para.hardflow = 2 ; r_para.dc_enable = 3 ; r_para.dc_put = 0 ; r_para.dc1_code = 0x11 ; r_para.dc2_code = 0x12 ; r_para.dc3_code = 0x93 ; r_para.dc4_code = 0x14 ; ret = fca_setparam( 1, &r_para ) ; if ( ret ) { printf( "error in fca_setparam\n" ) ; return ( ret ) ; } ret = fca_remains( &remains ) ; if ( ret ) { printf( "error in fca_remains\n" ) ; fca_bye( 1 ) ; return ( ret ) ; } printf( " remains = %ld\n", remains ) ; ret = fca_bye( 1 ) ; if ( ret ) { printf( "error in fca_bye\n" ) ; } return ( ret ) ; } 3.11 F-ROM Library ================== Library outline ~~~~~~~~~~~~~~~ Included in the F-ROM Library are the functions which are used to read the data files for the C Executor that are stored in the Flush ROM Module for FS30i (referred to as "F-ROM" hereafter). The data file for the C Executor (referred to as "C Executor data file" hereafter) is the file with the format which can be read by the C Executor applications. There are following three types of C Executor related files which are stored in the F-ROM. (1) C Executor program file This type is a conventional C Executor program file. +--------------------------------------+ | | | | | C Executor program | | | | | +--------------------------------------+ The contents of this file is a C Executor application program which is compiled and converted to the memory card format file. (2) C Executor program + C Executor data file This type is composed of a C Executor program file and C Executor data files combined together. +--------------------------------------+ | | | | | C Executor program | | | | | +--------------------------------------+ | Data file | | directory entry | +--------------------------------------+ | Data file 1 | +--------------------------------------+ | Data file 2 | +--------------------------------------+ | : | | : | | : | +--------------------------------------+ | Data file n | +--------------------------------------+ A C Executor application program is compiled and converted to the memory card format file. Then, Data files are combined to the C Executor program file by executing "dat2mem.com". When power is applied to the CNC, only program part of this type of file is loaded into D-RAM to run. (3) C Executor data file This type is composed of C Executor data files. +--------------------------------------+ | Data file | | directory entry | +--------------------------------------+ | Data file 1 | +--------------------------------------+ | Data file 2 | | | +--------------------------------------+ | : | | : | | : | | : | | : | +--------------------------------------+ | Data file n | +--------------------------------------+ "dat2mem" combines multiple data files into a file and converts it to Memory_Card format file. The C Executor data file is not loaded into D-RAM in CNC. As to the procedure to make previous types of Memory_Card files, refer to: Data file to Memory_Card file conversion utility manual (55d2m.man). [Note] Do not call these library functions while the PMC pages are displayed on the screen. This limitation comes from the F-ROM access arbitration process. This library function can be called in any of the Main/Alarm/ Communication tasks, but they cannot be called in multiple tasks at the same time. List of functions ~~~~~~~~~~~~~~~~~ -------------------------------------------------------------------------Name Function -------------------------------------------------------------------------1. aux_from_open Open the specified F-ROM file. 2. aux_from_close Close the F-ROM file. 3. aux_from_select Select data in the F-ROM file. 4. aux_from_moveptr Move read pointer. 5. aux_from_read Read data from the F-ROM file. 6. aux_from_getdir Read directory information of a F-ROM file. 7. aux_from_getinfo Read F-ROM file information. 8. aux_from_getc Read a character from the F-ROM file. 9. aux_from_gets Read a line from the F-ROM file. -------------------------------------------------------------------------- Function reference ~~~~~~~~~~~~~~~~~~ -----------------------------------------------------------------------------1. Open the specified F-ROM file. <Main,Alarm,Comm> -----------------------------------------------------------------------------[Name] aux_from_open [Syntax] #include <bios.h> int aux_from_open( char *filename, char *mode ) ; [Argument] filename mode Specify the name of the C Executor file in F-ROM to open. Specify access mode. Mode should always be read mode, "r". [Return] Returns zero if successful. Returns non-zero value if any error occurs. Error occurs in the following cases. * When the specified file does not exist. * When the F-ROM file is already opened by aux_from_open() function. * When the F-ROM file is already being accessed by another application. [Description] This function opens a C Executor file in the F-ROM and makes it ready to be read. The F-ROM file which can be opened by this function is C Executor file only. Following F-ROM file names can be specified. * "CEX x.xM" ( specify either "0.5", "1.0", "2.0", "3.0", "4.0", "5.0", "6.0", for "x.x" ) * "CEX?xxxx" ('?' represents a numeric character from '0' to '9') ("xxxx" represents max. 4 alpha-numeric characters) F-ROM file name has to be specified only by upper case letters. Also, the name should be specified in exactly eight characters. In case a file name is shorter than 8 characters, add space characters (20H) to make it 8 character long. -----------------------------------------------------------------------------2. Close the F-ROM file. <Main,Alarm,Comm> -----------------------------------------------------------------------------[Name] aux_from_close [Syntax] #include <bios.h> int aux_from_close( void ) ; [Argument] -----[Return] Returns zero if successful. Returns non-zero value if any error occurs. Error occurs in the following case. * When no F-ROM file is opened by aux_from_open() function. [Description] This function closes an opened C Executor file. -----------------------------------------------------------------------------3. Select data in the F-ROM file. <Main,Alarm,Comm> -----------------------------------------------------------------------------[Name] aux_from_select [Syntax] #include <bios.h> int aux_from_select( char *name ) ; [Argument] name Specify file name to be selected. [Return] Returns zero if successful. Returns non-zero value if any error occurs. Error occurs in the following case. * When specified file does not exist. [Description] This function selects one of the data files in the C Executor data file. File name argument is specified according to the MS-DOS 8.3 format. -----------------------------------------------------------------------------4. Move read pointer. <Main,Alarm,Comm> -----------------------------------------------------------------------------[Name] aux_from_moveptr [Syntax] #include <bios.h> int aux_from_moveptr( long offset, int origin ) ; [Argument] offset origin Byte count from base point. Base point, see description. [Return] Returns zero if successful. Returns non-zero value if any error occurs. Error occurs in the following cases. * When pointer is moved backward beyond top of file * When pointer is moved forward beyond end of file. [Description] This function moves the position of the read pointer on currently selected file. Pointer can be moved to any position. Specify the base point for move by "origin" as follows. FROM_SEEK_CUR FROM_SEEK_END FROM_SEEK_SET current pointer position end of file top of file Moving pointer forward beyond end of file or backward beyon top of file causes error. -----------------------------------------------------------------------------5. Read data from the F-ROM file. <Main,Alarm,Comm> -----------------------------------------------------------------------------[Name] aux_from_read [Syntax] #include <bios.h> int aux_from_read( unsigned char *buffer, unsigned int size ) ; [Argument] buffer size Buffer area to store read data. Size of the data to be read. [Return] Returns size of the data being read if successful. Returns zero if any error occurs. [Description] This function reads data from the selected data file and stores the data in the specified buffer area. Before calling this function, a data file, which data is read from, must be selected by aux_from_select() function. -----------------------------------------------------------------------------6. Read directory information of a F-ROM file. <Main,Alarm,Comm> -----------------------------------------------------------------------------[Name] aux_from_getdir [Syntax] #include <bios.h> int aux_from_getdir( struct infodir *buf, unsigned int *num ) ; struct infodir { char name[13] ; /* file name */ char reserve_1[3] ; /* reserved(not used) */ unsigned long address ; /* address of the first byte of the file */ unsigned long size ; /* file size */ char reserve_2[8] ; /* reserved(not used) */ } ; [Argument] buf num Area to store directory information. Area to store the number of directory entry. [Return] Returns zero if successful, and returns non-zero value if any error occurs. [Description] This function reads the directory information contained in C Executor data file. When "NULL" is specified for "buf", only the number of directory entry is read and stored in "num". Directory information for one data file occupies 32 bytes. -----------------------------------------------------------------------------7. Read F-ROM file information. <Main,Alarm,Comm> -----------------------------------------------------------------------------[Name] aux_from_getinfo [Syntax] #include <bios.h> int aux_from_getinfo( char *name ) ; [Argument] name C Executor file name in the F-ROM. [Return] Returns following value CEXEC CEXEC_DATA C_DATA if successful. C Executor program file C Executor program file + C Executor data file C Executor data file Returns -1 if following errors occur: * specified file does not exist, or * specified file is not a C Executor file. [Description] This function reads information about files stored in the F-ROM. There are following three types of C Executor files which is stored in the F-ROM. This function gives the type of the specified file. (1) C Executor program file This type is a Conventional C Executor program file. (2) C Executor program + C Executor data file Conventional C Executor program file and multiple C Executor data files are combined. (3) C Executor data file Data files for C Executor. "name" specifies the name of the F-ROM file. Following names can be specified as F-ROM file name * "CEX x.xM" ( specify either "0.5", "1.0", "2.0", "3.0", "4.0", "5.0", "6.0", for "x.x" ) * "CEX?Xxxx" ('?' represents a numeric character from '0' to '9') ("xxxx" represents max. 4 alpha-numeric characters) F-ROM file name has to be specified only by upper case letters. Also, the name should be specified in exactly eight characters. In case a file name is shorter than 8 characters, add space characters (20H) to make it 8 character long. -----------------------------------------------------------------------------8. Read a character from the F-ROM file. <Main,Alarm,Comm> -----------------------------------------------------------------------------[Name] aux_from_getc [Syntax] #include <bios.h> unsigned int aux_from_getc( void ) ; [Argument] -----[Return] Return the character being read if successful. Returns 0xFF if any error occurs. [Description] This function gets one character from selected data file. This function replaces line termination code, "Carriage Return + Line Feed ( CR + LF)", with single Line Feed character LF. When error occurs or end of file is detected, 0xFF is returned. Before calling this function, a data file, which data is read from, must be selected by aux_from_select() function. -----------------------------------------------------------------------------9. Read a line from the F-ROM file. <Main,Alarm,Comm> -----------------------------------------------------------------------------[Name] aux_from_gets [Syntax] #include <bios.h> int aux_from_gets( unsigned char *buffer, unsigned int size ) ; [Argument] buffer size Buffer area to store data being read. Data size to be read. [Return] Returns zero if successful. Returns -1 if any error occurs. [Description] This function reads one line of data from the selected data file and stores the data in the specified buffer area. A line is made up with all characters read before Line Feed character ('\n'). Line Feed character being read is stored in the buffer. A null character ('\0') is added at the end of the line. Reading character continues until Line Feed character ('\n) is encountered, end of file is detected or "size - 1" number of characters are read. This function replaces line termination code, "Carriage Return + Line Feed ( CR + LF)", with single Line Feed character LF. Before calling this function, a data file, which data is read from, must be selected by aux_from_select() function. [Example 1] /* Select a file, TEST02.DAT, read and display 10 bytes of data from the beginning of the file. Then move read pointer 50 bytes ahead of current position, and read and display 50 bytes of data. Used functions : aux_from_open , aux_from_close , aux_from_select aux_from_read , aux_from_moveptr */ void sample1(){ int i, ret ; unsigned char read_buf[SIZE] ; int read_size, offset ; if ( aux_from_open( "CEX 1.0M", "r" ) ) { printf( "Failed opening file\n" ) ; } else { if ( aux_from_select( "TEST02.DAT" ) ) { printf( "specified file not exist\n" ) ; } else { read_size = 10 ; ret = aux_from_read( read_buf, read_size ) ; if (ret != 0 ) { for ( i=0 ; i<ret ; i++) { printf( "%c", read_buf[i] ) ; } } printf( "\n---move pointer---\n" ); offset = 50 ; if ( aux_from_moveptr( offset, FROM_SEEK_CUR ) ) { printf( "Failed moving pointer\n" ) ; } else { read_size = 50 ; ret = aux_from_read( read_buf, read_size ) ; if (ret != 0 ) { for ( i=0 ; i<ret ; i++) { printf( "%c", read_buf[i] ) ; } } } } aux_from_close() ; } } [Example 2] /* Open F-ROM file of combined C Executor program file and C Executor data file and display directory list. Used functions : aux_from_open , aux_from_close , aux_from_getdir */ void sample2() { int dir_num, ret , i ; typedef infodir *dirarea ; dirarea dir_area ; printf( "List directory information\n" ) ; if ( aux_from_open( "CEX 1.0M", "r" ) ) { printf( " Failed opening file\n" ) ; } else { if ( aux_from_getdir( (infodir *)NULL, &dir_num ) ) { printf( "No directory information found\n" ) ; } else { if ( dir_num > 0 ) { printf( " --- directory list --- : %d file[s]\n", dir_num ) ; dir_area =(infodir *)malloc( 32 * (dir_num) ) ; if ( dir_area != 0 ) { if ( aux_from_getdir( dir_area, &dir_num ) ) { printf( "ERROR\n" ) ; } else { while ( dir_num > 0 ) { printf ( "%10s \n", &(dir_area->name) ) ; dir_num-- ; (unsigned int)dir_area += 32 ; } } } else { printf( "Could not allocate memory\n " ) ; } } } aux_from_close() ; } } [Example 3] /* Get information of F-ROM file CEX 1.0M, and display. Used function : aux_from_getinfo */ void sample3() { int file_type ; printf( "Showing F-ROM file information\n" ) ; file_type = aux_from_getinfo( "CEX 1.0M" ) ; switch ( file_type ) { case ( CEXEC ) : { printf( "C Executor program \n" ) ; break ; } case ( CEXEC_DATA ) : { printf( "C Executor program + C Executor data file \n" ) ; break ; } case ( C_DATA ) : { printf( "C Executor data file \n" ) ; break ; } default : { printf( "ERROR !! Error code:%x \n", file_type ) ; } } } 3.12 Touch-panel Library ======================== Overview of library ~~~~~~~~~~~~~~~~~~~ 1. Overview In case that the display device is "10.4-inch LCD with touch-panel", the C application can read status of the touch-panel. The information to be read is; Whether touch-panel is pushed or not. The coordinate of the pushed point if pushed. The CNC option "Touch-panel" is required to use touch-panel library. 2. Touch-panel coordinate The touch-panel library uses the following X-Y coordinate system whose origin is put at the upper-left point to represent points on the touch-panel. | | v Y ----> X +-----------------------------------+ |(0,0) | | | | | | | | | | | | | | | | | | | | | | (xxxx,yyyy)| +-----------------------------------+ The cooridinate on the touch-panel is represented as (X,Y) format using this coordinate system. (X:horizontal position, Y:vertical position) The whole coordinate range is (X,Y)=(0,0) - (639,479). This coordinate corresponds with the C Executor screen as below. +-----------------------------------+ |(0,0) | +-----------------------------------+ |(0,48) | | | | | | | | | | | | | | (639,447)| +-----------------------------------+ | (639,479)| +-----------------------------------+ ----^ -- | ^ | | | | | | | B A | | | | v | -- | v ----- A: 640x480 dots (using whole screen.) Text mode Graphic mode CRT_MODE_V30 _VRES16COLOR, _VRES16EXCOLOR, _VRES256COLOR The touch-panel coordinate is same as the graphic coordinate (physical coordinate) for both X and Y. B: 640x400 dots Text mode Graphic mode CRT_MODE_80X25 _98RESS16COLOR, _98RESS8COLOR, _98RESSCOLOR, _98RES16COLOR, _98RES8COLOR, _98RESCOLOR The relation of the touch-panel and the graphic (physical) coordinate is as follows. X(touch-panel) = X(graphic) Y(touch-panel) = Y(graphic) + 48 The relationship between touch-panel and graphic coordinate mentioned here establishes while the touch-panel is calibrated correctly. If the touch-panel is not exactly calibrated, there are little differences between display position and touch-panel coordinate. [Note] The touch-panel can sense only one point at a time. When multiple points are pushed simultaneously, the center point of all pushed points (in consideraton of each pressure) is read. For example, when (100,100) and (200,300) are pushed simultaneously, touch-panel senses that somewhere between (100,100) and (200,300) is pushed. This is caused by the physical specification (analog sensing) of the touch-panel. List of Functions ~~~~~~~~~~~~~~~~~ ---------------------------------------------------------------------Name Function ---------------------------------------------------------------------1. aux_tpl_read Read the status and (X,Y) coordinate of the touch-panel. ---------------------------------------------------------------------- Function Reference ~~~~~~~~~~~~~~~~~~ -----------------------------------------------------------------------------1. Read the status and (X,Y) coordinate of the touch-panel. <Main,Alarm,Comm> -----------------------------------------------------------------------------[Name] aux_tpl_read [Syntax] #include <bios.h> int aux_tpl_read( struct tpl_xy_coord *buf ) ; struct tpl_xy_coord { unsigned int unsigned int tpl_x_coord ; tpl_y_coord ; /* X-coordinate */ /* Y-coordinate */ } ; [Argument] buf X-Y coordinate structure of touch-panel. [Return] 0x80 - 0x82 Touch-panel is being pushed. 0x00 Touch-panel is not being pushed, or any error occurs. [Description] Reads the touch-panel status and the coordinate value of the pushed point when touch-panel is pushed. One of 0x80, 0x81 or 0x82 is returned as the return value when the touch-panel is pushed. The difference of these values is as follows. Value Status -------+--------------------------------------------------0x80 Start pushing. (received HEAD data) 0x81 Keep pushing. (received BODY data) 0x82 End pushing. received TAIL data) Start pushing End pushing v v +---------------------------+ | | ----------+ +------------^ ^ ^ ^ HEAD BODY BODY ... TAIL The status of touch-panel is not buffered. The status at calling this function by the application program is just returned. So, HEAD, BODY, TAIL are not exactly read as this order according to timing of calling by the application program. Usually it is not needed for the application program to distinguish return values, 0x80, 0x81 and 0x82. It is possible to assume that "Touch-panel is pushed" for all return value 0x80 - 0x82. When the return value of this function changes 0x00 -> 0x8N (N=0,1,2), assume that "start pushing". In the same way, "0x8N -> 0x8N" is "keep pushing" and "0x8N -> 0x00" is "end pushing". When the touch-panel is pushed, X and Y coordinates of the pushed points are stored in each "buf.tpl_x_coord" and "buf.tpl_y_coord" with binary format. Touch-panel without calibration ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ The touch-panel is used under calibrated condition usually. "Calibrated condition" is that the calibration data is set to match the actual pushed poisition with the detected coordinate. By clearing the memory of CNC (SRAM), also the calibration data are cleared and the touch-panel is made no-calibrated condition. The near correct pushed coordinates are read under no-calibrated condition. This function returns the different values from the calibrated condition. Value Status -------+--------------------------------------------------0x88 Received HEAD data. 0x89 Received BODY data. 0x8A Received TAIL data. That is, the bit3 of the return value indicates that the no-calibrated coordinate data are received. When "Touch-panel" option doesn't exist in CNC, this function returns "0". [Example] The following program wait until touch-panel is pushed, and displays coordinate of the pushed point. #include <bios.h> #include <stdio.h> void example( void ) { struct tpl_xy_coord buf ; int ret ; while ( !( ret = aux_tpl_read( &buf ) ) ) ; printf( "Touch panel is pushed at (%u,%u),", buf.tpl_x_coord, buf.tpl_y_coord ) ; printf( " this is " ) ; switch ( ret & ~TPL_NOCAL ) { case TPL_HEAD : printf( "HEAD" ) ; break ; case TPL_BODY : printf( "BODY" ) ; break ; case TPL_TAIL : printf( "TAIL" ) ; break ; } printf( " data.\n" ) ; } 4. Code Tables ============== 4.1 Keycode, screen control code ================================ 4.1.1 Keycode +----+------+------+------+------+------+------+-------+------+ | | 0x | 1x | 2x | 3x | 4x | 5x | 6x | 7x | |----+------+------+------+------+------+------+-------+------| | x0 | | | SP | 0 | @ | P | | | | x1 | | | | 1 | A | Q | | | | x2 | | | | 2 | B | R | | | | x3 | | | # | 3 | C | S | | | | x4 | | | | 4 | D | T | | | | x5 | | | | 5 | E | U | | | | x6 | | | & | 6 | F | V | | | | x7 | | | | 7 | G | W | | | | x8 | CAN | | ( | 8 | H | X | | | | x9 | | | ) | 9 | I | Y | | | | xA | EOB | | * | | J | Z | | | | xB | | | + | | K | [ | | | | xC | | | , | | L | | | | | xD |INPUT | | - | = | M | ] | | | | xE | | | . | | N | | | | | xF | | | / | ? | O | | | | +----+------+------+------+------+------+------+-------+------+ +----+------+------+------+------+------+------+-------+------+ | | 8x | 9x | Ax | Bx | Cx | Dx | Ex | Fx | |----+------+------+------+------+------+------+-------+------| | x0 | |RESET | | | | | |F0 | | x1 | | | | | | | |F1 | | x2 | | | | | | | |F2 | | x3 | | | | | | | |F3 | | x4 | |INSERT| | | | | |F4 | | x5 | |DELETE| | | | | |F5 | | x6 | |ALTER | | | | | |F6 | | x7 | | | | | | | |F7 | | x8 |Curs->| | | | | | POS |F8 | | x9 |Curs<-| | | | | | PROG |F9 | | xA |CursDn| HELP | | | | |OFFSET | | | xB |CursUp| | | | | |SYSTEM | | | xC | | | | | | |MESSAG | | | xD | | | | | | |GRAPH | | | xE |PageDn| | | | | |CUSTOM | FR | | xF |PageUp| | | | | |CUSTOM2| FL | +----+------+------+------+------+------+------+-------+------+ - Usage : For example, the keycode for the key 'A' is given as "41" (hex) by combining "4x" and "x1". - SP stands for space(white space). - Function keys or screen selection keys, POS .. CUSTOM, usually cannot be read from application program. - Keys F0 .. F9,FR,FL are soft-keys. 4.1.2 Keycode of special keys on MDI panel (1) Cursor key, Page key Key Symbol Code ---------------+---------------+-----CursorRight MDIKEY_CURRIGHT 0x88 CursorLeft MDIKEY_CURLEFT 0x89 CursorDown MDIKEY_CURDOWN 0x8A CursorUp MDIKEY_CURUP 0x8B PageDown MDIKEY_PAGEDN 0x8E PageUp MDIKEY_PAGEUP 0x8F (2) Editing key Key Symbol Code ---------------+---------------+-----[CAN] MDIKEY_CAN 0x08 [EOB] MDIKEY_EOB 0x0A [INPUT] MDIKEY_INPUT 0x0D [INSERT] MDIKEY_INSERT 0x94 [DELETE] MDIKEY_DELETE 0x95 [ALTER] MDIKEY_ALTER 0x96 (3) Other keys Key Symbol Code ---------------+---------------+-----[RESET] MDIKEY_RESET 0x90 [HELP] MDIKEY_HELP 0x9A (4) Soft keys [FL] [F0][F1][F2][F3][F4] [F5][F6][F7][F8][F9] [FR] Key Symbol Code ---------------+---------------+-----[F0] MDIKEY_14_F0 0xF0 [F1] MDIKEY_14_F1 0xF1 [F2] MDIKEY_14_F2 0xF2 [F3] MDIKEY_14_F3 0xF3 [F4] MDIKEY_14_F4 0xF4 [F5] MDIKEY_14_F5 0xF5 [F6] MDIKEY_14_F6 0xF6 [F7] MDIKEY_14_F7 0xF7 [F8] MDIKEY_14_F8 0xF8 [F9] MDIKEY_14_F9 0xF9 [FR] MDIKEY_FR 0xFE [FL] MDIKEY_FL 0xFF (5) Function keys Key Symbol Code ---------------+---------------+-----[POS] MDIKEY_POS 0xE8 [PROG] MDIKEY_PROG 0xE9 [OFFSET] MDIKEY_OFFSET 0xEA [SYSTEM] MDIKEY_SYSTEM 0xEB [MESSAGE] MDIKEY_MESSAGE 0xEC [GRAPH] MDIKEY_GRAPH 0xED [CUSTOM] MDIKEY_CUSTOM 0xEE [CUSTOM2] MDIKEY_CUSTOM 0xEF 4.1.3 CRT display control characters Code Symbol Function -------+-------+------------------------------------------------------0x08 BS Move cursor left one column. 0x09 TAB Move cursor to the next tab stop. (every 8 columns) 0x0A LF Move cursor down one line. 0x0D CR Move cursor to the beginning of the current line. 0x1B ESC Start escape sequence. 0x1E HOME Move cursor to the home position(upper left corner of the screen). 4.1.4 Display control escape sequences (1) Cursor movement Escape sequence Function ---------------+------------------------------------------------------ESC [H Move cursor to the home position. ESC [l;cH Move cursor to the c th column of the first line. (upper left corner of the screen is addressed as line 1, column 1) ESC [nA Move cursor up n lines. (move 1 line if n is omitted.) ESC [nB Move cursor down n lines. (move 1 line if n is omitted.) ESC [nC Move cursor right n columns. (move 1 column if n is omitted.) ESC [nD Move cursor left n columns. (move 1 column if n is omitted.) ESC D Move cursor down 1 line. Scroll up one line if cursor is at the bottom line. ESC E Move cursor to the left most column of the next line. Scroll up one line if cursor is at the bottom line. ESC M Move cursor up 1 line. Scroll down one line if cursor is at the top line. ESC [s Save current cursor position. ESC [u Restore cursor to the position saved by "ESC [s". (2) Deleting Escape sequence Function ---------------+------------------------------------------------------ESC [K Delete from current cursor position to end of line. ESC [0K Same as above. ESC [1K Delete from current cursor position to beginning of line. ESC [2K Delete current line. ESC [J Delete from current cursor position to end of screen. ESC [0J Same as above. ESC [1J Delete from current cursor position to beginning of screen. ESC [2J Delete whole screen. (3) Inserting/Deleting line Escape sequence Function ---------------+------------------------------------------------------ESC [nL Scroll current cursor line and succeeding lines down n lines, insert n blank lines and move cursor to the beginning of the first newly inserted blank line. ESC [nM Delete n lines beginning from current cursor line to downward, scroll up following lines and move cursor to the beginning of the first line of those scrolled up. (4) Display mode setting Escape sequence Function ---------------+------------------------------------------------------ESC [7h Turn on automatic wrapping around. (Default) ESC [?7h Same as above. ESC [7l Turn off automatic wrapping around. ESC [?7l Same as above. ESC [>5l Make cursor visible. (Default) ESC [>5h Make cursor invisible. ESC [>9l Output video signals to CRT. (Default) ESC [>9h Not output video signals to CRT. (5) Character attribute Escape sequence Function ---------------+------------------------------------------------------ESC [0m Restore default attribute. (White, no blinking, no reverse video) ESC [5m Turn on blinking. ESC [7m Turn on reverse video mode. ESC [25m Turn off blinking. ESC [27m Turn off reverse video mode. ESC [30m Black. ESC [31m Red. ESC [32m Green. ESC [33m Yellow. ESC [34m Blue. ESC [35m Magenta. ESC [36m Cyan. ESC [37m White. For monochrome display device, brightness of each character changes according to color specification as follows. Color Black Red Green Yellow Blue Magenta Cyan White -----------+-----------------------------------------------Brightness Low <-----------------------------------> High For VGA display device, additional escape sequences are available as follows. Escape sequence Function ---------------+------------------------------------------------------ESC [1m Turn on low intensity color. ESC [2m Don't draw background part of character. ESC [3m Turn on low intensity color for background. ESC [21m Draw background part of character. (Default) ESC [22m Turn off low intensity color. ESC [23m Turn off low intensity color for background. ESC [40m Background black. ESC [41m Background red. ESC [42m Background green. ESC [43m Background yellow. ESC [44m Background blue. ESC [45m Background magenta. ESC [46m Background cyan. ESC [47m Background white. On VGA display device, actual displayed colors for each escape sequence are defined by setting of color palettes for character display. The color palettes for character display are changeable by crt_setpalette function. (6) Selecting character set Escape sequence Function ---------------+------------------------------------------------------ESC (1 Select special characters and fragment set of 6x magnified numeric characters. ESC (2 Select fragment set of 6x magnified alphabetic characters. ESC (3 Select graphic character set. ESC (4 Select standard character set. (Default) ESC (6 Select 6x magnified character set. ESC (7 Select European character set (umlaut etc.) ESC (8 Select user defined character set. ESC (A Select JIS Kanji character set (Shift-JIS code). ESC (B Select FANUC Kanji character set (Shift-JIS code). (Default) ESC (C Select FANUC Kanji character set(Shift-FANUC code). ESC (a Select JIS character set (half-size, large font). ESC (b Select JIS character set (half-size, small font). ESC (E Select 9-inch font. ESC (F Select 14-inch font. (Default) 4.2 Displayable characters ========================== 4.2.1 Single byte characters (1) Displayable characters The characters, 20-7F, A0-DF, shown in the following table can be displayed on the screen. | 0123456789ABCDEF -----+----------------0000 | 0010 | 0020 | !"#$%&'()*+,-./ 0030 | 0123456789:;<=>? 0040 | @ABCDEFGHIJKLMNO NOTE: '\' is not a BACKSLASH, 0050 | PQRSTUVWXYZ[\]^_ but a Japanese YEN mark. 0060 | `abcdefghijklmno '~' is not a TILDE mark, 0070 | pqrstuvwxyz{|}~ but a OVERBAR. 0080 | 0090 | 00A0 | xxxxxxxxxxxxxxx -+ 00B0 | xxxxxxxxxxxxxxxx | This part is Japanese half-size 00C0 | xxxxxxxxxxxxxxxx | character set (KATAKANA). 00D0 | xxxxxxxxxxxxxxxx -+ 00E0 | 00F0 | (Note) Mesh mark is displayed for the character code 7F, and wave mark for A0. Above is the code table for the standard character set. ( "ESC (4" ) (2) Control code Following control codes are supported. Code Symbol Function -------+-------+------------------------------------------------------------08 BS Move cursor left one column. 09 TAB Move cursor to the next tab stop. (every 8 columns) 0A LF Move cursor down one line. 0D CR Move cursor to the beginning of the current line. 1B ESC Start escape sequence. 1E HOME Move cursor to the home position(upper left corner of the screen). 4.2.2 2-byte characters (1) JIS 1st level character set Following KANJI characters of JIS 1st level character set are available in C Executor. The characters in parentheses cannot be displayed. If these characters are output, double width space is displayed instead. FANUC original special marks are assigned to 885F through 889D of SJIS code. These special marks are described later. ------------------------------------------------------------------CHARACTER TABLE IS NOT LISTED IN THIS FILE. SEE "42CHAR_J.MAN" FOR JAPANESE KANJI CHARACTER SET. ------------------------------------------------------------------(2) JIS 2nd level character set Only following Kanji characters in JIS 2nd level character set are available for display. If JIS 2nd level Kanji characters other than following are output, double width space is displayed instead. ------------------------------------------------------------------CHARACTER TABLE IS NOT LISTED IN THIS FILE. SEE "42CHAR_J.MAN" FOR JAPANESE KANJI CHARACTER SET. ------------------------------------------------------------------- (3) FANUC special marks The FANUC special marks which are assigned to JIS 1st level character set code are shown below. No. SJIS [JIS ] FANUC Character -------+---------------+-------+---------------------------01 885F [2F40] 0752 right arrow 02 8860 [2F41] 0754 right-up arrow 03 8861 [2F42] 0756 up arrow 04 8862 [2F43] 0758 left-up arrow 05 8863 [2F44] 075A left arrow 06 8864 [2F45] 075C left-down arrow 07 8865 [2F46] 075E down arrow 08 8866 [2F47] 0760 right-down arrow 09 8867 [2F48] 0762 CW arrow 10 8868 [2F49] 0764 CCW arrow 11 8869 [2F4A] 0766 small arc 12 886A [2F4B] 0768 large arc 13 886B [2F4C] 076A small rectangle 14 886F [2F50] 077C finishing mark 1 15 8870 [2F51] 077E finishing mark 2 16 8871 [2F52] 0780 finishing mark 3 17 8872 [2F53] 0782 finishing mark 4 18 8880 [2F60] 1240 1/1 19 8881 [2F61] 1242 2/2 20 8882 [2F62] 1244 3/3 21 8883 [2F63] 1246 4/4 22 8884 [2F64] 1248 5/5 23 8885 [2F65] 124A 6/6 24 8886 [2F66] 124C 25 8887 [2F67] 124E 26 8888 [2F68] 1250 millimeter (mm) 27 8889 [2F69] 1252 centimeter (cm) 28 888A [2F6A] 1254 kilometer (km) 29 888B [2F6B] 1256 square centimeter (cm^2) 30 888C [2F6C] 1258 square meter (m^2) 31 888D [2F6D] 125A square kilometer (km^2) 32 888E [2F6E] 125C cubic centimeter (cm^3) 33 888F [2F6F] 125E cubic meter (m^3) 34 8890 [2F70] 1260 milligram (mg) 35 8891 [2F71] 1262 kilogram (kg) 36 8892 [2F72] 1264 (cc) 37 8893 [2F73] 1266 deciliter (dl) 38 8894 [2F74] 1268 liter (l) 39 8895 [2F75] 126A kiloliter (kl) 40 8896 [2F76] 126C millisecond (ms) 41 8897 [2F77] 126E microsecond 42 8898 [2F78] 1270 nanosecond (ns) 43 8899 [2F79] 1272 horse power (HP) 44 889A [2F7A] 1274 horse power (ps) 45 889B [2F7B] 1276 hertz (Hz) 46 889C [2F7C] 1278 joint-stock corporation 47 889D [2F7D] 127A copyright ((c)) (4) Describing 2-byte characters in source-codes The DIAB-SDS compiler does not support Japanese language. If a 2-byte character whose second byte happens to be 5Ch is included directly in a source file, it is not recognized as correct data. JIS 1st level character set ------------------------------------------------------------------CHARACTER TABLE IS NOT LISTED IN THIS FILE. SEE "42CHAR_J.MAN" FOR JAPANESE KANJI CHARACTER SET. ------------------------------------------------------------------JIS 2nd level character set ------------------------------------------------------------------CHARACTER TABLE IS NOT LISTED IN THIS FILE. SEE "42CHAR_J.MAN" FOR JAPANESE KANJI CHARACTER SET. ------------------------------------------------------------------- 4.2.3 Display code for single byte characters In the following tables, the code of the FANUC characters in each character set selected by the escape sequences, "ESC (x", are shown. . If , for example, 0x20 (space) is output in the "ESC (1" mode, FANUC character of the code 0x00E0 is displayed on the screen. (1) "ESC (1" characters Special characters, Fragments of 6x magnified numeric +----+------+------+------+------+------+------+------+------+------+------+ | | 2x | 3x | 4x | 5x | 6x | 7x | Ax | Bx | Cx | Dx | |----+------+------+------+------+------+------+------+------+------+------| | x0 | 00E0 | 00F8 | 0108 | 0118 | 0128 | 0138 | | 0760 | 0770 | 01F0 | | x1 | 00E1 | 00F9 | 0109 | 0119 | 0129 | 0139 | | 0761 | 0771 | 01F1 | | x2 | 00E2 | 00FA | 010A | 011A | 012A | 013A | 0752 | 0762 | 0772 | 01F2 | | x3 | 00E3 | 00FB | 010B | 011B | 012B | 013B | 0753 | 0763 | 0773 | 01F3 | | x4 | 00E4 | 00FC | 010C | 011C | 012C | 01D8 | 0754 | 0764 | 01E4 | 01F4 | | x5 | 00E5 | 00FD | 010D | 011D | 012D | 01D9 | 0755 | 0765 | 01E5 | 01F5 | | x6 | 00E6 | 00FE | 010E | 011E | 012E | 01DA | 0756 | 0766 | 01E6 | 01F6 | | x7 | 00E7 | 00FF | 010F | 011F | 012F | 01DB | 0757 | 0767 | 01E7 | 01F7 | | x8 | 00F0 | 0100 | 0110 | 0120 | 0130 | 01DC | 0758 | 0768 | 01E8 | 01F8 | | x9 | 00F1 | 0101 | 0111 | 0121 | 0131 | 01DD | 0759 | 0769 | 01E9 | 01F9 | | xA | 00F2 | 0102 | 0112 | 0122 | 0132 | 01DE | 075A | 076A | 01EA | 01FA | | xB | 00F3 | 0103 | 0113 | 0123 | 0133 | 01DF | 075B | 076B | 01EB | 01FB | | xC | 00F4 | 0104 | 0114 | 0124 | 0134 | 01E0 | 075C | 076C | 01EC | 01FC | | xD | 00F5 | 0105 | 0115 | 0125 | 0135 | 01E1 | 075D | 076D | 01ED | 01FD | | xE | 00F6 | 0106 | 0116 | 0126 | 0136 | 01E2 | 075E | 076E | 01EE | 01FE | | xF | 00F7 | 0107 | 0117 | 0127 | 0137 | 01E3 | 075F | 076F | 01EF | 01FF | +----+------+------+------+------+------+------+------+------+------+------+ (2) "ESC (2" Fragments of 6x magnified alphabetic characters +----+------+------+------+------+------+------+------+------+------+------+ | | 2x | 3x | 4x | 5x | 6x | 7x | Ax | Bx | Cx | Dx | |----+------+------+------+------+------+------+------+------+------+------| | x0 | 013C | 014C | 015C | 016C | 017C | 018C | 019C | 01AC | 01BC | 01CC | | x1 | 013D | 014D | 015D | 016D | 017D | 018D | 019D | 01AD | 01BD | 01CD | | x2 | 013E | 014E | 015E | 016E | 017E | 018E | 019E | 01AE | 01BE | 01CE | | x3 | 013F | 014F | 015F | 016F | 017F | 018F | 019F | 01AF | 01BF | 01CF | | x4 | 0140 | 0150 | 0160 | 0170 | 0180 | 0190 | 01A0 | 01B0 | 01C0 | 01D0 | | x5 | 0141 | 0151 | 0161 | 0171 | 0181 | 0191 | 01A1 | 01B1 | 01C1 | 01D1 | | x6 | 0142 | 0152 | 0162 | 0172 | 0182 | 0192 | 01A2 | 01B2 | 01C2 | 01D2 | | x7 | 0143 | 0153 | 0163 | 0173 | 0183 | 0193 | 01A3 | 01B3 | 01C3 | 01D3 | | x8 | 0144 | 0154 | 0164 | 0174 | 0184 | 0194 | 01A4 | 01B4 | 01C4 | 01D4 | | x9 | 0145 | 0155 | 0165 | 0175 | 0185 | 0195 | 01A5 | 01B5 | 01C5 | 01D5 | | xA | 0146 | 0156 | 0166 | 0176 | 0186 | 0196 | 01A6 | 01B6 | 01C6 | 01D6 | | xB | 0147 | 0157 | 0167 | 0177 | 0187 | 0197 | 01A7 | 01B7 | 01C7 | 01D7 | | xC | 0148 | 0158 | 0168 | 0178 | 0188 | 0198 | 01A8 | 01B8 | 01C8 | | | xD | 0149 | 0159 | 0169 | 0179 | 0189 | 0199 | 01A9 | 01B9 | 01C9 | | | xE | 014A | 015A | 016A | 017A | 018A | 019A | 01AA | 01BA | 01CA | | | xF | 014B | 015B | 016B | 017B | 018B | 019B | 01AB | 01BB | 01CB | | +----+------+------+------+------+------+------+------+------+------+------+ (3) "ESC (3" Graphic characters +----+------+------+------+------+------+------+------+------+------+------+ | | 2x | 3x | 4x | 5x | 6x | 7x | Ax | Bx | Cx | Dx | |----+------+------+------+------+------+------+------+------+------+------| | x0 | 1D50 | 1D60 | 1D70 | 1D80 | 1D90 | 1DA0 | 1DB0 | 1DC0 | 1DD0 | 1DE0 | | x1 | 1D51 | 1D61 | 1D71 | 1D81 | 1D91 | 1DA1 | 1DB1 | 1DC1 | 1DD1 | 1DE1 | | x2 | 1D52 | 1D62 | 1D72 | 1D82 | 1D92 | 1DA2 | 1DB2 | 1DC2 | 1DD2 | 1DE2 | | x3 | 1D53 | 1D63 | 1D73 | 1D83 | 1D93 | 1DA3 | 1DB3 | 1DC3 | 1DD3 | 1DE3 | | x4 | 1D54 | 1D64 | 1D74 | 1D84 | 1D94 | 1DA4 | 1DB4 | 1DC4 | 1DD4 | 1DE4 | | x5 | 1D55 | 1D65 | 1D75 | 1D85 | 1D95 | 1DA5 | 1DB5 | 1DC5 | 1DD5 | 1DE5 | | x6 | 1D56 | 1D66 | 1D76 | 1D86 | 1D96 | 1DA6 | 1DB6 | 1DC6 | 1DD6 | 1DE6 | | x7 | 1D57 | 1D67 | 1D77 | 1D87 | 1D97 | 1DA7 | 1DB7 | 1DC7 | 1DD7 | 1DE7 | | x8 | 1D58 | 1D68 | 1D78 | 1D88 | 1D98 | 1DA8 | 1DB8 | 1DC8 | 1DD8 | 1DE8 | | x9 | 1D59 | 1D69 | 1D79 | 1D89 | 1D99 | 1DA9 | 1DB9 | 1DC9 | 1DD9 | 1DE9 | | xA | 1D5A | 1D6A | 1D7A | 1D8A | 1D9A | 1DAA | 1DBA | 1DCA | 1DDA | 1DEA | | xB | 1D5B | 1D6B | 1D7B | 1D8B | 1D9B | 1DAB | 1DBB | 1DCB | 1DDB | 1DEB | | xC | 1D5C | 1D6C | 1D7C | 1D8C | 1D9C | 1DAC | 1DBC | 1DCC | 1DDC | 1DEC | | xD | 1D5D | 1D6D | 1D7D | 1D8D | 1D9D | 1DAD | 1DBD | 1DCD | 1DDD | 1DED | | xE | 1D5E | 1D6E | 1D7E | 1D8E | 1D9E | 1DAE | 1DBE | 1DCE | 1DDE | 1DEE | | xF | 1D5F | 1D6F | 1D7F | 1D8F | 1D9F | 1DAF | 1DBF | 1DCF | 1DDF | 1DEF | +----+------+------+------+------+------+------+------+------+------+------+ (4) "ESC (4" Standard character set +----+------+------+------+------+------+------+------+------+------+------+ | | 2x | 3x | 4x | 5x | 6x | 7x | Ax | Bx | Cx | Dx | |----+------+------+------+------+------+------+------+------+------+------| | x0 | 0020 | 0030 | 0040 | 0050 | 0F80 | 0F90 | 00A0 | 00B0 | 00C0 | 00D0 | | x1 | 0021 | 0031 | 0041 | 0051 | 0F81 | 0F91 | 00A1 | 00B1 | 00C1 | 00D1 | | x2 | 0022 | 0032 | 0042 | 0052 | 0F82 | 0F92 | 00A2 | 00B2 | 00C2 | 00D2 | | x3 | 0023 | 0033 | 0043 | 0053 | 0F83 | 0F93 | 00A3 | 00B3 | 00C3 | 00D3 | | x4 | 0024 | 0034 | 0044 | 0054 | 0F84 | 0F94 | 00A4 | 00B4 | 00C4 | 00D4 | | x5 | 0025 | 0035 | 0045 | 0055 | 0F85 | 0F95 | 00A5 | 00B5 | 00C5 | 00D5 | | x6 | 0026 | 0036 | 0046 | 0056 | 0F86 | 0F96 | 00A6 | 00B6 | 00C6 | 00D6 | | x7 | 0027 | 0037 | 0047 | 0057 | 0F87 | 0F97 | 00A7 | 00B7 | 00C7 | 00D7 | | x8 | 0028 | 0038 | 0048 | 0058 | 0F88 | 0F98 | 00A8 | 00B8 | 00C8 | 00D8 | | x9 | 0029 | 0039 | 0049 | 0059 | 0F89 | 0F99 | 00A9 | 00B9 | 00C9 | 00D9 | | xA | 002A | 003A | 004A | 005A | 0F8A | 0F9A | 00AA | 00BA | 00CA | 00DA | | xB | 002B | 003B | 004B | 005B | 0F8B | 0F9B | 00AB | 00BB | 00CB | 00DB | | xC | 002C | 003C | 004C | 005C | 0F8C | 0F9C | 00AC | 00BC | 00CC | 00DC | | xD | 002D | 003D | 004D | 005D | 0F8D | 0F9D | 00AD | 00BD | 00CD | 00DD | | xE | 002E | 003E | 004E | 005E | 0F8E | 0F9E | 00AE | 00BE | 00CE | 00DE | | xF | 002F | 003F | 004F | 005F | 0F8F | 0F9F | 00AF | 00BF | 00CF | 00DF | +----+------+------+------+------+------+------+------+------+------+------+ (5) "ESC (6" Fragments of 6x magnified characters +----+------+------+------+------+------+------+------+------+------+------+ | | 2x | 3x | 4x | 5x | 6x | 7x | Ax | Bx | Cx | Dx | |----+------+------+------+------+------+------+------+------+------+------| | x0 | | 0100 | | 0196 | | | | | | | | x1 | | 0106 | 013C | 019C | | | | | | | | x2 | | 010C | 0142 | 01A2 | | | 1CE0 | | | | | x3 | | 0112 | 0148 | 01A8 | | | 1CE6 | | | | | x4 | | 0118 | 014E | 01AE | | | 1CEC | | | | | x5 | | 011E | 0154 | 01B4 | | | | | | | | x6 | | 0124 | 015A | 01BA | | | | | | | | x7 | | 012A | 0160 | 01C0 | | | | | | | | x8 | | 0130 | 0166 | 01C6 | | | | | | | | x9 | | 0136 | 016C | 01CC | | | | | | | | xA | | | 0172 | 01D2 | | | | | | | | xB | | | 0178 | | | | | | | | | xC | | | 017E | | | | | | | | | xD | 01D8 | | 0184 | | | | | | | | | xE | 01DE | | 018A | | | | | | | | | xF | | | 0190 | | | | | | | | +----+------+------+------+------+------+------+------+------+------+------+ (*) A 6x magnified character is displayed combining 6 consecutive single byte characters, beginning with the code in above table. (6) "ESC (7" European character set (umlaut , etc.) +----+------+------+------+------+------+------+------+------+------+------+ | | 2x | 3x | 4x | 5x | 6x | 7x | Ax | Bx | Cx | Dx | |----+------+------+------+------+------+------+------+------+------+------| | x0 | 0020 | 0030 | 0040 | 0050 | 0F80 | 0F90 | 0FC0 | 0FD0 | 0FE0 | 0FF0 | | x1 | 0021 | 0031 | 0041 | 0051 | 0F81 | 0F91 | 0FC1 | 0FD1 | 0FE1 | 0FF1 | | x2 | 0022 | 0032 | 0042 | 0052 | 0F82 | 0F92 | 0FC2 | 0FD2 | 0FE2 | 0FF2 | | x3 | 0023 | 0033 | 0043 | 0053 | 0F83 | 0F93 | 0FC3 | 0FD3 | 0FE3 | 0FF3 | | x4 | 0024 | 0034 | 0044 | 0054 | 0F84 | 0F94 | 0FC4 | 0FD4 | 0FE4 | 0FF4 | | x5 | 0025 | 0035 | 0045 | 0055 | 0F85 | 0F95 | 0FC5 | 0FD5 | 0FE5 | 0FF5 | | x6 | 0026 | 0036 | 0046 | 0056 | 0F86 | 0F96 | 0FC6 | 0FD6 | 0FE6 | 0FF6 | | x7 | 0027 | 0037 | 0047 | 0057 | 0F87 | 0F97 | 0FC7 | 0FD7 | 0FE7 | 0FF7 | | x8 | 0028 | 0038 | 0048 | 0058 | 0F88 | 0F98 | 0FC8 | 0FD8 | 0FE8 | 0FF8 | | x9 | 0029 | 0039 | 0049 | 0059 | 0F89 | 0F99 | 0FC9 | 0FD9 | 0FE9 | 0FF9 | | xA | 002A | 003A | 004A | 005A | 0F8A | 0F9A | 0FCA | 0FDA | 0FEA | 0FFA | | xB | 002B | 003B | 004B | 005B | 0F8B | 0F9B | 0FCB | 0FDB | 0FEB | 0FFB | | xC | 002C | 003C | 004C | 005C | 0F8C | 0F9C | 0FCC | 0FDC | 0FEC | 0FFC | | xD | 002D | 003D | 004D | 005D | 0F8D | 0F9D | 0FCD | 0FDD | 0FED | 0FFD | | xE | 002E | 003E | 004E | 005E | 0F8E | 0F9E | 0FCE | 0FDE | 0FEE | 0FFE | | xF | 002F | 003F | 004F | 005F | 0F8F | 0F9F | 0FCF | 0FDF | 0FEF | 0FFF | +----+------+------+------+------+------+------+------+------+------+------+ 4.2.4 Kanji character code Following two types of codes are used in the application program. Shift-JIS code Shift-FANUC code selected by "ESC (B" (default) selected by "ESC (C" In the "ESC (B" mode, application programs can specify Shift-JIS code Kanji characters in character strings, similar to the MS-DOS applications. Shift-JIS code is converted to the FANUC code internally by the library. In the "ESC (C" mode, specified Kanji character code is converted to the FANUC code according to the following rule. Hangul characters or graphic characters can be displayed in this mode. code_high -= 0x6B ; if ( code_low >= 0x80 ) code_low -= 0x60 ; else code_low -= 0x40 ; code_low <<= 1 ; For example, by specifying the code 0x8140, the Hangul character of the FANUC code 0x1600 is displayed on the screen. 5. Other References =================== 5.1 Multitasking ================ 5.1.1 Task classes Application programs are composed of three independent task classes. +- User application program -----------------+ | +========================================+ | | | | | | | (A) Main Task | | | | | | | +========================================+ | | | | +- Auxiliary Task -----------------------+ | | | +===============+ +=================+ | | | | | (B) Alarm | |(C)Communication | | | | | | Task | | Task | | | | | +===============+ +=================+ | | | +----------------------------------------+ | +--------------------------------------------+ (A) Main task Most tasks, like writing onto the screen, reading keys or up-loading/down-loading CNC data, are classed as this task class. All library functions can be used in this task class. (B) Alarm task Normally, the task of this class runs periodically to watch various status information. (C) Communication task Usually, this task class is used to execute tasks related to the Reader/Punch Interface independent of the main task. But it can also be used for tasks other than communications. Similarly, communication tasks can also be accomplished by the tasks of other task classes. Both the alarm task and the communication task are referred to as auxiliary task. Because these two tasks are executed in the background of the main task, they are also referred to as background task. The main task is executed only while user screens are displayed. The alarm task and the communication task is executed background without any relation to the screen display. When user application program is composed of only one task, this task should be the main task. (supplement) Each task class corresponds to the macro-program of the Macro Executor as follows. Macro Executor C Executor -----------------------+--------------------------Conversational Macro Main task Auxiliary Macro Alarm task , Communication task Execution Macro none 5.1.2 Difference of each task class The auxiliary task is limited in available functions compared to the main task. Main task Alarm task Communication task -----------------------+---------------+---------------+------------------Standard functions x x x Key input x Character display x Graphic display x File I/O x x(*1) x(*1) CNC/PMC window function x x(*2) Reader/Punch Interface x x(*3) x(*3) x : can be used - : cannot be used (*1) A file cannot be accessed simultaneously by more than two tasks. File accesses arbitration should be considered by application program. (*2) Simultaneous access with main task will cause busy error. (*3) Accesses to the I/O port should be arbitrated by application program. 5.1.3 Task switching Task switching between the main task and the auxiliary task is executed by calling task management library functions in the application program. To run the auxiliary task periodically, the period is also specified by the application program. The priority of the task class is as follows. task class priority -----------------------+----------Main task low Communication task mid Alarm task high Auxiliary tasks are executed by interrupting the main task. Task switching from the auxiliary task to the task of lower priority is accomplished by calling functions which wait for certain events to happen. There are following functions which are used for this purpose. Event Function -----------------------+-----------------------------Time os_sync_tim(), os_wait_tim() Event flag os_wait_flg() Semaphore os_wait_sem() Status of serial port rs_wait() This type of task management is called "event driven" task management. +-------------------+ +----auxiliary task ----+ (run) +- (wait for event)-+ main task +------------------+ - - - - - (wait) - - - - -+ (run) + - ^ ^ system start Event happens 5.1.4 Data access between tasks To exchange data between tasks, the inter-task common variable is to be used. The variables defined in the special source files, dramver.c and sramver.c, are located in the inter-task common memory as the common variables. When defining the common variables in the files, dramver.c or sramver.c, specify the attribute "volatile" for the variables in the definition statement. Memory address space +--------------------------------+ | common variable (sramver.c) | | |---+ +--------------------------------+ | | common variable(dramver.c) | +---------------------------------+ v ^ v ^ v ^ +----------+ +----------+ +----------+ | | | | | | | Main | | Alarm | |Communica-| | task | | task | |tion task | | | | | | | +-----------------+ | | | | | | | | | | | | | | | | +----------+ +----------+ +----------+ | | v ^ v ^ v ^ | CNC control | +------------------------------------+ | software | | C Executor library(interface) | | | +------------------------------------+ | | v ^ | | +------------------------------------+ | | | C Executor library(kernel) | -> | | | | <- | | +------------------------------------+ +-----------------+ Data cannot be accessed between memory address spaces which are not connected by arrows in above figure. 5.1.5 Task Management Kind of tasks (1) CNC task * CNC interruption tasks Automatic or manual operation, servo control, spindle control, I/O transfer of PMC and execution of the ladder, MDI control, program editing, etc. are realized by these tasks. They are triggered by the timer interruptions and run periodically. There are actually multiple tasks which are waked by the timer interruptions. They are assumed to be single task for simplification in the following explanation. * CNC display task Displaying of the CNC screen, background editing, CNC window processing, etc. are realized by this task. This task is executed in the idle CPU time which is not used by the CNC interruption tasks. (2) User task * Main task Almost all processing of the user application, such as displaying of the user screen, are executed in this task. The TASK1 is the main task. * Background tasks These tasks are usually waked by various events and they are executed independently of the main task. The TASK2 (the communication task) and the TASK3 (the alarm task) are background tasks. These tasks execute the processing about the related events, then suspend execution to wait for the next event again, and give the CPU to the main task. Both the main task and the background tasks are executed in the idle CPU time which is not used by the CNC interruption tasks. 5.2 File system =============== The File system compatible with MS-DOS is included in C Executor library. (1) File definition The entire format is as follows. This supports the layered directories. [drive name:][\][directory name \...]name[.extension] The parts enclosed by [] can be omitted. (2) Drive name This is a English character (one character) indicating the drive in which files are stored. The available drive in C Executor library is as follows. Device Drive name Capacity ---------------+---------------+-----------------------------------S-RAM disk A: Maximum 59 KBytes (251 KBytes with option) S-RAM card B: 256 KBytes - 2MBytes or ATA compatible flash card The each drive names are fixed. (3) File name This contains a Drive name indicated by a character and a name by maximum 8 characters and an extension by maximum 3 characters. The drive name and the file name are separated with ':', and the name and the extension are separated with '.'. The Drive name and the extension are options. The File name is changed to one with capital characters and is discerned. The following characters can be used for a File name. ( The 2 bytes characters can not be used.) Alphabetic characters Numeric characters Special characters A .. Z 0 .. 9 $ & # % ' ( ) - @ ^ { } ~ ` ! _ (4) Reserved file name The following names are reserved for system. CON console device NUL null device This is used for the input from key board or the output to display unit. When this is specified, the objective file is not created. The following names can not be used. AUX..AUX4, COMx, PRN, LPTx, CLOCK, CLOCK$ (5) Wild card The following Wild card characters can be used for the File name and extension. ? * The meaning of any one character The meaning of any plural characters (contain nulls) As using Wild card characters, the file can be flexibly specified. But in case of the file specification with '*', the characters after '*' are neglected. (example 1) "TEST?.C" "TEST1.C" , "TEST2.C" , "TESTA.C" , "TESTB.C" etc. are applied. (example 2) "TEST*.C" "TEST1.C" , "TEST12.C" , "TESTA.C" , "TESTAB.C" etc. are applied. (example 3) "TEST*A.C" The character 'A' is neglected and so this example is the same as example 2). (6) Directory For the file information, names,sizes and update times are registered in the directory. The directory itself is a kind of files and can be layered. The basic directory of layered directories is called "Root directory". The Root directory is automatically created at initializing the device. The directory created below the root one is called "Sub directory". Within the range of the path name length(lower than 64 bytes), the Sub directories are created in so many layers. (7) Path name The following parts in a file definition is named "Path name". The Path name specifies a definite directory in the layered structure of directories. [\][directory name \...]directory name In the above, "[\]" of the head indicates a Root directory. Next "[directory name \...]" is the stretch of directory names continued until the objective directory. A Path name is need to be within 64 bytes. The separator among directories is normally specified with '\' and '/' may be used for the separator. So the latter is supported too. (8) Practicable number of files for opening simultaneously The number of files which the application can open simultaneously is fixed 60 as a whole. I/O Control buffers which are used by High level input/output functions(fopen,fclose,fprintf,...) are prepared respectively 15 for each task. At launching of each task, following three standard input/output functions are opened. stdin stdout stderr console(MDI) input console(CRT) output console(CRT) output (9) S-RAM disk The C Executor application can access a S-RAM disk. A S-RAM disk is a file device built on battery back upped RAM of CNC. Set the size by the unit of KByte in parameter No.8662 for the utilization of S-RAM. A S-RAM disk(max 59 KB,251 KB with option) is automatically initialized at power on right after changing the set data in parameter No.8662. And it is possible to initialize it by calling aux_file_format function in the application program. (10) S-RAM card or ATA flash card It is available for the application program to access a S-RAM card or ATA flash card which is inserted in the card slot beside LCD display device of FS30i. Refer "3.7 File Operation Library (37file.man)" for usage of memory card. 5.3 Power-on procedure ====================== 5.3.1 Key operation at power on On FS30i with C Executor, the special procedure is executed when the power is turned on with pushing the definite MDI keys. Key pushed at power on Execution ---------------+------------------------------------------------[M] + [0] The System starts up without executing C Executor. The CNC is executed in the same condition as no C Executor installed. This is used for disregarding C Executor function transiently. [M] + [3] The System application is launched without launching the User application. (note) * [M]+[0] means that [M] key and [0] key are pushed at one time. [M]+[3] means the same. * Please continue to push these keys till the normal NC screen or the user screen of C Executor is displayed after power on. 5.4 Parameter setting on CNC ============================ Parameters related to C Executor Descriptions of parameters Data number #7 #6 #5 #4 #3 #2 #1 #0 +--------+ +------+------+------+------+------+------+------+------+ | 8650 | | | | | CKM | | EKY | CNA | RSK | +--------+ +------+------+------+------+------+------+------+------+ Data format : Bit type RSK Specifies whether the key code is transferred to application when a reset key is pushed. 0 : not transferred 1 : transferred CNA Specifies whether the screen is changed to NC alarm screen when NC alarm is generated during the user screen by C Executor is displayed. 0 : the change whether automatically or not is decided by the value of parameter No.8000#1 NAP. 1 : Do not change without relation of the value of parameter No. 8000#1 NAP. EKY Expanded parts (9 through 11 lines) of MDI key are 0 : not read. 1 : read. CKM The bit-matrix of MDI key is 0 : not transferred to NC side. 1 : transferred to NC side. Set this bit to 1 only when it is specially need to read directly the bit-matrix in NC side. Set it to 0 normally. (Note) The change of the set data becomes effective after the next power on. Data number Data +--------+ +-------------------------------------------------------+ | 8661 | | Size of variable areas | +--------+ +-------------------------------------------------------+ Data format : word type Data unit : KByte Data range : 0 through 59 (251) Specify the size of the static variable areas which can be set by each task. Specify it by the unit of 1 Kbyte. The maximum size is 59 KBytes (251 KBytes in the case with SRAM 256 KB option). And the total value of a SRAM Disk size and this size should not exceed (usable SRAM size -1) KBytes (that is 63 or 255 KBytes). (Note) When this value is changed, the contents of variable areas and a SRAM Disk are initialized. The change of the set data becomes effective after the next power on. Data number Data +--------+ +-------------------------------------------------------+ | 8662 | | Size of SRAM Disk | +--------+ +-------------------------------------------------------+ Data format : word type Data unit : KByte Data range : 4 through 63 (255) Specify the size of a SRAM Disk. Specify it more than 4 KBytes by the unit of 1 KByte. The maximum size is 63 KBytes (255 KBytes in the case with SRAM 256KB option). And the total value of the size of variable area and this size should not exceed (usable SRAM size -1) KBytes (that is to say, 63 or 255 KBytes). (Note) When this value is changed, a SRAM Disk is initialized. The change of the set data becomes effective after the next power on. Data number Data +--------+ +-------------------------------------------------------+ | 8663 | | Specification of time zone | +--------+ +-------------------------------------------------------+ Data format : 2-word type Data unit : second Data range : -12*3600 through 12*3600 Specify the equation of time from Greenwich time by the unit of second. The value is -9 hours in Japan. (the value is -9*3600=-32400) (Note) The change of the set data becomes effective after the next power on. Data number Data +--------+ +-------------------------------------------------------+ | 8781 | | DRAM size used in C Executor | +--------+ +-------------------------------------------------------+ Data format : Byte type Data unit : 64 KBytes Data range : 12 through 96 Specify the size of a DRAM used in C Executor. And specify the value of more than 768 KBytes by the unit of 64 KBytes. It is regarded as 0 in the case that the value is set out of range. When the value is 0, the C Executor is not implemented. (Note) The usable size is also limited by the RAM size and the assembly of option. 5.5 Dat2mem utility manual ========================== ---------------------------------------------------Data file to Memory_Card file conversion utility ---------------------------------------------------The "dat2mem.com" is a utility program which converts arbitrary MS-DOS data file to Memory_Card file that is used for CNC. It reads multiple data files to make a Memory_Card file which can be directly loaded into CNC. It can also combine data files with existing Memory_Card file of a C Executor program to make up new Memory_Card file. (1) C Executor data file C Executor Library supports functions which make application programs capable of reading data files stored in the F-ROM of CNC controls. The data file of the format which can be read by C Executor applications is referred to as C Executor data file. Multiple MS-DOS data files can be combined and stored in a C Executor data file. C Executor application program can read individual MS-DOS files by specifying its file name. There are following two types of C Executor data file. (1) Data only file +-----------------------+ | Memory_Card file | | header | +-----------------------+ | Data file | | directory entry | +-----------------------+ | Data file 1 | | | +-----------------------+ | Data file 2 | | | +-----------------------+ | ... | | | +-----------------------+ | Data file n | | | +-----------------------+ Multiple MS-DOS data files are combined in this file. F-ROM file identification name for this type of file is "CEXnxxxx" where 'n' is a number from 0 to 9 and "xxxx" is any combination of max. 4 alphanumeric characters. Ten C Executor data files ( "CEX0xxxx" -"CEX9xxxx") can be stored in the F-ROM at maximum. Files stored in the F-ROM are identified by using leftmost 4 characters of the identification name. As a result, the files with identification names "CEX1DATA" and "CEX1TEXT" are assumed as the same file. That is, if a file "CEX1TEXT" is written to the F-ROM in which a file "CEX1DATA" is stored, the file "CEX1DATA" is deleted and only the file "CEX1TEXT" remains. The size of the C Executor data file is calculated by Memory_Card header size (416 bytes) + directory entry size (16 + number of data files * 32 bytes) + total size of all data files, and the F-ROM memory blocks of 128KB unit is allocated to the file. In this type of file are general data or machine tool dependent data (system parameters or offset data). (2) File with C Executor program and data +-----------------------+ | Memory_Card file | | header | +-----------------------+ | | | C Executor program | | | | | +-----------------------+ | Data file | | directory entry | +-----------------------+ | Data file 1 | | | +-----------------------+ | Data file 2 | | | +-----------------------+ | ... | | | +-----------------------+ | Data file n | | | +-----------------------+ --^ | Loaded into DRAM | when power ON v --- Multiple MS-DOS data files are combined with existing C Executor program file, in this type of file. F-ROM file identification name for this type of file is "CEX xxxM" where "xxx" stands for "1.0", "2.0", etc. Only one file of this type can be stored in F-ROM. It is also not allowed to put both this type of file and a C Executor program file without data file in the F-ROM. The size of this type of file is calculated by size of existing C Executor program file + directory entry size (16 + number of data file * 32 bytes) + total size of all data files and the F-ROM memory blocks of 128KB unit is allocated to the file. This type of file is suited to store the data closely related to the C Executor program, screen data for example. For both types C Executor data file, C Executor application program opens a C Executor data file by specifying file identification name ,"CEXnxxxx" or "CEX xxxM", then selects and reads one of the data files in it. In the directory entry, the "8.3 format" file name, data size and origin address in F-ROM file for each MS-DOS files are stored. C Executor application program can read the contents of this directory entry. There are no specific limitations for the size or type of the MS-DOS data file which is converted by this utility. The contents of the MS-DOS data file is stored in the C Executor data file as it is. (2) Necessary hardware * Personal computer executable for Microsoft Windows 2000 or Windows 98 * Free disk space larger than twice of the Memory_Card file size being created. (3) How to execute Type as follows after prompt. C:\> dat2mem xxx [Enter] "xxx" stands for the name of the Command file mentioned later. (4) Command file Command file is the file in which names of the related files are written. The format of the Command file is as follows. * * * * * A line beginning with semicolon is assumed as a comment line and ignored. A line with spaces only is ignored. Only the first word of the line other than above is valid. Leading space characters(space or tab character) of a line are ignored. Necessary information are written in the following order. (1) Name of the Memory_Card file being created Specify the name( usually *.mem) of the Memory_Card file to be created. The format of the file name part should be "CEXnxxxx", where 'n' is a number from 0 to 9 and "xxxx" is any combination of max. 4 alpha-numeric characters, "CEX1TOOL.MEM" or "CEX3DOC.MEM" for example. When creating new Memory_Card file by combining data files to the existing C Executor Memory_Card file, arbitrary Memory_Card file name can be specified. Drive name or directory name can be added as necessary. (2) Name of the existing C Executor Memory_Card file Specify the name ( usually *.mem) of the existing Memory_Card file in which C Executor program is stored. Add drive name or directory name as necessary. It is not necessary to specify this file name, when creating a C Executor data file which is composed of data file only. (3) Name of the data file Specify the name of the data file to be converted. Add drive name or directory name as necessary. Wild card characters, '*' or '?', can also be specified. When wild card characters are used, all files which match with the specified name are converted. File name cannot contain multi-byte characters or katakana characters. Only single byte alpha-numeric characters cam be used for the file name. Name of the data file may be specified in multiple lines. Maximum of 2000 data files can be combined in a Memory_Card file. [Example 1] Command file which combines all "*.dat" files in the directory "c:\data" and creates "CEX1PARM.MEM". --<< from the next line >>---------------------------------------------------;================================ ; DAT2MEM Specification file ;================================ ;---------------------------------------------------------------CEX1PARM.MEM ;---------------------------------------------------------------c:\data\*.dat ;---------------------------------------------------------------; end of spec file --<< to the previous line >>-------------------------------------------------[Example 2] Command file which combines data files, "\work\scrn1.dat", "\work\scrn2.dat" and "\text\msg.txt" , with existing file "cexec.mem" and creates new Memory_Card file "cexec_d.mem". --<< from the next line >>---------------------------------------------------;================================ ; DAT2MEM Specification file ;================================ ;---------------------------------------------------------------cexec_d.mem ;---------------------------------------------------------------cexec.mem ;---------------------------------------------------------------\work\scrn1.dat \work\scrn2.dat \text\msg.txt ;---------------------------------------------------------------; end of spec file --<< to the previous line >>-------------------------------------------------- (5) Error messages It can happen that following error messages are displayed. "insufficient memory" Cannot allocate enough memory to execute the program. "file open error xxx (??H)" Cannot open the file xxx. "file create error xxx (??H)" Cannot create the file xxx. "file read error xxx (??H)" Encountered an error while reading the file xxx. "file write error xxx (??H)" Encountered an error while writing into the file xxx. "insufficient disk space for xxx" Lack of free disk space to create the file xxx. "unexpected EOF xxx, line#??" Detected the end of file when attempted to read the ??th line of the file xxx. This can happen when command file is described incompletely. "invalid Memory_Card filename xxx" Invalid Memory_Card file name is specified. In case of data only Memory_Card file, the only acceptable file name format is "CEXnxxxx" where 'n' is a number from 0 to 9 and "xxxx" is any combination of alpha-numeric characters. There is no restrictions for the name of the Memory_Card file which contains C Executor program and data. "file xxx not found (??H)" Cannot fine the file xxx. "file searching error xxx (??H)" Encountered an error while searching for the file xxx. "too many input file" Attempted to convert more than 2000data files. "invalid filename xxx" Invalid characters, katakana characters or multi-byte characters, are included in the name of the data file. Files should be named with single-byte alphanumeric characters only. "not a simple Memory_Card file xxx" Data files are already combined in the specified C Executor Memory_Card file . Specify the Memory_Card file which contains C Executor program file only. 5.6 Conforming O8-digits program number ======================================= The program numbers are 8 digits in C language Executor for FANUC Series 30i. It is not compatible with the application of the program number 4 digits designed for FANUC Series 16/18. Please change the application referring to "Conforming CNC window library to O8-digits program number option" of the FANUC Series 16/18 C Executor programming manual. 5.7 Window task =============== 5.7.1 Overview C Executor system is composed of 3 tasks, Main task, Alarm task and Communication task. The Window task is fourth additional task to these 3 tasks. +--------------------------------------------+ | CNC Interruption TASKs | +--------------------------------------------+ +----------------------------+ +-------------+ +- | Alarm TASK | | | | +----------------------------+ | | Aux. tasks | +----------------------------+ | | +- | Communication TASK | | Window TASK | +----------------------------+ | | +-------------+ +------------+ | | Display tasks | Main TASK | | CNC TASK | | | +-------------+ +------------+ +-------------+ CNC tasks The window task runs with the tree tasks of C Executor and the CNC's display task simultaneously. This task is like the auxiliary tasks of C Executor, but it can display to the screen unlike them. About displaying screen, the window task is similar to the main task except that the target screen to display is only the VGA windows. So, it is impossible to display without VGA display device. (The execution itself is available even if any display device is equipped.) The window task can't read MDI key unlike the main task. It can read the status of touch-panel. The window task is provided for the following purposes. On the CNC with VGA display device, it opens VGA windows on the screen and controls them, and receives the commands of the operator via input signals of PMC or touch-panel. Such as controling "Software machine control panel" on the screen with touchpanel. It can be applied to the general purposes, but it is most suitable task to the above purpose. 5.7.2 Window task's execution The window task is loaded on the memory with the other tasks in the powerup sequence of CNC. This task is not automatically started. To start the window task, call "os_strt_wtsk()" function by the main task. When this function is executed successfully, the window task starts running simultaneously with the other 3 tasks and the CNC's display task. 5.7.3 Usage of the window task The typical processing flow of the window task is as follows. (1) (2) (3) (4) (5) (6) (7) Start | Initialize | | <---------------------+ | <----------------+ | | | | Wait the trigger ----------+ | to display no trigger | | | | | Open VGA window | | | | <----------------+ | | | | Display and read commands | | | | | | | | If display end -----------+ | | not end | | | Close VGA window | | | +-----------------------+ (1) Start The window task starts from "main()" function by calling "os_strt_wtsk()" in the main task. (2) Initialize General initialization such as variable setting,etc. (3) Wait the trigger to display The application program checks whether it should display VGA window or not. There are some conditions for the trigger to start displaying. Input signal from PMC. (using "pmc_rdpmcrng()" function) Status of touch-panel (using "aux_tpl_read()" function) Status of CNC (using "cnc_statinfo()" function,etc.) Notification of the other tasks (notify via DRAM/SRAM common variables) It is possible to always display the VGA window. (4) Open VGA window The application program opens VGA window using "vwin_open()" function. (5) Display and read commands The application program displays to the VGA window. It also receives operator's commands. To receive commands, use the following method; (because the application can't read MDI keys.) Input signal from PMC. (using "pmc_rdpmcrng()" function) Status of touch-panel (using "aux_tpl_read()" function) Notification of the other tasks (notify via DRAM/SRAM common variables) (6) If display end The application program detects the trigger to close the VGA window. It checks informations as same as "(3) Wait the trigger to display". (7) Close VGA window The application program closes the VGA window using "vwin_close()" function. It is possible to always open VGA windows on the screen rather than the application program opens them on demands. Also it is possible to open the invisible VGA window. 5.7.4 Available functions for the window task The following functions are available for the window task. (1) ANSI C Standard library All functions which are available for the main task are available. (2) MS-C extended C standard library All functions which are available for the main task are available. (3) Graphic library All functions which are available for the main task are available. The target screen to display is not the ordinary screen but VGA window. (4) CNC/PMC window library All functions which are available for the main task are available. Some functions require exclusive control between the other tasks. (5) MDI operation library Unavailable. (6) CRT operation library All functions which are available for the main task are available. The target screen to display is not the ordinary screen but VGA window. (7) File operation library Unavailable. (8) Serial library Unavailable. (9) Task management library Available except "os_strt_wtsk()". But it is ineffective to send/ receive events with the other tasks. (10) FCA library Unavailable. (11) F-ROM library Unavailable. (12) Touch-panel library Available. (13) Inter-task common variables (DRAM/SRAM) Available. 5.7.5 How to make application program The procedure to make window task application is mentioned below. Basically, it is same as the ordinary application which is composed of main task, alarm task and communication task. (1) Making main/alarm/communication tasks. "os_strt_wtsk()" function must be called in the main task. Except this, there is nothing to especially take case. Description of makefile about these tasks is same as usual. (2) Making window task. Make source modules (*.c) which include a "main()" function and other functions called from main() as same as the other tasks. (3) Definition modules of window task in makefile. Define object module names of the window task in the module definition line "TASK4 = " in makefile. (Example) TASK4 = winmain.o wintsk1.o wintsk2.o (4) Compile and link by "nmake" command. (5) Load the created memory card file into the CNC and run it. There is no special parameter setting about window task. 5.7.6 Notes Take case of the followings for using window task. (1) Task structure The task number of the window task is '4'. The window task is called "TASK4". All tasks of whole application including window task are as below. TASK1 TASK2 TASK3 TASK4 Main task Communication task Alarm task Window task 5.8 Conforming CNC screen display ================================= 5.8.1 Overview It is possible to run C Executor on the following equipments on which "CNC screen display" application. * FS300i (CNC equipment with Personal Computer function) * FS300i connected via high-speed serial bus with Personal Computer, and FS300i connected via Ethernet with Personal Computer. (using CNC's screen or PC's screen) The above two CNC equipments are described as "FS300i with PC" and "FS300i with HSSB/Ethernet" (HSSB:High Speed Serial Bus) in this document. For both CNCs, it is possible to display on the virtual CNC screen displayed on PC's screen by "CNC screen display" application as same as on the ordinary CNC screen. The virtual CNC screen is equivalent to VGA display device. C Executor application program which runs on the ordinary CNC equipment can also run on these equipments by re-compiling and linking as it is. (Some source codes might be modified.) Some screen display functions are restricted by "CNC screen display" application, and some function's behaviors are different from ordinary specifications on the true CNC. The "CNC screen display" application is abbreviated as "CNCscrnApp" in the following sections of this document. 5.8.2 How do application program run on each equipment In this section, how each task of the application program runs is described. (1) FS300i with PC Status of CNC & PC -------------------- Status of C-EXE application ------------------------------ PC starts | v CNC starts -------> Auxiliary tasks start [1] | | v | "CNCscrnApp" starts ------------> Main task starts [2] | | | | | *---> Window | | | [3] v | | "CNCscrnApp" ends ----------------------> x - - - - | | .[4] | | . v | . "CNCscrnApp" starts --------------------> x - - - - | | |[6] | | | v | | "CNCscrnApp" ends ----------------------> x - - - - | | .[4] | | . v v v task starts | | > x |[5] | | > x |[7] | | > x |[5] | v [1] Auxiliary tasks start at CNC system start-up time. After started, they run as same as on the ordinary FS30i. Because the main task and the window task don't run until "CNCscrnApp" starts for the first time, auxiliary tasks can't communicate with the main task or the window task. Except this, it is not necessary for auxiliary tasks to take care of whether CNC screen is displayed on PC or not. (Auxiliary tasks may not exist.) [2] The main task starts at the first time "CNCscrnApp" started. After this, it runs as same as on the ordinary FS30i until "CNCscrnApp" closes. Until then, the main task runs during displaying C-EXE screen and it sleeps during displaying CNC's screen. [3] The window task starts when "os_strt_wtsk()" function is called in the main task. After this, the window task goes on running whether CNC's screen is displayed or not. (The window task may not exist.) [4] The main task goes sleeping when "CNCscrnApp" is closed. This status is same as the screen is changed to CNC's screen. If C-EXE application inhibits screen changing, "CNCscrnApp" can't close itself. The application program should sometimes enable to change the screen. [5] The window task must close already opened VGA windows when "CNCscrnAPP" is terminated. "CNCscrnApp" can't close itself while any VGA windows keep opening. It is possible to test whether "CNCscrnApp" is going closed or not by "crt_pcinfo()" function. [6] The main task runs again when "CNCscrnApp" is re-opened. CNC's screen is selected when "CNCscrnApp" is re-opened. (That is, the main task is sleeping.) After then, the main task runs actually when C-EXE screen is selected. [7] The window task re-display VGA windows when "CNCscrnApp" is opened again. It is possible to test whether "CNCscrnApp" is re-opened or not by "crt_pcinfo()" function as same as [5]. (2) FS300i with HSSB/Ethernet Status of CNC & PC -------------------- Status of C-EXE application ------------------------------ CNC starts -------> Auxiliary tasks start [1] | --------------------> Main task starts [2] | | | | | *---> Window task starts | CNC side display | | [3] | v | | | "CNCscrnApp" starts --------------------> x - - - - - > x | | |[4] |[5] | PC side display | | | v | | | "CNCscrnApp" ends ----------------------> x - - - - - > x | | |[6] |[7] | CNC side display | | | v v v v [1] Auxiliary tasks start at CNC system start-up time. After started, they run as same as on the ordinary FS30i. It is not necessary for auxiliary tasks to take care of whether CNC screen is displayed on PC or not. (Auxiliary tasks may not exist.) [2] The main task starts after the auxiliary tasks started. It runs as same as on the ordinary FS30i until "CNCscrnApp" is opened on PC. Until then, the main task runs during displaying C-EXE screen and it sleeps during displaying CNC's screen. [3] The window task starts when "os_strt_wtsk()" function is called in the main task. After this, the window task goes on running whether CNC's screen is displayed or not. (The window task may not exist.) [4] When "CNCscrnApp" starts on PC, the main task goes sleeping once. Because CNC's screen must be selected for changing the screen between CNC side and PC side. After starting PC display, by changing the screen to C-EXE the main task runs again and the C-EXE screen is displayed. If C-EXE application inhibits screen changing, changing to PC side screen can't be completed. The application program should sometimes enable to change the screen. [5] The window task should close already opened VGA windows when "CNCscrnAPP" starts up. VGA windows opened on CNC side screen are still displayed after starting "CNCscrnApp" on PC side. To display VGA windows on PC side screen, once close VGA windows after starting "CNCscrnApp", then open them again. It is possible to test on which of CNC side or PC side the current screen is displayed by "crt_pcinfo()" function. [6] When "CNCscrnApp" is closed on PC and CNC side screen wakes up again, the main task goes sleeping once. Because CNC's screen must be selected for changing the screen between CNC side and PC side. After starting CNC side display, by changing the screen to C-EXE the main task runs again and the C-EXE screen is displayed. If C-EXE application inhibits screen changing, changing to CNC side screen can't be completed. The application program should sometimes enable to change the screen. [7] The window task must close already opened VGA windows when "CNCscrnAPP" is terminated. "CNCscrnApp" can't close itself while any VGA windows keep opening. It is possible to test whether "CNCscrnApp" is going closed or not by "crt_pcinfo()" function. After changing to CNC side, the window task opens VGA windows again. 5.8.3 Restrictions on specification In this section, differences from C Executor on the ordinary FS30i are described. You can regard the specifications which are not listed below as same as on the ordinary FS30i with VGA display device. The following descriptions are applied to PC side screen if no special comment. They runs on FS300i with HSSB/Ethernet as same as the ordinary FS30i. [*] mark which is added to "unavailable ..." etc. means that no error occurs and nothing is done even if the function is used. (1) It is impossible to start or terminate "CNCscrnApp" while C-EXE application inhibits screen changing. If starting or terminating "CNCscrnApp" is attempted during screen changing inhibition, the CNC equipment goes hung-up and "CNCscrnApp" can't run newly on PC. To recover this, it is required to restart both CNC equipment and PC. (2) The screen is initialized by changing screen between CNC side and PC side. At this time, all contents already displayed are cleared. So the application program must redraw the screen. (3) It is unavailable to access a memory card inserted in a memory card slot of FS300i with PC. An error ("Memory card is not inserted.") occurs if "aux_file_mount( 'B' )" is called. (4) Overlapping method about text and graphics in 16-color graphics (in which both text and graphics are displayed overlapping each other) is different from the ordinary FS30i. "Composite" mode is not supported. [*] Only "Character over graphics" or "Graphics over character" can be selected. The default mode if "Character over graphics". crt_setpalette( _PAL_COMP, CRT_PAL_COMP ) unavailable crt_setpalette( _PAL_COMP, CRT_PAL_CHAR ) available(default) crt_setpalette( _PAL_COMP, CRT_PAL_GRPH ) available (5) 256-color graphics is unavailable. [*] The following graphic modes which select 256-color graphics can't be specified in "_setvideomode()" function. _98RES16COLOR, _98RES8COLOR, _98RESCOLOR, _VRES256COLOR (6) Automatic key repeating is always effective for key-input from both PC's keyboard and MDI keyboard while PC side screen is alive. (It is independent of the application program setting.) While CNC side screen is alive on FS300i with HSSB/Ethernet, whether automatic key repeating is effective or not depends on the application program setting. (7) Customizing of MDI key for CNC's screen is unavailable. [*] "aux_mdi_putmatrix()" or "aux_mdi_altmatrix()" functions take no effect to CNC side key matrix. (8) It is impossible to turn ON and OFF back-light of LCD screen by "ESC [>9l" and "ESC [>9h" while PC side screen is alive. [*] (9) It is impossible to set LCD screen reverse. [*] That is, "crt_setpalette( _PAL_RVS, xxx )" is unavailable. (10) It is impossible to start or terminate "CNCscrnApp" while VGA windows are opened. (11) The main task and the window task don't run until "CNCscrnApp" starts first time after system-power-on on FS300i with PC. (12) It is unavailable to control function-keys on MDI panel by C-EXE application with "crt_setswt( CRT_SWT_MFKY )". [*] It is impossible to read function-key information even if "crt_readfkey()" function is executed. [*] 5.8.4 Making application program A) Alterations It is required for the already existing application program to modify the source codes as it avoids specification restrictions if you want to run the program on FS300i. You should take care of the following notices for making new application program. Index number of the following notices corresponds to the previous section's each item number. (1) An application program which runs on FS300i should not make screen changing inhibited. For example, don't execute "crt_setswt( CRT_SWT_DIS )" (don't inhibit screen changing actively), execute "crt_setswt( CRT_SWT_GREN )" while it draws graphics (enable to change screen during drawing graphics), etc. (2) Redraw all contents in the user screen if the screen is switched between CNC side and PC side. For example, get the current output device, CNC or PC, using "crt_pcinfo()" function, and if it switches, redraw whole screen. (3) Don't execute I/O operation from/to DRIVE B: (memory card) on FS300i with PC. (4) The application program which uses "Composite" graphic mode doesn't correctly draw graphics on FS300i. It is needed to redesign color specification for application screen using "Character over graphics" mode. (5) Don't use 256-color graphics mode. Modify the application program to use only 16 colors. (6) If you want not to use automatic key repeating on PC side screen, set delay time and interval time for key repeating both as max value (1024[msec]) using "aux_mdi_repeat()" function. (7) If you want to customize MDI key mapping for CNC's screen, alter key mapping on PC side ("CNCscrnApp"). (8),(9) To control LCD display (turning ON/OFF the back-light, reversing the screen), use the ordinary screen control feature of PC. (10) While the application program is displaying VGA windows, call "crt_pcinfo()" function periodically and close all VGA windows when PC side application is terminated. (11) The application program which runs on FS300i with PC must have an execution architecture such as it runs correctly without the main task and the window task running. For example, ladder program of PMC or macro program don't refer variables in which the main task sets any value, because it is no warranty that the main task has already run when ladder or macro program is executed. Execute initialization processes not in the main task but in any auxiliary tasks. (12) Basically, leave CNC screen switching control to CNC software. C-EXE application program should not touch screen switching process. B) Application building process Application building process for FS300i is same as for the ordinary FS30i. You will follow C-EXE application building process for the ordinary FS30i. The built memory-card-file is stored in F-ROM of CNC equipment. For FS300i with HSSB/Ethernet, write to F-ROM using boot menu as same as the ordinary FS30i. For FS300i with PC, write to CNC's F-ROM by PC side application program. C) Other notices Screen refresh speed may slow down while PC side screen is alive according to its PC's processor performance. But CNC internal process executions which is independent of screen displaying (such as auxiliary tasks execution) run as same speed as the ordinary FS30i. 5.8.5 Function reference -----------------------------------------------------------------------------1. Get status of CNC screen display application <Main> -----------------------------------------------------------------------------[Name] crt_pcinfo [Syntax] #include <crt.h> unsigned short crt_pcinfo( void ) ; [Arguments] -----[Return] Returns status of CNC screen display application. [Description] Gets status of "CNC screen display" application program which runs on PC of FANUC Series 300i. "CNC screen display" application program is used to display CNC screen (including C-EXE screen) on FS300i. CNC screen can be displayed only while this application program is running. This function is used to test if CNC screen is available or not when C Executor application program runs on FS300i. This function returns the following data as return value. Upper byte Lower byte +------------------------+------------------------+ | CNC system type | Status of "CNCscrnApp" | +------------------------+------------------------+ (1) CNC system type This is 1-byte value which indicates if CNC is FS300i with PC. CRT_CNC_30i 0x00 CRT_CNC_150I 0x01 Not FS300i with PC (ordinary FS30i, FS300i with HSSB/Ethernet) FS300i with PC (2) Status of "CNCscrnApp" This is a pack of bit-flags which indicates the status of "CNC screen display" application on PC. "1" means "effective" for each bit. CRT_PC_ENB 0x01 CRT_ETH_SIDE 0x08 CRT_PC_END CRT_PC_PWON CRT_PC_DWN CRT_PC_SIDE 0x10 0x20 0x40 0x80 "CNC screen display" is available. (This bit is set as "1" when CNC is FS300i with PC, FS300i with HSSB, FS300i with Ethernet.) CNC screen is displayed now. (FS300i with Ethernet) PC application terminated. PC application is starting up now. PC is down now. CNC screen is displayed now. You can get the current output device using CRT_PC_SIDE and CRT_ETH_SIDE. CRT_PC_SIDE CRT_ETH_SIDE Output device ---------------+---------------+-----------------------------0 0 CNC's display unit 1 0 PC (HSSB) display unit 1 1 PC (Ethernet) display unit 0 1 undefined The main task of C Executor runs only while CNC screen is displayed on PC side.(in case of FS300i with PC) Auxiliary tasks and the window task always run whether CNC screen is displayed or not. This function is used to test if screen function is available or not in auxiliary tasks or the window task. For example, "if CNC screen goes closed, the window task closes VGA windows", for this case, this function is used. Screen switching must be enabled when "CNCscrnApp" starts up and ends. (If screen switching is disabled, "CNCscrnApp" can't start/ end.) Call this function periodically, and enable screen switching when CRT_PC_PWON or CRT_PC_END flag rises up. [Example] The following program closes VGA windows when "CNCscrnApp" goes closed on PC. (This is executed in the window task.) #include <crt.h> void example( void ) { unsigned short pcinfo ; pcinfo = crt_pcinfo() ; /* Is CNC 300i ? */ if ( pcinfo & CRT_PC_ENB ) { /* Has PC app closed or been down ? */ if ( pcinfo & ( CRT_PC_END + CRT_PC_DWN ) ) { vwin_close( 0 ) ; vwin_close( 1 ) ; } } } 5.9 High-Level Task ==================== 5.9.1 Overview of High-Level Task High-Level Task is the independent task of C Executor ordinary tasks (Main Task, Auxiliary Tasks and Window Task) and is called at fixed intervals. Task priority +-------------------------------------------------------+ | CNC interrupt Tasks (Axis control,PMC execution,etc.) | | +--------------------+ | | High-Level Task | +----------------------------------+--------------------+ | CNC interrupt Tasks (Preparing, Automatic operation) | +----------------------------------+--------------------+ | Auxiliary Tasks | | +----------------+-----------------+ Window Task | | Main Task | CNC display Task| | +----------------+-----------------+--------------------+ High ^ | | | | | v Low 5.9.2 Specification (1) Execution spec. Execution interval 8 msec (Interval time is not always fixed. Refer following "Task execution rule".) Max. execution time 1 msec (for each 8 msec) (Actually, max. approx. 0.8 msec of execution time is recommended. Refer following "Task execution rule" for the details.) (2) Available variable types and operators The following variable types are available in High-Level task. Type char, unsigned char, short, unsigned short, int, unsigned int, long, unsigned long, array of these types and pointers to these type variables. Kind auto variable, static variable, global variable, D-RAM/S-RAM shared variable. The following operations are available in High-Level task. arithmetical operations (+,-,*,/,%) and logical operations (>>,<<,&, |,^,~) and kindred operations (++,--,&&,||, etc.) to char, unsigned char, short, unsigned short, int, unsigned int, long, unsigned long types. (3) Available library functions Only the following functions are available in High-Level Task. rettask() cnc_hldata() Stop execution of a high-level task Start and stop acquiring high-level task execution management data cnc_rdprgnum() Read the program number of a program being executed cnc_rdseqnum() Read the sequence number of a sequence being executed cnc_actf() Read the actual feed rate (F) of a controlled axis cnc_acts() Read the actual rotation speed of the spindle cnc_absolute() Read the absolute position of a controlled axis cnc_machine() Read the machine position of a controlled axis cnc_relative() Read the relative position of a controlled axis cnc_distance() Read the distance-yet-to-go of a controlled axis cnc_skip() Read the skip position of a controlled axis cnc_srvdelay() Read the servo delay amount for a controlled axis cnc_accdecdly() Read the acceleration/deceleration delay amount for a controlled axis cnc_alarm() Read alarm status cnc_rdspload() Read information about the load on the serial spindle cnc_adcnv() Read A/D conversion data pmc_rdpmcrng() Read arbitrary PMC data (input range specified) pmc_wrpmcrng() Output arbitrary PMC data (output range specified) All of the other library functions are unavailable. High-Level Task can't call all existent library functions, for example, ANSI standard functions such as "printf", "malloc", "strcpy", etc. or FANUC original functions other than those above. Refer to 34window.man for descriptions about functions other than rettask() or cnc_hldata(). (4) Reading/Writing PMC data Using pmc_rdpmcrng() and pmc_wrpmcrng() can, respectively, read and write PMC data (internal relays (R) and keep relays (K)). Refer to 34window.man for descriptions about pmc_rdpmcrng() or pmc_wrpmcrng(). (5) Data sharing with the other tasks High-Level Task can share data with the other tasks via D-RAM common variables (dramver.c) or S-RAM common variables (sramver.c). 5.9.3 Task execution rule High-Level Task is called after CNC task in the periodical interrupt procedure at 8msec intervals. <---- 8msec ---> <---- 8msec ---> <---- 8msec ---> |----------------|----------------|----------------| |--->|==>| |--->|==>| |--->|==>| (A) (B) (A) CNC task (B) C-EXE High-Level Task High-Level Task (B) is surely called once at each 8 msec. But execution intervals are not always exact 8 msec. (T1) (T2) <---- 8msec ---> <---- 8msec ---> <---- 8msec ---> <---- 8msec ---> |----------------|----------------|----------------|----------------| |--->|==>| |----->|==>| |--->|==>| |--->|==>| |<---- 9msec ----->|<--- 7msec -->|<---- 8msec --->| T1 T2 Interval of interrupt procedure Interval of High-Level Task ( == 8 msec ) ( != 8 msec ) The timing of calling High-Level Task changes according to execution time of CNC task (A) as mentioned above. Generally, each tasks on CNC system, such as CNC, PMC, Servo, etc., run synchronously by hand-shaking each other. Therefore, nothing must be considered about relationship to the other tasks even if the execution intervals change. Total processing time of above-mentioned (B) is limited up to 1 msec for each interruption. When the task attempts to run over 1 msec, the execution is forcedly interrupted by timer interruption. The interrupted task will restart its execution from the interrupted instruction in the next timer interruption procedure. <---- 8msec ---> <---- 8msec ---> <---- 8msec ---> |----------------|----------------|----------------| |--->|===>| |--->|=>| |--->|==>| (B) ^ ^ (B') INTERRUPTED RESTART |<------------ 16msec ----------->| (actual interval) In this case, a series of process is divided into multiple parts that are executed on separate interruptions. Therefore, it makes actual interval of the task longer than 8 msec. To avoid this, it is recommended to keep reserve of execution time for High-Level Task, not to reach the upper limit 1 msec. For example, keep actual max. execution time of High-Level task up to approximately 0.8 msec. C Executor management procedure takes approx. 0.02 msec for calling High-Level task. This time is included in the execution time of High-Level task. High-Level Task has priority over the other CNC tasks such as preparing task. If High-Level task runs long time, CPU time for CNC preparing task, etc. may be reduced. (In this case, any harmful effect, such as machining time by CNC's automatic operation increases, etc., may occur.) To avoid influence to the other tasks, it is better to keep execution time of HighLevel task as short as possible The following variables (management data) are defined for looking over the execution time of High-Level Task. extern struct HL_MNGDATA HL_DATA ; The detail of this management data is mentioned below. Each task of C Executor application that includes High-Level task starts as following order. Task start-up order ~~~~~~~~~~~~~~~~~~~ Initialize CNC soft | v Initialize C-EXE | v Prepare all tasks |-----------------------+ v | Start Alarm task | (Interruption procedure | | for every 8 msec) v | Start Communication task | | v v Start High-Level task Start Main task | v Start Window task (Alarm/Communication/Window tasks may not exists.) High-Level task starts on the 1st 8 msec interrupt procedure just after completion of preparation for all tasks. This execution doesn't link to any other tasks' start-up. Therefore, start-up order of High-Level task and the other tasks if not fixed. 5.9.4 Application programming The following sections mention development process of application including High-Level Task. (1) Source module(s) The structure of High-Level Task's source modules is same as the other tasks. That is, it has one or more source modules ( "*.c" file ) and one "main()" function is included in them. The structure of "main()" function is as follows. void main( void ) { [Initialization] <-- This is executed only at 1st interruption. for(;;) { [Process for each 8 msec] rettask() ; <-- This function interrupts the } execution of High-Level Task. } A series of process that is executed at each 8 msec makes a loop program flow. "rettask()" function must be called in the loop. (2) Describing makefile List the module names of High-Level Task on "TASK5=" line in module definition section on the top of "makefile". List depending relationship of each modules in module dependency block on the bottom of "makefile". These describing format is same as the other tasks. (3) Compiling and linking Compiling and linking process is same as the ordinary application program. (4) Setting, etc. No special settings (such as CNC parameter, etc.) are required for application program including High-Level Task. It is loaded into CNC and run as same as the ordinary application program. 5.9.5 Function reference -----------------------------------------------------------------------------1. Interrupt execution of High-Level Task <HILEV> -----------------------------------------------------------------------------[Name] rettask [Syntax] void rettask( void ) [Arguments] -----[Return] -----[Description] Interrupts High-Level Task's process. This function is called at the end of a series of process (for each 8 msec) in High-Level Task. The execution will restart just after this function in the next High-Level Task (after 8 msec). The program structure of High-Level Task is generally as follows. void main( void ) { [Initialization] for(;;) { [Process for each 8 msec] rettask() ; } } This function must be called in the main loop like this. -----------------------------------------------------------------------------2. Start and End of getting the High-Level task execution management data <HILEV> -----------------------------------------------------------------------------[Name] cnc_hldata [Syntax] #include <hilev.h> int cnc_hldata( int mode ) ; [Arguments] mode execution mode (DATA_START/DATA_END) [Return] Always 0 returns. [Description] The start and end of execution management data getting. The program structure of High-Level Task is generally as follows. void main( void ) { [Initialization] for(;;) { cnc_hldata( DATA_START ); [Process for each 8 msec]] cnc_hldata( DATA_END ); rettask() ; } } Make sure that the desired processing is executed between cnc_hldata calls, as shown above. [Attention] Please do not call this function in the case that don't get execution management data, to economize on processing time. 3. High-Level task execution management data "High-Level task execution management data" are variables in where how HighLevel task runs is stored. The following structure is defined. struct HL_MNGDATA { unsigned long unsigned int unsigned int unsigned int unsigned int unsigned int unsigned int unsigned int unsigned int unsigned int unsigned long HL_COUNT ; HL_STIME ; HL_ETIME ; HL_MAXETIME ; HL_MAXPROCTIME ; HL_TIMEOVER ; HL_RETFLAG ; HL_BUFCTRL ; HL_BUFSIZE ; HL_BUFIDX ; HL_PTRBUF ; } ; extern struct HL_MNGDATA HL_DATA ; All tasks can access this "HL_MNGDATA". All members are readable and writable. HL_COUNT High-Level task calling count (accumulated value). HL_STIME HL_ETIME High-Level task's execution start time. High-Level task's execution end time. When High-Level task starts and ends in each 8 msec interruption process are recorded in these members. This value is elapsed time ([micro-sec]) from the top of each 8 msec interruption process. And the next operation shows execution time of HighLevel task ([micro-sec]). HL_ETIME - HL_STIME HL_MAXETIME Maximum value of HL_ETIME. This is the maximum value of end time of High-Level task's execution. This indicates the maximum elapsed time of interruption process. The unit of this value is [micro-sec]. HL_MAXPROCTIME Maximum value of (HL_ETIME - HL_STIME) This is the maximum execution time of High-Level task. The unit of this value is [micro-sec]. HL_TIMEOVER Total counts that execution time exceeds the limit (1 msec). This is total count that High-Level task attempts to exceeds 1 msec execution time and is forcibly terminated. HL_RETFLAG "rettask()" function execution flag. This is internal flag. HL_BUFCTRL HL_BUFSIZE HL_BUFIDX HL_PTRBUF Execution time logging control flag. Execution time logging buffer size. Execution time logging buffer index. Pointer to execution time logging buffer. These are control variables for logging High-Level task's execution time (HL_STIME and HL_ETIME). To set command value in HL_BUFCTRL starts logging function. HL_BUFCTRL = 0 Stop logging (initial state) 1 Start logging (one shot) 2 Start logging (repeat) Before starting logging function, set address of buffer memory in HL_PTRBUF and byte size of it in HL_BUFSIZE. Buffer size must be multiple of 8. HL_BUFIDX is index which indicates writing position. At start time of logging, set HL_BUFIDX = 0. After starting logging, HL_STIME and HL_ETIME are stored in buffer memory for each High-Level task calling. When the index encounters the end of buffer, one of the following process will be done. HL_BUFCTRL = 1 HL_BUFCTRL = 2 Stop logging. HL_BUFCTRL is set as 0. Continue logging from the top of buffer memory with setting writing index (HL_BUFIDX) as 0. Data format stored in buffer memory is as follows. Byte offset from the top of buffer Stored data -------------------+--------------+0000 HL_STIME (0) +0004 HL_ETIME (0) +0008 HL_STIME (1) +0012 HL_ETIME (1) : : 5.10 Programming technique ========================== 5.10.1 Various techniques (1) Making application program faster There is considerable over-head in calling library function of C Executor. (in comparison with personal computer's applications.) This is mainly based on the two reason. 1. Execution of function may changes privilege level. To display to the screen or to call CNC window process, procedure changes privilege level. This transition of privilege level needs many CPU clocks. 2. Function may request CNC software. All "Write function" and a part of "Read function"(reading macro variable, etc.) of CNC window functions request CNC software to process, and wait completion. This takes more than 8msec ( = a half of poring period of CNC software) on the average. Therefore, frequent calling of function may make the processing speed of the application program down. Reducing function calling count, by using single function calling for multiple processes, makes speed up. (Example) * Character output Use "putchar()" to display one by one. --> Use "puts()" or "printf()" to display one character string. * Reading/Writing NC data To read/write the continuous data, use "range type" function other than single access type function. On VGA display device, characters are displayed very slowly while the character cursor is enabled by "ESC[>5l". To avoid this, disable the cursor by specifying "ESC[>5h" mode. (2) How to use inter-task common variable There are two type variables (memory) that C Executor application can access. Local memory Memory that only owner task can access. Inter-task common memory Memory that all tasks can access. < C Executor memory > +-------------------------------+ | Library memory | +-------------------------------+ | TASK1 local memory | +-------------------------------+ | TASK2 local memory | +-------------------------------+ | TASK3 local memory | +-------------------------------+ | Inter-task common memory | +-------------------------------+ --+ | +- Only each task can access. | --+ --+ +- All tasks can access. --+ Program code, global variables, static variables and stack are (including local variables) for each task are allocated in each task's local memory. < Local memory for each task > +-------------------------------+ | Program code | +-------------------------------+ | Global variables, | | Static variables | +-------------------------------+ | Stack area (Local variables) | +-------------------------------+ For multitask application, inter-task common variables, which are allocated on common memory area, is used to share information with the other tasks. There are two memory area for inter-task common variable on S-RAM and D-RAM. The variables which are defined in "SRAMVER.C" and "DRAMVER.C" of the application program are allocated on inter-task common memory area of S-RAM and D-RAM. < Inter-task common memory area > +-------------------------------+ | S-RAM common memory | <-- Vars. defined in SRAMVAR.C +-------------------------------+ | D-RAM common memory | <-- Vars. defined in DRAMVAR.C +-------------------------------+ These memory objects are able to accessed by each task. Put all data which are used for exchanging information between tasks on this inter-task common memory area. (i.e.,in variables defined in SRAMVER.C or DRAMVER.C) Take care of exchanging pointers between tasks. It is possible to exchange pointer value stored in common variable between tasks. But don't put data, which are pointed by the pointer, on the local memory area for each tasks. When the other task attempts to access the local memory of another task using the pointer, invalid memory access occurs. It is possible to exchange pointers which point memory object allocted on the common memory. 5.10.2 Applying C Executor to machine (1) Machine maintenance Machine Tool Builders(MTB) can make their own custom man-machine interface, such as screen display and operation method, on CNC device made by FANUC using C Executor. This is better for MTB and end users in most case. However, take care the following point. FANUC servicemen maintain FANUC-CNC which is equipped with machine tool running on field. FANUC servicemen well know about FANUC-CNC's operations. But they don't well know the MTB own operation methods. If servicemem don't suitably operate the machine by MTB own operation methods, maintenance work may not be carried smoothly. By the following consideration in MTB, problems on maintenance work are reduced. * Attach the manual on which operation method of your application is described to the machine surely. * Keep the NC screens which are needed for maintenance work (mainly such as [SYSTEM] screens) displayable. * Enable the basic machine operation even without your C application. (For example, while CNC is started with [M]+[0] keys.) (2) Application which needs sure response The auxiliary tasks don't well respond to the events because of task management specification. For example, in the application which has a periodical auxiliary task execution, the actual period of the auxiliary task may scatter by 10 - 20 [msec]. This is based on that the C application tasks coexist with the NC software tasks and its priority is lower than the NC task. The C application has an enough response for man-machine interface processing. Use the PMC ladder software or the C application of PMC for processing which needs sure response. For example, sampling machine signals or load of motors periodically, communicating with the other devices, PMC is more suitable for these application than C Executor. INDEX B-63944EN-3/01 INDEX <Number> <H> 2-byte characters........................................................... 720 High-Level Task ........................................................... 760 How do application program run on each equipment ... 750 <A> How to make application program.......................... 59, 748 ANSI C standard library ..................................... 18, 38, 70 <I> Application program......................................................... 8 Application program development environment............. 14 INDEX............................................................................ 35 Application programming............................................. 764 Installing the Diab C/C++ Power-PC compiler .............. 65 Applying C Executor to machine.................................. 772 <K> Available functions for the window task ...................... 747 Kanji character code ..................................................... 726 <C> Key operation at power on............................................ 734 C Executor ........................................................................ 6 Keycode ........................................................................ 713 C language library function list ...................................... 18 Keycode of special keys on MDI panel ........................ 714 C library............................................................................ 7 <L> CNC/PMC window library ............................... 24, 48, 301 List of Functions............................................................. 38 Code Tables .................................................................. 713 <M> Compatibility related to variables of type 'int' ................ 66 Composition of development system.............................. 14 MAKEFILE .................................................................... 63 Conforming CNC screen display .................................. 749 Making application program......................................... 755 Conforming O8-digits program number ....................... 744 MDI operation library................................................... 482 CRT display control characters..................................... 715 MS-C extended C standard library ......................... 21, 204 CRT operation library................................................... 507 Multitasking.................................................................. 727 <D> <N> Dat2mem utility manual ............................................... 738 Notes................................................................................... Data access between tasks ............................................ 729 <O> Describing 2-byte characters in source-codes................. 66 Other libraries ........................................................... 26, 51 Development procedure.................................................. 16 Other References........................................................... 727 Difference of each task class......................................... 728 Outline ............................................................................ 59 Display code for single byte characters ........................ 723 Overview........................................................... 3, 745, 749 Display control escape sequences................................. 715 Overview of High-Level Task....................................... 760 Displayable characters .................................................. 719 <P> <F> Parameter setting on CNC ............................................ 735 FCA Library ................................................................. 659 Power-on procedure...................................................... 734 Feature .............................................................................. 4 Programming technique................................................ 770 File Operation Library .................................................. 604 <R> File system.................................................................... 731 F-ROM Library............................................................. 692 Remarks .......................................................................... 67 Function reference .......................................... 68, 757, 765 Required software for application development ............. 37 Restrictions on specification......................................... 754 <G> Graphic library.................................................. 22, 46, 207 i-1 INDEX B-63944EN-3/01 <S> Save current environment for non-local jump. <Main,Alarm,Comm> .................................................. 111 Serial Library................................................................ 612 Single byte characters ................................................... 719 Special files .................................................................... 62 Specification ................................................................. 760 System components .......................................................... 6 <T> Task classes .................................................................. 727 Task execution rule....................................................... 762 Task Management......................................................... 730 Task management library.............................................. 631 Task switching.............................................................. 728 The hardwares of CNC which are used in C Executor.... 11 Touch-panel Library ..................................................... 707 <U> Usage of the window task ............................................. 746 Using compiler libraries ................................................. 66 <V> Various techniques ....................................................... 770 <W> Window task................................................................. 745 Window task's execution .............................................. 745 i-2 Jul., 2003 Date 01 Edition Contents Edition Date Contents FANUC Series 30i/300i/300is-MODEL A C Language Executor PROGRAMMIG MANUAL (B-63944EN-3) Revision Record • No part of this manual may be reproduced in any form. • All specifications and designs are subject to change without notice.