//********************************************************* // MAIN.cpp 11/08/99 //********************************************************* #include #include #include #include #include #include #include #include "mstep3.h" //----- define ------------------------------------------ #define CARD1 0 #define CARD2 1 #define COM_BACK BLUE #define COM_TEXT WHITE #define COM_UP_BACK WHITE #define COM_UP_TEXT BLACK+BLINK #define COM_ON_BACK RED #define COM_ON_TEXT WHITE #define SYS_ON_BACK MAGENTA #define SYS_ON_TEXT WHITE #define SYS_OFF_BACK CYAN #define SYS_OFF_TEXT WHITE #define SCREEN WHITE #define SCREEN_BACK BLUE #define CHANGE_MODE 0 #define TEST_DO 1 #define STOP_X 2 #define STOP_Y 3 #define STOP_Z 4 #define STOP_ALL 5 #define RESET_SYSTEM 6 #define BACK_HOME 7 #define BACK_HOME01 8 #define PULSE_MOVE 9 #define INTP_PULSE 10 #define INTP_LINE 11 #define INTP_LINE02 12 #define INTP_CIRCLE 13 #define INTP_CIRCLE02 14 #define INTP_ARC 15 #define INTP_ARC02 16 #define INTP_XYZ02 17 #define CONSTANT_SPEED 18 #define DEC_STOP 19 #define MULTI_TEST 20 //----- structure --------------------------------------- typedef struct { //---- parameter --------- unsigned int address; unsigned char exist; unsigned char DDA; unsigned char AD; unsigned int LSP; unsigned int HSP; unsigned char home_speed; unsigned char search_speed; unsigned int arc_speed; unsigned char x_mode; unsigned char x_dir; unsigned char x_son; unsigned char y_mode; unsigned char y_dir; unsigned char y_son; unsigned char z_mode; unsigned char z_dir; unsigned char z_son; //---- information ------- unsigned char op; unsigned char ip; unsigned char msc; unsigned char ls; unsigned char p1; unsigned char x_state; unsigned char y_state; unsigned char z_state; long XC; long XP; long YC; long YP; long ZC; long ZP; }CardParameter; typedef char string30[30]; typedef struct { int max; string30 name[30]; int x[30],y[30]; } menutype; //----- variable ---------------------------------------- menutype menu; CardParameter card1,card2; char screen_buffer[4096]; //#################################################################### //#################################################################### #define INTR 0x08 #define sampling_time 11931 // <1193180Hz>/11931=Hz(10ms) unsigned long sampling_counter1=0; void interrupt sampling_ISR(...); void interrupt (*old_handler)(...); void show_information(); void lamp_L(unsigned char lswitch, unsigned char x, unsigned char y, char show_text[10]); void lamp_H(unsigned char lswitch, unsigned char x, unsigned char y, char show_text[10]); //-------------------------------------------------------------------- void set_timer() { disable(); old_handler = getvect(INTR); setvect(INTR, sampling_ISR); outp(0x43, 0x34); outp(0x40, sampling_time & 0x00ff); outp(0x40, (sampling_time >> 8) ); outportb(0x20,0x20); enable(); } //-------------------------------------------------------------------- void release_timer() { disable(); outp(0x43, 0x34); outp(0x40, 0x00); outp(0x40, 0x00); setvect(INTR, old_handler); outportb(0x20,0x20); enable(); } //-------------------------------------------------------------------- void interrupt sampling_ISR(...) // 10ms sample once { int cx,cy,chkey; cx=wherex(); cy=wherey(); _setcursortype(_NOCURSOR); disable(); sampling_counter1 += sampling_time; if (sampling_counter1>65536L) { sampling_counter1-=65536L; old_handler(); // trigger original 0x08h (18.Hz) }; //----- check F7 ------------------------------ if ((chkey=bioskey(1))!=0) //don't get key if (chkey==0x4100) { bioskey(0); //get key MSTEP3_EMG_STOP(CARD1); } //----- get card 1 information ---------------- if (card1.exist==YES) { card1.ip = MSTEP3_DI(CARD1); card1.msc = MSTEP3_MSC(CARD1); MSTEP3_GET_CARD(CARD1); card1.ls =MSTEP3_GET_LIMIT(CARD1); card1.p1 =MSTEP3_GET_P1(CARD1); card1.XC =MSTEP3_GET_XC(CARD1); card1.XP =MSTEP3_GET_XP(CARD1); card1.YC =MSTEP3_GET_YC(CARD1); card1.YP =MSTEP3_GET_YP(CARD1); card1.ZC =MSTEP3_GET_ZC(CARD1); card1.ZP =MSTEP3_GET_ZP(CARD1); } show_information(); textbackground(SYS_OFF_BACK); textcolor(SYS_OFF_TEXT); gotoxy(cx,cy); _setcursortype(_NORMALCURSOR); outportb(0x20,0x20); enable(); } //#################################################################### //-------------------------------------------------------------------- void lamp_L(unsigned char lswitch, unsigned char x, unsigned char y, char show_text[10]) { if (lswitch!=0) { textbackground(SYS_OFF_BACK); textcolor(SYS_OFF_TEXT); } else { textbackground(SYS_ON_BACK); textcolor(SYS_ON_TEXT); } gotoxy(x,y); cprintf(show_text); } void lamp_H(unsigned char lswitch, unsigned char x, unsigned char y, char show_text[10]) { if (lswitch==0) { textbackground(SYS_OFF_BACK); textcolor(SYS_OFF_TEXT); } else { textbackground(SYS_ON_BACK); textcolor(SYS_ON_TEXT); } gotoxy(x,y); cprintf(show_text); } //------------------------------------------------------------------- void show_information() { char str[20]; lamp_L(card1.ip & 0x01,1,3, "/IP1"); lamp_L(card1.ip & 0x02,1,4, "/IP2"); lamp_L(card1.ip & 0x04,1,5, "/IP3"); lamp_L(card1.ip & 0x08,1,6, "/IP4"); lamp_L(card1.ip & 0x10,1,7, "/IP5"); lamp_L(card1.ip & 0x20,1,8, "/IP6"); lamp_L(card1.ip & 0x40,1,9, "/IP7"); lamp_L(card1.ip & 0x80,1,10,"/IP8"); lamp_H(card1.op & 0x01,6,3, "OP1"); lamp_H(card1.op & 0x02,6,4, "OP2"); lamp_H(card1.op & 0x04,6,5, "OP3"); lamp_H(card1.op & 0x08,6,6, "OP4"); lamp_H(card1.op & 0x10,6,7, "OP5"); lamp_H(card1.op & 0x20,6,8, "OP6"); lamp_H(card1.op & 0x40,6,9, "OP7"); lamp_L(card1.msc & 0x01,10,3, "/F1E"); lamp_L(card1.msc & 0x02,10,4, "/F1F"); lamp_L(card1.msc & 0x04,10,5, "/F2E"); lamp_L(card1.msc & 0x08,10,6, "/F2H"); lamp_L(card1.msc & 0x10,10,7, "/Xsp"); lamp_L(card1.msc & 0x20,10,8, "/Ysp"); lamp_L(card1.msc & 0x40,10,9, "/Zsp"); lamp_L(card1.msc & 0x80,10,10,"/EMG"); lamp_L(card1.ls & 0x01,15,3, "/XL+"); lamp_L(card1.ls & 0x02,15,4, "/XL-"); lamp_L(card1.ls & 0x04,15,5, "/YL+"); lamp_L(card1.ls & 0x08,15,6, "/YL-"); lamp_L(card1.ls & 0x10,15,7, "/ZL+"); lamp_L(card1.ls & 0x20,15,8, "/ZL-"); lamp_L(card1.ls & 0x40,15,9, "/EMG"); lamp_L(card1.p1 & 0x02,20,4, "/XI"); lamp_L(card1.p1 & 0x04,20,5, "/YI"); lamp_L(card1.p1 & 0x08,20,6, "/ZI"); lamp_H(card1.p1 & 0x10,20,7, "C1 "); lamp_H(card1.p1 & 0x20,20,8, "C2 "); lamp_H(card1.p1 & 0x40,20,9, "C3 "); //------------------------------------- textbackground(SYS_OFF_BACK); textcolor(SYS_OFF_TEXT); ltoa( card1.XC, str, 10); gotoxy(6,23); cprintf(" "); gotoxy(6,23); cprintf(str); ltoa( card1.XP, str, 10); gotoxy(18,23); cprintf(" "); gotoxy(18,23); cprintf(str); ltoa( card1.YC, str, 10); gotoxy(6,24); cprintf(" "); gotoxy(6,24); cprintf(str); ltoa( card1.YP, str, 10); gotoxy(18,24); cprintf(" "); gotoxy(18,24); cprintf(str); ltoa( card1.ZC, str, 10); gotoxy(6,25); cprintf(" "); gotoxy(6,25); cprintf(str); ltoa( card1.ZP, str, 10); gotoxy(18,25); cprintf(" "); gotoxy(18,25); cprintf(str); } //#################################################################### //#################################################################### void unpressed_text(unsigned char x, unsigned char y, string30 show_text) { textbackground(COM_BACK); textcolor(COM_TEXT); gotoxy(x,y); cprintf(show_text); gotoxy(x,y); } //---------------------------------------------------------- void pressed_text(unsigned char x, unsigned char y, string30 show_text) { textbackground(COM_UP_BACK); textcolor(COM_UP_TEXT); gotoxy(x,y); cprintf(show_text); gotoxy(x,y); } //---------------------------------------------------------- void work_text(unsigned char x, unsigned char y, string30 show_text) { textbackground(COM_ON_BACK); textcolor(COM_ON_TEXT); gotoxy(x,y); cprintf(show_text); gotoxy(x,y); } //--------------------------------------------------------- void show_control_mode() { lamp_H(card1.x_son & 0x01,22,14, "SON"); lamp_H(card1.x_mode & 0x04,26,14, "EN"); lamp_H(card1.x_mode & 0x08,26,15, "OE"); lamp_H(card1.x_mode & 0x40,22,15, "EXT"); textbackground(SYS_ON_BACK); textcolor(SYS_ON_TEXT); gotoxy(15,14); if ((card1.x_mode & 0x01)==DDA_CW_CCW) cprintf("CW/CCW"); else cprintf("DIR/P "); gotoxy(15,15); if ((card1.x_mode & 0x30)==ENC_AB_PHASE) cprintf("AB_P "); else if ((card1.x_mode & 0x30)==ENC_CW_CCW) cprintf("CW/CCW"); else cprintf("DIR/P "); textbackground(SYS_OFF_BACK); textcolor(SYS_OFF_TEXT); gotoxy(15,13); cprintf("X dir="); gotoxy(21,13); if (card1.x_dir==NORMAL_DIR) cprintf("NORMAL"); else cprintf("REVERSE"); lamp_H(card1.y_son & 0x01,22,17, "SON"); lamp_H(card1.y_mode & 0x04,26,17, "EN"); lamp_H(card1.y_mode & 0x08,26,18, "OE"); lamp_H(card1.y_mode & 0x40,22,18, "EXT"); textbackground(SYS_ON_BACK); textcolor(SYS_ON_TEXT); gotoxy(15,17); if ((card1.y_mode & 0x01)==DDA_CW_CCW) cprintf("CW/CCW"); else cprintf("DIR/P "); gotoxy(15,18); if ((card1.y_mode & 0x30)==ENC_AB_PHASE) cprintf("AB_P "); else if ((card1.y_mode & 0x30)==ENC_CW_CCW) cprintf("CW/CCW"); else cprintf("DIR/P "); textbackground(SYS_OFF_BACK); textcolor(SYS_OFF_TEXT); gotoxy(15,16); cprintf("Y dir="); gotoxy(21,16); if (card1.y_dir==NORMAL_DIR) cprintf("NORMAL"); else cprintf("REVERSE"); lamp_H(card1.z_son & 0x01,22,20, "SON"); lamp_H(card1.z_mode & 0x04,26,20, "EN"); lamp_H(card1.z_mode & 0x08,26,21, "OE"); lamp_H(card1.z_mode & 0x40,22,21, "EXT"); textbackground(SYS_ON_BACK); textcolor(SYS_ON_TEXT); gotoxy(15,20); if ((card1.z_mode & 0x01)==DDA_CW_CCW) cprintf("CW/CCW"); else cprintf("DIR/P "); gotoxy(15,21); if ((card1.z_mode & 0x30)==ENC_AB_PHASE) cprintf("AB_P "); else if ((card1.z_mode & 0x30)==ENC_CW_CCW) cprintf("CW/CCW"); else cprintf("DIR/P "); textbackground(SYS_OFF_BACK); textcolor(SYS_OFF_TEXT); gotoxy(15,19); cprintf("Z dir="); gotoxy(21,19); if (card1.z_dir==NORMAL_DIR) cprintf("NORMAL"); else cprintf("REVERSE"); } //--------------------------------------------------------- void init_system_display() { int i; //---- print title ------ textbackground(SYS_ON_BACK); textcolor(SYS_ON_TEXT); gotoxy(1,1); cprintf( " PISO-PS300 3-axis Stepping/Servo Control Card version 1.0 12/15/99"); window(1,2,27,25); textbackground(SYS_OFF_BACK); textcolor(SYS_OFF_TEXT); clrscr(); //-------- show pannel window(1,1,80,25); textbackground(SYS_ON_BACK); textcolor(SYS_ON_TEXT); gotoxy(1,2); cprintf(" I/O Information "); gotoxy(1,11); cprintf(" Motion Parameter "); menu.max=21; for (i=0; i<12; i++) { menu.x[i]=30; menu.y[i]=2+i*2; } for (i=12; i<24; i++) { menu.x[i]=55; menu.y[i]=2+(i-12)*2; } strcpy(menu.name[0], " Simulation/Real mode "); strcpy(menu.name[1], " test DO "); strcpy(menu.name[2], " MSTEP3_STOP_X "); strcpy(menu.name[3], " MSTEP3_STOP_Y "); strcpy(menu.name[4], " MSTEP3_STOP_Z "); strcpy(menu.name[5], " MSTEP3_STOP_ALL "); strcpy(menu.name[6], " MSTEP3_RESET_SYSTEM "); strcpy(menu.name[7], " MSTEP3_BACK_HOME "); strcpy(menu.name[8], " MSTEP3_BACK_HOME01 "); strcpy(menu.name[9], " MSTEP3_PULSE_MOVE "); strcpy(menu.name[10]," MSTEP3_INTP_PULSE "); strcpy(menu.name[11]," MSTEP3_INTP_LINE "); strcpy(menu.name[12]," MSTEP3_INTP_LINE02 "); strcpy(menu.name[13]," MSTEP3_INTP_CIRCLE "); strcpy(menu.name[14]," MSTEP3_INTP_CIRCLE02 "); strcpy(menu.name[15]," MSTEP3_INTP_ARC "); strcpy(menu.name[16]," MSTEP3_INTP_ARC02 "); strcpy(menu.name[17]," MSTEP3_INTP_XYZ02 "); strcpy(menu.name[18]," MSTEP3_CONSTANT_SPEED"); strcpy(menu.name[19]," MSTEP3_DEC_STOP "); strcpy(menu.name[20]," Multi testing "); for (i=0; il) c=l; /* right */ if (c>max-1) c=max-1; break; case 0x5300: if (l>0) /* del */ { for (j=c; j12)&(ch1<122)) { if ( c>=strlen(istr)) { istr[c]=ch1; istr[c+1]='\0'; c++; } else { istr[c]=ch1; c++;}; if (c>max-1) c=max-1; } break; } disable(); l=strlen(istr); textbackground(0); textcolor(7); gotoxy(x,y); for (j=0; j=menu.max) c -=12; // right break; case 0x4b00 : c -=12; if (c<0) c +=12; // left break; case 0x5000 : c++; if ( c>=menu.max ) c=0; // down break; case 0x4800 : c--; if ( c<0 ) c=menu.max-1; // up break; case 0x1c0d : work_text(menu.x[c], menu.y[c], menu.name[c]); // if (card1.exist==YES) operation(c); // enter pressed_text(menu.x[c], menu.y[c], menu.name[c]); break; //******************************************************* case 0x4100: //F7 STOP ALL MSTEP3_STOP_ALL(CARD1); break; default: break; } if (c!=oldc) { unpressed_text(menu.x[oldc], menu.y[oldc], menu.name[oldc]); pressed_text(menu.x[c], menu.y[c], menu.name[c]); oldc=c; }; } while (chkey!=0x011b); // ESC MSTEP3_RESET_SYSTEM(CARD1); release_timer(); textbackground(BLACK); clrscr(); gotoxy(1,25); }