Serial

The Serial interface is a wrapper for the pyserial library.

class labtronyx.interfaces.i_Serial.i_Serial(manager, **kwargs)[source]

Serial Interface

Wraps PySerial.

enumerate()[source]

Scans system for new resources and creates resource objects for them.

getResource(resID)[source]

Attempt to open a Serial instrument. If successful, a serial resource is added to the list of known resources and the object is returned.

Returns:object
Raises:ResourceUnavailable
Raises:InterfaceError
prune()[source]

Remove any resources that are no longer found on the system

class labtronyx.interfaces.i_Serial.r_Serial(manager, resID, **kwargs)[source]

Serial Resource Base class.

Wraps PySerial

Resource API is compatible with VISA resources, so any driver written for a VISA resource should also work for serial resources in the case that a VISA library is not available.

close()[source]

Close the resource. If a driver is loaded, that driver is also closed

Returns:True if successful, False otherwise
configure(**kwargs)[source]

Configure Serial port parameters for the resource.

Parameters:
  • timeout (int) – Command timeout
  • write_termination (str) – Write termination
  • baud_rate (int) – Serial Baudrate. Default 9600
  • data_bits (int) – Number of bits per frame. Default 8.
  • parity (str) – Data frame parity (‘N’one, ‘E’ven, ‘O’dd, ‘M’ark or ‘S’pace)
  • stop_bits (int) – Number of stop bits. Default 1
flush()[source]

Flush the output buffer

getConfiguration()[source]

Get the resource configuration

Returns:dict
getProperties()[source]

Get the property dictionary for the Serial resource.

Return type:dict[str:object]
inWaiting()[source]

Return the number of bytes in the receive buffer

Returns:int
Raises:InterfaceError
isOpen()[source]

Query the serial resource to find if it is open

Returns:bool
open()[source]

Open the resource and prepare to receive commands. If a driver is loaded, the driver will also be opened

Returns:True if successful, False otherwise
Raises:ResourceUnavailable
query(data, delay=None)[source]

Retreive ASCII-encoded data from the device given a prompt.

A combination of write(data) and read()

Parameters:
  • data (str) – Data to send
  • delay (float) – delay (in seconds) between write and read operations.
Returns:

str

Raises:

ResourceNotOpen

Raises:

InterfaceTimeout

Raises:

InterfaceError

read(termination=None)[source]

Read string data from the instrument.

Reading stops when the device stops sending, or the termination characters sequence was detected.

All line-ending characters are stripped from the end of the string.

Raises:ResourceNotOpen
read_raw(size=None)[source]

Read Binary-encoded data from the instrument.

No termination characters are stripped.

Parameters:size (int) – Number of bytes to read
Returns:bytes
Raises:ResourceNotOpen
write(data)[source]

Send ASCII-encoded data to the instrument. Includes termination character.

Raises exception if the resource is not open

Parameters:data (str) – Data to send
Raises:ResourceNotOpen
Raises:InterfaceTimeout
Raises:InterfaceError
write_raw(data)[source]

Send Binary-encoded data to the instrument. Termination character is not included

Parameters:data (str) – Data to send
Raises:ResourceNotOpen
Raises:InterfaceTimeout
Raises:InterfaceError