//-------------------------------------------------------------------- // demo.cpp for I-8091 card // // This program can test all of following command // ----------------------I-8091 testing kit----------------------------------- // (0)Exit (A)i8091_IS_X_STOP (K)i8091_CSP_MOVE // (1)i8091_RESET_SYSTEM (B)i8091_IS_Y_STOP (L)i8091_SLOW_DOWN // (2)i8091_SET_VAR (C)i8091_LIMIT_X (M)i8091_SLOW_STOP // (3)i8091_SET_DEFDIR (D)i8091_LIMIT_Y (N)i8091_INTP_PULSE // (4)i8091_SET_MODE (E)i8091_LSP_ORG (O)i8091_INTP_LINE // (5)i8091_SET_SERVO_ON (F)i8091_HSP_ORG (P)i8091_INTP_LINE02 // (6)i8091_SET_NC (G)i8091_LSP_PULSE_MOVE (Q)i8091_CIRCLE02 // (7)i8091_STOP_X (H)i8091_HSP_PULSE_MOVE (R)i8091_ARC02 // (8)i8091_STOP_Y (I)i8091_LSP_MOVE (S)User Define Testing // (9)i8091_STOP_ALL (J)i8091_HSP_MOVE // // The output pulse amount can be monitored from I-8090 card. When directly // connect the CW/PULSE, CCW/DIR of I-8091 to I-8090. The encoder value // can be shown on the LED display. Its format as following. // ex: 0.2 1 2 8 : X-axis encoder value // 5 3.4 0 2 : Y-axis encoder value // 1 0 0.1 0 : Z-axis encoder value // the dot(.) stands for which axis. //-------------------------------------------------------------------- // v1.0 6/20/2001 // //-------------------------------------------------------------------- #include #include #include #include #include #include "8000.h" #include "i8090.h" #include "i8091.h" #define i8090 0x0d #define i8091 0x0e #define i8092 0x0f #define NOCARD 0x00 #define BasePort 0x0080 #define SlotOffset 0x0020 #define IDPort 0x0000 #define CARD0 0 #define CARD1 1 #define CARD2 2 #define CARD3 3 #define CARD4 4 #define CARD5 5 #define CARD6 6 #define CARD7 7 #define MAX_SLOT_NO 8 unsigned int PortAddress[8]={0x080, 0x0a0, 0x0c0, 0x0e0, 0x140, 0x160, 0x180, 0x1a0}; //--------------------------------------------------------------------- typedef struct { int address; unsigned char DDA,AD; unsigned int LSP,HSP; unsigned char xmode,ymode; unsigned char xdir,ydir; unsigned char xson,yson; unsigned char NCmode; } i8091CardType; i8091CardType card1; unsigned char i8090Slot,i8091Slot; unsigned int x_value; unsigned int y_value; unsigned int z_value; unsigned char index; unsigned char x_index; unsigned char y_index; unsigned char z_index; int ShowAxis; //--------------------------------------------------- //-------------------------------------------------------------------- void ShowLedValue(long value,unsigned char axis) { long j; unsigned char negative_value; if (value<0) negative_value=1; else negative_value=0; value=labs(value); j=value-10*(value/10); if (negative_value) Show5DigitLedWithDot(0x05, j); else Show5DigitLed(0x05, j); value=value/10; j=value-10*(value/10); Show5DigitLed(0x04, j); value=value/10; j=value-10*(value/10); if (axis==Z_axis) Show5DigitLedWithDot(0x03, j); else Show5DigitLed(0x03, j); value=value/10; j=value-10*(value/10); if (axis==Y_axis) Show5DigitLedWithDot(0x02, j); else Show5DigitLed(0x02, j); value=value/10; j=value-10*(value/10); if (axis==X_axis) Show5DigitLedWithDot(0x01, j); else Show5DigitLed(0x01, j); } //--------------------------------------------------- void ShowCardName(unsigned char SlotNum) { unsigned char temp; Show5DigitLed(0x05, SlotNum); //temp=inportb(BasePort+SlotNum*SlotOffset); temp=inportb(PortAddress[SlotNum]); switch (temp) { case i8090: //i8090 3-axis encoder card Show5DigitLedSeg (0x01, 0x7F); Show5DigitLedSeg (0x02, 0x7E); Show5DigitLedSeg (0x03, 0x7B); Show5DigitLedSeg (0x04, 0x7E); break; case i8091: //i8091 2-axis stepping card Show5DigitLedSeg (0x01, 0x7F); Show5DigitLedSeg (0x02, 0x7E); Show5DigitLedSeg (0x03, 0x7B); Show5DigitLedSeg (0x04, 0x30); break; case i8092: //i8092 Show5DigitLedSeg (0x01, 0x7F); Show5DigitLedSeg (0x02, 0x7E); Show5DigitLedSeg (0x03, 0x7B); Show5DigitLedSeg (0x04, 0x6D); break; default: Show5DigitLedSeg (0x01, 0x01); Show5DigitLedSeg (0x02, 0x01); Show5DigitLedSeg (0x03, 0x01); Show5DigitLedSeg (0x04, 0x01); break; }; } //--------------------------------------------------- unsigned char CardSearch(unsigned char SlotNum) { unsigned char temp; //temp=inportb(BasePort+SlotNum*SlotOffset); temp=inportb(PortAddress[SlotNum]); ShowCardName(SlotNum); switch (temp) { case i8090: //i8090 3-axis encoder card Print("Slot %d = i8090\r\n",SlotNum); return i8090; case i8091: //i8091 2-axis stepping card Print("Slot %d = i8091\r\n",SlotNum); return i8091; case i8092: //i8092 Print("Slot %d = i8092\r\n",SlotNum); return i8092; default: Print("Slot %d = No Card\r\n",SlotNum); return NOCARD; }; } //--------------------------------------------------- void DisplayEncoder() { int key; x_value = i8090_GET_ENCODER(i8090Slot, X_axis); y_value = i8090_GET_ENCODER(i8090Slot, Y_axis); z_value = i8090_GET_ENCODER(i8090Slot, Z_axis); index = i8090_GET_INDEX(i8090Slot); x_index = index & 0x01; y_index = (index & 0x02) >> 1; z_index = (index & 0x04) >> 2; if (IsSystemKey()) { key=GetSystemKey(); ClearSystemKey(); switch (key) { case SKEY_DOWN: ShowAxis++; if (ShowAxis>2) ShowAxis=0; break; case SKEY_UP: ShowAxis--; if (ShowAxis<0) ShowAxis=2; break; }; } switch (ShowAxis) { case 0: ShowLedValue(x_value,X_axis); break; case 1: ShowLedValue(y_value,Y_axis); break; case 2: ShowLedValue(z_value,Z_axis); break; }; if (x_index) LedRunOff(); else LedRunOn(); if (y_index) LedCommOff(); else LedCommOn(); if (z_index) LedBattOff(); else LedBattOn(); Delay(1); } //--------------------------------------------------- void stop_process() { i8091_STOP_ALL(CARD1); i8091_SET_VAR(CARD1, card1.DDA, card1.AD, card1.LSP, card1.HSP); i8091_SET_DEFDIR(CARD1, card1.xdir, card1.ydir); i8091_SET_MODE(CARD1, card1.xmode, card1.ymode); i8091_SET_SERVO_ON(CARD1, card1.xson, card1.yson); i8091_SET_NC(CARD1, card1.NCmode); Delay(50); } //--------------------------------------------------- void main () { int chkey,tempint,speed; int xpulse,ypulse; unsigned char j,temp,axis,dir; long pulse,x,y,R; ResetScanBuffer(); ClearSystemKey(); ShowAxis=0; i8090Slot=99; i8091Slot=99; for (j=0; j>bye-bye...\r\n"); return; //--------------------------------------------------------------- case '1': Print(">>i8091_RESET_SYSTEM\r\n"); i8091_RESET_SYSTEM(CARD1); stop_process(); break; //--------------------------------------------------------------- case '2': Print(">>i8091_SET_VAR\r\n"); Print("Input DDA cycle(1~254)="); Scanf("%d",&tempint); card1.DDA=(unsigned char)tempint; Print("Input AD acceleratio/deceleration(1~254)="); Scanf("%d",&tempint); card1.AD=(unsigned char)tempint; Print("Input LSP low speed(1~254)="); Scanf("%d",&tempint); card1.LSP=(unsigned char)tempint; Print("Input HSP high speed(LSP~2040)="); Scanf("%d",&tempint); card1.HSP=(int)tempint; i8091_SET_VAR(CARD1, card1.DDA, card1.AD, card1.LSP, card1.HSP); break; //--------------------------------------------------------------- case '3': Print(">>i8091_SET_DEFDIR\r\n"); Print("Input X axis direction definition(0:NORMAL 1:REVERSE)="); Scanf("%d",&tempint); if (tempint==0) card1.xdir=NORMAL_DIR; else card1.xdir=REVERSE_DIR; Print("Input Y axis direction definition(0:NORMAL 1:REVERSE)="); Scanf("%d",&tempint); if (tempint==0) card1.ydir=NORMAL_DIR; else card1.ydir=REVERSE_DIR; i8091_SET_DEFDIR(CARD1, card1.xdir, card1.ydir); break; //--------------------------------------------------------------- case '4': Print(">>i8091_SET_MODE\r\n"); Print("Input X axis output pulse mode(0:CW_CCW 1:PULSE_DIR)="); Scanf("%d",&tempint); if (tempint==0) card1.xmode=CW_CCW; else card1.xmode=PULSE_DIR; Print("Input Y axis output pulse mode(0:CW_CCW 1:PULSE_DIR)="); Scanf("%d",&tempint); if (tempint==0) card1.ymode=CW_CCW; else card1.ymode=PULSE_DIR; i8091_SET_MODE(CARD1, card1.xmode, card1.ymode); break; //--------------------------------------------------------------- case '5': Print(">>i8091_SET_SERVO_ON\r\n"); Print("Input X axis servo on(0:OFF 1:ON)="); Scanf("%d",&tempint); if (tempint==0) card1.xson=OFF; else card1.xson=ON; Print("Input Y axis servo on(0:OFF 1:ON)="); Scanf("%d",&tempint); if (tempint==0) card1.yson=OFF; else card1.yson=ON; i8091_SET_SERVO_ON(CARD1, card1.xson, card1.yson); break; //--------------------------------------------------------------- case '6': Print(">>i8091_SET_NC\r\n"); Print("Input Normal Close mode(0:OFF 1:ON)="); Scanf("%d",&tempint); if (tempint==1) card1.NCmode=ON; else card1.NCmode=OFF; i8091_SET_NC(CARD1, card1.NCmode); break; //--------------------------------------------------------------- case '7': Print(">>i8091_STOP_X\r\n"); i8091_STOP_X(CARD1); break; //--------------------------------------------------------------- case '8': Print(">>i8091_STOP_Y\r\n"); i8091_STOP_Y(CARD1); break; //--------------------------------------------------------------- case '9': Print(">>i8091_STOP_ALL\r\n"); stop_process(); break; //--------------------------------------------------------------- case 'a','A': Print(">>i8091_IS_X_STOP -->"); if (i8091_IS_X_STOP(CARD1)==YES) Print("YES\r\n"); else Print("NO\r\n"); break; //--------------------------------------------------------------- case 'b','B': Print(">>i8091_IS_Y_STOP -->"); if (i8091_IS_Y_STOP(CARD1)==YES) Print("YES\r\n"); else Print("NO\r\n"); break; //--------------------------------------------------------------- case 'c','C': Print(">>i8091_LIMIT_X\r\n"); temp=i8091_LIMIT_X(CARD1); Print(">>/HOME1 /LS11 xxx xxx /LS14 /FF1EF /FF1FF /EMG\r\n"); Print(">> %d %d %d %d %d %d %d %d\r\n", (temp&0x01), (temp&0x02) >> 1, (temp&0x04) >> 2, (temp&0x08) >> 3, (temp&0x10) >> 4, (temp&0x20) >> 5, (temp&0x40) >> 6, (temp&0x80) >> 7); break; //--------------------------------------------------------------- case 'd','D': Print(">>i8091_LIMIT_Y\r\n"); temp=i8091_LIMIT_Y(CARD1); Print(">>/HOME2 /LS21 xxx xxx /LS24 CPUS /XSTOP /YSTOP\r\n"); Print(">> %d %d %d %d %d %d %d %d\r\n", (temp&0x01), (temp&0x02) >> 1, (temp&0x04) >> 2, (temp&0x08) >> 3, (temp&0x10) >> 4, (temp&0x20) >> 5, (temp&0x40) >> 6, (temp&0x80) >> 7); break; //--------------------------------------------------------------- case 'e','E': Print(">>i8091_LSP_ORG\r\n"); Print("Which axis (1:X-axis 2:Y-axis)="); Scanf("%d",&tempint); axis=(unsigned char) tempint; if ((axis!=X_axis) && (axis!=Y_axis)) break; i8091_LSP_ORG(CARD1,CCW,axis); break; //--------------------------------------------------------------- case 'f','F': Print(">>i8091_HSP_ORG\r\n"); Print("Which axis (1:X-axis 2:Y-axis)="); Scanf("%d",&tempint); axis=(unsigned char)tempint; if ((axis!=X_axis) && (axis!=Y_axis)) break; i8091_HSP_ORG(CARD1,CCW,axis); break; //--------------------------------------------------------------- case 'g','G': Print(">>i8091_LSP_PULSE_MOVE\r\n"); Print("Which axis (1:X-axis 2:Y-axis)="); Scanf("%d",&tempint); axis=(unsigned char)tempint; Print("input pulse number(+- 2^31 -1) = "); Scanf("%ld",&pulse); if ((axis!=1) && (axis!=2)) break; i8091_LSP_PULSE_MOVE(CARD1,axis,pulse); break; //--------------------------------------------------------------- case 'h','H': Print(">>i8091_HSP_PULSE_MOVE\r\n"); Print("Which axis (1:X-axis 2:Y-axis)="); Scanf("%d",&tempint); axis=(unsigned char)tempint; Print("input pulse number(+- 2^31 -1) = "); Scanf("%ld",&pulse); Print("Input speed (LSP~2040) = "); Scanf("%d",&speed); if ((axis!=1) && (axis!=2)) break; if (speed>2040) break; i8091_HSP_PULSE_MOVE(CARD1,axis,pulse,speed); break; //--------------------------------------------------------------- case 'i','I': Print(">>i8091_LSP_MOVE\r\n"); Print("Which axis (1:X-axis 2:Y-axis)="); Scanf("%d",&tempint); axis=(unsigned char)tempint; Print("Which direction (0:CW 1:CCW)="); Scanf("%d",&tempint); dir=(unsigned char)tempint; if ((axis!=X_axis) && (axis!=Y_axis)) break; if ((dir!=CW) && (dir!=CCW)) break; i8091_LSP_MOVE(CARD1,dir,axis); break; //--------------------------------------------------------------- case 'j','J': Print(">>i8091_HSP_MOVE\r\n"); Print("Which axis (1:X-axis 2:Y-axis)="); Scanf("%d",&tempint); axis=(unsigned char)tempint; Print("Which direction (0:CW 1:CCW)="); Scanf("%d",&tempint); dir=(unsigned char)tempint; if ((axis!=X_axis) && (axis!=Y_axis)) break; if ((dir!=CW) && (dir!=CCW)) break; i8091_HSP_MOVE(CARD1,dir,axis); break; //--------------------------------------------------------------- case 'k','K': Print(">>i8091_CSP_MOVE\r\n"); Print("Which axis (1:X-axis 2:Y-axis)="); Scanf("%d",&tempint); axis=(unsigned char)tempint; Print("Which direction (0:CW 1:CCW)="); Scanf("%d",&tempint); dir=(unsigned char)tempint; Print("constant speed(1~2040)="); Scanf("%d",&speed); if ((axis!=X_axis) && (axis!=Y_axis)) break; if ((dir!=CW) && (dir!=CCW)) break; if ((speed==0) || (speed>2040)) break; i8091_CSP_MOVE(CARD1,dir,axis,speed); break; //--------------------------------------------------------------- case 'l','L': Print(">>i8091_SLOW_DOWN\r\n"); Print("Which axis (1:X-axis 2:Y-axis)="); Scanf("%d",&tempint); axis=(unsigned char)tempint; if ((axis!=X_axis) && (axis!=Y_axis)) break; i8091_SLOW_DOWN(CARD1,axis); break; //--------------------------------------------------------------- case 'm','M': Print(">>i8091_SLOW_STOP\r\n"); Print("Which axis (1:X-axis 2:Y-axis)="); Scanf("%d",&tempint); axis=(unsigned char)tempint; if ((axis!=X_axis) && (axis!=Y_axis)) break; i8091_SLOW_STOP(CARD1,axis); break; //--------------------------------------------------------------- case 'n','N': Print(">>i8091_INTP_PULSE\r\n"); Print("X pulse number (-2047 ~ 2047) = "); Scanf("%d",&xpulse); Print("Y pulse number (-2047 ~ 2047) = "); Scanf("%d",&ypulse); if (abs(xpulse) > 2047 ) break; if (abs(ypulse) > 2047 ) break; i8091_INTP_PULSE(CARD1,xpulse,ypulse); break; //--------------------------------------------------------------- case 'o','O': Print(">>i8091_INTP_LINE\r\n"); Print("X pulse number (+- 524287) = "); Scanf("%ld",&x); Print("Y pulse number (+- 524287) = "); Scanf("%ld",&y); if (labs(x) > 524287) break; if (labs(y) > 524287) break; i8091_INTP_LINE(CARD1,x,y); break; //--------------------------------------------------------------- case 'p','P': Print(">>i8091_INTP_LINE02\r\n"); Print("X pulse number (+- 2^31 -1) = "); Scanf("%ld",&x); Print("Y pulse number (+- 2^31 -1) = "); Scanf("%ld",&y); Print("Input speed (LSP~2040) = "); Scanf("%d",&speed); if (speed2040) break; Print("Press any key to break...\r\n"); i8091_INTP_LINE02(CARD1,x,y,speed,0); do { DisplayEncoder(); if (Kbhit()) stop_process(); } while (i8091_INTP_STOP()!=READY); break; //--------------------------------------------------------------- case 'q','Q': Print(">>i8091_INTP_CIRCLE02\r\n"); Print("center point X = "); Scanf("%ld",&x); Print("center point Y = "); Scanf("%ld",&y); Print("Which direction (0:CW 1:CCW)="); Scanf("%d",&tempint); Print("Input speed (LSP~2040) = "); Scanf("%d",&speed); dir=(unsigned char)tempint; if ((dir!=CW) && (dir!=CCW)) break; if (speed2040) break; Print("Press any key to break...\r\n"); i8091_INTP_CIRCLE02(CARD1,x,y,dir,speed,0); do { DisplayEncoder(); if (Kbhit()) stop_process(); } while (i8091_INTP_STOP()!=READY); break; //--------------------------------------------------------------- case 'r','R': Print(">>i8091_INTP_ARC02\r\n"); Print("center point X = "); Scanf("%ld",&x); Print("center point Y = "); Scanf("%ld",&y); Print("Radius R = "); Scanf("%ld",&R); Print("Which direction (0:CW 1:CCW)="); Scanf("%d",&tempint); Print("Input speed (LSP~2040) = "); Scanf("%d",&speed); dir=(unsigned char)tempint; if ((dir!=CW) && (dir!=CCW)) break; if (speed2040) break; Print("Press any key to break...\r\n"); i8091_INTP_ARC02(CARD1,x,y,R,dir,speed,0); do { DisplayEncoder(); if (Kbhit()) stop_process(); } while (i8091_INTP_STOP()!=READY); break; //--------------------------------------------------------------- case 's','S': Print(">>User define testing\r\n"); //test LINE02, no acceleration i8091_INTP_LINE02(CARD1,1000,1000,20,1); do {DisplayEncoder();} while (i8091_INTP_STOP()!=READY); i8091_INTP_LINE02(CARD1,2000,1000,22,1); do {DisplayEncoder();} while (i8091_INTP_STOP()!=READY); i8091_INTP_LINE02(CARD1,2000,2000,24,1); do {DisplayEncoder();} while (i8091_INTP_STOP()!=READY); i8091_INTP_LINE02(CARD1,1000,2000,26,1); do {DisplayEncoder();} while (i8091_INTP_STOP()!=READY); do {DisplayEncoder();} while (i8091_IS_X_STOP(CARD1)==NO); Delay(2000); //test WAIT_X, WAIT_Y, WAIT_Z i8091_INTP_LINE02(CARD1, 10000,-10000,150,0); do {DisplayEncoder();} while (i8091_INTP_STOP()!=READY); i8091_INTP_LINE02(CARD1, -10000, 10000,150,0); do {DisplayEncoder();} while (i8091_INTP_STOP()!=READY); do {DisplayEncoder();} while (i8091_IS_X_STOP(CARD1)==NO); do {DisplayEncoder();} while (i8091_IS_Y_STOP(CARD1)==NO); Delay(2000); i8091_INTP_CIRCLE02(CARD1, 5000,-5000, CW, 150, 0); do {DisplayEncoder();} while (i8091_INTP_STOP()!=READY); do {DisplayEncoder();} while (i8091_IS_X_STOP(CARD1)==NO); do {DisplayEncoder();} while (i8091_IS_Y_STOP(CARD1)==NO); break; } DisplayEncoder(); while (Kbhit()) { Getch(); } Print("Press any key to continue...\r\n"); while (!Kbhit()) DisplayEncoder(); Getch(); } while (1); }