/* * ***************************************************************** * * * * * Copyright (c) Fast Corporation, 2001 * * * * * * All Rights Reserved. Unpublished rights reserved under * * * the copyright laws of the Japan. * * * * * * The software contained on this media is proprietary to * * * and embodies the confidential technology of Fast * * * Corporation. Possession, use, duplication or * * * dissemination of the software and media is authorized only * * * pursuant to a valid written license from Fast Corporation. * * * * * ***************************************************************** */ /* CSC90X アライメント&RS232Cコマンド通信(標準入出力版)ALIGNSTD.C */ /*[作成者]H.Yagi */ /* 目的: 関数: 履歴: Ver 1.0 97/08/14 Ver 1.2 01/10/12 プログラム終了時に標準入出力を強制的にC-NETに設定していたのを プログラム起動前の設定に戻すよう修正。 注記:m_menu.hをインクルードして下さい。 m_menu.c及びm_note.cをリンクして下さい。 */ /* * Include compiler runtime library */ #include #include #include /* * Include CSC90X library */ #include "f_stdlib.h" #include "f_time.h" #include "f_gui.h" #include "f_stdio.h" #include "f_graph.h" #include "f_image.h" #include "f_pinf.h" #include "f_video.h" #include "f_system.h" #include "f_search.h" /* * Include CSC90X common local */ #include "m_menu.h" /* * プロトタイプ宣言 */ void main( void ); void main_menu_disp( void ); void disp_help( void ); int search_exec( void ); void remote( void ); void rmt_search( void ); int d4i5_d( double ); void draw_cros( int, int ); void point_set( void ); void user_proc1( int, int, PARADIGM * ); void user_proc2( int, int, PARADIGM * ); void kanrenzuke( void ); extern int message_note( void ); /* * メニュー項目 */ #define LANG_N 2 #define MAIN_MENU_N 4 static const char *str_main_menu[MAIN_MENU_N][LANG_N] = { { " GRAY ", " グレイ " }, { "SET POINT ", " 座標設定 " }, { " LEARN ", "サーチ&関連付" }, { " REMOTE ", " リモート " } }; #define INIT_CUR_POS_X 255 #define INIT_CUR_POS_Y 239 #define MAX_NO_GRAY_SEARCH 50 static int Rslt_Buf[(MAX_NO_GRAY_SEARCH * 3)]; int pad_level; PVAL value[2]; static char ss[70]; double search_x, search_y; int zahyo_x1, zahyo_y1; int zahyo_x2, zahyo_y2; int sotai_x1, sotai_y1; int sotai_x2, sotai_y2; int v_zahyo_x1, v_zahyo_y1; int v_zahyo_x2, v_zahyo_y2; /* * メイン */ void main( void ) { int sts; int xpos; int ypos; int s_xpos; int s_ypos; int std_terminate; int stdin, stdout; /* 初期メッセージ表示 */ if( NORMAL_RETURN != message_note() ) return; /* パラメタ初期化 */ xpos = INIT_CUR_POS_X; ypos = INIT_CUR_POS_Y; s_xpos = INIT_CUR_POS_X; s_ypos = INIT_CUR_POS_Y; /* 入力ビデオ制御 */ Lib_input_video_control( GRAY_PLANE ); /* ビデオ出力表示項目制御 */ Lib_display_control( GRAY_PLANE | LINE_PLANE | CHAR_PLANE ); /* ビデオ表示項目クリア */ Lib_memory_clear( LINE_PLANE | CHAR_PLANE ); /* カーソル初期化 */ Lib_init_cursor(); /* メインメニューの表示 */ main_menu_disp(); /* マウスカーソルの表示 */ Lib_draw_cursor( INIT_CUR_POS_X, INIT_CUR_POS_Y ); /*GRAY_PTN.SYSを使用する*/ if ( NORMAL_RETURN == Lib_gs_open_data_file( CONTINUE_PTN_AREA ) ) { std_terminate = Lib_get_terminate(); stdin = Lib_get_stdin(); stdout = Lib_get_stdout(); /* 標準入出力 オープン */ Lib_set_terminate( TERMINATE_CRLF ); Lib_set_stdin( RS232C_CH0 ); Lib_set_stdout( RS232C_CH0 ); if ( NORMAL_RETURN == Lib_open_io( ) ) { v_zahyo_x1 = zahyo_x1 = 255; v_zahyo_y1 = zahyo_y1 = 240; v_zahyo_x2 = zahyo_x2 = 255; v_zahyo_y2 = zahyo_y2 = 240; /* メニュー制御 */ for (;;) { sts = 0; /* マウス位置読みとり */ sts = Lib_see_current_position( &xpos, &ypos ); if ( s_xpos != xpos || s_ypos != ypos ) { /* マウス表示位置移動 */ Lib_move_cursor( xpos, ypos ); s_xpos = xpos; s_ypos = ypos; } /* 処理振り分け */ if ( CURSOR_EXECUTE == sts ) { if ( xpos > MENU_1_XS && xpos < MENU_1_XE && ypos > MENU_1_YS && ypos < MENU_1_YE ) { Lib_memory_clear( LINE_PLANE | CHAR_PLANE ); Lib_system_process( GRAY_MENU ); /* GRAYパッドの呼出し */ Lib_memory_clear( LINE_PLANE | CHAR_PLANE ); main_menu_disp(); } else if ( xpos > MENU_2_XS && xpos < MENU_2_XE && ypos > MENU_2_YS && ypos < MENU_2_YE ) { Lib_memory_clear( LINE_PLANE | CHAR_PLANE ); point_set(); /* 座標設定 */ Lib_memory_clear( LINE_PLANE | CHAR_PLANE ); main_menu_disp(); } else if ( xpos > MENU_3_XS && xpos < MENU_3_XE && ypos > MENU_3_YS && ypos < MENU_3_YE ) { Lib_memory_clear( LINE_PLANE | CHAR_PLANE ); kanrenzuke( ); /* サーチ&関連付 */ main_menu_disp(); } else if ( xpos > MENU_4_XS && xpos < MENU_4_XE && ypos > MENU_4_YS && ypos < MENU_4_YE ) { Lib_memory_clear( LINE_PLANE | CHAR_PLANE ); Lib_erase_cursor(); remote(); /* リモート */ Lib_memory_clear( LINE_PLANE | CHAR_PLANE ); Lib_draw_cursor( 255, 100 ); main_menu_disp(); } else if ( xpos > MENU_H_XS && xpos < MENU_H_XE && ypos > MENU_H_YS && ypos < MENU_H_YE ) { Lib_memory_clear( LINE_PLANE | CHAR_PLANE ); disp_help(); /* ヘルプ */ main_menu_disp(); } else if ( xpos > MENU_E_XS && xpos < MENU_E_XE && ypos > MENU_E_YS && ypos < MENU_E_YE ) { break; /* 終了 */ } } } /* 標準入出力 クローズ */ Lib_close_io( ); Lib_set_terminate( std_terminate ); Lib_set_stdin( stdin ); Lib_set_stdout( stdout ); } else Lib_display_message( 100, 200, "エラー", "Lib_open_io 異常終了" ); Lib_gs_close_data_file(); } else Lib_display_message( 100, 200, "エラー", "パタンエリアは使用できません" ); } /* * メインメニュー表示 */ static void main_menu_disp( void ) { int iLanguage; /* 日本語/英語表示文字列切替情報取得 */ iLanguage = Lib_get_disp_language(); /* 整列キー表示 -> ( m_menu.c ) */ SUB_menu_disp4he( (char *)str_main_menu[0][iLanguage], (char *)str_main_menu[1][iLanguage], (char *)str_main_menu[2][iLanguage], (char *)str_main_menu[3][iLanguage] ); } /* * ヘルプ表示 */ static void disp_help( void ) { Lib_chrdisp( 10, 8, "【機能\概要】 ALIGNSTD" ); Lib_chrdisp( 11, 10, "アライメント&コマンド通信(標準入出力版)" ); Lib_chrdisp( 11, 12, "アライメントマークの位置と関連付けした任意の2点" ); Lib_chrdisp( 11, 14, "座標を標準入出力へ出力します。" ); Lib_chrdisp( 11, 18, "コマンド" ); Lib_chrdisp( 11, 20, " S:実行" ); Lib_chrdisp( 11, 22, " E:リモートモードを終了しローカルモードへ移行" ); } /************************************************************************/ /* サーチ試行 */ /************************************************************************/ int search_exec( void ) { int gs_no; int rtn; gs_no = Lib_get_gsearch_no(); rtn = Lib_gs_psearch( ON_DISPLAY, gs_no, Rslt_Buf ); if ( rtn < 0 ) { Lib_sprintf( ss ,"[グレーサーチエラー]rtn : %d", rtn ); Lib_chrdisp( 1, 28, ss ); } return( rtn ); } /************************************************************************/ /* リモート      */ /************************************************************************/ void remote( ) { char buf[20]; char command[5]; int ch; Lib_cls( ( LINE_PLANE | CHAR_PLANE ), BLACK_COLOR ); /* プロンプト */ Lib_putchar( '>' ); for ( ; ; ) { Lib_chrdisp( 50, 3, "【リモート】" ); /* バッファのゴミを排出 */ command[0] = 0x00; /* NULL */ for ( ; ; ) { if ( EOF != ( ch = Lib_getchar( ) ) ) { Lib_sprintf( buf, "%c", ( ch & 0xff ) ); Lib_putchar( buf[0] ); /* エコーバック */ strcat( command, buf ); if ( 0x0d == ch ) break; } } if ( 2 == strlen( command ) ) { if ( 0 == strcmp( "S\r", command ) ) { rmt_search(); Lib_putchar( '>' ); } else if ( 0 == strcmp( "E\r", command ) ) { Lib_sprintf( ss, "REMOTE END" ); Lib_puts( ss ); break; } else { Lib_cls( ( LINE_PLANE | CHAR_PLANE ), BLACK_COLOR ); Lib_chrdisp( 1, 30, "コマンドエラー" ); Lib_sprintf( ss, "E1" ); Lib_puts( ss ); Lib_putchar( '>' ); } } else if ( 1 == strlen( command ) ) { if ( 0 == strcmp( "\r", command ) ) Lib_putchar( '>' ); else { Lib_cls( ( LINE_PLANE | CHAR_PLANE ), BLACK_COLOR ); Lib_chrdisp( 1, 30, "コマンドエラー" ); Lib_sprintf( ss, "E1" ); Lib_puts( ss ); Lib_putchar( '>' ); } } else { Lib_cls( ( LINE_PLANE | CHAR_PLANE ), BLACK_COLOR ); Lib_chrdisp( 1, 30, "コマンド文字数エラー" ); Lib_sprintf( ss, "E2" ); Lib_puts( ss ); Lib_putchar( '>' ); } } Lib_memory_clear( LINE_PLANE | CHAR_PLANE ); } /************************************************************************/ /* パタンサーチ(リモート) */ /************************************************************************/ void rmt_search( ) { int ret; int x1, y1, x2, y2; Lib_freeze( TRANSMIT ); ret = search_exec(); /* サーチ試行 */ if ( ret > 0 ) { search_x = d4i5_d( (double)Rslt_Buf[0] / 10.0 ); search_y = d4i5_d( (double)Rslt_Buf[1] / 10.0 ); /* 結果送信 */ Lib_sprintf( ss, "(A_MARK ) X = %5.1f, Y = %5.1f, V = %4d", (double)Rslt_Buf[0] / 10.0, (double)Rslt_Buf[1] / 10.0, Rslt_Buf[2] ); Lib_puts( ss ); x1 = d4i5_d( search_x ) + sotai_x1; y1 = d4i5_d( search_y ) + sotai_y1; Lib_sprintf( ss, "(POINT_1) x1 = %3d, y1 = %3d", x1, y1 ); Lib_puts( ss ); draw_cros( x1, y1 ); x2 = d4i5_d( search_x ) + sotai_x2; y2 = d4i5_d( search_y ) + sotai_y2; Lib_sprintf( ss, "(POINT_2) x2 = %3d, y2 = %3d", x2, y2 ); Lib_puts( ss ); draw_cros( x2, y2 ); } else { Lib_sprintf( ss, "サーチ エラー!" ); Lib_puts( ss ); Lib_sprintf( ss, "ERR:サーチ エラー! ( RTN = %d )", ret ); Lib_chrdisp( 1, 30, ss ); } Lib_freerun( ); } /***********************************************************************/ /* 入力数値(double)の4捨5入した数値(int)を返す */ /***********************************************************************/ int d4i5_d( double in ) { int out; if ( in >= 0.0 ) out = (int)( in + 0.5 ); else out = (int)( in - 0.5 ); return( out ); } /************************************************************************/ /* クロスマーク表示 */ /************************************************************************/ void draw_cros( x, y ) int x, y; { Lib_drawline( x-8, y, x+8, y ); Lib_drawline( x, y-8, x, y+8 ); } /************************************************************************/ /* 座標設定    */ /************************************************************************/ void point_set() { int no; pad_level = Lib_view_open(); Lib_view_set_title( pad_level, "座標設定" ); Lib_view_set_point( pad_level, 5, 5, "座標 1", zahyo_x1, zahyo_y1, 3, 0 ); Lib_view_set_point( pad_level, 5, 35, "座標 2", zahyo_x2, zahyo_y2, 3, 1 ); Lib_set_paradigm( pad_level, 0, WHOLE_TIMING, user_proc1 ); Lib_set_paradigm( pad_level, 1, WHOLE_TIMING, user_proc2 ); Lib_view_set_size( pad_level, 50, 80, 5, 5 ); Lib_draw_menu( pad_level ); draw_cros( zahyo_x1, zahyo_y1 ); draw_cros( zahyo_x2, zahyo_y2 ); if( ERROR_RETURN != ( no = Lib_process_menu( pad_level, value ) ) ) { switch( no ) { case 101: /*「実行」が選択された */ zahyo_x1 = value[0].point_type.x; zahyo_y1 = value[0].point_type.y; zahyo_x2 = value[1].point_type.x; zahyo_y2 = value[1].point_type.y; break; case 102: /*「取り消し」が選択された */ break; } } Lib_erase_menu( pad_level ); Lib_view_close( pad_level ); } /************************************************************************/ /* 座標位置表示(1) */ /************************************************************************/ void user_proc1( Timing, Numb, val ) int Timing; int Numb; PARADIGM val[]; { Lib_cls( LINE_PLANE, 0 ); draw_cros( val[0].int_type, val[1].int_type ); draw_cros( v_zahyo_x2, v_zahyo_y2 ); if ( Timing == END_TIMING ) { v_zahyo_x1 = val[0].int_type; v_zahyo_y1 = val[1].int_type; } } /************************************************************************/ /* 座標位置表示(2) */ /************************************************************************/ void user_proc2( Timing, Numb, val ) int Timing; int Numb; PARADIGM val[]; { Lib_cls( LINE_PLANE, 0 ); draw_cros( v_zahyo_x1, v_zahyo_y1 ); draw_cros( val[0].int_type, val[1].int_type ); if ( Timing == END_TIMING ) { v_zahyo_x2 = val[0].int_type; v_zahyo_y2 = val[1].int_type; } } /************************************************************************/ /* サーチ&関連付け  */ /************************************************************************/ void kanrenzuke( ) { int ret; double dx, dy; Lib_freeze( TRANSMIT ); ret = search_exec(); /* サーチ試行 */ if ( 0 < ret ) { dx = d4i5_d( (double)Rslt_Buf[0] / 10.0 ); dy = d4i5_d( (double)Rslt_Buf[1] / 10.0 ); sotai_x1 = zahyo_x1 - d4i5_d( dx ); sotai_y1 = zahyo_y1 - d4i5_d( dy ); sotai_x2 = zahyo_x2 - d4i5_d( dx ); sotai_y2 = zahyo_y2 - d4i5_d( dy ); Lib_line( d4i5_d( dx ), d4i5_d( dy ), zahyo_x1, zahyo_y1, DASHED_LINE ); Lib_line( d4i5_d( dx ), d4i5_d( dy ), zahyo_x2, zahyo_y2, DASHED_LINE ); draw_cros( zahyo_x1, zahyo_y1 ); draw_cros( zahyo_x2, zahyo_y2 ); } else { Lib_sprintf( ss, "ERR:サーチ エラー! ( RTN = %d )", ret ); Lib_chrdisp( 1, 30, ss ); } Lib_freerun( ); }