4.2 COMPort Object

The top-level object of the COM Port UCX component. Reads from and writes to serial ports.

4.2.1 BaudRate property

Sets the baud rate on the COM port.

Syntax

 object.BaudRate[=BaudRate As Integer]
 

Type

Integer.

Attributes

Read/write.

Remarks

BaudRate is an optional parameter that sets the COM port's baud rate. Valid values are: 110, 150, 300, 600, 1200, 2400, and 9600.

Example

This example sets the baud rate to 600 for COM1.

 Set ComObj = CreateObject("UCX:COMPort") 
 ComObj.Port = COM1 
 ComObj.BaudRate = 600
 

See Also

4.2.2 DataBits property

Sets the number of data bits to 7 or 8.

Syntax

 object.DataBits[=Number As Integer]
 

Type

Integer.

Attributes

Read/write.

Remarks

Number is an optional parameter that sets the number of data bits. Valid values are 7 and 8.

Example

This example sets number of data bits to 7 on COM1.

 Set ComObj = CreateObject("UCX:COMPort") 
 ComObj.Port = COM1 
 ComObj.BaudRate = 600 
 ComObj.DataBits = 7 
 ComObj.Parity = EVEN
 

4.2.3 Parity property

Sets the parity to even or odd.

Syntax

 object.Parity=[Bit As Integer]
 

Type

Integer.

Attributes

Read/write.

Remarks

Valid Bit parameter values are EVEN and ODD.

Example

This example sets parity to EVEN on COM1.

 Set ComObj = CreateObject("UCX:COMPort") 
 ComObj.Port = COM1 
 ComObj.BaudRate = 600 
 ComObj.DataBits = 7 
 ComObj.Parity = EVEN
 

4.2.4 Port property

Sets the COM port number.

Syntax

 object.Port[=Number As Integer]
 

Type

Integer.

Attributes

Read/write.

Remarks

Number is an optional parameter that sets the COM port number. See Port Constants.

Example

This example sets COM1 as the serial port to use.

 Set ComObj = CreateObject("UCX:COMPort") 
 ComObj.Port = COM1
 

See Also

4.2.5 StopBits property

Sets the stop bits value to 1 or 2.

Syntax

 object.StopBits[=Number As Integer]
 

Type

Integer.

Attributes

Read/write.

Remarks

Number is an optional parameter that sets the stop bits value to 1 or 2.

Example

This example sets the stop bits value to 2 on COM1.

 Set ComObj = CreateObject("UCX:COMPort") 
 ComObj.Port = COM1 
 ComObj.BaudRate = 600 
 ComObj.DataBits = 7 
 ComObj.Parity = EVEN 
 ComObj.StopBits = 2
 

4.2.6 Xon property

Sets the serial port to on or off.

Syntax

 object.Xon =Status As Boolean]
 

Type

Boolean.

Attributes

Read/write.

Remarks

Valid Status parameter values are TRUE or FALSE.

Example

This example sets the serial port COM1 to ON.

 Set ComObj = CreateObject("UCX:COMPort") 
 ComObj.Port = COM1 
 ComObj.BaudRate = 600 
 ComObj.DataBits = 7 
 ComObj.Parity = EVEN 
 ComObj.StopBits = 2 
 ComObj.Xon = TRUE
 

4.2.7 Clear method

Clears the data buffer for a specified serial port.

Syntax

 object.Clear()
 

Parameters

None.

Return Values

Boolean. Returns TRUE if successful; otherwise, FALSE.

Example

This example clears the data buffer for serial port COM1.

 Set ComObj = CreateObject("UCX:COMPort") 
 ComObj.Port = COM1 
 ComObj.BaudRate = 600 
 ComObj.DataBits = 7 
 ComObj.Parity = EVEN 
 ComObj.StopBits = 2 
 ComObj.Xon = TRUE 
 ComObj.Open() 
 ComObj.Clear()
 

4.2.8 Close method

Closes a specified serial port.

Syntax

 object.Close()
 

Parameters

None.

Return Values

Boolean. Returns TRUE if successful; otherwise, FALSE.

Example

This example closes the serial port COM1.

 Set ComObj = CreateObject("UCX:COMPort") 
 ComObj.Port = COM1 
 ComObj.BaudRate = 600 
 ComObj.DataBits = 7 
 ComObj.Parity = EVEN 
 ComObj.StopBits = 2 
 ComObj.Xon = TRUE 
 ComObj.Open() 
 ComObj.Clear() 
 ComObj.Close()
 

4.2.9 Open method

Opens and initializes a specified serial port.

Syntax

 object.Open()
 

Parameters

None.

Return Values

Boolean. Returns TRUE if successful; otherwise, FALSE.

Example

This example opens and initializes the serial port COM1.

 Set ComObj = CreateObject("UCX:COMPort") 
 ComObj.Port = COM1 
 ComObj.BaudRate = 600 
 ComObj.DataBits = 7 
 ComObj.Parity = EVEN 
 ComObj.StopBits = 2 
 ComObj.Xon = TRUE 
 ComObj.Open() 
 ComObj.Clear()
 

4.2.10 Read method

Reads from a specified serial port.

Syntax

 object.Read   ([BytesToRead As Integer])
 

Parameters

BytesToRead
Optional. The number of bytes to read.

Return Values

String.

Example

This example reads one byte from serial port COM1.

 Set ComObj = CreateObject("UCX:COMPort") 
 ComObj.Port = COM1 
 ComObj.BaudRate = 600 
 ComObj.DataBits = 7 
 ComObj.Parity = EVEN 
 ComObj.StopBits = 2 
 ComObj.Xon = TRUE 
 ComObj.Open() 
 ComObj.Clear() 
 If(ComObj.Ready()) Then 
      data = ComObj.Read(1) 
 EndIf 
 ComObj.Close()
 

4.2.11 Ready method

Determines if a character is in the buffer for a specified serial port and if that character is ready to be read.

Syntax

 object.Ready
 

Parameters

None.

Return Values

Boolean. Returns TRUE if successful; otherwise, FALSE.

Example

This example determines if a character is in the buffer for serial port COM1 and if that characters is ready to be read.

 Set ComObj = CreateObject("UCX:COMPort") 
 ComObj.Port = COM1 
 ComObj.BaudRate = 600 
 ComObj.DataBits = 7 
 ComObj.Parity = EVEN 
 ComObj.StopBits = 2 
 ComObj.Xon = TRUE 
 ComObj.Open() 
 ComObj.Clear() 
 ComObj.Write("Once again, Novell leads the way") 
 If(ComObj.Ready()) Then 
      data = ComObj.Read(1) 
 EndIf 
 ComObj.Close()
 

4.2.12 Write method

Writes a string to a specified serial port.

Syntax

 object.Write   (Data As String)
 

Parameters

Data
The data to write into the port.

Return Values

Boolean. Returns TRUE if successful; otherwise, FALSE.

Example

This example writes the text "Once again, Novell leads the way" to serial port COM1.

 Set ComObj = CreateObject("UCX:COMPort") 
 ComObj.Port = COM1 
 ComObj.BaudRate = 600 
 ComObj.DataBits = 7 
 ComObj.Parity = EVEN 
 ComObj.StopBits = 2 
 ComObj.Xon = TRUE 
 ComObj.Open() 
 ComObj.Clear() 
 ComObj.Write("Once again, Novell leads the way") 
 If(ComObj.Ready()) Then 
      data = ComObj.Read(1) 
 EndIf 
 ComObj.Close()
 

4.2.13 XmodemReceive method

Receives a file using the xmodem protocol.

Syntax

 object.XmodemReceive 
    (FileName As String)
 

Parameters

FileName
The name of the file to receive.

Return Values

Boolean. Returns TRUE if successful; otherwise, FALSE.

Example

This example receives the file test.c using the xmodem protocol.

 Set ComObj = CreateObject("UCX:COMPort") 
 ComObj.Port = COM1 
 ComObj.BaudRate = 600 
 ComObj.DataBits = 7 
 ComObj.Parity = EVEN 
 ComObj.StopBits = 2 
 ComObj.Xon = TRUE 
 ComObj.Open() 
 ComObj.Clear() 
 ComObj.XmodemSend("test.c") 
 ComObj.XmodemReceive("test.c") 
 
 

4.2.14 XmodemSend method

Sends a file using the xmodem protocol.

Syntax

 object.XmodemSend 
    (FileName As String)
 

Parameters

FileName
The name of the file to send.

Return Values

Boolean. Returns TRUE if successful; otherwise, FALSE.

Example

This example sends the file test.c using the xmodem protocol.

 Set ComObj = CreateObject("UCX:COMPort") 
 ComObj.Port = COM1 
 ComObj.BaudRate = 600 
 ComObj.DataBits = 7 
 ComObj.Parity = EVEN 
 ComObj.StopBits = 2 
 ComObj.Xon = TRUE 
 ComObj.Open() 
 ComObj.Clear() 
 ComObj.XmodemSend("test.c")