bingaman@dcc1.UUCP (George C. Bingaman) (02/26/86)
Can anyone tell me how I can get version 2.0 of Turbo Pascal running under MS/PC-DOS to check the status of a device? I would like to verify that the printer is online, and that the drive is ready before doing I/O. I would also like to have the program check to see what drive it is being run from. I have looked thru Borland's reference manual, but if the info is there I'm missing it. Any help would be greatly appreciated. Thanks in advance, George =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= | / akgua \ George C. Bingaman | / cbosgd \ DeKalb Community College | ...!/ hplabs \!gatech!dcc1!bingaman 2101 Womack Rd. | \ ihnp4 / Dunwoody (Atlanta) Ga. 30338 | \ seismo / | \ ulysses/ =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= -- =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= | / akgua \ George C. Bingaman | / cbosgd \ DeKalb Community College | ...!/ hplabs \!gatech!dcc1!bingaman 2101 Womack Rd. | \ ihnp4 / Dunwoody (Atlanta) Ga. 30338 | \ seismo / | \ ulysses/ =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
cc100jr@gitpyr.UUCP (Joel M. Rives) (02/26/86)
In article <198@dcc1.UUCP> bingaman@dcc1.UUCP (George C. Bingaman) writes: > > Can anyone tell me how I can get version 2.0 of Turbo Pascal running under >MS/PC-DOS to check the status of a device? I would like to verify that the >printer is online, and that the drive is ready before doing I/O. I would also >like to have the program check to see what drive it is being run from. > I have looked thru Borland's reference manual, but if the info is there I'm >missing it. Any help would be greatly appreciated. > -------------------------------------------------------------------------------- I recommend that you re-read section 14.8 in the Version 2.0 Reference Manual. This section deals with the function IOresult. By setting {$I-} as a compiler directive, you can do your own I/O error trapping. Experiment a little. It can't hurt and you may learn a lot. One suggestion for checking which drive the program is running from is as follows: Assume that the name of the program you are running is called "myprog.com". const MaxDrive = { the greatest reference letter for a disk drive for your system } type drives = '@'..MaxDrive; { @ = no drive or nil drive } {$I-} function disk_drive: drives; var exists : boolean; drive : drives; test : text; path : string[20]; begin assign(test,'dummy.tst'); rewrite(test); writeln(test,'This is a test file'); close(test); exists := false; drive := '@'; while (not exists) and (drive < MaxDrive) do begin drive := drives(ord(drive) + 1); path := drive + ':' + 'dummy.tst'; assign(test,path); exists := IOresult = 0; close(test); end; erase(test); if exists then disk_drive := drive else disk_drive := '@'; end; { disk_drive } {$I+} This function could be called (in this example) as follows: var current : drives; begin . . . current := disk_drive; . . . end. The variable "current" should then contain the letter of the drive which the program is currently working from. -Joel Rives Joel Rives Georgia Insitute of Technology, Atlanta Georgia, 30332 ...!{akgua,allegra,amd,hplabs,ihnp4,seismo,ut-ngp}!gatech!gitpyr!cc100jr "Remember, no matter where you go, there you are!" << Buckaroo Banzai >>
jrv@siemens.UUCP (02/27/86)
The sample program assumes that you don't have some file called 'dummy.tst' floating around on any of the other disks in the system. Also, does the {$I-} option cause the critical error handler to be bypassed? If not you will probably get the MS-DOS error about disk drive not ready if you try to access a floppy disk which does not have a disk in it. Rather annoying! (I have never used Turbo-Pascal.) Finally, if Turbo-Pascal gives you access to MS-DOS functions then executing function 19h - Current Disk will return the current default disk. Unless I read the request wrong that should give you the information you need Jim Vallino {allegra,inhp4}!princeton!siemens!jrv
jrv@siemens.UUCP (02/27/86)
For testing the status of a device, MS-DOS provides function 44h - I/O control for Devices. To check for printer status set the registers before the function call as follows: ah = 44h I/O Control for Devices al = 07h Get output status bx = 04h Standard printer file handle You'll need to find the exact Turbo-Pascal syntax to do this. On return from the function call Al = 0ffh if the printer is ready and 00 if it is not. (I just tested this to make sure.) If you want to test other than the standard printer then you will have to open that device first to get a file handle for it to place in the BX register. For testing disk drives I know of no way other than trying to read/write to them. You then run into the problem of getting the MS-DOS error if the disk drive is not ready (i.e. an open floppy door). To trap this you have to substitute for the Critical Error Handler at Interrupt 24h. However, you still have to wait for the floppy drive to power up and find that it is not ready. Has anyone found a better way to test for disk ready status?? Jim Vallino {allegra,inhp4}!princeton!siemens!jrv