/* * ***************************************************************** * * * * * Copyright (c) Fast Corporation, 1997 * * * * * * 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 2値計測サンプルソフト 90xbin.c */ /*[作成者]A.Sekimori */ /*[概要] 2値計測のサンプルソフトです。 */ /* トラックボールの操作のほかに、フォトカプラ絶縁I/Oからトリガを */ /* 入力することによって実行することができます。 */ /* */ /* トリガ DI0をONで計測実行 */ /* 出力 READY・・・DO0を出力 */ /* 正常終了・・・DO3を出力 */ /* 異常終了・・・DO4を出力 */ /* 正常終了の場合、重心座標、面積をRS232CのCH0に出力します。 */ /* 目的: 関数: 履歴: Ver 1.0 97/09/10 注記:m_menu.hをインクルードして下さい。 m_menu.c及びm_note.cをリンクして下さい。 */ /* Include compiler runtime library */ #include #include #include /* Include CSC90X library */ #include "f_stdio.h" /* 標準入出力 */ #include "f_stdlib.h" /* メモリ領域割当 */ #include "f_file.h" /* ファイルシステム */ #include "f_math.h" /* 数学演算 */ #include "f_gui.h" /* GUI */ #include "f_graph.h" /* モニタ表示 */ #include "f_pinf.h" /* システムパラメータ */ #include "f_video.h" /* ビデオ入力制御 */ #include "f_image.h" /* フレームバッファ */ #include "f_time.h" /* 時刻サービス */ #include "f_gray.h" /* 濃度変換 */ #include "f_meas.h" /* 2値 */ #include "f_exmeas.h" /* 2値 */ #include "f_system.h" /* システム制御 */ #include "f_binmem.h" /* メモリ操作・画像変形 */ #include "f_dido.h" /* フォトカプラ絶縁I/O */ /* Include CSC90X common local */ #include "m_menu.h" /* メニュー項目 */ #define LANG_N 2 #define MAIN_MENU_N 2 static const char *str_main_menu[MAIN_MENU_N][LANG_N] = { { " SET ", " 設 定 " }, { " REMOTE ", " リモート " }, }; #define INIT_CUR_POS_X 255 #define INIT_CUR_POS_Y 239 /* 表示メニュー */ #define D_KEY1_XS 1 /* キー「設定」の表示位置(X) */ #define D_KEY_YS 455 /* キーの表示位置(Y) */ #define D_STR 8 /* キーの表示文字数 */ #define BL_MIN 0 #define BL_MAX 255 #define AR_MIN 0 #define AR_MAX 245760 #define CONTINUE 100 #define END 200 /* DIDO */ #define MODULE_NO 0 #define DI_START 0x0001 #define DO_READY 0x0001 #define DO_OK 0x0008 #define DO_NG 0x0010 #define ALL_CLR 0x0000 static char *disp_menu_key[5] = { " 前頁 ", " 次頁 ", " 前塊 ", " 次塊 ", " 終了 " }; typedef struct { int bin_level; /* 2値レベル */ int color; /* 対象物の色 */ int edge; /* ウィンドウ接触塊 */ int al_limit; /* 面積下限値 */ int au_limit; /* 面積上限値 */ } BIN_P; typedef struct { int xs; /* 処理範囲始点X */ int ys; /* 処理範囲始点Y */ int x_size; /* 処理範囲サイズX */ int y_size; /* 処理範囲サイズY */ } WINDOW; typedef struct { BIN_P bp_data; WINDOW win_data; } DATA; static BIN_P bp; static WINDOW win; static char *select_c[2] = { "黒", "白" }; static struct MEASDATA *measp; static int *indextbl; static struct CALCDATA *calcp; static unsigned int max_blob; static int pad_level_b; /* プロトタイプ宣言 */ void main( void ); void main_menu_disp( void ); void disp_help( void ); void set_bin_level( int, int, PARADIGM * ); void video_init( void ); void data_init( void ); void save_file( char * ); int load_file( char * ); void bin_command( void ); void set_bin_param( void ); int result_disp_menu( int, int *, int * ); void test_measure_execute( void ); void set_bin_window( void ); int measure_execute( void ); void remote( void ); void cross_mark( int, int, int ); void num_disp( int, int, int ); extern int message_note( void ); /* メイン */ void main( void ) { int sts; int xpos; int ypos; int s_xpos; int s_ypos; /* カーソル初期化 */ Lib_init_cursor(); /* 初期メッセージ表示 */ if( NORMAL_RETURN != message_note() ) return; /* 2値結果表示 */ Lib_set_display_switch( ON ); if ( 0 < Lib_open_dido() ) /* DI/DO初期化 */ { if ( NORMAL_RETURN == Lib_opensio( SIO_CHANNEL0 ) ) { if ( ERROR_RETURN == load_file( "90XBIN.CFG" ) ) /* ファイルをロード */ data_init(); /* ロードに失敗したのでデータを初期化 */ /* ビデオ入力の初期化 */ video_init(); /* パラメタ初期化 */ xpos = INIT_CUR_POS_X; ypos = INIT_CUR_POS_Y; s_xpos = INIT_CUR_POS_X; s_ypos = INIT_CUR_POS_Y; /* ビデオ表示項目クリア */ Lib_memory_clear( LINE_PLANE | CHAR_PLANE ); /* メインメニューの表示 */ main_menu_disp(); /* マウスカーソルの表示 */ Lib_draw_cursor( INIT_CUR_POS_X, INIT_CUR_POS_Y ); /* メニュー制御 */ 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 ); bin_command(); 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 ); remote(); Lib_memory_clear( LINE_PLANE | CHAR_PLANE ); 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; /* 終了 */ } } } } else Lib_display_message( 100, 200, "エラー", "RS232Cがオープンできません" ); } else Lib_display_message( 100, 200, "エラー", "DI/DOボードがオープンできません" ); Lib_clossio( SIO_CHANNEL0 ); Lib_close_dido(); } /* メインメニュー表示 */ 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 *)NULL, (char *)NULL ); } /* ヘルプ表示 */ void disp_help( void ) { Lib_chrdisp( 10, 8, "【機能\概要】 90XBIN" ); Lib_chrdisp( 11, 10, "2値計測サンプルソ\フトです。" ); Lib_chrdisp( 11, 13, "【設定】 2値計測の各種設定を行います。" ); Lib_chrdisp( 11, 15, "【リモート】リモートモードへ移行します。" ); Lib_chrdisp( 11, 17, " DI0をONで計測し重心座標、面積を" ); Lib_chrdisp( 11, 19, " RS232CのCH0へ出力します。" ); Lib_chrdisp( 11, 21, " トラックボール右ボタン押下で戻ります。" ); } /***** データ初期化 *****/ void data_init( void ) { /* 2値計測・パラメータ */ bp.bin_level = 128; /* 2値レベル */ bp.color = BLACK_COLOR; /* 対象物の色 */ bp.edge = ON; /* ウィンドウ接触塊 */ bp.al_limit = 0; /* 面積下限値 */ bp.au_limit = 245760; /* 面積上限値 */ /* 2値計測処理範囲 */ win.xs = 0; /* ウィンドウ始点X */ win.ys = 0; /* ウィンドウ始点Y */ win.x_size = 512; /* ウィンドウサイズX */ win.y_size = 480; /* ウィンドウサイズY */ } /***** ビデオ入力の初期化 *****/ void video_init( void ) { /* 入力ビデオ制御 */ Lib_input_video_control( GRAY_PLANE | BIN_PLANE ); /* 入力ビデオチャネル設定 */ Lib_xvideo_channel( WAITING, 0 ); /* ビデオ出力表示項目制御 */ Lib_display_control( GRAY_PLANE | LINE_PLANE | CHAR_PLANE ); /* 2値レベル更新 */ Lib_video_bin_level( bp.bin_level ); } /***** 設定ファイルのセーブ *****/ void save_file( f_name ) char f_name[]; { DATA *ap; char fp_name[30]; unsigned long file_size; int idc; idc = Lib_shelter_plane( 0, 0, (Lib_get_dx_size() - 1), (Lib_get_dy_size() - 1), CHAR_PLANE ); Lib_cls( ( LINE_PLANE | CHAR_PLANE ), BLACK_COLOR ); Lib_set_cursor_shape( HOURGLASS_TYPE ); if ( ( DATA * )NULL != ( ap = ( DATA * )Lib_mlalloc( sizeof( DATA ) ) ) ) { ap->bp_data = bp; ap->win_data = win; Lib_sprintf( fp_name, "\\FS0\\%s", f_name ); /* 設定ファイルのセーブ */ Lib_display_comment( 144, 228, "設定ファイルをセーブ中です" ); if ( ( unsigned long )NULL == ( file_size = Lib_fsave( fp_name, ( char * )ap, sizeof( DATA ) ) ) ) { Lib_display_message( 120, 200, "エラー", "設定ファイルをセーブできません" ); } Lib_lfree( ( char * )ap ); } else Lib_display_message( 120, 200, "エラー", "メモリーが確保できません" ); Lib_cls( ( LINE_PLANE | CHAR_PLANE ), BLACK_COLOR ); Lib_set_cursor_shape( ARROW_TYPE ); Lib_recover_plane( idc ); } /***** 設定ファイルのロード *****/ int load_file( f_name ) char f_name[]; { DATA *ap; char fp_name[30]; unsigned long file_size; int error_status; if ( ( DATA * )NULL != ( ap = ( DATA * )Lib_mlalloc( sizeof( DATA ) ) ) ) { Lib_sprintf( fp_name, "\\FS0\\%s", f_name ); /* 設定ファイルのロード */ if ( ( unsigned long )NULL != ( file_size = Lib_fload( fp_name, ( char * )ap, sizeof( DATA ) ) ) ) { bp = ap->bp_data; win = ap->win_data; error_status = NORMAL_RETURN; } else { /*Lib_display_message( 120, 200, "エラー", "設定ファイルをロードできません" );*/ error_status = ERROR_RETURN; } Lib_lfree( ( char * )ap ); } else { Lib_display_message( 120, 200, "エラー", "メモリーが確保できません" ); error_status = ERROR_RETURN; } return( error_status ); } /***** 2値メニュー *****/ void bin_command( void ) { int no; int pad_level; int status_flag; Lib_cls( ( LINE_PLANE | CHAR_PLANE ), BLACK_COLOR ); pad_level = Lib_view_open(); Lib_view_set_title( pad_level, "2値" ); Lib_view_set_null( pad_level, 5, 5, "設定" , 0 ); Lib_view_set_null( pad_level, 5, 35, "処理範囲", 1 ); Lib_view_set_null( pad_level, 5, 65, "試行" , 2 ); Lib_view_set_null( pad_level, 5, 95, "セーブ" , 3 ); Lib_view_set_size( pad_level, 50, 50, 5, 5 ); Lib_draw_command( pad_level ); for ( status_flag = ON; OFF != status_flag; ) { if ( ERROR_RETURN != ( no = Lib_process_command( pad_level ) ) ) { switch( no ) { case 0:/* 設定 */ set_bin_param(); break; case 1:/* 処理範囲 */ set_bin_window(); break; case 2:/* 試行 */ test_measure_execute(); break; case 3:/* セーブ */ save_file( "90XBIN.CFG" ); break; case 102:/* 終了 */ status_flag = OFF; break; } } } Lib_erase_command( pad_level ); Lib_view_close( pad_level ); Lib_cls( ( LINE_PLANE | CHAR_PLANE ), BLACK_COLOR ); } /***** 2値パラメータ設定 *****/ void set_bin_param( void ) { PVAL value[5]; int no; int idc; idc = Lib_shelter_plane( 0, 0, (Lib_get_dx_size() - 1), (Lib_get_dy_size() - 1), CHAR_PLANE ); Lib_cls( ( LINE_PLANE | CHAR_PLANE ), BLACK_COLOR ); pad_level_b = Lib_view_open(); /* パッドのオープン */ Lib_view_set_title( pad_level_b, "設定" ); /* パッドタイトルの登録 */ /* 各属性メニューの登録 */ Lib_view_set_uniq_numeral( pad_level_b, 5, 5, "2値レベル" , bp.bin_level, BL_MIN , BL_MAX , 0 ); Lib_view_set_select ( pad_level_b, 5, 35, "対象物の色", bp.color, 2, select_c, 1 ); Lib_view_set_uniq_alter ( pad_level_b, 5, 65, "境界" , bp.edge , 2 ); Lib_view_set_uniq_numeral( pad_level_b, 5, 95, "面積下限値", bp.al_limit, AR_MIN, AR_MAX, 3 ); Lib_view_set_uniq_numeral( pad_level_b, 5, 125, "面積上限値", bp.au_limit, AR_MIN, AR_MAX, 4 ); Lib_set_paradigm( pad_level_b, 0, WHOLE_TIMING, set_bin_level ); /* パッドの表示位置の登録 */ Lib_view_set_size( pad_level_b, 30, 30, 5, 5 ); Lib_draw_menu( pad_level_b ); /* メニューパッドの表示 */ if ( ERROR_RETURN != ( no = Lib_process_menu( pad_level_b, value ) ) ) /* メニュー値の取得 */ { switch( no ) { case 101: /*「実行」が選択された */ bp.bin_level = value[0].value_type; bp.color = value[1].select_type; bp.edge = value[2].on_off_type; bp.al_limit = value[3].value_type; bp.au_limit = value[4].value_type; break; case 102: /*「取り消し」が選択された */ break; } } Lib_erase_menu( pad_level_b ); Lib_view_close( pad_level_b ); Lib_recover_plane( idc ); } /***** 2値レベル設定(パラダイム) *****/ void set_bin_level( Timing, Numb, val ) int Timing; int Numb; PARADIGM val[]; { if ( Timing == START_TIMING ) { Lib_erase_menu( pad_level_b ); Lib_display_control( BIN_PLANE | LINE_PLANE | CHAR_PLANE ); Lib_memory_clear( BIN_PLANE ); } else if ( Timing == END_TIMING ) { Lib_display_control( GRAY_PLANE | LINE_PLANE | CHAR_PLANE ); Lib_memory_clear( LINE_PLANE | CHAR_PLANE ); Lib_draw_menu( pad_level_b ); } Lib_video_bin_level( (int)val[0].long_type ); Lib_freerun(); } /***** 2値計測処理範囲設定 *****/ void set_bin_window( void ) { PVAL value[2]; int pad_level_w; int no; int idc; idc = Lib_shelter_plane( 0, 0, (Lib_get_dx_size() - 1), (Lib_get_dy_size() - 1), CHAR_PLANE ); Lib_display_control( BIN_PLANE | LINE_PLANE | CHAR_PLANE ); Lib_cls( ( LINE_PLANE | CHAR_PLANE ), BLACK_COLOR ); pad_level_w = Lib_view_open(); /* パッドのオープン */ Lib_view_set_title( pad_level_w, "処理範囲" ); /* 各属性メニューの登録 */ Lib_view_set_box( pad_level_w, 5, 5, "W始点" , win.xs , win.ys , 3, 1, 0 ); Lib_view_set_box( pad_level_w, 5, 35, "Wサイズ", win.x_size, win.y_size, 3, 0, 1 ); /* パッドの表示位置の登録 */ Lib_view_set_size( pad_level_w, 5, 410, 5, 5 ); Lib_draw_menu( pad_level_w ); /* メニューパッドの表示 */ if ( ERROR_RETURN != ( no = Lib_process_menu( pad_level_w, value ) ) ) /* メニュー値の取得 */ { switch( no ) { case 101: /*「実行」が選択された */ win.xs = value[0].box_type.x; win.ys = value[0].box_type.y; win.x_size = value[1].box_type.x; win.y_size = value[1].box_type.y; break; case 102: /*「取り消し」が選択された */ break; } } Lib_erase_menu( pad_level_w ); Lib_view_close( pad_level_w ); Lib_display_control( GRAY_PLANE | LINE_PLANE | CHAR_PLANE ); Lib_recover_plane( idc ); } /***** 2値計測試行 *****/ void test_measure_execute( void ) { char ss[50]; char *error_string; int status; int error_code; int ct; int num; int page,blob_no; int idc; idc = Lib_shelter_plane( 0, 0, (Lib_get_dx_size() - 1), (Lib_get_dy_size() - 1), CHAR_PLANE ); /* システムで設定されている「最大ブローブ数」の値を取得し、indextblに必要な容量の */ /* ワークメモリを確保する */ max_blob = Lib_get_meas_max_blob(); if ( ( int * )NULL != ( indextbl = ( int * )Lib_mlalloc( ( max_blob + 1 ) * 4 ) ) ) { Lib_display_control( BIN_PLANE | LINE_PLANE | CHAR_PLANE ); Lib_set_stage_window( win.xs, win.ys, win.xs + win.x_size - 1, win.ys + win.y_size - 1 ); Lib_set_display_switch( ON ); Lib_video_bin_level( bp.bin_level ); num = 0; page = 1; ct = 0; Lib_freeze( TRANSMIT ); Lib_Open_meas_structure(); if ( NORMAL_RETURN == ( status = Lib_xmeasure( bp.color, bp.edge, bp.al_limit, &measp ) ) ) { if ( 0 != ( num = Lib_xorderng( measp, 0, 0, bp.color, bp.au_limit, bp.al_limit, indextbl ) ) ) { for ( ; ; ) { blob_no = indextbl[ct]; Lib_calcult( page, blob_no, &calcp ); if ( END == result_disp_menu( num, &page, &ct ) ) break; Lib_cls( ( LINE_PLANE | CHAR_PLANE ), BLACK_COLOR ); } } else Lib_display_message( 100, 200, "エラー", "Lib_xorderng" ); } else if ( ERROR_RETURN == status ) { error_code = Lib_get_meas_error_code(); error_string = Lib_get_meas_error_string(); Lib_sprintf( ss, "[%d] : %s", error_code, error_string ); Lib_display_message( 100, 200, "2値計測エラー", ss ); status = ERROR_RETURN; } Lib_lfree( ( char * )indextbl ); } else Lib_chrdisp( 1, 30, "エラー:indextbl用のワークメモリを確保できません。" ); Lib_freerun(); Lib_set_stage_window( 0, 0, 511, 479 ); Lib_cls( ( LINE_PLANE | CHAR_PLANE | BIN_PLANE ), BLACK_COLOR ); Lib_display_control( GRAY_PLANE | LINE_PLANE | CHAR_PLANE ); Lib_recover_plane( idc ); } /***** 2値計測結果表示メニュー *****/ int result_disp_menu( num, page, ct ) int num; int *page; int *ct; { int cpx,cpy; int status; int width,height; int d_key2_xs,d_key3_xs,d_key4_xs,d_key5_xs; int d_key1_xe,d_key2_xe,d_key3_xe,d_key4_xe,d_key5_xe; status = CONTINUE; /* メニュー・キー初期表示 */ Lib_display_key( D_KEY1_XS, D_KEY_YS, ( char * )disp_menu_key[0], 1 ); Lib_get_key_size( D_STR, &width, &height ); d_key1_xe = D_KEY1_XS + width - 1; d_key2_xs = D_KEY1_XS + width + 1; Lib_display_key( d_key2_xs, D_KEY_YS, ( char * )disp_menu_key[1], 1 ); Lib_get_key_size( D_STR, &width, &height ); d_key2_xe = d_key2_xs + width - 1; d_key3_xs = d_key2_xs + width + 1; Lib_display_key( d_key3_xs, D_KEY_YS, ( char * )disp_menu_key[2], 1 ); Lib_get_key_size( D_STR, &width, &height ); d_key3_xe = d_key3_xs + width - 1; d_key4_xs = d_key3_xs + width + 1; Lib_display_key( d_key4_xs, D_KEY_YS, ( char * )disp_menu_key[3], 1 ); Lib_get_key_size( D_STR, &width, &height ); d_key4_xe = d_key4_xs + width - 1; d_key5_xs = d_key4_xs + width + 1; Lib_display_key( d_key5_xs, D_KEY_YS, ( char * )disp_menu_key[4], 1 ); Lib_get_key_size( D_STR, &width, &height ); d_key5_xe = d_key5_xs + width - 1; /* トラック・ボールの左ボタンクリック? */ if ( CURSOR_EXECUTE == Lib_get_current_position( &cpx, &cpy ) ) { if ( D_KEY1_XS <= cpx && cpx <= d_key1_xe && D_KEY_YS < cpy ) { /* 「前頁」が選択された */ Lib_display_key( D_KEY1_XS, D_KEY_YS, ( char * )disp_menu_key[0], 2 ); *page = ( *page ) - 1; } else if ( d_key2_xs <= cpx && cpx <= d_key2_xe && D_KEY_YS < cpy ) { /* 「次頁」が選択された */ Lib_display_key( d_key2_xs, D_KEY_YS, ( char * )disp_menu_key[1], 2 ); *page = ( *page ) + 1; } else if ( d_key3_xs <= cpx && cpx <= d_key3_xe && D_KEY_YS < cpy ) { /* 「前塊」が選択された */ Lib_display_key( d_key3_xs, D_KEY_YS, ( char * )disp_menu_key[2], 2 ); *ct = ( *ct ) - 1; } else if ( d_key4_xs <= cpx && cpx <= d_key4_xe && D_KEY_YS < cpy ) { /* 「次塊」が選択された */ Lib_display_key( d_key4_xs, D_KEY_YS, ( char * )disp_menu_key[3], 2 ); *ct = ( *ct ) + 1; } else if ( d_key5_xs <= cpx && cpx <= d_key5_xe && D_KEY_YS < cpy ) { /* 「終了」が選択された */ Lib_display_key( d_key5_xs, D_KEY_YS, ( char * )disp_menu_key[4], 2 ); status = END; } if ( *page < 1 ) *page = 1; else if ( 3 < *page ) *page = 3; if ( *ct < 0 ) *ct = 0; else if ( num <= *ct ) *ct = num - 1; } return( status ); } /***** リモート *****/ void remote( void ) { int cpx,cpy; int di_bit_pattern; int do_bit_pattern; int status; Lib_cls( ( LINE_PLANE | CHAR_PLANE ), BLACK_COLOR ); Lib_erase_cursor(); for ( ; ; ) { do_bit_pattern = DO_READY; Lib_write_dido( MODULE_NO, do_bit_pattern ); Lib_display_comment( 430, 0, "リモート" ); if ( CURSOR_CANCEL == Lib_see_current_position( &cpx, &cpy ) ) break; else { if ( NORMAL_RETURN == Lib_read_dido( MODULE_NO, &di_bit_pattern ) ) { if ( ( DI_START & di_bit_pattern ) == DI_START ) { Lib_cls( ( LINE_PLANE | CHAR_PLANE ), BLACK_COLOR ); Lib_display_comment( 430, 0, "リモート" ); if ( NORMAL_RETURN == ( status = measure_execute() ) ) do_bit_pattern = ( do_bit_pattern | DO_OK ); else if ( ERROR_RETURN == status ) do_bit_pattern = ( do_bit_pattern | DO_NG ); Lib_write_dido( MODULE_NO, do_bit_pattern ); for ( ; ; ) { if ( NORMAL_RETURN == Lib_read_dido( MODULE_NO, &di_bit_pattern ) ) { if ( ( DI_START & di_bit_pattern ) != DI_START ) { Lib_freerun(); Lib_cls( ( LINE_PLANE | CHAR_PLANE ), BLACK_COLOR ); break; } } } Lib_write_dido( MODULE_NO, ALL_CLR ); } } else Lib_chrdisp( 1, 30, "エラー:DIDO読み取り異常" ); } } Lib_freerun(); Lib_write_dido( MODULE_NO, ALL_CLR ); Lib_display_control( GRAY_PLANE | LINE_PLANE | CHAR_PLANE ); Lib_cls( ( LINE_PLANE | CHAR_PLANE | GRAY_PLANE ), BLACK_COLOR ); Lib_look_current_position( &cpx, &cpy ); Lib_draw_cursor( cpx, cpy ); } /***** 2値計測実行(リモート) *****/ int measure_execute( void ) { char ss[80]; char *error_string; int status; int error_code; int ct; int num; int blob_no; int area; int sumi,sumj; int center_x,center_y; Lib_cls( ( LINE_PLANE | CHAR_PLANE | BIN_PLANE | GRAY_PLANE ), BLACK_COLOR ); /* システムで設定されている「最大ブローブ数」の値を取得し、indextblに必要な容量の */ /* ワークメモリを確保する */ max_blob = Lib_get_meas_max_blob(); if ( ( int * )NULL != ( indextbl = ( int * )Lib_mlalloc( ( max_blob + 1 ) * 4 ) ) ) { Lib_display_control( BIN_PLANE | LINE_PLANE | CHAR_PLANE ); Lib_set_stage_window( win.xs, win.ys, win.xs + win.x_size - 1, win.ys + win.y_size - 1 ); Lib_video_bin_level( bp.bin_level ); Lib_freeze( TRANSMIT ); Lib_Open_meas_structure(); if ( NORMAL_RETURN == ( status = Lib_xmeasure( bp.color, bp.edge, bp.al_limit, &measp ) ) ) { Lib_Make_meas_structure( (void *)measp ); if ( 0 != ( num = Lib_xorderng( measp, 0, 0, bp.color, bp.au_limit, bp.al_limit, indextbl ) ) ) { for ( ct = 0; ct < num; ct++ ) { blob_no = indextbl[ct]; area = *( Meas_area + blob_no ); sumi = *( Meas_sumi + blob_no ); sumj = *( Meas_sumj + blob_no ); center_x = sumi / area; center_y = sumj / area; cross_mark( center_x, center_y, 5 ); num_disp( center_x, center_y, blob_no ); Lib_sprintf( ss, "%04d:%03d,%03d,%06d\r\n", blob_no, center_x, center_y, area ); Lib_putso( SIO_CHANNEL0, strlen( ss ), ss ); } status = NORMAL_RETURN; } else { Lib_chrdisp( 1, 30, "エラー:Lib_xorderng" ); status = ERROR_RETURN; } } else if ( ERROR_RETURN == status ) { error_code = Lib_get_meas_error_code(); error_string = Lib_get_meas_error_string(); Lib_sprintf( ss, "2値計測エラー [%d] : %s", error_code, error_string ); Lib_chrdisp( 1, 30, ss ); status = ERROR_RETURN; } Lib_lfree( ( char * )indextbl ); } else Lib_chrdisp( 1, 30, "エラー:indextbl用のワークメモリを確保できません。" ); Lib_freerun(); Lib_set_stage_window( 0, 0, 511, 479 ); return( status ); } /***** 十字マーク *****/ void cross_mark( x, y, l ) int x; int y; int l; { Lib_drawline( x - l, y, x + l, y ); Lib_drawline( x, y - l, x, y + l ); } /***** 対象物番号表示 *****/ void num_disp( x, y, num ) int x, y; int num; { char ss[5]; int xxx,yyy; xxx = x / 8; yyy = y / 16; Lib_sprintf( ss, "%d", num ); Lib_chrdisp( xxx, yyy, ss ); }