home *** CD-ROM | disk | FTP | other *** search
- ' == [ GENERAL NOTES ] ================================================
- ' =
- ' This Basic program demonstrates how to interface to the =
- ' AsyncTermio device driver. The interface used finds it's =
- ' origin on AT&T's UNIX systems. =
- ' =
- ' The generalized UNIX serial link interface was originally moved =
- ' to MS-DOS for C programmers that desire to port serial comm =
- ' software between MS-DOS and UNIX. =
- ' =
- ' Most Basic programmers will tell you that Basic's COM port =
- ' management is sufficient for most applications. We agree. =
- ' However, should you desire to use the generalized UNIX serial =
- ' port interface, Async TermIO will suffice. =
- ' =
- ' With the OPEN COM statement, Basic provides: =
- ' =
- ' + Speed, Parity, Stopbits, Character Length Control. =
- ' + Asynchronous buffering of input and output. =
- ' + Call back functions that are invoked on COM activity. =
- ' + Exception handling. =
- ' + Timing. =
- ' =
- ' With the OPEN COM statement, Basic DOES NOT provide: =
- ' =
- ' + Xon/Xoff Flow Control. =
- ' + The interface is not generalized across environments. =
- ' and is not portable to other operating systems. =
- ' + Not as diverse as the generalized UNIX interface. =
- ' =
- ' The trade-offs of writing serial communications software are =
- ' discussed at length in the Async TermIO documentation. =
- ' =
- ' Please review the publication (See Async TermIO User's Manual) =
- ' "Portable Serial Communications Between MS-DOS & UNIX" =
- ' =
- ' =======================================================================
- ' =
- ' Copyright (c) 1988 Boulder Software Group =
- ' P.O. BOX 14200 =
- ' Boulder, CO 80308-4200 =
- ' =
- ' (303) 440-7868 (Voice) =
- ' (303) 449-8612 (FAX) =
- ' =
- ' =======================================================================
- '
-
- '
- ' == [ INCLUDE FILES ] ================================================
- ' =
- ' The include file TERMIO.H contains several constants that are =
- ' use to set flags, compare values, function declarations, etc. =
- ' =
- ' =======================================================================
- '
-
- ' $INCLUDE: 'TERMIO.H'
-
-
- '
- ' == [ TTYDEVICEIOCTL ] ================================================
- ' =
- ' TtyDeviceIoctl is responsible for taking the INTEGER =
- ' FileHandle, the Command (what to do), and a Basic record =
- ' of type TtyParam. Depending on the Command (see printed doc) =
- ' the device attributes set in the TtyParam record will be issued =
- ' to the device associated with the FileHandle. =
- ' =
- ' It is somewhat more awkward to implement this function in =
- ' Basic than in C, however, it is possible. =
- ' =
- ' =======================================================================
- ' =
- ' NOTE: =
- ' =
- ' Normally the function TtyDeviceIoctl() would be named =
- ' Ioctl() (as it is in C), however, Basic reserves IOCTL =
- ' as a keyword and thus we can't use it as an identifier. =
- ' =
- ' The name TtyDeviceIoctl() was arbitrarily chosen, the =
- ' source code is provided below, so feel free to change it =
- ' to what ever you want. Note that TtyDeviceIoctl() will be =
- ' described as the function ioctl() in all accompanying =
- ' documentation. =
- ' =
- ' =======================================================================
- '
- '
- '
- FUNCTION TtyDeviceIoctl( FileHandle AS INTEGER, Command AS INTEGER, TtyParams AS Termio ) STATIC
-
- DIM TtyDevice AS MsdosTermio
- DIM InRegs AS RegType
- DIM OutRegs AS RegType
-
-
- '
- ' Make a copy of the record (struct) for the device call
- '
-
- TtyDevice.TtyParams = TtyParams
-
- '
- ' Set the mode of the device identified by FileHandle to
- ' true binary. The BIN bit must be set in the device attribute
- ' word inside the device driver.
- '
-
- IF( SetBinaryMode( FileHandle ) <> PASS ) THEN
-
- TtyDeviceIoctl = FAIL
- EXIT FUNCTION
-
- END IF
-
-
- '
- ' If the Command is TCSBRK, TCXONC, or TCFLSH then
- ' the argument should be passed as an integer.
- ' If this is the case, read the current value of the
- ' termio record (struct) contained internally to the
- ' device driver
- '
-
- SELECT CASE ( Command )
- CASE TCSBRK, TCXONC, TCFLSH
-
- '
- ' Read the current struct
- '
-
- TtyDevice.FileHandle = FileHandle
- TtyDevice.Command = Command
- TtyDevice.Arguement = 0
-
- InRegs.AX = &H4400 OR ( ReadCXBytes AND &H00FF )
- InRegs.BX = FileHandle
- InRegs.CX = LEN( TtyDevice )
- InRegs.DX = VARPTR( TtyDevice )
- InRegs.DS = VARSEG( TtyDevice )
-
- CALL INTERRUPT( &H0021, InRegs, OutRegs )
-
- IF ( ( OutRegs.Flags AND &H0001 ) <> 0 ) THEN
- TtyDeviceIoctl = FAIL
- EXIT FUNCTION
- END IF
-
- CASE TCGETS, TCSETS, TCSETAW, TCSETAF
-
- CASE ELSE
- TtyDeviceIoctl = FAIL
- EXIT FUNCTION
- END SELECT
-
- '
- ' Examine the Command and determine whether to read or
- ' write bytes to using the rea MS-DOS IOCTL function call
- '
-
- SELECT CASE( Command )
- CASE TCGETS
- FunctionValue = ReadCXBytes
-
- CASE TCSETS, TCSETAW, TCSETAF
- FunctionValue = WriteCXBytes
- TtyDevice.Arguement = 0
-
- '
- ' Special case: When Command is TCSETBRK, TCXONC, or
- ' TCFLSH then the Argument (TtyParams) contains an
- ' integer ( 0, 1, or 2 per the command) than can be
- ' found by referencing the first member of the structure
- ' (Ciflag) that Basic "thought" was passed.
- '
-
- CASE TCSETBRK, TCXONC, TCFLSH
- FunctionValue = WriteCXBytes
- TtyDevice.Arguement = TtyParams.Ciflag
-
- CASE ELSE
- TtyDeviceIoctl = FAIL
- EXIT FUNCTION
- END SELECT
-
- '
- ' Perform the operation on the structure via MS-DOS
- '
-
- TtyDevice.FileHandle = FileHandle
- TtyDevice.Command = Command
-
- InRegs.AX = &H4400 OR ( FunctionValue AND &H00FF )
- InRegs.BX = FileHandle
- InRegs.CX = LEN( TtyDevice )
- InRegs.DX = VARPTR( TtyDevice )
- InRegs.DS = VARSEG( TtyDevice )
-
- CALL INTERRUPT( &H0021, InRegs, OutRegs )
-
- '
- ' Copy the information from the device driver to the
- ' callers record.
- '
-
- TtyParams = TtyDevice.TtyParams
-
- '
- ' See if we failed the function call
- '
-
- IF ( ( OutRegs.Flags AND &H0001 ) <> 0 ) THEN
- TtyDeviceIoctl = FAIL
- EXIT FUNCTION
- END IF
-
-
- TtyDeviceIoctl = PASS
-
- END FUNCTION
-
-
- '
- ' == [ SETBINARYMODE ] ================================================
- ' =
- ' This function is used by TtyDeviceIoctl() to set binary mode =
- ' in the device's attribute block. The user should not have to =
- ' call this function. =
- ' =
- ' =======================================================================
- '
- '
- '
- FUNCTION SetBinaryMode( FileHandle AS INTEGER )
-
- DIM InRegs AS RegType
- DIM OutRegs AS RegType
-
- '
- ' Obtain a copy of the device attribute word from the
- ' device driver identified by FileHandle
- '
-
- InRegs.AX = &H4400
- InRegs.BX = FileHandle
-
- CALL INTERRUPT( &H0021, InRegs, OutRegs )
-
- IF ( ( OutRegs.Flags AND &H0001 ) <> 0 ) THEN
- SetBinaryMode = FAIL
- EXIT FUNCTION
- END IF
-
- '
- ' Or in the bit that indicates that the device will
- ' operate in binary mode
- '
-
- InRegs.AX = &H4401
- InRegs.BX = FileHandle
- InRegs.DX = ( OutRegs.DX AND &H00FF ) OR &H0020
-
- CALL INTERRUPT( &H0021, InRegs, OutRegs )
-
- IF ( ( OutRegs.Flags AND &H0001 ) <> 0 ) THEN
- SetBinaryMode = FAIL
- EXIT FUNCTION
- END IF
-
- SetBinaryMode = PASS
-
- END FUNCTION
-
-