CommTools CDF Function Reference

Sept 7, 2001

This CDF Library includes the following functions:

FUNCTION REFERENCE


OpenComPort


Input Parameters

PortNumber Integer (1=Com1, 2=Com2, 3=Com3 ...)
BaudRate Long (Desired baud rate)

Return Value

PortHandle Long (Handle to the Port that must be supplied to other functions)

What It Does

This function opens the specified COM port and returns a 'handle' to the port, which is used for the other routines. If the function fails, the handle returned will have a value of 0 .

The com port is initialized to the following parameters:


Parity        NONE
Data Bits     8
Stop Bits     1
Input Buffer  2048 bytes
Output Buffer 2048 bytes

ExtendedOpenPort


Input Parameters


PortNumber    Integer  (1=Com1, 2=Com2, 3=Com3 ...)
BaudRate      Long     (Desired baud rate)
DataBits      Integer  (7 or 8)
StopBits      Integer  (usually 1, sometimes 2)
Parity        Integer  (0=none, 1=odd, 2=even, 3=mark, 4=space)

Return Value


PortHandle    Long     (Handle to the Port that must be supplied to other
                        functions)

What It Does

This function is identical to OpenComPort, except it allows for more precise control of the port's characteristics. OpenComPort uses the 'popular' default values for parity, data, and stop bits. ExtendedOpenPort allows you to specify these values. ExtendedOpenPort returns a 'handle' to the port, which is used for the other routines. If the function fails, the handle returned will have a value of 0 .

The com port is initialized to the following parameters:


Input Buffer  2048 bytes
Output Buffer 2048 bytes

SendString


Input Parameters


PortHandle    Long     (Handle returned by OpenComPort)
TextToSend    String   (Text Message to Send)

Return Value


Status        Long     (GetAsyncState value)

What It Does

This function sends the string in TextToSend out the port identified by PortHandle. The function returns the AsyncStatus value which will usually be 0 unless an error occurred. An ASCII (13) [Carriage Return] is appended to the string before it is sent.


GetString


Input Parameters


PortHandle    Long     (Handle returned by OpenComPort)

Return Value


TextMessage   String   (Message Retrieved from COM port)

What It Does

This returns the next available string from the COM port specified by PortHandle. The function only returns a value if a string terminate by a carriage return (ascii 13) is waiting. Partial strings are not returned UNLESS 511 characters of unterminated text is in the com port buffer. If unterminated data is in the port buffer, an empty string is returned.


GetAsyncState


Input Parameters

NOTHING

Return Value

Status Long

What It Does

This function can be used to determine the last error encountered by the COM port manager. Although there are many possible values, the following lists some of the more common values (last four digits of status):


0000          Ok
0002          File not found
0003          Path not found
0005          Access Denied
0101          Disk Full
2900          No more ports
2920          Incomplete data in buffer
2921          Buffer is full
2922          Buffer is empty
2925          String is longer than 255

contact LANimation for a complete list of possible codes.


ClosePort


Input Parameters


PortHandle    Long     (Handle returned by OpenComPort)

Return Value


nothing       Long

What It Does

This function closes the port and releases all resources used by the port control logic.


KeyPressed


Input Parameters


nothing

Return Value


0 or 1       integer

What It Does

This function returns a 1 if a key has been pressed on the keyboard and a 0 if not. It only returns the current state of the keyboard, it does not wait for input. This makes it useful for 'Press any key to terminate ...' operation in communications monitoring loops.

 

 

This web site best viewed with Microsoft Internet Explorer version 5.0 or higher