The text of a manual · part 36 of 40
2D JANUS PSK for C/C++ Reference Manual, pages 351 to 360
Pages 351 to 360 of 400
The original document is the PDF (793 KB). This is its text as extracted, unedited; tables and drawings read best in the PDF, and each page heading opens it at that page.
For the Intermec J2020, Intermec J2010 and Intermec J2050
Page 351
B Sample Interrupt Programs
Page 352
blank
Page 353
Sample Interrupt Programs
B
This appendix lists C language programs that demonstrate how to use interrupts.
Using the Sample Programs The sample programs in this appendix demonstrate how to use software interrupts in place of the Intermec PSK functions. It is much easier to write programs that use the PSK functions than to write programs that directly call the software interrupts. For more information on using software interrupts, see Chapter 3, “Software Interrupts.” Note: Do not run programs that use PSK library functions on your PC. If you attempt to run these programs, you will receive an error message and the program will not run.
CAUTION
Caution Do not run programs that use Intermec-specific interrupt extensions on your PC. If you attempt to run these programs, they will cause your PC to lock up and possibly corrupt your system BIOS. Conseil N’exécutez pas de programmes utilisant des extensions d’interruption spécifiques à Intermec sur votre PC. Si vous tentez de les exécuter sans le Simulator, ces programmes risquent de verrouiller votre PC et d’altérer le BIOS de votre système.
B-3
Page 354
apmif.c apmif.c /* apmif.c * * This program is an APM interface test module. It allows entry of the APM * interface registers from the MS-DOS command line, and then it makes an APM call. * The results displayed are the register contents returned from the call. * * Compiler: Borland C++ 3.11 */ typedef unsigned char uchar; typedef unsigned int uint; #include <stdio.h> #include <ctype.h> #include <string.h> uint tohex(char*); void get_data(char**); void call_APM(void); void print_IV(void); uint AX_REG,BX_REG,CX_REG,DX_REG,CARRY; void main(int argc,char **argv){ AX_REG = 0x5300; BX_REG = 0x0; CX_REG = 0x0; DX_REG = 0x0; call_APM();
//check for pm enabled if (BX_REG != 0x504D){ //504D = PM, means apm implemented printf("APM not supported.\n\n"); return; } if ((CX_REG & 0x0008) != 0) //check for pm disabled printf("PM is disabled.\n\n"); AX_REG = 0x5301; BX_REG = 0x0; CX_REG = 0x0; DX_REG = 0x0; call_APM();
// connect as apm client if (CARRY != 0){ printf("APM client already connected.\n\n"); } else{ printf("Successful connect.\n\n"); } if (argc == 1) // if no arguments, prompt for them printf("Enter AX BX CX...\n\n"); get_data(argv);
B-4
Page 355
apmif.c
B
//display register values entered printf("i AX=%0.4X BX=%0.4X\ni CX=%0.4X DX=%0.4X\n", AX_REG,BX_REG,CX_REG,DX_REG); call_APM();
//do the apm call
/* have to call standby twice to make it work (so it won't skip activity)*/ if ((AX_REG == 0x5307)&&(CX_REG == 0x0001)) call_APM(); //display the register values returned printf("o AX=%0.4X BX=%0.4X\no CX=%0.4X DX=%0.4X\n", AX_REG,BX_REG,CX_REG,DX_REG); printf("carry=%0.4X\n\n",CARRY); if (AX_REG == 0x530B){ //if get pm event and standby, do it if ((BX_REG & 0x01) != 0x0){ AX_REG = 0x5307; BX_REG = 0x0001; CX_REG = 0x0001; call_APM(); call_APM(); } } } void call_APM(){ /* the call apm interface routine */ asm{ push ax push bx push cx push dx mov ax,AX_REG mov bx,BX_REG mov cx,CX_REG mov dx,DX_REG int 15h mov AX_REG,ax mov BX_REG,bx mov CX_REG,cx mov DX_REG,dx pop dx pop cx pop bx pop ax } /* end asm */ asm mov CARRY,0 asm jnc a asm inc CARRY a: } void get_data (char **dos_arg){ char *regval; char charbuff[10];
/* get the register values from user entry */ regval = *dos_arg++; if (*dos_arg == 0) {
B-5
Page 356
apmif.c printf("Enter AX value in hex:"); fflush(stdin); regval=charbuff; gets (regval); } else regval = *dos_arg++; AX_REG = tohex(regval); if (*dos_arg == 0) { printf("Enter BX value in hex:"); fflush(stdin); regval=charbuff; gets (regval); } else regval = *dos_arg++; BX_REG = tohex(regval); if (*dos_arg == 0) { printf("Enter CX value in hex:"); fflush(stdin); regval=charbuff; gets (regval); } else regval = *dos_arg++; CX_REG = tohex(regval); if (*dos_arg == 0) { DX_REG = 0; } else { regval = *dos_arg++; DX_REG = tohex(regval); } } uint tohex(char *string){ uint ctr; uint num; uint value = 0; uint stop;
/* convert ascii characters to hex */ stop=strlen(string); for (ctr = 0; ctr < stop; ctr++){ value <<= 4; num = string[ctr]; num -= '0'; num = (num > 9) ? (num - ('A' - ':')) : num; num = (num > 15) ? (num - ('a' - 'A')) : num; value += num; } /* end for */ return value; }
B-6
Page 357
appbreak.cpp
B appbreak.cpp /* appbreak.cpp * * This program demonstrates application break control using interrupts. * * The operator presses application break to exit program. The application break sequence * is as follows: * * Start the Appbreak program: * 1/0 turn off Janus * F3+2+left arrow at the same time * 1 by itself * 1/0 turn Janus back on * * Written: Aug. 30, 1993 * Last Modified: Aug. 30, 1993 * Author: Ray Rogers * Compiler: Borland C++ 3.1 */ #include #include #include #include #include
"dos.h" "stdio.h" "stdlib.h" "conio.h" "im20lib.h"
#define #define #define #define #define #define
KEY_Int BREAK_REQ TRANS_OK VALID_SERVICE ESC FOREVER
0x7e 0xff 0x00 0x00 0x1b 1
// keyboard interrupt // break requested // sucessful KSCPU transaction // valid service call to 0x7e // escape key // endless loop control typedef struct { IM_UCHAR status; IM_UCHAR request; } RESP_BUFF;
// KSCPU comm status // request made or not?
RESP_BUFF
// KSCPU response buffer rbuff;
// Prototypes IM_UINT Chk_App_Break(RESP_BUFF *); void main() { clrscr(); printf("%s", "\n\rDo appl. break or\n\rpress ESC\n\r"); while(FOREVER) { if(VALID_SERVICE == Chk_App_Break(&rbuff)) { if(rbuff.status == TRANS_OK) { if(rbuff.request == BREAK_REQ) { printf("%s", "\n\rAppl. Break detected!\n\r"); exit(0); } }
B-7
Page 358
appbreak.cpp
} // end VALID_SERVICE if(kbhit()) if(getch() == ESC) // just in case { printf("%s", "\n\rEscape was pressed!\n\r"); exit(0); } } } // Check for application break request IM_UINT Chk_App_Break(RESP_BUFF *rbuff) { _ES = FP_SEG((RESP_BUFF *) rbuff); // far pointer to response buffer _BX = FP_OFF((RESP_BUFF *) rbuff); // far pointer to response buffer _AH = 0x01; geninterrupt(KEY_Int); return(_AH); }
B-8
// check app break function
Page 359
backlite.cpp
B backlite.cpp /* backlite.cpp * * This program demonstrates how to toggle the back light. * * Written: Aug. 12, 1993 * Last Modified: Aug. 19, 1993 * Author: Ray Rogers * Compiler: Borland C++ 3.1 */ #include
"dos.h"
#define
LCD_Int
0x79 void main() { _AH = 0x01; _AL = 0x02;
// LCD size mode manager interrupt
// back light function // toggle back light state geninterrupt(LCD_Int); }
B-9
Page 360
close.cpp close.cpp /* close.cpp * * This program demonstrates how to close COM2 on the 2D JANUS. * * Written: Feb. 10, 1999 * Last Modified: Feb. 10, 1999 * Author: Peter J. Girodat * Compiler: Borland C++ 3.1 */ #include <dos.h> #include <stdio.h> #include <stdlib.h> #define RS_VECTOR 0x7D #define RS_ASIC_RESET 0x0C #define RS_CLOSE_COM2 0x0D #define RS_ALL_SUCESS 0x0100 #define RS_INVALID_REQUEST 0x8100 void main() { _AH = RS_CLOSE_COM2; _AL = 0;
/* Interrupt 7DH Reader Services */ /* Function 0CH ASIC Reset */ /* Function 0DH Close COM2 */ /* Reader Service sucessful */ /* Invalid function Hex code received */
// AH = Function 0DH geninterrupt(RS_VECTOR); if (_AX == RS_ALL_SUCESS) printf ("COM2 CLOSED\n"); else if (_AX == RS_INVALID_REQUEST) printf ("JANUS 1D Reader\n"); }
B-10