[futurebasic] Re: [FB] Port in a storm

Message: < previous - next > : Reply : Subscribe : Cleanse
Home   : October 1999 : Group Archive : Group : All Groups

From: Mel Patrick <mel@...>
Date: Thu, 7 Oct 1999 20:35:50 -0700
> >After accessing a LAN via modem and disconnecting, my non-networking printer
>>will not work. The message that comes up is that the port is in use even
>>though no programs show as being active. The only way I can get it to print
>>is to restart the computer.
>>
>>Does someone have any code to clear the ports so that the printer doesn't
> >think that the port is in use. (Or any other suggestions that may work)

This is what I use to slam dunk the serial ports :


'----------------------------
' Serial Port Reset
' by Jon Birck
' mods by Ross W. Lambert
' This source code is in
' public domain.

'---------------------------- Constants


_portFree               = 0
_portBusy               = 2

_serModemPortIn         = -6
_serModemPortOut        = -7
_serPrinterPortIn       = -8
_serPrinterPortOut      = -9

'---------------------------- Functions

CLEAR LOCAL MODE
LOCAL FN closeSerialDriver(drvName$)
   DIM pBlk.50
   pBlk.ioRefNum% = VAL(drvName$)                  ' really!
END FN = FN CLOSE(@pBlk)                          ' returns osErr%

'----------------------------

LOCAL FN closeDrivers(port%)
   DIM 255 drv$
   DIM osErr%
 
   LONG IF port% = _modemPort
     drv$                  = STR$(_serModemPortIn)
     osErr%                = FN closeSerialDriver(drv$)
     LONG IF osErr%        = _noErr
       drv$                = STR$(_serModemPortOut)
       osErr%              = FN closeSerialDriver(drv$)
     END IF
   XELSE                                           ' printer port
     drv$                  = STR$(_serPrinterPortIn)
     osErr%                = FN closeSerialDriver(drv$)
     LONG IF osErr%        = _noErr
       drv$                = STR$(_serPrinterPortOut)
       osErr%              = FN closeSerialDriver(drv$)
     END IF
   END IF
 
END FN = osErr%

'----------------------------

' FN portStatus returns the status of the given serial port.

' OK for Miniruntime: Yes

' INPUTS:  port%   -  INTEGER: port number (_modemPort or _printerPort)
' OUTPUT:  pStatus% -  INTEGER: status: 0=not in use, 1=AppleTalk, 2=in use
' GLOBALS: none

LOCAL MODE
LOCAL FN portStatus(port%)
   DIM pStatus%
 
   SELECT port%
     CASE _modemPort
       pStatus% = PEEK(_portAUse)
     CASE _printerPort
       pStatus% = PEEK(_portBUse)
   END SELECT
   IF (pStatus% AND &0F) = _useATalk THEN pStatus% = _useATalk
   IF pStatus% > _portBusy THEN pStatus% = _portFree
 
END FN = pStatus%

'----------------------------

' OK for Miniruntime: Yes

' INPUTS:  port%   -  INTEGER: port number (_modemPort or _printerPort)
' OUTPUT:  none
' GLOBALS: none

LOCAL MODE
LOCAL FN resetPort(port%)
   DIM osErr%
 
   osErr% = _noErr
   LONG IF FN portStatus(port%) = _portBusy
     osErr% = FN closeDrivers(port%)
   END IF
END FN = osErr%

'----------------------------

LOCAL MODE
LOCAL FN waitForInput$(msg$)
   DIM 1 key$
   DIM mouseDn%
   PRINT msg$
   DO
     key$ = INKEY$
     mouseDn% = FN BUTTON
   UNTIL ((LEN(key$)>0) OR (mouseDn% =_true))
END FN = key$

'---------------------------- Main

WINDOW 1, "Serial Port Software Reset"
PRINT
PRINT " This demo will do a software reset of your modem port."
PRINT

k$ = FN waitForInput$(" Press RETURN to continue, any other key to abort...")
PRINT

LONG IF k$ = CHR$(13)
   LONG IF FN resetPort(_modemPort) = _noErr
     PRINT " Port reset successful!"
   XELSE
     PRINT " Error on reset, #" + STR$(osErr%)
   END IF
XELSE
   PRINT " Reset aborted."
END IF
'
PRINT " Do you want to reset your printer port?"
PRINT
k$ = FN waitForInput$(" Press RETURN to continue, any other key to abort...")
LONG IF k$ = CHR$(13)
   LONG IF FN resetPort(_printerPort) = _noErr
     PRINT " Port reset successful!"
   XELSE
     PRINT " Error on reset, #" + STR$(osErr%)
   END IF
XELSE
   PRINT " Reset aborted."
END IF
'
PRINT

PRINT
FN waitForInput$ (" Press any key to end.")


Mel Patrick
mel@...