/* * ***************************************************************** * * * * * 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 DI/DOテストプログラム testdido.c */ /*[作成者]A.Sekimori */ /*[概要] DI/DOボードの入出力をテストするサンプルソフトです。 */ /* 外部装置と接続し入出力をチェックする事ができます。 */ /* 目的: 関数: 履歴: Ver 1.0 95/09/19 Ver 2.0 95/09/20 操作系の見直し */ #include "f_stdio.h" /* 標準入出力 */ #include "f_stdlib.h" /* メモリ領域割当 */ #include "f_gui.h" /* GUI */ #include "f_graph.h" /* モニタ表示 */ #include "f_pinf.h" /* システムパラメータ */ #include "f_video.h" /* ビデオ入力制御 */ #include "f_image.h" /* フレームバッファ */ #include "f_system.h" /* システム制御 */ #include "f_dido.h" /* フォトカプラ絶縁I/O */ /* 警告メニュー */ #define N_KEY1_XS 0 /* キーの表示開始位置(X) */ #define N_KEY_YS 1 /* キーの表示位置(Y) */ #define N_KEY_SIZE_Y 25 /* キーのサイズ(縦) */ #define N_STR 8 /* キーの表示文字数 */ #define NOTE_KEY_NUM 2 /* 警告メニューキーの数 */ /* DIDO */ #define MODULE_NO 0 #define ALL_CLR 0x0000 #define ON 1 #define OFF 0 #define LANG_N 2 #define NOTE_MENU_N 2 static const char *str_note_menu[NOTE_MENU_N][LANG_N] = { { " ACCEPT ", " 承 諾 " }, { " DENY ", " 否 認 " } }; static int cpx,cpy; static int bpx,bpy; static int di_bit_pattern; static int do_bit_pattern; static int on_off_switch[16]; static int signal[16] = { 0x0001, 0x0002, 0x0004, 0x0008, 0x0010, 0x0020, 0x0040, 0x0080, 0x0100, 0x0200, 0x0400, 0x0800, 0x1000, 0x2000, 0x4000, 0x8000 }; static int mask[16] = { 0xfffe, 0xfffd, 0xfffb, 0xfff7, 0xffef, 0xffdf, 0xffbf, 0xff7f, 0xfeff, 0xfdff, 0xfbff, 0xf7ff, 0xefff, 0xdfff, 0xbfff, 0x7fff }; void main( void ); void di_read( void ); void do_write( void ); int message_note( void ); int note_menu( void ); /***** メイン関数 *****/ void main ( void ) { char s[50]; int ct; int status; Lib_display_control( LINE_PLANE | CHAR_PLANE ); Lib_init_cursor(); /* 初期メッセージ表示 */ if( NORMAL_RETURN == message_note() ) { cpx = 255; cpy = 239; bpx = 255; bpy = 239; Lib_draw_cursor( cpx, cpy ); di_bit_pattern = 0; do_bit_pattern = 0; if ( ERROR_RETURN != Lib_open_dido() ) { Lib_look_current_position( &cpx, &cpy ); Lib_chrdisp( 1, 1, "DI/DOテストプログラム Ver 3.0" ); Lib_chrdisp( 1, 30, "キャンセル・キーで終了" ); Lib_kanjishift( NORMAL_FONT, DOUBLE_FONT, 5, 48, 80, "DI" ); Lib_kanjishift( NORMAL_FONT, DOUBLE_FONT, 5, 304, 80, "DO" ); Lib_chrdisp( 13, 8, "ランプ" ); Lib_chrdisp( 45, 8, "スイッチ" ); for ( ct = 0; ct < 16; ct++ ) { on_off_switch[ct] = OFF; /* 実行キーの反応を高速化するためDOの初期状態を表示 */ Lib_sprintf( s, "%2d □ OFF", ct ); Lib_chrdisp( 40, ct + 9, s ); } for ( ; ; ) { status = Lib_see_current_position( &cpx, &cpy ); if ( bpx != cpx || bpy != cpy ) { bpx = cpx; bpy = cpy; Lib_move_cursor( cpx, cpy ); } if ( CURSOR_EXECUTE == status ) /* 実行キーの反応を高速化するためEXECUTEの時のみdo_writeへ飛ぶ */ do_write(); else if ( CURSOR_CANCEL == status ) { Lib_write_dido( MODULE_NO, ALL_CLR ); break; } di_read(); } } else Lib_display_message( 120, 200, "エラー", "DIDOボードが存在しません" ); Lib_close_dido(); } Lib_cls( ( LINE_PLANE | CHAR_PLANE ), BLACK_COLOR ); } /****** DI *****/ void di_read( void ) { char s[50]; int ct; if ( NORMAL_RETURN == Lib_read_dido( MODULE_NO, &di_bit_pattern ) ) { for ( ct = 0; ct < 16; ct++ ) { if ( ( signal[ct] & di_bit_pattern ) == signal[ct] ) { Lib_sprintf( s, "%2d ● ON ", ct ); Lib_chrdisp( 8, ct + 9, s ); } else { Lib_sprintf( s, "%2d ○ OFF", ct ); Lib_chrdisp( 8, ct + 9, s ); } } } } /***** DO *****/ void do_write( void ) { char s[50]; int ct; int ys,ye; if ( 360 < cpx && cpx < 376 ) { for ( ct = 0; ct < 16; ct++ ) { ys = ( ct + 9 - 1 ) * 16; ye = ( ct + 9 ) * 16; if ( ys < cpy && cpy < ye ) { if ( ON == on_off_switch[ct] ) { on_off_switch[ct] = OFF; do_bit_pattern = ( do_bit_pattern & mask[ct] ); Lib_sprintf( s, "%2d □ OFF", ct ); Lib_chrdisp( 40, ct + 9, s ); } else if ( OFF == on_off_switch[ct] ) { on_off_switch[ct] = ON; do_bit_pattern = ( do_bit_pattern | signal[ct] ); Lib_sprintf( s, "%2d ■ ON ", ct ); Lib_chrdisp( 40, ct + 9, s ); } } } Lib_write_dido( MODULE_NO, do_bit_pattern ); } } /***** 初期メッセージ表示 *****/ int message_note( void ) { int status; int menu_no; Lib_chrdisp(20, 6, "【使用許諾事項】" ); Lib_chrdisp( 8, 8, "このサンプルプログラムソ\ースは90X製品において" ); Lib_chrdisp( 8, 10, "動作するプログラムを作成する際の参考例です。" ); Lib_chrdisp( 8, 12, "このサンプルプログラムの機能\はお客様固有の目的に" ); Lib_chrdisp( 8, 14, "対する適合性に関していかなる保証も行いません。" ); Lib_chrdisp(22, 16, "【責任の限度】" ); Lib_chrdisp( 8, 18, "FASTは、いかなる場合でもお客様に対して、たとえ" ); Lib_chrdisp( 8, 20, "FASTがそのような損害の可能\性について告知されて" ); Lib_chrdisp( 8, 22, "いた場合にもまた当事者からのいかなる請求があったと" ); Lib_chrdisp( 8, 24, "しても、逸失利益を含むいかなる特別、付随的、または" ); Lib_chrdisp( 8, 26, "派生的損害に対し責任を負わないものとします。" ); if ( 0 == ( menu_no = note_menu() ) ) /* 承諾 */ status = NORMAL_RETURN; else if ( 1 == menu_no ) /* 否認 */ status = ERROR_RETURN; Lib_cls( ( LINE_PLANE | CHAR_PLANE ), BLACK_COLOR ); return( status ); } /***** 警告メニュー *****/ int note_menu( void ) { int ct; int status; int width,height; int n_key_xs[NOTE_KEY_NUM]; int n_key_xe[NOTE_KEY_NUM]; int key_no; int key_num; int iLanguage; /* 日本語/英語表示文字列切替情報取得 */ iLanguage = Lib_get_disp_language(); n_key_xs[0] = N_KEY1_XS; key_num = NOTE_KEY_NUM - 1; /* メニュー・キー初期表示及びキーの始点終点の計算 */ Lib_get_key_size( N_STR, &width, &height ); for ( ct = 0; ct < key_num; ct++ ) { Lib_display_key( n_key_xs[ct], N_KEY_YS, ( char * )str_note_menu[ct][iLanguage], 1 ); n_key_xe[ct] = n_key_xs[ct] + width - 1; n_key_xs[ct+1] = n_key_xs[ct] + width + 1; } /* 「終了」キーの表示 */ n_key_xs[ct] = 511 - width + 1; n_key_xe[ct] = n_key_xs[ct] + width - 1; Lib_display_key( n_key_xs[ct], N_KEY_YS, ( char * )str_note_menu[ct][iLanguage], 1 ); /* トラック・ボールの左ボタンクリック? */ if ( CURSOR_EXECUTE == ( status = Lib_get_current_position( &cpx, &cpy ) ) ) { /* どのキーが選択されたかを判断する */ for ( ct = 0; ct < NOTE_KEY_NUM; ct++ ) { if ( n_key_xs[ct] <= cpx && cpx <= n_key_xe[ct] && cpy < N_KEY_SIZE_Y ) { Lib_display_key( n_key_xs[ct], N_KEY_YS, ( char * )str_note_menu[ct][iLanguage], 2 ); key_no = ct; break; } } } return( key_no ); }