BPS Script API  2.24.4
bps::AsyncIO Class Reference

The bps.AsyncIO class provides functionality for reading and writing asynchronous serial ports. More...

Public Types

enum  AccessMode { ReadOnly = 0x0001 , WriteOnly = 0x0002 , ReadWrite = 0x0003 }
 This enum is used with open() to describe the mode in which a port is opened. More...
 

Public Member Functions

 AsyncIO ()
 Creates a serial port object with the with fileName.
 
void close ()
 Closes the port.
 
void open (AccessMode aAccessMode)
 Opens the port in the specified access mode if possible; otherwise throws an exception. More...
 
String read ()
 
Number readByte ()
 Reads one byte from the port if possible; otherwise throws an exception. More...
 
String toString () const
 
void write (String aData)
 Writes data to the port if possible; otherwise throws an exception. More...
 
void writeByte (Number aByte)
 Writes a byte to the port is possible; otherwise throws an exception. More...
 

Properties

Number bitRate
 The transmission speed given as bits per second. More...
 
Number dataBits
 The data bits per word. More...
 
Number defaultEncoding
 Default encoding used for static text read/write methods, and initial encoding for files opened subsequently in script context. More...
 
Number encoding
 Encoding for the non-static text read and write methods. More...
 
Number flowControl
 The flow control to regulate transmission. More...
 
Number parity
 The parity. More...
 
String portName
 The serial port name. More...
 
Array portNames
 List of all asynchronous serial ports available on the current computer.
 
Number stopBits
 The stop bits per word. More...
 
Number writeTimeout
 The write timeout in milliseconds. More...
 

Detailed Description

The bps.AsyncIO class provides functionality for reading and writing asynchronous serial ports.

Asynchronous devices are often called COM device on windows, or tty character devices on unix based operating systems.

Member Enumeration Documentation

◆ AccessMode

This enum is used with open() to describe the mode in which a port is opened.

Enumerator
ReadOnly 

Opens the port in read-only mode.

WriteOnly 

Opens the port in write-only mode.

ReadWrite 

The port is opened for reading and writing.

Member Function Documentation

◆ open()

void bps::AsyncIO::open ( AccessMode  aAccessMode)

Opens the port in the specified access mode if possible; otherwise throws an exception.

Parameters
aAccessModeThe file access mode flag(s).
Exceptions
Errorthrown if open fails.

◆ read()

String bps::AsyncIO::read ( )
Returns
All data currently in the receive buffer.

◆ readByte()

Number bps::AsyncIO::readByte ( )

Reads one byte from the port if possible; otherwise throws an exception.

Returns
The numeric code of the byte read.

◆ toString()

String bps::AsyncIO::toString ( ) const
Returns
Returns "AsyncIO(port name)"

◆ write()

void bps::AsyncIO::write ( String  aData)

Writes data to the port if possible; otherwise throws an exception.

Parameters
aDataThe data to write.

◆ writeByte()

void bps::AsyncIO::writeByte ( Number  aByte)

Writes a byte to the port is possible; otherwise throws an exception.

Parameters
aByteThe numeric code of the byte to write.

Property Documentation

◆ bitRate

Number bps::AsyncIO::bitRate
readwrite

The transmission speed given as bits per second.

Set the bit rate before opening the device.

ConstantEncoding
bps.AsyncIO.B110110 bits per second.
bps.AsyncIO.B300300 bits per second.
bps.AsyncIO.B600600 bits per second.
bps.AsyncIO.B12001200 bits per second.
bps.AsyncIO.B24002400 bits per second.
bps.AsyncIO.B48004800 bits per second.
bps.AsyncIO.B96009600 bits per second.
bps.AsyncIO.B1920019200 bits per second.
bps.AsyncIO.B3840038400 bits per second.
bps.AsyncIO.B5760057600 bits per second.
bps.AsyncIO.B115200115200 bits per second.

◆ dataBits

Number bps::AsyncIO::dataBits
readwrite

The data bits per word.

Set the data bits before opening the device.

ConstantEncoding
bps.AsyncIO.D55 bits per word.
bps.AsyncIO.D66 bits per word.
bps.AsyncIO.D77 bits per word.
bps.AsyncIO.D88 bits per word.

◆ defaultEncoding

Number bps::AsyncIO::defaultEncoding
readwrite

Default encoding used for static text read/write methods, and initial encoding for files opened subsequently in script context.

The initial default encoding at application start is UTF-8.

ConstantEncoding
bps.AsyncIO.Utf8UTF-8
bps.AsyncIO.Latin1Latin 1
bps.AsyncIO.Local8BitLocal 8 Bit
bps.AsyncIO.IBM850IBM 850
Note
Changing the default encoding will not change the encoding of files previously opened in script context. It will however effect existing files created in C++ context, when the encoding property was not yet changed from within a script.

◆ encoding

Number bps::AsyncIO::encoding
readwrite

Encoding for the non-static text read and write methods.

The encoding of files opened in script context is initialized to the value of defaultEncoding at opening time. The encoding of files opened in C++ context is bps.AsyncIO.Default.

ConstantEncoding
bps.AsyncIO.DefaultUse defaultEncoding.
bps.AsyncIO.Utf8UTF-8
bps.AsyncIO.Latin1Latin 1
bps.AsyncIO.Local8BitLocal 8 Bit
bps.AsyncIO.IBM850IBM 850

◆ flowControl

Number bps::AsyncIO::flowControl
readwrite

The flow control to regulate transmission.

Set the flow control before opening the device.

ConstantEncoding
bps.AsyncIO.NoFlowControlNo flow control at all. DTR and RTS always on.
bps.AsyncIO.HardHardware flow control by DTR and RTS.
bps.AsyncIO.SoftSoftware flow control by XON/XOFF. DTR and RTS always on.
bps.AsyncIO.HardAndSoftHardware flow control plus software flow control.

◆ parity

Number bps::AsyncIO::parity
readwrite

The parity.

Set the parity before opening the device.

ConstantEncoding
bps.AsyncIO.NoParityNo parity.
bps.AsyncIO.OddOdd parity.
bps.AsyncIO.EvenEven parity.
bps.AsyncIO.MarkMark parity.
bps.AsyncIO.SpaceSpace parity.

◆ portName

String bps::AsyncIO::portName
readwrite

The serial port name.

Set the port name before opening the device.

On windows, the port name must be given as \\ .\COM10 for ports above COM9. It is recommended to use this name schema also for ports COM1 to COM9.

◆ stopBits

Number bps::AsyncIO::stopBits
readwrite

The stop bits per word.

Set the stop bits before opening the device.

ConstantEncoding
bps.AsyncIO.S1One stop bit per word.
bps.AsyncIO.S1_5One and a half stop bits per word.
bps.AsyncIO.S2Two stop bits per word.

◆ writeTimeout

Number bps::AsyncIO::writeTimeout
readwrite

The write timeout in milliseconds.

A value of 0 disables write timeout and waits forever. The initial default value is 0. Set the write timeout before opening the device.


The documentation for this class was generated from the following file: