*/
Stuck? Need help? Ask questions on our forums.
*/

View \GLOBAL.BAS

Serial Communication programming examples in Windows

Submitted By: WEBMASTER
Rating: starstar (Rate It)


' Communication Demo is a sample aplication showing how the
' Windows COMM API function can be used in a Visual Basic program.
' This sample program does not utilize all the functions available
' through the Windows COMM API function, but is a can be used as
' a starting point.                                                ==

TYPE CommStateDCB
    Id          AS STRING * 1   ' Port Id from OpenComm
    BaudRate    AS INTEGER      ' Baud Rate
    ByteSize    AS STRING * 1   ' Data Bit Size (4 to 8)
    Parity      AS STRING * 1   ' Parity
    StopBits    AS STRING * 1   ' Stop Bits
    RlsTimeOut  AS INTEGER      ' Carrier Detect Time "CD"
    CtsTimeOut  AS INTEGER      ' Clear-to-Send Time
    DsrTimeOut  AS INTEGER      ' Data-Set-Ready Time
    ModeControl AS INTEGER      ' Mode Control Bit Fields
    XonChar     AS STRING * 1   ' XON character
    XoffChar    AS STRING * 1   ' XOFF character
    XonLim      AS INTEGER      ' Min characters in buffer before XON is sent
    XoffLim     AS INTEGER      ' Max characters in buffer before XOFF is send
    PeChar      AS STRING * 1   ' Parity Error Character
    EofChar     AS STRING * 1   ' EOF/EOD character
    EvtChar     AS STRING * 1   ' Event character
    TxDelay     AS INTEGER      ' Reserved/Not Used
END TYPE

TYPE TextMetrics
    tmHeight AS INTEGER
    work1 AS STRING * 14
    work2 AS STRING * 9
    Work3 AS STRING * 6
END TYPE

DECLARE FUNCTION OpenComm Lib "user" (BYVAL a AS STRING, BYVAL b AS INTEGER, BYVAL c AS INTEGER) AS INTEGER
DECLARE FUNCTION CloseComm Lib "user" (BYVAL a AS INTEGER) AS INTEGER

DECLARE FUNCTION WriteComm Lib "user" (BYVAL a AS INTEGER, BYVAL b AS STRING, BYVAL c AS INTEGER) AS INTEGER
DECLARE FUNCTION ReadComm Lib "user" (BYVAL a AS INTEGER, BYVAL b AS STRING, BYVAL c AS INTEGER) AS INTEGER

DECLARE FUNCTION GetCommEventMask Lib "user" (BYVAL a AS INTEGER, BYVAL b AS INTEGER) AS INTEGER
DECLARE FUNCTION SetCommEventMask Lib "user" (BYVAL a AS INTEGER, BYVAL b AS INTEGER) AS INTEGER

DECLARE FUNCTION SetCommState Lib "user" (b AS CommStateDCB) AS INTEGER
DECLARE FUNCTION GetCommState Lib "user" (BYVAL a AS INTEGER, b AS CommStateDCB) AS INTEGER

DECLARE FUNCTION REMoveMenu Lib "User" (ByVal hMenu As Integer, ByVal nPosition As Integer, ByVal wFlags As Integer) As Integer
DECLARE FUNCTION GetSystemMenu Lib "User" (BYVAL hWnd AS INTEGER, BYVAL Action AS INTEGER) AS INTEGER

Global CONST FALSE = 0
Global CONST TRUE = NOT FALSE

Global CONST MF_BYPOSITION = &H400  'Used by RemoveMenu()

' COMM OPEN Error Numbers

Global CONST IE_BADID = -1      ' Invalid or unsupported id
Global CONST IE_OPEN = -2       ' Device Already Open
Global CONST IE_NOPEN = -3      ' Device Not Open
Global CONST IE_MEMORY = -4     ' Unable to allocate queues
Global CONST IE_DEFAULT = -5    ' Error in default parameters
Global CONST IE_HARDWARE = -10  ' Hardware Not Present
Global CONST IE_BYTESIZE = -11  ' Illegal Byte Size
Global CONST IE_BAUDRATE = -12  ' Unsupported BaudRate

' COMM EVENT MASK

Global CONST EV_RXCHAR = &H1
Global CONST EV_RXFLAG = &H2
Global CONST EV_TXEMPTY = &H4
Global CONST EV_CTS = &H8
Global CONST EV_DSR = &H10
Global CONST EV_RLSD = &H20
Global CONST EV_BREAK = &H40
Global CONST EV_ERR = &H80
Global CONST EV_RING = &H100
Global CONST EV_PERR = &H200
Global CONST EV_ALL = &H3FF
           
Global CommHandle AS INTEGER
Global CommDeviceNum AS INTEGER

Global CommPortName AS STRING
Global PostPortName AS STRING

Global CommEventMask AS INTEGER
Global PostEventMask AS INTEGER

Global CommState AS CommStateDCB
Global PostState AS CommStateDCB

Global CommRBBuffer AS INTEGER
Global PostRBBuffer AS INTEGER

Global CommTBBuffer AS INTEGER
Global PostTBBuffer AS INTEGER

Global CommReadInterval AS INTEGER
Global PostReadInterval AS INTEGER

Global CaptionLeft      AS INTEGER
Global CaptionTop       AS INTEGER
Global CaptionHeight    AS INTEGER
Global CaptionCenter    AS INTEGER
Global CaptionWidth     AS INTEGER
Global CaptionText$

corner
© 1996-2008 CommunityHeaven LLC. All rights reserved. Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
North American business development: Nicolai Wadstrom. Publisher: Lars Hagelin.