Attribute VB_Name = "Module1" '**************************************************************** 'Title- * ' VB32COMM.BAS * '*Description- * '* Provides the basic link between the COMM-DRV/NT * '* library and BASIC functions. * '**************************************************************** '**************************************************************** '*=====BAUDS * '**************************************************************** Global Const BAUD110 = 0 '110 baud Global Const BAUD150 = 1 '150 baud Global Const BAUD300 = 2 '300 baud Global Const BAUD600 = 3 '600 baud Global Const BAUD1200 = 4 '1200 baud Global Const BAUD2400 = 5 '2400 baud Global Const BAUD4800 = 6 '4800 baud Global Const BAUD9600 = 7 '9600 baud Global Const BAUD19200 = 8 '19200 baud Global Const BAUD38400 = 9 '38400 baud Global Const BAUD57600 = 10 '57600 baud Global Const BAUD115200 = 11 '115.2 kbaud Global Const BAUDUSER00 = 12 'User baud rate Global Const BAUD14400 = 12 '14400 baud Global Const BAUDUSER01 = 13 'User baud rate Global Const BAUD28800 = 13 '28800 baud Global Const BAUDUSER02 = 14 'User baud rate Global Const BAUDUSER03 = 15 'User baud rate Global Const BAUDUSER04 = 16 'User baud rate Global Const BAUDUSER05 = 17 'User baud rate Global Const BAUDUSER06 = 18 'User baud rate Global Const BAUDUSER07 = 19 'User baud rate Global Const BAUDUSER08 = 20 'User baud rate Global Const BAUDUSER09 = 21 'User baud rate '**************************************************************** '*=====Parities * '**************************************************************** Global Const PAR_NONE = 0 'No parity Global Const PAR_ODD = 1 'ODD parity Global Const PAR_EVEN = 2 'Even parity Global Const PAR_SODD = 3 'Sticky ODD parity Global Const PAR_SEVEN = 4 'Sticky Even parity Global Const PARITY_NONE = 0 'No parity Global Const PARITY_ODD = 1 'ODD parity Global Const PARITY_EVEN = 2 'Even parity Global Const PARITY_SODD = 3 'Sticky ODD parity Global Const PARITY_SEVEN = 4 'Sticky Even parity '**************************************************************** '*=====Lengths * '**************************************************************** Global Const LENGTH_5 = 0 '5 bits Global Const LENGTH_6 = 1 '6 bits Global Const LENGTH_7 = 2 '7 bits Global Const LENGTH_8 = 3 '8 bits '**************************************************************** '*=====Stobits * '**************************************************************** Global Const STOPBIT_1 = 0 '1 Stop bit Global Const STOPBIT_2 = 1 '2 Stop bit '**************************************************************** '*=====Break * '**************************************************************** Global Const BREAK_OFF = 0 'Break off Global Const BREAK_ON = 1 'Break on '**************************************************************** '*=====PROTOCOL * '**************************************************************** Global Const PROT_RTSRTS = 0 'Local CTS/RTS-Remote CTS/RTS Global Const PROT_RTSXON = 1 'Local CTS/RTS-Remote XON/XOFF Global Const PROT_RTSDTR = 2 'Local CTS/RTS-Remote DSR/DTR Global Const PROT_RTSNON = 3 'Local CTS/RTS-Remote no prot Global Const PROT_NONNON = 4 'Local no prot-Remote no prot Global Const PROT_NONXON = 5 'Local no protocol-Remote XOFF/XON Global Const PROT_XONNON = 6 'Local XOFF/XON-Remote no prot Global Const PROT_XONXON = 7 'Local XON/XOFF-Remote XON/XOFF Global Const PROT_DTRNON = 8 'Local DSR/DTR-Remote no protocol Global Const PROT_DTRRTS = 9 'Local DSR/DTR-Remote CTS/RTS Global Const PROT_DTRDTR = 10 'Local DSR/DTR-Remote DSR/DTR Global Const PROT_DTRXON = 11 'Local DSR/DTR-Remote DSR/DTR Global Const PROT_NONRTS = 12 'Local no prot-Remote CTS/RTS prot Global Const PROT_NONDTR = 13 'Local no prot-Remote DSR/DTR prot Global Const PROT_XONRTS = 14 'Local XOFF/XON- Remote CTS/RTS Global Const PROT_XONDTR = 15 'Local XOFF/XON-Remote DSR/DTR '**************************************************************** 'Flag2 bit settings(User flag(pcb.flag2)) * '**************************************************************** Global Const STOREALL = &H1 'Set=Store LSR/MSR/PORT/DATA Global Const LEAVE_DTR = &H8 'Set=DTR unchanged on cleanup Global Const LEAVE_RTS = &H10 'Set=RTS unchanged on cleanup Global Const IGNORE_16550 = &H20 'Set=Do not enable 16550 Global Const DISABLE_MODEMSIG = &H40 'Set=Disable RTS/DTR on setup Global Const NOCHANGE_MODEMSIG = &H80 'Set=On setup leave RTS/DTR Global Const PARENTPORT = &H800 'Set=VxD use pport for parent Global Const PCIFLAG = &H1000 'Set=PCI card/Adr=VenID Seg=DevID Global Const TIMESTAMPBYTES = &H2000 'Timestamp bytes in stream Global Const NINEBITPROTOCOL = &H4000 'Use Nine Bit protocol Global Const MULTIDROP = &H8000 'Use multidrop protocol '**************************************************************** '*=====Return error codes * '**************************************************************** Global Const RS232ERR_NONE = 0 'RS232 no error Global Const RS232ERR_BUFFER = 1 'RS232 buf not set/buf changed Global Const RS232ERR_ACTIVE = 2 'RS232 port not active Global Const RS232ERR_XMTBUF = 3 'RS232 xmit buffer full Global Const RS232ERR_RCVBUF = 4 'RS232 recv buffer empty Global Const RS232ERR_SYNTAX = 5 'RS232 port syntax error Global Const RS232ERR_BUFSIZ = 6 'RS232 invalid buffer size Global Const RS232ERR_PORT = 7 'RS232 invalid port Global Const RS232ERR_HANDLR = 8 'RS232 handler changed Global Const RS232ERR_BAUD = 9 'RS232 invalid baud rate Global Const RS232ERR_PARITY = 10 'RS232 invalid parity Global Const RS232ERR_LNGTH = 11 'RS232 invalid data length Global Const RS232ERR_STOPBIT = 12 'RS232 invalid # stopbits Global Const RS232ERR_PROTOCOL = 13 'RS232 invalid protocol Global Const RS232ERR_IRQCHANGED = 14 'RS232 IRQ changed Global Const RS232ERR_PORTCHANGED = 15 'RS232 port changed Global Const RS232ERR_THRESHOLD = 16 'RS232 invalid threshold Global Const RS232ERR_INVIRQ = 17 'RS232 invalid IRQ Global Const RS232ERR_INTOFF = 18 'RS232 interrupts not enabled Global Const RS232ERR_BREAK = 19 'RS232 invalid break syntax Global Const RS232ERR_FATAL = 20 'RS232 fatal error Global Const RS232ERR_DSR = 21 'RS232 CTS error Global Const RS232ERR_INVADR = 22 'RS232 Invalid RS232 address Global Const RS232ERR_ENVIRON = 23 'Environment variable not set Global Const RS232ERR_IOCTL = 24 'Error issuing IOCTL call Global Const RS232ERR_ATEXIT = 25 'Error issuing atexit cleanup Global Const RS232ERR_DEVINIT = 26 'Error mapping for dir calls Global Const RS232ERR_DOSOPEN = 27 'Error opening Device Global Const RS232ERR_MALLOC = 28 'Error allocating memory Global Const RS232ERR_EXTMICRO = 29 'Error on external micro Global Const RS232ERR_CARDCHANGED = 30 'Card changed error Global Const RS232ERR_CARDTYPE = 31 'Card type error Global Const RS232ERR_NOSUPPORT = 32 'Not supported Global Const RS232ERR_CMDBUFFULL = 33 'Card command buffer full Global Const RS232ERR_PPORT = 34 'Invalid parent PCB Global Const RS232ERR_NODEVICE = 35 'No device for this port Global Const RS232ERR_UNKNOWN = 36 'Unknow error Global Const RS232ERR_BUSY = 37 'Busy Global Const RS232ERR_NOTIMER = 38 'No more timers available Global Const RS232ERR_INT14VEC = 39 'INT 14H vector changed Global Const RS232ERR_INT1CVEC = 40 'Timer vector changed Global Const RS232ERR_DPMI = 41 'DPMI error Global Const RS232ERR_WINBUF = 42 'No windows buffer or too small Global Const RS232ERR_NOASYNCRES = 43 'No asynchronous resources left Global Const RS232ERR_NOTIMERRES = 44 'No timer resources left Global Const RS232ERR_NOOTHERES = 45 'Out of other resources Global Const RS232ERR_FILEIO = 46 'File I/O error Global Const RS232ERR_HMEMG64 = 47 'Hardware memory exceeded 64K Global Const RS232ERR_MAPVXD = 48 'VxD not present/other VxD error Global Const RS232ERR_THREAD = 49 'Could not start a thread '**************************************************************** '8250 Asynchronous adapter offsets and bits * '**************************************************************** Global Const BAUD_LOW = 0 'Offset to low byte of baud divisor Global Const DATABUF = 0 'Offset to rcv/xmt buffer Global Const BAUD_HIGH = 1 'Offset to high byte of baud divisor Global Const IER = 1 'Interrupt Enable Register Global Const IER_RDA = &H1 'Receive Data Available int bit Global Const IER_THRE = &H2 'Transmitter Hold Reg. Empty int bit Global Const IER_RLS = &H4 'Receive Line Status int bit Global Const IER_MS = &H8 'Modem Status int bit Global Const IIR = 2 'Interrupt Identification Register Global Const IIR_RLS = &H6 '*equal* if Receiver Line Stat int Global Const IIR_RDA = &H4 '*equal* to if character ready Global Const IIR_THRE = &H2 '*equal* to if TX buffer empty Global Const IIR_PEND = &H1 ' zero if any interrupt pending Global Const IIR_MS = &H0 '*equal* to if Modem Status int Global Const IIR_FIFOL = &H40 'FIFO ACTIVE Global Const IIR_FIFOH = &H80 'FIFO ACTIVE Global Const FCR = 2 'FIFO Control Register Global Const FCR_ENAB = &H1 'FIFO Enable Global Const FCR_RRESET = &H2 'Receiver FIFO Reset Global Const FCR_XRESET = &H4 'Xmitter FIFO Reset Global Const FCR_DMASEL = &H8 'DMA Select Global Const FCR_TTRGLSB = &H10 'Xmitter Trigger LSB Global Const FCR_TTRGMSB = &H20 'Xmitter Trigger MSB Global Const FCR_RTRGLSB = &H40 'Receiver Trigger LSB Global Const FCR_RTRGMSB = &H80 'Receiver Trigger MSB Global Const EFR = 2 'Enhanced Feature Register Global Const EFR_RCVX1ONOFF = &H2 'Receiver compares Xon1/Xoff1 Global Const EFR_XMTX2ONOFF = &H4 'Xmitter compares Xon2/Xoff2 Global Const EFR_ENABLE = &H10 'Enable certain bits in IER,ISR,FCR,MCR Global Const EFR_SPECCHAR = &H20 'Special character select Global Const EFR_AUTORTS = &H40 'Enable Auto RTS Global Const EFR_AUTOCTS = &H80 'Enable Auto CTS Global Const LCR = 3 'Line Control Register Global Const LCR_WLS0 = 0 'Word Length Select Bit 0 Global Const LCR_WLS1 = &H1 'Word Length Select Bit 1 Global Const LCR_STOPBITS1 = &H4 'Number of stop bits Global Const LCR_PARITYEN = &H8 'Enab Parity(see SPARITY & EPARITY) Global Const LCR_EPARITY = &H10 'Even Parity Bit Global Const LCR_SPARITY = &H20 'Stick Parity Global Const LCR_BREAK = &H40 'set if break desired Global Const LCR_DLAB = &H80 'Divisor Latch Access Bit Global Const MCR = 4 'Modem Control Register Global Const MCR_DTR = &H1 'Data Terminal Ready Global Const MCR_RTS = &H2 'Request To Send Global Const MCR_OUT1 = &H4 'Output 1 (unused) Global Const MCR_OUT2 = &H8 'Output 2 (External Int Enable) Global Const MCR_LOOP = &H10 'Loopback enable Global Const XON1R = 4 'XON1 reg when LCR=0xBF Global Const LSR = 5 'Line Status Register Global Const LSR_DATA = &H1 'Data Ready bit Global Const LSR_OVERRUN = &H2 'Overrun error bit Global Const LSR_PARITY = &H4 'Parity error bit Global Const LSR_FRAMING = &H8 'Framing error bit Global Const LSR_BREAK = &H10 'Break Detect Global Const LSR_THRE = &H20 'Transmit Holding Register Empty Global Const LSR_TSRE = &H40 'Transmit Shift Register Empty Global Const XON2R = 5 'XON2 reg when LCR=0xBF*/ Global Const MSR = 6 'Modem Status Register Global Const MSR_DEL_CTS = &H1 'Delta Clear To Send Global Const MSR_DEL_DSR = &H2 'Delta Data Set Ready Global Const MSR_EDGE_RI = &H4 'Trailing Edge of Ring Indicator Global Const MSR_DEL_SIGD = &H8 'elta Receive Line Signal Detect Global Const MSR_CTS = &H10 'Clear To Send Global Const MSR_DSR = &H20 'Data Set Ready Global Const MSR_RI = &H40 'Ring Indicator - during entire ring Global Const MSR_DCD = &H80 'Data Carrier Detect - on line Global Const XOFF1R = 6 'XOFF1 reg when LCR=0xBF Global Const SCR = 7 'Scratch Register Global Const XOFF2R = 7 'XOFF2 reg when LCR=0xBF '**************************************************************** 'COMMDRV Port Control Block * '**************************************************************** Type port_param ser_rs232_base As Long 'Base address of port Irq As Integer 'Interrupt number filler01 As String * 2 'Filler Baud As Long 'baud rate index Parity As Integer 'parity index lngth As Integer 'length index stopbit As Integer 'stopbit index brk As Integer 'Break protocol As Integer 'protocol index block As String * 2 'Lowbyte=inblock Highbyte=outblock inbuf_low As Long 'Low threshold of recv buffer inbuf_high As Long 'High threshold of xmit buffer buffer_seg As Long 'Segment to start of buffer buffer_off As Long 'Offset to start of buffer inbuf_len As Long 'Input buffer length outbuf_len As Long 'Output buffer length aux_addr1 As String * 1 'Subport address sflag As String * 1 'Flag filler02 As String * 2 cardseg As Long 'Memory card segment cardtype As Integer 'Card Type filler03 As String * 2 intfunc As Long 'Interupt function serror As Long 'Error flag Flag As Long 'General purpose flag inbuf_count As Long '# bytes in input buf outbuf_count As Long '# of bytes in ouput lost_ichar As Long 'Lost inputted bytes lost_ochar As Long 'Lost outputted bytes total_ichar As Long 'Total attempted bytes in total_ochar As Long 'Total attempted bytes out devfuncs As Long 'Ptr to table of ptrs to dev funcs lsr_msr As Integer 'Low Byte=MSR<==>High Byte=LSR filler04 As String * 2 ddata As Long 'Data that sub-device driver may use inbuf_start As Long 'Input buffer control block outbuf_start As Long 'Output buffer control block irqp As Long 'Pointer to irq parameter block Port As Long 'Port number flag2 As Long 'Secondary flag obufoff As Long 'Output buf off if DIFFXBUF set obufseg As Long 'Output buf seg if DIFFXBUF set pport As Long 'Parent port ppcb As Long 'Parent pcb timer_iblk As Long 'Timer block timer_oblk As Long 'Timer block hblock As String * 2 'Hi bytes of input/output timeouts char_xon As String * 1 'XON char(Receive) char_xoff As String * 1 'XOFF char(Receive) char_xxon As String * 1 'XON char(xmit) char_xxoff As String * 1 'XOFF char(xmit) filler05 As String * 2 'Filler auxpcb As Long 'Pointer to auxiliary PCB prot_local As Long 'Local protocol prot_remote As Long 'Remote protocol opcb As Long 'Pointer to this PCB dflag As Long 'Subdevice specific flag o_baud_reg As String * 2 'Old baud rate o_lcr_reg As String * 1 'Old LCR o_mcr_reg As String * 1 'Old MCR o_ier_reg As String * 1 'Old IER tuart As String * 1 'UART type filler06 As String * 2 'Filler nextpcb As Long 'Pointer to next End Type '**************************************************************** 'VxD Port Control Block Structure * '**************************************************************** Type vxd_port_param VTotalIn As Long 'Number of characters received. VTotalOut As Long 'Number of characters transmitted. VInBufCnt As Long 'Input buffer count VOutBufCnt As Long 'Output buffer count VIRingSize As Long 'Size of input buffer VORingSize As Long 'Size of output buffer VMSRIntCnt As Long 'Number of MSR ints VLSRIntCnt As Long 'Number of LSR ints VXmtIntCnt As Long 'Number of XMT ints VRcvIntCnt As Long 'Number of RCV ints VRcvLostCnt As Long 'Number of received characters lost. VXmtLostCnt As Long 'Number of transmit characters lost. VOFlushCnt As Long 'Output flush count VIFlushCnt As Long 'Input flush count VMSRReg As String * 1 'Current modem status register VLSRReg As String * 1 'Current line status register VTypeUART As String * 1 'Type of UART VFillerb1 As String * 1 'Filler VPort As Integer 'COMM-DRV port number VBase As Integer 'Base address VIrq As Integer 'IRQ VBaud As Integer 'Baud rate VBreak As Integer 'Break VLength As Integer 'Length VParity As Integer 'Parity VStopbit As Integer 'Stop bits VProtocol As Integer 'Protocol VCardseg As Integer 'Card segment VCharXon As String * 1 'XON character to expect from remote VCharXoff As String * 1 'XOFF character to expect from remote VCharXxon As String * 1 'XON character to send to remote VCharXxoff As String * 1 'XOFF character to send to remote VFlag As Long 'Flag VCurOverrunCnt As Long 'Ovrrun err cnt VCurParityCnt As Long 'Parity err cnt VCurFramingCnt As Long 'Framing err cnt VCurBreakCnt As Long 'Break err cnt VBytesRead As Long 'Number of bytes read from VxD VBytesWrite As Long 'Number of bytes written to VxD VXonIn As Long 'Number of XON received VXoffIn As Long 'Number of XOFF received VXonOut As Long 'Number of XON sent VXoffOut As Long 'Number of XOFF sent VDevBase As Integer 'Device Relative Base Address entered VDevIrq As Integer 'Device RelativeIRQ Entered VDData As Integer 'Actual DData entered VDFlag As Integer 'Actual DFlag Entered VSubPort As Integer 'Actual Subport Entered VFiller5 As Integer 'Spare VIrqPCB As Long 'Pointer to IRQ PCB VFillerb2(6) As Long 'Room for growth VPCBIdx As Integer 'Index to this PCB VXmtCnt As Integer 'Number of bytes to xmit at once VORingTop As Long 'Start of output buffer ring VORingBottom As Long 'Bottom of output buffer ring+1 VORingInput As Long 'Current input pointer to output buf VORingOutput As Long 'Current output pointer to output bu VIRingTop As Long 'Start of input buffer ring VIRingBottom As Long 'Bottom of input buffer ring+1 VIRingInput As Long 'Current input pointer to input buf VIRingOutput As Long 'Current output pointer to input buf VProtLocal As Long 'Local protocol index VProtRemote As Long 'Remote protocol index VInbufHigh As Long 'Input buffer high threshold VInbufLow As Long 'Input buffer high threshold VNextPCBPtr As Long 'Pointer to next PCB VOldBaudReg As String * 2 'Old Baud Rate Register VOldMCRReg As String * 1 'Old Modem Control Register VOldLCRReg As String * 1 'Old Line Control Register VOldFCRReg As String * 1 'Old FIFO Control Register VOldIERReg As String * 1 'Old Interrupt Enable Register VFillerb3 As String * 2 'Filler(Complete 32bit boundary) VCtsOn As Long '# of Cts On transition VCtsOff As Long '# of Cts Off transition VCdOn As Long '# of Cd On transition VCdOff As Long '# of Cd Off transition VRiOn As Long '# of Ri On transition VRiOff As Long '# of Ri Off transition VDsrOn As Long '# of Dsr On transition VDsrOff As Long '# of Dsr Off transition VFillerb4(2) As Long 'Room for growth VPPCB As Long 'Parent PCB End Type '**************************************************************** 'Declarations for VxD functions in cdrvxd32.dll * '**************************************************************** Declare Function WCSCVxDBreakOff& Lib "cdrvxd32.dll" (ByVal Port&) Declare Function WCSCVxDBreakOn& Lib "cdrvxd32.dll" (ByVal Port&) Declare Function WCSCVxDBytesInRcvBuf& Lib "cdrvxd32.dll" (ByVal Port&) Declare Function WCSCVxDBytesInXmtBuf& Lib "cdrvxd32.dll" (ByVal Port&) Declare Function WCSCVxDCallbackOnEvent& Lib "cdrvxd32.dll" (ByVal p&, ByVal Evt&, ByVal V1&, ByVal V2&, ByVal Fnc&) Declare Function WCSCVxDCleanup& Lib "cdrvxd32.dll" (ByVal Port&) Declare Function WCSCVxDDtrOff& Lib "cdrvxd32.dll" (ByVal Port&) Declare Function WCSCVxDDtrOn& Lib "cdrvxd32.dll" (ByVal Port&) Declare Function WCSCVxDDeleteEvent& Lib "cdrvxd32.dll" (ByVal p&, ByVal Evt&) Declare Function WCSCVxDFlush& Lib "cdrvxd32.dll" (ByVal Port&, ByVal mode&) Declare Function WCSCVxDGetMetrics& Lib "cdrvxd32.dll" (ByVal Port&, ByVal cd&) Declare Function WCSCVxDGetPacket& Lib "cdrvxd32.dll" (ByVal p&, ByVal c&, ByVal pkt$) Declare Function WCSCVxDGetPort& Lib "cdrvxd32.dll" (ByVal p&, vpcb As vxd_port_param, ByVal flg&) Declare Function WCSCVxDGetRegister& Lib "cdrvxd32.dll" (ByVal p&, ByVal r&, v&) Declare Function WCSCVxDInit& Lib "cdrvxd32.dll" () Declare Function WCSCVxDInitializePort& Lib "cdrvxd32.dll" (p&, ByVal subport&, ByVal adr%, ByVal Irq%, ByVal cardtype%, ByVal cardseg%, ByVal Flag%) Declare Function WCSCVxDIsAllDataOut& Lib "cdrvxd32.dll" (ByVal Port&) Declare Function WCSCVxDOpenPort& Lib "cdrvxd32.dll" (ByVal sp&, ByVal adr%, ByVal ir%, ByVal ct%, ByVal cs%, ByVal f%, ByVal pp&) Declare Function WCSCVxDPutPacket& Lib "cdrvxd32.dll" (ByVal p&, ByVal c&, ByVal pkt$) Declare Function WCSCVxDPutRegister& Lib "cdrvxd32.dll" (ByVal p&, ByVal r&, ByVal v&) Declare Function WCSCVxDRtsOff& Lib "cdrvxd32.dll" (ByVal Port&) Declare Function WCSCVxDRtsOn& Lib "cdrvxd32.dll" (ByVal Port&) Declare Function WCSCVxDSetBaudDiv& Lib "cdrvxd32.dll" (ByVal b&, ByVal d&) Declare Function WCSCVxDSetPortCharacteristics& Lib "cdrvxd32.dll" (ByVal p&, ByVal Baud%, ByVal Parity%, ByVal Length%, ByVal stopbit%, ByVal protocol%) Declare Function WCSCVxDSetup& Lib "cdrvxd32.dll" (pcb As port_param, Id&) Declare Function WCSCVxDSizeOfRcvBuf& Lib "cdrvxd32.dll" (ByVal Port&) Declare Function WCSCVxDSizeOfXmtBuf& Lib "cdrvxd32.dll" (ByVal Port&) Declare Function WCSCVxDSpaceInRcvBuf& Lib "cdrvxd32.dll" (ByVal Port&) Declare Function WCSCVxDSpaceInXmtBuf& Lib "cdrvxd32.dll" (ByVal Port&) Declare Function WCSCVxDViewPacket& Lib "cdrvxd32.dll" (ByVal p&, ByVal c&, ByVal pkt$) Declare Function WCSCVxDWaitForEvent& Lib "cdrvxd32.dll" (ByVal p&, ByVal Evt&, ByVal Tim&, ByVal V1&, ByVal V2&)